shrub/pkg/arvo/app/azimuth-tracker.hoon

173 lines
4.3 KiB
Plaintext
Raw Normal View History

2019-11-15 03:39:28 +03:00
/- eth-watcher
/+ ethereum, azimuth, default-agent, verb
2020-12-08 03:47:06 +03:00
=, jael
2019-11-15 03:39:28 +03:00
|%
++ app-state
$: %0
url=@ta
whos=(set ship)
==
+$ poke-data
$% :: %listen
::
[%listen whos=(list ship) =source:jael]
:: %watch: configure node url
::
[%watch url=@ta]
==
--
::
|%
++ 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) ,@) ~]
::
++ event-logs-to-udiffs
|= event-logs=(list =event-log:rpc:ethereum)
^- =udiffs:point
%+ murn event-logs
|= =event-log:rpc:ethereum
^- (unit [=ship =udiff:point])
?~ mined.event-log
~
?: removed.u.mined.event-log
~& [%removed-log event-log]
~
=/ =id:block [block-hash block-number]:u.mined.event-log
=, azimuth-events:azimuth
=, abi:ethereum
?: =(broke-continuity i.topics.event-log)
=/ who=@ (decode-topics t.topics.event-log ~[%uint])
=/ num=@ (decode-results data.event-log ~[%uint])
`[who id %rift num %.n]
2019-11-15 03:39:28 +03:00
?: =(changed-keys i.topics.event-log)
=/ who=@ (decode-topics t.topics.event-log ~[%uint])
=/ [enc=octs aut=octs sut=@ud rev=@ud]
2019-11-15 03:39:28 +03:00
%+ decode-results data.event-log
~[[%bytes-n 32] [%bytes-n 32] %uint %uint]
`[who id %keys [rev sut (pass-from-eth:azimuth enc aut sut)] %.n]
2019-11-15 03:39:28 +03:00
?: =(lost-sponsor i.topics.event-log)
=/ [who=@ pos=@]
2019-11-15 03:39:28 +03:00
(decode-topics t.topics.event-log ~[%uint %uint])
`[who id %spon ~]
?: =(escape-accepted i.topics.event-log)
=/ [who=@ wer=@]
2019-11-15 03:39:28 +03:00
(decode-topics t.topics.event-log ~[%uint %uint])
`[who id %spon `wer]
~& [%bad-topic event-log]
~
::
++ jael-update
|= =udiffs:point
2019-11-19 07:36:21 +03:00
^- (list card:agent:gall)
:- [%give %fact ~[/] %azimuth-udiffs !>(udiffs)]
|- ^- (list card:agent:gall)
2019-11-15 03:39:28 +03:00
?~ 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)
2019-11-15 03:39:28 +03:00
::
++ start
|= [state=app-state our=ship dap=term]
2019-11-19 07:36:21 +03:00
^- card:agent:gall
2019-11-15 03:39:28 +03:00
=/ args=vase !>
:+ %watch /[dap]
^- config:eth-watcher
:* url.state =(%czar (clan:title our)) ~m5 ~m30
launch:contracts:azimuth
~
2019-11-15 03:39:28 +03:00
~[azimuth:contracts:azimuth]
2021-04-15 11:02:58 +03:00
~
2019-11-15 03:39:28 +03:00
(topics whos.state)
==
[%pass /wa %agent [our %eth-watcher] %poke %eth-watcher-poke args]
--
::
=| state=app-state
2019-11-16 00:02:37 +03:00
%+ verb |
2019-11-19 07:36:21 +03:00
^- agent:gall
|_ =bowl:gall
2019-11-15 03:39:28 +03:00
+* this .
def ~(. (default-agent this %|) bowl)
::
++ on-init
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall agent:gall)
2019-11-15 03:39:28 +03:00
:_ this :_ ~
2019-11-19 07:36:21 +03:00
^- card:agent:gall
2019-11-15 03:39:28 +03:00
[%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]
?> (our.bowl src.bowl)
2019-11-15 03:39:28 +03:00
?. ?=(%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]
==
::
2019-11-15 03:39:28 +03:00
++ on-watch
|= =path
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall _this)
2019-11-15 03:39:28 +03:00
?< =(/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 on-peek:def
++ on-agent
2019-11-19 07:36:21 +03:00
|= [=wire =sign:agent:gall]
2019-11-15 03:39:28 +03:00
?. ?=([%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)
:_ this
2019-11-19 07:36:21 +03:00
^- (list card:agent:gall)
2019-11-15 03:39:28 +03:00
%- jael-update
?- -.diff
%history (event-logs-to-udiffs loglist.diff)
%logs (event-logs-to-udiffs loglist.diff)
2019-11-15 03:39:28 +03:00
%disavow [*ship id.diff %disavow ~]~
==
::
++ on-arvo on-arvo:def
++ on-fail on-fail:def
--