Merge pull request #946 from urbit/azimuth

Compatibility with Azimuth
This commit is contained in:
Fang 2018-12-18 20:48:32 +01:00 committed by GitHub
commit 3f3f623226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1176 additions and 1140 deletions

View File

@ -81,7 +81,7 @@
=+ => (from-seed:bip32 64^seed)
(derive-path "m/44'/60'/0'/0/0")
:+ [public-key private-key]
(address-from-prv:ethereum private-key)
(address-from-prv:key:ethereum private-key)
chain-code
::
++ urbit

View File

@ -1,8 +1,8 @@
::
|_ upd=update:constitution:ethe
|_ upd=update:azimuth
::
++ grab :: convert from
|%
++ noun update:constitution:ethe :: from %noun
++ noun update:azimuth :: from %noun
--
--

View File

@ -21,10 +21,9 @@
=, able:jael
=, crypto
=, jael
=, ethe
=, constitution:ethe
=, ethereum
=, constitution:ethereum
=, rpc
=, azimuth
:: ::::
:::: # models :: data structures
:: ::::
@ -71,11 +70,11 @@
kyz=(map ship public) :: public key state
== ::
$= eth :: ethereum (vent)
::TODO the subscribers here never hear dns or hul...
::TODO the subscribers here never hear dns or pos...
$: yen=(set duct) :: trackers
dns=dnses :: on-chain dns state
hul=(map ship hull) :: on-chain ship state
::TODO do we want (map ship diff-hull) too?
pos=(map ship point) :: on-chain ship state
::TODO do we want (map ship diff-point) too?
== ::
== ::
++ state-absolute :: absolute urbit
@ -559,7 +558,7 @@
:: +order-events: sort changes by block and log numbers
::
++ order-events
|= loz=(list (pair event-id diff-constitution))
|= loz=(list (pair event-id diff-azimuth))
^+ loz
%+ sort loz
:: sort by block number, then by event log number,
@ -635,12 +634,12 @@
^- ship
:: XX save %dawn sponsor in .own.sub, check there
::
=/ hul (~(get by hul.eth.sub) who)
?: ?& ?=(^ hul)
?=(^ net.u.hul)
?=(^ sponsor.u.net.u.hul)
=/ pot (~(get by pos.eth.sub) who)
?: ?& ?=(^ pot)
?=(^ net.u.pot)
?=(^ sponsor.u.net.u.pot)
==
u.sponsor.u.net.u.hul
u.sponsor.u.net.u.pot
:: XX fall back to most recent sponsor instead?
::
(^sein:title who)
@ -1101,7 +1100,7 @@
++ extract-snap :: extract rewind point
^- snapshot
:* kyz.puk.sub
[dns hul]:eth.sub
[dns pos]:eth.sub
heard.etn
latest-block.etn
==
@ -1329,7 +1328,7 @@
=? +> new
::TODO should we be mutating state here,
:: or better to move this into ++vent:feel?
+>(dns.eth *dnses, hul.eth ~, kyz.puk ~)
+>(dns.eth *dnses, pos.eth ~, kyz.puk ~)
=? +> |(new !=(0 ~(wyt by evs)))
%- vent:feel
:- %chain
@ -1371,7 +1370,7 @@
(~(put by kyz) who -)
::
++ file-event
|= [wer=event-id dif=diff-constitution]
|= [wer=event-id dif=diff-azimuth]
^+ [kyz ..file]
?: (~(has in heard) wer)
~& %ignoring-already-heard-event
@ -1386,16 +1385,16 @@
==
=^ kyz ..file
?- -.dif
%hull ~|(wer=wer (file-hull +.dif))
%point ~|(wer=wer (file-point +.dif))
%dns [kyz (file-dns +.dif)]
==
[kyz (file-snap wer)]
::
++ file-hull
|= [who=ship dif=diff-hull]
++ file-point
|= [who=ship dif=diff-point]
^+ [kyz ..file]
=- ::TODO =; with just the type
=. hul.eth (~(put by hul.eth) who hel)
=. pos.eth (~(put by pos.eth) who pon)
:: new keys
::
?: ?=(%& -.new)
@ -1423,26 +1422,26 @@
[hen %slip %g %sunk who lyf]
==
==
:: hel: updated hull
:: pon: updated point
:: new: new keypair or "kept continuity?" (yes is no-op)
^- [hel=hull new=(each (pair life pass) ?)]
=+ hul=(fall (~(get by hul.eth) who) *hull)
^- [pon=point new=(each (pair life pass) ?)]
=+ pot=(fall (~(get by pos.eth) who) *point)
::
:: sanity checks, should never fail if we operate correctly
::
~| [%diff-order-insanity -.dif who (~(get by hul.eth) who)]
~| [%diff-order-insanity -.dif who (~(get by pos.eth) who)]
?> ?+ -.dif &
%spawned ?> ?=(^ kid.hul)
!(~(has in spawned.u.kid.hul) who.dif)
%keys ?> ?=(^ net.hul)
=(life.dif +(life.u.net.hul))
%continuity ?> ?=(^ net.hul)
=(new.dif +(continuity-number.u.net.hul))
%spawned ?> ?=(^ kid.pot)
!(~(has in spawned.u.kid.pot) who.dif)
%keys ?> ?=(^ net.pot)
=(life.dif +(life.u.net.pot))
%continuity ?> ?=(^ net.pot)
=(new.dif +(continuity-number.u.net.pot))
==
::
:: apply hull changes, catch continuity and key changes
:: apply point changes, catch continuity and key changes
::
:- (apply-hull-diff hul dif)
:- (apply-point-diff pot dif)
=* nop |+& :: no-op
?+ -.dif nop
%continuity |+|
@ -1666,7 +1665,7 @@
:: +put-change: store change made by event
::
++ put-change
|= [cause=event-id dif=diff-constitution]
|= [cause=event-id dif=diff-azimuth]
?: (~(has by changes) cause) :: one diff per event
~& [%duplicate-cause cause]
!!
@ -1747,7 +1746,7 @@
:* %eth-get-logs
`number+from-block
`number+next-block
~[ships:contracts]
~[azimuth:contracts]
~
==
::
@ -1755,7 +1754,7 @@
::
:: +new-filter: request a new polling filter
::
:: Listens only to the Ships state contract, and only from
:: Listens only to the Azimuth state contract, and only from
:: the last-heard block onward.
::
++ new-filter
@ -1766,10 +1765,10 @@
:: XX We want to load from a snapshot at least 40 blocks behind, then
:: replay to the present
:: `[%number ?:((lte latest-block 40) 0 (sub.add latest-block 40))]
::TODO or Ships origin block when 0
::TODO or Azimuth origin block when 0
~ ::TODO we should probably chunck these, maybe?
:: https://stackoverflow.com/q/49339489
~[ships:contracts]
~[azimuth:contracts]
~
==
::
@ -1883,7 +1882,7 @@
:: +accept: process single event
::
++ accept
|= [cause=event-id dif=diff-constitution]
|= [cause=event-id dif=diff-azimuth]
^+ +>
?: (~(has in heard) cause)
~& %accept-ignoring-duplicate-event
@ -2071,16 +2070,16 @@
==
=+ cuz=[block-number.place log-index.place]
::
?: =(event.log changed-dns:ships-events)
?: =(event.log changed-dns:azimuth-events)
=+ ^- [pri=tape sec=tape ter=tape]
%+ decode-results data.log
~[%string %string %string]
%+ put-change cuz
[%dns (crip pri) (crip sec) (crip ter)]
::
=+ dif=(event-log-to-hull-diff log)
=+ dif=(event-log-to-point-diff log)
?~ dif +>.$
(put-change cuz %hull u.dif)
(put-change cuz %point u.dif)
:: :: ++restore-block:et
++ restore-block :: rewind before block
|= block=@ud
@ -2103,7 +2102,7 @@
?: |(=(~ old-qeu) (lth block block-number:(need ~(top to old-qeu))))
[snap.snap +>.^$]
$
~& [%restoring-block block latest-block.snap ~(wyt by hul.eth.snap)]
~& [%restoring-block block latest-block.snap ~(wyt by pos.eth.snap)]
(restore-snap snap &)
:: :: ++restore-snap:et
++ restore-snap :: restore snapshot
@ -2129,7 +2128,7 @@
latest-block.etn latest-block.snap
kyz.puk.sub kyz.snap
dns.eth.sub dns.eth.snap
hul.eth.sub hul.eth.snap
pos.eth.sub pos.eth.snap
sap sap(last-block 0)
moves
?. look moves

File diff suppressed because it is too large Load Diff

View File

@ -56,9 +56,9 @@
::
=^ results3 jael-gate
=/ hiss-httr=hiss:eyre
%+ json-request:ethereum
%+ json-request:rpc:ethereum
(need url)
%+ request-to-json:ethereum
%+ request-to-json:rpc:ethereum
`'block number'
[%eth-block-number ~]
%- jael-take-with-comparator :*

View File

@ -1,9 +1,9 @@
/+ *test
|%
:: example hull for ~zod
:: example point for ~zod
::
++ hul
^- hull:constitution:ethe
++ pot
^- point:azimuth-types
:+ [0x0 0x0 0x0 0x0]
:* ~
life=1
@ -15,19 +15,19 @@
sponsor=[~ u=~zod]
escape=~
==
[~ u=[spawn-proxy=0x0 spawn-count=2 spawned=~]]
[~ u=[spawn-proxy=0x0 spawned=~]]
:: secret key for ~zod
::
++ sec
^- ring
0w8.Ugyke.eUOf2.NcHRo.tZA7r.P8vP6.DGKp4.yn-BI.etdzb.ucv75.WgRob.H1-7n.
4qCje.gc7z7.1i-3T.9~8UR.IGkGH.6NWR2
:: Ships contract address
:: Azimuth contract address
::
++ ships
++ azimuth
%- crip
%+ weld "0x"
(render-hex-bytes:ethereum 20 `@`ships:contracts:constitution:ethe)
(render-hex-bytes:ethereum 20 `@`azimuth:contracts:^azimuth)
:: snapshot
::
++ snap
@ -38,11 +38,11 @@
dns.eth
['urbit.org' 'urbit.org' '']
::
hul.eth
pos.eth
%- malt
:* ~zod^hul
~marzod^hul
(turn (gulf 1 255) |=(gal=@ gal^hul))
:* ~zod^pot
~marzod^pot
(turn (gulf 1 255) |=(gal=@ gal^pot))
==
::
latest-block 4.230.000
@ -64,18 +64,18 @@
!> &
!> ?=(^ zar)
::
++ test-give-hull
++ test-give-point
=/ oct
%- as-octs:mimes:html
%+ rap 3
:~ '{"jsonrpc":"2.0","id":"0","method":"eth_call","params":[{"data":"'
'0xb3220694'
'0x63fa9a87'
'0000000000000000000000000000000000000000000000000000000000000000'
'","to":"' ships '"},"0x0"]}'
'","to":"' azimuth '"},"0x0"]}'
==
%+ expect-eq
!> oct
!> (hull:give:dawn 0 ~zod)
!> (point:give:dawn 0 ~zod)
::
++ test-give-turf
=/ oct
@ -84,15 +84,15 @@
:~ '[{"jsonrpc":"2.0","id":"turf-0","method":"eth_call","params":[{"data":"'
'0xeccc8ff1'
'0000000000000000000000000000000000000000000000000000000000000000'
'","to":"' ships '"},"0x0"]},'
'","to":"' azimuth '"},"0x0"]},'
'{"jsonrpc":"2.0","id":"turf-1","method":"eth_call","params":[{"data":"'
'0xeccc8ff1'
'0000000000000000000000000000000000000000000000000000000000000001'
'","to":"' ships '"},"0x0"]},'
'","to":"' azimuth '"},"0x0"]},'
'{"jsonrpc":"2.0","id":"turf-2","method":"eth_call","params":[{"data":"'
'0xeccc8ff1'
'0000000000000000000000000000000000000000000000000000000000000002'
'","to":"' ships '"},"0x0"]}]'
'","to":"' azimuth '"},"0x0"]}]'
==
%+ expect-eq
!> oct
@ -143,27 +143,26 @@
[[~zod 1 zod.kyz] [~nec 1 nec.kyz] ~]
!> (czar:take:dawn oct)
::
++ test-take-hull
++ test-take-point
=/ oct
%- as-octs:mimes:html
%+ rap 3
:~ '{"jsonrpc":"2.0","result":"'
'0x0000000000000000000000000000000000000000000000000000000000000001'
'b69b6818b17b7cc22f8e0a2291f58e4aa840cbf44cb2f1c94dc3d71e3cda0d94'
'0xb69b6818b17b7cc22f8e0a2291f58e4aa840cbf44cb2f1c94dc3d71e3cda0d94'
'3defb87516f42ce4327820b588002aa53e52527af8d23bee4aa215fa296bdf5f'
'0000000000000000000000000000000000000000000000000000000000000001'
'0000000000000000000000000000000000000000000000000000000000000001'
'0000000000000000000000000000000000000000000000000000000000000000'
'0000000000000000000000000000000000000000000000000000000000000002'
'0000000000000000000000000000000000000000000000000000000000000000'
'0000000000000000000000000000000000000000000000000000000000000000'
'0000000000000000000000000000000000000000000000000000000000000001'
'0000000000000000000000000000000000000000000000000000000000000000'
'0000000000000000000000000000000000000000000000000000000000000001'
'0000000000000000000000000000000000000000000000000000000000000000'
'"}'
==
%+ expect-eq
!> [~ hul]
!> (hull:take:dawn ~zod oct)
!> [~ pot]
!> (point:take:dawn ~zod oct)
::
++ test-take-turf
=/ oct
@ -192,10 +191,10 @@
!> [~ 4.230.000]
!> (bloq:snap:dawn snap)
::
++ test-snap-hull
++ test-snap-point
%+ expect-eq
!> [~ hul]
!> (hull:snap:dawn ~zod snap)
!> [~ pot]
!> (point:snap:dawn ~zod snap)
::
++ test-snap-czar
%+ expect-eq
@ -211,36 +210,36 @@
=/ sed [~zod 1 sec ~]
%+ expect-eq
!> [%& `~zod]
!> (veri:dawn sed hul ~)
!> (veri:dawn sed pot ~)
::
++ test-veri-not-spawned
=/ sed [~zod 1 sec ~]
%+ expect-eq
!> [%| %not-keyed]
!> (veri:dawn sed =>(hul .(net ~)) ~)
!> (veri:dawn sed =>(pot .(net ~)) ~)
::
++ test-veri-wrong-key
=/ sed [~zod 1 sec:ex:(pit:nu:crub:crypto 24 %foo) ~]
%+ expect-eq
!> [%| %key-mismatch]
!> (veri:dawn sed hul ~)
!> (veri:dawn sed pot ~)
::
++ test-veri-life-mismatch
=/ sed [~zod 2 sec ~]
%+ expect-eq
!> [%| %life-mismatch]
!> (veri:dawn sed hul ~)
!> (veri:dawn sed pot ~)
::
++ test-veri-already-booted
=/ sed [~zod 1 sec ~]
;: weld
%+ expect-eq
!> [%| %already-booted]
!> (veri:dawn sed hul `[1 |])
!> (veri:dawn sed pot `[1 |])
::
%+ expect-eq
!> [%| %already-booted]
!> (veri:dawn sed hul `[2 &])
!> (veri:dawn sed pot `[2 &])
==
::
++ test-veri-earl-good
@ -253,7 +252,7 @@
[who 1 sec:ex:cub `sig]
%+ expect-eq
!> [%& ~]
!> (veri:dawn sed hul ~)
!> (veri:dawn sed pot ~)
::
++ test-veri-earl-missing-sig
=/ cub (pit:nu:crub:crypto 24 %foo)
@ -262,7 +261,7 @@
[who 1 sec:ex:cub ~]
%+ expect-eq
!> [%| %missing-sig]
!> (veri:dawn sed hul ~)
!> (veri:dawn sed pot ~)
::
++ test-veri-earl-parent-not-keyed
=/ cub (pit:nu:crub:crypto 24 %foo)
@ -274,7 +273,7 @@
[who 1 sec:ex:cub `sig]
%+ expect-eq
!> [%| %parent-not-keyed]
!> (veri:dawn sed =>(hul .(net ~)) ~)
!> (veri:dawn sed =>(pot .(net ~)) ~)
::
++ test-veri-earl-life-mismatch
=/ cub (pit:nu:crub:crypto 24 %foo)
@ -286,7 +285,7 @@
[who 2 sec:ex:cub `sig]
%+ expect-eq
!> [%| %life-mismatch]
!> (veri:dawn sed hul ~)
!> (veri:dawn sed pot ~)
::
++ test-veri-earl-invalid-sig
=/ cub (pit:nu:crub:crypto 24 %foo)
@ -299,7 +298,7 @@
[who 1 sec:ex:cub `sig]
%+ expect-eq
!> [%| %invalid-sig]
!> (veri:dawn sed hul ~)
!> (veri:dawn sed pot ~)
::
=/ sed
=/ sig
@ -308,7 +307,7 @@
[who 1 sec:ex:cub `sig]
%+ expect-eq
!> [%| %invalid-sig]
!> (veri:dawn sed hul ~)
!> (veri:dawn sed pot ~)
==
::
++ test-veri-earl-already-booted
@ -321,7 +320,7 @@
[who 1 sec:ex:cub `sig]
%+ expect-eq
!> [%| %already-booted]
!> (veri:dawn sed hul `[1 |])
!> (veri:dawn sed pot `[1 |])
::
++ test-veri-pawn-good
=/ cub (pit:nu:crub:crypto 24 %foo)
@ -329,7 +328,7 @@
=/ sed [who 1 sec:ex:cub ~]
%+ expect-eq
!> [%& ~]
!> (veri:dawn sed *hull:constitution:ethe ~)
!> (veri:dawn sed *point:azimuth-types ~)
::
++ test-veri-pawn-key-mismatch
=/ cub (pit:nu:crub:crypto 24 %foo)
@ -337,7 +336,7 @@
=/ sed [who 1 sec:ex:(pit:nu:crub:crypto 24 %bar) ~]
%+ expect-eq
!> [%| %key-mismatch]
!> (veri:dawn sed *hull:constitution:ethe ~)
!> (veri:dawn sed *point:azimuth-types ~)
::
++ test-veri-pawn-invalid-life
=/ cub (pit:nu:crub:crypto 24 %foo)
@ -345,7 +344,7 @@
=/ sed [who 2 sec:ex:cub ~]
%+ expect-eq
!> [%| %invalid-life]
!> (veri:dawn sed *hull:constitution:ethe ~)
!> (veri:dawn sed *point:azimuth-types ~)
::
++ test-veri-pawn-already-booted
=/ cub (pit:nu:crub:crypto 24 %foo)
@ -353,5 +352,5 @@
=/ sed [who 1 sec:ex:cub ~]
%+ expect-eq
!> [%| %already-booted]
!> (veri:dawn sed *hull:constitution:ethe `[1 |])
!> (veri:dawn sed *point:azimuth-types `[1 |])
--

View File

@ -5,7 +5,7 @@
::
++ test-static-args
%+ expect-eq
!> %- encode-args:ethereum
!> %- encode-args:abi:ethereum
:~ [%string "dave"]
[%bool &]
[%array [%uint 1] [%uint 2] [%uint 3] ~]
@ -24,7 +24,7 @@
::
++ test-dynamic-args
%+ expect-eq
!> %- encode-args:ethereum
!> %- encode-args:abi:ethereum
:~ [%uint `@ud`0x123]
[%array [%uint `@ud`0x456] [%uint `@ud`0x789] ~]
[%bytes-n (as-octt:mimes:html (flop "1234567890"))]
@ -41,4 +41,4 @@
"000000000000000000000000000000000000000000000000000000000000000d"
"48656c6c6f2c20776f726c642100000000000000000000000000000000000000"
==
--
--

View File

@ -4,7 +4,7 @@
::
++ test-signing-transaction-1
%+ expect-eq
!> %+ sign-transaction:ethereum
!> %+ sign-transaction:key:ethereum
:* 123
1.000
5.000
@ -25,7 +25,7 @@
::
++ test-signing-transaction-2
%+ expect-eq
!> %+ sign-transaction:ethereum
!> %+ sign-transaction:key:ethereum
:* 42
1.000
5.000