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
|
|
|
|
fail=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
|
2020-11-09 16:27:04 +03:00
|
|
|
:: TODO: write up how we can get on-agent %fact (success) or on-arvo Behn timeout
|
|
|
|
::
|
2020-10-24 19:13:36 +03:00
|
|
|
++ 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)
|
|
|
|
%watch-ack
|
2020-11-09 16:27:04 +03:00
|
|
|
?+ -.wire `this
|
|
|
|
%set-provider
|
|
|
|
?~ provider `this
|
|
|
|
?^ p.sign `this(provider ~)
|
|
|
|
?. =(src.bowl host.u.provider) `this
|
|
|
|
:_ this(provider `[host.u.provider %.y])
|
|
|
|
%+ weld (retry:hc pend) (retry:hc fail)
|
|
|
|
==
|
|
|
|
::
|
2020-11-04 16:55:47 +03:00
|
|
|
%fact
|
|
|
|
=^ cards state
|
|
|
|
?+ p.cage.sign `state
|
2020-11-09 16:27:04 +03:00
|
|
|
%btc-provider-update
|
|
|
|
~& >> !<(update:bp q.cage.sign)
|
2020-11-04 16:55:47 +03:00
|
|
|
`state
|
|
|
|
%btc-wallet-store-request
|
2020-11-09 16:27:04 +03:00
|
|
|
~& >> !<(request:bws q.cage.sign)
|
2020-11-04 16:55:47 +03:00
|
|
|
(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
|
|
|
|
++ handle-command
|
|
|
|
|= comm=command
|
|
|
|
^- (quip card _state)
|
|
|
|
~& > comm
|
|
|
|
`state
|
2020-11-09 15:43:30 +03:00
|
|
|
:: set-provider algo:
|
2020-11-07 12:14:34 +03:00
|
|
|
:: - add provider, connected false
|
|
|
|
:: - on negative ack: delete the provider
|
2020-10-24 19:13:36 +03:00
|
|
|
::
|
|
|
|
++ handle-action
|
|
|
|
|= act=action
|
|
|
|
^- (quip card _state)
|
|
|
|
?- -.act
|
|
|
|
%set-provider
|
2020-11-04 18:24:00 +03:00
|
|
|
=* sub-card
|
|
|
|
[%pass /set-prov %agent [provider.act %btc-provider] %watch /clients]
|
2020-10-24 19:13:36 +03:00
|
|
|
:_ state
|
2020-11-04 18:24:00 +03:00
|
|
|
?~ provider ~[sub-card]
|
|
|
|
:~ [%pass /leave-prov %agent [host.u.provider %btc-provider] %leave ~]
|
|
|
|
sub-card
|
|
|
|
==
|
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 16:27:04 +03:00
|
|
|
?~ provider ~|("provider not set" !!)
|
2020-11-09 15:43:30 +03:00
|
|
|
=/ ri=req-id:bp (mk-req-id (hash-xpub:bwsl +>.req))
|
|
|
|
:- ~[(get-address-info ri host.u.provider a.req)]
|
2020-11-09 16:27:04 +03:00
|
|
|
state(pend (~(put by pend) ri req))
|
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 15:43:30 +03:00
|
|
|
%poke %btc-provider-action !>([ri %get-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-10-24 19:13:36 +03:00
|
|
|
--
|