Skip to content

Commit

Permalink
Implement rollBackward
Browse files Browse the repository at this point in the history
  • Loading branch information
HeinrichApfelmus committed Oct 2, 2024
1 parent 66e819c commit a1686a5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Pure.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE DuplicateRecordFields #-}
module Cardano.Wallet.Deposit.Pure
(
-- * Types
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a1686a5

Please sign in to comment.