From 4508aa9c95ebe17eb072554eb7939977c3d552bc Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 6 Dec 2018 14:11:14 -0500 Subject: [PATCH 1/2] updates the |take:dawn gates to produce units and print errors --- sys/zuse.hoon | 101 +++++++++++++++++++++++++++------------ tests/sys/zuse/dawn.hoon | 9 ++-- 2 files changed, 76 insertions(+), 34 deletions(-) diff --git a/sys/zuse.hoon b/sys/zuse.hoon index a0d0d9b251..5ac6747019 100644 --- a/sys/zuse.hoon +++ b/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) diff --git a/tests/sys/zuse/dawn.hoon b/tests/sys/zuse/dawn.hoon index e820925f02..fd88ca9d82 100644 --- a/tests/sys/zuse/dawn.hoon +++ b/tests/sys/zuse/dawn.hoon @@ -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 From 5bedf98b77a13fdcfd8a214d22308afb7d7fc5a7 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 7 Dec 2018 02:06:54 -0500 Subject: [PATCH 2/2] updates the |snap:dawn gates to produce units --- sys/zuse.hoon | 28 +++++++++++++++------------- tests/sys/zuse/dawn.hoon | 8 ++++---- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/sys/zuse.hoon b/sys/zuse.hoon index 5ac6747019..eaa316a72f 100644 --- a/sys/zuse.hoon +++ b/sys/zuse.hoon @@ -8361,14 +8361,18 @@ :: ++ bloq |= snap=snapshot:jael - ^- @ud + ^- (unit @ud) + =- ?:(?=(%| -.out) ~ (some p.out)) + ^= out %- mule |. latest-block.snap :: +czar:snap:dawn: extract galaxy table :: ++ czar |= snap=snapshot:jael - ^- (map ship [=life =pass]) - %- malt + ^- (unit (map ship [=life =pass])) + =- ?:(?=(%| -.out) ~ (some p.out)) + ^= out %- mule |. + %- ~(gas by *(map ship [=life =pass])) %+ turn (gulf 0 255) |= gal=@ ^- [ship [life pass]] @@ -8379,26 +8383,24 @@ :: ++ hull |= [who=ship snap=snapshot:jael] - ^- hull:constitution:ethe - =/ res (~(get by hul.eth.snap) who) - ?~ res - ~& ['hull not found in snapshot; can\'t verify' who=who] - !! - u.res + ^- (unit hull:constitution:ethe) + (~(get by hul.eth.snap) who) :: +turf:snap:dawn: extract network domains :: ++ turf |= snap=snapshot:jael - ^- (list ^turf) + ^- (unit (list ^turf)) + =- ?:(?=(%| -.out) ~ (some p.out)) + ^= out %- mule |. %+ murn - ^- (list (pair)) + ^- (list host:eyre) %+ murn ^- (list @t) ~[pri sec ter]:dns.eth.snap |= dom=@t - ^- (unit (pair)) + ^- (unit host:eyre) (rush dom thos:de-purl:html) - |=([* a=*] ((soft ^turf) a)) + |=(a=host:eyre ?:(?=(%| -.a) ~ (some p.a))) -- :: +veri:dawn: validate keys, life, discontinuity, &c :: diff --git a/tests/sys/zuse/dawn.hoon b/tests/sys/zuse/dawn.hoon index fd88ca9d82..cbd08fe19e 100644 --- a/tests/sys/zuse/dawn.hoon +++ b/tests/sys/zuse/dawn.hoon @@ -189,22 +189,22 @@ :: ++ test-snap-bloq %+ expect-eq - !> 4.230.000 + !> [~ 4.230.000] !> (bloq:snap:dawn snap) :: ++ test-snap-hull %+ expect-eq - !> hul + !> [~ hul] !> (hull:snap:dawn ~zod snap) :: ++ test-snap-czar %+ expect-eq !> 256 - !> ~(wyt by (czar:snap:dawn snap)) + !> ~(wyt by (need (czar:snap:dawn snap))) :: ++ test-snap-turf %+ expect-eq - !> `(list turf)`~[~['org' 'urbit'] ~['org' 'urbit']] + !> [~ `(list turf)`~[~['org' 'urbit'] ~['org' 'urbit']]] !> (turf:snap:dawn snap) :: ++ test-veri-good