shrub/WALLET.scratch.md
2021-05-26 18:30:15 -07:00

131 lines
3.8 KiB
Markdown

# btc-wallet-* Scratch Code
## xpub
xpub1 is from mnemonic from PRIVATE.scratch
```
=bl -build-file %/lib/btc-wallet-store/hoon
=xpub1 'zpub6r8dKyWJ31XF6n69KKeEwLjVC5ruqAbiJ4QCqLsrV36Mvx9WEjUaiPNPGFLHNCCqgCdy6iZC8ZgHsm6a1AUTVBMVbKGemNcWFcwBGSjJKbD'
=xpub2 'xpub6D7yaZieZEeG617UcKXDhbsDeso6bmxSAiGWkvkASoiwcjaRtrH5HeNRnDT25s7zmxYzj6MtFe32dVqcf9YcBKKgn9THHjwn2uSjkvobK4e'
=bl -build-file %/lib/btc-wallet-store/hoon
```
### get address at indices
```
=walt1 (from-xpub:bl xpub1 [%4 0x5566.7788] ~ ~ ~)
(~(mk-address wad:bl walt1 %0) 0)
:: gives [%bech32 'bc1q0adfj7ur750hjwufzzlfj5ytqzsnd7fz9fjuzc']
```
### update address data
```
=walt1 (from-xpub:bl xpub1 ~ ~ ~)
(~(mk-address wad:bl walt1 %0) 0)
:: gives bc1q0adfj7ur750hjwufzzlfj5ytqzsnd7fz9fjuzc
=walt1 (~(watch-address wad:bl walt1 %0) [%bech32 'bc1q0adfj7ur750hjwufzzlfj5ytqzsnd7fz9fjuzc'] [%0 0 ~])
nixt.walt1
:: gives [p=1 q=0] (nixt updated since it was 0)
=walt1 (~(watch-address wad:bl walt1 %0) [%bech32 'bc1qa5jcdww8u8493zttjjf6q5wu89e6knpvmsh7x4'] [%0 2 ~])
nixt.walt1=walt1 (~(watch-address wad:bl walt1 %0) [%bech32 'bc1qa5jcdww8u8493zttjjf6q5wu89e6knpvmsh7x4'] [%0 2 ~])
nixt.walt1
:: gives [p=1 q=0] (no update)
=walt1 (~(watch-address wad:bl walt1 %0) [%bech32 'bc1qvqrdh8suyv63ntaa0d7hmcamavv8283sngh6e5'] [%0 1 ~])
nixt.walt1
:: gives [p=3 q=0] (skips index 2, since already a used address there)
=walt1 (~(watch-address wad:bl walt1 %0) [%bech32 'bc1qvqrdh8suyv63ntaa0d7hmcamavv8283sngh6e5'] [%0 4 ~])
:: gives error, because address is inserted at index that doesn't match it
```
### generate new address (for receiving payment)
```
=walt1 (from-xpub:bl xpub1 ~ ~)
=res ~(gen-address wad:bl walt1 %0)
p.res
nixt.q.res
:: gives
:: [%bech32 'bc1q0adfj7ur750hjwufzzlfj5ytqzsnd7fz9fjuzc']
:: [p=1 q=0]
```
## Scanning
Mnemonic
```
abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
```
## Address Generation Integration Test
All on `~zod`:
```
:btc-provider|command [%set-credentials api-url='http://localhost:50002']
:btc-wallet-hook|action [%set-provider ~zod]
=scan-xpub 'zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs'
=fprint [%4 0xdead.beef]
:btc-wallet-store|action [%add-wallet scan-xpub fprint ~ [~ 3] [~ 6]]
:btc-wallet-store|action [%generate-address scan-xpub %0 meta=~]
```
:: make sure that the above address is watched
## Make a full TXBU
Provider is `~zod`, `~dopzod` is a client. Use the xpub from PRIVATE.md to have a balance
### setup
On `~zod`:
```
|commit %home
|start %btc-provider
|start %btc-wallet-store
|start %btc-wallet-hook
:btc-provider|command [%set-credentials api-url='http://localhost:50002']
:btc-provider|command [%whitelist-clients `(set ship)`(sy ~[~dopzod])]
=xpubzod 'zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs'
:btc-wallet-hook|action [%set-provider ~zod]
=fprint [%4 0xdead.beef]
:btc-wallet-store|action [%add-wallet xpubzod fprint ~ [~ 8] [~ 6]]
```
on `~dopzod`:
```
:: xpub from PRIVATE.md
|commit %home
|start %btc-wallet-store
|start %btc-wallet-hook
:btc-wallet-hook|action [%set-provider ~zod]
=xpubp 'zpub6r8dKyWJ31XF6n69KKeEwLjVC5ruqAbiJ4QCqLsrV36Mvx9WEjUaiPNPGFLHNCCqgCdy6iZC8ZgHsm6a1AUTVBMVbKGemNcWFcwBGSjJKbD'
=fprint [%4 0xbeef.dead]
:btc-wallet-store|action [%add-wallet xpubp fprint ~ [~ 8] [~ 6]]
```
### request address
on `~dopzod`:
```
:btc-wallet-hook|action [%req-pay-address payee=~zod value=2.000 [~ 30]]
:btc-wallet-hook +dbug [%state 'poym']
```
Sign the tx, then paste:
```
=tx TXHEX
:btc-wallet-hook|action [%broadcast-tx tx]
```
### Send Transaction
Check wallet store
```
:btc-wallet-store +dbug [%state 'history']
```
## scrys
```
.^((list @t) %gx /=btc-wallet-store=/scanned/noun)
.^(@ud %gx /=btc-wallet-store=/balance/[xpubp]/noun)
```