mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-19 04:41:37 +03:00
naive: add app/naive to download from ethereum
This commit is contained in:
parent
c162758e92
commit
0fbbd3aa28
225
pkg/arvo/app/naive.hoon
Normal file
225
pkg/arvo/app/naive.hoon
Normal file
@ -0,0 +1,225 @@
|
||||
/- eth-watcher
|
||||
/+ ethereum, azimuth, naive, default-agent, verb, dbug
|
||||
=, jael
|
||||
|%
|
||||
++ app-state
|
||||
$: %0
|
||||
url=@ta
|
||||
whos=(set ship)
|
||||
nas=^state:naive
|
||||
logs=(list =event-log:rpc:ethereum)
|
||||
==
|
||||
+$ poke-data
|
||||
$% :: %listen
|
||||
::
|
||||
[%listen whos=(list ship) =source:jael]
|
||||
:: %watch: configure node url
|
||||
::
|
||||
[%watch url=@ta]
|
||||
==
|
||||
+$ tagged-diff [=id:block diff:naive]
|
||||
--
|
||||
::
|
||||
|%
|
||||
++ verifier
|
||||
^- ^verifier:naive
|
||||
|= [dat=@ v=@ r=@ s=@]
|
||||
=/ result
|
||||
%- mule
|
||||
|.
|
||||
=, secp256k1:secp:crypto
|
||||
%- address-from-pub:key:ethereum
|
||||
%- serialize-point
|
||||
(ecdsa-raw-recover dat v r s)
|
||||
?- -.result
|
||||
%| ~
|
||||
%& `p.result
|
||||
==
|
||||
::
|
||||
++ topics
|
||||
|= ships=(set ship)
|
||||
^- (list ?(@ux (list @ux)))
|
||||
?: & ~
|
||||
:: The first topic should be one of these event types
|
||||
::
|
||||
:- => azimuth-events:azimuth
|
||||
:~ broke-continuity
|
||||
changed-keys
|
||||
lost-sponsor
|
||||
escape-accepted
|
||||
==
|
||||
:: If we're looking for a specific set of ships, specify them as
|
||||
:: the second topic. Otherwise don't specify the second topic so
|
||||
:: we will match all ships.
|
||||
::
|
||||
?: =(~ ships)
|
||||
~
|
||||
[(turn ~(tap in ships) ,@) ~]
|
||||
::
|
||||
++ run-logs
|
||||
|= [nas=^state:naive logs=(list event-log:rpc:ethereum)]
|
||||
^- [(list tagged-diff) ^state:naive]
|
||||
?~ logs
|
||||
`nas
|
||||
?~ mined.i.logs
|
||||
$(logs t.logs)
|
||||
=^ raw-effects nas
|
||||
=/ data
|
||||
?~ data.i.logs *@ux
|
||||
?: =(data.i.logs '0x') *@ux
|
||||
~| data.i.logs
|
||||
(hex-to-num:ethereum data.i.logs)
|
||||
=/ =event-log:naive
|
||||
[address.i.logs data topics.i.logs]
|
||||
=/ res (mule |.((naive verifier nas %log event-log)))
|
||||
?- -.res
|
||||
%& p.res
|
||||
%| ((slog 'naive-fail' p.res) `nas)
|
||||
==
|
||||
=/ effects-1
|
||||
=/ =id:block [block-hash block-number]:u.mined.i.logs
|
||||
(turn raw-effects |=(=diff:naive [id diff]))
|
||||
=^ effects-2 nas $(logs t.logs)
|
||||
[(welp effects-1 effects-2) nas]
|
||||
::
|
||||
++ run-batch
|
||||
|= [nas=^state:naive batch=@]
|
||||
^+ *naive
|
||||
(naive verifier nas %bat batch)
|
||||
::
|
||||
++ to-udiffs
|
||||
|= effects=(list tagged-diff)
|
||||
^- =udiffs:point
|
||||
%+ murn effects
|
||||
|= tag=tagged-diff
|
||||
^- (unit [=ship =udiff:point])
|
||||
?. ?=(%point +<.tag) ~
|
||||
?+ +>+<.tag ~
|
||||
%rift `[ship.tag id.tag %rift rift.tag]
|
||||
%keys `[ship.tag id.tag %keys [life crypto-suite pass]:tag]
|
||||
%sponsor `[ship.tag id.tag %spon sponsor.tag]
|
||||
==
|
||||
::
|
||||
++ jael-update
|
||||
|= =udiffs:point
|
||||
^- (list card:agent:gall)
|
||||
?: & ~
|
||||
:- [%give %fact ~[/] %azimuth-udiffs !>(udiffs)]
|
||||
|- ^- (list card:agent:gall)
|
||||
?~ udiffs
|
||||
~
|
||||
=/ =path /(scot %p ship.i.udiffs)
|
||||
:: Should really give all diffs involving each ship at the same time
|
||||
::
|
||||
:- [%give %fact ~[path] %azimuth-udiffs !>(~[i.udiffs])]
|
||||
$(udiffs t.udiffs)
|
||||
::
|
||||
++ start
|
||||
|= [state=app-state our=ship dap=term]
|
||||
^- card:agent:gall
|
||||
=/ args=vase !>
|
||||
:+ %watch /[dap]
|
||||
^- config:eth-watcher
|
||||
:* url.state =(%czar (clan:title our)) ~m5 ~h30
|
||||
launch:contracts:azimuth
|
||||
~[azimuth:contracts:azimuth]
|
||||
(topics whos.state)
|
||||
==
|
||||
[%pass /wa %agent [our %eth-watcher] %poke %eth-watcher-poke args]
|
||||
--
|
||||
::
|
||||
=| state=app-state
|
||||
%- agent:dbug
|
||||
%+ verb |
|
||||
^- agent:gall
|
||||
|_ =bowl:gall
|
||||
+* this .
|
||||
def ~(. (default-agent this %|) bowl)
|
||||
::
|
||||
++ on-init
|
||||
^- (quip card:agent:gall agent:gall)
|
||||
:_ this :_ ~
|
||||
^- card:agent:gall
|
||||
[%pass /eth-watcher %agent [our.bowl %eth-watcher] %watch /logs/[dap.bowl]]
|
||||
::
|
||||
++ on-save !>(state)
|
||||
++ on-load
|
||||
|= old=vase
|
||||
`this(state !<(app-state old))
|
||||
::
|
||||
++ on-poke
|
||||
|= [=mark =vase]
|
||||
?: =(%noun mark)
|
||||
?+ q.vase !!
|
||||
%rerun
|
||||
=^ effects nas.state (run-logs *^state:naive logs.state)
|
||||
`this
|
||||
::
|
||||
%resub
|
||||
:_ this :_ ~
|
||||
[%pass /eth-watcher %agent [our.bowl %eth-watcher] %watch /logs/[dap.bowl]]
|
||||
==
|
||||
?. ?=(%azimuth-tracker-poke mark)
|
||||
(on-poke:def mark vase)
|
||||
=+ !<(poke=poke-data vase)
|
||||
?- -.poke
|
||||
%listen [[%pass /lo %arvo %j %listen (silt whos.poke) source.poke]~ this]
|
||||
%watch
|
||||
=. url.state url.poke
|
||||
[[(start state [our dap]:bowl) ~] this]
|
||||
==
|
||||
::
|
||||
++ on-watch
|
||||
|= =path
|
||||
^- (quip card:agent:gall _this)
|
||||
?< =(/sole/drum path)
|
||||
?> ?=(?(~ [@ ~]) path)
|
||||
=/ who=(unit ship)
|
||||
?~ path ~
|
||||
`(slav %p i.path)
|
||||
=. whos.state
|
||||
?~ who
|
||||
~
|
||||
(~(put in whos.state) u.who)
|
||||
:_ this :_ ~
|
||||
(start state [our dap]:bowl)
|
||||
::
|
||||
++ on-leave on-leave:def
|
||||
++ on-peek
|
||||
|= =path
|
||||
?: =(/x/nas path)
|
||||
``nas+!>(nas.state)
|
||||
?: =(/x/logs path)
|
||||
``logs+!>(logs.state)
|
||||
~
|
||||
::
|
||||
++ on-agent
|
||||
|= [=wire =sign:agent:gall]
|
||||
?. ?=([%eth-watcher ~] wire)
|
||||
(on-agent:def wire sign)
|
||||
?. ?=(%fact -.sign)
|
||||
(on-agent:def wire sign)
|
||||
?. ?=(%eth-watcher-diff p.cage.sign)
|
||||
(on-agent:def wire sign)
|
||||
=+ !<(diff=diff:eth-watcher q.cage.sign)
|
||||
?: ?=(%disavow -.diff)
|
||||
[(jael-update [*ship id.diff %disavow ~]~) this]
|
||||
::
|
||||
=. logs.state
|
||||
?- -.diff
|
||||
%history loglist.diff
|
||||
%logs (welp logs.state loglist.diff)
|
||||
==
|
||||
=^ effects nas.state
|
||||
%+ run-logs
|
||||
?- -.diff
|
||||
%history *^state:naive
|
||||
%logs nas.state
|
||||
==
|
||||
loglist.diff
|
||||
::
|
||||
[(jael-update (to-udiffs effects)) this]
|
||||
::
|
||||
++ on-arvo on-arvo:def
|
||||
++ on-fail on-fail:def
|
||||
--
|
@ -17,15 +17,6 @@
|
||||
:: for some reason? IMO if either side is on L2, then both sides
|
||||
:: should operate on L2
|
||||
::
|
||||
:: TODO: should we emit all the events azimuth.sol does? might be
|
||||
:: convenient for tracking edges? Yes
|
||||
::
|
||||
:: TODO: add nonces to txs. how to keep track of them? need replay
|
||||
:: protection. maybe we can add nonces to ships instead of addresses?
|
||||
:: Then what about operators? Looks like we can keep nonces out of the
|
||||
:: tx data by just including it in the signed data. If the signature
|
||||
:: succeeds but the tx fails, i guess the nonce should be advanced
|
||||
::
|
||||
:: TODO: think about whether nonces are safe when associated with
|
||||
:: ship/address
|
||||
::
|
||||
@ -34,8 +25,10 @@
|
||||
::
|
||||
:: TODO: polymorphic addresses to save tx space?
|
||||
::
|
||||
:: TODO: default sponsor in get-point
|
||||
::
|
||||
/+ std
|
||||
=> => std
|
||||
=> =+ std
|
||||
:: Constants
|
||||
::
|
||||
|%
|
||||
@ -61,6 +54,11 @@
|
||||
0xb2d3.a6e7.a339.f5c8.ff96.265e.2f03.a010.
|
||||
a854.1070.f374.4a24.7090.9644.1508.1546
|
||||
::
|
||||
:: OwnershipTransferred(address,address)
|
||||
++ ownership-transferred
|
||||
0x8be0.079c.5316.5914.1344.cd1f.d0a4.f284.
|
||||
1949.7f97.22a3.daaf.e3b4.186f.6b64.57e0
|
||||
::
|
||||
:: EscapeRequested(uint32,uint32)
|
||||
++ escape-requested
|
||||
0xb4d4.850b.8f21.8218.141c.5665.cba3.79e5.
|
||||
@ -202,7 +200,7 @@
|
||||
::
|
||||
+$ event-log
|
||||
$: address=@ux
|
||||
data=@
|
||||
data=@ux
|
||||
topics=(lest @ux)
|
||||
==
|
||||
+$ input
|
||||
@ -427,13 +425,15 @@
|
||||
=/ existing (~(get by points.state) ship)
|
||||
?^ existing
|
||||
`u.existing
|
||||
?+ (ship-rank ship) ~>(%slog.[0 %strange-point] ~)
|
||||
%0 `%*(. *point dominion %l1)
|
||||
=| =point
|
||||
=. who.sponsor.net.point (sein ship)
|
||||
?+ (ship-rank ship) ~>(%slog.[0 %strange-point] ~&(ship=ship ~))
|
||||
%0 `point(dominion %l1)
|
||||
?(%1 %2)
|
||||
=/ existing-parent $(ship (sein ship))
|
||||
?~ existing-parent ~
|
||||
:- ~
|
||||
%* . *point
|
||||
%= point
|
||||
dominion
|
||||
?- dominion.u.existing-parent
|
||||
%l1 %l1
|
||||
@ -450,6 +450,9 @@
|
||||
|= [=state log=event-log]
|
||||
^- [effects ^state]
|
||||
=* log-name i.topics.log
|
||||
?: =(log-name activated:log-names) `state
|
||||
?: =(log-name spawned:log-names) `state
|
||||
?: =(log-name ownership-transferred:log-names) `state
|
||||
?: =(log-name changed-dns:log-names)
|
||||
?> ?=(~ t.topics.log)
|
||||
=/ words (rip 8 data.log)
|
||||
@ -479,6 +482,7 @@
|
||||
?> ?=([@ *] t.topics.log)
|
||||
=* ship=@ i.t.topics.log
|
||||
=/ the-point (get-point state ship)
|
||||
~| log=log
|
||||
?> ?=(^ the-point)
|
||||
=* point u.the-point
|
||||
=- [effects state(points (~(put by points.state) ship new-point))]
|
||||
@ -510,12 +514,12 @@
|
||||
::
|
||||
?: =(log-name changed-keys:log-names)
|
||||
?> ?=(~ t.t.topics.log)
|
||||
=/ words (rip 8 data.log)
|
||||
?> ?=([@ @ @ @ ~] words) :: TODO: reverse order?
|
||||
=* encryption=@ i.words
|
||||
=* authentication=@ i.t.words
|
||||
=* crypto-suite=@ i.t.t.words :: TODO: store in state, or add to pass
|
||||
=* life=@ i.t.t.t.words
|
||||
=/ encryption=@ (cut 8 [3 1] data.log)
|
||||
=/ authentication=@ (cut 8 [2 1] data.log)
|
||||
:: TODO: store in state, or add to pass
|
||||
::
|
||||
=/ crypto-suite=@ (cut 8 [1 1] data.log)
|
||||
=/ life=@ (cut 8 [0 1] data.log)
|
||||
=/ =pass (pass-from-eth 32^encryption 32^authentication crypto-suite)
|
||||
:- [%point ship %keys life crypto-suite pass]~
|
||||
point(life.net life, pass.net pass)
|
||||
@ -576,6 +580,7 @@
|
||||
point(address.voting-proxy.own to)
|
||||
::
|
||||
~> %slog.[0 %unknown-log]
|
||||
~& log=i.topics.log
|
||||
`point
|
||||
::
|
||||
:: Receive batch of L2 transactions
|
||||
|
@ -202,6 +202,11 @@
|
||||
|= [a=bloq b=@ c=@]
|
||||
(add (lsh [a (met a b)] c) b)
|
||||
::
|
||||
++ cut :: slice
|
||||
~/ %cut :: TODO: jet
|
||||
|= [a=bloq [b=step c=step] d=@]
|
||||
(end [a c] (rsh [a b] d))
|
||||
::
|
||||
++ dad :: concatenate fixed
|
||||
~/ %dad
|
||||
|= [=bite a=@ b=@]
|
||||
|
@ -15,18 +15,18 @@
|
||||
;< =latest=block bind:m (get-latest-block:ethio url.pup)
|
||||
;< pup=watchpup bind:m (zoom pup number.id.latest-block)
|
||||
=| vows=disavows
|
||||
?. eager.pup
|
||||
::?. eager.pup
|
||||
(pure:m !>([vows pup]))
|
||||
|- ^- form:m
|
||||
=* loop $
|
||||
?: (gth number.pup number.id.latest-block)
|
||||
(pure:m !>([vows pup]))
|
||||
;< =block bind:m (get-block-by-number:ethio url.pup number.pup)
|
||||
;< [=new=disavows pup=watchpup] bind:m (take-block pup block)
|
||||
%= loop
|
||||
pup pup
|
||||
vows (weld vows new-disavows)
|
||||
==
|
||||
:: |- ^- form:m
|
||||
:: =* loop $
|
||||
:: ?: (gth number.pup number.id.latest-block)
|
||||
:: (pure:m !>([vows pup]))
|
||||
:: ;< =block bind:m (get-block-by-number:ethio url.pup number.pup)
|
||||
:: ;< [=new=disavows pup=watchpup] bind:m (take-block pup block)
|
||||
:: %= loop
|
||||
:: pup pup
|
||||
:: vows (weld vows new-disavows)
|
||||
:: ==
|
||||
::
|
||||
:: Process a block, detecting and handling reorgs
|
||||
::
|
||||
@ -81,11 +81,12 @@
|
||||
=/ m (strand:strandio ,watchpup)
|
||||
^- form:m
|
||||
=/ zoom-margin=number:block 30
|
||||
=/ zoom-step=number:block 100.000
|
||||
=/ zoom-step=number:block 10.000
|
||||
?: (lth latest-number (add number.pup zoom-margin))
|
||||
(pure:m pup)
|
||||
=/ up-to-number=number:block (sub latest-number zoom-margin)
|
||||
=/ up-to-number=number:block (min (add 1.000.000 number.pup) (sub latest-number zoom-margin))
|
||||
|-
|
||||
~& > [%zooming number.pup up-to-number]
|
||||
=* loop $
|
||||
?: (gth number.pup up-to-number)
|
||||
(pure:m pup(blocks ~))
|
||||
|
Loading…
Reference in New Issue
Block a user