2020-10-30 14:45:38 +03:00
|
|
|
# btc-wallet-* Scratch Code
|
|
|
|
|
|
|
|
## xpub
|
|
|
|
```
|
2020-10-31 12:41:00 +03:00
|
|
|
=xpub1 'zpub6r8dKyWJ31XF6n69KKeEwLjVC5ruqAbiJ4QCqLsrV36Mvx9WEjUaiPNPGFLHNCCqgCdy6iZC8ZgHsm6a1AUTVBMVbKGemNcWFcwBGSjJKbD'
|
|
|
|
=xpub2 'xpub6D7yaZieZEeG617UcKXDhbsDeso6bmxSAiGWkvkASoiwcjaRtrH5HeNRnDT25s7zmxYzj6MtFe32dVqcf9YcBKKgn9THHjwn2uSjkvobK4e'
|
2020-10-30 14:45:38 +03:00
|
|
|
=bl -build-file %/lib/btc-wallet-store/hoon
|
|
|
|
```
|
|
|
|
|
|
|
|
### add
|
|
|
|
```
|
|
|
|
:btc-wallet-store|action [%add-wallet xpub ~ ~]
|
|
|
|
```
|
|
|
|
|
|
|
|
### get address at indices
|
|
|
|
```
|
|
|
|
=walt1 (from-xpub:walt:bl xpub1 ~ ~)
|
|
|
|
(get-address:walt1 %0 0)
|
|
|
|
```
|
|
|
|
|
2020-10-31 12:41:00 +03:00
|
|
|
### update address data
|
|
|
|
```
|
|
|
|
=walt1 (from-xpub:walt:bl xpub1 ~ ~)
|
2020-10-31 14:25:32 +03:00
|
|
|
(mk-address:walt1 %0 0)
|
|
|
|
:: gives bc1q0adfj7ur750hjwufzzlfj5ytqzsnd7fz9fjuzc
|
|
|
|
=walt1 (insert-address:walt1 [%bech32 'bc1q0adfj7ur750hjwufzzlfj5ytqzsnd7fz9fjuzc'] [%0 0 ~])
|
|
|
|
nixt:walt1
|
|
|
|
:: gives [p=1 q=0] (nixt updated since it was 0)
|
|
|
|
=walt1 (insert-address:walt1 [%bech32 'bc1qa5jcdww8u8493zttjjf6q5wu89e6knpvmsh7x4'] [%0 2 ~])
|
|
|
|
nixt:walt1
|
|
|
|
:: gives [p=1 q=0] (no update)
|
|
|
|
=walt1 (insert-address:walt1 [%bech32 'bc1qvqrdh8suyv63ntaa0d7hmcamavv8283sngh6e5'] [%0 1 ~])
|
|
|
|
nixt:walt1
|
|
|
|
:: gives [p=3 q=0] (skips index 2, since already a used address there)
|
2020-10-31 12:41:00 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
## Algos
|
|
|
|
|
|
|
|
Scan addresses. (map xpub (pair list list))
|
2020-10-31 15:38:53 +03:00
|
|
|
outgoing wire is /scan/xpub/change/idx
|
|
|
|
- keep (jug cord idx) of xpub+chyg -> idx
|
2020-10-31 12:41:00 +03:00
|
|
|
- every time we get a response
|
2020-10-31 15:38:53 +03:00
|
|
|
- check whether idx in `scanning`--ignore if not (old response)
|
|
|
|
- insert the address into the wallet **if it's used**
|
|
|
|
- if used, update `has-used` for this xpub to be true
|
|
|
|
- delete idx from `scanning` jug
|
|
|
|
- check whether `scanning` is now empty
|
|
|
|
|
2020-10-31 12:41:00 +03:00
|
|
|
|
2020-10-30 14:45:38 +03:00
|
|
|
|
|
|
|
## scratch code, refactor
|
2020-10-31 12:41:00 +03:00
|
|
|
++ update-utxos
|
2020-10-30 14:45:38 +03:00
|
|
|
|= [a=address:btc us=(set utxo)]
|
|
|
|
^- (quip card _state)
|
|
|
|
=/ xpubs=(list tape)
|
|
|
|
%~ tap in
|
|
|
|
~(key by walts.state)
|
|
|
|
|- ?~ xpubs `state
|
|
|
|
=/ w=walt (~(got by walts.state) i.xpubs)
|
|
|
|
?: (~(has by wach.w) a)
|
|
|
|
%: send-address-update
|
|
|
|
i.xpubs
|
|
|
|
(update-wallet w a us)
|
|
|
|
a
|
|
|
|
us
|
|
|
|
==
|
|
|
|
$(xpubs t.xpubs)
|
|
|
|
::
|
|
|
|
++ update-wallet
|
|
|
|
|= [w=walt a=address:btc us=(set utxo)]
|
|
|
|
^- walt
|
|
|
|
=/ curr-addi=addi
|
|
|
|
(~(got by wach.w) a)
|
|
|
|
w(wach (~(put by wach.w) a curr-addi(used %.y, utxos us)))
|
|
|
|
::
|
|
|
|
++ send-address-update
|
|
|
|
|= [xpub=tape =walt a=address:btc us=(set utxo)]
|
|
|
|
^- (quip card _state)
|
|
|
|
:_ state(walts (~(put by walts.state) xpub walt))
|
|
|
|
~[[%give %fact ~[/wallets] %btc-wallet-store-update !>([%address a us])]]
|
|
|
|
::
|
|
|
|
++ add-wallet
|
|
|
|
|= [xpub=tape scan-to=(unit scon) max-gap=(unit @)]
|
|
|
|
^- (quip card _state)
|
|
|
|
?: (~(has by walts.state) xpub)
|
|
|
|
~& >>> "xpub already imported"
|
|
|
|
`state
|
|
|
|
=/ wallet=walt
|
|
|
|
:* (from-extended:bip32 xpub)
|
|
|
|
(xpub-type:btc xpub)
|
|
|
|
*wach
|
|
|
|
[0 0]
|
|
|
|
%.n
|
|
|
|
(fall scan-to *scon)
|
|
|
|
(fall max-gap max-gap.state)
|
|
|
|
==
|
|
|
|
`state(walts (~(put by walts.state) xpub wallet))
|