Created
October 25, 2024 01:27
-
-
Save prednaz/02a598104ce1b8916dd4813e32b7d148 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validationFailureScriptContexts | |
:: ShelleyBasedEra ConwayEra | |
-> SystemStart | |
-> LedgerEpochInfo | |
-> LedgerProtocolParameters ConwayEra | |
-> UTxO ConwayEra | |
-> TxBodyContent BuildTx ConwayEra | |
-> AddressInEra ConwayEra | |
-> Map (PlutusPurpose AsIx StandardConway) (FixShow ScriptContext) | |
validationFailureScriptContexts | |
sbe | |
systemstart | |
history | |
(LedgerProtocolParameters pp) | |
utxo | |
txbodycontent | |
changeaddr = | |
fmap FixShow | |
. fromRight mempty | |
. fmap | |
( \txbody -> | |
case makeSignedTransaction [] txbody of | |
ShelleyTx _ tx -> | |
M.mapMaybe | |
( \case | |
Left | |
(ValidationFailure _ _ _ (PlutusWithContext _ _ _ (pwcArgs :: PlutusArgs l) _ _)) -> | |
case isLanguage @l of | |
SPlutusV1 -> Nothing | |
SPlutusV2 -> Nothing | |
SPlutusV3 -> Just $ unPlutusV3Args $ pwcArgs | |
_ -> Nothing | |
) | |
( evalTxExUnitsWithLogs | |
pp | |
tx | |
(toLedgerUTxO sbe utxo) | |
(unLedgerEpochInfo history) | |
systemstart | |
) | |
) | |
-- shamefully copied from https://cardano-api.cardano.intersectmbo.org/cardano-api/internal/src/Cardano.Api.Fees.html#makeTransactionBodyAutoBalance | |
$ createAndValidateTransactionBody | |
sbe | |
txbodycontent | |
{ txOuts = | |
txOuts txbodycontent | |
++ [ TxOut changeaddr (lovelaceToTxOutValue sbe 0) TxOutDatumNone ReferenceScriptNone | |
] | |
-- TODO: think about the size of the change output | |
-- 1,2,4 or 8 bytes? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment