shrub/sur/btc-wallet-store.hoon

110 lines
3.4 KiB
Plaintext
Raw Normal View History

2020-10-28 16:20:24 +03:00
:: wallets are compatible with BIPs 44, 49, and 84
:: m / purpose' / coin_type' / account' / change / address_index
2020-10-29 15:10:54 +03:00
:: change can be 0 or 1
2020-10-28 16:20:24 +03:00
::
2020-12-06 14:46:32 +03:00
/- *btc, bp=btc-provider
2020-10-29 15:10:54 +03:00
/+ bip32
2020-10-24 19:13:36 +03:00
|%
2020-10-30 14:45:38 +03:00
++ max-index (dec (pow 2 32))
2020-10-31 14:25:32 +03:00
:: chyg: whether account is (non-)change. 0 or 1
:: idx: an address_index
2020-10-31 14:25:32 +03:00
:: nixt: next indices to generate addresses from (non-change/change)
2020-12-04 13:29:12 +03:00
:: addi: HD path along with UTXOs
2020-12-05 17:51:25 +03:00
:: - used: whether the address has been used
2020-10-31 14:25:32 +03:00
:: wach: map for watched addresses.
:: Membership implies the address is known by outside parties or had prior activity
:: scon: indices to initially scan to in (non-)change accounts
2020-10-30 14:45:38 +03:00
:: defaults to 2^32-1 (i.e. all the addresses, ~4B)
2020-10-29 15:10:54 +03:00
:: wilt: stores xpub; copulates with thousands of indices to form addresses
2020-10-28 16:20:24 +03:00
::
2020-10-29 21:07:43 +03:00
+$ chyg $?(%0 %1)
2020-10-31 14:25:32 +03:00
+$ idx @
+$ nixt (pair idx idx)
2020-12-05 17:51:25 +03:00
+$ addi [used=? =chyg =idx utxos=(set utxo)]
2020-10-29 15:10:54 +03:00
+$ wach (map address addi)
2020-10-31 14:25:32 +03:00
+$ scon $~([max-index max-index] (pair idx idx))
2020-10-28 16:20:24 +03:00
+$ wilt _bip32
2020-11-11 15:30:22 +03:00
:: walt: wallet datastructure
:: scanned: whether the wallet's addresses have been checked for prior activity
:: scan-to
2020-11-13 15:47:11 +03:00
:: max-gap: maximum number of consec blank addresses before wallet stops scanning
:: confs: confirmations required (after this is hit for an address, wallet stops refreshing it)
2020-11-11 15:30:22 +03:00
::
+$ walt
2020-12-06 20:53:02 +03:00
$: =xpub
=wilt
2020-11-11 15:30:22 +03:00
=bipt
=wach
=nixt
scanned=?
scan-to=scon
2020-11-13 15:47:11 +03:00
max-gap=@ud
confs=@ud
2020-11-11 15:30:22 +03:00
==
2020-12-07 11:59:30 +03:00
:: input: utxo for a transaction
2020-11-19 14:44:12 +03:00
:: feyb: fee per byte in sats
:: key: HD wallet path
:: txi/txo: input/output for a transaction being built
2020-12-06 14:46:32 +03:00
:: txbu: tx builder -- all information needed to make a transaction for signing
:: peta: optional payment metadata
2020-11-17 18:34:48 +03:00
::
2020-12-07 11:59:30 +03:00
+$ input [=utxo =chyg =idx]
2020-12-06 20:53:02 +03:00
+$ peta (unit [payer=ship value=sats])
2020-11-19 14:44:12 +03:00
+$ feyb sats
+$ key [=bipt =chyg =idx]
2020-11-20 14:58:27 +03:00
+$ txi [=utxo ur=(unit rawtx) =key]
2020-11-19 14:44:12 +03:00
+$ txo [=address value=sats]
2020-12-06 20:53:02 +03:00
+$ txbu
$: =req-id:bp
=xpub
payee=(unit ship)
=vbytes
txis=(list txi)
txos=(list txo)
==
2020-12-06 14:46:32 +03:00
:: hest: an entry in the history log
::
+$ hest
$: =txid
recvd=@da
inputs=(list [=utxo s=(unit ship)])
outputs=(list [=output s=(unit ship)])
==
2020-12-07 16:27:26 +03:00
+$ history (map xpub (map txid hest))
2020-12-06 14:46:32 +03:00
:: state/watch variables:
2020-11-28 10:25:32 +03:00
:: scanning addresses and monitoring generated addresses
:: batch: indexes to scan for a given chyg
:: scans: all scans underway (batches)
2020-12-06 14:46:32 +03:00
:: piym-watch: any address we've been told has an incoming payment promised
2020-10-31 15:38:53 +03:00
::
2020-11-03 14:50:10 +03:00
+$ batch [todo=(set idx) endpoint=idx has-used=?]
2020-11-02 16:12:44 +03:00
+$ scans (map [xpub chyg] batch)
::
:: %add-wallet: add wallet to state and initiate a scan
2020-12-03 12:47:54 +03:00
:: %address-info: give new data about an address.
:: - used: address has been seen on the BTC blockchain?
:: - block: the most recent block at the time of this information being retrieved
:: TODO: document
2020-10-31 15:38:53 +03:00
::
2020-10-31 12:41:00 +03:00
+$ action
2020-11-13 15:47:11 +03:00
$% [%add-wallet =xpub scan-to=(unit scon) max-gap=(unit @ud) confs=(unit @ud)]
2020-12-03 12:47:54 +03:00
[%address-info =xpub =chyg =idx utxos=(set utxo) used=? block=@ud]
2020-12-06 14:46:32 +03:00
[%generate-address =xpub =chyg =peta]
2020-11-19 18:54:01 +03:00
[%generate-txbu =xpub payee=(unit ship) feyb=sats txos=(list txo)]
2020-12-07 17:31:48 +03:00
[%add-history-entry =xpub =hest]
2020-11-11 11:17:54 +03:00
==
::
+$ update
2020-12-06 20:53:02 +03:00
$% [%generate-address =xpub =address =peta]
2020-11-22 15:57:25 +03:00
[%generate-txbu =xpub =txbu]
2020-12-06 14:46:32 +03:00
[%saw-piym s=ship =txid]
2020-11-13 15:47:11 +03:00
[%scan-done =xpub]
2020-10-29 21:07:43 +03:00
==
2020-12-04 21:54:59 +03:00
:: last-block: most recent block this address was checked
2020-10-31 20:26:58 +03:00
::
2020-11-13 15:47:11 +03:00
+$ request
2020-12-04 21:54:59 +03:00
$% [%address-info last-block=@ud a=address =xpub =chyg =idx]
2020-12-07 16:27:26 +03:00
[%tx-info last-block=@ud =txid]
2020-11-13 15:47:11 +03:00
==
2020-10-24 19:13:36 +03:00
--