wallet store stores last-block

This commit is contained in:
timlucmiptev 2020-11-13 14:47:11 +02:00 committed by ixv
parent 54dd843690
commit ada891684e
5 changed files with 31 additions and 17 deletions

View File

@ -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

View File

@ -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)]

View File

@ -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]

View File

@ -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

View File

@ -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]
==
--