From 794d3fe570d587accd08ef767f26dc7c308d60cd Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Thu, 21 Oct 2021 13:03:05 -0500 Subject: [PATCH 1/2] bitcoin: revive settings-store migration --- pkg/bitcoin/app/btc-wallet.hoon | 63 +++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/pkg/bitcoin/app/btc-wallet.hoon b/pkg/bitcoin/app/btc-wallet.hoon index 86c05df721..2f56c45506 100644 --- a/pkg/bitcoin/app/btc-wallet.hoon +++ b/pkg/bitcoin/app/btc-wallet.hoon @@ -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,37 @@ == [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)) + %- zing + %+ turn ~(tap by bucket.dat) + (cork copy-if-missing drop) + :: + ++ 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) @@ -864,7 +910,7 @@ :: %tx-info :: TODO: why do we get a nest-fail when using =^ ? - =/ [cards=(list card) sty=state-2] + =/ [cards=(list card) sty=state-3] (handle-tx-info:hc info.p.upd) :_ sty :_ cards @@ -1056,7 +1102,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 ~ From 36793615b6ea54db3d616b5c28b551abda8d3160 Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Thu, 21 Oct 2021 14:09:51 -0500 Subject: [PATCH 2/2] bitcoin: address joe review --- pkg/bitcoin/app/btc-wallet.hoon | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pkg/bitcoin/app/btc-wallet.hoon b/pkg/bitcoin/app/btc-wallet.hoon index 2f56c45506..d2fc5ac70e 100644 --- a/pkg/bitcoin/app/btc-wallet.hoon +++ b/pkg/bitcoin/app/btc-wallet.hoon @@ -183,9 +183,7 @@ ?> ?=(%bucket -.dat) |^ :- =/ del=event:settings [%del-bucket %landscape %btc-wallet] (poke-our:hc %settings-store %settings-event !>(del)) - %- zing - %+ turn ~(tap by bucket.dat) - (cork copy-if-missing drop) + (murn ~(tap by bucket.dat) copy-if-missing) :: ++ copy-if-missing |= [=key:settings =val:settings] @@ -899,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 @@ -910,9 +908,9 @@ :: %tx-info :: TODO: why do we get a nest-fail when using =^ ? - =/ [cards=(list card) sty=state-3] + =^ cards=(list card) state (handle-tx-info:hc info.p.upd) - :_ sty + :_ state :_ cards (poke-internal:hc [%close-pym info.p.upd]) ::