various: fix dependencies & tests

This commit is contained in:
Liam Fitzgerald 2021-09-17 14:51:19 +10:00
parent 5e5e0cb681
commit 143a8e08e6
77 changed files with 112 additions and 1781 deletions

View File

@ -87,6 +87,7 @@
-- --
:: ::
|_ =bowl:gall |_ =bowl:gall
++ bec byk.bowl(r da+now.bowl)
:: ::
++ poke-spider ++ poke-spider
|= [=path our=@p =cage] |= [=path our=@p =cage]

View File

@ -118,6 +118,7 @@
-- --
:: ::
|_ =bowl:gall |_ =bowl:gall
++ bec byk.bowl(r da+now.bowl)
++ poke-spider ++ poke-spider
|= [=path our=@p =cage] |= [=path our=@p =cage]
^- card ^- card
@ -138,7 +139,7 @@
^- (list card) ^- (list card)
=/ tid=@ta =/ tid=@ta
:((cury cat 3) dap.bowl '--' node-id '--' (scot %uv eny.bowl)) :((cury cat 3) dap.bowl '--' node-id '--' (scot %uv eny.bowl))
=/ args [~ `tid bec %eth-send-txs !>([node step txs]] =/ args [~ `tid bec %eth-send-txs !>([node step txs])]
:~ (watch-spider /send/[tid] our.bowl /thread-result/[tid]) :~ (watch-spider /send/[tid] our.bowl /thread-result/[tid])
(poke-spider /send/[tid] our.bowl %spider-start !>(args)) (poke-spider /send/[tid] our.bowl %spider-start !>(args))
== ==

View File

@ -175,6 +175,7 @@
-- --
:: ::
|_ =bowl:gall |_ =bowl:gall
++ bec byk.bowl(r da+now.bowl)
++ setup-cards ++ setup-cards
^- (list card) ^- (list card)
:~ wait-export :~ wait-export

View File

@ -547,7 +547,7 @@
=+ .^ =+ .^
=tube:clay =tube:clay
%cc %cc
/(scot %p our.bowl)/[q.byk.bowl]/(scot %da now.bowl)/[output]/json /(scot %p our.bowl)/[desk]/(scot %da now.bowl)/[output]/json
== ==
:_ state(serving (~(del by serving.state) tid)) :_ state(serving (~(del by serving.state) tid))
%+ give-simple-payload:app:server eyre-id %+ give-simple-payload:app:server eyre-id

View File

@ -1,76 +0,0 @@
:: Print useful diagnostic information
::
:: base-hash: loosely, the most recent successfully applied update.
:: Technically, the mergebase of %home with OTA source
:: sour-hash: most recently downloaded update (not necessarily applied)
:: home-hash: hash of %home desk, which may differ if you have changed
:: it, for example with notebooks or 3rd party apps
:: kids-hash: hash of the %kids desk, which is what you serve to your
:: children
:: glob-hash: hash of the glob, which is the js for landscape
::
/- glob
/+ version
:- %say
|= [[now=time * bec=beak] ~ ~]
=* our p.bec
=/ sponsor (sein:title our now our)
:- %noun
=<
:~
[%base-hash (base-hash:version our now)]
[%sour-hash sour-hash]
[%home-hash .^(@uv %cz (pathify ~.home ~))]
[%kids-hash .^(@uv %cz (pathify ~.kids ~))]
[%glob-hash glob-state]
::
(info %our our)
(info %sponsor sponsor)
(info %dopzod ~dopzod)
::
["Compare lifes and rifts to values here:"]
["https://etherscan.io/address/azimuth.eth#readContract"]
[" life - getKeyRevisionNumber"]
[" rift - getContinuityNumber"]
==
|%
++ pathify
|= [a=@ta b=(unit ship)]
^- path
=/ o=@ta (scot %p our)
=/ n=@ta (scot %da now)
?~ b ~[o a n]
~[o a n (scot %p u.b)]
::
++ info
|= [=term =ship]
:: unitized life and rift
=/ lyfe .^((unit @ud) %j (pathify ~.lyfe `ship))
=/ ryft .^((unit @ud) %j (pathify ~.ryft `ship))
:* term
ship=ship
point=(crip (slag 2 (scow %ui ship)))
:: report as units
life=lyfe
rift=ryft
==
::
++ sour-hash
=+ .^ ota=(unit [=ship =desk =aeon:clay])
%gx /(scot %p our)/hood/(scot %da now)/kiln/ota/noun
==
?~ ota
*@uv
=/ parent (scot %p ship.u.ota)
=+ .^(=cass:clay %cs /[parent]/[desk.u.ota]/1/late/foo)
.^(@uv %cz /[parent]/[desk.u.ota]/(scot %ud ud.cass))
::
++ glob-state
^- (list [path @uv @tas])
=+ !< [@ud =globs:glob]
.^(vase %gx (weld (pathify ~.glob ~) /dbug/state/noun))
%+ turn ~(tap by globs)
|= [srv=path hash=@uv glob=(unit [? *])]
^- [path @uv @tas]
[srv hash ?~(glob %waiting ?:(-.u.glob %done %trying))]
--

View File

@ -1 +0,0 @@
../../base-dev/lib/treaty.hoon

View File

@ -0,0 +1,13 @@
|_ =desk
++ grad %noun
++ grow
|%
++ noun desk
++ json s+desk
--
++ grab
|%
++ noun ^desk
++ json so:dejs:format
--
--

View File

@ -85,7 +85,6 @@
|. |.
=/ ford =/ ford
%: ford:fusion %: ford:fusion
bud
*ankh:clay *ankh:clay
deletes=~ deletes=~
changes=(my [/lib/self/hoon &+hoon+source]~) changes=(my [/lib/self/hoon &+hoon+source]~)
@ -101,7 +100,6 @@
++ test-mar-mime ^- tang ++ test-mar-mime ^- tang
=/ ford =/ ford
%: ford:fusion %: ford:fusion
bud
*ankh:clay *ankh:clay
deletes=~ deletes=~
changes=(my [/mar/mime/hoon &+hoon+mar-mime]~) changes=(my [/mar/mime/hoon &+hoon+mar-mime]~)
@ -122,7 +120,6 @@
++ test-mar-udon ^- tang ++ test-mar-udon ^- tang
=/ ford =/ ford
%: ford:fusion %: ford:fusion
bud
*ankh:clay *ankh:clay
deletes=~ deletes=~
^= changes ^= changes
@ -154,7 +151,6 @@
== ==
=/ ford =/ ford
%: ford:fusion %: ford:fusion
bud
*ankh:clay *ankh:clay
deletes=~ deletes=~
changes changes
@ -174,7 +170,6 @@
== ==
=/ ford =/ ford
%: ford:fusion %: ford:fusion
bud
*ankh:clay *ankh:clay
deletes=~ deletes=~
changes changes
@ -195,7 +190,6 @@
== ==
=/ ford =/ ford
%: ford:fusion %: ford:fusion
bud
*ankh:clay *ankh:clay
deletes=~ deletes=~
changes changes
@ -210,7 +204,6 @@
++ test-gen-hello ^- tang ++ test-gen-hello ^- tang
=/ ford =/ ford
%: ford:fusion %: ford:fusion
bud
*ankh:clay *ankh:clay
deletes=~ deletes=~
changes=(my [/gen/hello/hoon &+hoon+gen-hello]~) changes=(my [/gen/hello/hoon &+hoon+gen-hello]~)
@ -231,7 +224,6 @@
++ test-lib-strandio ^- tang ++ test-lib-strandio ^- tang
=/ ford =/ ford
%: ford:fusion %: ford:fusion
bud
*ankh:clay *ankh:clay
deletes=~ deletes=~
^= changes ^= changes

View File

@ -2346,6 +2346,7 @@
++ scry-provides-code ^- roof ++ scry-provides-code ^- roof
|= [gang =view =beam] |= [gang =view =beam]
^- (unit (unit cage)) ^- (unit (unit cage))
?: =(%gd view) ``noun+!>(%base)
?: &(=(%ca view) =(/gen/handler/hoon s.beam)) ?: &(=(%ca view) =(/gen/handler/hoon s.beam))
:+ ~ ~ :+ ~ ~
vase+!>(!>(|=(* |=(* [[%404 ~] ~])))) vase+!>(!>(|=(* |=(* [[%404 ~] ~]))))

View File

@ -33,13 +33,13 @@
=/ ship ~nec =/ ship ~nec
:: ::
=/ call-args =/ call-args
=/ =task:gall [%jolt dap %home] =/ =task:gall [%jolt %base dap]
[duct task] [duct task]
:: ::
=/ =move:gall-gate =/ =move:gall-gate
=/ =wire /sys/cor/[dap]/(scot %p ship)/home/(scot %da time) =/ =wire /sys/cor/[dap]/(scot %p ship)/base/(scot %da time)
=/ =note-arvo =/ =note-arvo
[%c %warp ship %home ~ %sing %a da+time /app/[dap]/hoon] [%c %warp ship %base ~ %sing %a da+time /app/[dap]/hoon]
[duct %pass wire note-arvo] [duct %pass wire note-arvo]
:: ::
=/ expected-moves=(list move:gall-gate) ~[move] =/ expected-moves=(list move:gall-gate) ~[move]

View File

@ -1,81 +0,0 @@
/- *treaty
/+ dock=docket
|%
++ enjs
=, enjs:format
|%
++ merge
|= [a=json b=json]
^- json
?> &(?=(%o -.a) ?=(%o -.b))
[%o (~(uni by p.a) p.b)]
::
++ treaty
|= t=^treaty
%+ merge (docket:enjs:dock docket.t)
%- pairs
:~ ship+s+(scot %p ship.t)
desk+s+desk.t
cass+(case case.t)
hash+s+(scot %uv hash.t)
==
::
++ case
|= c=^case
%+ frond -.c
?- -.c
%da s+(scot %da p.c)
%tas s+(scot %tas p.c)
%ud (numb p.c)
==
++ foreign-desk
|= [s=^ship =desk]
^- cord
(crip "{(scow %p s)}/{(trip desk)}")
::
++ alliance
|= a=^alliance
^- json
:- %a
%+ turn ~(tap in a)
|= [=^ship =desk]
^- json
s+(foreign-desk ship desk)
::
++ treaty-update
|= u=update:^treaty
^- json
%+ frond -.u
?- -.u
%add (treaty treaty.u)
%del s+(foreign-desk +.u)
::
%ini
%- pairs
%+ turn ~(tap by init.u)
|= [[s=^ship =desk] t=^treaty]
[(foreign-desk s desk) (treaty t)]
==
::
++ ally-update
|= u=update:ally
^- json
%+ frond -.u
?- -.u
?(%add %del) s+(scot %p ship.u)
::
%ini
%- pairs
%+ turn ~(tap by init.u)
|= [s=^ship a=^alliance]
[(scot %p s) (alliance a)]
::
%new
%- pairs
:~ ship+s+(scot %p ship.u)
alliance+(alliance alliance.u)
==
==
--
--

View File

@ -1 +0,0 @@
../../base-dev/lib/treaty.hoon

View File

@ -83,7 +83,6 @@
pass pass:io pass pass:io
:: ::
++ on-init ++ on-init
=. current-timebox now.bowl
`this `this
:: ::
++ on-save !>(-.state) ++ on-save !>(-.state)

View File

@ -1,7 +1,7 @@
:~ title+'Garden' :~ title+'Garden'
info+'An app launcher for Urbit.' info+'An app launcher for Urbit.'
color+0xee.5432 color+0xee.5432
glob-http+'https://bootstrap.urbit.org/glob-0v2.dne76.9hibl.1o442.h6l11.cn7os.glob' glob-http+'https://bootstrap.urbit.org/glob-0vk49j3.ne5gf.5viv2.ghlb4.r6b8n.glob'
::glob-ames+~zod ::glob-ames+~zod
base+'grid' base+'grid'
version+[0 0 1] version+[0 0 1]

View File

@ -1 +0,0 @@
../../base-dev/lib/treaty.hoon

View File

@ -0,0 +1,81 @@
/- *treaty
/+ dock=docket
|%
++ enjs
=, enjs:format
|%
++ merge
|= [a=json b=json]
^- json
?> &(?=(%o -.a) ?=(%o -.b))
[%o (~(uni by p.a) p.b)]
::
++ treaty
|= t=^treaty
%+ merge (docket:enjs:dock docket.t)
%- pairs
:~ ship+s+(scot %p ship.t)
desk+s+desk.t
cass+(case case.t)
hash+s+(scot %uv hash.t)
==
::
++ case
|= c=^case
%+ frond -.c
?- -.c
%da s+(scot %da p.c)
%tas s+(scot %tas p.c)
%ud (numb p.c)
==
++ foreign-desk
|= [s=^ship =desk]
^- cord
(crip "{(scow %p s)}/{(trip desk)}")
::
++ alliance
|= a=^alliance
^- json
:- %a
%+ turn ~(tap in a)
|= [=^ship =desk]
^- json
s+(foreign-desk ship desk)
::
++ treaty-update
|= u=update:^treaty
^- json
%+ frond -.u
?- -.u
%add (treaty treaty.u)
%del s+(foreign-desk +.u)
::
%ini
%- pairs
%+ turn ~(tap by init.u)
|= [[s=^ship =desk] t=^treaty]
[(foreign-desk s desk) (treaty t)]
==
::
++ ally-update
|= u=update:ally
^- json
%+ frond -.u
?- -.u
?(%add %del) s+(scot %p ship.u)
::
%ini
%- pairs
%+ turn ~(tap by init.u)
|= [s=^ship a=^alliance]
[(scot %p s) (alliance a)]
::
%new
%- pairs
:~ ship+s+(scot %p ship.u)
alliance+(alliance alliance.u)
==
==
--
--

View File

@ -1,5 +1,5 @@
/+ dock=docket /+ treaty
|_ treaties=(list treaty:dock) |_ treaties=(list treaty:treaty)
++ grow ++ grow
|% |%
++ noun treaties ++ noun treaties
@ -7,14 +7,14 @@
^- ^json ^- ^json
%- pairs:enjs:format %- pairs:enjs:format
%+ turn treaties %+ turn treaties
|= =treaty:dock |= t=treaty:treaty
:- (crip "{(scow %p ship.treaty)}/{(trip desk.treaty)}") :- (crip "{(scow %p ship.t)}/{(trip desk.t)}")
(treaty:enjs:dock treaty) (treaty:enjs:treaty t)
-- --
++ grab ++ grab
|% |%
++ noun (list treaty:dock) ++ noun (list treaty:treaty)
-- --
++ grad %noun ++ grad %noun
-- --

View File

@ -10,7 +10,6 @@ import Notifications from '~/views/apps/notifications/notifications';
import { PermalinkRoutes } from '~/views/apps/permalinks/app'; import { PermalinkRoutes } from '~/views/apps/permalinks/app';
import Profile from '~/views/apps/profile/profile'; import Profile from '~/views/apps/profile/profile';
import Settings from '~/views/apps/settings/settings'; import Settings from '~/views/apps/settings/settings';
import TermApp from '~/views/apps/term/app';
import ErrorComponent from '~/views/components/Error'; import ErrorComponent from '~/views/components/Error';
import { useShortcut } from '~/logic/state/settings'; import { useShortcut } from '~/logic/state/settings';
@ -97,7 +96,6 @@ function getNotificationRedirect(link: string) {
} else if (link.startsWith('/invite')) { } else if (link.startsWith('/invite')) {
return getInviteRedirect(link); return getInviteRedirect(link);
} }
} }
export const Content = (props) => { export const Content = (props) => {
@ -154,16 +152,6 @@ export const Content = (props) => {
/> />
)} )}
/> />
<Route
path='/~term'
render={p => (
<TermApp
location={p.location}
match={p.match}
{...props}
/>
)}
/>
<Route path='/~landscape'> <Route path='/~landscape'>
<Landscape /> <Landscape />
</Route> </Route>

View File

@ -6,7 +6,6 @@
%group-store %group-store
%invite-store %invite-store
%s3-store %s3-store
%settings-store
%chat-cli %chat-cli
%chat-hook %chat-hook
%chat-view %chat-view

View File

@ -1,7 +1,7 @@
:~ title+'Landscape' :~ title+'Landscape'
info+'A suite of applications to communicate on Urbit' info+'A suite of applications to communicate on Urbit'
color+0xee.5432 color+0xee.5432
glob-http+'https://bootstrap.urbit.org/glob-0v7.bcnlj.eocmq.cmbeu.b8s54.8se40.glob' glob-http+'https://bootstrap.urbit.org/glob-0v4.oicrf.rs88p.9jra8.e186l.losvv.glob'
base+'landscape' base+'landscape'
version+[1 3 5] version+[1 3 5]
website+'https://tlon.io' website+'https://tlon.io'

View File

@ -1,866 +0,0 @@
:: ethereum: utilities
::
=, ethereum-types
|%
:: deriving and using ethereum keys
::
++ key
|%
++ address-from-pub
=, keccak:crypto
|= pub=@
%+ end [3 20]
%+ keccak-256 64
(rev 3 64 pub)
::
++ address-from-prv
(cork pub-from-prv address-from-pub)
::
++ pub-from-prv
=, secp256k1:secp:crypto
|= prv=@
%- serialize-point
(priv-to-pub prv)
::
++ sign-transaction
=, crypto
|= [tx=transaction:rpc pk=@]
^- @ux
:: hash the raw transaction data
=/ hash=@
=/ dat=@
%- encode-atoms:rlp
:: with v=chain-id, r=0, s=0
tx(chain-id [chain-id.tx 0 0 ~])
=+ wid=(met 3 dat)
%- keccak-256:keccak
[wid (rev 3 wid dat)]
:: sign transaction hash with private key
=+ (ecdsa-raw-sign:secp256k1:secp hash pk)
:: complete transaction is raw data, with r and s
:: taken from the signature, and v as per eip-155
%- encode-atoms:rlp
tx(chain-id [:(add (mul chain-id.tx 2) 35 v) r s ~])
--
::
:: rlp en/decoding
::NOTE https://github.com/ethereum/wiki/wiki/RLP
::
++ rlp
|%
::NOTE rlp encoding doesn't really care about leading zeroes,
:: but because we need to disinguish between no-bytes zero
:: and one-byte zero (and also empty list) we end up with
:: this awful type...
+$ item
$% [%l l=(list item)]
[%b b=byts]
==
:: +encode-atoms: encode list of atoms as a %l of %b items
::
++ encode-atoms
|= l=(list @)
^- @
%+ encode %l
%+ turn l
|=(a=@ b+[(met 3 a) a])
::
++ encode
|= in=item
|^ ^- @
?- -.in
%b
?: &(=(1 wid.b.in) (lte dat.b.in 0x7f))
dat.b.in
=- (can 3 ~[b.in [(met 3 -) -]])
(encode-length wid.b.in 0x80)
::
%l
=/ out=@
%+ roll l.in
|= [ni=item en=@]
(cat 3 (encode ni) en)
%^ cat 3 out
(encode-length (met 3 out) 0xc0)
==
::
++ encode-length
|= [len=@ off=@]
?: (lth len 56) (add len off)
=- (cat 3 len -)
:(add (met 3 len) off 55)
--
:: +decode-atoms: decode expecting a %l of %b items, producing atoms within
::
++ decode-atoms
|= dat=@
^- (list @)
=/ i=item (decode dat)
~| [%unexpected-data i]
?> ?=(%l -.i)
%+ turn l.i
|= i=item
~| [%unexpected-list i]
?> ?=(%b -.i)
dat.b.i
::
++ decode
|= dat=@
^- item
=/ bytes=(list @) (flop (rip 3 dat))
=? bytes ?=(~ bytes) ~[0]
|^ item:decode-head
::
++ decode-head
^- [done=@ud =item]
?~ bytes
~| %rlp-unexpected-end
!!
=* byt i.bytes
:: byte in 0x00-0x79 range encodes itself
::
?: (lte byt 0x79)
:- 1
[%b 1^byt]
:: byte in 0x80-0xb7 range encodes string length
::
?: (lte byt 0xb7)
=+ len=(sub byt 0x80)
:- +(len)
:- %b
len^(get-value 1 len)
:: byte in 0xb8-0xbf range encodes string length length
::
?: (lte byt 0xbf)
=+ led=(sub byt 0xb7)
=+ len=(get-value 1 led)
:- (add +(led) len)
:- %b
len^(get-value +(led) len)
:: byte in 0xc0-f7 range encodes list length
::
?: (lte byt 0xf7)
=+ len=(sub byt 0xc0)
:- +(len)
:- %l
%. len
decode-list(bytes (slag 1 `(list @)`bytes))
:: byte in 0xf8-ff range encodes list length length
::
?: (lte byt 0xff)
=+ led=(sub byt 0xf7)
=+ len=(get-value 1 led)
:- (add +(led) len)
:- %l
%. len
decode-list(bytes (slag +(led) `(list @)`bytes))
~| [%rip-not-bloq-3 `@ux`byt]
!!
::
++ decode-list
|= rem=@ud
^- (list item)
?: =(0 rem) ~
=+ ^- [don=@ud =item] ::TODO =/
decode-head
:- item
%= $
rem (sub rem don)
bytes (slag don bytes)
==
::
++ get-value
|= [at=@ud to=@ud]
^- @
(rep 3 (flop (swag [at to] bytes)))
--
--
::
:: abi en/decoding
::NOTE https://solidity.readthedocs.io/en/develop/abi-spec.html
::
++ abi
=> |%
:: solidity types. integer bitsizes ignored
++ etyp
$@ $? :: static
%address %bool
%int %uint
%real %ureal
:: dynamic
%bytes %string
==
$% :: static
[%bytes-n n=@ud]
:: dynamic
[%array-n t=etyp n=@ud]
[%array t=etyp]
==
::
:: solidity-style typed data. integer bitsizes ignored
++ data
$% [%address p=address]
[%string p=tape]
[%bool p=?]
[%int p=@sd]
[%uint p=@ud]
[%real p=@rs]
[%ureal p=@urs]
[%array-n p=(list data)]
[%array p=(list data)]
[%bytes-n p=octs] ::TODO just @, because context knows length?
[%bytes p=octs]
==
--
=, mimes:html
|%
:: encoding
::
++ encode-args
:: encode list of arguments.
::
|= das=(list data)
^- tape
(encode-data [%array-n das])
::
++ encode-data
:: encode typed data into ABI bytestring.
::
|= dat=data
^- tape
?+ -.dat
~| [%unsupported-type -.dat]
!!
::
%array-n
:: enc(X) = head(X[0]) ... head(X[k-1]) tail(X[0]) ... tail(X[k-1])
:: where head and tail are defined for X[i] being of a static type as
:: head(X[i]) = enc(X[i]) and tail(X[i]) = "" (the empty string), or as
:: head(X[i]) = enc(len( head(X[0])..head(X[k-1])
:: tail(X[0])..tail(X[i-1]) ))
:: and tail(X[i]) = enc(X[i]) otherwise.
::
:: so: if it's a static type, data goes in the head. if it's a dynamic
:: type, a reference goes into the head and data goes into the tail.
::
:: in the head, we first put a placeholder where references need to go.
=+ hol=(reap 64 'x')
=/ hes=(list tape)
%+ turn p.dat
|= d=data
?. (is-dynamic-type d) ^$(dat d)
hol
=/ tas=(list tape)
%+ turn p.dat
|= d=data
?. (is-dynamic-type d) ""
^$(dat d)
:: once we know the head and tail, we can fill in the references in head.
=- (weld nes `tape`(zing tas))
^- [@ud nes=tape]
=+ led=(lent (zing hes))
%+ roll hes
|= [t=tape i=@ud nes=tape]
:- +(i)
:: if no reference needed, just put the data.
?. =(t hol) (weld nes t)
:: calculate byte offset of data we need to reference.
=/ ofs=@ud
=- (div - 2) :: two hex digits per byte.
%+ add led :: count head, and
%- lent %- zing :: count all tail data
(scag i tas) :: preceding ours.
=+ ref=^$(dat [%uint ofs])
:: shouldn't hit this unless we're sending over 2gb of data?
~| [%weird-ref-lent (lent ref)]
?> =((lent ref) (lent hol))
(weld nes ref)
::
%array :: where X has k elements (k is assumed to be of type uint256):
:: enc(X) = enc(k) enc([X[1], ..., X[k]])
:: i.e. it is encoded as if it were an array of static size k, prefixed
:: with the number of elements.
%+ weld $(dat [%uint (lent p.dat)])
$(dat [%array-n p.dat])
::
%bytes-n
:: enc(X) is the sequence of bytes in X padded with zero-bytes to a
:: length of 32.
:: Note that for any X, len(enc(X)) is a multiple of 32.
~| [%bytes-n-too-long max=32 actual=p.p.dat]
?> (lte p.p.dat 32)
(pad-to-multiple (render-hex-bytes p.dat) 64 %right)
::
%bytes :: of length k (which is assumed to be of type uint256)
:: enc(X) = enc(k) pad_right(X), i.e. the number of bytes is encoded as a
:: uint256 followed by the actual value of X as a byte sequence, followed
:: by the minimum number of zero-bytes such that len(enc(X)) is a
:: multiple of 32.
%+ weld $(dat [%uint p.p.dat])
(pad-to-multiple (render-hex-bytes p.dat) 64 %right)
::
%string
:: enc(X) = enc(enc_utf8(X)), i.e. X is utf-8 encoded and this value is
:: interpreted as of bytes type and encoded further. Note that the length
:: used in this subsequent encoding is the number of bytes of the utf-8
:: encoded string, not its number of characters.
$(dat [%bytes (lent p.dat) (swp 3 (crip p.dat))])
::
%uint
:: enc(X) is the big-endian encoding of X, padded on the higher-order
:: (left) side with zero-bytes such that the length is a multiple of 32
:: bytes.
(pad-to-multiple (render-hex-bytes (as-octs p.dat)) 64 %left)
::
%bool
:: as in the uint8 case, where 1 is used for true and 0 for false
$(dat [%uint ?:(p.dat 1 0)])
::
%address
:: as in the uint160 case
$(dat [%uint `@ud`p.dat])
==
::
++ is-dynamic-type
|= a=data
?. ?=(%array-n -.a)
?=(?(%string %bytes %array) -.a)
&(!=((lent p.a) 0) (lien p.a is-dynamic-type))
::
:: decoding
::
++ decode-topics decode-arguments
::
++ decode-results
:: rex: string of hex bytes with leading 0x.
|* [rex=@t tys=(list etyp)]
=- (decode-arguments - tys)
%^ rut 9
(rsh [3 2] rex)
(curr rash hex)
::
++ decode-arguments
|* [wos=(list @) tys=(list etyp)]
=/ wos=(list @) wos :: get rid of tmi
=| win=@ud
=< (decode-from 0 tys)
|%
++ decode-from
|* [win=@ud tys=(list etyp)]
?~ tys !!
=- ?~ t.tys dat
[dat $(win nin, tys t.tys)]
(decode-one win ~[i.tys])
::
++ decode-one
::NOTE we take (list etyp) even though we only operate on
:: a single etyp as a workaround for urbit/arvo#673
|* [win=@ud tys=(list etyp)]
=- [nin dat]=- ::NOTE ^= regular form broken
?~ tys !!
=* typ i.tys
=+ wor=(snag win wos)
?+ typ
~| [%unsupported-type typ]
!!
::
?(%address %bool %uint) :: %int %real %ureal
:- +(win)
?- typ
%address `@ux`wor
%uint `@ud`wor
%bool =(1 wor)
==
::
%string
=+ $(tys ~[%bytes])
[nin (trip (swp 3 q.dat))]
::
%bytes
:- +(win)
:: find the word index of the actual data.
=/ lic=@ud (div wor 32)
:: learn the bytelength of the data.
=/ len=@ud (snag lic wos)
(decode-bytes-n +(lic) len)
::
[%bytes-n *]
:- (add win +((div (dec n.typ) 32)))
(decode-bytes-n win n.typ)
::
[%array *]
:- +(win)
:: find the word index of the actual data.
=. win (div wor 32)
:: read the elements from their location.
%- tail
%^ decode-array-n ~[t.typ] +(win)
(snag win wos)
::
[%array-n *]
(decode-array-n ~[t.typ] win n.typ)
==
::
++ decode-bytes-n
|= [fro=@ud bys=@ud]
^- octs
:: parse {bys} bytes from {fro}.
:- bys
%+ rsh
:- 3
=+ (mod bys 32)
?:(=(0 -) - (sub 32 -))
%+ rep 8
%- flop
=- (swag [fro -] wos)
+((div (dec bys) 32))
::
++ decode-array-n
::NOTE we take (list etyp) even though we only operate on
:: a single etyp as a workaround for urbit/arvo#673
::NOTE careful! produces lists without type info
=| res=(list)
|* [tys=(list etyp) fro=@ud len=@ud]
^- [@ud (list)]
?~ tys !!
?: =(len 0) [fro (flop `(list)`res)]
=+ (decode-one fro ~[i.tys]) :: [nin=@ud dat=*]
$(res ^+(res [dat res]), fro nin, len (dec len))
--
--
::
:: communicating with rpc nodes
::NOTE https://github.com/ethereum/wiki/wiki/JSON-RPC
::
++ rpc
:: types
::
=> =, abi
=, format
|%
:: raw call data
++ call-data
$: function=@t
arguments=(list data)
==
::
:: raw transaction data
+$ transaction
$: nonce=@ud
gas-price=@ud
gas=@ud
to=address
value=@ud
data=@ux
chain-id=@ux
==
::
:: ethereum json rpc api
::
:: supported requests.
++ request
$% [%eth-block-number ~]
[%eth-call cal=call deb=block]
$: %eth-new-filter
fro=(unit block)
tob=(unit block)
adr=(list address)
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 ?(@ux (list @ux)))
==
$: %eth-get-logs-by-hash
has=@
adr=(list address)
top=(list ?(@ux (list @ux)))
==
[%eth-get-filter-changes fid=@ud]
[%eth-get-transaction-count adr=address =block]
[%eth-get-transaction-receipt txh=@ux]
[%eth-send-raw-transaction dat=@ux]
==
::
::TODO clean up & actually use
++ response
$% ::TODO
[%eth-new-filter fid=@ud]
[%eth-get-filter-logs los=(list event-log)]
[%eth-get-logs los=(list event-log)]
[%eth-get-logs-by-hash los=(list event-log)]
[%eth-got-filter-changes los=(list event-log)]
[%eth-transaction-hash haz=@ux]
==
::
++ event-log
$: :: null for pending logs
$= mined %- unit
$: log-index=@ud
transaction-index=@ud
transaction-hash=@ux
block-number=@ud
block-hash=@ux
removed=?
==
::
address=@ux
data=@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.
++ call
$: from=(unit address)
to=address
gas=(unit @ud)
gas-price=(unit @ud)
value=(unit @ud)
data=tape
==
::
:: minimum data needed to construct a read call
++ proto-read-request
$: id=(unit @t)
to=address
call-data
==
::
:: block to operate on.
++ block
$% [%number n=@ud]
[%label l=?(%earliest %latest %pending)]
==
--
::
:: logic
::
|%
++ encode-call
|= call-data
^- tape
::TODO should this check to see if the data matches the function signature?
=- :(weld "0x" - (encode-args arguments))
%+ scag 8
%+ render-hex-bytes 32
%- keccak-256:keccak:crypto
(as-octs:mimes:html function)
::
:: building requests
::
++ json-request
=, eyre
|= [url=purl jon=json]
^- hiss
:^ url %post
%- ~(gas in *math)
~['Content-Type'^['application/json']~]
(some (as-octt (en-json:html jon)))
:: +light-json-request: like json-request, but for %l
::
:: TODO: Exorcising +purl from our system is a much longer term effort;
:: get the current output types for now.
::
++ light-json-request
|= [url=purl:eyre jon=json]
^- request:http
::
:* %'POST'
(crip (en-purl:html url))
~[['content-type' 'application/json']]
(some (as-octt (en-json:html jon)))
==
::
++ batch-read-request
|= req=(list proto-read-request)
^- json
a+(turn req read-request)
::
++ read-request
|= proto-read-request
^- json
%+ request-to-json id
:+ %eth-call
^- call
[~ to ~ ~ ~ `tape`(encode-call function arguments)]
[%label %latest]
::
++ request-to-json
=, enjs:format
|= [riq=(unit @t) req=request]
^- json
%- pairs
=; r=[met=@t pas=(list json)]
::TODO should use request-to-json:rpc:jstd,
:: and probably (fall riq -.req)
:* jsonrpc+s+'2.0'
method+s+met.r
params+a+pas.r
::TODO would just jamming the req noun for id be a bad idea?
?~ riq ~
[id+s+u.riq]~
==
?- -.req
%eth-block-number
['eth_blockNumber' ~]
::
%eth-call
:- 'eth_call'
:~ (eth-call-to-json cal.req)
(block-to-json deb.req)
==
::
%eth-new-filter
:- 'eth_newFilter'
:_ ~
:- %o %- ~(gas by *(map @t json))
=- (murn - same)
^- (list (unit (pair @t json)))
:~ ?~ fro.req ~
`['fromBlock' (block-to-json u.fro.req)]
::
?~ tob.req ~
`['toBlock' (block-to-json u.tob.req)]
::
::TODO fucking tmi
?: =(0 (lent adr.req)) ~
:+ ~ 'address'
?: =(1 (lent adr.req)) (tape (address-to-hex (snag 0 adr.req)))
:- %a
(turn adr.req (cork address-to-hex tape))
::
?~ top.req ~
:+ ~ '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
['eth_getFilterLogs' (tape (num-to-hex fid.req)) ~]
::
%eth-get-logs
:- 'eth_getLogs'
:_ ~
:- %o %- ~(gas by *(map @t json))
=- (murn - same)
^- (list (unit (pair @t json)))
:~ ?~ fro.req ~
`['fromBlock' (block-to-json u.fro.req)]
::
?~ tob.req ~
`['toBlock' (block-to-json u.tob.req)]
::
?: =(0 (lent adr.req)) ~
:+ ~ 'address'
?: =(1 (lent adr.req)) (tape (address-to-hex (snag 0 adr.req)))
:- %a
(turn adr.req (cork address-to-hex tape))
::
?~ top.req ~
:+ ~ 'topics'
(topics-to-json top.req)
==
::
%eth-get-logs-by-hash
:- 'eth_getLogs'
:_ ~ :- %o
%- ~(gas by *(map @t json))
=- (murn - same)
^- (list (unit (pair @t json)))
:~ `['blockHash' (tape (transaction-to-hex has.req))]
::
?: =(0 (lent adr.req)) ~
:+ ~ 'address'
?: =(1 (lent adr.req)) (tape (address-to-hex (snag 0 adr.req)))
:- %a
(turn adr.req (cork address-to-hex tape))
::
?~ top.req ~
:+ ~ 'topics'
(topics-to-json top.req)
==
::
%eth-get-filter-changes
['eth_getFilterChanges' (tape (num-to-hex fid.req)) ~]
::
%eth-get-transaction-count
:- 'eth_getTransactionCount'
:~ (tape (address-to-hex adr.req))
(block-to-json block.req)
==
::
%eth-get-transaction-receipt
['eth_getTransactionReceipt' (tape (transaction-to-hex txh.req)) ~]
::
%eth-send-raw-transaction
['eth_sendRawTransaction' (tape (num-to-hex dat.req)) ~]
==
::
++ eth-call-to-json
=, enjs:format
|= cal=call
^- json
:- %o %- ~(gas by *(map @t json))
=- (murn - same)
^- (list (unit (pair @t json)))
:~ ?~ from.cal ~
`['from' (tape (address-to-hex u.from.cal))]
::
`['to' (tape (address-to-hex to.cal))]
::
?~ gas.cal ~
`['gas' (tape (num-to-hex u.gas.cal))]
::
?~ gas-price.cal ~
`['gasPrice' (tape (num-to-hex u.gas-price.cal))]
::
?~ value.cal ~
`['value' (tape (num-to-hex u.value.cal))]
::
?~ data.cal ~
`['data' (tape data.cal)]
==
::
++ block-to-json
|= dob=block
^- json
?- -.dob
%number s+(crip '0' 'x' ((x-co:co 1) n.dob))
%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
::
++ parse-hex-result
|= j=json
^- @
?> ?=(%s -.j)
(hex-to-num p.j)
::
++ parse-eth-new-filter-res parse-hex-result
::
++ parse-eth-block-number parse-hex-result
::
++ parse-transaction-hash parse-hex-result
::
++ parse-eth-get-transaction-count parse-hex-result
::
++ parse-event-logs
(ar:dejs:format parse-event-log)
::
++ parse-event-log
=, dejs:format
|= log=json
^- event-log
=- ((ot -) log)
:~ =- ['logIndex'^(cu - (mu so))]
|= li=(unit @t)
?~ li ~
=- `((ou -) log) ::TODO not sure if elegant or hacky.
:~ 'logIndex'^(un (cu hex-to-num so))
'transactionIndex'^(un (cu hex-to-num so))
'transactionHash'^(un (cu hex-to-num so))
'blockNumber'^(un (cu hex-to-num so))
'blockHash'^(un (cu hex-to-num so))
'removed'^(uf | bo)
==
::
address+(cu hex-to-num so)
data+so
::
=- topics+(cu - (ar so))
|= r=(list @t)
^- (lest @ux)
?> ?=([@t *] r)
:- (hex-to-num i.r)
(turn t.r hex-to-num)
==
--
::
:: utilities
::TODO give them better homes!
::
++ num-to-hex
|= n=@
^- tape
%- prefix-hex
?: =(0 n)
"0"
%- render-hex-bytes
(as-octs:mimes:html n)
::
++ address-to-hex
|= a=address
^- tape
%- prefix-hex
(render-hex-bytes 20 `@`a)
::
++ transaction-to-hex
|= h=@
^- tape
%- prefix-hex
(render-hex-bytes 32 h)
::
++ prefix-hex
|= a=tape
^- tape
['0' 'x' a]
::
++ render-hex-bytes
:: atom to string of hex bytes without 0x prefix and dots.
|= a=octs
^- tape
((x-co:co (mul 2 p.a)) q.a)
::
++ pad-to-multiple
|= [wat=tape mof=@ud wer=?(%left %right)]
^- tape
=+ len=(lent wat)
?: =(0 len) (reap mof '0')
=+ mad=(mod len mof)
?: =(0 mad) wat
=+ tad=(reap (sub mof mad) '0')
%- weld
?:(?=(%left wer) [tad wat] [wat tad])
::
++ hex-to-num
|= a=@t
(rash (rsh [3 2] a) hex)
--

View File

@ -0,0 +1 @@
../../base-dev/lib/ethereum.hoon

View File

@ -1,562 +0,0 @@
/- sur=hark-store, post
/+ resource, graph-store, group-store
^?
=< [. sur]
=, sur
|%
++ upgrade
|%
++ to-three
=* two state-two
=* three state-three
|%
++ index
|= =index:two
^- (unit index:three)
`index
++ contents
|= =contents:two
^- (unit contents:three)
?. ?=(%group -.contents)
`contents
=- ?: =(~ -) ~
`[%group -]
%+ murn list.contents
|= =group-contents:two
^- (unit group-contents:three)
?: ?=(?(%add %remove) -.group-contents)
~
`group-contents
::
++ stats-index
|= =stats-index:two
^- (unit stats-index:three)
`stats-index
::
++ notifications
upg-notifications:upg
::
++ upg
%. [index stats-index contents]
%: upgrade
index:two
stats-index:two
contents:two
index:three
stats-index:three
contents:three
==
--
::
++ to-four
=* three state-three
=* four state-four
|%
++ index
|= =index:three
^- (unit index:four)
`index
++ contents
|= =contents:three
^- (unit contents:four)
?. ?=(%graph -.contents)
`contents
`[%graph (turn list.contents post-to-one:upgrade:graph-store)]
::
++ unreads-each
upg-unreads-each:upg
::
++ notifications
upg-notifications:upg
::
++ stats-index
|= =stats-index:three
^- (unit stats-index:four)
`stats-index
::
++ upg
%. [index stats-index contents]
%: upgrade
index:three
stats-index:three
contents:three
index:four
stats-index:four
contents:four
==
--
::
++ to-five
=* four state-four
=* five sur
|%
++ mark
|= module=@t
^- (unit @t)
?+ module ~
%chat `%graph-validator-chat
%publish `%graph-validator-publish
%link `%graph-validator-link
==
++ index
|= =index:four
^- (unit index:five)
?: ?=(%group -.index)
`index
=* i index
`[%graph graph.i (mark module.i) description.i index.i]
::
++ contents
|= =contents:four
^- (unit contents:five)
`contents
::
++ unreads-each
upg-unreads-each:upg
::
++ stats-index
|= =stats-index:four
^- (unit stats-index:five)
`stats-index
::
++ upg
%. [index stats-index contents]
%: upgrade
index:four
stats-index:four
contents:four
index:five
stats-index:five
contents:five
==
++ notifications
upg-notifications:upg
--
::
++ upgrade
|* $: :: input molds
in-index=mold
in-stats-index=mold
in-contents=mold
:: output molds
out-index=mold
out-stats-index=mold
out-contents=mold
==
=> . =>
|%
::
++ in
|%
::
+$ index in-index
+$ stats-index in-stats-index
+$ contents in-contents
+$ unreads-each (jug stats-index index)
+$ timebox (map index notification)
+$ notification
[date=@da read=? =contents]
++ orm
((ordered-map time timebox) gth)
+$ notifications
((mop time timebox) gth)
--
++ out
|%
::
::
+$ index out-index
+$ stats-index out-stats-index
+$ contents out-contents
+$ timebox (map out-index notification)
+$ unreads-each (jug stats-index index)
+$ notification
[date=@da read=? contents=out-contents]
+$ notifications
((mop time timebox) gth)
++ orm
((ordered-map time timebox) gth)
--
--
|= $: fun-index=$-(index:in (unit index:out))
fun-stats-index=$-(stats-index:in (unit stats-index:out))
fun-contents=$-(contents:in (unit contents:out))
==
|%
::
++ upg-unreads-each
|= =unreads-each:in
^- unreads-each:out
%- ~(gas by *unreads-each:out)
%+ murn ~(tap by unreads-each)
|= [=stats-index:in indices=(set index:in)]
^- (unit [stats-index:out (set index:out)])
=/ new-stats
(fun-stats-index stats-index)
?~ new-stats ~
=/ new-indices
(upg-indices indices)
?: =(0 ~(wyt ^in new-indices)) ~
`[u.new-stats new-indices]
::
++ upg-indices
|= indices=(set index:in)
^- (set index:out)
%- ~(gas ^in *(set index:out))
(murn ~(tap ^in indices) fun-index)
::
++ upg-notifications
|= =notifications:in
^- notifications:out
%+ gas:orm:out *notifications:out
^- (list [@da timebox:out])
%+ murn (tap:orm:in notifications)
|= [time=@da =timebox:in]
^- (unit [@da =timebox:out])
=/ new-timebox=timebox:out
(upg-timebox timebox)
?: =(0 ~(wyt by timebox))
~
`[time new-timebox]
::
++ upg-timebox
|= =timebox:in
^- timebox:out
%- ~(gas by *timebox:out)
%+ murn ~(tap by timebox)
|= [=index:in =notification:in]
^- (unit [index:out notification:out])
=/ new-index
(fun-index index)
?~ new-index ~
=/ new-notification
(upg-notification notification)
?~ new-notification ~
`[u.new-index u.new-notification]
::
++ upg-notification
|= n=notification:in
^- (unit notification:out)
=/ new-contents
(fun-contents contents.n)
?~ new-contents ~
`[date.n read.n u.new-contents]
--
--
++ dejs
=, dejs:format
|%
++ index
%- of
:~ graph+graph-index
group+group-index
==
::
++ group-index
%- ot
:~ group+dejs-path:resource
description+so
==
::
++ graph-index
%- ot
:~ graph+dejs-path:resource
mark+(mu so)
description+so
index+(su ;~(pfix fas (more fas dem)))
==
::
++ stats-index
%- of
:~ graph+graph-stats-index
group+dejs-path:resource
==
++ graph-stats-index
%- ot
:~ graph+dejs-path:resource
index+graph-store-index
==
:: parse date as @ud
:: TODO: move to zuse
++ sd
|= jon=json
^- @da
?> ?=(%s -.jon)
`@da`(rash p.jon dem:ag)
::
++ notif-ref
^- $-(json [(unit @da) ^index])
%- ot
:~ time+(mu sd)
index+index
==
++ graph-store-index
(su ;~(pfix fas (more fas dem)))
::
++ add
|= jon=json
[*^index *notification]
::
++ read-graph-index
%- ot
:~ index+stats-index
target+graph-store-index
==
::
++ action
^- $-(json ^action)
%- of
:~ seen+ul
archive+notif-ref
read-note+index
add-note+add
set-dnd+bo
read-count+stats-index
read-graph+dejs-path:resource
read-group+dejs-path:resource
read-each+read-graph-index
read-all+ul
==
--
::
++ enjs
=, enjs:format
|%
++ update
|= upd=^update
^- json
|^
%+ frond -.upd
?+ -.upd a+~
%added (added +.upd)
%timebox (timebox +.upd)
%set-dnd b+dnd.upd
%count (numb count.upd)
%more (more +.upd)
%read-each (read-each +.upd)
%read-count (stats-index +.upd)
%unread-each (unread-each +.upd)
%unread-count (unread-count +.upd)
%remove-graph s+(enjs-path:resource +.upd)
%seen-index (seen-index +.upd)
%unreads (unreads +.upd)
%read-note (index +.upd)
%note-read (note-read +.upd)
::
%archive
(notif-ref +.upd)
==
::
++ note-read
|= [tim=@da idx=^index]
%- pairs
:~ time+s+(scot %ud tim)
index+(index idx)
==
::
++ stats-index
|= s=^stats-index
%+ frond -.s
|^
?- -.s
%graph (graph-stats-index +.s)
%group s+(enjs-path:resource +.s)
==
::
++ graph-stats-index
|= [graph=resource =index:graph-store]
%- pairs
:~ graph+s+(enjs-path:resource graph)
index+(index:enjs:graph-store index)
==
--
::
++ unreads
|= l=(list [^stats-index ^stats])
^- json
:- %a
^- (list json)
%+ turn l
|= [idx=^stats-index s=^stats]
%- pairs
:~ stats+(stats s)
index+(stats-index idx)
==
::
++ unread
|= =^unreads
%+ frond
-.unreads
?- -.unreads
%each a+(turn ~(tap by indices.unreads) index:enjs:graph-store)
::
%count
(numb num.unreads)
==
::
++ stats
|= s=^stats
^- json
%- pairs
:~ unreads+(unread unreads.s)
last+(time last-seen.s)
==
++ added
|= [idx=^index not=^notification]
^- json
%- pairs
:~ index+(index idx)
notification+(notification not)
==
::
++ notif-ref
|= [tim=(unit @da) idx=^index]
^- json
%- pairs
:~ [%time ?~(tim ~ s+(scot %ud u.tim))]
index+(index idx)
==
++ seen-index
|= [tim=@da idx=^stats-index]
^- json
%- pairs
:~ time+(time tim)
index+(stats-index idx)
==
::
++ more
|= upds=(list ^update)
^- json
a+(turn upds update)
::
++ index
|= =^index
%+ frond -.index
|^
?- -.index
%graph (graph-index +.index)
%group (group-index +.index)
==
::
++ graph-index
|= $: graph=resource
mark=(unit mark)
description=@t
idx=index:graph-store
==
^- json
%- pairs
:~ graph+s+(enjs-path:resource graph)
mark+s+(fall mark '')
description+s+description
index+(index:enjs:graph-store idx)
==
::
++ group-index
|= [group=resource description=@t]
^- json
%- pairs
:~ group+s+(enjs-path:resource group)
description+s+description
==
--
::
++ notification
|= ^notification
^- json
%- pairs
:~ time+(time date)
contents+(^contents contents)
==
::
++ contents
|= =^contents
^- json
%+ frond -.contents
|^
?- -.contents
%graph (graph-contents +.contents)
%group (group-contents +.contents)
==
::
++ graph-contents
|= =(list post:post)
^- json
:- %a
(turn list post:enjs:graph-store)
::
++ group-contents
|= =(list ^group-contents)
^- json
:- %a
%+ turn list
|= =^group-contents
(update:enjs:group-store group-contents)
--
::
++ indexed-notification
|= [=^index =^notification]
%- pairs
:~ index+(^index index)
notification+(^notification notification)
==
::
++ timebox
|= [tim=(unit @da) l=(list [^index ^notification])]
^- json
%- pairs
:~ time+`json`?~(tim ~ s+(scot %ud u.tim))
:- %notifications
^- json
:- %a
%+ turn l
|= [=^index =^notification]
^- json
(indexed-notification index notification)
==
::
++ read-each
|= [s=^stats-index target=index:graph-store]
%- pairs
:~ index+(stats-index s)
target+(index:enjs:graph-store target)
==
::
++ unread-each
|= [s=^stats-index target=index:graph-store tim=@da]
%- pairs
:~ index+(stats-index s)
target+(index:enjs:graph-store target)
last+(time tim)
==
::
++ unread-count
|= [s=^stats-index tim=@da]
%- pairs
:~ index+(stats-index s)
last+(time tim)
==
--
--
::
++ to-stats-index
|= =index
^- stats-index
?- -.index
%graph [%graph graph.index index.index]
%group [%group group.index]
==
++ stats-index-is-index
|= [=stats-index =index]
?- -.index
%graph
?. ?=(%graph -.stats-index) %.n
=([graph index]:index [graph index]:stats-index)
::
%group
?. ?=(%group -.stats-index) %.n
=(group:index group:stats-index)
==
--

View File

@ -1 +0,0 @@
../../base-dev/lib/treaty.hoon

View File

@ -1,13 +0,0 @@
/+ *hark-store
|_ act=action
++ grad %noun
++ grow
|%
++ noun act
--
++ grab
|%
++ noun action
++ json action:dejs
--
--

View File

@ -1,15 +0,0 @@
/+ *hark-store
|_ upd=update
++ grad %noun
++ grow
|%
++ noun upd
++ json
%+ frond:enjs:format 'harkUpdate'
(update:enjs upd)
--
++ grab
|%
++ noun update
--
--

View File

@ -1,21 +0,0 @@
:: json-rpc: protocol types
::
|%
+$ request
$: id=@t
method=@t
params=request-params
==
::
+$ request-params
$% [%list (list json)]
[%object (list (pair @t json))]
==
+$ response
$~ [%fail *httr:eyre]
$% [%result id=@t res=json]
[%error id=@t code=@t message=@t] ::TODO data?
[%fail hit=httr:eyre]
[%batch bas=(list response)]
==
--

View File

@ -1,95 +0,0 @@
:: Note: these are for BTC testnet
::
/- spider, rpc=json-rpc
/+ strandio, bc=bitcoin, bcu=bitcoin-utils
=, strand=strand:spider
=>
|%
++ url1 "http://localhost:50002"
++ addr ^-(address:bc [%bech32 'bc1q39wus23jwe7m2j7xmrfr2svhrtejmsn262x3j2'])
++ btc-req
^- request:http
=, enjs:format
:* method=%'POST'
url=`@ta`(crip (weld url1 "/btc-rpc"))
header-list=['Content-Type'^'application/json' ~]
^= body
%- some
%- as-octt:mimes:html
%- en-json:html
%- pairs
:~ jsonrpc+s+'2.0'
id+s+'block-info'
method+s+'getblockchaininfo'
==
==
++ electrs-req
^- request:http
=, enjs:format
:* method=%'POST'
url=`@ta`(crip (weld url1 "/electrs-rpc"))
header-list=['Content-Type'^'application/json' ~]
^= body
%- some
%- as-octt:mimes:html
%- en-json:html
%- pairs
:~ jsonrpc+s+'2.0'
id+s+'list-unspent'
method+s+'blockchain.scripthash.listunspent'
params+a+~[[%s '34aae877286aa09828803af27ce2315e72c4888efdf74d7d067c975b7c558789']]
==
==
::
:: convert address to Electrs ScriptHash that it uses to index
:: big-endian sha256 of the output script
::
++ electrs-script-hash
|= a=address:bc
^- hexb:bc
%- flip:byt:bcu
%- sha256:bcu
(to-script-pubkey:adr:bc a)
::
++ parse-json-rpc
|= =json
^- (unit response:rpc)
=/ res=(unit [@t ^json])
%. json
=, dejs-soft:format
(ot id+so result+some ~)
?^ res `[%result u.res]
~| parse-one-response=json
:+ ~ %error %- need
%. json
=, dejs-soft:format
(ot id+so error+(ot code+no message+so ~) ~)
::
++ parse-response
|= =client-response:iris
=/ m (strand:strandio ,(unit response:rpc))
^- form:m
?> ?=(%finished -.client-response)
?~ full-file.client-response
(pure:m ~)
=/ body=@t q.data.u.full-file.client-response
=/ jon=(unit json) (de-json:html body)
?~ jon (pure:m ~)
(pure:m (parse-json-rpc u.jon))
::
++ attempt-request
|= =request:http
=/ m (strand:strandio ,~)
^- form:m
(send-request:strandio request)
--
^- thread:spider
|= arg=vase
:: =+ !<([~ a=@ud] arg)
=/ m (strand ,vase)
^- form:m
;< ~ bind:m (attempt-request electrs-req)
;< rep=client-response:iris bind:m
take-client-response:strandio
;< rpc-resp=(unit response:rpc) bind:m (parse-response rep)
(pure:m !>(rpc-resp))

View File

@ -1,13 +0,0 @@
/- spider, rpc=json-rpc
/+ strandio, bcu=bitcoin-utils
=, strand=strand:spider
=>
|%
++ blah 2
--
^- thread:spider
|= arg=vase
:: =+ !<([~ a=@ud] arg)
=/ m (strand ,vase)
^- form:m
(pure:m !>(blah))