mirror of
https://github.com/urbit/shrub.git
synced 2024-12-24 03:14:30 +03:00
WIP: lib/btc-wallet-store refactored
This commit is contained in:
parent
61b9c8a508
commit
001f42c949
2
ARCH.md
2
ARCH.md
@ -41,7 +41,7 @@ Incoming data:
|
|||||||
- responses from `btc-provider`
|
- responses from `btc-provider`
|
||||||
- connectivity status from `btc-provider`
|
- connectivity status from `btc-provider`
|
||||||
- address lookup requests from `btc-wallet-store`
|
- address lookup requests from `btc-wallet-store`
|
||||||
- newlyy generated/watched addresses from `btc-wallet-store`
|
- newly generated/watched addresses from `btc-wallet-store`
|
||||||
|
|
||||||
Outgoing data:
|
Outgoing data:
|
||||||
- pokes `btc-wallet-store` with address updates
|
- pokes `btc-wallet-store` with address updates
|
||||||
|
@ -12,34 +12,31 @@ absurd sick rose mask magnet know slide spell rent casual someone grant giant in
|
|||||||
=bl -build-file %/lib/btc-wallet-store/hoon
|
=bl -build-file %/lib/btc-wallet-store/hoon
|
||||||
```
|
```
|
||||||
|
|
||||||
### add
|
|
||||||
```
|
|
||||||
:btc-wallet-store|action [%add-wallet xpub ~ ~]
|
|
||||||
```
|
|
||||||
|
|
||||||
### get address at indices
|
### get address at indices
|
||||||
```
|
```
|
||||||
=walt1 (from-xpub:walt:bl xpub1 ~ ~)
|
=walt1 (from-xpub:bl xpub1 ~ ~)
|
||||||
(get-address:walt1 %0 0)
|
(~(mk-address wad:bl walt1 %0) 0)
|
||||||
|
:: gives [%bech32 'bc1q0adfj7ur750hjwufzzlfj5ytqzsnd7fz9fjuzc']
|
||||||
```
|
```
|
||||||
|
|
||||||
### update address data
|
### update address data
|
||||||
```
|
```
|
||||||
=walt1 (from-xpub:walt:bl xpub1 ~ ~)
|
=walt1 (from-xpub:bl xpub1 ~ ~)
|
||||||
(~(mk-address walt1 %0) 0)
|
(~(mk-address wad:bl walt1 %0) 0)
|
||||||
:: gives bc1q0adfj7ur750hjwufzzlfj5ytqzsnd7fz9fjuzc
|
:: gives bc1q0adfj7ur750hjwufzzlfj5ytqzsnd7fz9fjuzc
|
||||||
=walt1 (~(insert-address walt1 %0) [%bech32 'bc1q0adfj7ur750hjwufzzlfj5ytqzsnd7fz9fjuzc'] [%0 0 ~])
|
=walt1 (~(watch-address wad:bl walt1 %0) [%bech32 'bc1q0adfj7ur750hjwufzzlfj5ytqzsnd7fz9fjuzc'] [%0 0 ~])
|
||||||
nixt.st.walt1
|
nixt.walt1
|
||||||
:: gives [p=1 q=0] (nixt updated since it was 0)
|
:: gives [p=1 q=0] (nixt updated since it was 0)
|
||||||
=walt1 (~(insert-address walt1 %0) [%bech32 'bc1qa5jcdww8u8493zttjjf6q5wu89e6knpvmsh7x4'] [%0 2 ~])
|
=walt1 (~(watch-address wad:bl walt1 %0) [%bech32 'bc1qa5jcdww8u8493zttjjf6q5wu89e6knpvmsh7x4'] [%0 2 ~])
|
||||||
nixt.st.walt1
|
nixt.walt1=walt1 (~(watch-address wad:bl walt1 %0) [%bech32 'bc1qa5jcdww8u8493zttjjf6q5wu89e6knpvmsh7x4'] [%0 2 ~])
|
||||||
|
nixt.walt1
|
||||||
:: gives [p=1 q=0] (no update)
|
:: gives [p=1 q=0] (no update)
|
||||||
=walt1 (~(insert-address walt1 %0) [%bech32 'bc1qvqrdh8suyv63ntaa0d7hmcamavv8283sngh6e5'] [%0 1 ~])
|
=walt1 (~(watch-address wad:bl walt1 %0) [%bech32 'bc1qvqrdh8suyv63ntaa0d7hmcamavv8283sngh6e5'] [%0 1 ~])
|
||||||
nixt.st.walt1
|
nixt.walt1
|
||||||
:: gives [p=3 q=0] (skips index 2, since already a used address there)
|
:: gives [p=3 q=0] (skips index 2, since already a used address there)
|
||||||
|
|
||||||
=walt1 (insert-address:walt1 [%bech32 'bc1qvqrdh8suyv63ntaa0d7hmcamavv8283sngh6e5'] [%0 4 ~])
|
=walt1 (~(watch-address wad:bl walt1 %0) [%bech32 'bc1qvqrdh8suyv63ntaa0d7hmcamavv8283sngh6e5'] [%0 4 ~])
|
||||||
:: gives error, because address is inserted at the wrong index
|
:: gives error, because address is inserted at index that doesn't match it
|
||||||
```
|
```
|
||||||
|
|
||||||
### generate new address (for receiving payment)
|
### generate new address (for receiving payment)
|
||||||
|
@ -6,14 +6,6 @@
|
|||||||
=+ ecc=secp256k1
|
=+ ecc=secp256k1
|
||||||
|%
|
|%
|
||||||
++ default-max-gap 20
|
++ default-max-gap 20
|
||||||
:: walt: door parameterized on chyg (the change account to use for current operation)
|
|
||||||
:: to access state, use VARNAME.st.WALTNAME, e.g. nixt.st.walt1
|
|
||||||
::
|
|
||||||
:: wach: map of watched addresses
|
|
||||||
:: scanned: whether the wallet's addresses have been checked for prior activity
|
|
||||||
:: scan-to
|
|
||||||
:: max-gap
|
|
||||||
::
|
|
||||||
::
|
::
|
||||||
++ hash-xpub
|
++ hash-xpub
|
||||||
|= [=xpub:btc =chyg =idx]
|
|= [=xpub:btc =chyg =idx]
|
||||||
@ -22,37 +14,36 @@
|
|||||||
=/ dat=@ (cat 3 xpub chygidx)
|
=/ dat=@ (cat 3 xpub chygidx)
|
||||||
%- ripemd-160:ripemd:crypto
|
%- ripemd-160:ripemd:crypto
|
||||||
[(met 3 dat) dat]
|
[(met 3 dat) dat]
|
||||||
++ walt
|
|
||||||
=| st=[=wilt =bipt =wach =nixt scanned=? scan-to=scon max-gap=@]
|
|
||||||
|_ =chyg
|
|
||||||
+* this .
|
|
||||||
::
|
::
|
||||||
++ from-xpub
|
++ from-xpub
|
||||||
|= [=xpub:btc scan-to=(unit scon) max-gap=(unit @)]
|
|= [=xpub:btc scan-to=(unit scon) max-gap=(unit @)]
|
||||||
^- _this
|
^- walt
|
||||||
%= this
|
:* (from-extended:bip32 (trip xpub))
|
||||||
wilt.st (from-extended:bip32 (trip xpub))
|
(xpub-type:btc xpub)
|
||||||
bipt.st (xpub-type:btc xpub)
|
*wach
|
||||||
wach.st *wach
|
[0 0]
|
||||||
nixt.st [0 0]
|
%.n
|
||||||
scanned.st %.n
|
(fall scan-to *scon)
|
||||||
scan-to.st (fall scan-to *scon)
|
(fall max-gap default-max-gap)
|
||||||
max-gap.st (fall max-gap default-max-gap)
|
|
||||||
==
|
==
|
||||||
|
:: wad: door for processing walts (wallets)
|
||||||
|
:: parameterized on a walt and it's chyg account
|
||||||
::
|
::
|
||||||
|
++ wad
|
||||||
|
|_ [w=walt =chyg]
|
||||||
++ mk-address
|
++ mk-address
|
||||||
|= =idx
|
|= =idx
|
||||||
^- address:btc
|
^- address:btc
|
||||||
=/ pubkey=@ux
|
=/ pubkey=@ux
|
||||||
%- compress-point:ecc
|
%- compress-point:ecc
|
||||||
pub:(derive-public:(derive-public:wilt.st (@ chyg)) idx)
|
pub:(derive-public:(derive-public:wilt.w (@ chyg)) idx)
|
||||||
?: ?=(%bip84 bipt.st)
|
?: ?=(%bip84 bipt.w)
|
||||||
(need (encode-pubkey:bech32:btc %main pubkey))
|
(need (encode-pubkey:bech32:btc %main pubkey))
|
||||||
~|("legacy addresses not supported yet " !!)
|
~|("legacy addresses not supported yet " !!)
|
||||||
:: generates and watches the next available address
|
:: generates and watches the next available address
|
||||||
::
|
::
|
||||||
++ gen-address
|
++ gen-address
|
||||||
^- (pair address:btc _this)
|
^- (pair address:btc walt)
|
||||||
=/ addr (mk-address nixt-idx)
|
=/ addr (mk-address nixt-idx)
|
||||||
:- addr
|
:- addr
|
||||||
(watch-address addr [chyg nixt-idx *(set utxo:btc)])
|
(watch-address addr [chyg nixt-idx *(set utxo:btc)])
|
||||||
@ -60,29 +51,29 @@
|
|||||||
::
|
::
|
||||||
++ watch-address
|
++ watch-address
|
||||||
|= [a=address:btc =addi]
|
|= [a=address:btc =addi]
|
||||||
^- _this
|
^- walt
|
||||||
?> =(chyg chyg.addi)
|
?> =(chyg chyg.addi)
|
||||||
?> =(a (mk-address idx.addi))
|
?> =(a (mk-address idx.addi))
|
||||||
=? nixt.st (is-nixt addi)
|
=? nixt.w (is-nixt addi)
|
||||||
new:bump-nixt
|
new:bump-nixt
|
||||||
this(wach.st (~(put by wach.st) a addi))
|
w(wach (~(put by wach.w) a addi))
|
||||||
:: update an address if it's in our wach map
|
:: update an address if it's in wach map
|
||||||
::
|
::
|
||||||
++ update-address
|
++ update-address
|
||||||
|= [a=address:btc utxos=(set utxo:btc)]
|
|= [a=address:btc utxos=(set utxo:btc)]
|
||||||
^- _this
|
^- walt
|
||||||
=/ adi=(unit addi)
|
=/ adi=(unit addi)
|
||||||
(~(get by wach.st) a)
|
(~(get by wach.w) a)
|
||||||
?~ adi this
|
?~ adi w
|
||||||
this(wach.st (~(put by wach.st) a u.adi(utxos utxos)))
|
w(wach (~(put by wach.w) a u.adi(utxos utxos)))
|
||||||
::
|
::
|
||||||
++ is-nixt
|
++ is-nixt
|
||||||
|= =addi ^- ?
|
|= =addi ^- ?
|
||||||
?: ?=(%0 chyg.addi)
|
?: ?=(%0 chyg.addi)
|
||||||
=(idx.addi p.nixt.st)
|
=(idx.addi p.nixt.w)
|
||||||
=(idx.addi q.nixt.st)
|
=(idx.addi q.nixt.w)
|
||||||
++ nixt-idx
|
++ nixt-idx
|
||||||
?:(?=(%0 chyg) p.nixt.st q.nixt.st)
|
?:(?=(%0 chyg) p.nixt.w q.nixt.w)
|
||||||
:: Returns: the prior idx in the account
|
:: Returns: the prior idx in the account
|
||||||
:: nixt with account idx bumped
|
:: nixt with account idx bumped
|
||||||
:: Increments idx until an unwatched address is found
|
:: Increments idx until an unwatched address is found
|
||||||
@ -93,13 +84,13 @@
|
|||||||
:- nixt-idx
|
:- nixt-idx
|
||||||
=/ new-idx=idx +(nixt-idx)
|
=/ new-idx=idx +(nixt-idx)
|
||||||
|- ?> (lte new-idx max-index)
|
|- ?> (lte new-idx max-index)
|
||||||
?. (~(has by wach.st) (mk-address new-idx))
|
?. (~(has by wach.w) (mk-address new-idx))
|
||||||
(set-nixt new-idx)
|
(set-nixt new-idx)
|
||||||
$(new-idx +(new-idx))
|
$(new-idx +(new-idx))
|
||||||
::
|
::
|
||||||
++ set-nixt
|
++ set-nixt
|
||||||
|= idx=@ ^- nixt
|
|= idx=@ ^- nixt
|
||||||
?:(?=(%0 chyg) [idx q.nixt.st] [p.nixt.st idx])
|
?:(?=(%0 chyg) [idx q.nixt.w] [p.nixt.w idx])
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
:: scon: indices to initially scan to in (non-)change accounts
|
:: scon: indices to initially scan to in (non-)change accounts
|
||||||
:: defaults to 2^32-1 (i.e. all the addresses, ~4B)
|
:: defaults to 2^32-1 (i.e. all the addresses, ~4B)
|
||||||
:: wilt: stores xpub; copulates with thousands of indices to form addresses
|
:: wilt: stores xpub; copulates with thousands of indices to form addresses
|
||||||
:: walt: wallet metadata
|
|
||||||
::
|
::
|
||||||
+$ chyg $?(%0 %1)
|
+$ chyg $?(%0 %1)
|
||||||
+$ idx @
|
+$ idx @
|
||||||
@ -26,6 +25,20 @@
|
|||||||
+$ wach (map address addi)
|
+$ wach (map address addi)
|
||||||
+$ scon $~([max-index max-index] (pair idx idx))
|
+$ scon $~([max-index max-index] (pair idx idx))
|
||||||
+$ wilt _bip32
|
+$ wilt _bip32
|
||||||
|
:: walt: wallet datastructure
|
||||||
|
:: scanned: whether the wallet's addresses have been checked for prior activity
|
||||||
|
:: scan-to
|
||||||
|
:: max-gap
|
||||||
|
::
|
||||||
|
+$ walt
|
||||||
|
$: =wilt
|
||||||
|
=bipt
|
||||||
|
=wach
|
||||||
|
=nixt
|
||||||
|
scanned=?
|
||||||
|
scan-to=scon
|
||||||
|
max-gap=@
|
||||||
|
==
|
||||||
:: todo: Set of indices; empty it out until none are left--means scanning of that batch is done
|
:: todo: Set of indices; empty it out until none are left--means scanning of that batch is done
|
||||||
:: start: index this batch started scanning from
|
:: start: index this batch started scanning from
|
||||||
::
|
::
|
||||||
|
Loading…
Reference in New Issue
Block a user