From ada891684e51984d76b7f34033175409a3eade33 Mon Sep 17 00:00:00 2001 From: timlucmiptev Date: Fri, 13 Nov 2020 14:47:11 +0200 Subject: [PATCH] wallet store stores last-block --- WALLET.scratch.md | 3 ++- app/btc-provider.hoon | 7 +++++-- app/btc-wallet-store.hoon | 12 +++++++----- lib/btc-wallet-store.hoon | 11 ++++++++--- sur/btc-wallet-store.hoon | 15 +++++++++------ 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/WALLET.scratch.md b/WALLET.scratch.md index db7dff28f..ecaa8c032 100644 --- a/WALLET.scratch.md +++ b/WALLET.scratch.md @@ -59,9 +59,10 @@ abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon ### manual scanning of empty wallet Uses `btc-wallet-hook`, with max-gap=3 ``` +:btc-provider|command [%set-credentials api-url='http://localhost:50002'] :btc-wallet-hook|action [%set-provider ~dopzod] =scan-xpub 'zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs' -:btc-wallet-store|action [%add-wallet scan-xpub ~ [~ 3]] +:btc-wallet-store|action [%add-wallet scan-xpub ~ [~ 3] [~ 6]] :btc-wallet-store +dbug :: shows scans with the xpub and {0 1 2} todos diff --git a/app/btc-provider.hoon b/app/btc-provider.hoon index 08a906106..a83b8bdb7 100644 --- a/app/btc-provider.hoon +++ b/app/btc-provider.hoon @@ -124,6 +124,10 @@ ++ mk-wire |= act=action ^- wire /[-.body.act]/[req-id.act]/[(scot %da now.bowl)] +:: +++ get-req-id + |= =wire ^- req-id + +<.wire :: 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. @@ -148,11 +152,10 @@ :: ?+ wire ~|("Unexpected HTTP response" !!) [%address-info @ *] - =/ req-id=@t +>-.wire =/ resp=response:rpc (parse-response rpc-resp) ?> ?=([%get-address-info *] resp) :_ state - ~[(send-update [%& req-id %address-info +.resp])] + ~[(send-update [%& (get-req-id wire) %address-info +.resp])] :: [%ping @ *] :- ~[(send-status %connected)] diff --git a/app/btc-wallet-store.hoon b/app/btc-wallet-store.hoon index ebe402f6d..561f84eef 100644 --- a/app/btc-wallet-store.hoon +++ b/app/btc-wallet-store.hoon @@ -16,12 +16,14 @@ :: walts: all wallets, keyed by their xpubs :: scans: batch info for wallets being scanned :: batch-size: how many addresses to send out at once for checking +:: last-block: most recent block seen by the store :: +$ state-0 $: %0 walts=(map xpub:btc walt) =scans - batch-size=@ + batch-size=@ud + last-block=@ud == :: +$ card card:agent:gall @@ -40,7 +42,7 @@ ++ on-init ^- (quip card _this) ~& > '%btc-wallet-store initialized' - `this(state [%0 *(map xpub:btc walt) *^scans default-max-gap]) + `this(state [%0 *(map xpub:btc walt) *^scans max-gap:defaults 0]) ++ on-save ^- vase !>(state) @@ -66,7 +68,6 @@ ?> (team:title our.bowl src.bowl) ?+ pax (on-watch:def pax) [%requests *] - :: TODO: run req-scan on all scans :_ this %- zing %~ val by @@ -183,10 +184,11 @@ :: ++ end-scan |= [=xpub] - ^- _state + ^- (quip card _state) =/ w=walt (~(got by walts) xpub) =. scans (~(del by scans) [xpub %0]) =. scans (~(del by scans) [xpub %1]) + :- ~[[%give %fact ~[/updates] %btc-wallet-store-update !>([%scan-done xpub])]] state(walts (~(put by walts) xpub w(scanned %.y))) :: initiate a scan if one hasn't started :: check status of scan if one is running @@ -197,7 +199,7 @@ =/ s0 (scan-status xpub %0) =/ s1 (scan-status xpub %1) ?: ?&(empty.s0 done.s0 empty.s1 done.s1) - `(end-scan xpub) + (end-scan xpub) =/ [cards0=(list card) batch0=batch] (bump-batch xpub %0) =/ [cards1=(list card) batch1=batch] diff --git a/lib/btc-wallet-store.hoon b/lib/btc-wallet-store.hoon index 104e120e8..58d3e0884 100644 --- a/lib/btc-wallet-store.hoon +++ b/lib/btc-wallet-store.hoon @@ -5,7 +5,11 @@ =, secp:crypto =+ ecc=secp256k1 |% -++ default-max-gap 20 +++ defaults + |% + ++ max-gap 20 + ++ confs 6 + -- :: ++ hash-xpub |= [=xpub:btc =chyg =idx] @@ -16,7 +20,7 @@ [(met 3 dat) dat] :: ++ from-xpub - |= [=xpub:btc scan-to=(unit scon) max-gap=(unit @)] + |= [=xpub:btc scan-to=(unit scon) max-gap=(unit @ud) confs=(unit @ud)] ^- walt :* (from-extended:bip32 (trip xpub)) (xpub-type:btc xpub) @@ -24,7 +28,8 @@ [0 0] %.n (fall scan-to *scon) - (fall max-gap default-max-gap) + (fall max-gap max-gap:defaults) + (fall confs confs:defaults) == :: wad: door for processing walts (wallets) :: parameterized on a walt and it's chyg account diff --git a/sur/btc-wallet-store.hoon b/sur/btc-wallet-store.hoon index 9d64f370f..cb1b8f57e 100644 --- a/sur/btc-wallet-store.hoon +++ b/sur/btc-wallet-store.hoon @@ -28,7 +28,8 @@ :: walt: wallet datastructure :: scanned: whether the wallet's addresses have been checked for prior activity :: scan-to -:: max-gap +:: max-gap: maximum number of consec blank addresses before wallet stops scanning +:: confs: confirmations required (after this is hit for an address, wallet stops refreshing it) :: +$ walt $: =wilt @@ -37,7 +38,8 @@ =nixt scanned=? scan-to=scon - max-gap=@ + max-gap=@ud + confs=@ud == :: todo: Set of indices; empty it out until none are left--means scanning of that batch is done :: start: index this batch started scanning from @@ -52,7 +54,7 @@ :: %update-address: update info of an address if we're watching it :: +$ action - $% [%add-wallet =xpub scan-to=(unit scon) max-gap=(unit @)] + $% [%add-wallet =xpub scan-to=(unit scon) max-gap=(unit @ud) confs=(unit @ud)] [%watch-address =xpub =chyg =idx utxos=(set utxo) used=?] [%update-address a=address utxos=(set utxo)] [%generate-address =xpub =chyg] @@ -60,9 +62,10 @@ :: +$ update $% [%generate-address =address] + [%scan-done =xpub] == :: -+$ req-method - $?(%scan-address) -+$ request [method=req-method a=address =xpub =chyg =idx] ++$ request + $% [%scan-address a=address =xpub =chyg =idx] + == --