2018-03-23 22:55:30 +03:00
|
|
|
/- constitution, ethereum, json-rpc
|
2018-04-10 22:38:35 +03:00
|
|
|
/+ constitution, ethereum
|
2018-03-23 22:55:30 +03:00
|
|
|
::TODO =, ethereum / constitution causes bail fail. find minimal repro
|
2018-04-10 22:38:35 +03:00
|
|
|
=> [. constitution ^constitution ethereum]
|
2018-03-23 22:55:30 +03:00
|
|
|
=, eyre
|
|
|
|
|%
|
|
|
|
++ state
|
2018-04-09 17:59:14 +03:00
|
|
|
$: ships=(map @p hull)
|
2018-04-18 00:11:59 +03:00
|
|
|
dns=[pri=@t sec=@t ter=@t]
|
2018-04-18 01:43:35 +03:00
|
|
|
latest-block=@ud :: last heard
|
2018-04-09 17:59:14 +03:00
|
|
|
filter=(unit @ud) :: our filter id
|
2018-03-23 22:55:30 +03:00
|
|
|
==
|
|
|
|
::
|
2018-04-09 17:59:14 +03:00
|
|
|
++ complete-ship
|
|
|
|
$: state=hull
|
|
|
|
history=(list diff-hull) :: newest first
|
|
|
|
keys=(map @ud (pair @ @))
|
|
|
|
==
|
|
|
|
::
|
|
|
|
+= move [bone card] :: [target side-effect]
|
2018-03-23 22:55:30 +03:00
|
|
|
++ card :: side-effect
|
|
|
|
$% [%peer wire gill:gall path]
|
|
|
|
[%hiss wire (unit user:eyre) mark [%hiss hiss]]
|
|
|
|
==
|
|
|
|
--
|
|
|
|
::
|
|
|
|
|_ {bol=bowl:gall state}
|
|
|
|
::
|
|
|
|
++ prep
|
|
|
|
|= old=(unit *)
|
|
|
|
:: ?~ old
|
2018-04-09 17:59:14 +03:00
|
|
|
ta-save:ta-init:ta
|
2018-04-10 22:38:35 +03:00
|
|
|
:: ta-save:ta
|
2018-03-23 22:55:30 +03:00
|
|
|
::
|
2018-04-09 17:59:14 +03:00
|
|
|
++ ta
|
|
|
|
|_ $: moves=(list move) :: side-effects
|
|
|
|
reqs=(list (pair (unit @t) request)) :: rpc requests
|
|
|
|
wir=wire :: wire for reqs
|
|
|
|
==
|
|
|
|
+* this .
|
|
|
|
::
|
|
|
|
++ ta-save
|
|
|
|
^- (quip move _+>)
|
2018-04-18 01:43:35 +03:00
|
|
|
:_ +>
|
|
|
|
=- (weld - (flop moves))
|
2018-04-10 22:38:35 +03:00
|
|
|
^- (list move)
|
|
|
|
?~ reqs ~
|
|
|
|
:_ ~
|
|
|
|
:- ost.bol
|
2018-04-09 17:59:14 +03:00
|
|
|
%+ rpc-request:ca wir
|
2018-04-10 22:38:35 +03:00
|
|
|
a+(turn (flop reqs) request-to-json)
|
2018-04-09 17:59:14 +03:00
|
|
|
::
|
|
|
|
++ ta-move
|
|
|
|
|= mov=move
|
|
|
|
%_(+> moves [mov moves])
|
|
|
|
::
|
|
|
|
++ ta-card
|
|
|
|
|= car=card
|
|
|
|
(ta-move [ost.bol car])
|
|
|
|
::
|
|
|
|
++ ta-request
|
|
|
|
|= [id=(unit @t) req=request]
|
|
|
|
%_(+> reqs [[id req] reqs])
|
|
|
|
::
|
|
|
|
++ ta-read
|
|
|
|
|= cal=ships:function
|
2018-04-18 15:03:34 +03:00
|
|
|
=+ (ships:function-to-call cal)
|
|
|
|
%+ ta-request `id
|
|
|
|
:+ %eth-call
|
|
|
|
[~ ships:contracts ~ ~ ~ (encode-call dat)]
|
|
|
|
[%label %latest]
|
2018-04-09 17:59:14 +03:00
|
|
|
::
|
|
|
|
++ ta-read-ships
|
|
|
|
|= who=(list @p)
|
2018-04-09 21:22:06 +03:00
|
|
|
?~ who this
|
|
|
|
$(who t.who, this (ta-read %ships i.who))
|
2018-04-09 17:59:14 +03:00
|
|
|
::
|
|
|
|
::
|
2018-04-18 01:43:35 +03:00
|
|
|
++ ta-new-filter
|
|
|
|
%+ ta-request `'new filter'
|
|
|
|
:* %eth-new-filter
|
|
|
|
`[%number +(latest-block)]
|
|
|
|
~
|
|
|
|
~[ships:contracts]
|
|
|
|
~
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ ta-take-filter
|
|
|
|
|= rep=response:json-rpc
|
|
|
|
?< ?=(%batch -.rep)
|
|
|
|
?: ?=(%error -.rep)
|
|
|
|
~& [%filter-rpc-error message.rep]
|
|
|
|
::TODO retry or something
|
|
|
|
+>
|
|
|
|
=. filter `(parse-eth-new-filter-res res.rep)
|
|
|
|
ta-read-filter
|
|
|
|
::
|
|
|
|
++ ta-poll-filter
|
|
|
|
=. wir /init
|
|
|
|
?~ filter ta-new-filter
|
|
|
|
%+ ta-request `'poll filter'
|
|
|
|
[%eth-get-filter-changes u.filter]
|
|
|
|
::
|
|
|
|
++ ta-read-filter
|
|
|
|
=. wir /init
|
|
|
|
?~ filter ta-new-filter
|
|
|
|
%+ ta-request `'filter logs'
|
|
|
|
[%eth-get-filter-logs u.filter]
|
|
|
|
::
|
|
|
|
++ ta-take-filter-results
|
|
|
|
|= rep=response:json-rpc
|
|
|
|
?< ?=(%batch -.rep)
|
|
|
|
?: ?=(%error -.rep)
|
|
|
|
?. =('filter not found' message.rep)
|
|
|
|
~& [%filter-rpc-error message.rep]
|
|
|
|
+>
|
|
|
|
ta-new-filter
|
|
|
|
?> ?=(%a -.res.rep)
|
|
|
|
=* changes p.res.rep
|
|
|
|
~& [%filter-changes (lent changes)]
|
|
|
|
|- ^+ +>.^$
|
|
|
|
?~ changes +>.^$
|
|
|
|
=. +>.^$ (ta-take-filter-result i.changes)
|
|
|
|
$(changes t.changes)
|
|
|
|
::
|
|
|
|
++ ta-take-filter-result
|
|
|
|
|= res=json
|
|
|
|
=, dejs:format
|
|
|
|
=+ log=(parse-event-log res)
|
|
|
|
?~ mined.log +>.$
|
|
|
|
?: =(event.log changed-dns:ships-events)
|
|
|
|
::TODO update dns in state
|
|
|
|
=+ (decode-results data.log ~[%string %string %string])
|
|
|
|
+>.$
|
|
|
|
~& (turn (event-log-to-hull-diffs log) (cork tail head))
|
|
|
|
+>.$
|
|
|
|
::
|
|
|
|
::
|
2018-04-09 17:59:14 +03:00
|
|
|
++ ta-init
|
2018-04-18 01:43:35 +03:00
|
|
|
=. wir /init
|
|
|
|
=< ta-new-filter
|
|
|
|
::TODO =< ta-read-dns
|
|
|
|
%- ta-read-ships
|
2018-04-09 21:22:06 +03:00
|
|
|
(gulf ~zod ~nec) ::TODO ~fes)
|
2018-04-09 17:59:14 +03:00
|
|
|
::
|
2018-04-09 21:22:06 +03:00
|
|
|
++ ta-init-results
|
2018-04-09 17:59:14 +03:00
|
|
|
|= rep=response:json-rpc
|
|
|
|
^+ this
|
|
|
|
?> ?=(%batch -.rep)
|
|
|
|
=. wir /init
|
2018-04-09 21:22:06 +03:00
|
|
|
|- ^+ +>.^$
|
|
|
|
?~ bas.rep +>.^$
|
|
|
|
=. +>.^$ (ta-init-result i.bas.rep)
|
|
|
|
$(bas.rep t.bas.rep)
|
|
|
|
::
|
|
|
|
++ ta-init-result
|
|
|
|
|= rep=response:json-rpc
|
|
|
|
?< ?=(%batch -.rep)
|
2018-04-18 01:43:35 +03:00
|
|
|
?: =('new filter' id.rep)
|
|
|
|
(ta-take-filter rep)
|
|
|
|
?: ?| =('poll filter' id.rep)
|
|
|
|
=('filter logs' id.rep)
|
|
|
|
==
|
|
|
|
(ta-take-filter-results rep)
|
2018-04-09 21:22:06 +03:00
|
|
|
?: ?=(%error -.rep)
|
2018-04-18 01:43:35 +03:00
|
|
|
~& [%init-rpc-error message.rep]
|
2018-04-09 21:22:06 +03:00
|
|
|
::TODO retry or something
|
|
|
|
+>.$
|
|
|
|
?> ?=(%s -.res.rep)
|
2018-04-10 22:38:35 +03:00
|
|
|
=+ cal=(parse-id id.rep)
|
|
|
|
?: ?=(%get-spawned -.cal)
|
|
|
|
=/ kis=(list @p)
|
|
|
|
%- (list @p) ::NOTE because arrays are still typeless
|
|
|
|
(decode-results p.res.rep [%array %uint]~)
|
|
|
|
=. ships
|
|
|
|
%+ ~(put by ships) who.cal
|
|
|
|
=+ (~(got by ships) who.cal)
|
|
|
|
-(spawned (~(gas in spawned) kis))
|
|
|
|
(ta-read-ships kis)
|
2018-04-18 01:43:35 +03:00
|
|
|
?> ?=(%ships -.cal)
|
2018-04-10 22:38:35 +03:00
|
|
|
?> ?=(%s -.res.rep)
|
2018-04-09 17:59:14 +03:00
|
|
|
=/ hul=hull:eth-noun
|
2018-04-09 21:22:06 +03:00
|
|
|
(decode-results p.res.rep hull:eth-type)
|
|
|
|
?. active.hul +>.$
|
2018-04-09 17:59:14 +03:00
|
|
|
=. ships
|
2018-04-10 22:38:35 +03:00
|
|
|
%+ ~(put by ships) who.cal
|
2018-04-09 17:59:14 +03:00
|
|
|
(hull-from-eth hul)
|
2018-04-10 22:38:35 +03:00
|
|
|
?: =(0 spawn-count.hul) +>.$
|
|
|
|
(ta-read %get-spawned who.cal)
|
2018-04-09 17:59:14 +03:00
|
|
|
--
|
|
|
|
::
|
|
|
|
:: arms for card generation
|
|
|
|
++ ca
|
|
|
|
|%
|
|
|
|
++ rpc-request
|
|
|
|
|= [w=wire j=json]
|
|
|
|
^- card
|
|
|
|
:^ %hiss w ~
|
|
|
|
:+ %json-rpc-response %hiss
|
|
|
|
=- (json-request - j)
|
|
|
|
=+ (need (de-purl:html 'http://localhost:8545'))
|
|
|
|
-(p.p |)
|
|
|
|
--
|
2018-03-23 22:55:30 +03:00
|
|
|
::
|
2018-04-09 17:59:14 +03:00
|
|
|
++ kids
|
|
|
|
|= pre=@p
|
|
|
|
^- (list @p)
|
|
|
|
=/ wyd=bloq
|
|
|
|
?+ (clan:title pre) 0
|
|
|
|
%czar 3
|
|
|
|
%king 4
|
|
|
|
%duke 5
|
|
|
|
==
|
|
|
|
%+ turn
|
|
|
|
(gulf 1 (dec (pow 2 (bex wyd))))
|
|
|
|
?: =(~zod pre)
|
|
|
|
|=(a=@p (lsh 3 1 a))
|
|
|
|
|=(a=@p (cat wyd pre a))
|
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
|
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
|
2018-04-10 22:38:35 +03:00
|
|
|
::
|
|
|
|
spawn-count
|
|
|
|
::
|
|
|
|
~
|
|
|
|
::
|
2018-04-04 20:13:30 +03:00
|
|
|
`@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
|
|
|
==
|
|
|
|
::
|
|
|
|
++ poke-noun
|
|
|
|
|= a/@
|
2018-04-18 01:43:35 +03:00
|
|
|
^- (quip move _+>)
|
2018-04-09 17:59:14 +03:00
|
|
|
?: =(a 0)
|
|
|
|
~& [%have-ships ~(key by ships)]
|
|
|
|
[~ +>.$]
|
2018-04-18 01:43:35 +03:00
|
|
|
?: =(a 1)
|
|
|
|
ta-save:ta-poll-filter:ta
|
|
|
|
?: =(a 2)
|
|
|
|
ta-save:ta-new-filter:ta
|
|
|
|
?: =(a 3)
|
|
|
|
ta-save:ta-read-filter:ta
|
2018-03-23 22:55:30 +03:00
|
|
|
[~ +>.$]
|
|
|
|
::
|
|
|
|
++ sigh-tang
|
|
|
|
|= [w=wire t=tang]
|
|
|
|
~& [%failed-sigh]
|
|
|
|
~& (turn t (cury wash [0 80]))
|
|
|
|
[~ +>.$]
|
|
|
|
::
|
2018-04-09 17:59:14 +03:00
|
|
|
++ sigh-json-rpc-response-init
|
|
|
|
|= [w=wire r=response:json-rpc]
|
|
|
|
~& %got-init-response
|
2018-04-09 21:22:06 +03:00
|
|
|
ta-save:(ta-init-results:ta r)
|
2018-04-09 17:59:14 +03:00
|
|
|
::
|
2018-04-18 01:43:35 +03:00
|
|
|
++ sigh-json-rpc-response-filter-poll
|
|
|
|
|= [w=wire r=response:json-rpc]
|
|
|
|
~& %got-filter-poll-results
|
|
|
|
ta-save:(ta-take-filter-results:ta r)
|
|
|
|
::
|
2018-03-23 22:55:30 +03:00
|
|
|
++ sigh-json-rpc-response
|
|
|
|
|= [w=wire r=response:json-rpc]
|
|
|
|
~& [%rpc-resp w r]
|
|
|
|
[~ +>.$]
|
|
|
|
--
|