Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- getSpendingTxIn :: ScriptPurpose crypto -> Maybe ( TxIn crypto)
- getDatumAlonzo :: 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)
- evalScripts :: forall era tx. ( Era era, Show ( Script era), HasField "body" tx ( TxBody era), HasField "wits" tx ( TxWitness era), HasField "vldt" ( TxBody era) ValidityInterval ) => ProtVer -> tx -> [( ShortByteString , Language , [ Data era], ExUnits , CostModel )] -> ScriptResult
- scriptsNeeded :: forall era tx. ( Era era, HasField "inputs" ( TxBody era) ( Set ( TxIn ( Crypto era))), HasField "wdrls" ( TxBody era) ( Wdrl ( Crypto era)), HasField "certs" ( TxBody era) ( StrictSeq ( DCert ( Crypto era))), HasField "body" tx ( TxBody era)) => UTxO era -> tx -> [( ScriptPurpose ( Crypto era), ScriptHash ( Crypto era))]
- scriptsNeededFromBody :: forall era. ( Era era, HasField "inputs" ( TxBody era) ( Set ( TxIn ( Crypto era))), HasField "wdrls" ( TxBody era) ( Wdrl ( Crypto era)), HasField "certs" ( TxBody era) ( StrictSeq ( DCert ( Crypto era)))) => UTxO era -> TxBody era -> [( ScriptPurpose ( Crypto era), ScriptHash ( Crypto era))]
- language :: Script era -> Maybe Language
-
data
CollectError
crypto
- = NoRedeemer !( ScriptPurpose crypto)
- | NoWitness !( ScriptHash crypto)
- | NoCostModel ! Language
- | BadTranslation !( TranslationError crypto)
- collectTwoPhaseScriptInputs :: forall era. ( Era era, ExtendedUTxO era, Script era ~ Script era, HasField "_costmdls" ( PParams era) CostModels , HasField "wdrls" ( TxBody era) ( Wdrl ( Crypto era)), HasField "certs" ( TxBody era) ( StrictSeq ( DCert ( Crypto era))), HasField "inputs" ( TxBody era) ( Set ( TxIn ( Crypto era))), HasField "wits" ( Tx era) ( TxWitness era)) => EpochInfo ( Either Text ) -> SystemStart -> PParams era -> Tx era -> UTxO era -> Either [ CollectError ( Crypto era)] [( ShortByteString , Language , [ Data era], ExUnits , CostModel )]
- knownToNotBe1Phase :: Map ( ScriptHash ( Crypto era)) ( Script era) -> ( ScriptPurpose ( Crypto era), ScriptHash ( Crypto era)) -> Maybe ( ScriptPurpose ( Crypto era), Language , ShortByteString )
Documentation
getSpendingTxIn :: ScriptPurpose crypto -> Maybe ( TxIn crypto) Source #
Only the Spending ScriptPurpose contains TxIn
getDatumAlonzo :: 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) Source #
Get the Data associated with a ScriptPurpose. Only the Spending ScriptPurpose contains Data. The null list is returned for the other kinds.
evalScripts :: forall era tx. ( Era era, Show ( Script era), HasField "body" tx ( TxBody era), HasField "wits" tx ( TxWitness era), HasField "vldt" ( TxBody era) ValidityInterval ) => ProtVer -> tx -> [( ShortByteString , Language , [ Data era], ExUnits , CostModel )] -> ScriptResult Source #
evaluate a list of scripts, All scripts in the list must be True. There are two kinds of scripts, evaluate each kind using the appropriate mechanism.
scriptsNeeded :: forall era tx. ( Era era, HasField "inputs" ( TxBody era) ( Set ( TxIn ( Crypto era))), HasField "wdrls" ( TxBody era) ( Wdrl ( Crypto era)), HasField "certs" ( TxBody era) ( StrictSeq ( DCert ( Crypto era))), HasField "body" tx ( TxBody era)) => UTxO era -> tx -> [( ScriptPurpose ( Crypto era), ScriptHash ( Crypto era))] Source #
scriptsNeededFromBody :: forall era. ( Era era, HasField "inputs" ( TxBody era) ( Set ( TxIn ( Crypto era))), HasField "wdrls" ( TxBody era) ( Wdrl ( Crypto era)), HasField "certs" ( TxBody era) ( StrictSeq ( DCert ( Crypto era)))) => UTxO era -> TxBody era -> [( ScriptPurpose ( Crypto era), ScriptHash ( Crypto era))] Source #
Uses of inputs in ‘txscripts’ and ‘neededScripts’
There are currently 3 sets of inputs (spending, collateral, reference). A particular TxInput
can appear in more than one of the sets. Even in all three at the same, but that may not be
a really useful case. Inputs are where you find scripts with the
Spending
purpose.
1) Collateral inputs are only spent if phase two fails. Their corresponding TxOut can only have Key (not Script) Pay credentials, so ‘neededScripts’ does not look there. 2) Reference inputs are not spent in the current Tx, unless that same input also appears in one of the other sets. If that is not the case, their credentials are never needed, so anyone can access the inline datums and scripts in their corresponding TxOut, without needing any authorizing credentials. So ‘neededScripts’ does not look there. 3) Spending inputs are always spent. So their Pay credentials are always needed.
Collect information (purpose and ScriptHash) about all the Credentials that refer to scripts that will be needed to run in a TxBody in the Utxow rule. Note there may be credentials that cannot be run, so are not collected. In Babbage, reference inputs, fit that description. Purposes include 1) Spending (payment script credentials, but NOT staking scripts) in the Addr of a TxOut, pointed to by some input that needs authorization. Be sure (getField @"inputs" txb) gets all such inputs. In some Eras there may be multiple sets of inputs, which ones should be included? Currently that is only the spending inputs. Because collateral inputs can only have key-locked credentials, and reference inputs are never authorized. That might not always be the case. 2) Rewarding (Withdrawals), 3) Minting (minted field), and 4) Certifying (Delegating) scripts.
scriptsNeeded
is an aggregation of the needed Credentials referring to Scripts used in Utxow rule.
The flip side of
scriptsNeeded
(which collects script hashes) is
txscripts
which finds the
actual scripts. We maintain an invariant that every script credential refers to some actual script.
This is tested in the test function
validateMissingScripts
in the Utxow rule.
data CollectError crypto Source #
When collecting inputs for twophase scripts, 3 things can go wrong.
NoRedeemer !( ScriptPurpose crypto) | |
NoWitness !( ScriptHash crypto) | |
NoCostModel ! Language | |
BadTranslation !( TranslationError crypto) |
Instances
collectTwoPhaseScriptInputs :: forall era. ( Era era, ExtendedUTxO era, Script era ~ Script era, HasField "_costmdls" ( PParams era) CostModels , HasField "wdrls" ( TxBody era) ( Wdrl ( Crypto era)), HasField "certs" ( TxBody era) ( StrictSeq ( DCert ( Crypto era))), HasField "inputs" ( TxBody era) ( Set ( TxIn ( Crypto era))), HasField "wits" ( Tx era) ( TxWitness era)) => EpochInfo ( Either Text ) -> SystemStart -> PParams era -> Tx era -> UTxO era -> Either [ CollectError ( Crypto era)] [( ShortByteString , Language , [ Data era], ExUnits , CostModel )] Source #
Collect the inputs for twophase scripts. If any script can't find ist data return a list of CollectError, if all goes well return a list of quadruples with the inputs. Previous PredicateFailure tests should ensure we find Data for every script, BUT the consequences of not finding Data means scripts can get dropped, so things might validate that shouldn't. So we double check that every Script has its Data, and if that is not the case, a PredicateFailure is raised in the Utxos rule.
knownToNotBe1Phase :: Map ( ScriptHash ( Crypto era)) ( Script era) -> ( ScriptPurpose ( Crypto era), ScriptHash ( Crypto era)) -> Maybe ( ScriptPurpose ( Crypto era), Language , ShortByteString ) Source #