Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 615970a

Browse files
authored
Merge pull request #3742 from input-output-hk/kderme/CBR-193
[CBR-466] fix address reported as unused during restoration
2 parents e411663 + 985cba8 commit 615970a

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

wallet-new/src/Cardano/Wallet/Kernel/DB/HdWallet.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module Cardano.Wallet.Kernel.DB.HdWallet (
5555
, hdAccountName
5656
, hdAccountState
5757
, hdAccountStateCurrent
58+
, hdAccountStateCurrentCombined
5859
, hdAccountStateUpToDate
5960
, hdAccountRestorationState
6061
-- *** Account state: up to date
@@ -477,6 +478,16 @@ hdAccountStateCurrent g = to $ \case
477478
HdAccountStateIncomplete st ->
478479
st ^. hdIncompleteCurrent . unCheckpoints . _Wrapped . SNE.head . g
479480

481+
hdAccountStateCurrentCombined :: (a -> a -> a)
482+
-> (forall c. IsCheckpoint c => Getter c a)
483+
-> Getter HdAccountState a
484+
hdAccountStateCurrentCombined combine g = to $ \case
485+
HdAccountStateUpToDate st ->
486+
st ^. hdUpToDateCheckpoints . unCheckpoints . _Wrapped . SNE.head . g
487+
HdAccountStateIncomplete st ->
488+
combine (st ^. hdIncompleteCurrent . unCheckpoints . _Wrapped . SNE.head . g)
489+
(st ^. hdIncompleteHistorical . unCheckpoints . _Wrapped . SNE.head . g)
490+
480491
{-------------------------------------------------------------------------------
481492
Predicates and tests
482493
-------------------------------------------------------------------------------}

wallet-new/src/Cardano/Wallet/Kernel/DB/Spec.hs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import Universum
5151
import Control.Lens (Getter, from, lazy, strict, to, _Wrapped)
5252
import Control.Lens.TH (makeLenses)
5353
import Data.Coerce (coerce)
54+
import Data.Map as M
5455
import qualified Data.SafeCopy as SC
5556
import Formatting (bprint, build, (%))
5657
import qualified Formatting.Buildable
@@ -187,10 +188,22 @@ initPartialCheckpoint ctx utxo = PartialCheckpoint {
187188
Core.utxoBalance utxo
188189
, _pcheckpointPending = Pending.empty
189190
, _pcheckpointForeign = Pending.empty
190-
, _pcheckpointBlockMeta = LocalBlockMeta emptyBlockMeta
191+
, _pcheckpointBlockMeta = LocalBlockMeta $ BlockMeta {
192+
_blockMetaSlotId = InDb mempty
193+
, _blockMetaAddressMeta = utxoToAddressMeta utxo
194+
}
191195
, _pcheckpointContext = ctx
192196
}
193197

198+
utxoToAddressMeta :: Core.Utxo -> Map (InDb Core.Address) AddressMeta
199+
utxoToAddressMeta utxo =
200+
M.fromList $ fmap (\u -> (InDb $ Core.toAddress u, usedMeta)) (M.elems utxo)
201+
where
202+
usedMeta = AddressMeta {
203+
_addressMetaIsUsed = True
204+
, _addressMetaIsChange = False
205+
}
206+
194207
-- | A full check point with a non-Nothing context can be " downcast " to a
195208
-- partial checkpoint by forgetting that we have complete block metadata.
196209
-- The provided 'BlockContext' will only be used when the full checkpoint's

wallet-new/src/Cardano/Wallet/Kernel/Util/Core.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module Cardano.Wallet.Kernel.Util.Core (
1919
, utxoRestrictToInputs
2020
, utxoRemoveInputs
2121
, utxoUnions
22+
, toAddress
2223
-- * Transactions
2324
, paymentAmount
2425
, toCoin

wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Conv.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ toAddress acc hdAddress =
200200
(V1 addressOwnership)
201201
where
202202
cardanoAddress = hdAddress ^. HD.hdAddressAddress . fromDb
203-
addressMeta = acc ^. HD.hdAccountState . HD.hdAccountStateCurrent (cpAddressMeta cardanoAddress)
203+
addressMeta = acc ^. HD.hdAccountState . HD.hdAccountStateCurrentCombined (<>) (cpAddressMeta cardanoAddress)
204204
-- NOTE
205205
-- In this particular case, the address had to be known by us. As a matter
206206
-- of fact, to construct a 'WalletAddress', we have to be aware of pieces

0 commit comments

Comments
 (0)