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 ### manual scanning of empty wallet
Uses `btc-wallet-hook`, with max-gap=3 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] :btc-wallet-hook|action [%set-provider ~dopzod]
=scan-xpub 'zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs' =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 :btc-wallet-store +dbug
:: shows scans with the xpub and {0 1 2} todos :: shows scans with the xpub and {0 1 2} todos

View File

@ -124,6 +124,10 @@
++ mk-wire ++ mk-wire
|= act=action ^- wire |= act=action ^- wire
/[-.body.act]/[req-id.act]/[(scot %da now.bowl)] /[-.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. :: 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 :: For actions that require collating multiple RPC calls, uses req-card to call out
:: to RPC again if more information is required. :: to RPC again if more information is required.
@ -148,11 +152,10 @@
:: ::
?+ wire ~|("Unexpected HTTP response" !!) ?+ wire ~|("Unexpected HTTP response" !!)
[%address-info @ *] [%address-info @ *]
=/ req-id=@t +>-.wire
=/ resp=response:rpc (parse-response rpc-resp) =/ resp=response:rpc (parse-response rpc-resp)
?> ?=([%get-address-info *] resp) ?> ?=([%get-address-info *] resp)
:_ state :_ state
~[(send-update [%& req-id %address-info +.resp])] ~[(send-update [%& (get-req-id wire) %address-info +.resp])]
:: ::
[%ping @ *] [%ping @ *]
:- ~[(send-status %connected)] :- ~[(send-status %connected)]

View File

@ -16,12 +16,14 @@
:: walts: all wallets, keyed by their xpubs :: walts: all wallets, keyed by their xpubs
:: scans: batch info for wallets being scanned :: scans: batch info for wallets being scanned
:: batch-size: how many addresses to send out at once for checking :: batch-size: how many addresses to send out at once for checking
:: last-block: most recent block seen by the store
:: ::
+$ state-0 +$ state-0
$: %0 $: %0
walts=(map xpub:btc walt) walts=(map xpub:btc walt)
=scans =scans
batch-size=@ batch-size=@ud
last-block=@ud
== ==
:: ::
+$ card card:agent:gall +$ card card:agent:gall
@ -40,7 +42,7 @@
++ on-init ++ on-init
^- (quip card _this) ^- (quip card _this)
~& > '%btc-wallet-store initialized' ~& > '%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 ++ on-save
^- vase ^- vase
!>(state) !>(state)
@ -66,7 +68,6 @@
?> (team:title our.bowl src.bowl) ?> (team:title our.bowl src.bowl)
?+ pax (on-watch:def pax) ?+ pax (on-watch:def pax)
[%requests *] [%requests *]
:: TODO: run req-scan on all scans
:_ this :_ this
%- zing %- zing
%~ val by %~ val by
@ -183,10 +184,11 @@
:: ::
++ end-scan ++ end-scan
|= [=xpub] |= [=xpub]
^- _state ^- (quip card _state)
=/ w=walt (~(got by walts) xpub) =/ w=walt (~(got by walts) xpub)
=. scans (~(del by scans) [xpub %0]) =. scans (~(del by scans) [xpub %0])
=. scans (~(del by scans) [xpub %1]) =. 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))) state(walts (~(put by walts) xpub w(scanned %.y)))
:: initiate a scan if one hasn't started :: initiate a scan if one hasn't started
:: check status of scan if one is running :: check status of scan if one is running
@ -197,7 +199,7 @@
=/ s0 (scan-status xpub %0) =/ s0 (scan-status xpub %0)
=/ s1 (scan-status xpub %1) =/ s1 (scan-status xpub %1)
?: ?&(empty.s0 done.s0 empty.s1 done.s1) ?: ?&(empty.s0 done.s0 empty.s1 done.s1)
`(end-scan xpub) (end-scan xpub)
=/ [cards0=(list card) batch0=batch] =/ [cards0=(list card) batch0=batch]
(bump-batch xpub %0) (bump-batch xpub %0)
=/ [cards1=(list card) batch1=batch] =/ [cards1=(list card) batch1=batch]

View File

@ -5,7 +5,11 @@
=, secp:crypto =, secp:crypto
=+ ecc=secp256k1 =+ ecc=secp256k1
|% |%
++ default-max-gap 20 ++ defaults
|%
++ max-gap 20
++ confs 6
--
:: ::
++ hash-xpub ++ hash-xpub
|= [=xpub:btc =chyg =idx] |= [=xpub:btc =chyg =idx]
@ -16,7 +20,7 @@
[(met 3 dat) dat] [(met 3 dat) dat]
:: ::
++ from-xpub ++ 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 ^- walt
:* (from-extended:bip32 (trip xpub)) :* (from-extended:bip32 (trip xpub))
(xpub-type:btc xpub) (xpub-type:btc xpub)
@ -24,7 +28,8 @@
[0 0] [0 0]
%.n %.n
(fall scan-to *scon) (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) :: wad: door for processing walts (wallets)
:: parameterized on a walt and it's chyg account :: parameterized on a walt and it's chyg account

View File

@ -28,7 +28,8 @@
:: walt: wallet datastructure :: walt: wallet datastructure
:: scanned: whether the wallet's addresses have been checked for prior activity :: scanned: whether the wallet's addresses have been checked for prior activity
:: scan-to :: 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 +$ walt
$: =wilt $: =wilt
@ -37,7 +38,8 @@
=nixt =nixt
scanned=? scanned=?
scan-to=scon 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 :: 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 :: start: index this batch started scanning from
@ -52,7 +54,7 @@
:: %update-address: update info of an address if we're watching it :: %update-address: update info of an address if we're watching it
:: ::
+$ action +$ 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=?] [%watch-address =xpub =chyg =idx utxos=(set utxo) used=?]
[%update-address a=address utxos=(set utxo)] [%update-address a=address utxos=(set utxo)]
[%generate-address =xpub =chyg] [%generate-address =xpub =chyg]
@ -60,9 +62,10 @@
:: ::
+$ update +$ update
$% [%generate-address =address] $% [%generate-address =address]
[%scan-done =xpub]
== ==
:: ::
+$ req-method +$ request
$?(%scan-address) $% [%scan-address a=address =xpub =chyg =idx]
+$ request [method=req-method a=address =xpub =chyg =idx] ==
-- --