2020-10-24 19:13:36 +03:00
|
|
|
:: btc-wallet-hook.hoon
|
2020-10-28 16:20:24 +03:00
|
|
|
::
|
2020-11-04 16:55:47 +03:00
|
|
|
:: Subscribes to:
|
2020-10-28 16:20:24 +03:00
|
|
|
:: btc-provider:
|
2020-11-04 16:55:47 +03:00
|
|
|
:: - connection status
|
|
|
|
:: - RPC call results/errors
|
|
|
|
::
|
|
|
|
:: btc-wallet-store
|
|
|
|
:: - requests for address info
|
|
|
|
:: - updates to existing address info
|
|
|
|
::
|
|
|
|
:: Sends updates to:
|
2020-10-28 16:20:24 +03:00
|
|
|
:: none
|
2020-10-24 19:13:36 +03:00
|
|
|
::
|
2020-11-09 15:29:30 +03:00
|
|
|
/- *btc, *btc-wallet-hook, bws=btc-wallet-store, bp=btc-provider
|
2020-11-05 10:51:17 +03:00
|
|
|
/+ shoe, dbug, default-agent, bwsl=btc-wallet-store
|
2020-10-24 19:13:36 +03:00
|
|
|
|%
|
|
|
|
+$ versioned-state
|
|
|
|
$% state-0
|
|
|
|
==
|
2020-11-04 16:55:47 +03:00
|
|
|
:: provdider: maybe ship if provider is set
|
2020-10-24 19:13:36 +03:00
|
|
|
::
|
2020-11-04 16:55:47 +03:00
|
|
|
+$ state-0
|
|
|
|
$: %0
|
2020-11-09 16:27:04 +03:00
|
|
|
provider=(unit [host=ship connected=?])
|
2020-11-04 16:55:47 +03:00
|
|
|
pend=back
|
|
|
|
==
|
2020-10-24 19:13:36 +03:00
|
|
|
::
|
|
|
|
+$ card card:shoe
|
|
|
|
+$ command
|
|
|
|
$? %add-xpub
|
|
|
|
==
|
|
|
|
::
|
|
|
|
--
|
|
|
|
=| state-0
|
|
|
|
=* state -
|
|
|
|
%- agent:dbug
|
|
|
|
^- agent:gall
|
|
|
|
%- (agent:shoe command)
|
|
|
|
^- (shoe:shoe command)
|
|
|
|
=<
|
|
|
|
|_ =bowl:gall
|
|
|
|
+* this .
|
|
|
|
des ~(. (default:shoe this command) bowl)
|
|
|
|
def ~(. (default-agent this %|) bowl)
|
|
|
|
hc ~(. +> bowl)
|
|
|
|
::
|
|
|
|
++ command-parser command-parser:des
|
|
|
|
++ tab-list tab-list:des
|
|
|
|
++ can-connect can-connect:des
|
|
|
|
++ on-command on-command:des
|
|
|
|
++ on-connect on-connect:des
|
|
|
|
++ on-disconnect on-disconnect:des
|
|
|
|
::
|
|
|
|
++ on-init
|
|
|
|
^- (quip card _this)
|
|
|
|
~& > '%btc-wallet-hook initialized'
|
2020-11-04 16:55:47 +03:00
|
|
|
:_ this
|
|
|
|
:~ [%pass /r/[(scot %da now.bowl)] %agent [our.bowl %btc-wallet-store] %watch /requests]
|
|
|
|
[%pass /u/[(scot %da now.bowl)] %agent [our.bowl %btc-wallet-store] %watch /updates]
|
|
|
|
==
|
2020-10-24 19:13:36 +03:00
|
|
|
++ on-save
|
|
|
|
^- vase
|
|
|
|
!>(state)
|
|
|
|
++ on-load
|
|
|
|
|= old-state=vase
|
|
|
|
^- (quip card _this)
|
|
|
|
~& > '%btc-wallet-hook recompiled'
|
|
|
|
`this(state !<(versioned-state old-state))
|
|
|
|
++ on-poke
|
|
|
|
|= [=mark =vase]
|
|
|
|
^- (quip card _this)
|
|
|
|
=^ cards state
|
|
|
|
?+ mark (on-poke:def mark vase)
|
|
|
|
%btc-wallet-hook-action
|
|
|
|
(handle-action:hc !<(action vase))
|
|
|
|
==
|
|
|
|
[cards this]
|
|
|
|
::
|
|
|
|
++ on-watch on-watch:def
|
|
|
|
++ on-leave on-leave:def
|
|
|
|
++ on-peek on-peek:def
|
|
|
|
++ on-agent
|
|
|
|
|= [=wire =sign:agent:gall]
|
2020-11-09 15:43:30 +03:00
|
|
|
^- (quip card _this)
|
2020-10-24 19:13:36 +03:00
|
|
|
?+ -.sign (on-agent:def wire sign)
|
2020-11-10 13:30:06 +03:00
|
|
|
%kick
|
|
|
|
?~ provider `this
|
|
|
|
?: ?& ?=(%set-provider -.wire)
|
|
|
|
=(host.u.provider src.bowl)
|
|
|
|
==
|
|
|
|
`this(provider ~)
|
|
|
|
`this
|
|
|
|
::
|
2020-11-04 16:55:47 +03:00
|
|
|
%fact
|
|
|
|
=^ cards state
|
|
|
|
?+ p.cage.sign `state
|
2020-11-10 13:30:06 +03:00
|
|
|
%btc-provider-status
|
|
|
|
(handle-provider-status:hc !<(status:bp q.cage.sign))
|
|
|
|
::
|
2020-11-09 16:27:04 +03:00
|
|
|
%btc-provider-update
|
2020-11-04 16:55:47 +03:00
|
|
|
`state
|
2020-11-10 13:30:06 +03:00
|
|
|
::
|
2020-11-04 16:55:47 +03:00
|
|
|
%btc-wallet-store-request
|
|
|
|
(handle-request:hc !<(request:bws q.cage.sign))
|
|
|
|
==
|
|
|
|
[cards this]
|
2020-10-24 19:13:36 +03:00
|
|
|
==
|
|
|
|
++ on-arvo on-arvo:def
|
|
|
|
++ on-fail on-fail:def
|
|
|
|
--
|
|
|
|
|_ =bowl:gall
|
2020-11-10 13:30:06 +03:00
|
|
|
:: if status is %connected, retry all pending address lookups
|
|
|
|
::
|
|
|
|
++ handle-provider-status
|
|
|
|
|= s=status:bp
|
|
|
|
^- (quip card _state)
|
|
|
|
?~ provider `state
|
|
|
|
?. =(host.u.provider src.bowl) `state
|
|
|
|
?- s
|
|
|
|
%connected
|
|
|
|
:- (retry pend)
|
|
|
|
state(provider `[host.u.provider %.y])
|
|
|
|
%disconnected
|
|
|
|
`state(provider `[host.u.provider %.n])
|
|
|
|
==
|
|
|
|
::
|
2020-10-24 19:13:36 +03:00
|
|
|
++ handle-command
|
|
|
|
|= comm=command
|
|
|
|
^- (quip card _state)
|
|
|
|
~& > comm
|
|
|
|
`state
|
|
|
|
::
|
|
|
|
++ handle-action
|
|
|
|
|= act=action
|
|
|
|
^- (quip card _state)
|
|
|
|
?- -.act
|
|
|
|
%set-provider
|
2020-11-04 18:24:00 +03:00
|
|
|
=* sub-card
|
2020-11-10 13:30:06 +03:00
|
|
|
[%pass /set-provider %agent [provider.act %btc-provider] %watch /clients]
|
2020-11-09 18:34:29 +03:00
|
|
|
:_ state(provider [~ provider.act %.n])
|
2020-11-04 18:24:00 +03:00
|
|
|
?~ provider ~[sub-card]
|
2020-11-10 13:30:06 +03:00
|
|
|
:~ [%pass /set-provider %agent [host.u.provider %btc-provider] %leave ~]
|
2020-11-04 18:24:00 +03:00
|
|
|
sub-card
|
|
|
|
==
|
2020-11-09 18:34:29 +03:00
|
|
|
::
|
|
|
|
%force-retry
|
2020-11-10 13:30:06 +03:00
|
|
|
[(retry pend) state]
|
2020-10-24 19:13:36 +03:00
|
|
|
==
|
2020-11-04 16:55:47 +03:00
|
|
|
++ handle-request
|
|
|
|
|= req=request:bws
|
|
|
|
^- (quip card _state)
|
|
|
|
?- -.req
|
|
|
|
%scan-address
|
2020-11-09 15:43:30 +03:00
|
|
|
=/ ri=req-id:bp (mk-req-id (hash-xpub:bwsl +>.req))
|
2020-11-09 18:34:29 +03:00
|
|
|
:_ state(pend (~(put by pend) ri req))
|
2020-11-10 14:09:59 +03:00
|
|
|
?~ provider ~
|
|
|
|
?: provider-connected
|
|
|
|
~[(get-address-info ri host.u.provider a.req)]
|
|
|
|
~& > "provider not set"
|
|
|
|
~
|
2020-11-04 16:55:47 +03:00
|
|
|
==
|
|
|
|
::
|
2020-11-09 16:27:04 +03:00
|
|
|
++ retry
|
|
|
|
|= =back
|
|
|
|
^- (list card)
|
|
|
|
?~ provider ~|("provider not set" !!)
|
|
|
|
%+ turn ~(tap by back)
|
|
|
|
|= [ri=req-id:bp req=request:bws]
|
|
|
|
(get-address-info ri host.u.provider a.req)
|
|
|
|
::
|
2020-11-04 16:55:47 +03:00
|
|
|
++ get-address-info
|
2020-11-09 15:43:30 +03:00
|
|
|
|= [ri=req-id:bp host=ship a=address] ^- card
|
2020-11-04 16:55:47 +03:00
|
|
|
:* %pass /[(scot %da now.bowl)] %agent [host %btc-provider]
|
2020-11-09 18:34:29 +03:00
|
|
|
%poke %btc-provider-action !>([ri %address-info a])
|
2020-11-04 16:55:47 +03:00
|
|
|
==
|
2020-11-09 15:29:30 +03:00
|
|
|
++ mk-req-id
|
|
|
|
|= hash=@ux ^- req-id:bp
|
|
|
|
(scot %ux hash)
|
2020-11-10 14:09:59 +03:00
|
|
|
++ provider-connected
|
|
|
|
^- ?
|
|
|
|
?~ provider %.n
|
|
|
|
connected.u.provider
|
2020-10-24 19:13:36 +03:00
|
|
|
--
|