2018-03-23 22:55:30 +03:00
|
|
|
/- constitution, ethereum, json-rpc
|
|
|
|
/+ ethereum
|
|
|
|
::TODO =, ethereum / constitution causes bail fail. find minimal repro
|
|
|
|
=> [. constitution ethereum]
|
|
|
|
=, eyre
|
|
|
|
|%
|
|
|
|
++ state
|
|
|
|
$: ships=registry
|
|
|
|
block=@ud
|
|
|
|
filter=(unit @ud)
|
|
|
|
ships-c=address
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ move [bone card] :: [target side-effect]
|
|
|
|
++ card :: side-effect
|
|
|
|
$% [%peer wire gill:gall path]
|
|
|
|
[%hiss wire (unit user:eyre) mark [%hiss hiss]]
|
|
|
|
==
|
|
|
|
--
|
|
|
|
::
|
|
|
|
|_ {bol=bowl:gall state}
|
|
|
|
::
|
|
|
|
++ prep
|
|
|
|
|= old=(unit *)
|
|
|
|
:: ?~ old
|
|
|
|
init
|
|
|
|
:: [~ ..prep(fid u.old)]
|
|
|
|
::
|
|
|
|
++ init
|
|
|
|
=/ sc=address
|
|
|
|
0xa9c7.9b9c.5e4e.1fdc.69c1.
|
|
|
|
9fc0.6232.64c8.da50.7a22
|
|
|
|
:_ ..init(ships-c sc)
|
|
|
|
=- [ost.bol -]~
|
|
|
|
%+ rpc-req /init
|
|
|
|
%- batch-read-request
|
|
|
|
%+ turn (gulf ~zod ~per) :: ~fes)
|
|
|
|
|= p=@p
|
|
|
|
:+ `(scot %p p) sc
|
|
|
|
['getShipData(uint32)' ~[uint+`@`p]]
|
|
|
|
::
|
|
|
|
++ rpc-req
|
|
|
|
|= [w=wire j=json]
|
|
|
|
^- card
|
|
|
|
:^ %hiss w ~
|
|
|
|
:+ %json-rpc-response %hiss
|
|
|
|
=- (json-request - j)
|
|
|
|
=+ (need (de-purl:html 'http://localhost:8545'))
|
|
|
|
-(p.p |)
|
|
|
|
::
|
|
|
|
++ sigh-json-rpc-response-init
|
|
|
|
|= [w=wire rep=response:json-rpc]
|
|
|
|
~& [%res rep]
|
|
|
|
?> ?=(%batch -.rep)
|
|
|
|
=- ~& [%ship-data `(list (pair ship hull))`-]
|
|
|
|
[~ +>.$(ships (~(gas in ships) -))]
|
|
|
|
%+ murn bas.rep
|
|
|
|
::TODO ++parse-ship-data into lib
|
|
|
|
|= r=response:json-rpc
|
|
|
|
^- (unit (pair ship hull))
|
|
|
|
?: ?=(%error -.r) ~ ::TODO retry on error?
|
|
|
|
?> ?=(%result -.r)
|
|
|
|
?> ?=(%s -.res.r)
|
2018-04-04 20:13:30 +03:00
|
|
|
=/ hul=hull:eth-noun
|
|
|
|
(decode-results p.res.r hull:eth-type)
|
2018-03-23 22:55:30 +03:00
|
|
|
:: don't care about latent ships.
|
2018-04-04 20:13:30 +03:00
|
|
|
?. active.hul ~
|
2018-03-23 22:55:30 +03:00
|
|
|
:+ ~ (slav %p id.r)
|
2018-04-04 20:13:30 +03:00
|
|
|
(hull-from-eth hul)
|
2018-03-23 22:55:30 +03:00
|
|
|
::
|
|
|
|
::TODO there definitely needs to be a helper function of some kind,
|
|
|
|
:: but is there a way for the type system to be aware of the return
|
|
|
|
:: type if we ask for ie ~[%address %uint %bool] data as a noun?
|
2018-04-04 20:13:30 +03:00
|
|
|
++ hull-from-eth
|
|
|
|
|= hul=hull:eth-noun
|
2018-03-23 22:55:30 +03:00
|
|
|
^- hull
|
2018-04-04 20:13:30 +03:00
|
|
|
=, hul
|
|
|
|
:* owner
|
|
|
|
spawn-count
|
2018-03-23 22:55:30 +03:00
|
|
|
::
|
2018-04-04 20:13:30 +03:00
|
|
|
?> =(32 p.encryption-key)
|
|
|
|
`@`q.encryption-key
|
2018-03-23 22:55:30 +03:00
|
|
|
::
|
2018-04-04 20:13:30 +03:00
|
|
|
?> =(32 p.authentication-key)
|
|
|
|
`@`q.authentication-key
|
2018-03-23 22:55:30 +03:00
|
|
|
::
|
2018-04-04 20:13:30 +03:00
|
|
|
key-revision
|
|
|
|
`@p`sponsor
|
2018-03-23 22:55:30 +03:00
|
|
|
::
|
2018-04-04 20:13:30 +03:00
|
|
|
?. escape-requested ~
|
|
|
|
``@p`escape-to
|
2018-03-23 22:55:30 +03:00
|
|
|
::
|
2018-04-04 20:13:30 +03:00
|
|
|
spawn-proxy
|
|
|
|
transfer-proxy
|
2018-03-23 22:55:30 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
++ poke-noun
|
|
|
|
|= a/@
|
|
|
|
=+ ships-c=0xa9c7.9b9c.5e4e.1fdc.69c1.9fc0.6232.64c8.da50.7a22
|
|
|
|
?: =(a 1)
|
|
|
|
%+ send-rpc-req /block
|
|
|
|
(request-to-json `'eth-blocknum' [%eth-block-number ~])
|
|
|
|
?: =(a 2)
|
|
|
|
%+ send-rpc-req /call
|
|
|
|
%- batch-read-request
|
|
|
|
:~ :+ `'ships-of 0x0'
|
|
|
|
ships-c
|
|
|
|
['getOwnedShips(address)' ~[address+0x0]]
|
|
|
|
::
|
|
|
|
:+ `'ship-data 0'
|
|
|
|
ships-c
|
|
|
|
['getShipData(uint32)' ~[uint+0]]
|
|
|
|
==
|
|
|
|
?: =(a 3)
|
|
|
|
~& %making-filter
|
|
|
|
%+ send-rpc-req /new-filter
|
|
|
|
%+ request-to-json `'new-filter'
|
|
|
|
[%eth-new-filter ~ ~ ~[ships-c] ~]
|
|
|
|
?: =(a 4)
|
|
|
|
~& [%asking-filter-update (need filter)]
|
|
|
|
%+ send-rpc-req /filter-update
|
|
|
|
%+ request-to-json `'req-iq'
|
|
|
|
[%eth-get-filter-changes (need filter)]
|
|
|
|
[~ +>.$]
|
|
|
|
::
|
|
|
|
++ send-move
|
|
|
|
|= c/card
|
|
|
|
[[ost.bol c]~ +>.$]
|
|
|
|
::
|
|
|
|
++ send-rpc-req
|
|
|
|
|= [w=wire j=json]
|
|
|
|
%^ send-move %hiss w
|
|
|
|
:^ ~ %json-rpc-response %hiss
|
|
|
|
=- (json-request - j)
|
|
|
|
=+ (need (de-purl:html 'http://localhost:8545'))
|
|
|
|
-(p.p |)
|
|
|
|
::
|
|
|
|
++ sigh-tang
|
|
|
|
|= [w=wire t=tang]
|
|
|
|
~& [%failed-sigh]
|
|
|
|
~& (turn t (cury wash [0 80]))
|
|
|
|
[~ +>.$]
|
|
|
|
::
|
|
|
|
++ sigh-json-rpc-response
|
|
|
|
|= [w=wire r=response:json-rpc]
|
|
|
|
~& [%rpc-resp w r]
|
|
|
|
[~ +>.$]
|
|
|
|
--
|