mirror of
https://github.com/urbit/shrub.git
synced 2024-11-24 13:06:09 +03:00
Merge a3b43137d6
into release/next-userspace
This commit is contained in:
commit
26ea30e72f
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:e0c05655f47ff81c8d4985a061d3ff57526a436adf25f667432a48c5cd10d438
|
||||
size 12190347
|
||||
oid sha256:be17c5c2390ad9530245c9b479a03f3d77b6220abb2fb5132456085b5de1a758
|
||||
size 12302174
|
||||
|
@ -11,21 +11,21 @@
|
||||
::
|
||||
/- *bitcoin, json-rpc, *btc-provider
|
||||
/+ dbug, default-agent, bl=btc, groupl=group, resource
|
||||
~% %btc-provider-top ..part ~
|
||||
|%
|
||||
+$ card card:agent:gall
|
||||
+$ versioned-state
|
||||
$% state-0
|
||||
==
|
||||
::
|
||||
+$ state-0 [%0 =host-info =whitelist]
|
||||
::
|
||||
+$ card card:agent:gall
|
||||
::
|
||||
--
|
||||
%- agent:dbug
|
||||
=| state-0
|
||||
=* state -
|
||||
^- agent:gall
|
||||
=<
|
||||
~% %btc-provider-agent ..send-status ~
|
||||
|_ =bowl:gall
|
||||
+* this .
|
||||
def ~(. (default-agent this %|) bowl)
|
||||
@ -53,20 +53,115 @@
|
||||
`this(state !<(versioned-state old-state))
|
||||
::
|
||||
++ on-poke
|
||||
~/ %on-poke
|
||||
|= [=mark =vase]
|
||||
^- (quip card _this)
|
||||
|^
|
||||
?> ?|((team:title our.bowl src.bowl) (is-client:hc src.bowl))
|
||||
=^ cards state
|
||||
?+ mark (on-poke:def mark vase)
|
||||
%btc-provider-command
|
||||
?> (team:title our.bowl src.bowl)
|
||||
(handle-command:hc !<(command vase))
|
||||
(handle-command !<(command vase))
|
||||
::
|
||||
%btc-provider-action
|
||||
(handle-action:hc !<(action vase))
|
||||
(handle-action !<(action vase))
|
||||
==
|
||||
[cards this]
|
||||
::
|
||||
++ handle-command
|
||||
|= comm=command
|
||||
^- (quip card _state)
|
||||
?- -.comm
|
||||
%set-credentials
|
||||
:_ state(host-info [api-url.comm %.n network.comm 0 *(set ship)])
|
||||
:~ do-ping:hc
|
||||
(start-ping-timer:hc ~s30)
|
||||
==
|
||||
::
|
||||
%add-whitelist
|
||||
:- ~
|
||||
?- -.wt.comm
|
||||
%public
|
||||
state(public.whitelist %.y)
|
||||
::
|
||||
%kids
|
||||
state(kids.whitelist %.y)
|
||||
::
|
||||
%users
|
||||
state(users.whitelist (~(uni in users.whitelist) users.wt.comm))
|
||||
::
|
||||
%groups
|
||||
state(groups.whitelist (~(uni in groups.whitelist) groups.wt.comm))
|
||||
==
|
||||
::
|
||||
%remove-whitelist
|
||||
=. state
|
||||
?- -.wt.comm
|
||||
%public
|
||||
state(public.whitelist %.n)
|
||||
::
|
||||
%kids
|
||||
state(kids.whitelist %.n)
|
||||
::
|
||||
%users
|
||||
state(users.whitelist (~(dif in users.whitelist) users.wt.comm))
|
||||
::
|
||||
%groups
|
||||
state(groups.whitelist (~(dif in groups.whitelist) groups.wt.comm))
|
||||
==
|
||||
clean-client-list
|
||||
==
|
||||
::
|
||||
:: +clean-client-list: remove clients who are no longer whitelisted
|
||||
:: called after a whitelist change
|
||||
::
|
||||
++ clean-client-list
|
||||
^- (quip card _state)
|
||||
=/ to-kick=(set ship)
|
||||
%- silt
|
||||
%+ murn ~(tap in clients.host-info)
|
||||
|= c=ship ^- (unit ship)
|
||||
?:((is-whitelisted:hc c) ~ `c)
|
||||
:_ state(clients.host-info (~(dif in clients.host-info) to-kick))
|
||||
%+ turn ~(tap in to-kick)
|
||||
|=(c=ship [%give %kick ~[/clients] `c])
|
||||
::
|
||||
:: if not connected, only %ping action is allowed
|
||||
::
|
||||
++ handle-action
|
||||
|= act=action
|
||||
^- (quip card _state)
|
||||
:_ state
|
||||
?. ?|(connected.host-info ?=(%ping -.act))
|
||||
~& >>> "Not connected to RPC"
|
||||
~[(send-update:hc [%| %not-connected 500])]
|
||||
:_ ~
|
||||
%+ req-card act
|
||||
^- action:rpc-types
|
||||
?- -.act
|
||||
%address-info [%get-address-info address.act]
|
||||
%tx-info [%get-tx-vals txid.act]
|
||||
%raw-tx [%get-raw-tx txid.act]
|
||||
%broadcast-tx [%broadcast-tx rawtx.act]
|
||||
%ping [%get-block-info ~]
|
||||
%block-info [%get-block-info block.act]
|
||||
==
|
||||
::
|
||||
++ req-card
|
||||
|= [act=action ract=action:rpc-types]
|
||||
=/ req=request:http
|
||||
(gen-request:bl host-info ract)
|
||||
[%pass (rpc-wire act) %arvo %i %request req *outbound-config:iris]
|
||||
::
|
||||
++ rpc-wire
|
||||
|= act=action
|
||||
^- wire
|
||||
/[-.act]/[(scot %ux (cut 3 [0 20] eny.bowl))]
|
||||
--
|
||||
::
|
||||
++ on-watch
|
||||
~/ %on-watch
|
||||
|= pax=path
|
||||
^- (quip card _this)
|
||||
:: checking provider permissions before trying to subscribe
|
||||
@ -91,23 +186,100 @@
|
||||
this(clients.host-info (~(put in clients.host-info) src.bowl))
|
||||
::
|
||||
++ on-arvo
|
||||
|= [=wire =sign-arvo]
|
||||
~/ %on-arvo
|
||||
|= [wir=wire =sign-arvo]
|
||||
|^
|
||||
^- (quip card _this)
|
||||
:: check for connectivity every 30 seconds
|
||||
::
|
||||
?: ?=([%ping-timer *] wire)
|
||||
?: ?=([%ping-timer *] wir)
|
||||
:_ this
|
||||
:~ do-ping:hc
|
||||
(start-ping-timer:hc ~s30)
|
||||
==
|
||||
=^ cards state
|
||||
?+ +<.sign-arvo (on-arvo:def wire sign-arvo)
|
||||
%http-response
|
||||
(handle-rpc-response:hc wire client-response.sign-arvo)
|
||||
==
|
||||
?+ +<.sign-arvo (on-arvo:def wir sign-arvo)
|
||||
%http-response
|
||||
(handle-rpc-response wir client-response.sign-arvo)
|
||||
==
|
||||
[cards this]
|
||||
::
|
||||
:: Handles HTTP responses from RPC servers. Parses for errors,
|
||||
:: then handles response. For actions that require collating multiple
|
||||
:: RPC calls, uses req-card to call out to RPC again if more
|
||||
:: information is required.
|
||||
++ handle-rpc-response
|
||||
|= [=wire response=client-response:iris]
|
||||
^- (quip card _state)
|
||||
?. ?=(%finished -.response) `state
|
||||
=* status status-code.response-header.response
|
||||
:: handle error types: connection errors, RPC errors (in order)
|
||||
::
|
||||
=^ conn-err state
|
||||
(connection-error status)
|
||||
?^ conn-err
|
||||
:_ state(connected.host-info %.n)
|
||||
:~ (send-status:hc [%disconnected ~])
|
||||
(send-update:hc [%| u.conn-err])
|
||||
==
|
||||
::
|
||||
%+ handle-rpc-result wire
|
||||
%- parse-result:rpc:bl
|
||||
(get-rpc-response:bl response)
|
||||
::
|
||||
++ handle-rpc-result
|
||||
|= [=wire r=result:rpc-types]
|
||||
^- (quip card _state)
|
||||
?+ -.wire ~|("Unexpected HTTP response" !!)
|
||||
%address-info
|
||||
?> ?=([%get-address-info *] r)
|
||||
:_ state
|
||||
~[(send-update:hc [%.y %address-info +.r])]
|
||||
::
|
||||
%tx-info
|
||||
?> ?=([%get-tx-vals *] r)
|
||||
:_ state
|
||||
~[(send-update:hc [%.y %tx-info +.r])]
|
||||
::
|
||||
%raw-tx
|
||||
?> ?=([%get-raw-tx *] r)
|
||||
:_ state
|
||||
~[(send-update:hc [%.y %raw-tx +.r])]
|
||||
::
|
||||
%broadcast-tx
|
||||
?> ?=([%broadcast-tx *] r)
|
||||
:_ state
|
||||
~[(send-update:hc [%.y %broadcast-tx +.r])]
|
||||
::
|
||||
%ping
|
||||
?> ?=([%get-block-info *] r)
|
||||
:_ state(connected.host-info %.y, block.host-info block.r)
|
||||
:_ ~
|
||||
%- send-status:hc
|
||||
?: =(block.host-info block.r)
|
||||
[%connected network.host-info block.r fee.r]
|
||||
[%new-block network.host-info block.r fee.r blockhash.r blockfilter.r]
|
||||
::
|
||||
%block-info
|
||||
?> ?=([%get-block-info *] r)
|
||||
:_ state
|
||||
~[(send-update:hc [%.y %block-info network.host-info +.r])]
|
||||
==
|
||||
::
|
||||
++ connection-error
|
||||
|= status=@ud
|
||||
^- [(unit error) _state]
|
||||
?+ status [`[%rpc-error ~] state]
|
||||
%200 [~ state]
|
||||
%400 [`[%bad-request status] state]
|
||||
%401 [`[%no-auth status] state(connected.host-info %.n)]
|
||||
%502 [`[%not-connected status] state(connected.host-info %.n)]
|
||||
%504 [`[%not-connected status] state(connected.host-info %.n)]
|
||||
==
|
||||
--
|
||||
::
|
||||
++ on-peek
|
||||
~/ %on-peek
|
||||
|= pax=path
|
||||
^- (unit (unit cage))
|
||||
?+ pax (on-peek:def pax)
|
||||
@ -115,7 +287,7 @@
|
||||
``noun+!>((is-whitelisted:hc (ship (slav %p +>-.pax))))
|
||||
::
|
||||
[%x %is-client @t ~]
|
||||
``noun+!>((is-client (ship (slav %p +>-.pax))))
|
||||
``noun+!>((is-client:hc (ship (slav %p +>-.pax))))
|
||||
==
|
||||
::
|
||||
++ on-leave on-leave:def
|
||||
@ -123,176 +295,8 @@
|
||||
++ on-fail on-fail:def
|
||||
--
|
||||
:: helper core
|
||||
~% %btc-provider-helper ..card ~
|
||||
|_ =bowl:gall
|
||||
++ handle-command
|
||||
|= comm=command
|
||||
^- (quip card _state)
|
||||
?- -.comm
|
||||
%set-credentials
|
||||
:- :~ do-ping
|
||||
(start-ping-timer ~s30)
|
||||
==
|
||||
%= state
|
||||
host-info
|
||||
[api-url.comm connected=%.n network.comm block=0 clients=*(set ship)]
|
||||
==
|
||||
::
|
||||
%add-whitelist
|
||||
?- -.wt.comm
|
||||
%public
|
||||
`state(public.whitelist %.y)
|
||||
::
|
||||
%kids
|
||||
`state(kids.whitelist %.y)
|
||||
::
|
||||
%users
|
||||
`state(users.whitelist (~(uni in users.whitelist) users.wt.comm))
|
||||
::
|
||||
%groups
|
||||
`state(groups.whitelist (~(uni in groups.whitelist) groups.wt.comm))
|
||||
==
|
||||
::
|
||||
%remove-whitelist
|
||||
=. state
|
||||
?- -.wt.comm
|
||||
%public
|
||||
state(public.whitelist %.n)
|
||||
::
|
||||
%kids
|
||||
state(kids.whitelist %.n)
|
||||
::
|
||||
%users
|
||||
state(users.whitelist (~(dif in users.whitelist) users.wt.comm))
|
||||
::
|
||||
%groups
|
||||
state(groups.whitelist (~(dif in groups.whitelist) groups.wt.comm))
|
||||
==
|
||||
clean-client-list
|
||||
==
|
||||
:: if not connected, only %ping action is allowed
|
||||
::
|
||||
++ handle-action
|
||||
|= act=action
|
||||
^- (quip card _state)
|
||||
?. ?|(connected.host-info ?=(%ping -.act))
|
||||
~& >>> "Not connected to RPC"
|
||||
[~[(send-update [%| %not-connected 500])] state]
|
||||
::
|
||||
=/ ract=action:rpc-types
|
||||
?- -.act :: ~|("Invalid action" !!)
|
||||
%address-info
|
||||
[%get-address-info address.act]
|
||||
::
|
||||
%tx-info
|
||||
[%get-tx-vals txid.act]
|
||||
::
|
||||
%raw-tx
|
||||
[%get-raw-tx txid.act]
|
||||
::
|
||||
%broadcast-tx
|
||||
[%broadcast-tx rawtx.act]
|
||||
::
|
||||
%ping
|
||||
[%get-block-info ~]
|
||||
::
|
||||
%block-info
|
||||
[%get-block-info block.act]
|
||||
==
|
||||
[~[(req-card act ract)] state]
|
||||
::
|
||||
++ req-card
|
||||
|= [act=action ract=action:rpc-types]
|
||||
=| out=outbound-config:iris
|
||||
=/ req=request:http
|
||||
(gen-request:bl host-info ract)
|
||||
[%pass (rpc-wire act) %arvo %i %request req out]
|
||||
:: wire structure: /action-tas/now
|
||||
::
|
||||
++ rpc-wire
|
||||
|= act=action ^- wire
|
||||
/[-.act]/[(scot %ux (cut 3 [0 20] eny.bowl))]
|
||||
::
|
||||
++ kick-client
|
||||
|= client=ship
|
||||
^- (quip card _state)
|
||||
~& >>> "dropping client {<client>}"
|
||||
:- ~[[%give %kick ~[/clients] `client]]
|
||||
state(clients.host-info (~(dif in clients.host-info) (silt ~[client])))
|
||||
::
|
||||
:: Handles HTTP responses from RPC servers. Parses for errors, then handles response.
|
||||
:: For actions that require collating multiple RPC calls, uses req-card to call out
|
||||
:: to RPC again if more information is required.
|
||||
::
|
||||
++ handle-rpc-response
|
||||
|= [=wire response=client-response:iris]
|
||||
^- (quip card _state)
|
||||
?. ?=(%finished -.response) `state
|
||||
=* status status-code.response-header.response
|
||||
:: handle error types: connection errors, RPC errors (in order)
|
||||
::
|
||||
=^ conn-err state
|
||||
(connection-error status)
|
||||
?^ conn-err
|
||||
:_ state(connected.host-info %.n)
|
||||
~[(send-status [%disconnected ~]) (send-update [%| u.conn-err])]
|
||||
::
|
||||
%+ handle-rpc-result wire
|
||||
%- parse-result:rpc:bl
|
||||
(get-rpc-response:bl response)
|
||||
::
|
||||
++ connection-error
|
||||
|= status=@ud
|
||||
^- [(unit error) _state]
|
||||
?+ status [`[%rpc-error ~] state]
|
||||
%200
|
||||
[~ state]
|
||||
%400
|
||||
[`[%bad-request status] state]
|
||||
%401
|
||||
[`[%no-auth status] state(connected.host-info %.n)]
|
||||
%502
|
||||
[`[%not-connected status] state(connected.host-info %.n)]
|
||||
%504
|
||||
[`[%not-connected status] state(connected.host-info %.n)]
|
||||
==
|
||||
::
|
||||
++ handle-rpc-result
|
||||
|= [=wire r=result:rpc-types]
|
||||
^- (quip card _state)
|
||||
?+ -.wire ~|("Unexpected HTTP response" !!)
|
||||
%address-info
|
||||
?> ?=([%get-address-info *] r)
|
||||
:_ state
|
||||
~[(send-update [%.y %address-info +.r])]
|
||||
::
|
||||
%tx-info
|
||||
?> ?=([%get-tx-vals *] r)
|
||||
:_ state
|
||||
~[(send-update [%.y %tx-info +.r])]
|
||||
::
|
||||
%raw-tx
|
||||
?> ?=([%get-raw-tx *] r)
|
||||
:_ state
|
||||
~[(send-update [%.y %raw-tx +.r])]
|
||||
::
|
||||
%broadcast-tx
|
||||
?> ?=([%broadcast-tx *] r)
|
||||
:_ state
|
||||
~[(send-update [%.y %broadcast-tx +.r])]
|
||||
::
|
||||
%ping
|
||||
?> ?=([%get-block-info *] r)
|
||||
:_ state(connected.host-info %.y, block.host-info block.r)
|
||||
?: =(block.host-info block.r)
|
||||
~[(send-status [%connected network.host-info block.r fee.r])]
|
||||
~[(send-status [%new-block network.host-info block.r fee.r blockhash.r blockfilter.r])]
|
||||
::
|
||||
%block-info
|
||||
?> ?=([%get-block-info *] r)
|
||||
:_ state
|
||||
~[(send-update [%.y %block-info network.host-info +.r])]
|
||||
==
|
||||
::
|
||||
++ send-status
|
||||
|= =status ^- card
|
||||
%- ?: ?=(%new-block -.status)
|
||||
@ -305,13 +309,14 @@
|
||||
^- card
|
||||
=+ c=[%give %fact ~[/clients] %btc-provider-update !>(update)]
|
||||
?: ?=(%.y -.update)
|
||||
:: ~& >> "prov. update: {<p.update>}"
|
||||
c
|
||||
~& >> "prov. err: {<p.update>}"
|
||||
c
|
||||
::
|
||||
++ is-whitelisted
|
||||
|= user=ship ^- ?
|
||||
~/ %is-whitelisted
|
||||
|= user=ship
|
||||
^- ?
|
||||
|^
|
||||
?| public.whitelist
|
||||
=(our.bowl user)
|
||||
@ -319,8 +324,10 @@
|
||||
(~(has in users.whitelist) user)
|
||||
in-group
|
||||
==
|
||||
::
|
||||
++ is-kid
|
||||
=(our.bowl (sein:title our.bowl now.bowl user))
|
||||
::
|
||||
++ in-group
|
||||
=/ gs ~(tap in groups.whitelist)
|
||||
|-
|
||||
@ -328,28 +335,16 @@
|
||||
?: (~(is-member groupl bowl) user i.gs)
|
||||
%.y
|
||||
$(gs t.gs)
|
||||
:: .^((unit group:g) %gx ;:(weld /=group-store=/groups p /noun))
|
||||
--
|
||||
:: +clean-client-list: remove clients who are no longer whitelisted
|
||||
:: called after a whitelist change
|
||||
::
|
||||
++ clean-client-list
|
||||
^- (quip card _state)
|
||||
=/ to-kick=(set ship)
|
||||
%- silt
|
||||
%+ murn ~(tap in clients.host-info)
|
||||
|= c=ship ^- (unit ship)
|
||||
?:((is-whitelisted c) ~ `c)
|
||||
:_ state(clients.host-info (~(dif in clients.host-info) to-kick))
|
||||
%+ turn ~(tap in to-kick)
|
||||
|=(c=ship [%give %kick ~[/clients] `c])
|
||||
::
|
||||
++ is-client
|
||||
|= user=ship ^- ?
|
||||
|= user=ship
|
||||
^- ?
|
||||
(~(has in clients.host-info) user)
|
||||
::
|
||||
++ start-ping-timer
|
||||
|= interval=@dr ^- card
|
||||
|= interval=@dr
|
||||
^- card
|
||||
[%pass /ping-timer %arvo %b %wait (add now.bowl interval)]
|
||||
::
|
||||
++ do-ping
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -26,6 +26,6 @@
|
||||
<div id="portal-root"></div>
|
||||
<script src="/~landscape/js/channel.js"></script>
|
||||
<script src="/~landscape/js/session.js"></script>
|
||||
<script src="/~btc/js/bundle/index.f7ab13b7db3ec1f8b55a.js"></script>
|
||||
<script src="/~btc/js/bundle/index.b53f5e618705a4f11835.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -5,8 +5,8 @@
|
||||
/- glob, *resource
|
||||
/+ default-agent, verb, dbug
|
||||
|%
|
||||
++ landscape-hash 0v4.3us6c.ma3il.h5bch.qacg3.70qjl
|
||||
++ btc-wallet-hash 0v1.9p61c.bd4vn.deevh.0ldbq.fkqo3
|
||||
++ landscape-hash 0v7.0bqfl.auvn6.m43ts.414as.hp1j4
|
||||
++ btc-wallet-hash 0v6.h33vk.c3n1c.4gpkn.cci4c.pnh4r
|
||||
+$ state-0 [%0 hash=@uv glob=(unit (each glob:glob tid=@ta))]
|
||||
+$ state-1 [%1 =globs:glob]
|
||||
+$ all-states
|
||||
|
@ -24,6 +24,6 @@
|
||||
<div id="portal-root"></div>
|
||||
<script src="/~landscape/js/channel.js"></script>
|
||||
<script src="/~landscape/js/session.js"></script>
|
||||
<script src="/~landscape/js/bundle/index.af45eeaf465dff7d73f1.js"></script>
|
||||
<script src="/~landscape/js/bundle/index.eabec1cd16691a198a5e.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,5 +1,6 @@
|
||||
/- bc=bitcoin
|
||||
/+ bcu=bitcoin-utils
|
||||
~% %bip-158-top ..part ~
|
||||
|%
|
||||
++ params
|
||||
|%
|
||||
@ -8,6 +9,7 @@
|
||||
--
|
||||
::
|
||||
++ siphash
|
||||
~/ %siphash
|
||||
|= [k=byts m=byts]
|
||||
^- byts
|
||||
|^
|
||||
@ -86,25 +88,28 @@
|
||||
:: write appends to the back
|
||||
::
|
||||
++ str
|
||||
~% %str ..params ~
|
||||
|%
|
||||
++ read-bit
|
||||
~/ %read-bit
|
||||
|= s=bits:bc
|
||||
^- [bit=@ub rest=bits:bc]
|
||||
?> (gth wid.s 0)
|
||||
:* ?:((gth wid.s (met 0 dat.s)) 0b0 0b1)
|
||||
[(dec wid.s) (end [0 (dec wid.s)] dat.s)]
|
||||
==
|
||||
:+ ?:((gth wid.s (met 0 dat.s)) 0b0 0b1)
|
||||
(dec wid.s)
|
||||
(end [0 (dec wid.s)] dat.s)
|
||||
::
|
||||
::
|
||||
++ read-bits
|
||||
~/ %read-bits
|
||||
|= [n=@ s=bits:bc]
|
||||
^- [bits:bc rest=bits:bc]
|
||||
=| bs=bits:bc
|
||||
|-
|
||||
?: =(n 0) [bs s]
|
||||
=^ b s (read-bit s)
|
||||
$(n (dec n), bs (write-bits bs [1 b]))
|
||||
=/ r=@ (sub wid.s n)
|
||||
:- n^(cut 0 [r n] dat.s)
|
||||
r^(cut 0 [0 r] dat.s)
|
||||
::
|
||||
++ write-bits
|
||||
~/ %write-bits
|
||||
|= [s1=bits:bc s2=bits:bc]
|
||||
^- bits:bc
|
||||
[(add wid.s1 wid.s2) (can 0 ~[s2 s1])]
|
||||
@ -112,6 +117,7 @@
|
||||
:: +gol: Golomb-Rice encoding/decoding
|
||||
::
|
||||
++ gol
|
||||
~% %gol ..params ~
|
||||
|%
|
||||
:: +en: encode x and append to end of s
|
||||
:: - s: bits stream
|
||||
@ -119,6 +125,7 @@
|
||||
:: - p: golomb-rice p param
|
||||
::
|
||||
++ en
|
||||
~/ %en
|
||||
|= [s=bits:bc x=@ p=@]
|
||||
^- bits:bc
|
||||
=+ q=(rsh [0 p] x)
|
||||
@ -128,6 +135,7 @@
|
||||
(write-bits:str unary r)
|
||||
::
|
||||
++ de
|
||||
~/ %de
|
||||
|= [s=bits:bc p=@]
|
||||
^- [delta=@ rest=bits:bc]
|
||||
|^ ?> (gth wid.s 0)
|
||||
@ -148,6 +156,7 @@
|
||||
:: +hsh
|
||||
::
|
||||
++ hsh
|
||||
~% %hsh ..params ~
|
||||
|%
|
||||
:: +to-range
|
||||
:: - item: scriptpubkey to hash
|
||||
@ -155,6 +164,7 @@
|
||||
:: - k: key for siphash (end of blockhash, reversed)
|
||||
::
|
||||
++ to-range
|
||||
~/ %to-range
|
||||
|= [item=byts f=@ k=byts]
|
||||
^- @
|
||||
(rsh [0 64] (mul f (rev 3 (siphash k item))))
|
||||
@ -171,6 +181,7 @@
|
||||
--
|
||||
::
|
||||
++ parse-filter
|
||||
~/ %parse-filter
|
||||
|= filter=hexb:bc
|
||||
^- [n=@ux gcs-set=bits:bc]
|
||||
=/ n n:(de:csiz:bcu filter)
|
||||
@ -180,6 +191,7 @@
|
||||
:: +to-key: blockhash (little endian) to key for siphash
|
||||
::
|
||||
++ to-key
|
||||
~/ %to-key
|
||||
|= blockhash=tape
|
||||
^- byts
|
||||
%+ take:byt:bcu 16
|
||||
@ -191,6 +203,7 @@
|
||||
:: - targets: scriptpubkeys to match
|
||||
::
|
||||
++ match
|
||||
~/ %match
|
||||
|= [filter=hexb:bc k=byts targets=(list byts)]
|
||||
^- ?
|
||||
=/ [p=@ m=@] [p:params m:params]
|
||||
@ -214,6 +227,7 @@
|
||||
:: - targets: scriptpubkeys to match
|
||||
::
|
||||
++ all-match
|
||||
~/ %all-match
|
||||
|= [filter=hexb:bc blockhash=hexb:bc targets=(list [address:bc byts])]
|
||||
^- (set [address:bc hexb:bc])
|
||||
=/ k (to-key (trip (to-cord:hxb:bcu blockhash)))
|
||||
|
@ -1,8 +1,8 @@
|
||||
:: lib/bitcoin-utils.hoon
|
||||
:: Utilities for working with BTC data types and transactions
|
||||
::
|
||||
/- sur=bitcoin
|
||||
=, sur
|
||||
/- *bitcoin
|
||||
~% %bitcoin-utils-lib ..part ~
|
||||
|%
|
||||
::
|
||||
:: TODO: move this bit/byt stuff to zuse
|
||||
@ -12,6 +12,7 @@
|
||||
:: +blop: munge bit and byt sequences (cat, flip, take, drop)
|
||||
::
|
||||
++ blop
|
||||
~/ %blop
|
||||
|_ =bloq
|
||||
+$ biyts [wid=@ud dat=@]
|
||||
++ cat
|
||||
@ -48,6 +49,7 @@
|
||||
++ byt ~(. blop 3)
|
||||
::
|
||||
++ bit
|
||||
~/ %bit
|
||||
=/ bl ~(. blop 0)
|
||||
|%
|
||||
++ cat cat:bl:bit
|
||||
@ -79,16 +81,19 @@
|
||||
:: big endian sha256: input and output are both MSB first (big endian)
|
||||
::
|
||||
++ sha256
|
||||
~/ %sha256
|
||||
|= =byts
|
||||
^- hexb
|
||||
%- flip:byt
|
||||
[32 (shay (flip:byt byts))]
|
||||
::
|
||||
++ dsha256
|
||||
~/ %dsha256
|
||||
|= =byts
|
||||
(sha256 (sha256 byts))
|
||||
::
|
||||
++ hash-160
|
||||
~/ %hash-160
|
||||
|= val=byts
|
||||
^- hexb
|
||||
=, ripemd:crypto
|
||||
@ -100,8 +105,10 @@
|
||||
:: hxb: hex parsing utilities
|
||||
::
|
||||
++ hxb
|
||||
~% %hxb ..blop ~
|
||||
|%
|
||||
++ from-cord
|
||||
~/ %from-cord
|
||||
|= h=@t
|
||||
^- hexb
|
||||
?: =('' h) 1^0x0
|
||||
@ -113,10 +120,11 @@
|
||||
=+ (rsh [3 2] -)
|
||||
:: Parse hex to atom
|
||||
::
|
||||
:- (div (lent (trip h)) 2)
|
||||
`@ux`(rash - hex)
|
||||
=/ a (need (de:base16:mimes:html -))
|
||||
[-.a `@ux`+.a]
|
||||
::
|
||||
++ to-cord
|
||||
~/ %to-cord
|
||||
|= =hexb
|
||||
^- cord
|
||||
(en:base16:mimes:html hexb)
|
||||
@ -128,8 +136,10 @@
|
||||
:: - decode: little endian to big endian
|
||||
::
|
||||
++ csiz
|
||||
~% %csiz ..blop ~
|
||||
|%
|
||||
++ en
|
||||
~/ %en
|
||||
|= a=@
|
||||
^- hexb
|
||||
=/ l=@ (met 3 a)
|
||||
@ -140,6 +150,7 @@
|
||||
~|("Cannot encode CompactSize longer than 8 bytes" !!)
|
||||
::
|
||||
++ de
|
||||
~/ %de
|
||||
|= h=hexb
|
||||
^- [n=hexb rest=hexb]
|
||||
=/ s=@ux dat:(take:byt 1 h)
|
||||
@ -162,5 +173,4 @@
|
||||
=> (de h)
|
||||
[dat.n rest]
|
||||
--
|
||||
::
|
||||
--
|
||||
|
@ -2,13 +2,13 @@
|
||||
:: top-level Bitcoin constants
|
||||
:: expose BIP libraries
|
||||
::
|
||||
/- sur=bitcoin
|
||||
/- *bitcoin
|
||||
/+ bech32=bip-b173, pbt=bip-b174, bcu=bitcoin-utils, bip-b158
|
||||
=, sur
|
||||
=, bcu
|
||||
~% %bitcoin-lib ..part ~
|
||||
|%
|
||||
++ overhead-weight ^-(vbytes 11)
|
||||
++ input-weight
|
||||
~/ %input-weight
|
||||
|= =bipt
|
||||
^- vbytes
|
||||
?- bipt
|
||||
@ -40,8 +40,10 @@
|
||||
:: adr: address manipulation
|
||||
::
|
||||
++ adr
|
||||
~% %adr ..overhead-weight ~
|
||||
|%
|
||||
++ get-bipt
|
||||
~/ %get-bipt
|
||||
|= a=address
|
||||
^- bipt
|
||||
=/ spk=hexb (to-script-pubkey:adr a)
|
||||
@ -52,35 +54,37 @@
|
||||
~|("Invalid address" !!)
|
||||
::
|
||||
++ to-cord
|
||||
~/ %to-cord
|
||||
|= a=address ^- cord
|
||||
?: ?=([%base58 *] a)
|
||||
(scot %uc +.a)
|
||||
+.a
|
||||
::
|
||||
++ from-pubkey
|
||||
~/ %from-pubkey
|
||||
|= [=bipt =network pubkey=hexb]
|
||||
^- address
|
||||
?- bipt
|
||||
%44
|
||||
:- %base58
|
||||
=< ^-(@uc dat)
|
||||
%- cat:byt
|
||||
%- cat:byt:bcu
|
||||
:- ?- network
|
||||
%main 1^0x0
|
||||
%testnet 1^0x6f
|
||||
==
|
||||
~[(hash-160 pubkey)]
|
||||
~[(hash-160:bcu pubkey)]
|
||||
::
|
||||
%49
|
||||
:- %base58
|
||||
=< ^-(@uc dat)
|
||||
%- cat:byt
|
||||
%- cat:byt:bcu
|
||||
:~ ?- network
|
||||
%main 1^0x5
|
||||
%testnet 1^0xc4
|
||||
==
|
||||
%- hash-160
|
||||
(cat:byt ~[2^0x14 (hash-160 pubkey)])
|
||||
%- hash-160:bcu
|
||||
(cat:byt:bcu ~[2^0x14 (hash-160:bcu pubkey)])
|
||||
==
|
||||
::
|
||||
%84
|
||||
@ -89,6 +93,7 @@
|
||||
==
|
||||
::
|
||||
++ from-cord
|
||||
~/ %from-cord
|
||||
|= addrc=@t
|
||||
|^
|
||||
=/ addrt=tape (trip addrc)
|
||||
@ -117,12 +122,13 @@
|
||||
--
|
||||
::
|
||||
++ to-script-pubkey
|
||||
~/ %to-script-pubkey
|
||||
|= =address
|
||||
^- hexb
|
||||
?- -.address
|
||||
%bech32
|
||||
=+ h=(from-address:bech32 +.address)
|
||||
%- cat:byt
|
||||
%- cat:byt:bcu
|
||||
:~ 1^0x0
|
||||
1^wid.h
|
||||
h
|
||||
@ -130,21 +136,21 @@
|
||||
::
|
||||
%base58
|
||||
=/ h=hexb [21 `@ux`+.address]
|
||||
=+ lead-byt=dat:(take:byt 1 h)
|
||||
=+ lead-byt=dat:(take:byt:bcu 1 h)
|
||||
=/ version-network=[bipt network]
|
||||
?: =(0x0 lead-byt) [%44 %main]
|
||||
?: =(0x6f lead-byt) [%44 %testnet]
|
||||
?: =(0x5 lead-byt) [%49 %main]
|
||||
?: =(0xc4 lead-byt) [%49 %testnet]
|
||||
~|("Invalid base58 address: {<+.address>}" !!)
|
||||
%- cat:byt
|
||||
%- cat:byt:bcu
|
||||
?: ?=(%44 -.version-network)
|
||||
:~ 3^0x76.a914
|
||||
(drop:byt 1 h)
|
||||
(drop:byt:bcu 1 h)
|
||||
2^0x88ac
|
||||
==
|
||||
:~ 2^0xa914
|
||||
(drop:byt 1 h)
|
||||
(drop:byt:bcu 1 h)
|
||||
1^0x87
|
||||
==
|
||||
==
|
||||
@ -155,6 +161,8 @@
|
||||
:: - ignores signatures in inputs
|
||||
::
|
||||
++ txu
|
||||
~% %bitcoin-lib-txu ..overhead-weight ~
|
||||
=, bcu
|
||||
|%
|
||||
++ en
|
||||
|%
|
||||
|
@ -1,8 +1,6 @@
|
||||
/- bp=btc-provider, json-rpc
|
||||
/+ bc=bitcoin
|
||||
^?
|
||||
::=< [sur .]
|
||||
::=, sur
|
||||
/+ bc=bitcoin, bcu=bitcoin-utils
|
||||
~% %btc-provider-lib ..part ~
|
||||
|%
|
||||
:: +from-epoch: time since Jan 1, 1970 in seconds.
|
||||
::
|
||||
@ -25,8 +23,8 @@
|
||||
~[['Content-Type' 'application/json']]
|
||||
=, html
|
||||
%- some
|
||||
%- as-octt:mimes
|
||||
(en-json body)
|
||||
%- as-octt:mimes
|
||||
(en-json body)
|
||||
==
|
||||
::
|
||||
++ gen-request
|
||||
@ -36,6 +34,7 @@
|
||||
api-url.host-info ract
|
||||
::
|
||||
++ rpc
|
||||
~/ %rpc
|
||||
=, dejs:format
|
||||
|%
|
||||
++ parse-result
|
||||
@ -62,6 +61,7 @@
|
||||
%get-block-info
|
||||
[id.res (block-info res.res)]
|
||||
==
|
||||
::
|
||||
++ address-info
|
||||
%- ot
|
||||
:~ [%address (cu from-cord:adr:bc so)]
|
||||
@ -69,47 +69,53 @@
|
||||
[%used bo]
|
||||
[%block ni]
|
||||
==
|
||||
::
|
||||
++ utxo
|
||||
%- ot
|
||||
%- ot
|
||||
:~ ['tx_pos' ni]
|
||||
['tx_hash' (cu from-cord:hxb:bc so)]
|
||||
['tx_hash' (cu from-cord:hxb:bcu so)]
|
||||
[%height ni]
|
||||
[%value ni]
|
||||
[%recvd (cu from-epoch ni)]
|
||||
==
|
||||
::
|
||||
++ tx-vals
|
||||
%- ot
|
||||
:~ [%included bo]
|
||||
[%txid (cu from-cord:hxb:bc so)]
|
||||
[%txid (cu from-cord:hxb:bcu so)]
|
||||
[%confs ni]
|
||||
[%recvd (cu from-epoch ni)]
|
||||
[%inputs (ar tx-val)]
|
||||
[%outputs (ar tx-val)]
|
||||
==
|
||||
::
|
||||
++ tx-val
|
||||
%- ot
|
||||
:~ [%txid (cu from-cord:hxb:bc so)]
|
||||
:~ [%txid (cu from-cord:hxb:bcu so)]
|
||||
[%pos ni]
|
||||
[%address (cu from-cord:adr:bc so)]
|
||||
[%value ni]
|
||||
==
|
||||
::
|
||||
++ raw-tx
|
||||
%- ot
|
||||
:~ [%txid (cu from-cord:hxb:bc so)]
|
||||
[%rawtx (cu from-cord:hxb:bc so)]
|
||||
:~ [%txid (cu from-cord:hxb:bcu so)]
|
||||
[%rawtx (cu from-cord:hxb:bcu so)]
|
||||
==
|
||||
::
|
||||
++ broadcast-tx
|
||||
%- ot
|
||||
:~ [%txid (cu from-cord:hxb:bc so)]
|
||||
:~ [%txid (cu from-cord:hxb:bcu so)]
|
||||
[%broadcast bo]
|
||||
[%included bo]
|
||||
==
|
||||
::
|
||||
++ block-info
|
||||
%- ot
|
||||
:~ [%block ni]
|
||||
[%fee (mu ni)]
|
||||
[%blockhash (cu from-cord:hxb:bc so)]
|
||||
[%blockfilter (cu from-cord:hxb:bc so)]
|
||||
[%blockhash (cu from-cord:hxb:bcu so)]
|
||||
[%blockfilter (cu from-cord:hxb:bcu so)]
|
||||
==
|
||||
--
|
||||
--
|
||||
@ -126,17 +132,17 @@
|
||||
%get-tx-vals
|
||||
%- get-request
|
||||
%+ mk-url '/gettxvals/'
|
||||
(to-cord:hxb:bc txid.ract)
|
||||
(to-cord:hxb:bcu txid.ract)
|
||||
::
|
||||
%get-raw-tx
|
||||
%- get-request
|
||||
%+ mk-url '/getrawtx/'
|
||||
(to-cord:hxb:bc txid.ract)
|
||||
(to-cord:hxb:bcu txid.ract)
|
||||
::
|
||||
%broadcast-tx
|
||||
%- get-request
|
||||
%+ mk-url '/broadcasttx/'
|
||||
(to-cord:hxb:bc rawtx.ract)
|
||||
(to-cord:hxb:bcu rawtx.ract)
|
||||
::
|
||||
%get-block-count
|
||||
%- get-request
|
||||
|
@ -1,7 +1,7 @@
|
||||
:: lib/btc.hoon
|
||||
::
|
||||
/- *btc-wallet, json-rpc, bp=btc-provider
|
||||
/+ bip32, bc=bitcoin
|
||||
/+ bip32, bc=bitcoin, bcu=bitcoin-utils
|
||||
=, secp:crypto
|
||||
=+ ecc=secp256k1
|
||||
|%
|
||||
@ -424,6 +424,7 @@
|
||||
%get-block-info
|
||||
[id.res (block-info res.res)]
|
||||
==
|
||||
::
|
||||
++ address-info
|
||||
%- ot
|
||||
:~ [%address (cu from-cord:adr:bc so)]
|
||||
@ -434,7 +435,7 @@
|
||||
++ utxo
|
||||
%- ot
|
||||
:~ ['tx_pos' ni]
|
||||
['tx_hash' (cu from-cord:hxb:bc so)]
|
||||
['tx_hash' (cu from-cord:hxb:bcu so)]
|
||||
[%height ni]
|
||||
[%value ni]
|
||||
[%recvd (cu from-epoch ni)]
|
||||
@ -442,7 +443,7 @@
|
||||
++ tx-vals
|
||||
%- ot
|
||||
:~ [%included bo]
|
||||
[%txid (cu from-cord:hxb:bc so)]
|
||||
[%txid (cu from-cord:hxb:bcu so)]
|
||||
[%confs ni]
|
||||
[%recvd (cu from-epoch ni)]
|
||||
[%inputs (ar tx-val)]
|
||||
@ -450,19 +451,19 @@
|
||||
==
|
||||
++ tx-val
|
||||
%- ot
|
||||
:~ [%txid (cu from-cord:hxb:bc so)]
|
||||
:~ [%txid (cu from-cord:hxb:bcu so)]
|
||||
[%pos ni]
|
||||
[%address (cu from-cord:adr:bc so)]
|
||||
[%value ni]
|
||||
==
|
||||
++ raw-tx
|
||||
%- ot
|
||||
:~ [%txid (cu from-cord:hxb:bc so)]
|
||||
[%rawtx (cu from-cord:hxb:bc so)]
|
||||
:~ [%txid (cu from-cord:hxb:bcu so)]
|
||||
[%rawtx (cu from-cord:hxb:bcu so)]
|
||||
==
|
||||
++ broadcast-tx
|
||||
%- ot
|
||||
:~ [%txid (cu from-cord:hxb:bc so)]
|
||||
:~ [%txid (cu from-cord:hxb:bcu so)]
|
||||
[%broadcast bo]
|
||||
[%included bo]
|
||||
==
|
||||
@ -470,8 +471,8 @@
|
||||
%- ot
|
||||
:~ [%block ni]
|
||||
[%fee (mu ni)]
|
||||
[%blockhash (cu from-cord:hxb:bc so)]
|
||||
[%blockfilter (cu from-cord:hxb:bc so)]
|
||||
[%blockhash (cu from-cord:hxb:bcu so)]
|
||||
[%blockfilter (cu from-cord:hxb:bcu so)]
|
||||
==
|
||||
--
|
||||
--
|
||||
@ -488,17 +489,17 @@
|
||||
%get-tx-vals
|
||||
%- get-request
|
||||
%+ mk-url '/gettxvals/'
|
||||
(to-cord:hxb:bc txid.ract)
|
||||
(to-cord:hxb:bcu txid.ract)
|
||||
::
|
||||
%get-raw-tx
|
||||
%- get-request
|
||||
%+ mk-url '/getrawtx/'
|
||||
(to-cord:hxb:bc txid.ract)
|
||||
(to-cord:hxb:bcu txid.ract)
|
||||
::
|
||||
%broadcast-tx
|
||||
%- get-request
|
||||
%+ mk-url '/broadcasttx/'
|
||||
(to-cord:hxb:bc rawtx.ract)
|
||||
(to-cord:hxb:bcu rawtx.ract)
|
||||
::
|
||||
%get-block-count
|
||||
%- get-request
|
||||
|
@ -1,7 +1,7 @@
|
||||
:: Note: these are for BTC testnet
|
||||
::
|
||||
/- spider, rpc=json-rpc
|
||||
/+ strandio, bc=bitcoin
|
||||
/+ strandio, bc=bitcoin, bcu=bitcoin-utils
|
||||
=, strand=strand:spider
|
||||
=>
|
||||
|%
|
||||
@ -47,8 +47,8 @@
|
||||
++ electrs-script-hash
|
||||
|= a=address:bc
|
||||
^- hexb:bc
|
||||
%- flip:byt:bc
|
||||
%- sha256:bc
|
||||
%- flip:byt:bcu
|
||||
%- sha256:bcu
|
||||
(to-script-pubkey:adr:bc a)
|
||||
::
|
||||
++ parse-json-rpc
|
||||
|
@ -1,4 +1,4 @@
|
||||
/+ *test, *bitcoin, bip32
|
||||
/+ *test, *bitcoin, *bitcoin-utils, bip32
|
||||
=, secp:crypto
|
||||
=+ ecc=secp256k1
|
||||
|%
|
||||
|
@ -5,4 +5,4 @@ dojo:
|
||||
|
||||
it should return with the following hash:
|
||||
|
||||
`0v1.9p61c.bd4vn.deevh.0ldbq.fkqo3`
|
||||
`0v6.h33vk.c3n1c.4gpkn.cci4c.pnh4r`
|
||||
|
@ -10,8 +10,6 @@ import './css/custom.css';
|
||||
|
||||
// rebuild x3
|
||||
|
||||
window.NETWORK = 'testnet'; // 'bitcoin'
|
||||
|
||||
const channel = new window.channel();
|
||||
api.setChannel(window.ship, channel);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user