Merge branch 'master' into light-integration

* master: (38 commits)
  bumped ames protocol number
  landscape 3f83c798bd61b7e6cef5c4e2f7c7f3ac89d4ec09
  removed hard calls on json blobs
  Support eth_getBlockByNumber Ethereum RPC call
  added initial image support to udon parser (#1085)
  Tiebout - Apple Push Notification Server App (#1084)
  Implement +from-unix for turning timestamps into @da
  Add support to `lens-command` for pill output and optimized base64 encoding. (#1068)
  Point to the correct topics when decoding Azimuth events
  Add trailing newlines
  Use unit to disambiguate poll timer state
  Lightly re-order ++watcher core, add comments
  Implement ++peek so the app can by scried
  Remove debug pokes
  Implement %eth-watcher, an app for tracking Ethereum events
  add control flow to |verb
  Be accurate in incoming/hoon-side structures also
  More accurately represent Ethereum RPC filter topics
  also pin validate-x to now
  pin to local time because using local desk
  ...
This commit is contained in:
Joe Bryan 2019-03-13 13:39:12 -07:00
commit e98c379405
35 changed files with 84667 additions and 189 deletions

View File

@ -83,16 +83,6 @@ function barMass(urb) {
}
Promise.resolve(urbit)
// XX temporary
// send ctrl-x to select dojo
//
.then(function(){
return urbit.expect(/talk\[\] /)
.then(function() {
return urbit.pty.write("\x18")
})
.then(function() { return urbit })
})
.then(actions.safeBoot)
.then(function(){
return barMass(urbit);

View File

@ -1044,6 +1044,7 @@
?- -.sink.com
$stdout [%show %0]
$output-file $(sink.com [%command (cat 3 '@' pax.sink.com)])
$output-pill $(sink.com [%command (cat 3 '.' pax.sink.com)])
$output-clay [%file (need (de-beam:format pax.sink.com))]
$url [%http %post (crip (en-purl:html url.sink.com))]
$to-api !!

568
app/eth-watcher.hoon Normal file
View File

@ -0,0 +1,568 @@
:: watcher: ethereum event log collector
::
/+ *eth-watcher
::
=, ethereum
=, rpc
::
|%
++ state
$: eyes=(map name eye)
==
::
++ eye
$: config
latest-block=@ud
filter-id=@ud
poll-timer=(unit @da)
snapshot
sap=history
==
::
++ history
$: interval=_100
max-count=_10
count=@ud
latest-block=@ud
snaps=(qeu snapshot)
==
::
++ move (pair bone card)
++ card
$% [%hiss wire (unit user:eyre) mark %hiss hiss:eyre]
[%wait wire @da]
[%rest @da]
[%info wire desk nori:clay]
[%diff %eth-watcher-update update]
[%quit ~]
==
--
::
|_ [bowl:gall state]
::
++ prep
|= old=(unit state)
?~ old
[~ ..prep]
[~ ..prep(+<+ u.old)]
::
++ poke-noun
|= [what=?(%save %load) =name]
^- (quip move _+>)
=+ eye=(fall (~(get by eyes) name) *eye)
?- what
%save
=/ pax=path
/(scot %p our)/home/(scot %da now)/watcher/[name]/jam
:_ +>.$
:_ ~
^- move
:* ost
%info
/jamfile
(foal:space:userlib pax [%jam !>((jam eye))])
==
::
%load
=. eyes
%+ ~(put by eyes) name
=- (^eye (cue .^(@ %cx -)))
/(scot %p our)/home/(scot %da now)/watcher/[name]/jam
done:new-filter:(open:watcher name)
==
::
++ poke-eth-watcher-action
|= act=action
^- (quip move _+>)
?- -.act
%watch
done:(init:watcher +.act)
::
%clear
wipe:(open:watcher +.act)
==
::
++ peek-x
|= pax=path
^- (unit (unit [%noun *]))
?. ?=([@ *] pax) ~
=+ eye=(~(get by eyes) i.pax)
?~ eye [~ ~]
:: /name: all logs
::
?~ t.pax ``[%noun logs.u.eye]
:: /name/num: most recent num logs
::
=+ num=(slaw %ud i.t.pax)
?^ num ``[%noun (scag u.num logs.u.eye)]
:: /name/debug: debug information
::
?. ?=(%debug i.t.pax) ~
=- ``[%noun -]
=, u.eye
:* node=(en-purl:html node)
last=last-heard-block
lent=(lent logs)
time=poll-timer
==
::
++ peer
|= pax=path
^- (quip move _+>)
?> ?=([@ ~] pax)
done:(put-snapshot-diff:(open:watcher i.pax) ost)
::
++ wake
|= [wir=wire ~]
^- (quip move _+>)
?> ?=([@ %poll ~] wir)
done:poll-filter:(open:watcher i.wir)
::
++ sigh-tang
|= [wir=wire res=tang]
^- (quip move _+>)
~& ['something went wrong!' wir]
~_ res
[~ +>.$]
::
++ sigh-json-rpc-response
|= [wir=wire res=response:rpc:jstd]
^- (quip move _+>)
?> ?=([@ *] wir)
=< done
%- sigh-json-rpc-response:(open:watcher i.wir)
[t.wir res]
::
++ watcher
|_ $: =name
=eye
rewind-block=(unit @ud)
new-logs=loglist
moves=(list move)
==
::
:: +open: initialize core
::
++ open
|= nom=^name
^+ +>
+>.$(name nom, eye (~(got by eyes) nom))
::
:: +init: set up eye and initialize core
::
++ init
|= [nom=^name =config]
^+ +>
=. name nom
=. eye
%*(. *^eye - config, last-heard-block from-block.config)
get-latest-block
::
:: +| outward
::
:: +wipe: delete eye
::
++ wipe
=> cancel-wait-poll
=> cancel-subscribers
:- (flop moves)
..watcher(eyes (~(del by eyes) name))
::
:: +done: store changes, update subscribers
::
++ done
^- [(list move) _..watcher]
=? . ?=(^ rewind-block)
:: if we're rewinding to a block, then we throw away any moves
:: and changes we were going to make.
::
=: moves *(list move)
new-logs *loglist
==
(restore-block u.rewind-block)
:: if we have any updates, send them
::
=? . !=(~ new-logs)
(fan-diff %logs new-logs)
:: produce moves, store updated state
::
:- (flop moves)
..watcher(eyes (~(put by eyes) name eye))
::
:: +put-move: store side-effect
::
++ put-move
|= =card
%_(+> moves [[ost card] moves])
::
++ put-moves
|= moz=(list move)
%_(+> moves (weld (flop moz) moves))
::
:: +put-rpc-request: store rpc request to ethereum node
::
++ put-rpc-request
|= [wir=wire id=(unit @t) req=request]
^+ +>
%- put-move
^- card
:* %hiss
[name wir]
~
%json-rpc-response
%hiss
%+ json-request node.eye
(request-to-json id req)
==
::
:: +put-log: store change made by event
::
++ put-log
|= log=event-log
%_ +>
new-logs (store-new-logs ~[log] new-logs)
logs.eye (store-new-logs ~[log] logs.eye)
heard.eye (~(put in heard.eye) (log-to-id log))
==
::
:: +| subscriptions
::
++ put-diff
|= [for=bone dif=update]
%_(+> moves [[for %diff %eth-watcher-update dif] moves])
::
++ put-snapshot-diff
|= for=bone
(put-diff for %snap last-heard-block.eye heard.eye logs.eye)
::
++ get-subscribers
^- (list bone)
%+ murn ~(tap by sup)
|= [b=bone s=ship p=path]
^- (unit bone)
?> ?=([@ *] p)
?:(=(name i.p) `b ~)
::
++ fan-diff
|= dif=update
%- put-moves
%+ turn get-subscribers
|= b=bone
^- move
[b %diff %eth-watcher-update dif]
::
++ cancel-subscribers
%- put-moves
%+ turn get-subscribers
|=(b=bone [b %quit ~])
::
:: +| catch-up-operations
::
:: +get-latest-block
::
:: Get latest block from eth node and compare to our own latest block.
:: Get intervening blocks in chunks until we're caught up, then set
:: up a filter going forward.
::
++ get-latest-block
=> cancel-wait-poll
(put-rpc-request /catch-up/block-number `'block number' %eth-block-number ~)
::
:: +catch-up: get next chunk
::
++ catch-up
|= from-block=@ud
^+ +>
?: (gte from-block latest-block.eye)
new-filter
=/ next-block (min latest-block.eye (add from-block 5.760)) :: ~d1
~? debug=|
[%catching-up from=from-block to=latest-block.eye]
%- put-rpc-request
:+ /catch-up/step/(scot %ud from-block)/(scot %ud next-block)
`'catch up'
:* %eth-get-logs
`number+from-block
`number+next-block
contracts.eye
topics.eye
==
::
:: +| filter-operations
::
:: +new-filter: request a new polling filter
::
:: Listens from the last-heard block onward.
::
++ new-filter
%- put-rpc-request
:+ /filter/new `'new filter'
^- request:rpc
:* %eth-new-filter
`number+last-heard-block.eye
?~(to-block.eye ~ `number+u.to-block.eye)
contracts.eye
topics.eye
==
::
:: +read-filter: get all events the filter captures
::
++ read-filter
%- put-rpc-request
:+ /filter/logs `'filter logs'
[%eth-get-filter-logs filter-id.eye]
::
:: +poll-filter: get all new events since last poll (or filter creation)
::
++ poll-filter
?: =(0 filter-id.eye)
~& %no-filter-bad-poll
.
%- put-rpc-request
:+ /filter/changes `'poll filter'
[%eth-get-filter-changes filter-id.eye]
::
:: +wait-poll: remind us to poll in four minutes
::
:: Four minutes because Ethereum RPC filters time out after five.
:: We don't check for an existing timer or clear an old one here,
:: sane flows shouldn't see this being called superfluously.
::
++ wait-poll
=+ wen=(add now ~m4)
%- put-move(poll-timer.eye `wen)
[%wait name^/poll wen]
::
:: +cancel-wait-poll: remove poll reminder
::
++ cancel-wait-poll
?~ poll-timer.eye ..cancel-wait-poll
%- put-move(poll-timer.eye ~)
[%rest u.poll-timer.eye]
::
:: +| filter-results
::
:: +sigh-json-rpc-response: process rpc response
::
++ sigh-json-rpc-response
|= [wir=wire res=response:rpc:jstd]
^+ +>
~! -.res
?: ?=(%fail -.res)
?: =(405 p.hit.res)
~& 'HTTP 405 error (expected if using infura)'
+>.$
?. =(5 (div p.hit.res 100))
~& [%http-error hit.res]
+>.$
?+ wir
~& [%retrying-node ~] ::((soft tang) q.res)]
wait-poll
[%catch-up %step @ta @ta ~]
~& %retrying-catch-up
(catch-up (slav %ud `@ta`i.t.t.wir))
==
?+ wir ~|([%weird-sigh-wire wir] !!)
[%filter %new *]
(take-new-filter res)
::
[%filter *]
(take-filter-results res)
::
[%catch-up %block-number ~]
(take-block-number res)
::
[%catch-up %step @ta @ta ~]
=/ from-block (slav %ud `@ta`i.t.t.wir)
=/ next-block (slav %ud `@ta`i.t.t.t.wir)
(take-catch-up-step res from-block next-block)
==
::
:: +take-new-filter: store filter-id and read it
::
++ take-new-filter
|= rep=response:rpc:jstd
^+ +>
~| rep
?< ?=(%batch -.rep)
?< ?=(%fail -.rep)
?: ?=(%error -.rep)
~& [%filter-error--retrying message.rep]
new-filter
=- read-filter(filter-id.eye -)
(parse-eth-new-filter-res res.rep)
::
:: +take-filter-results: parse results into event-logs and process them
::
++ take-filter-results
|= rep=response:rpc:jstd
^+ +>
?< ?=(%batch -.rep)
?< ?=(%fail -.rep)
?: ?=(%error -.rep)
?. ?| =('filter not found' message.rep) :: geth
=('Filter not found' message.rep) :: parity
==
~& [%unhandled-filter-error +.rep]
+>
~& [%filter-timed-out--recreating block=last-heard-block.eye +.rep]
:: arguably should rewind 40 blocks on the off chance the chain reorganized
:: when we blinked. this will also restart the filter.
::
:: (restore-block ?:((lth last-heard-block 40) 0 (sub.add last-heard-block 40)))
::
:: counter-argument: it's a royal pain to restore from a snapshot
:: every time you can't ping the node for 5 minutes. this is likely
:: to destabilize the network. better to manually restore if we
:: notice an anomaly.
::
:: third way: don't trust anything that doesn't have 40 confirmations
::
new-filter
:: kick polling timer, only if it hasn't already been.
=? +> |(?=(~ poll-timer.eye) (gth now u.poll-timer.eye))
wait-poll
(take-events rep)
::
:: +take-block-number: take block number and start catching up
::
++ take-block-number
|= rep=response:rpc:jstd
^+ +>
?< ?=(%batch -.rep)
?< ?=(%fail -.rep)
?: ?=(%error -.rep)
~& [%take-block-number-error--retrying message.rep]
get-latest-block
=. latest-block.eye (parse-eth-block-number res.rep)
(catch-up last-heard-block.eye)
::
:: +take-catch-up-step: process chunk
::
++ take-catch-up-step
|= [rep=response:rpc:jstd from-block=@ud next-block=@ud]
^+ +>
?< ?=(%batch -.rep)
?< ?=(%fail -.rep)
?: ?=(%error -.rep)
~& [%catch-up-step-error--retrying message.rep]
(catch-up from-block)
=. +>.$ (take-events rep)
(catch-up next-block)
::
:: +take-events: process events
::
++ take-events
|= rep=response:rpc:jstd
^+ +>
?< ?=(%batch -.rep)
?< ?=(%fail -.rep)
?< ?=(%error -.rep)
?. ?=(%a -.res.rep)
~& [%events-not-array rep]
!!
=* changes p.res.rep
~? &(debug=| (gth (lent changes) 0))
:* %processing-changes
changes=(lent changes)
block=last-heard-block.eye
id=filter-id.eye
==
|- ^+ +>.^$
?~ changes +>.^$
=. +>.^$
(take-event-log (parse-event-log i.changes))
$(changes t.changes)
::
:: +take-event-log: obtain changes from event-log
::
++ take-event-log
|= log=event-log
^+ +>
?~ mined.log
~& %ignoring-unmined-event
+>
=* place u.mined.log
?: (~(has in heard.eye) block-number.place log-index.place)
?. removed.u.mined.log
~? debug=|
[%ignoring-duplicate-event tx=transaction-hash.u.mined.log]
+>
:: block was reorganized away, so rewind to this block and
:: start syncing again.
::
~& :* 'removed event! Perhaps chain has reorganized?'
tx-hash=transaction-hash.u.mined.log
block-number=block-number.u.mined.log
block-hash=block-hash.u.mined.log
==
%= +>
rewind-block
:- ~
?~ rewind-block
block-number.place
(min block-number.place u.rewind-block)
==
=. last-heard-block.eye
(max block-number.place last-heard-block.eye)
?: ?& (gte block-number.place from-block.eye)
?| ?=(~ to-block.eye)
(lte block-number.place u.to-block.eye)
==
==
(put-log log)
~& :* %event-block-out-of-range
got=block-number.place
from=from-block.eye
to=to-block.eye
==
+>.$
::
:: +restore-block: rewind to block or earlier
::
++ restore-block
|= block=@ud
^+ +>
=/ old-qeu snaps.sap.eye
:: clear history
::
=: snaps.sap.eye ~
count.sap.eye 0
latest-block.sap.eye 0
==
:: find a snapshot we can use, remove ones that are too new
::
=^ snap=snapshot +>.$
?: |(=(~ old-qeu) (lth block last-heard-block:(need ~(top to old-qeu))))
[%*(. *snapshot last-heard-block from-block.eye) +>.$]
|- ^- [snapshot _+>.^$]
=^ snap=snapshot old-qeu
~(get to old-qeu)
=: count.sap.eye +(count.sap.eye)
latest-block.sap.eye last-heard-block.snap
snaps.sap.eye (~(put to snaps.sap.eye) snap)
==
?: |(=(~ old-qeu) (lth block last-heard-block:(need ~(top to old-qeu))))
[snap +>.^$]
$
~& [%restoring-block block last-heard-block.snap]
(restore-snap snap)
::
:: +restore-snap: revert state to snapshot
::
++ restore-snap
|= snap=snapshot
^+ +>
:: notify subscribers
::TODO be more nuanced about what changed, maybe
::
=. +>.$ (fan-diff snap+snap)
:: restore state and kick new fetch cycle
::
%= get-latest-block
last-heard-block.eye last-heard-block.snap
heard.eye heard.snap
logs.eye logs.snap
==
--
--

View File

@ -169,6 +169,7 @@
++ poke-helm-tlon-init-stream (wrap poke-tlon-init-stream):from-helm
++ poke-helm-automass (wrap poke-automass):from-helm
++ poke-helm-cancel-automass (wrap poke-cancel-automass):from-helm
++ poke-helm-bonk (wrap poke-bonk):from-helm
++ poke-hood-sync (wrap poke-sync):from-kiln
++ poke-kiln-commit (wrap poke-commit):from-kiln
++ poke-kiln-info (wrap poke-info):from-kiln

269
app/tiebout.hoon Normal file
View File

@ -0,0 +1,269 @@
/- hall, tiebout
=, tiebout
=, eyre
|%
+$ move [bone card]
::
+$ card
$% [%poke wire dock poke]
[%peer wire dock path]
[%pull wire dock ~]
[%diff diff]
[%hiss wire [~ ~] %httr %hiss hiss]
==
::
+$ diff
$% [%hall-rumor rumor:hall]
[%tiebout-action action]
==
::
+$ poke
$% [%tiebout-action action]
==
::
+$ state
$% [%0 tiebout-zero]
==
::
+$ tiebout-zero
$:
:: iOS device token
::
token=@t
:: ship that routes notifications to Apple
::
king=@p
:: url of Apple server to send notifications to
::
baseurl=@t
:: name and last read
::
circles=(map name:hall @)
==
::
--
::
:: state:
::
|_ [bol=bowl:gall sta=state]
::
:: +this: app core subject
::
++ this .
::
:: +prep: set up app state, upgrade app state
::
++ prep
|= old=(unit state)
^- (quip move _this)
?~ old
:- ~
%= this
king.sta ~dabben-larbet
baseurl.sta 'https://api.push.apple.com/3/device/'
==
?- -.u.old
%0
[~ this(sta u.old)]
==
::
:: +coup: receive acknowledgement for poke, print error if it failed
::
++ coup
|= [wir=wire err=(unit tang)]
^- (quip move _this)
?~ err
[~ this]
(mean u.err)
::
:: +poke-noun: receive debugging actions
::
++ poke-noun
|= act=action
^- (quip move _this)
(poke-tiebout-action act)
::
:: +poke-tiebout-action: main action handler
::
++ poke-tiebout-action
|= act=action
^- (quip move _this)
?- -.act
$king (set-king +.act)
$token (set-token +.act)
$baseurl (set-baseurl +.act)
$add-circle (add-circle +.act)
$del-circle (del-circle +.act)
$notify (send-notify +.act)
==
::
:: +add-circle: add circle and subscribe for updates
::
++ add-circle
|= nom=name:hall
^- (quip move _this)
:_ this(circles.sta (~(put by circles.sta) nom 0))
[ost.bol %peer /our/[nom] [our.bol %hall] /circle/[nom]/config/grams]~
::
:: +del-circle: delete circle and unsubscribe from updates
::
++ del-circle
|= nom=name:hall
^- (quip move _this)
:_ this(circles.sta (~(del by circles.sta) nom))
[ost.bol %pull /our/[nom] [our.bol %hall] ~]~
::
:: +set-king: set king @p
::
++ set-king
|= kng=@p
^- (quip move _this)
[~ this(king.sta kng)]
::
:: +set-token: set iOS device token @t
::
++ set-token
|= tok=@t
^- (quip move _this)
[~ this(token.sta tok)]
::
:: +set-baseurl: set base url @t
::
++ set-baseurl
|= burl=@t
^- (quip move _this)
[~ this(baseurl.sta burl)]
::
:: +send-notify: if king, send hiss. if not, do nothing.
::
++ send-notify
|= not=notification
^- (quip move _this)
?: =(king.sta our.bol)
:_ this
[ost.bol %hiss /request [~ ~] %httr %hiss (create-apns-request not)]~
[~ this]
::
:: +diff-hall-prize: receive new circle data
::
++ diff-hall-prize
|= [wir=wire piz=prize:hall]
^- (quip move _this)
?+ wir
(mean [leaf+"invalid wire for diff: {(spud wir)}"]~)
::
:: %our: set config of circle and iterate through messages, sending
:: notifications for all messages where number is higher than our last-read
::
{%our @ @}
?> ?=(%circle -.piz)
=/ nom/name:hall i.t.wir
=/ red/@ud red.loc.cos.piz
[~ this(circles.sta (~(put by circles.sta) nom red))]
==
::
:: +reap: recieve acknowledgement for peer
::
++ reap
|= [wir=wire err=(unit tang)]
^- (quip move _this)
?~ err
[~ this]
?+ wir
(mean [leaf+"invalid wire for diff: {(spud wir)}"]~)
::
{%our @ @}
?< ?=(~ t.wir)
[~ this]
==
::
:: +quit: receive subscription failed, resubscribe
::
++ quit
|= wir=wire
^- (quip move _this)
?+ wir
(mean [leaf+"invalid wire for diff: {(spud wir)}"]~)
::
{%our @ @}
?< ?=(~ t.wir)
:_ this
=/ doc/dock [our.bol %hall]
[ost.bol %peer /our/[i.t.wir] doc /circle/[i.t.wir]/config/grams]~
==
::
:: +diff-hall-rumor: receive message or a read event from a hall circle
::
++ diff-hall-rumor
|= [wir=wire rum=rumor:hall]
^- (quip move _this)
?+ wir
(mean [leaf+"invalid wire for diff: {(spud wir)}"]~)
::
:: %our
::
{%our @ @}
?> ?=(%circle -.rum)
=/ nom/name:hall i.t.wir
?+ -.rum.rum
[~ this]
::
:: %gram: send notification if envelope is lower than read number
::
%gram
=/ red (~(get by circles.sta) nom)
?~ red
(mean [leaf+"invalid circle for diff: {(spud wir)}"]~)
?: (gth num.nev.rum.rum u.red)
:_ this(circles.sta (~(put by circles.sta) nom u.red))
(conditional-msg-to-not u.red nev.rum.rum)
:_ this
(conditional-msg-to-not u.red nev.rum.rum)
::
:: %config: set our read number
::
%config
?+ -.dif.rum.rum
[~ this]
::
%read
[~ this(circles.sta (~(put by circles.sta) nom red.dif.rum.rum))]
==
==
==
::
:: generate notification move from hall message if conditions are met
::
++ conditional-msg-to-not
|= [red=@ud env=envelope:hall]
^- (list move)
?: =(aut.gam.env our.bol)
~
=/ pay %- my :~
alert+s+'New message from {(cite:title aut.gam.env)}'
==
=/ not/notification [token.sta 'com.tlon.urbit-client' pay]
?: (lte num.env red)
~
=/ doc/dock [king.sta dap.bol]
[ost.bol %poke /ask-king doc %tiebout-action [%notify not]]~
::
:: +create-apns-request: create hiss with payload for APNs
::
++ create-apns-request
|= not=notification
^- hiss
=/ furl=@t (crip (weld (trip baseurl.sta) (trip token.not)))
=/ url=purl (need (de-purl:html furl))
=/ jon=json :- %o
%- my :~
aps+o+payload.not
==
:^ url %post
%- my :~
apns-topic+[topic.not ~] :: generate map from raw noun
==
(some (as-octt:mimes:html (en-json:html jon)))
--

7
gen/hood/bonk.hoon Normal file
View File

@ -0,0 +1,7 @@
:: Helm: bonk ames
::
:::: /hoon/bonk/hood/gen
::
/? 310
:- %say
|=({^ ~ ~} helm-bonk+~)

View File

@ -5,35 +5,89 @@
::
=+ [pad=& url=|]
|%
::
+$ byte @D
+$ word24 @
::
++ div-ceil
:: divide, rounding up.
|= [x=@ y=@] ^- @
?: =(0 (mod x y))
(div x y)
+((div x y))
::
++ explode-bytes
:: Explode a bytestring into list of bytes. Result is in LSB order.
|= =octs ^- (list byte)
=/ atom-byte-width (met 3 q.octs)
=/ leading-zeros (sub p.octs atom-byte-width)
(weld (reap leading-zeros 0) (rip 3 q.octs))
::
++ explode-words
:: Explode a bytestring to words of bit-width `wid`. Result is in LSW order.
|= [wid=@ =octs]
^- (list @)
=/ atom-bit-width (met 0 q.octs)
=/ octs-bit-width (mul 8 p.octs)
=/ atom-word-width (div-ceil atom-bit-width wid)
=/ rslt-word-width (div-ceil octs-bit-width wid)
=/ pad (sub rslt-word-width atom-word-width)
=/ x (ripn wid q.octs)
%+ weld x
(reap pad 0)
::
:: +en:base64: encode +octs to base64 cord
::
:: Encode an `octs` into a base64 string.
::
:: First, we break up the input into a list of 24-bit words. The input
:: might not be a multiple of 24-bits, so we add 0-2 padding bytes at
:: the end (to the least-significant side, with a left-shift).
::
:: Then, we encode each block into four base64 characters.
::
:: Finally we remove the padding that we added at the beginning: for
:: each byte that was added, we replace one character with an = (unless
:: `pad` is false, in which case we just remove the extra characters).
::
++ en
|= inp=octs
^- cord
:: dif: offset from 3-byte block
^- $-(octs cord)
::
=/ dif=@ud (~(dif fo 3) 0 p.inp)
:: dap: reversed, 3-byte block-aligned input
::
=/ dap=@ux (lsh 3 dif (rev 3 inp))
=/ cha
?: url
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
%- crip
%- flop
%+ weld
?.(pad ~ (reap dif '='))
%+ slag dif
|- ^- tape
?: =(0x0 dap) ~
=/ d (end 3 3 dap)
:* (cut 3 [(cut 0 [0 6] d) 1] cha)
(cut 3 [(cut 0 [6 6] d) 1] cha)
(cut 3 [(cut 0 [12 6] d) 1] cha)
(cut 3 [(cut 0 [18 6] d) 1] cha)
$(dap (rsh 3 3 dap))
==
::
|^ |= bs=octs ^- cord
=+ ^- [padding=@ blocks=(list word24)]
(octs-to-blocks bs)
(crip (flop (unpad padding (encode-blocks blocks))))
::
++ octs-to-blocks
|= bs=octs ^- [padding=@ud (list word24)]
=/ padding=@ud (~(dif fo 3) 0 p.bs)
=/ padded=octs [(add padding p.bs) (lsh 3 padding (rev 3 bs))]
[padding (explode-words 24 padded)]
::
++ unpad
|= [extra=@ t=tape] ^- tape
=/ without (slag extra t)
?. pad without
(weld (reap extra '=') without)
::
++ encode-blocks
|= ws=(list word24) ^- tape
(zing (turn ws encode-block))
::
++ encode-block
|= w=word24 ^- tape
=/ a (cut 3 [(cut 0 [0 6] w) 1] cha)
=/ b (cut 3 [(cut 0 [6 6] w) 1] cha)
=/ c (cut 3 [(cut 0 [12 6] w) 1] cha)
=/ d (cut 3 [(cut 0 [18 6] w) 1] cha)
~[a b c d]
--
::
:: +de:base64: decode base64 cord to (unit @)
::
++ de

38
lib/eth-watcher.hoon Normal file
View File

@ -0,0 +1,38 @@
:: eth-watcher utilities
::
/- *eth-watcher
::
|%
:: +log-to-id: extract the event-id from an event-log
::
++ log-to-id
|= log=event-log:rpc:ethereum
^- event-id:ethereum
?> ?=(^ mined.log)
:- block-number.u.mined.log
log-index.u.mined.log
::
:: +store-new-logs: add logs to an old loglist, ensuring newest-first ordering
::
:: assumes :new is already ordered newest-first
::
++ store-new-logs
|= [new=loglist old=loglist]
^- loglist
?~ new old
=+ new-place=(log-to-id i.new)
|-
?~ old [i.new old]
=+ old-place=(log-to-id i.old)
:: if the :old-place is older than :new-place,
:: put :new-place down, and grab the next one from :new
:: otherwise, keep looking through :old
::
?: ?| (gth block.new-place block.old-place)
?& =(block.new-place block.old-place)
(gth log.new-place log.old-place)
==
==
[i.new ^$(new t.new)]
[i.old $(old t.old)]
--

View File

@ -99,12 +99,12 @@
^- part
:* %drum
%2
~ :: sys
(deft-fish our) :: eel
(deft-apes our) :: ray
~ :: fur
~ :: bin
== ::
sys=~
eel=(deft-fish our)
ray=(deft-apes our)
fur=~
bin=~
==
::
::
++ en-gill :: gill to wire
@ -245,7 +245,9 @@
::
++ se-adit :: update servers
^+ .
%+ roll ~(tap in ray)
:: ensure dojo connects after talk
=* dojo-on-top aor
%+ roll (sort ~(tap in ray) dojo-on-top)
=< .(con +>)
|: $:{wel/well:gall con/_..se-adit} ^+ con
=. +>.$ con

View File

@ -37,7 +37,8 @@
=+ sez=(fall (~(get by hoc) ost) $:session)
=> |% :: arvo structures
++ card ::
$% {$conf wire dock $load ship term} ::
$% [%bonk wire ~] ::
{$conf wire dock $load ship term} ::
{$flog wire flog:dill} ::
[%mint wire our=ship p=ship q=safe:rights:jael]
{$nuke wire ship} ::
@ -106,6 +107,12 @@
|= ~
abet:(emit %rest way.mass-timer.sez nex.mass-timer.sez)
::
++ poke-bonk
|= ~
~& .^((unit @da) %a /(scot %p our)/time/(scot %da now)/(scot %p our))
%- %- slog :_ ~ .^(tank %b /(scot %p our)/timers/(scot %da now))
abet:(emit %bonk /bonk ~)
::
++ take-wake-automass
|= [way=wire ~]
=. nex.mass-timer.sez (add now tim.mass-timer.sez)

View File

@ -15,7 +15,7 @@
;div#root
;+ inner
==
;script@"/~~/landscape/js/index-min.js";
;script@"/~~/landscape/js/index.js";
==
::
==

150
lib/number-to-words.hoon Normal file
View File

@ -0,0 +1,150 @@
:: |number-to-words: conversion of unsigned integers to a tape
::
:: returns a unit because not all numbers can always be represented
::
|%
++ numbers
|%
++ ten 10
++ one-hundred 100
++ one-thousand (pow 10 3)
++ one-million (pow 10 6)
++ one-billion (pow 10 9)
++ one-trillion (pow 10 12)
++ one-quadrillion (pow 10 15)
++ one-quintillion (pow 10 18)
++ one-sextillion (pow 10 21)
++ one-septillion (pow 10 24)
++ one-octillion (pow 10 27)
++ one-nonillion (pow 10 30)
++ one-decillion (pow 10 33)
++ one-undecillion (pow 10 36)
++ one-duodecillion (pow 10 39)
++ one-tredecillion (pow 10 42)
++ one-quattuordecillion (pow 10 45)
++ one-quindecillion (pow 10 48)
++ one-sexdecillion (pow 10 51)
++ one-septendecillion (pow 10 54)
++ one-octodecillion (pow 10 57)
++ one-novemdecillion (pow 10 60)
++ one-vigintillion (pow 10 63)
++ max (pow 10 66)
--
++ eng-us
|%
++ to-words
|= num=@u
^- (unit tape)
=+ numbers
?: (gte num max)
~
:- ~
|-
^- tape
:: 0-19
?: =(num 0) "zero"
?: =(num 1) "one"
?: =(num 2) "two"
?: =(num 3) "three"
?: =(num 4) "four"
?: =(num 5) "five"
?: =(num 6) "six"
?: =(num 7) "seven"
?: =(num 8) "eight"
?: =(num 9) "nine"
?: =(num 10) "ten"
?: =(num 11) "eleven"
?: =(num 12) "twelve"
?: =(num 13) "thirteen"
?: =(num 14) "fourteen"
?: =(num 15) "fifteen"
?: =(num 16) "sixteen"
?: =(num 17) "seventeen"
?: =(num 18) "eighteen"
?: =(num 19) "nineteen"
:: 20-99
::
:: tpl: tens place
:: rem: ones place
:: sfx: suffix
::
=/ tpl (div num ten)
=/ rem (mod num ten)
=/ sfx
?: |(=(rem 0) (gte tpl 10))
~
['-' $(num rem)]
?: =(tpl 2) (weld "twenty" sfx)
?: =(tpl 3) (weld "thirty" sfx)
?: =(tpl 4) (weld "forty" sfx)
?: =(tpl 5) (weld "fifty" sfx)
?: =(tpl 6) (weld "sixty" sfx)
?: =(tpl 7) (weld "seventy" sfx)
?: =(tpl 8) (weld "eighty" sfx)
?: =(tpl 9) (weld "ninety" sfx)
:: 100-max
::
:: num-break: repeated pattern from 100 on
::
=/ num-break
::
:: min: minimum to qualify for this break
:: str: english word for this break
::
|= [min=@u str=tape]
=/ rem (mod num min)
;: weld
^$(num (div num min))
[' ' str]
?: =(rem 0)
~
%+ weld
?:((lth rem one-hundred) " and " ", ")
^$(num rem)
==
::
?: (lth num one-thousand)
(num-break one-hundred "hundred")
?: (lth num one-million)
(num-break one-thousand "thousand")
?: (lth num one-billion)
(num-break one-million "million")
?: (lth num one-trillion)
(num-break one-billion "billion")
?: (lth num one-quadrillion)
(num-break one-trillion "trillion")
?: (lth num one-quintillion)
(num-break one-quadrillion "quadrillion")
?: (lth num one-sextillion)
(num-break one-quintillion "quintillion")
?: (lth num one-septillion)
(num-break one-sextillion "sextillion")
?: (lth num one-octillion)
(num-break one-septillion "septillion")
?: (lth num one-nonillion)
(num-break one-octillion "octillion")
?: (lth num one-decillion)
(num-break one-nonillion "nonillion")
?: (lth num one-undecillion)
(num-break one-decillion "decillion")
?: (lth num one-duodecillion)
(num-break one-undecillion "undecillion")
?: (lth num one-tredecillion)
(num-break one-duodecillion "duodecillion")
?: (lth num one-quattuordecillion)
(num-break one-tredecillion "tredecillion")
?: (lth num one-quindecillion)
(num-break one-quattuordecillion "quattuordecillion")
?: (lth num one-sexdecillion)
(num-break one-quindecillion "quindecillion")
?: (lth num one-septendecillion)
(num-break one-sexdecillion "sexdecillion")
?: (lth num one-octodecillion)
(num-break one-septendecillion "septendecillion")
?: (lth num one-novemdecillion)
(num-break one-octodecillion "octodecillion")
?: (lth num one-vigintillion)
(num-break one-novemdecillion "novemdecillion")
(num-break one-vigintillion "vigintillion")
--
--

View File

@ -0,0 +1,7 @@
/- *eth-watcher
|_ act=action
++ grab
|%
++ noun action
--
--

View File

@ -0,0 +1,7 @@
/- *eth-watcher
|_ upd=update
++ grab
|%
++ noun update
--
--

View File

@ -44,6 +44,7 @@
%- of :~
stdout+none
output-file+so
output-pill+so
output-clay+(su (easy /sentinel/path))
url+(su auri:de-purl:html)
to-api+(su ;~(plug sym ;~(pfix col prn)))

View File

@ -3,6 +3,8 @@
::
/? 310
/- sole
/+ base64
!:
::
::::
::
@ -53,6 +55,11 @@
?+ -.sef ~
$tan (wall (turn (flop p.sef) |=(a/tank ~(ram re a))))
$txt s+(crip p.sef)
$sag
=/ =atom (jam q.sef)
=/ =octs [(met 3 atom) atom]
=/ enc (en:base64 octs)
(pairs file+s+(crip <`path`p.sef>) data+s+enc ~)
$sav
(pairs file+s+(crip <`path`p.sef>) data+s+(crip (en-base64:mimes:html q.sef)) ~)
::

33
mar/tiebout-action.hoon Normal file
View File

@ -0,0 +1,33 @@
/- hall, tiebout
=, format
::
|_ act=action:tiebout
::
++ grow
|%
++ tank >act<
--
::
++ grab
|%
++ noun action:tiebout
++ json
|= jon=^json
^- action:tiebout
=< (action jon)
|%
++ action
%- of:dejs
:~ token+so:dejs
add-circle+sa
del-circle+sa
==
++ sa :: string as ta
|= jon=^json
?> ?=([%s *] jon)
(scot %tas p.jon)
--
--
::
--

39
sur/eth-watcher.hoon Normal file
View File

@ -0,0 +1,39 @@
:: watcher: ethereum event log collector
::
|%
++ name @tas
::
++ config
$: node=purl:eyre
from-block=@ud
to-block=(unit @ud)
contracts=(list address:ethereum)
topics=(list $@(@ux (list @ux)))
==
::
++ action
$% [%watch =name =config]
::TODO support modifying existing config for future polling
[%clear =name]
==
::
++ update
$% :: %snap: all known-good logs, sent on-subscribe and on-reorg
::TODO there's probably a way to be more nuanced about what we forgot
:: to cope with a reorg
::
[%snap =snapshot]
:: %vent: newly added logs
::
[%logs =loglist]
==
::
++ snapshot
$: last-heard-block=@ud
heard=(set event-id:ethereum)
logs=loglist
==
::
++ loglist
(list event-log:rpc:ethereum) :: newest first
--

View File

@ -19,6 +19,7 @@
++ sink
$% {$stdout ~}
{$output-file pax/@t}
{$output-pill pax/@t}
{$output-clay pax/path}
{$url url/purl:eyre}
{$to-api api/term command/@t}

21
sur/tiebout.hoon Normal file
View File

@ -0,0 +1,21 @@
/- hall
=, eyre
::
::
|%
+$ notification
$: token=@t
topic=@t
payload=(map @t json)
==
::
+$ action
$% [%token tok=@t] :: set device token
[%king kng=@p] :: set ship to route notifications through
[%baseurl bur=@t] :: set url to send notifications to
[%notify not=notification] :: send notification
[%add-circle nom=name:hall] :: send notifications for this circle
[%del-circle nom=name:hall] :: stop sending for this circle
==
::
--

View File

@ -51,7 +51,7 @@
++ mill (each vase milt) :: vase+metavase
++ milt {p/* q/*} :: metavase
++ monk (each ship {p/@tas q/@ta}) :: general identity
++ muse {p/@tas q/duct r/arvo} :: sourced move
++ muse {p/@tas q/duct r/arvo s/@ud} :: sourced move
++ move {p/duct q/arvo} :: arvo move
++ ovum {p/wire q/curd} :: typeless ovum
++ pane (list {p/@tas q/vase}) :: kernel modules
@ -473,7 +473,7 @@
::
++ hurl :: start loop
|= {lac/? ovo/ovum}
~? &(!lac !=(%belt -.q.ovo)) [%unix -.q.ovo p.ovo]
~? &(!lac !=(%belt -.q.ovo)) ["" %unix -.q.ovo p.ovo]
:: ^- {p/(list ovum) q/(pair worm (list {p/@tas q/vase}))}
^- {p/(list ovum) q=(list [label=@tas =vane])}
?> ?=(^ p.ovo)
@ -485,6 +485,7 @@
:+ %&
[%cell [%atom %tas `%soft] %noun]
[%soft q.ovo]
0
==
==
::
@ -497,7 +498,7 @@
(swim:win org pux hen hil)
::
++ fire :: execute
|= {org/term lal/term pux/(unit wire) hen/duct hil/mill}
|= {org/term deh/@ud lal/term pux/(unit wire) hen/duct hil/mill}
^- {{p/(list ovum) q/(list muse)} _vanes}
?: &(?=(^ pux) ?=($~ hen))
[[[[lal u.pux] (curd +>.hil)]~ ~] vanes]
@ -510,7 +511,8 @@
[-.tuh [+<.tuh [i.naf +>.tuh]]]
::
=+ fiq=(race org lal pux hen hil vane.i.naf)
[[~ (turn p.fiq |=(a/move [lal a]))] [[label.i.naf q.fiq] t.naf]]
:- [~ (turn p.fiq |=(a/move [lal p.a q.a +(deh)]))]
[[label.i.naf q.fiq] t.naf]
::
++ jack :: dispatch card
|= {lac/? gum/muse}
@ -518,11 +520,13 @@
~| %failed-jack
:: =. lac |(lac ?=(?(%g %f) p.gum))
:: =. lac &(lac !?=($b p.gum))
%+ fire
p.gum
%^ fire
p.gum
s.gum
?- -.r.gum
$pass
~? &(!lac !=(%$ p.gum))
:- (runt [s.gum '|'] "")
:^ %pass [p.gum p.q.r.gum]
[(symp +>-.q.q.r.gum) p.r.gum]
q.gum
@ -534,11 +538,14 @@
~| [%jack-bad-card p.gum (symp +>-.p.r.gum)]
!!
~? &(!lac |(!=(%blit +>-.p.r.gum) !=(%d p.gum)))
:- (runt [s.gum '|'] "")
[%give p.gum (symp +>-.p.r.gum) `duct`q.gum]
[i.i.q.gum [~ t.i.q.gum] t.q.gum p.r.gum]
::
$slip
~? !lac [%slip p.gum (symp +>-.q.p.r.gum) q.gum]
~? !lac
:- (runt [s.gum '|'] "")
[%slip p.gum (symp +>-.q.p.r.gum) q.gum]
[p.p.r.gum ~ q.gum q.p.r.gum]
==
::
@ -563,7 +570,7 @@
[%soft q.ovo]
%+ kick lac
%+ turn vanes
|=([label=@tas *] [label ~ [%pass p.ovo label card]])
|=([label=@tas *] [label ~ [%pass p.ovo label card] 0])
--
--
=< :: Arvo larval stage
@ -782,11 +789,20 @@
=. q.q.ovo
:- %userspace
:- %|
:~ hoon+`pit
zuse+`bud
:: hoon-cache+`p.niz
:~ hoon+&+pit
zuse+&+bud
:+ %caches %|
%+ turn
%+ sort vanes
|=([a=[lab=@tas *] b=[lab=@tas *]] (aor lab.a lab.b))
|=([label=@tas =vane] [(cat 3 %vane- label) %& worm.vane])
q.q.ovo
dot+`.
:+ %vases %|
%+ turn
%+ sort vanes
|=([a=[lab=@tas *] b=[lab=@tas *]] (aor lab.a lab.b))
|=([label=@tas =vane] [(cat 3 %vane- label) %& vase.vane])
dot+&+.
==
[[~ ovo] +>.$]
:: add entropy
@ -920,4 +936,3 @@
|= txt/@
q:(slap bud (ream txt))
--

View File

@ -956,12 +956,21 @@
(sub len (met boz dat))
(swp boz dat)
::
:: Like `rip` but produces n-bit blocks instead of 2^n bit blocks.
::
++ ripn
~/ %ripn
|= {bits=@ud x=@}
^- (list @)
?: =(0 x) ~
[(end 0 bits x) $(x (rsh 0 bits x))]
::
++ rip :: disassemble
~/ %rip
|= {a/bloq b/@}
|= {=bloq x=@}
^- (list @)
?: =(0 b) ~
[(end a 1 b) $(b (rsh a 1 b))]
?: =(0 x) ~
[(end bloq 1 x) $(x (rsh bloq 1 x))]
::
++ rsh :: right-shift
~/ %rsh
@ -15369,6 +15378,7 @@
{$code p/tape} :: code literal
{$text p/tape} :: text symbol
{$link p/(list graf) q/tape} :: URL
{$mage p/tape q/tape} :: image
{$expr p/tuna:hoot} :: interpolated hoon
==
--
@ -15497,7 +15507,7 @@
[[lin `~] +<.^$]
[[lin ~] eat-newline]
::
++ look :: inspedt line
++ look :: inspect line
^- (unit trig)
%+ bind (wonk (look:parse loc txt))
|= a/trig ^+ a
@ -15856,6 +15866,16 @@
(ifix [lit rit] (cash rit))
==
::
:: ![alt text](url)
::
%+ stag %mage
;~ pfix zap
;~ (glue (punt whit))
(ifix [lac rac] (cash rac))
(ifix [lit rit] (cash rit))
==
==
::
:: #hoon
::
%+ stag %list
@ -15942,6 +15962,7 @@
`(list graf)`[%text (tufa ~-~201d. ~)]~
==
$link [[%a [%href q.nex] ~] ^$(gaf p.nex)]~
$mage [[%img [%src q.nex] ?~(p.nex ~ [%alt p.nex]~)] ~]~
==
--
::

View File

@ -6,7 +6,7 @@
=, ames
:: this number needs to be below 8
::
=+ protocol-version=0
=+ protocol-version=2
|%
+= move [p=duct q=(wind note:able gift:able)] :: local move
:: |pact: internal packet structures
@ -1331,6 +1331,8 @@
::
%pito
:_ fox(tim `p.bon)
%- flop
^- (list move)
:- [gad.fox %pass /ames %b %wait p.bon]
?~ tim.fox ~
[gad.fox %pass /ames %b %rest u.tim.fox]~
@ -1461,6 +1463,13 @@
%barn
:_ fox(gad hen)
[%bock ~]~
::
%bonk
:_ fox
?~ tim.fox
~& %ames-bonk-e
~
[%pito u.tim.fox]~
::
%hear
(~(gnaw am [our now fox ski]) %good p.kyz q.kyz)
@ -1508,7 +1517,14 @@
[[%wine who " has sunk"]~ fox]
::
%vega
[~ fox]
:: re-initialize our cryptosuite B cores
::
=/ =wund
%+ turn
val.ton.fox
|= [=life =ring *]
[life ring (nol:nu:crub:crypto ring)]
[~ fox(val.ton wund)]
::
%wake
(~(wake am [our now fox ski]) hen)
@ -1536,11 +1552,28 @@
?. =(our his)
~
``[%noun !>(pals:~(um am [our now fox ski]))]
?: ?=([%time ~] tyl)
?. =(our his)
~
``[%noun !>(tim.fox)]
~
::
++ wegh
^- mass
:+ %ames %|
:~ dot+&+fox
:~ :+ %town %|
=> ton.fox
:~ wund+&+val
deed+&+law
fast+&+seh
them+&+hoc
==
:+ %corn %|
=> zac.fox
:~ incoming+&+nys
complete+&+olz
neighbor+&+wab
==
dot+&+fox
==
--

View File

@ -25,51 +25,38 @@
|%
:: %entry-points
::
:: +born: handle urbit restart
:: +born: urbit restarted; refresh :next-wake and store wakeup timer duct
::
++ born
^+ [moves state]
:: store this duct for setting unix wakeup timers
::
=. unix-duct.state duct
:: process any elapsed timers and clear and reset :next-wake
::
=> notify-clients
set-wake(next-wake.state ~)
++ born set-unix-wake(next-wake.state ~, unix-duct.state duct)
:: +crud: error report; hand off to %dill to be printed
::
++ crud
|= [p=@tas q=tang]
^+ [moves state]
[[duct %slip %d %flog %crud p q]~ state]
:: +rest: cancel the timer at :date, resetting :next-wake if needed
:: +rest: cancel the timer at :date, then adjust unix wakeup
:: +wait: set a new timer at :date, then adjust unix wakeup
::
++ rest
|= date=@da
^+ [moves state]
::
=. timers.state (unset-timer [date duct])
set-wake
++ rest |=(date=@da set-unix-wake(timers.state (unset-timer [date duct])))
++ wait |=(date=@da set-unix-wake(timers.state (set-timer [date duct])))
:: +vega: learn of a kernel upgrade
::
++ vega
[moves state]
:: +wait: set a new timer at :date, resetting :next-wake if needed
::
++ wait
|= date=@da
^+ [moves state]
:: process elapsed timers first to maintain sort order
::
=. event-core notify-clients
=. timers.state (set-timer [date duct])
set-wake
:: +wake: unix says we should wake up; notify clients and set :next-wake
++ vega [moves state]
:: +wake: unix says wake up; process the elapsed timer and set :next-wake
::
++ wake
^+ [moves state]
=> notify-clients
set-wake(next-wake.state ~)
::
?~ timers.state ~|(%behn-wake-no-timer !!)
:: if unix woke us too early, retry by resetting the unix wakeup timer
::
?: (gth date.i.timers.state now)
~? debug=%.n [%behn-wake-too-soon `@dr`(sub date.i.timers.state now)]
set-unix-wake(next-wake.state ~)
:: pop first timer, tell vane it has elapsed, and adjust next unix wakeup
::
=< set-unix-wake
(emit-vane-wake(timers.state t.timers.state) duct.i.timers.state)
:: +wegh: produce memory usage report for |mass
::
++ wegh
@ -85,28 +72,10 @@
::+|
::
++ event-core .
:: +notify-clients: wake up vanes whose timers have expired
:: +emit-vane-wake: produce a move to wake a vane; assumes no prior moves
::
:: When we return the list moves to clients, we flop them so they're in
:: the same order as they were in :timers.
::
++ notify-clients
=* timers timers.state
|- ^+ event-core
::
?~ timers
=. moves (flop moves)
event-core
::
?: (gth date.i.timers now)
=. moves (flop moves)
event-core
::
%_ $
timers t.timers
moves [[duct.i.timers %give %wake ~] moves]
==
:: +set-wake: set or unset a unix timer to wake us when next timer expires
++ emit-vane-wake |=(=^duct event-core(moves [duct %give %wake ~]~))
:: +emit-doze: set new unix wakeup timer in state and emit move to unix
::
:: We prepend the unix %doze event so that it is handled first. Arvo must
:: handle this first because the moves %behn emits will get handled in
@ -116,30 +85,40 @@
:: back into %behn and emits a second %doze, the second %doze would be
:: handled by unix first which is incorrect.
::
++ set-wake
^+ [moves state]
++ emit-doze
|= =date=(unit @da)
^+ event-core
:: make sure we don't try to wake up in the past
::
=? date-unit ?=(^ date-unit) `(max now u.date-unit)
::
%_ event-core
next-wake.state date-unit
moves [[unix-duct.state %give %doze date-unit] moves]
==
:: +set-unix-wake: set or unset next unix wakeup timer based on :i.timers
::
++ set-unix-wake
=< [moves state]
^+ event-core
::
=* next-wake next-wake.state
=* timers timers.state
=* unix-duct unix-duct.state
:: if no timers, cancel existing wakeup timer or no-op
::
?~ timers
?~ next-wake
[moves state]
:_ state(next-wake ~)
[[unix-duct %give %doze ~] moves]
event-core
(emit-doze ~)
:: if :next-wake is in the past or not soon enough, reset it
::
?^ next-wake
?: &((gte date.i.timers u.next-wake) (lte now u.next-wake))
[moves state]
:_ state(next-wake `date.i.timers)
[[unix-duct %give %doze `date.i.timers] moves]
event-core
(emit-doze `date.i.timers)
:: there was no unix wakeup timer; set one
::
:_ state(next-wake `date.i.timers)
[[unix-duct %give %doze `date.i.timers] moves]
(emit-doze `date.i.timers)
:: +set-timer: set a timer, maintaining the sort order of the :timers list
::
++ set-timer
@ -152,6 +131,7 @@
:: ignore duplicates
::
?: =(t i.timers)
~? debug=%.n [%behn-set-duplicate t]
timers
:: timers at the same date form a fifo queue
::
@ -163,11 +143,12 @@
::
++ unset-timer
=* timers timers.state
|= [t=timer]
|= t=timer
^+ timers
:: if we don't have this timer, no-op; for debugging, add a printf here
:: if we don't have this timer, no-op
::
?~ timers
~? debug=%.n [%behn-unset-missing t]
~
?: =(i.timers t)
t.timers

View File

@ -1757,7 +1757,9 @@
:* hen %pass
[%foreign-x (scot %p our) (scot %p her) syd car (scot cas) pax]
%f %build live=%.n %pin
(case-to-date cas)
:: See ++validate-plops to explain why it's not (case-to-date cas)
::
now
(vale-page [her syd] peg)
==
::
@ -1868,7 +1870,14 @@
%- emit
:* hen %pass
[%foreign-plops (scot %p our) (scot %p her) syd lum ~]
%f %build live=%.n %pin (case-to-date cas)
%f %build live=%.n %pin
:: This corresponds to all the changes from [her syd]
:: to [our %home]. This should be (case-to-date cas)
:: in the context of the foreign desk, but since we're
:: getting everything from our own desk now we want to
:: use our most recent commit.
::
now
%list
^- (list schematic:ford)
%+ turn ~(tap in pop)

View File

@ -1297,6 +1297,7 @@
^- (unit @tas)
?+ sep ~& [%ap-vain sep]
~
$bonk `%a
$build `%f
$cash `%a
$conf `%g

View File

@ -2141,7 +2141,7 @@
==
=+ cuz=[block-number.place log-index.place]
::
?: =(event.log changed-dns:azimuth-events)
?: =(i.topics.log changed-dns:azimuth-events)
=+ ^- [pri=tape sec=tape ter=tape]
%+ decode-results data.log
~[%string %string %string]

View File

@ -355,6 +355,7 @@
== == == ::
++ task :: in request ->$
$% {$barn ~} :: new unix process
{$bonk ~} :: reset the timer
{$crud p/@tas q/(list tank)} :: error with trace
{$hear p/lane q/@} :: receive packet
{$halo p/lane q/@ r/ares} :: hole with trace
@ -7068,6 +7069,13 @@
:: ::::
++ chrono ^?
|%
:: +from-unix: unix timestamp to @da
::
++ from-unix
|= timestamp=@ud
^- @da
%+ add ~1970.1.1
(mul timestamp ~s1)
:: :: ++dawn:chrono:
++ dawn :: Jan 1 weekday
|= yer/@ud
@ -7663,79 +7671,79 @@
^- (unit (pair ship diff-point))
~? ?=(~ mined.log) %processing-unmined-event
::
?: =(event.log owner-changed)
?: =(i.topics.log owner-changed)
=+ ^- [who=@ wer=address]
(decode-topics topics.log ~[%uint %address])
(decode-topics t.topics.log ~[%uint %address])
`[who %owner wer]
::
?: =(event.log activated)
?: =(i.topics.log activated)
=/ who=@
(decode-topics topics.log ~[%uint])
(decode-topics t.topics.log ~[%uint])
`[who %activated who]
::
?: =(event.log spawned)
?: =(i.topics.log spawned)
=+ ^- [pre=@ who=@]
(decode-topics topics.log ~[%uint %uint])
(decode-topics t.topics.log ~[%uint %uint])
`[pre %spawned who]
::
?: =(event.log escape-requested)
?: =(i.topics.log escape-requested)
=+ ^- [who=@ wer=@]
(decode-topics topics.log ~[%uint %uint])
(decode-topics t.topics.log ~[%uint %uint])
`[who %escape `wer]
::
?: =(event.log escape-canceled)
=/ who=@ (decode-topics topics.log ~[%uint])
?: =(i.topics.log escape-canceled)
=/ who=@ (decode-topics t.topics.log ~[%uint])
`[who %escape ~]
::
?: =(event.log escape-accepted)
?: =(i.topics.log escape-accepted)
=+ ^- [who=@ wer=@]
(decode-topics topics.log ~[%uint %uint])
(decode-topics t.topics.log ~[%uint %uint])
`[who %sponsor & wer]
::
?: =(event.log lost-sponsor)
?: =(i.topics.log lost-sponsor)
=+ ^- [who=@ pos=@]
(decode-topics topics.log ~[%uint %uint])
(decode-topics t.topics.log ~[%uint %uint])
`[who %sponsor | pos]
::
?: =(event.log changed-keys)
=/ who=@ (decode-topics topics.log ~[%uint])
?: =(i.topics.log changed-keys)
=/ who=@ (decode-topics t.topics.log ~[%uint])
=+ ^- [enc=octs aut=octs sut=@ud rev=@ud]
%+ decode-results data.log
~[[%bytes-n 32] [%bytes-n 32] %uint %uint]
`[who %keys rev (pass-from-eth enc aut sut)]
::
?: =(event.log broke-continuity)
=/ who=@ (decode-topics topics.log ~[%uint])
?: =(i.topics.log broke-continuity)
=/ who=@ (decode-topics t.topics.log ~[%uint])
=/ num=@ (decode-results data.log ~[%uint])
`[who %continuity num]
::
?: =(event.log changed-management-proxy)
?: =(i.topics.log changed-management-proxy)
=+ ^- [who=@ sox=address]
(decode-topics topics.log ~[%uint %address])
(decode-topics t.topics.log ~[%uint %address])
`[who %management-proxy sox]
::
?: =(event.log changed-voting-proxy)
?: =(i.topics.log changed-voting-proxy)
=+ ^- [who=@ tox=address]
(decode-topics topics.log ~[%uint %address])
(decode-topics t.topics.log ~[%uint %address])
`[who %voting-proxy tox]
::
?: =(event.log changed-spawn-proxy)
?: =(i.topics.log changed-spawn-proxy)
=+ ^- [who=@ sox=address]
(decode-topics topics.log ~[%uint %address])
(decode-topics t.topics.log ~[%uint %address])
`[who %spawn-proxy sox]
::
?: =(event.log changed-transfer-proxy)
?: =(i.topics.log changed-transfer-proxy)
=+ ^- [who=@ tox=address]
(decode-topics topics.log ~[%uint %address])
(decode-topics t.topics.log ~[%uint %address])
`[who %transfer-proxy tox]
::
:: warn about unimplemented events, but ignore
:: the ones we know are harmless.
~? ?! .= event.log
~? ?! .= i.topics.log
:: OwnershipTransferred(address,address)
0x8be0.079c.5316.5914.1344.cd1f.d0a4.f284.
1949.7f97.22a3.daaf.e3b4.186f.6b64.57e0
[%unimplemented-event event.log]
[%unimplemented-event i.topics.log]
~
::
++ apply-point-diff
@ -8083,11 +8091,12 @@
::
++ decode-topics
:: tox: list of hex words
|* [tox=(list @t) tys=(list etyp)]
=- (decode-arguments - tys)
%+ roll tox
|= [top=@t tos=@t]
(cat 3 tos (rsh 3 2 top))
|* [tox=(lest @ux) tys=(list etyp)]
=- (decode-arguments (crip -) tys)
%+ render-hex-bytes (mul 32 (lent tox))
%+ roll `(list @ux)`tox
|= [top=@ux tos=@]
(cat 8 top tos)
::
++ decode-results
:: rex: string of hex bytes with leading 0x.
@ -8218,14 +8227,15 @@
fro=(unit block)
tob=(unit block)
adr=(list address)
top=(list octs)
top=(list ?(@ux (list @ux)))
==
[%eth-get-block-by-number bon=@ud txs=?]
[%eth-get-filter-logs fid=@ud]
$: %eth-get-logs
fro=(unit block)
tob=(unit block)
adr=(list address)
top=(list octs)
top=(list ?(@ux (list @ux)))
==
[%eth-get-filter-changes fid=@ud]
[%eth-send-raw-transaction dat=@ux]
@ -8254,8 +8264,16 @@
::
address=@ux
data=@t
event=@ux
topics=(list @t)
:: event data
::
:: For standard events, the first topic is the event signature
:: hash. For anonymous events, the first topic is the first
:: indexed argument.
:: Note that this does not support the "anonymous event with
:: zero topics" case. This has dubious usability, and using
:: +lest instead of +list saves a lot of ?~ checks.
::
topics=(lest @ux)
==
::
:: data for eth_call.
@ -8379,8 +8397,14 @@
(turn adr.req (cork address-to-hex tape))
::
?~ top.req ~
:^ ~ 'topics' %a
(turn `(list octs)`top.req :(cork render-hex-bytes prefix-hex tape))
:+ ~ 'topics'
(topics-to-json top.req)
==
::
%eth-get-block-by-number
:- 'eth_getBlockByNumber'
:~ (tape (num-to-hex bon.req))
b+txs.req
==
::
%eth-get-filter-logs
@ -8406,8 +8430,8 @@
(turn adr.req (cork address-to-hex tape))
::
?~ top.req ~
:^ ~ 'topics' %a
(turn `(list octs)`top.req :(cork render-hex-bytes prefix-hex tape))
:+ ~ 'topics'
(topics-to-json top.req)
==
::
%eth-get-filter-changes
@ -8450,6 +8474,23 @@
%label s+l.dob
==
::
++ topics-to-json
|= tos=(list ?(@ux (list @ux)))
^- json
:- %a
=/ ttj
;: cork
(cury render-hex-bytes 32)
prefix-hex
tape:enjs:format
==
%+ turn tos
|= t=?(@ (list @))
?@ t
?: =(0 t) ~
(ttj `@`t)
a+(turn t ttj)
::
:: parsing responses
::
::TODO ++ parse-response |= json ^- response
@ -8489,11 +8530,12 @@
address+(cu hex-to-num so)
data+so
::
::TODO doesn't account for the anonymous event case, which has no hash.
=- topics+(cu - (ar so))
|= r=(list @t)
^- (lest @ux)
?> ?=([@t *] r)
[(hex-to-num i.r) t.r]
:- (hex-to-num i.r)
(turn t.r hex-to-num)
==
--
::

View File

@ -14,6 +14,37 @@
--
::
|%
++ test-explode-bytes
;: weld
%+ expect-eq
!> ~
!> (flop (explode-bytes:base64 [0 `@`0]))
::
%+ expect-eq
!> ~[0x0 0x0 0x0]
!> (flop (explode-bytes:base64 [3 `@`0]))
::
%+ expect-eq
!> ~[0x1 0x1 0x1]
!> (flop (explode-bytes:base64 [3 `@`0x1.0101]))
==
::
++ test-explode-words
;: weld
%+ expect-eq
!> ~
!> (flop (explode-words:base64 1 [0 `@`0]))
::
%+ expect-eq
!> ~[0 0 0 0 0 0 0 1]
!> (flop (explode-words:base64 3 [3 `@`1]))
::
%+ expect-eq
!> ~[0x0 0x12.3456 0x78.9abc 0xde.f012 0x34.5678]
!> =/ inp [15 `@`0x1234.5678.9abc.def0.1234.5678]
(flop (explode-words:base64 24 inp))
==
::
++ test-base64
;: weld
%+ expect-eq

View File

@ -0,0 +1,69 @@
:: tests for number-to-words
::
/+ number-to-words, *test
::
|%
++ test-eng-us
=+ eng-us:number-to-words
;: weld
%+ expect-eq
!> `(unit tape)``"zero"
!> (to-words 0)
::
%+ expect-eq
!> `(unit tape)``"one"
!> (to-words 1)
::
%+ expect-eq
!> `(unit tape)``"twelve"
!> (to-words 12)
::
%+ expect-eq
!> `(unit tape)``"twenty"
!> (to-words 20)
::
%+ expect-eq
!> `(unit tape)``"ninety-nine"
!> (to-words 99)
::
%+ expect-eq
!> `(unit tape)``"one hundred"
!> (to-words 100)
::
%+ expect-eq
!> `(unit tape)``"one hundred and eleven"
!> (to-words 111)
::
%+ expect-eq
!> `(unit tape)``"one thousand"
!> (to-words 1.000)
::
%+ expect-eq
!> `(unit tape)``"one thousand, one hundred and eleven"
!> (to-words 1.111)
::
%+ expect-eq
!> `(unit tape)``"one million and one"
!> (to-words 1.000.001)
::
%+ expect-eq
!> `(unit tape)``"one trillion"
!> (to-words (pow 10 12))
::
%+ expect-eq
!>
^- (unit tape)
:- ~
;: weld
"eighteen quintillion, four hundred and forty-six quadrillion, seven "
"hundred and forty-four trillion, seventy-three billion, seven "
"hundred and nine million, five hundred and fifty-one thousand, six "
"hundred and sixteen"
==
!> (to-words 18.446.744.073.709.551.616)
::
%+ expect-eq
!> `(unit tape)``"one vigintillion"
!> (to-words (pow 10 63))
==
--

55
tests/sys/hoon/bits.hoon Normal file
View File

@ -0,0 +1,55 @@
/+ *test
|%
++ test-bits
;: weld
::
:: Random sanity testing
::
%+ expect-eq
!> ~[0x3 0x7 0x7]
!> (flop (ripn 3 0xff))
%+ expect-eq
!> ~[0x1 0xee 0xff]
!> (flop (ripn 8 0x1.eeff))
%+ expect-eq
!> ~[0x1 0xe 0xe 0xf 0xf]
!> (flop (ripn 4 0x1.eeff))
::
:: Typical use-cases
::
%+ expect-eq
!> ~[0x1 0x23.4567 0x89.abcd]
!> (flop (ripn 24 0x1.2345.6789.abcd))
::
:: Edge cases
::
%+ expect-eq
!> ~
!> (flop (ripn 31 0x0))
%+ expect-eq
!> ~
!> (flop (ripn 1 0x0))
::
:: Word boundaries
::
%+ expect-eq
!> ~[0x7fff.ffff]
!> (flop (ripn 31 0x7fff.ffff))
%+ expect-eq
!> ~[0x1 0x7fff.ffff]
!> (flop (ripn 31 0xffff.ffff))
%+ expect-eq
!> ~[0x3 0x7fff.ffff]
!> (flop (ripn 31 0x1.ffff.ffff))
%+ expect-eq
!> ~[0x3 0x7fff.ffff 0x7fff.ffff]
!> (flop (ripn 31 0xffff.ffff.ffff.ffff))
%+ expect-eq
!> ~[0x1 0x1.ffff 0x1.ffff]
!> (flop (ripn 17 0x7.ffff.ffff))
%+ expect-eq
!> ~[0x123 0x456 0x789 0xabc 0xdef 0x12 0x345 0x678]
!> (flop (ripn 12 0x1234.5678.9abc.def0.1234.5678))
==
::
--

View File

@ -11,7 +11,7 @@
^- manx
;div
;div
=urb-component "TopicCreatePage"
=urb-component "TopicCreatePage"
=urb-ship "{(scow %p p.bem.gas)}"
=urb-claypath "{<pax>}"
=urb-content "{(trip body)}"

83033
web/landscape/js/index.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -14,7 +14,7 @@
;div.flex-col-2;
;div.flex-col-x
;div.profile-avatar
;div(urb-component "Sigil", urb-size "320", urb-ship "{(scow %p p.bem.gas)}", urb-suffix "false");
;div(urb-component "Sigil", urb-size "310", urb-ship "{(scow %p p.bem.gas)}", urb-suffix "false");
;div(urb-component "ProfileMsgBtn", urb-ship "{(scow %p p.bem.gas)}");
==
==

View File

@ -16,21 +16,6 @@
;div.flex-col-2;
;div.flex-col-x
;a.vanilla.btn.btn-primary(href (trip 'javascript:(function(){document.querySelectorAll("[urb-devices]")[0].classList.add("hide"); document.querySelectorAll("[urb-qr]")[0].classList.remove("hide");})()')): Connect device
;h2.mt-6: Devices
;h3.text-mono.mt-4: 108.208.53.121
;div: Current session
;h3.text-mono.mt-4: 67.188.43.52
;div: Chrome on OS X 10.12.6
;div
;span.mr-3: Last login:
;span.text-mono: 2018.4.21
==
;h3.text-mono.mt-4: 43.222.12.64
;div: iOS 14.11
;div
;span.mr-3: Last login:
;span.text-mono: 2018.3.12
==
;div.mt-6
;a.h3.vanilla.text-red(href "javascript:void(0)"): Log Out ↓
==