shrub/sur/btc-wallet-store.hoon

72 lines
2.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-10-29 15:10:54 +03:00
/- *btc
/+ 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-10-29 15:10:54 +03:00
:: addi: address with metadata inside a change path
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)
+$ addi [=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
$: =wilt
=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-11-17 18:34:48 +03:00
:: input: utxo for a transaction
::
+$ input [=utxo =chyg =idx]
2020-10-31 20:26:58 +03:00
:: todo: Set of indices; empty it out until none are left--means scanning of that batch is done
2020-11-11 15:30:22 +03:00
:: start: index this batch started scanning from
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
:: %scan: start a scan of the next address batch in a wallet
:: if the scan is complete, update the wallet and remove from scans
:: %watch-address: watch an address if used, remove from scans batch if not
:: %update-address: update info of an address if we're watching it
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)]
[%address-info =xpub =chyg =idx utxos=(set utxo) used=? blockcount=@ud]
2020-11-19 12:45:05 +03:00
[%generate-address =xpub =chyg meta=(unit [payer=ship value=sats])]
2020-11-11 11:17:54 +03:00
==
::
+$ update
2020-11-19 12:45:05 +03:00
$% [%generate-address =address meta=(unit [payer=ship value=sats])]
2020-11-13 15:47:11 +03:00
[%scan-done =xpub]
2020-10-29 21:07:43 +03:00
==
2020-10-31 20:26:58 +03:00
::
2020-11-13 15:47:11 +03:00
+$ request
$% [%scan-address a=address =xpub =chyg =idx]
==
2020-10-24 19:13:36 +03:00
--