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-11-02 10:21:48 +03:00
|
|
|
(~(mk-address walt1 %0) 0)
|
2020-10-31 14:25:32 +03:00
|
|
|
:: gives bc1q0adfj7ur750hjwufzzlfj5ytqzsnd7fz9fjuzc
|
2020-11-02 10:21:48 +03:00
|
|
|
=walt1 (~(insert-address walt1 %0) [%bech32 'bc1q0adfj7ur750hjwufzzlfj5ytqzsnd7fz9fjuzc'] [%0 0 ~])
|
|
|
|
nixt.st.walt1
|
2020-10-31 14:25:32 +03:00
|
|
|
:: gives [p=1 q=0] (nixt updated since it was 0)
|
2020-11-02 10:21:48 +03:00
|
|
|
=walt1 (~(insert-address walt1 %0) [%bech32 'bc1qa5jcdww8u8493zttjjf6q5wu89e6knpvmsh7x4'] [%0 2 ~])
|
|
|
|
nixt.st.walt1
|
2020-10-31 14:25:32 +03:00
|
|
|
:: gives [p=1 q=0] (no update)
|
2020-11-02 10:21:48 +03:00
|
|
|
=walt1 (~(insert-address walt1 %0) [%bech32 'bc1qvqrdh8suyv63ntaa0d7hmcamavv8283sngh6e5'] [%0 1 ~])
|
|
|
|
nixt.st.walt1
|
2020-10-31 14:25:32 +03:00
|
|
|
:: gives [p=3 q=0] (skips index 2, since already a used address there)
|
2020-11-02 10:21:48 +03:00
|
|
|
|
|
|
|
=walt1 (insert-address:walt1 [%bech32 'bc1qvqrdh8suyv63ntaa0d7hmcamavv8283sngh6e5'] [%0 4 ~])
|
|
|
|
:: gives error, because address is inserted at the wrong index
|
|
|
|
```
|
|
|
|
|
|
|
|
### generate new address (for receiving payment)
|
|
|
|
```
|
|
|
|
=walt1 (from-xpub:walt:bl xpub1 ~ ~)
|
|
|
|
=res ~(gen-address walt1 %0)
|
|
|
|
p.res
|
|
|
|
nixt.st.q.res
|
|
|
|
:: gives
|
|
|
|
:: [%bech32 'bc1q0adfj7ur750hjwufzzlfj5ytqzsnd7fz9fjuzc']
|
|
|
|
:: [p=1 q=0]
|
2020-10-31 12:41:00 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
## Algos
|
|
|
|
|
2020-11-02 10:53:04 +03:00
|
|
|
### 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
|
2020-11-02 13:37:55 +03:00
|
|
|
|
|
|
|
* start scan
|
|
|
|
- get `nixt` from wallet
|
|
|
|
- generate
|
|
|
|
- store their indexes in scan
|
|
|
|
- send address+ idx [xpub chyg] to provider
|
2020-11-02 10:53:04 +03:00
|
|
|
|
2020-11-02 13:37:55 +03:00
|
|
|
#### in wallet-hook
|
2020-11-02 10:53:04 +03:00
|
|
|
* send address-watch req
|
|
|
|
- send address to provider with req-id
|
|
|
|
- set a Behn for 30s, put in timeouts
|
|
|
|
|
|
|
|
* on response from server
|
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
|
2020-10-31 18:03:00 +03:00
|
|
|
- check whether scanning is now empty. If it is, check whether has-used is true
|
2020-11-02 10:53:04 +03:00
|
|
|
|
|
|
|
* on error
|
|
|
|
|
|
|
|
* on timeout
|
|
|
|
|
2020-11-02 13:37:55 +03:00
|
|
|
### Monitor addresses
|
|
|
|
- nixt also stores next 50 addresses for each account.
|
|
|
|
- every update-address call also checks those
|
2020-10-30 14:45:38 +03:00
|
|
|
|
|
|
|
::
|
|
|
|
++ 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])]]
|
|
|
|
::
|