Skip to content

Commit

Permalink
add sum of the deposits in a transaction event
Browse files Browse the repository at this point in the history
  • Loading branch information
goolord committed Jul 8, 2021
1 parent 6cd0c2f commit f2c4ac6
Showing 1 changed file with 15 additions and 4 deletions.
Expand Up @@ -18,6 +18,7 @@ module Shelley.Spec.Ledger.STS.Utxo
( UTXO,
UtxoEnv (..),
UtxoPredicateFailure (..),
UtxoEvent (..),
PredicateFailure,
)
where
Expand Down Expand Up @@ -75,7 +76,7 @@ import Control.State.Transition
trans,
wrapEvent,
wrapFailed,
(?!),
(?!), tellEvent
)
import Data.Foldable (foldl', toList)
import Data.Map.Strict (Map)
Expand Down Expand Up @@ -116,6 +117,7 @@ import Shelley.Spec.Ledger.UTxO
txouts,
txup,
)
import Data.Void (Void)

data UTXO era

Expand All @@ -128,6 +130,10 @@ data UtxoEnv era

deriving instance Show (Core.PParams era) => Show (UtxoEnv era)

data UtxoEvent era
= TotalDeposits Coin
| UpdateEvent (Event (Core.EraRule "PPUP" era))

data UtxoPredicateFailure era
= BadInputsUTxO
!(Set (TxIn (Crypto era))) -- The bad transaction inputs
Expand Down Expand Up @@ -296,6 +302,7 @@ instance
type Environment (UTXO era) = UtxoEnv era
type BaseM (UTXO era) = ShelleyBase
type PredicateFailure (UTXO era) = UtxoPredicateFailure era
type Event (UTXO era) = UtxoEvent era

transitionRules = [utxoInductive]

Expand Down Expand Up @@ -337,6 +344,7 @@ utxoInductive ::
State (utxo era) ~ UTxOState era,
Signal (utxo era) ~ Tx era,
PredicateFailure (utxo era) ~ UtxoPredicateFailure era,
Event (utxo era) ~ UtxoEvent era,
Environment (Core.EraRule "PPUP" era) ~ PPUPEnv era,
State (Core.EraRule "PPUP" era) ~ PPUPState era,
Signal (Core.EraRule "PPUP" era) ~ Maybe (Update era),
Expand Down Expand Up @@ -421,7 +429,9 @@ utxoInductive = do

let refunded = keyRefunds pp txb
let txCerts = toList $ getField @"certs" txb
let depositChange = totalDeposits pp (`Map.notMember` stakepools) txCerts <-> refunded
let totalDeposits' = totalDeposits pp (`Map.notMember` stakepools) txCerts
tellEvent $ TotalDeposits totalDeposits'
let depositChange = totalDeposits' <-> refunded

pure
UTxOState
Expand All @@ -434,9 +444,10 @@ utxoInductive = do
instance
( Era era,
STS (PPUP era),
PredicateFailure (Core.EraRule "PPUP" era) ~ PpupPredicateFailure era
PredicateFailure (Core.EraRule "PPUP" era) ~ PpupPredicateFailure era,
Event (Core.EraRule "PPUP" era) ~ Void
) =>
Embed (PPUP era) (UTXO era)
where
wrapFailed = UpdateFailure
wrapEvent = id
wrapEvent = UpdateEvent

0 comments on commit f2c4ac6

Please sign in to comment.