From a1686a510ddbf315d2433be8382a14731bb0bd8a Mon Sep 17 00:00:00 2001 From: Heinrich Apfelmus Date: Fri, 30 Aug 2024 16:10:10 +0200 Subject: [PATCH] Implement `rollBackward` --- .../src/Cardano/Wallet/Deposit/Pure.hs | 26 ++++++++++++++++++- .../Wallet/Deposit/Pure/Submissions.hs | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Pure.hs b/lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Pure.hs index 1aefe710aca..03562dc2123 100644 --- a/lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Pure.hs +++ b/lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Pure.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE DuplicateRecordFields #-} module Cardano.Wallet.Deposit.Pure ( -- * Types @@ -86,6 +87,7 @@ import Data.Word.Odd import qualified Cardano.Wallet.Deposit.Pure.Address as Address import qualified Cardano.Wallet.Deposit.Pure.Balance as Balance +import qualified Cardano.Wallet.Deposit.Pure.RollbackWindow as Rollback import qualified Cardano.Wallet.Deposit.Pure.Submissions as Sbm import qualified Cardano.Wallet.Deposit.Pure.UTxO as UTxO import qualified Cardano.Wallet.Deposit.Pure.UTxO.UTxOHistory as UTxOHistory @@ -203,7 +205,29 @@ rollBackward :: Read.ChainPoint -> WalletState -> (WalletState, Read.ChainPoint) -rollBackward point w = (w, point) -- FIXME: This is a mock implementation +rollBackward targetPoint w = + ( w + { utxoHistory = + UTxOHistory.rollback actualSlot (utxoHistory w) + , submissions = + Delta.apply (Sbm.rollBackward actualSlot) (submissions w) + } + , actualPoint + ) + where + h = utxoHistory w + + targetSlot = Read.slotFromChainPoint targetPoint + actualSlot = Read.slotFromChainPoint actualPoint + + -- NOTE: We don't keep enough information about + -- the block hashes to roll back to + -- any other point than the target point (or genesis). + actualPoint = + if (targetSlot `Rollback.member` UTxOHistory.getRollbackWindow h) + -- FIXME: Add test for rollback window of `submissions` + then targetPoint + else Read.GenesisPoint availableBalance :: WalletState -> Read.Value availableBalance = UTxO.balance . availableUTxO diff --git a/lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Pure/Submissions.hs b/lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Pure/Submissions.hs index 17e94c62d1e..ab92943ab82 100644 --- a/lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Pure/Submissions.hs +++ b/lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Pure/Submissions.hs @@ -69,5 +69,5 @@ rollForward block = [ Sbm.RollForward tip txs ] txids = undefined block txs = map (tip,) txids -rollBackward :: Read.SlotNo -> DeltaTxSubmissions +rollBackward :: Read.Slot -> DeltaTxSubmissions rollBackward = undefined