2020-10-30 14:45:38 +03:00
|
|
|
/- *btc-wallet-store
|
|
|
|
/+ bip32, btc
|
|
|
|
=, secp:crypto
|
|
|
|
=+ ecc=secp256k1
|
|
|
|
|%
|
|
|
|
++ default-max-gap 20
|
|
|
|
:: xpub
|
|
|
|
:: wilt
|
|
|
|
:: bipt: BIP44/49/84
|
|
|
|
:: wach
|
|
|
|
:: next: next index to generate address for in non-change/change accounts respectively
|
|
|
|
:: scanned: whether the wallet's addresses have been checked for prior activity
|
|
|
|
:: if unscanned, 'next' values won't be valid
|
|
|
|
:: scan-to
|
|
|
|
:: max-gap
|
|
|
|
::
|
2020-10-31 12:41:00 +03:00
|
|
|
++ is-next
|
|
|
|
|= [adi=addi next=idxs] ^- ?
|
|
|
|
?| =(idx.addi p.next)
|
|
|
|
=(idx.addi q.next)
|
|
|
|
==
|
|
|
|
::
|
2020-10-30 14:45:38 +03:00
|
|
|
++ walt
|
|
|
|
|_ [=wilt =bipt =wach next=idxs scanned=? scan-to=scon max-gap=@u]
|
2020-10-31 12:41:00 +03:00
|
|
|
+* this .
|
|
|
|
::
|
2020-10-30 14:45:38 +03:00
|
|
|
++ from-xpub
|
2020-10-31 12:41:00 +03:00
|
|
|
|= [=xpub:btc scan-to=(unit scon) max-gap=(unit @u)]
|
|
|
|
^- _this
|
|
|
|
%= this
|
|
|
|
wilt (from-extended:bip32 (trip xpub))
|
2020-10-30 14:45:38 +03:00
|
|
|
bipt (xpub-type:btc xpub)
|
|
|
|
wach *^wach
|
2020-10-31 12:41:00 +03:00
|
|
|
next [[%0 0] [%1 0]]
|
2020-10-30 14:45:38 +03:00
|
|
|
scanned %.n
|
|
|
|
scan-to (fall scan-to *scon)
|
|
|
|
max-gap (fall max-gap default-max-gap)
|
|
|
|
==
|
|
|
|
++ get-address
|
|
|
|
|= [=chyg idx=@]
|
|
|
|
^- address:btc
|
|
|
|
=/ pubkey=@ux
|
|
|
|
%- compress-point:ecc
|
|
|
|
pub:(derive-public:(derive-public:wilt (@u chyg)) idx)
|
|
|
|
?: ?=(%bip84 bipt)
|
|
|
|
(need (encode-pubkey:bech32:btc %main pubkey))
|
|
|
|
~|("legacy addresses not supported yet" !!)
|
2020-10-31 12:41:00 +03:00
|
|
|
::
|
|
|
|
:: should take index as a parameter so that we can write that to addi and update used
|
|
|
|
++ insert-address %dummy
|
|
|
|
++ update-address
|
|
|
|
|= [a=address:btc used=? utxos=(set utxo:btc)]
|
|
|
|
^- _this
|
|
|
|
=/ adi=(unit addi)
|
|
|
|
(~(get by wach) a)
|
|
|
|
?~ adi this
|
|
|
|
=. wach
|
|
|
|
(~(put by wach) a u.adi(used used, utxos utxos))
|
|
|
|
?. ?&(used (is-next u.adi next)) this
|
|
|
|
:: if used AND this is next index, we need to do update next
|
|
|
|
this
|
|
|
|
::
|
|
|
|
++ next-unused-idx
|
|
|
|
|= c=chyg
|
|
|
|
^- idx
|
|
|
|
=/ indices=(list idx)
|
|
|
|
%+ turn ~(val by wach)
|
|
|
|
|=(a=addi idx.a)
|
|
|
|
*idx
|
|
|
|
:: check next for this one--problem is that we can't index in
|
2020-10-30 14:45:38 +03:00
|
|
|
--
|
|
|
|
--
|