2020-10-24 19:13:36 +03:00
|
|
|
:: btc-wallet-store.hoon
|
2020-10-19 12:04:51 +03:00
|
|
|
:: Manages wallet pubkeys
|
|
|
|
::
|
2020-10-28 16:20:24 +03:00
|
|
|
:: Subscriptions: none
|
|
|
|
:: To Subscribers:
|
|
|
|
:: watched address updates
|
|
|
|
::
|
2020-10-29 15:10:54 +03:00
|
|
|
/- *btc-wallet-store
|
|
|
|
/+ dbug, default-agent, bip32, btc
|
2020-10-19 12:04:51 +03:00
|
|
|
|%
|
|
|
|
+$ versioned-state
|
|
|
|
$% state-0
|
|
|
|
==
|
|
|
|
::
|
2020-10-30 12:06:42 +03:00
|
|
|
+$ state-0
|
|
|
|
$: %0
|
|
|
|
walts=(map tape walt)
|
|
|
|
max-gap=@
|
|
|
|
==
|
2020-10-19 12:04:51 +03:00
|
|
|
::
|
2020-10-24 19:13:36 +03:00
|
|
|
+$ card card:agent:gall
|
2020-10-19 12:04:51 +03:00
|
|
|
::
|
|
|
|
--
|
|
|
|
=| state-0
|
|
|
|
=* state -
|
|
|
|
%- agent:dbug
|
|
|
|
^- agent:gall
|
2020-10-29 15:10:54 +03:00
|
|
|
=<
|
2020-10-19 12:04:51 +03:00
|
|
|
|_ =bowl:gall
|
|
|
|
+* this .
|
|
|
|
def ~(. (default-agent this %|) bowl)
|
2020-10-29 15:10:54 +03:00
|
|
|
hc ~(. +> bowl)
|
2020-10-19 12:04:51 +03:00
|
|
|
::
|
|
|
|
++ on-init
|
|
|
|
^- (quip card _this)
|
2020-10-24 19:13:36 +03:00
|
|
|
~& > '%btc-wallet-store initialized'
|
2020-10-30 12:06:42 +03:00
|
|
|
`this(state [%0 *(map tape walt) max-gap=20])
|
2020-10-19 12:04:51 +03:00
|
|
|
++ on-save
|
|
|
|
^- vase
|
|
|
|
!>(state)
|
|
|
|
++ on-load
|
|
|
|
|= old-state=vase
|
|
|
|
^- (quip card _this)
|
2020-10-24 19:13:36 +03:00
|
|
|
~& > '%btc-wallet-store recompiled'
|
2020-10-19 12:04:51 +03:00
|
|
|
`this(state !<(versioned-state old-state))
|
|
|
|
++ on-poke
|
|
|
|
|= [=mark =vase]
|
|
|
|
^- (quip card _this)
|
2020-10-29 15:10:54 +03:00
|
|
|
?> (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]
|
2020-10-19 12:04:51 +03:00
|
|
|
::
|
2020-10-29 21:07:43 +03:00
|
|
|
++ on-watch
|
|
|
|
|= pax=path
|
|
|
|
^- (quip card _this)
|
|
|
|
?> (team:title our.bowl src.bowl)
|
|
|
|
?> ?=([%wallets *] pax)
|
|
|
|
`this
|
2020-10-19 12:04:51 +03:00
|
|
|
++ on-leave on-leave:def
|
|
|
|
++ on-peek on-peek:def
|
|
|
|
++ on-agent on-agent:def
|
|
|
|
++ on-arvo on-arvo:def
|
|
|
|
++ on-fail on-fail:def
|
|
|
|
--
|
2020-10-29 15:10:54 +03:00
|
|
|
::
|
|
|
|
|_ =bowl:gall
|
|
|
|
++ handle-action
|
|
|
|
|= act=action
|
|
|
|
^- (quip card _state)
|
|
|
|
?- -.act
|
|
|
|
%add-wallet
|
2020-10-30 12:06:42 +03:00
|
|
|
(add-wallet +.act)
|
2020-10-29 21:07:43 +03:00
|
|
|
::
|
|
|
|
%update-address
|
|
|
|
(update-address +.act)
|
2020-10-29 15:10:54 +03:00
|
|
|
==
|
2020-10-29 21:07:43 +03:00
|
|
|
++ update-address
|
|
|
|
|= [a=address us=(set utxo)]
|
|
|
|
^- (quip card _state)
|
|
|
|
=/ xpubs=(list tape)
|
|
|
|
%~ tap in
|
2020-10-30 12:06:42 +03:00
|
|
|
~(key by walts.state)
|
2020-10-29 21:07:43 +03:00
|
|
|
|- ?~ xpubs `state
|
2020-10-30 12:06:42 +03:00
|
|
|
=/ w=walt (~(got by walts.state) i.xpubs)
|
2020-10-29 21:07:43 +03:00
|
|
|
?: (~(has by wach.w) a)
|
|
|
|
%: send-address-update
|
|
|
|
i.xpubs
|
|
|
|
(update-wallet w a us)
|
|
|
|
a
|
|
|
|
us
|
|
|
|
==
|
|
|
|
$(xpubs t.xpubs)
|
|
|
|
::
|
|
|
|
++ update-wallet
|
|
|
|
|= [w=walt a=address us=(set utxo)]
|
|
|
|
^- walt
|
|
|
|
=/ curr-addi=addi
|
|
|
|
(~(got by wach.w) a)
|
|
|
|
w(wach (~(put by wach.w) a curr-addi(used %.y, utxos us)))
|
|
|
|
::
|
|
|
|
++ send-address-update
|
|
|
|
|= [xpub=tape =walt a=address us=(set utxo)]
|
|
|
|
^- (quip card _state)
|
2020-10-30 12:06:42 +03:00
|
|
|
:_ state(walts (~(put by walts.state) xpub walt))
|
2020-10-29 21:07:43 +03:00
|
|
|
~[[%give %fact ~[/wallets] %btc-wallet-store-update !>([%address a us])]]
|
|
|
|
::
|
2020-10-29 15:10:54 +03:00
|
|
|
++ add-wallet
|
2020-10-30 12:06:42 +03:00
|
|
|
|= [xpub=tape scan-to=(unit scon) max-gap=(unit @)]
|
2020-10-29 15:10:54 +03:00
|
|
|
^- (quip card _state)
|
2020-10-30 12:06:42 +03:00
|
|
|
?: (~(has by walts.state) xpub)
|
2020-10-29 15:10:54 +03:00
|
|
|
~& >>> "xpub already imported"
|
|
|
|
`state
|
|
|
|
=/ wallet=walt
|
|
|
|
:* (from-extended:bip32 xpub)
|
|
|
|
(xpub-type:btc xpub)
|
2020-10-29 21:07:43 +03:00
|
|
|
*wach
|
|
|
|
[0 0]
|
2020-10-30 12:06:42 +03:00
|
|
|
%.n
|
|
|
|
(fall scan-to *scon)
|
|
|
|
(fall max-gap max-gap.state)
|
2020-10-29 15:10:54 +03:00
|
|
|
==
|
2020-10-30 12:06:42 +03:00
|
|
|
`state(walts (~(put by walts.state) xpub wallet))
|
2020-10-29 15:10:54 +03:00
|
|
|
--
|