@@ -501,8 +501,8 @@ observableRollbackUseInTestsOnly = runUpdateDiscardSnapshot $
501
501
-- 'createHdWallet'/'createWalletHdRnd' in "Cardano.Wallet.Kernel.Wallets".
502
502
--
503
503
-- INVARIANT: Creating a new wallet always come with a fresh HdAccount and
504
- -- a fresh 'HdAddress' attached to it, so we have to pass these two extra
505
- -- piece of into to the update function. We do @not@ build these inside the
504
+ -- an optional 'HdAddress' attached to it, so we have to pass these two extra
505
+ -- pieces of info to the update function. We do @not@ build these inside the
506
506
-- update function because derivation requires an 'EncryptedSecretKey' and
507
507
-- definitely we do not want it to show up in our acid-state logs.
508
508
--
@@ -511,8 +511,8 @@ createHdWallet :: HdRoot
511
511
-- ^ The default HdAccountId to go with this HdRoot. This
512
512
-- function will take responsibility of creating the associated
513
513
-- 'HdAccount'.
514
- -> HdAddress
515
- -- ^ The default HdAddress to go with this HdRoot.
514
+ -> Maybe HdAddress
515
+ -- ^ An optional default HdAddress to go with this HdRoot.
516
516
-> Map HdAccountId (Utxo ,[AddrWithId ])
517
517
-> Update DB (Either HD. CreateHdRootError () )
518
518
createHdWallet newRoot defaultHdAccountId defaultHdAddress utxoByAccount =
@@ -532,14 +532,12 @@ createHdWallet newRoot defaultHdAccountId defaultHdAddress utxoByAccount =
532
532
insertDefault :: Map HdAccountId (Utxo , [AddrWithId ])
533
533
-> Map HdAccountId (Utxo , [AddrWithId ])
534
534
insertDefault m =
535
- let defaultAddr = ( defaultHdAddress ^. hdAddressId
536
- , defaultHdAddress ^. hdAddressAddress . fromDb
537
- )
535
+ let addrWithId = fmap toAddrWithId defaultHdAddress
538
536
in case Map. lookup defaultHdAccountId m of
539
537
Just (utxo, addrs) ->
540
- Map. insert defaultHdAccountId (utxo, defaultAddr : addrs) m
538
+ Map. insert defaultHdAccountId (utxo, maybe addrs ( : addrs) addrWithId ) m
541
539
Nothing ->
542
- Map. insert defaultHdAccountId (mempty , [defaultAddr] ) m
540
+ Map. insert defaultHdAccountId (mempty , maybeToList addrWithId ) m
543
541
544
542
-- | Create an HdWallet with HdRoot, without defaultHdAddress. Since we use this function
545
543
-- for external wallets only, we don't have defaultHdAddress here (because in the current
@@ -578,8 +576,8 @@ createHdExternalWallet newRoot defaultHdAccountId utxoByAccount =
578
576
-- starting from the 'HdAccountOutsideK' state.
579
577
--
580
578
-- INVARIANT: Creating a new wallet always come with a fresh HdAccount and
581
- -- a fresh 'HdAddress' attached to it, so we have to pass these two extra
582
- -- piece of into to the update function. We do @not@ build these inside the
579
+ -- an optional 'HdAddress' attached to it, so we have to pass these two extra
580
+ -- pieces of info to the update function. We do @not@ build these inside the
583
581
-- update function because derivation requires an 'EncryptedSecretKey' and
584
582
-- definitely we do not want it to show up in our acid-state logs.
585
583
--
@@ -588,8 +586,8 @@ restoreHdWallet :: HdRoot
588
586
-- ^ The default HdAccountId to go with this HdRoot. This
589
587
-- function will take responsibility of creating the associated
590
588
-- 'HdAccount'.
591
- -> HdAddress
592
- -- ^ The default HdAddress to go with this HdRoot
589
+ -> Maybe HdAddress
590
+ -- ^ Optional default HdAddress to go with this HdRoot
593
591
-> BlockContext
594
592
-- ^ The initial block context for restorations
595
593
-> Map HdAccountId (Utxo , Utxo , [AddrWithId ])
@@ -613,15 +611,17 @@ restoreHdWallet newRoot defaultHdAccountId defaultHdAddress ctx utxoByAccount =
613
611
insertDefault :: Map HdAccountId (Utxo , Utxo , [AddrWithId ])
614
612
-> Map HdAccountId (Utxo , Utxo , [AddrWithId ])
615
613
insertDefault m =
616
- let defaultAddr = ( defaultHdAddress ^. hdAddressId
617
- , defaultHdAddress ^. hdAddressAddress . fromDb
618
- )
614
+ let addrWithId = fmap toAddrWithId defaultHdAddress
619
615
in case Map. lookup defaultHdAccountId m of
620
616
Just (utxo, utxo', addrs) ->
621
- Map. insert defaultHdAccountId (utxo, utxo', defaultAddr : addrs) m
617
+ Map. insert defaultHdAccountId (utxo, utxo', maybe addrs ( : addrs) addrWithId ) m
622
618
Nothing ->
623
- Map. insert defaultHdAccountId (mempty , mempty , [defaultAddr] ) m
619
+ Map. insert defaultHdAccountId (mempty , mempty , maybeToList addrWithId ) m
624
620
621
+ toAddrWithId :: HdAddress -> AddrWithId
622
+ toAddrWithId addr = ( addr ^. hdAddressId
623
+ , addr ^. hdAddressAddress . fromDb
624
+ )
625
625
{- ------------------------------------------------------------------------------
626
626
Internal: support for updating accounts
627
627
-------------------------------------------------------------------------------}
0 commit comments