From 236745444e89e50dd8fabcd014cdd2cd343612b5 Mon Sep 17 00:00:00 2001 From: timlucmiptev Date: Wed, 4 Nov 2020 15:55:47 +0200 Subject: [PATCH] WIP: pend/fail tables --- app/btc-wallet-hook.hoon | 80 +++++++++++++++++++++++++++++---------- app/btc-wallet-store.hoon | 26 +++++++++---- sur/btc-provider.hoon | 1 - sur/btc-wallet-hook.hoon | 14 ++++--- 4 files changed, 87 insertions(+), 34 deletions(-) diff --git a/app/btc-wallet-hook.hoon b/app/btc-wallet-hook.hoon index 871d2ee34..0b0f68371 100644 --- a/app/btc-wallet-hook.hoon +++ b/app/btc-wallet-hook.hoon @@ -1,20 +1,31 @@ :: btc-wallet-hook.hoon :: -:: Subscriptions: +:: Subscribes to: :: btc-provider: -:: connection status -:: RPC call results/errors -:: To Subscribers: +:: - connection status +:: - RPC call results/errors +:: +:: btc-wallet-store +:: - requests for address info +:: - updates to existing address info +:: +:: Sends updates to: :: none :: -/- *btc-wallet-hook -/+ shoe, dbug, default-agent +/- *btc, *btc-wallet-hook, bws=btc-wallet-store +/+ shoe, dbug, default-agent, lib-bws=btc-wallet-store |% +$ versioned-state $% state-0 == +:: provdider: maybe ship if provider is set :: -+$ state-0 [%0 provider=(unit ship)] ++$ state-0 + $: %0 + provider=(unit [host=ship works=?]) + pend=back + fail=back + == :: +$ card card:shoe +$ command @@ -45,8 +56,10 @@ ++ on-init ^- (quip card _this) ~& > '%btc-wallet-hook initialized' - :: sub to wallet-store - `this + :_ 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] + == ++ on-save ^- vase !>(state) @@ -74,8 +87,17 @@ ?+ -.sign (on-agent:def wire sign) %watch-ack ?: ?=(%set-provider -.wire) - `this(provider.state `src.bowl) + `this(provider.state `[src.bowl %.y]) `this + %fact + =^ cards state + ?+ p.cage.sign `state + %btc-provider-response + `state + %btc-wallet-store-request + (handle-request:hc !<(request:bws q.cage.sign)) + == + [cards this] == ++ on-arvo on-arvo:def ++ on-fail on-fail:def @@ -92,17 +114,35 @@ |= act=action ^- (quip card _state) ?- -.act - %get-balance - ~& > %get-balance - ~& > addresses.act - `state - :: %set-provider :_ state - [[%pass /set-provider %agent [provider.act %btc-provider] %watch /clients]]~ - :: - %add-xpub - ~& > xpub.act - `state +:: TODO %+ weld +:: ?~(provider *(list card) ~[[%pass /leave-prov %agent [host.u.provider %btc-provider] %leave ~]]) + ~[[%pass /set-prov %agent [provider.act %btc-provider] %watch /clients]] == +++ handle-request + |= req=request:bws + ^- (quip card _state) + ?- -.req + %scan-address + ?~ provider ~|("provider not set" !!) + =/ ri=req-id (mk-req-id +.req) + =/ a=address *address +:: TODO (~(mk-address (from-xpub:walt:lib-bws xpub.req) chyg.req) idx.req) + :- ~[(get-address-info host.u.provider a)] + state(pend (~(put by pend) ri +.req)) + == +:: +++ get-address-info + |= [host=ship a=address] ^- card + :* %pass /[(scot %da now.bowl)] %agent [host %btc-provider] + %poke %btc-provider-action !>([%get-address-info a]) + == +:: +++ mk-req-id + |= [=xpub =chyg:bws =idx:bws] ^- req-id + =/ chygidx=@ (cat 3 ?:(=(%0 chyg) '0' '1') idx) + =/ dat=@ (cat 3 xpub chygidx) + %- ripemd-160:ripemd:crypto + [(met 3 dat) dat] -- diff --git a/app/btc-wallet-store.hoon b/app/btc-wallet-store.hoon index 6546933bf..d19388212 100644 --- a/app/btc-wallet-store.hoon +++ b/app/btc-wallet-store.hoon @@ -1,9 +1,11 @@ :: btc-wallet-store.hoon :: Manages wallet pubkeys :: -:: Subscriptions: none -:: To Subscribers: -:: watched address updates +:: Subscribes to: none +:: +:: Sends updates on: +:: - /requests: to request data about addresses +:: - /updates: new data about one of our addresses :: /- *btc-wallet-store /+ dbug, default-agent, *btc-wallet-store, btc, bip32 @@ -62,8 +64,12 @@ |= pax=path ^- (quip card _this) ?> (team:title our.bowl src.bowl) - ?> ?=([%wallets *] pax) - `this + ?+ pax (on-watch:def pax) + [%requests *] + `this + [%updates *] + `this + == ++ on-leave on-leave:def ++ on-peek on-peek:def ++ on-agent on-agent:def @@ -89,6 +95,13 @@ %update-address `state == +:: Wallet-scan algorithm: +:: Initiate a batch for each chyg, with max-gap idxs in it +:: Send that to /requests subscribers to call out to providers and get the info +:: Whenever a %watch-address result comes back +:: - remove that idx from todo.batch +:: - do run-scan to check whether that chyg is done +:: - if it isn't, refill it with idxs to scan :: ++ req-scan |= [b=batch =xpub =chyg] @@ -161,10 +174,7 @@ ^- (quip card _state) =/ s0 (scan-status xpub %0) =/ s1 (scan-status xpub %1) - ~& >> s0 - ~& >> s1 ?: ?&(empty.s0 done.s0 empty.s1 done.s1) - ~& > "ending scan" `(end-scan xpub) =/ [cards0=(list card) batch0=batch] (bump-batch xpub %0) diff --git a/sur/btc-provider.hoon b/sur/btc-provider.hoon index aac9682e0..59ff13bb9 100644 --- a/sur/btc-provider.hoon +++ b/sur/btc-provider.hoon @@ -42,4 +42,3 @@ -- -- - diff --git a/sur/btc-wallet-hook.hoon b/sur/btc-wallet-hook.hoon index 76b5f77c2..f695b3271 100644 --- a/sur/btc-wallet-hook.hoon +++ b/sur/btc-wallet-hook.hoon @@ -1,9 +1,13 @@ -/- *btc +/- *btc, bws=btc-wallet-store |% -+$ xpub tape +:: req-id: hash of [xpub chyg idx] +:: addo: wallet index to send result of request to +:: back: lookup table of req-id -> addo +:: ++$ req-id @ux ++$ addo [=xpub =chyg:bws =idx:bws] ++$ back (map req-id addo) +$ action - $% [%get-balance addresses=(set address)] - [%set-provider provider=ship] - [%add-xpub xpub=tape] + $% [%set-provider provider=ship] == --