{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Cardano.Ledger.Alonzo
( AlonzoEra,
Self,
TxOut,
Value,
TxBody,
Script,
AuxiliaryData,
PParams,
PParamsDelta,
)
where
import Cardano.Ledger.Alonzo.Data (AuxiliaryData (..), Datum (..))
import Cardano.Ledger.Alonzo.Genesis
import Cardano.Ledger.Alonzo.Language (Language (..))
import Cardano.Ledger.Alonzo.PParams
( PParams,
PParams' (..),
PParamsUpdate,
updatePParams,
)
import Cardano.Ledger.Alonzo.PlutusScriptApi (getDatumAlonzo)
import qualified Cardano.Ledger.Alonzo.Rules.Bbody as Alonzo (AlonzoBBODY)
import qualified Cardano.Ledger.Alonzo.Rules.Ledger as Alonzo (AlonzoLEDGER)
import Cardano.Ledger.Alonzo.Rules.Utxo (utxoEntrySize)
import qualified Cardano.Ledger.Alonzo.Rules.Utxo as Alonzo (AlonzoUTXO)
import qualified Cardano.Ledger.Alonzo.Rules.Utxos as Alonzo (UTXOS)
import qualified Cardano.Ledger.Alonzo.Rules.Utxow as Alonzo (AlonzoUTXOW)
import Cardano.Ledger.Alonzo.Scripts (Script (..), isPlutusScript)
import Cardano.Ledger.Alonzo.Tx (ValidatedTx (..), alonzoInputHashes, minfee)
import Cardano.Ledger.Alonzo.TxBody (TxBody, TxOut (TxOut), getAlonzoTxOutEitherAddr)
import Cardano.Ledger.Alonzo.TxInfo (ExtendedUTxO (..), alonzoTxInfo, validScript)
import qualified Cardano.Ledger.Alonzo.TxSeq as Alonzo (TxSeq (..), hashTxSeq)
import Cardano.Ledger.Alonzo.TxWitness (TxWitness (..))
import Cardano.Ledger.AuxiliaryData (AuxiliaryDataHash (..), ValidateAuxiliaryData (..))
import Cardano.Ledger.BaseTypes (BlocksMade (..))
import Cardano.Ledger.Coin
import qualified Cardano.Ledger.Core as Core
import qualified Cardano.Ledger.Crypto as CC
import qualified Cardano.Ledger.Era as EraModule
import Cardano.Ledger.Keys (GenDelegs (GenDelegs))
import qualified Cardano.Ledger.Mary.Value as V (Value)
import Cardano.Ledger.PoolDistr (PoolDistr (..))
import Cardano.Ledger.Rules.ValidationMode (applySTSNonStatic)
import Cardano.Ledger.SafeHash (hashAnnotated)
import Cardano.Ledger.Serialization (mkSized)
import Cardano.Ledger.Shelley (nativeMultiSigTag)
import qualified Cardano.Ledger.Shelley.API as API
import Cardano.Ledger.Shelley.Constraints
( UsesPParams (..),
UsesTxOut (..),
UsesValue,
)
import Cardano.Ledger.Shelley.EpochBoundary
import Cardano.Ledger.Shelley.Genesis (genesisUTxO, sgGenDelegs, sgMaxLovelaceSupply, sgProtocolParams)
import Cardano.Ledger.Shelley.LedgerState
( AccountState (..),
DPState (..),
EpochState (..),
LedgerState (..),
NewEpochState (..),
smartUTxOState,
_genDelegs,
)
import Cardano.Ledger.Shelley.Metadata (validMetadatum)
import qualified Cardano.Ledger.Shelley.Rules.Epoch as Shelley
import qualified Cardano.Ledger.Shelley.Rules.Mir as Shelley
import qualified Cardano.Ledger.Shelley.Rules.Newpp as Shelley
import qualified Cardano.Ledger.Shelley.Rules.Rupd as Shelley
import qualified Cardano.Ledger.Shelley.Rules.Snap as Shelley
import qualified Cardano.Ledger.Shelley.Rules.Tick as Shelley
import qualified Cardano.Ledger.Shelley.Rules.Upec as Shelley
import qualified Cardano.Ledger.Shelley.Tx as Shelley
import Cardano.Ledger.Shelley.UTxO (balance)
import Cardano.Ledger.ShelleyMA.Rules.Utxo (consumed)
import Cardano.Ledger.ShelleyMA.Timelocks (validateTimelock)
import Cardano.Ledger.Val (Val (inject), coin, (<->))
import Control.Arrow (left)
import Control.Monad.Except (liftEither)
import Control.Monad.Reader (runReader)
import Control.State.Transition.Extended (TRC (TRC))
import Data.Default (def)
import Data.Foldable (toList)
import qualified Data.Map.Strict as Map
import Data.Maybe.Strict
import qualified Data.Set as Set
import GHC.Records (HasField (..))
data AlonzoEra c
instance CC.Crypto c => EraModule.Era (AlonzoEra c) where
type Crypto (AlonzoEra c) = c
getTxOutEitherAddr :: TxOut (AlonzoEra c)
-> Either
(Addr (Crypto (AlonzoEra c))) (CompactAddr (Crypto (AlonzoEra c)))
getTxOutEitherAddr = TxOut (AlonzoEra c)
-> Either
(Addr (Crypto (AlonzoEra c))) (CompactAddr (Crypto (AlonzoEra c)))
forall era.
HashAlgorithm (ADDRHASH (Crypto era)) =>
TxOut era -> Either (Addr (Crypto era)) (CompactAddr (Crypto era))
getAlonzoTxOutEitherAddr
getAllTxInputs :: TxBody (AlonzoEra c) -> Set (TxIn (Crypto (AlonzoEra c)))
getAllTxInputs TxBody (AlonzoEra c)
txb = Set (TxIn c)
spending Set (TxIn c) -> Set (TxIn c) -> Set (TxIn c)
forall a. Ord a => Set a -> Set a -> Set a
`Set.union` Set (TxIn c)
collateral
where
spending :: Set (TxIn c)
spending = TxBody (AlonzoEra c) -> Set (TxIn c)
forall k (x :: k) r a. HasField x r a => r -> a
getField @"inputs" TxBody (AlonzoEra c)
TxBody (AlonzoEra c)
txb
collateral :: Set (TxIn c)
collateral = TxBody (AlonzoEra c) -> Set (TxIn c)
forall k (x :: k) r a. HasField x r a => r -> a
getField @"collateral" TxBody (AlonzoEra c)
TxBody (AlonzoEra c)
txb
instance API.ShelleyEraCrypto c => API.ApplyTx (AlonzoEra c) where
reapplyTx :: Globals
-> LedgerEnv (AlonzoEra c)
-> MempoolState (AlonzoEra c)
-> Validated (Tx (AlonzoEra c))
-> m (MempoolState (AlonzoEra c))
reapplyTx Globals
globals LedgerEnv (AlonzoEra c)
env MempoolState (AlonzoEra c)
state Validated (Tx (AlonzoEra c))
vtx =
let res :: Either
[LedgerPredicateFailure (AlonzoEra c)] (MempoolState (AlonzoEra c))
res =
(Reader
Globals
(Either
[LedgerPredicateFailure (AlonzoEra c)]
(MempoolState (AlonzoEra c)))
-> Globals
-> Either
[LedgerPredicateFailure (AlonzoEra c)]
(MempoolState (AlonzoEra c)))
-> Globals
-> Reader
Globals
(Either
[LedgerPredicateFailure (AlonzoEra c)]
(MempoolState (AlonzoEra c)))
-> Either
[LedgerPredicateFailure (AlonzoEra c)] (MempoolState (AlonzoEra c))
forall a b c. (a -> b -> c) -> b -> a -> c
flip Reader
Globals
(Either
[LedgerPredicateFailure (AlonzoEra c)]
(MempoolState (AlonzoEra c)))
-> Globals
-> Either
[LedgerPredicateFailure (AlonzoEra c)] (MempoolState (AlonzoEra c))
forall r a. Reader r a -> r -> a
runReader Globals
globals
(Reader
Globals
(Either
[LedgerPredicateFailure (AlonzoEra c)]
(MempoolState (AlonzoEra c)))
-> Either
[LedgerPredicateFailure (AlonzoEra c)]
(MempoolState (AlonzoEra c)))
-> (TRC (AlonzoLEDGER (AlonzoEra c))
-> Reader
Globals
(Either
[LedgerPredicateFailure (AlonzoEra c)]
(MempoolState (AlonzoEra c))))
-> TRC (AlonzoLEDGER (AlonzoEra c))
-> Either
[LedgerPredicateFailure (AlonzoEra c)] (MempoolState (AlonzoEra c))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) (rtype :: RuleType).
(STS s, RuleTypeRep rtype, m ~ BaseM s) =>
RuleContext rtype s -> m (Either [PredicateFailure s] (State s))
forall (m :: * -> *) (rtype :: RuleType).
(STS (EraRule "LEDGER" (AlonzoEra c)), RuleTypeRep rtype,
m ~ BaseM (EraRule "LEDGER" (AlonzoEra c))) =>
RuleContext rtype (EraRule "LEDGER" (AlonzoEra c))
-> m (Either
[PredicateFailure (EraRule "LEDGER" (AlonzoEra c))]
(State (EraRule "LEDGER" (AlonzoEra c))))
applySTSNonStatic
@(Core.EraRule "LEDGER" (AlonzoEra c))
(TRC (AlonzoLEDGER (AlonzoEra c))
-> Either
[LedgerPredicateFailure (AlonzoEra c)]
(MempoolState (AlonzoEra c)))
-> TRC (AlonzoLEDGER (AlonzoEra c))
-> Either
[LedgerPredicateFailure (AlonzoEra c)] (MempoolState (AlonzoEra c))
forall a b. (a -> b) -> a -> b
$ (Environment (AlonzoLEDGER (AlonzoEra c)),
State (AlonzoLEDGER (AlonzoEra c)),
Signal (AlonzoLEDGER (AlonzoEra c)))
-> TRC (AlonzoLEDGER (AlonzoEra c))
forall sts. (Environment sts, State sts, Signal sts) -> TRC sts
TRC (LedgerEnv (AlonzoEra c)
Environment (AlonzoLEDGER (AlonzoEra c))
env, MempoolState (AlonzoEra c)
State (AlonzoLEDGER (AlonzoEra c))
state, Validated (ValidatedTx (AlonzoEra c)) -> ValidatedTx (AlonzoEra c)
forall tx. Validated tx -> tx
API.extractTx Validated (Tx (AlonzoEra c))
Validated (ValidatedTx (AlonzoEra c))
vtx)
in Either (ApplyTxError (AlonzoEra c)) (MempoolState (AlonzoEra c))
-> m (MempoolState (AlonzoEra c))
forall e (m :: * -> *) a. MonadError e m => Either e a -> m a
liftEither (Either (ApplyTxError (AlonzoEra c)) (MempoolState (AlonzoEra c))
-> m (MempoolState (AlonzoEra c)))
-> (Either
[LedgerPredicateFailure (AlonzoEra c)] (MempoolState (AlonzoEra c))
-> Either
(ApplyTxError (AlonzoEra c)) (MempoolState (AlonzoEra c)))
-> Either
[LedgerPredicateFailure (AlonzoEra c)] (MempoolState (AlonzoEra c))
-> m (MempoolState (AlonzoEra c))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([LedgerPredicateFailure (AlonzoEra c)]
-> ApplyTxError (AlonzoEra c))
-> Either
[LedgerPredicateFailure (AlonzoEra c)] (MempoolState (AlonzoEra c))
-> Either (ApplyTxError (AlonzoEra c)) (MempoolState (AlonzoEra c))
forall (a :: * -> * -> *) b c d.
ArrowChoice a =>
a b c -> a (Either b d) (Either c d)
left [LedgerPredicateFailure (AlonzoEra c)]
-> ApplyTxError (AlonzoEra c)
forall era.
[PredicateFailure (EraRule "LEDGER" era)] -> ApplyTxError era
API.ApplyTxError (Either
[LedgerPredicateFailure (AlonzoEra c)] (MempoolState (AlonzoEra c))
-> m (MempoolState (AlonzoEra c)))
-> Either
[LedgerPredicateFailure (AlonzoEra c)] (MempoolState (AlonzoEra c))
-> m (MempoolState (AlonzoEra c))
forall a b. (a -> b) -> a -> b
$ Either
[LedgerPredicateFailure (AlonzoEra c)] (MempoolState (AlonzoEra c))
res
instance API.ShelleyEraCrypto c => API.ApplyBlock (AlonzoEra c)
instance (CC.Crypto c) => Shelley.ValidateScript (AlonzoEra c) where
isNativeScript :: Script (AlonzoEra c) -> Bool
isNativeScript Script (AlonzoEra c)
x = Bool -> Bool
not (Script (AlonzoEra c) -> Bool
forall era. Script era -> Bool
isPlutusScript Script (AlonzoEra c)
Script (AlonzoEra c)
x)
scriptPrefixTag :: Script (AlonzoEra c) -> ByteString
scriptPrefixTag Script (AlonzoEra c)
script =
case Script (AlonzoEra c)
script of
(TimelockScript _) -> ByteString
nativeMultiSigTag
(PlutusScript PlutusV1 _) -> ByteString
"\x01"
(PlutusScript PlutusV2 _) -> ByteString
"\x02"
validateScript :: Script (AlonzoEra c) -> Tx (AlonzoEra c) -> Bool
validateScript (TimelockScript script) Tx (AlonzoEra c)
tx = Timelock (Crypto (AlonzoEra c)) -> Tx (AlonzoEra c) -> Bool
forall era.
(UsesTxBody era, HasField "vldt" (TxBody era) ValidityInterval,
HasField
"addrWits" (Tx era) (Set (WitVKey 'Witness (Crypto era)))) =>
Timelock (Crypto era) -> Tx era -> Bool
validateTimelock @(AlonzoEra c) Timelock (Crypto (AlonzoEra c))
script Tx (AlonzoEra c)
tx
validateScript (PlutusScript _ _) Tx (AlonzoEra c)
_tx = Bool
True
instance
( CC.Crypto c
) =>
API.CanStartFromGenesis (AlonzoEra c)
where
type AdditionalGenesisConfig (AlonzoEra c) = AlonzoGenesis
initialState :: ShelleyGenesis (AlonzoEra c)
-> AdditionalGenesisConfig (AlonzoEra c)
-> NewEpochState (AlonzoEra c)
initialState ShelleyGenesis (AlonzoEra c)
sg AdditionalGenesisConfig (AlonzoEra c)
ag =
EpochNo
-> BlocksMade (Crypto (AlonzoEra c))
-> BlocksMade (Crypto (AlonzoEra c))
-> EpochState (AlonzoEra c)
-> StrictMaybe (PulsingRewUpdate (Crypto (AlonzoEra c)))
-> PoolDistr (Crypto (AlonzoEra c))
-> StashedAVVMAddresses (AlonzoEra c)
-> NewEpochState (AlonzoEra c)
forall era.
EpochNo
-> BlocksMade (Crypto era)
-> BlocksMade (Crypto era)
-> EpochState era
-> StrictMaybe (PulsingRewUpdate (Crypto era))
-> PoolDistr (Crypto era)
-> StashedAVVMAddresses era
-> NewEpochState era
NewEpochState
EpochNo
initialEpochNo
(Map (KeyHash 'StakePool c) Natural -> BlocksMade c
forall crypto.
Map (KeyHash 'StakePool crypto) Natural -> BlocksMade crypto
BlocksMade Map (KeyHash 'StakePool c) Natural
forall k a. Map k a
Map.empty)
(Map (KeyHash 'StakePool c) Natural -> BlocksMade c
forall crypto.
Map (KeyHash 'StakePool crypto) Natural -> BlocksMade crypto
BlocksMade Map (KeyHash 'StakePool c) Natural
forall k a. Map k a
Map.empty)
( AccountState
-> SnapShots (Crypto (AlonzoEra c))
-> LedgerState (AlonzoEra c)
-> PParams (AlonzoEra c)
-> PParams (AlonzoEra c)
-> NonMyopic (Crypto (AlonzoEra c))
-> EpochState (AlonzoEra c)
forall era.
AccountState
-> SnapShots (Crypto era)
-> LedgerState era
-> PParams era
-> PParams era
-> NonMyopic (Crypto era)
-> EpochState era
EpochState
(Coin -> Coin -> AccountState
AccountState (Integer -> Coin
Coin Integer
0) Coin
reserves)
SnapShots (Crypto (AlonzoEra c))
forall crypto. SnapShots crypto
emptySnapShots
( UTxOState (AlonzoEra c)
-> DPState (Crypto (AlonzoEra c)) -> LedgerState (AlonzoEra c)
forall era.
UTxOState era -> DPState (Crypto era) -> LedgerState era
LedgerState
( UTxO (AlonzoEra c)
-> Coin
-> Coin
-> State (EraRule "PPUP" (AlonzoEra c))
-> UTxOState (AlonzoEra c)
forall era.
Era era =>
UTxO era
-> Coin -> Coin -> State (EraRule "PPUP" era) -> UTxOState era
smartUTxOState
UTxO (AlonzoEra c)
initialUtxo
(Integer -> Coin
Coin Integer
0)
(Integer -> Coin
Coin Integer
0)
State (EraRule "PPUP" (AlonzoEra c))
forall a. Default a => a
def
)
(DState c -> PState c -> DPState c
forall crypto. DState crypto -> PState crypto -> DPState crypto
DPState (DState c
forall a. Default a => a
def {_genDelegs :: GenDelegs c
_genDelegs = Map (KeyHash 'Genesis c) (GenDelegPair c) -> GenDelegs c
forall crypto.
Map (KeyHash 'Genesis crypto) (GenDelegPair crypto)
-> GenDelegs crypto
GenDelegs Map (KeyHash 'Genesis c) (GenDelegPair c)
Map
(KeyHash 'Genesis (Crypto (AlonzoEra c)))
(GenDelegPair (Crypto (AlonzoEra c)))
genDelegs}) PState c
forall a. Default a => a
def)
)
(PParams' Identity (AlonzoEra c)
-> AlonzoGenesis -> PParams' Identity (AlonzoEra c)
forall era1 era2.
PParams' Identity era1 -> AlonzoGenesis -> PParams' Identity era2
extendPPWithGenesis PParams' Identity (AlonzoEra c)
pp AdditionalGenesisConfig (AlonzoEra c)
AlonzoGenesis
ag)
(PParams' Identity (AlonzoEra c)
-> AlonzoGenesis -> PParams' Identity (AlonzoEra c)
forall era1 era2.
PParams' Identity era1 -> AlonzoGenesis -> PParams' Identity era2
extendPPWithGenesis PParams' Identity (AlonzoEra c)
pp AdditionalGenesisConfig (AlonzoEra c)
AlonzoGenesis
ag)
NonMyopic (Crypto (AlonzoEra c))
forall a. Default a => a
def
)
StrictMaybe (PulsingRewUpdate (Crypto (AlonzoEra c)))
forall a. StrictMaybe a
SNothing
(Map (KeyHash 'StakePool c) (IndividualPoolStake c) -> PoolDistr c
forall crypto.
Map (KeyHash 'StakePool crypto) (IndividualPoolStake crypto)
-> PoolDistr crypto
PoolDistr Map (KeyHash 'StakePool c) (IndividualPoolStake c)
forall k a. Map k a
Map.empty)
()
where
initialEpochNo :: EpochNo
initialEpochNo = EpochNo
0
initialUtxo :: UTxO (AlonzoEra c)
initialUtxo = ShelleyGenesis (AlonzoEra c) -> UTxO (AlonzoEra c)
forall era.
(Era era, UsesTxOut era) =>
ShelleyGenesis era -> UTxO era
genesisUTxO ShelleyGenesis (AlonzoEra c)
sg
reserves :: Coin
reserves =
Value c -> Coin
forall t. Val t => t -> Coin
coin (Value c -> Coin) -> Value c -> Coin
forall a b. (a -> b) -> a -> b
$
Coin -> Value c
forall t. Val t => Coin -> t
inject (Word64 -> Coin
word64ToCoin (ShelleyGenesis (AlonzoEra c) -> Word64
forall era. ShelleyGenesis era -> Word64
sgMaxLovelaceSupply ShelleyGenesis (AlonzoEra c)
sg))
Value c -> Value c -> Value c
forall t. Val t => t -> t -> t
<-> UTxO (AlonzoEra c) -> Value (AlonzoEra c)
forall era. Era era => UTxO era -> Value era
balance UTxO (AlonzoEra c)
initialUtxo
genDelegs :: Map
(KeyHash 'Genesis (Crypto (AlonzoEra c)))
(GenDelegPair (Crypto (AlonzoEra c)))
genDelegs = ShelleyGenesis (AlonzoEra c)
-> Map
(KeyHash 'Genesis (Crypto (AlonzoEra c)))
(GenDelegPair (Crypto (AlonzoEra c)))
forall era.
ShelleyGenesis era
-> Map (KeyHash 'Genesis (Crypto era)) (GenDelegPair (Crypto era))
sgGenDelegs ShelleyGenesis (AlonzoEra c)
sg
pp :: PParams' Identity (AlonzoEra c)
pp = ShelleyGenesis (AlonzoEra c) -> PParams' Identity (AlonzoEra c)
forall era. ShelleyGenesis era -> PParams era
sgProtocolParams ShelleyGenesis (AlonzoEra c)
sg
instance CC.Crypto c => UsesTxOut (AlonzoEra c) where
makeTxOut :: Proxy (AlonzoEra c)
-> Addr (Crypto (AlonzoEra c))
-> Value (AlonzoEra c)
-> TxOut (AlonzoEra c)
makeTxOut Proxy (AlonzoEra c)
_proxy Addr (Crypto (AlonzoEra c))
addr Value (AlonzoEra c)
val = Addr (Crypto (AlonzoEra c))
-> Value (AlonzoEra c)
-> StrictMaybe (DataHash (Crypto (AlonzoEra c)))
-> TxOut (AlonzoEra c)
forall era.
(Era era, Compactible (Value era), Val (Value era),
HasCallStack) =>
Addr (Crypto era)
-> Value era -> StrictMaybe (DataHash (Crypto era)) -> TxOut era
TxOut Addr (Crypto (AlonzoEra c))
addr Value (AlonzoEra c)
val StrictMaybe (DataHash (Crypto (AlonzoEra c)))
forall a. StrictMaybe a
SNothing
instance CC.Crypto c => API.CLI (AlonzoEra c) where
evaluateMinFee :: PParams (AlonzoEra c) -> Tx (AlonzoEra c) -> Coin
evaluateMinFee = PParams (AlonzoEra c) -> Tx (AlonzoEra c) -> Coin
forall era.
(HasField "_minfeeA" (PParams era) Natural,
HasField "_minfeeB" (PParams era) Natural,
HasField "_prices" (PParams era) Prices,
HasField "wits" (Tx era) (Witnesses era),
HasField "txrdmrs" (Witnesses era) (Redeemers era),
HasField "txsize" (Tx era) Integer) =>
PParams era -> Tx era -> Coin
minfee
evaluateConsumed :: PParams (AlonzoEra c)
-> UTxO (AlonzoEra c)
-> TxBody (AlonzoEra c)
-> Value (AlonzoEra c)
evaluateConsumed = PParams (AlonzoEra c)
-> UTxO (AlonzoEra c)
-> TxBody (AlonzoEra c)
-> Value (AlonzoEra c)
forall era.
(Era era,
HasField "certs" (TxBody era) (StrictSeq (DCert (Crypto era))),
HasField "inputs" (TxBody era) (Set (TxIn (Crypto era))),
HasField "mint" (TxBody era) (Value era),
HasField "wdrls" (TxBody era) (Wdrl (Crypto era)),
HasField "_keyDeposit" (PParams era) Coin) =>
PParams era -> UTxO era -> TxBody era -> Value era
consumed
addKeyWitnesses :: Tx (AlonzoEra c)
-> Set (WitVKey 'Witness (Crypto (AlonzoEra c)))
-> Tx (AlonzoEra c)
addKeyWitnesses (ValidatedTx b ws aux iv) Set (WitVKey 'Witness (Crypto (AlonzoEra c)))
newWits = TxBody (AlonzoEra c)
-> TxWitness (AlonzoEra c)
-> IsValid
-> StrictMaybe (AuxiliaryData (AlonzoEra c))
-> ValidatedTx (AlonzoEra c)
forall era.
TxBody era
-> TxWitness era
-> IsValid
-> StrictMaybe (AuxiliaryData era)
-> ValidatedTx era
ValidatedTx TxBody (AlonzoEra c)
b TxWitness (AlonzoEra c)
ws' IsValid
aux StrictMaybe (AuxiliaryData (AlonzoEra c))
iv
where
ws' :: TxWitness (AlonzoEra c)
ws' = TxWitness (AlonzoEra c)
ws {txwitsVKey :: Set (WitVKey 'Witness (Crypto (AlonzoEra c)))
txwitsVKey = Set (WitVKey 'Witness c)
-> Set (WitVKey 'Witness c) -> Set (WitVKey 'Witness c)
forall a. Ord a => Set a -> Set a -> Set a
Set.union Set (WitVKey 'Witness c)
Set (WitVKey 'Witness (Crypto (AlonzoEra c)))
newWits (TxWitness (AlonzoEra c)
-> (Era (AlonzoEra c),
Script (AlonzoEra c) ~ Script (AlonzoEra c)) =>
Set (WitVKey 'Witness (Crypto (AlonzoEra c)))
forall era.
TxWitness era
-> (Era era, Script era ~ Script era) =>
Set (WitVKey 'Witness (Crypto era))
txwitsVKey TxWitness (AlonzoEra c)
ws)}
evaluateMinLovelaceOutput :: PParams (AlonzoEra c) -> TxOut (AlonzoEra c) -> Coin
evaluateMinLovelaceOutput PParams (AlonzoEra c)
pp TxOut (AlonzoEra c)
out =
Integer -> Coin
Coin (Integer -> Coin) -> Integer -> Coin
forall a b. (a -> b) -> a -> b
$ TxOut (AlonzoEra c) -> Integer
forall era c.
(Era era,
HasField "datahash" (TxOut era) (StrictMaybe (DataHash c))) =>
TxOut era -> Integer
utxoEntrySize TxOut (AlonzoEra c)
out Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Coin -> Integer
unCoin (PParams' Identity (AlonzoEra c) -> HKD Identity Coin
forall (f :: * -> *) era. PParams' f era -> HKD f Coin
_coinsPerUTxOWord PParams (AlonzoEra c)
PParams' Identity (AlonzoEra c)
pp)
type instance Core.Tx (AlonzoEra c) = ValidatedTx (AlonzoEra c)
type instance Core.TxOut (AlonzoEra c) = TxOut (AlonzoEra c)
type instance Core.TxBody (AlonzoEra c) = TxBody (AlonzoEra c)
type instance Core.Value (AlonzoEra c) = V.Value c
type instance Core.Script (AlonzoEra c) = Script (AlonzoEra c)
type instance Core.AuxiliaryData (AlonzoEra c) = AuxiliaryData (AlonzoEra c)
type instance Core.PParams (AlonzoEra c) = PParams (AlonzoEra c)
type instance Core.Witnesses (AlonzoEra c) = TxWitness (AlonzoEra c)
type instance Core.PParamsDelta (AlonzoEra c) = PParamsUpdate (AlonzoEra c)
instance CC.Crypto c => UsesValue (AlonzoEra c)
instance (CC.Crypto c) => UsesPParams (AlonzoEra c) where
mergePPUpdates :: proxy (AlonzoEra c)
-> PParams (AlonzoEra c)
-> PParamsDelta (AlonzoEra c)
-> PParams (AlonzoEra c)
mergePPUpdates proxy (AlonzoEra c)
_ = PParams (AlonzoEra c)
-> PParamsDelta (AlonzoEra c) -> PParams (AlonzoEra c)
forall era. PParams era -> PParamsUpdate era -> PParams era
updatePParams
instance CC.Crypto c => ValidateAuxiliaryData (AlonzoEra c) c where
hashAuxiliaryData :: AuxiliaryData (AlonzoEra c) -> AuxiliaryDataHash c
hashAuxiliaryData AuxiliaryData (AlonzoEra c)
x = SafeHash c EraIndependentAuxiliaryData -> AuxiliaryDataHash c
forall crypto.
SafeHash crypto EraIndependentAuxiliaryData
-> AuxiliaryDataHash crypto
AuxiliaryDataHash (AuxiliaryData (AlonzoEra c)
-> SafeHash c EraIndependentAuxiliaryData
forall c i x.
(HasAlgorithm c, HashAnnotated x i c) =>
x -> SafeHash c i
hashAnnotated AuxiliaryData (AlonzoEra c)
AuxiliaryData (AlonzoEra c)
x)
validateAuxiliaryData :: ProtVer -> AuxiliaryData (AlonzoEra c) -> Bool
validateAuxiliaryData ProtVer
pv (AuxiliaryData metadata scrips) =
(Metadatum -> Bool) -> Map Word64 Metadatum -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Metadatum -> Bool
validMetadatum Map Word64 Metadatum
metadata
Bool -> Bool -> Bool
&& (Script (AlonzoEra c) -> Bool)
-> StrictSeq (Script (AlonzoEra c)) -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (ProtVer -> Script (AlonzoEra c) -> Bool
forall era. ProtVer -> Script era -> Bool
validScript ProtVer
pv) StrictSeq (Script (AlonzoEra c))
StrictSeq (Script (AlonzoEra c))
scrips
instance CC.Crypto c => EraModule.SupportsSegWit (AlonzoEra c) where
type TxSeq (AlonzoEra c) = Alonzo.TxSeq (AlonzoEra c)
fromTxSeq :: TxSeq (AlonzoEra c) -> StrictSeq (Tx (AlonzoEra c))
fromTxSeq = TxSeq (AlonzoEra c) -> StrictSeq (Tx (AlonzoEra c))
forall era. TxSeq era -> StrictSeq (ValidatedTx era)
Alonzo.txSeqTxns
toTxSeq :: StrictSeq (Tx (AlonzoEra c)) -> TxSeq (AlonzoEra c)
toTxSeq = StrictSeq (Tx (AlonzoEra c)) -> TxSeq (AlonzoEra c)
forall era.
(Era era, SafeToHash (TxWitness era)) =>
StrictSeq (ValidatedTx era) -> TxSeq era
Alonzo.TxSeq
hashTxSeq :: TxSeq (AlonzoEra c)
-> Hash (HASH (Crypto (AlonzoEra c))) EraIndependentBlockBody
hashTxSeq = TxSeq (AlonzoEra c)
-> Hash (HASH (Crypto (AlonzoEra c))) EraIndependentBlockBody
forall era.
Era era =>
TxSeq era -> Hash (Crypto era) EraIndependentBlockBody
Alonzo.hashTxSeq
numSegComponents :: Word64
numSegComponents = Word64
4
instance API.ShelleyEraCrypto c => API.ShelleyBasedEra (AlonzoEra c)
instance CC.Crypto c => ExtendedUTxO (AlonzoEra c) where
txInfo :: PParams (AlonzoEra c)
-> Language
-> EpochInfo (Either Text)
-> SystemStart
-> UTxO (AlonzoEra c)
-> Tx (AlonzoEra c)
-> Either (TranslationError (Crypto (AlonzoEra c))) VersionedTxInfo
txInfo = PParams (AlonzoEra c)
-> Language
-> EpochInfo (Either Text)
-> SystemStart
-> UTxO (AlonzoEra c)
-> Tx (AlonzoEra c)
-> Either (TranslationError (Crypto (AlonzoEra c))) VersionedTxInfo
forall era.
(Era era, Value era ~ Value (Crypto era),
HasField "wits" (Tx era) (TxWitness era),
HasField
"datahash"
(TxOut era)
(StrictMaybe (SafeHash (Crypto era) EraIndependentData)),
HasField "_protocolVersion" (PParams era) ProtVer,
HasField "inputs" (TxBody era) (Set (TxIn (Crypto era))),
HasField
"reqSignerHashes"
(TxBody era)
(Set (KeyHash 'Witness (Crypto era))),
HasField "certs" (TxBody era) (StrictSeq (DCert (Crypto era))),
HasField "wdrls" (TxBody era) (Wdrl (Crypto era)),
HasField "mint" (TxBody era) (Value (Crypto era)),
HasField "vldt" (TxBody era) ValidityInterval) =>
PParams era
-> Language
-> EpochInfo (Either Text)
-> SystemStart
-> UTxO era
-> Tx era
-> Either (TranslationError (Crypto era)) VersionedTxInfo
alonzoTxInfo
inputDataHashes :: Map (ScriptHash (Crypto (AlonzoEra c))) (Script (AlonzoEra c))
-> ValidatedTx (AlonzoEra c)
-> UTxO (AlonzoEra c)
-> (Set (DataHash (Crypto (AlonzoEra c))),
Set (TxIn (Crypto (AlonzoEra c))))
inputDataHashes = Map (ScriptHash (Crypto (AlonzoEra c))) (Script (AlonzoEra c))
-> ValidatedTx (AlonzoEra c)
-> UTxO (AlonzoEra c)
-> (Set (DataHash (Crypto (AlonzoEra c))),
Set (TxIn (Crypto (AlonzoEra c))))
forall era.
(HasField "inputs" (TxBody era) (Set (TxIn (Crypto era))),
ValidateScript era, TxOut era ~ TxOut era) =>
Map (ScriptHash (Crypto era)) (Script era)
-> ValidatedTx era
-> UTxO era
-> (Set (DataHash (Crypto era)), Set (TxIn (Crypto era)))
alonzoInputHashes
txscripts :: UTxO (AlonzoEra c)
-> Tx (AlonzoEra c)
-> Map (ScriptHash (Crypto (AlonzoEra c))) (Script (AlonzoEra c))
txscripts UTxO (AlonzoEra c)
_ = TxWitness (AlonzoEra c)
-> Map (ScriptHash c) (Script (AlonzoEra c))
forall era.
TxWitness era -> Map (ScriptHash (Crypto era)) (Script era)
txscripts' (TxWitness (AlonzoEra c)
-> Map (ScriptHash c) (Script (AlonzoEra c)))
-> (ValidatedTx (AlonzoEra c) -> TxWitness (AlonzoEra c))
-> ValidatedTx (AlonzoEra c)
-> Map (ScriptHash c) (Script (AlonzoEra c))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (x :: k) r a. HasField x r a => r -> a
forall r a. HasField "wits" r a => r -> a
getField @"wits"
getAllowedSupplimentalDataHashes :: TxBody (AlonzoEra c)
-> UTxO (AlonzoEra c) -> Set (DataHash (Crypto (AlonzoEra c)))
getAllowedSupplimentalDataHashes TxBody (AlonzoEra c)
txbody UTxO (AlonzoEra c)
_ =
[DataHash c] -> Set (DataHash c)
forall a. Ord a => [a] -> Set a
Set.fromList
[ DataHash c
dh
| TxOut (AlonzoEra c)
out <- TxBody (AlonzoEra c) -> [TxOut (AlonzoEra c)]
forall era. ExtendedUTxO era => TxBody era -> [TxOut era]
allOuts TxBody (AlonzoEra c)
txbody,
SJust DataHash c
dh <- [TxOut (AlonzoEra c) -> StrictMaybe (DataHash c)
forall k (x :: k) r a. HasField x r a => r -> a
getField @"datahash" TxOut (AlonzoEra c)
out]
]
getDatum :: Tx (AlonzoEra c)
-> UTxO (AlonzoEra c)
-> ScriptPurpose (Crypto (AlonzoEra c))
-> Maybe (Data (AlonzoEra c))
getDatum = Tx (AlonzoEra c)
-> UTxO (AlonzoEra c)
-> ScriptPurpose (Crypto (AlonzoEra c))
-> Maybe (Data (AlonzoEra c))
forall era tx.
(HasField
"datahash" (TxOut era) (StrictMaybe (DataHash (Crypto era))),
HasField "wits" tx (TxWitness era)) =>
tx -> UTxO era -> ScriptPurpose (Crypto era) -> Maybe (Data era)
getDatumAlonzo
getTxOutDatum :: TxOut (AlonzoEra c) -> Datum (AlonzoEra c)
getTxOutDatum TxOut (AlonzoEra c)
txOut =
case TxOut (AlonzoEra c) -> StrictMaybe (DataHash c)
forall k (x :: k) r a. HasField x r a => r -> a
getField @"datahash" TxOut (AlonzoEra c)
TxOut (AlonzoEra c)
txOut of
StrictMaybe (DataHash c)
SNothing -> Datum (AlonzoEra c)
forall era. Datum era
NoDatum
SJust DataHash c
dh -> DataHash (Crypto (AlonzoEra c)) -> Datum (AlonzoEra c)
forall era. DataHash (Crypto era) -> Datum era
DatumHash DataHash c
DataHash (Crypto (AlonzoEra c))
dh
allOuts :: TxBody (AlonzoEra c) -> [TxOut (AlonzoEra c)]
allOuts TxBody (AlonzoEra c)
txbody = StrictSeq (TxOut (AlonzoEra c)) -> [TxOut (AlonzoEra c)]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (StrictSeq (TxOut (AlonzoEra c)) -> [TxOut (AlonzoEra c)])
-> StrictSeq (TxOut (AlonzoEra c)) -> [TxOut (AlonzoEra c)]
forall a b. (a -> b) -> a -> b
$ TxBody (AlonzoEra c) -> StrictSeq (TxOut (AlonzoEra c))
forall k (x :: k) r a. HasField x r a => r -> a
getField @"outputs" TxBody (AlonzoEra c)
TxBody (AlonzoEra c)
txbody
allSizedOuts :: TxBody (AlonzoEra c) -> [Sized (TxOut (AlonzoEra c))]
allSizedOuts = (TxOut (AlonzoEra c) -> Sized (TxOut (AlonzoEra c)))
-> [TxOut (AlonzoEra c)] -> [Sized (TxOut (AlonzoEra c))]
forall a b. (a -> b) -> [a] -> [b]
map TxOut (AlonzoEra c) -> Sized (TxOut (AlonzoEra c))
forall a. ToCBOR a => a -> Sized a
mkSized ([TxOut (AlonzoEra c)] -> [Sized (TxOut (AlonzoEra c))])
-> (TxBody (AlonzoEra c) -> [TxOut (AlonzoEra c)])
-> TxBody (AlonzoEra c)
-> [Sized (TxOut (AlonzoEra c))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxBody (AlonzoEra c) -> [TxOut (AlonzoEra c)]
forall era. ExtendedUTxO era => TxBody era -> [TxOut era]
allOuts
type instance Core.EraRule "UTXOS" (AlonzoEra c) = Alonzo.UTXOS (AlonzoEra c)
type instance Core.EraRule "UTXO" (AlonzoEra c) = Alonzo.AlonzoUTXO (AlonzoEra c)
type instance Core.EraRule "UTXOW" (AlonzoEra c) = Alonzo.AlonzoUTXOW (AlonzoEra c)
type instance Core.EraRule "LEDGER" (AlonzoEra c) = Alonzo.AlonzoLEDGER (AlonzoEra c)
type instance Core.EraRule "BBODY" (AlonzoEra c) = Alonzo.AlonzoBBODY (AlonzoEra c)
type instance Core.EraRule "DELEG" (AlonzoEra c) = API.DELEG (AlonzoEra c)
type instance Core.EraRule "DELEGS" (AlonzoEra c) = API.DELEGS (AlonzoEra c)
type instance Core.EraRule "DELPL" (AlonzoEra c) = API.DELPL (AlonzoEra c)
type instance Core.EraRule "EPOCH" (AlonzoEra c) = Shelley.EPOCH (AlonzoEra c)
type instance Core.EraRule "LEDGERS" (AlonzoEra c) = API.LEDGERS (AlonzoEra c)
type instance Core.EraRule "MIR" (AlonzoEra c) = Shelley.MIR (AlonzoEra c)
type instance Core.EraRule "NEWEPOCH" (AlonzoEra c) = API.NEWEPOCH (AlonzoEra c)
type instance Core.EraRule "NEWPP" (AlonzoEra c) = Shelley.NEWPP (AlonzoEra c)
type instance Core.EraRule "POOL" (AlonzoEra c) = API.POOL (AlonzoEra c)
type instance Core.EraRule "POOLREAP" (AlonzoEra c) = API.POOLREAP (AlonzoEra c)
type instance Core.EraRule "PPUP" (AlonzoEra c) = API.PPUP (AlonzoEra c)
type instance Core.EraRule "RUPD" (AlonzoEra c) = Shelley.RUPD (AlonzoEra c)
type instance Core.EraRule "SNAP" (AlonzoEra c) = Shelley.SNAP (AlonzoEra c)
type instance Core.EraRule "TICK" (AlonzoEra c) = Shelley.TICK (AlonzoEra c)
type instance Core.EraRule "TICKF" (AlonzoEra c) = Shelley.TICKF (AlonzoEra c)
type instance Core.EraRule "UPEC" (AlonzoEra c) = Shelley.UPEC (AlonzoEra c)
type Self c = AlonzoEra c
type Value era = V.Value (EraModule.Crypto era)
type PParamsDelta era = PParamsUpdate era