Merge pull request #5346 from urbit/lf/nicer-btc-migration

bitcoin: revive settings-store migration
This commit is contained in:
fang 2021-10-22 15:45:40 +02:00 committed by GitHub
commit 252e142d5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,7 +4,7 @@
:: x/scanned: (list xpub) of all scanned wallets
:: x/balance/xpub: balance (in sats) of wallet
/- *btc-wallet, bp=btc-provider, settings
/+ dbug, default-agent, bl=btc, bc=bitcoin, bcu=bitcoin-utils, bip32
/+ dbug, default-agent, bl=btc, bc=bitcoin, bcu=bitcoin-utils, bip32, agentio
~% %btc-wallet-top ..part ~
|%
+$ card card:agent:gall
@ -24,6 +24,7 @@
$% state-0
state-1
state-2
state-3
==
::
+$ state-0
@ -57,8 +58,9 @@
::
+$ state-1 [%1 base-state]
+$ state-2 [%2 base-state]
+$ state-3 [%3 base-state]
--
=| state-2
=| state-3
=* state -
%- agent:dbug
^- agent:gall
@ -68,6 +70,8 @@
+* this .
def ~(. (default-agent this %|) bowl)
hc ~(. +> bowl)
io ~(. agentio bowl)
pass pass:io
::
++ on-init
^- (quip card _this)
@ -83,7 +87,7 @@
:- cards
%_ this
state
:* %2
:* %3
~
*(map xpub:bc walt)
*^btc-state
@ -110,8 +114,14 @@
=| cards=(list card)
|-
?- -.ver
%3
[(flop cards) this(state ver)]
::
%2
[cards this(state ver)]
%_ $
-.ver %3
cards :_(cards (~(wait pass /migrate-settings) (add now.bowl ~s1)))
==
::
%1
=? cards ?=(^ prov.ver)
@ -138,6 +148,11 @@
|^
=^ cards state
?+ mark (on-poke:def mark vase)
::
%noun
?> =(our.bowl src.bowl)
(handle-noun q.vase)
::
%btc-wallet-command
?> =(our.bowl src.bowl)
(handle-command !<(command vase))
@ -152,6 +167,35 @@
==
[cards this]
::
++ handle-noun
|= non=*
?> ?=(%migrate-settings non)
:_ state
^- (list card)
=/ bas=path /(scot %p our.bowl)/settings-store/(scot %da now.bowl)
?. .^(? %gu bas)
~& [dap.bowl %settings-store-mia]
~
?. .^(? %gx (weld bas /has-bucket/landscape/btc-wallet/noun))
~
=/ dat
.^(data:settings %gx (weld bas /bucket/landscape/btc-wallet/noun))
?> ?=(%bucket -.dat)
|^ :- =/ del=event:settings [%del-bucket %landscape %btc-wallet]
(poke-our:hc %settings-store %settings-event !>(del))
(murn ~(tap by bucket.dat) copy-if-missing)
::
++ copy-if-missing
|= [=key:settings =val:settings]
^- (unit card)
=/ hav=?
.^(? %gx (weld bas /has-entry/[q.byk.bowl]/btc-wallet/[key]/noun))
?: hav ~
~& [dap.bowl %importing-previous-setting key]
=/ put=event:settings [%put-entry q.byk.bowl %btc-wallet key val]
`(poke-our:hc %settings-store %settings-event !>(put))
--
::
++ handle-command
|= comm=command
^- (quip card _state)
@ -853,8 +897,8 @@
|= upd=update:bp
^- (quip card _state)
|^
?~ prov `state
?. =(host.u.prov src.bowl) `state
?: =(~ prov) `state
?. =(host:(need prov) src.bowl) `state
?. ?=(%.y -.upd) `state
?- -.p.upd
%address-info
@ -864,9 +908,9 @@
::
%tx-info
:: TODO: why do we get a nest-fail when using =^ ?
=/ [cards=(list card) sty=state-2]
=^ cards=(list card) state
(handle-tx-info:hc info.p.upd)
:_ sty
:_ state
:_ cards
(poke-internal:hc [%close-pym info.p.upd])
::
@ -1056,7 +1100,12 @@
==
::
++ on-leave on-leave:def
++ on-arvo on-arvo:def
++ on-arvo
|= [=wire sign=sign-arvo]
^- (quip card _this)
?. ?=([%migrate-settings ~] wire) (on-arvo:def wire sign)
?> ?=([%behn *] sign)
(on-poke %noun !>(%migrate-settings))
++ on-fail on-fail:def
--
~% %btc-wallet-helper ..card ~