skeleton for btc-wallet-store

This commit is contained in:
timlucmiptev 2020-10-29 14:10:54 +02:00 committed by ixv
parent 7b00d8c99e
commit e03d084fb0
6 changed files with 76 additions and 17 deletions

View File

@ -47,7 +47,7 @@
?> ?|((team:title our.bowl src.bowl) (is-client:hc src.bowl))
=^ cards state
?: ?=(%btc-provider-command mark)
?> (team:title our.bowl src.bowl)
?> (team:title our.bowl src.bowl)
(handle-command:hc !<(command vase))
?+ mark (on-poke:def mark vase)
%btc-provider-action

View File

@ -5,28 +5,27 @@
:: To Subscribers:
:: watched address updates
::
/+ dbug, default-agent
/- *btc-wallet-store
/+ dbug, default-agent, bip32, btc
|%
+$ versioned-state
$% state-0
==
::
+$ state-0 [%0 connected=?]
+$ state-0 [%0 wallets=(map tape walt)]
::
+$ card card:agent:gall
+$ command
$? %add-wallet
==
::
--
=| state-0
=* state -
%- agent:dbug
^- agent:gall
=<
|_ =bowl:gall
+* this .
des ~(. (default:shoe this command) bowl)
def ~(. (default-agent this %|) bowl)
hc ~(. +> bowl)
::
++ on-init
^- (quip card _this)
@ -43,7 +42,13 @@
++ on-poke
|= [=mark =vase]
^- (quip card _this)
`this
?> (team:title our.bowl src.bowl)
=^ cards state
?+ mark (on-poke:def mark vase)
%btc-wallet-store-action
(handle-action:hc !<(action vase))
==
[cards this]
::
++ on-watch on-watch:def
++ on-leave on-leave:def
@ -52,3 +57,26 @@
++ on-arvo on-arvo:def
++ on-fail on-fail:def
--
::
|_ =bowl:gall
++ handle-action
|= act=action
^- (quip card _state)
?- -.act
%add-wallet
(add-wallet xpub.act)
==
++ add-wallet
|= xpub=tape
^- (quip card _state)
?: (~(has by wallets.state) xpub)
~& >>> "xpub already imported"
`state
=/ wallet=walt
:* (from-extended:bip32 xpub)
(xpub-type:btc xpub)
[%.n 0 *wach]
[%.n 0 *wach]
==
`state(wallets (~(put by wallets.state) xpub wallet))
--

View File

@ -0,0 +1,13 @@
:: Sends an action to btc-wallet-store
::
:: Commands:
::
::
::
/- *btc-wallet-store
::
:- %say
|= $: [now=@da eny=@uvJ =beak]
[[act=action ~] ~]
==
[%btc-wallet-store-action act]

View File

@ -1,5 +1,13 @@
/- *btc
|%
++ xpub-type
|= xpub=tape
^- bipt
=/ prefix=tape (scag 4 xpub)
?: =("xpub" prefix) %bip44
?: =("ypub" prefix) %bip49
?: =("zpub" prefix) %bip84
~|("invalid xpub: {<xpub>}" !!)
:: big endian sha256: input and output are both MSB first (big endian)
::
++ sha256

View File

@ -1,22 +1,31 @@
:: wallets are compatible with BIPs 44, 49, and 84
:: m / purpose' / coin_type' / account' / change / address_index
:: change can be 0 or 1
::
/- *btc, bip32
/- *btc
/+ bip32
|%
:: wilt: copulates with thousands of indices to form addresses
:: addi: address with metadata inside a change path
:: wach: map for watched addresses
:: chyg: stores the state of a change/non-change path
:: wilt: stores xpub; copulates with thousands of indices to form addresses
:: walt: wallet metadata
::
+$ addi [idx=@ used=? utxos=(set utxo)]
+$ wach (map address addi)
+$ chyg [scanned=? next=@ =wach]
+$ wilt _bip32
+$ walt
$: :: scanned: whether we've checked all addresses for prior activity
$: :: bipt: BIP44/49/84
:: ching: non-change addresses
:: chang: change addresses
:: watch: address -> [change address_index]
::
=wilt
scanned=?
ching=((mop @ address-info) gth)
chang=((mop @ address-info) gth)
watch=(map address [change=@ index=@])
=bipt
ching=chyg
chang=chyg
==
+$ action
$% [%add-wallet xpub=tape]
==
--

View File

@ -3,7 +3,8 @@
+$ legacy-address $%([%legacy @uc])
+$ bech32-address $%([%bech32 cord])
+$ address ?(legacy-address bech32-address)
+$ sats @ud
+$ bipt $?(%bip44 %bip49 %bip84)
+$ sats @ud ::
+$ hash256 [wid=%32 dat=@ux]
+$ hash160 [wid=%20 dat=@ux]
+$ hash ?(hash256 hash160)