mirror of
https://github.com/urbit/shrub.git
synced 2025-01-04 18:43:46 +03:00
updates the |take:dawn gates to produce units and print errors
This commit is contained in:
parent
7283353bce
commit
4508aa9c95
101
sys/zuse.hoon
101
sys/zuse.hoon
@ -8236,34 +8236,55 @@
|
||||
:: |take:dawn: parse responses for pre-boot validation
|
||||
::
|
||||
++ take
|
||||
=, dejs:format
|
||||
=, dejs-soft:format
|
||||
|%
|
||||
:: +bloq:take:dawn: parse block number
|
||||
::
|
||||
++ bloq
|
||||
|= rep=octs
|
||||
^- @ud
|
||||
=/ jon=json (need (de-json:html q.rep))
|
||||
=/ res=cord ((ot result+so ~) jon)
|
||||
(hex-to-num:ethereum res)
|
||||
^- (unit @ud)
|
||||
=/ jon=(unit json) (de-json:html q.rep)
|
||||
?~ jon
|
||||
~&([%bloq-take-dawn %invalid-json] ~)
|
||||
=/ res=(unit cord) ((ot result+so ~) u.jon)
|
||||
?~ res
|
||||
~&([%bloq-take-dawn %invalid-response rep] ~)
|
||||
=/ out
|
||||
%- mule |.
|
||||
(hex-to-num:ethereum u.res)
|
||||
?: ?=(%& -.out)
|
||||
(some p.out)
|
||||
~&([%bloq-take-dawn %invalid-block-number] ~)
|
||||
:: +czar:take:dawn: parse galaxy table
|
||||
::
|
||||
++ czar
|
||||
|= rep=octs
|
||||
^- (map ship [=life =pass])
|
||||
=/ jon=json (need (de-json:html q.rep))
|
||||
=/ res=(list [@t @t])
|
||||
((ar (ot id+so result+so ~)) jon)
|
||||
%+ roll res
|
||||
|= $: res=[id=@t result=@t]
|
||||
^- (unit (map ship [=life =pass]))
|
||||
=/ jon=(unit json) (de-json:html q.rep)
|
||||
?~ jon
|
||||
~&([%czar-take-dawn %invalid-json] ~)
|
||||
=/ res=(unit (list [@t @t]))
|
||||
((ar (ot id+so result+so ~)) u.jon)
|
||||
?~ res
|
||||
~&([%czar-take-dawn %invalid-response rep] ~)
|
||||
=/ dat=(unit (list [who=ship enc=octs aut=octs sut=@ud rev=@ud]))
|
||||
=- ?:(?=(%| -.out) ~ (some p.out))
|
||||
^= out %- mule |.
|
||||
%+ turn u.res
|
||||
|= [id=@t result=@t]
|
||||
^- [who=ship enc=octs aut=octs sut=@ud rev=@ud]
|
||||
:- `@p`(slav %ud (rsh 3 4 id))
|
||||
%+ decode-results:ethereum
|
||||
result
|
||||
~[[%bytes-n 32] [%bytes-n 32] %uint %uint]
|
||||
?~ dat
|
||||
~&([%bloq-take-dawn %invalid-galaxy-table] ~)
|
||||
:- ~
|
||||
%+ roll u.dat
|
||||
|= $: [who=ship enc=octs aut=octs sut=@ud rev=@ud]
|
||||
kyz=(map ship [=life =pass])
|
||||
==
|
||||
^+ kyz
|
||||
=/ who=ship (slav %ud (rsh 3 4 id.res))
|
||||
=+ ^- [enc=octs aut=octs sut=@ud rev=@ud]
|
||||
%+ decode-results:ethereum
|
||||
result.res
|
||||
~[[%bytes-n 32] [%bytes-n 32] %uint %uint]
|
||||
=/ pub=(unit pass)
|
||||
(pass-from-eth:constitution:ethereum enc aut sut)
|
||||
?~ pub kyz
|
||||
@ -8272,24 +8293,40 @@
|
||||
::
|
||||
++ hull
|
||||
|= [who=ship rep=octs]
|
||||
^- hull:constitution:ethe
|
||||
=/ jon=json (need (de-json:html q.rep))
|
||||
=/ res=cord ((ot result+so ~) jon)
|
||||
~? =(res '0x') 'bad result from node; is ships address correct?'
|
||||
%+ hull-from-eth:constitution:ethereum
|
||||
who
|
||||
:_ *deed:eth-noun:constitution:ethereum
|
||||
(decode-results:ethereum res hull:eth-type:constitution:ethe)
|
||||
^- (unit hull:constitution:ethe)
|
||||
=/ jon=(unit json) (de-json:html q.rep)
|
||||
?~ jon
|
||||
~&([%hull-take-dawn %invalid-json] ~)
|
||||
=/ res=(unit cord) ((ot result+so ~) u.jon)
|
||||
?~ res
|
||||
~&([%hull-take-dawn %invalid-response rep] ~)
|
||||
~? =(u.res '0x')
|
||||
'bad result from node; is ships address correct?'
|
||||
=/ out
|
||||
%- mule |.
|
||||
%+ hull-from-eth:constitution:ethereum
|
||||
who
|
||||
:_ *deed:eth-noun:constitution:ethereum
|
||||
(decode-results:ethereum u.res hull:eth-type:constitution:ethe)
|
||||
?: ?=(%& -.out)
|
||||
(some p.out)
|
||||
~&([%hull-take-dawn %invalid-hull] ~)
|
||||
:: +turf:take:dawn: parse network domains
|
||||
::
|
||||
++ turf
|
||||
|= rep=octs
|
||||
^- (list ^turf)
|
||||
=/ jon=json (need (de-json:html q.rep))
|
||||
=/ res=(list [@t @t])
|
||||
((ar (ot id+so result+so ~)) jon)
|
||||
=/ dom=(list (pair @ud ^turf))
|
||||
%+ turn res
|
||||
^- (unit (list ^turf))
|
||||
=/ jon=(unit json) (de-json:html q.rep)
|
||||
?~ jon
|
||||
~&([%turf-take-dawn %invalid-json] ~)
|
||||
=/ res=(unit (list [@t @t]))
|
||||
((ar (ot id+so result+so ~)) u.jon)
|
||||
?~ res
|
||||
~&([%turf-take-dawn %invalid-response rep] ~)
|
||||
=/ dat=(unit (list (pair @ud ^turf)))
|
||||
=- ?:(?=(%| -.out) ~ (some p.out))
|
||||
^= out %- mule |.
|
||||
%+ turn u.res
|
||||
|= [id=@t result=@t]
|
||||
^- (pair @ud ^turf)
|
||||
:- (slav %ud (rsh 3 5 id))
|
||||
@ -8298,6 +8335,10 @@
|
||||
=/ hot=host:eyre
|
||||
(scan dom thos:de-purl:html)
|
||||
?>(?=(%& -.hot) p.hot)
|
||||
?~ dat
|
||||
~&([%turf-take-dawn %invalid-domains] ~)
|
||||
:- ~
|
||||
=* dom u.dat
|
||||
:: sort by id, ascending, removing duplicates
|
||||
::
|
||||
=| tuf=(map ^turf @ud)
|
||||
|
@ -104,7 +104,7 @@
|
||||
'{"id":"0","jsonrpc":"2.0","result":"0x20"}'
|
||||
=/ boq 32
|
||||
%+ expect-eq
|
||||
!> boq
|
||||
!> [~ boq]
|
||||
!> (bloq:take:dawn oct)
|
||||
::
|
||||
++ test-take-czar
|
||||
@ -138,7 +138,8 @@
|
||||
638.361.167.187.097.711.481.986.932.531.569.955.478.938.087.263.286.158.
|
||||
823.313.739.767.009.446.819.531.923.255.637.798.148.055.143.938.146
|
||||
%+ expect-eq
|
||||
!> %- ~(gas by *(map ship [=life =pass]))
|
||||
!> :- ~
|
||||
%- ~(gas by *(map ship [=life =pass]))
|
||||
[[~zod 1 zod.kyz] [~nec 1 nec.kyz] ~]
|
||||
!> (czar:take:dawn oct)
|
||||
::
|
||||
@ -161,7 +162,7 @@
|
||||
'"}'
|
||||
==
|
||||
%+ expect-eq
|
||||
!> hul
|
||||
!> [~ hul]
|
||||
!> (hull:take:dawn ~zod oct)
|
||||
::
|
||||
++ test-take-turf
|
||||
@ -183,7 +184,7 @@
|
||||
'"}]'
|
||||
==
|
||||
%+ expect-eq
|
||||
!> [/org/urbit ~]
|
||||
!> [~ [/org/urbit ~]]
|
||||
!> (turf:take:dawn oct)
|
||||
::
|
||||
++ test-snap-bloq
|
||||
|
Loading…
Reference in New Issue
Block a user