change address doesn't keep generating gaps

This commit is contained in:
timlucmiptev 2020-12-09 14:49:23 +02:00 committed by ixv
parent ea3376f0ee
commit b4cd9c6d0e
3 changed files with 23 additions and 6 deletions

View File

@ -335,6 +335,7 @@
:: if no peta (payer/value), just prints address :: if no peta (payer/value), just prints address
:: ::
%generate-address %generate-address
:: TODO: find a way to not print the below for a change address
?~ peta.upd ~&(> "wallet-hook: %generate-address: {<address.upd>}" `state) ?~ peta.upd ~&(> "wallet-hook: %generate-address: {<address.upd>}" `state)
=/ [payer=ship value=sats] u.peta.upd =/ [payer=ship value=sats] u.peta.upd
:_ state(ps.piym (~(put by ps.piym) payer [xpub.upd address.upd payer value])) :_ state(ps.piym (~(put by ps.piym) payer [xpub.upd address.upd payer value]))

View File

@ -136,8 +136,8 @@
:: - generate new change address :: - generate new change address
:: - add that address+change value to the txbu :: - add that address+change value to the txbu
:: - send txbu update :: - send txbu update
:: - send address update
:: - send a request for info on the address (watch it) :: - send a request for info on the address (watch it)
:: - DON'T send an address update for the address, since it's change
:: ::
:: TODO: end to end tests :: TODO: end to end tests
%generate-txbu %generate-txbu
@ -155,11 +155,10 @@
?~ chng ?~ chng
[~[(send-update [%generate-txbu xpub.act u.tb])] state] [~[(send-update [%generate-txbu xpub.act u.tb])] state]
=/ [addr=address:btc =idx w=walt] =/ [addr=address:btc =idx w=walt]
~(gen-address wad u.uw %1) ~(nixt-address wad u.uw %1)
=+ new-txbu=(~(add-output txb u.tb) addr u.chng `[fprint.w bipt.w %1 idx]) =+ new-txbu=(~(add-output txb u.tb) addr u.chng `[fprint.w bipt.w %1 idx])
:_ state(walts (~(put by walts) xpub.act w)) :_ state(walts (~(put by walts) xpub.act w))
:~ (send-update [%generate-txbu xpub.act new-txbu]) :~ (send-update [%generate-txbu xpub.act new-txbu])
(send-update [%generate-address xpub.act addr ~])
%+ send-request ~[requests-path] %+ send-request ~[requests-path]
:* %address-info last-block :* %address-info last-block
addr xpub.act %1 idx addr xpub.act %1 idx

View File

@ -80,14 +80,31 @@
?: ?=(%bip84 bipt.w) ?: ?=(%bip84 bipt.w)
(need (encode-pubkey:bech32:btc %main dat:(pubkey idx))) (need (encode-pubkey:bech32:btc %main dat:(pubkey idx)))
~|("legacy addresses not supported yet " !!) ~|("legacy addresses not supported yet " !!)
:: generates and watches the next available address :: +nixt-address: used to get change addresses
:: - gets the current next available address
:: - doesn't bump nixt-address if it's unused
:: - if used, fall back to gen-address and make a new one
::
++ nixt-address
^- (trel address:btc idx:btc walt)
=/ addr (mk-address nixt-idx)
~| "lib/btc-wallet-store: get-next-address: nixt shouldn't be blank"
=/ =addi (~(got by wach.w) addr)
?. used.addi
[addr nixt-idx w]
gen-address
::
:: +gen-address:
:: - generates the next available address
:: - watches it (using update address)
:: ::
++ gen-address ++ gen-address
^- (trel address:btc idx:btc walt) ^- (trel address:btc idx:btc walt)
=/ addr (mk-address nixt-idx) =/ addr (mk-address nixt-idx)
:* addr :* addr
nixt-idx nixt-idx
(update-address addr [%.n chyg nixt-idx *(set utxo:btc)]) %+ update-address addr
[%.n chyg nixt-idx *(set utxo:btc)]
== ==
:: +update-address :: +update-address
:: - insert a new address :: - insert a new address
@ -112,7 +129,7 @@
?:(?=(%0 chyg) p.nixt.w q.nixt.w) ?:(?=(%0 chyg) p.nixt.w q.nixt.w)
:: +bump-nixt: return wallet with bumped nixt :: +bump-nixt: return wallet with bumped nixt
:: - find next unused address :: - find next unused address
:: - add that address to wach :: - watches that address
:: - crashes if max-index is passed :: - crashes if max-index is passed
:: ::
++ bump-nixt ++ bump-nixt