Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions wallet-new/src/Cardano/Wallet/Kernel/DB/HdWallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module Cardano.Wallet.Kernel.DB.HdWallet (
, hdAccountName
, hdAccountState
, hdAccountStateCurrent
, hdAccountStateCurrentCombined
, hdAccountStateUpToDate
, hdAccountRestorationState
-- *** Account state: up to date
Expand Down Expand Up @@ -475,6 +476,16 @@ hdAccountStateCurrent g = to $ \case
HdAccountStateIncomplete st ->
st ^. hdIncompleteCurrent . unCheckpoints . _Wrapped . SNE.head . g

hdAccountStateCurrentCombined :: (a -> a -> a)
-> (forall c. IsCheckpoint c => Getter c a)
-> Getter HdAccountState a
hdAccountStateCurrentCombined combine g = to $ \case
HdAccountStateUpToDate st ->
st ^. hdUpToDateCheckpoints . unCheckpoints . _Wrapped . SNE.head . g
HdAccountStateIncomplete st ->
combine (st ^. hdIncompleteCurrent . unCheckpoints . _Wrapped . SNE.head . g)
(st ^. hdIncompleteHistorical . unCheckpoints . _Wrapped . SNE.head . g)

{-------------------------------------------------------------------------------
Predicates and tests
-------------------------------------------------------------------------------}
Expand Down
15 changes: 14 additions & 1 deletion wallet-new/src/Cardano/Wallet/Kernel/DB/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import Universum
import Control.Lens (Getter, from, lazy, strict, to, _Wrapped)
import Control.Lens.TH (makeLenses)
import Data.Coerce (coerce)
import Data.Map as M
import qualified Data.SafeCopy as SC
import Formatting (bprint, build, (%))
import qualified Formatting.Buildable
Expand Down Expand Up @@ -187,10 +188,22 @@ initPartialCheckpoint ctx utxo = PartialCheckpoint {
Core.utxoBalance utxo
, _pcheckpointPending = Pending.empty
, _pcheckpointForeign = Pending.empty
, _pcheckpointBlockMeta = LocalBlockMeta emptyBlockMeta
, _pcheckpointBlockMeta = LocalBlockMeta $ BlockMeta {
_blockMetaSlotId = InDb mempty
, _blockMetaAddressMeta = utxoToAddressMeta utxo
}
, _pcheckpointContext = ctx
}

utxoToAddressMeta :: Core.Utxo -> Map (InDb Core.Address) AddressMeta
utxoToAddressMeta utxo =
M.fromList $ fmap (\u -> (InDb $ Core.toAddress u, usedMeta)) (M.elems utxo)
where
usedMeta = AddressMeta {
_addressMetaIsUsed = True
, _addressMetaIsChange = False
}

-- | A full check point with a non-Nothing context can be " downcast " to a
-- partial checkpoint by forgetting that we have complete block metadata.
-- The provided 'BlockContext' will only be used when the full checkpoint's
Expand Down
1 change: 1 addition & 0 deletions wallet-new/src/Cardano/Wallet/Kernel/Util/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Cardano.Wallet.Kernel.Util.Core (
, utxoRestrictToInputs
, utxoRemoveInputs
, utxoUnions
, toAddress
-- * Transactions
, paymentAmount
, toCoin
Expand Down
2 changes: 1 addition & 1 deletion wallet-new/src/Cardano/Wallet/WalletLayer/Kernel/Conv.hs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ toAddress acc hdAddress =
(V1 addressOwnership)
where
cardanoAddress = hdAddress ^. HD.hdAddressAddress . fromDb
addressMeta = acc ^. HD.hdAccountState . HD.hdAccountStateCurrent (cpAddressMeta cardanoAddress)
addressMeta = acc ^. HD.hdAccountState . HD.hdAccountStateCurrentCombined (<>) (cpAddressMeta cardanoAddress)
-- NOTE
-- In this particular case, the address had to be known by us. As a matter
-- of fact, to construct a 'WalletAddress', we have to be aware of pieces
Expand Down