From 926c508961b34ed3805b0f71b208fabb284914ab Mon Sep 17 00:00:00 2001 From: timlucmiptev Date: Mon, 2 Nov 2020 12:51:07 +0200 Subject: [PATCH] change provider types; refactor gen-adress --- WALLET.scratch.md | 11 ++++++----- app/btc-provider.hoon | 2 +- app/btc-wallet-store.hoon | 5 +++-- lib/btc-wallet-store.hoon | 25 +++++++++---------------- sur/btc-provider.hoon | 2 +- sur/btc-wallet-store.hoon | 2 +- 6 files changed, 21 insertions(+), 26 deletions(-) diff --git a/WALLET.scratch.md b/WALLET.scratch.md index fe7df78b05..7ac19a5395 100644 --- a/WALLET.scratch.md +++ b/WALLET.scratch.md @@ -51,20 +51,21 @@ nixt.st.q.res ## Algos ### Scan addresses -* types - - req-id=@ux: hash160 of (cat xpub chyg) * maps: - scans ([xpub chyg] -> waltscan) - - pend/fail: (req-id -> [=idx key=[xpub chyg]]) - - timeouts: (req-id -> @da) -- store Behns for each req * start scan - get `nixt` from wallet - - generate + - choose the next N indices - store their indexes in scan - send address+ idx [xpub chyg] to provider #### in wallet-hook +* types + - req-id=@ux: hash160 of (cat xpub chyg) + - pend/fail: (req-id -> [=idx key=[xpub chyg]]) + - timeouts: (req-id -> @da) -- store Behns for each req + * send address-watch req - send address to provider with req-id - set a Behn for 30s, put in timeouts diff --git a/app/btc-provider.hoon b/app/btc-provider.hoon index c694b2be2a..c20284ac1b 100644 --- a/app/btc-provider.hoon +++ b/app/btc-provider.hoon @@ -85,7 +85,7 @@ |^ ^- (quip card _state) =/ ract=action:rpc ?- -.act - %get-address-info + %watch-address [%erpc %get-address-utxos address.act] == [~[(req-card act ract)] state] diff --git a/app/btc-wallet-store.hoon b/app/btc-wallet-store.hoon index d2702c9b03..0279788fb3 100644 --- a/app/btc-wallet-store.hoon +++ b/app/btc-wallet-store.hoon @@ -12,13 +12,14 @@ $% state-0 == :: walts: all wallets, keyed by their xpubs -:: scanning: sets of idxs currently being scanned, keyed by xpub+chyg -:: has-used: whether xpub+chyg being scanned has previously used addresses, keyed by xpub+chyg +:: scans: batch info for wallets being scanned +:: batch-size: how many addresses to send out at once for checking :: +$ state-0 $: %0 walts=(map xpub:btc _walt) =scans + =batch-size == :: +$ card card:agent:gall diff --git a/lib/btc-wallet-store.hoon b/lib/btc-wallet-store.hoon index 3b5c70bd0d..975cd8e63f 100644 --- a/lib/btc-wallet-store.hoon +++ b/lib/btc-wallet-store.hoon @@ -32,20 +32,6 @@ scan-to.st (fall scan-to *scon) max-gap.st (fall max-gap default-max-gap) == - :: generates the next available address - :: adds it to wach (i.e. treat it as used and out in the wild) - :: - ++ gen-address - ^- (pair address:btc _this) - =^ curr-idx nixt.st - bump-nixt - =/ addr (mk-address curr-idx) - :- addr - %= this - wach.st %+ ~(put by wach.st) - addr - [chyg curr-idx *(set utxo:btc)] - == :: ++ mk-address |= =idx @@ -55,10 +41,17 @@ pub:(derive-public:(derive-public:wilt.st (@ chyg)) idx) ?: ?=(%bip84 bipt.st) (need (encode-pubkey:bech32:btc %main pubkey)) - ~|("legacy addresses not supported yet" !!) + ~|("legacy addresses not supported yet " !!) + :: generates and watches the next available address + :: + ++ gen-address + ^- (pair address:btc _this) + =/ addr (mk-address nixt-idx) + :- addr + (watch-address addr [chyg nixt-idx *(set utxo:btc)]) :: insert a new address; update "nixt" free address if this one was it :: - ++ insert-address + ++ watch-address |= [a=address:btc =addi] ^- _this ?> =(chyg chyg.addi) diff --git a/sur/btc-provider.hoon b/sur/btc-provider.hoon index d006cf58a9..aac9682e06 100644 --- a/sur/btc-provider.hoon +++ b/sur/btc-provider.hoon @@ -8,7 +8,7 @@ $% [%get-address-info =address] == +$ result - $% [%get-address-info a=address utxos=(set utxo) used=?] + $% [%watch-address a=address utxos=(set utxo) used=?] == +$ error $% [%not-connected ~] diff --git a/sur/btc-wallet-store.hoon b/sur/btc-wallet-store.hoon index 4246082368..d70e00b6fc 100644 --- a/sur/btc-wallet-store.hoon +++ b/sur/btc-wallet-store.hoon @@ -30,7 +30,7 @@ :: start: index this batch started scanning from :: +$ batch [todo=(set idx) has-used=? start=idx] -+$ scans (map [xpub chyg] batch) ++$ scans (map [xpub chyg] batch) :: +$ action $% [%add-wallet =xpub scan-to=(unit scon) max-gap=(unit @)]