-
Notifications
You must be signed in to change notification settings - Fork 29
makeUnsignedTx: error when Plutus scripts present without protocol params #1181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,6 +24,7 @@ module Cardano.Api.Experimental.Tx.Internal.BodyContent.New | |||||||||
| , TxWithdrawals (..) | ||||||||||
| , TxBodyContent (..) | ||||||||||
| , Datum (..) | ||||||||||
| , MakeUnsignedTxError (..) | ||||||||||
| , defaultTxBodyContent | ||||||||||
| , extractDatumsAndHashes | ||||||||||
| , getDatums | ||||||||||
|
|
@@ -106,6 +107,7 @@ import Cardano.Api.Governance.Internal.Action.VotingProcedure | |||||||||
| import Cardano.Api.Key.Internal | ||||||||||
| import Cardano.Api.Ledger.Internal.Reexport (StrictMaybe (..)) | ||||||||||
| import Cardano.Api.Ledger.Internal.Reexport qualified as L | ||||||||||
| import Cardano.Api.Monad.Error (liftMaybe) | ||||||||||
| import Cardano.Api.Plutus.Internal.Script | ||||||||||
| ( PlutusScript (..) | ||||||||||
| , PlutusScriptVersion (..) | ||||||||||
|
|
@@ -170,11 +172,27 @@ import Data.Typeable (cast) | |||||||||
| import GHC.Exts (IsList (..)) | ||||||||||
| import Lens.Micro | ||||||||||
|
|
||||||||||
| -- | Error that can occur when constructing an unsigned transaction. | ||||||||||
| data MakeUnsignedTxError | ||||||||||
| = -- | Plutus scripts are present in the transaction but no protocol | ||||||||||
| -- parameters were provided. Protocol parameters are required to | ||||||||||
| -- compute the script integrity hash (script_data_hash). | ||||||||||
| MakeUnsignedTxMissingProtocolParams | ||||||||||
| deriving (Eq, Show) | ||||||||||
|
|
||||||||||
| instance Error MakeUnsignedTxError where | ||||||||||
| prettyError MakeUnsignedTxMissingProtocolParams = | ||||||||||
| mconcat | ||||||||||
| [ "Transaction uses Plutus scripts but no protocol parameters were provided. " | ||||||||||
| , "Protocol parameters are required to compute the script integrity hash " | ||||||||||
| , "(script_data_hash) from the cost models." | ||||||||||
| ] | ||||||||||
|
|
||||||||||
| makeUnsignedTx | ||||||||||
| :: forall era | ||||||||||
| . Era era | ||||||||||
| -> TxBodyContent (LedgerEra era) | ||||||||||
| -> UnsignedTx (LedgerEra era) | ||||||||||
| -> Either MakeUnsignedTxError (UnsignedTx (LedgerEra era)) | ||||||||||
| makeUnsignedTx DijkstraEra _ = error "makeUnsignedTx: Dijkstra era not supported yet" | ||||||||||
| makeUnsignedTx era@ConwayEra bc = obtainCommonConstraints era $ do | ||||||||||
|
Comment on lines
191
to
197
|
||||||||||
| let TxScriptWitnessRequirements languages scripts datums redeemers = collectTxBodyScriptWitnessRequirements bc | ||||||||||
|
|
@@ -197,12 +215,13 @@ makeUnsignedTx era@ConwayEra bc = obtainCommonConstraints era $ do | |||||||||
| totCollateral = unTxTotalCollateral <$> txTotalCollateral bc | ||||||||||
| txAuxData = toAuxiliaryData (txMetadata bc) (txAuxScripts bc) | ||||||||||
| scriptValidity = scriptValidityToIsValid $ txScriptValidity bc | ||||||||||
| scriptIntegrityHash = | ||||||||||
| convPParamsToScriptIntegrityHash | ||||||||||
| protocolParameters | ||||||||||
| redeemers | ||||||||||
| datums | ||||||||||
| languages | ||||||||||
|
|
||||||||||
| scriptIntegrityHash <- | ||||||||||
| convPParamsToScriptIntegrityHash | ||||||||||
| protocolParameters | ||||||||||
| redeemers | ||||||||||
| datums | ||||||||||
| languages | ||||||||||
|
|
||||||||||
| let setMint = convMintValue apiMintValue | ||||||||||
| setReqSignerHashes = convExtraKeyWitnesses apiExtraKeyWitnesses | ||||||||||
|
|
@@ -235,11 +254,12 @@ makeUnsignedTx era@ConwayEra bc = obtainCommonConstraints era $ do | |||||||||
| & L.rdmrsTxWitsL .~ redeemers | ||||||||||
|
|
||||||||||
| let eraSpecificTxBody = eraSpecificLedgerTxBody era ledgerTxBody bc | ||||||||||
| UnsignedTx $ | ||||||||||
| L.mkBasicTx eraSpecificTxBody | ||||||||||
| & L.witsTxL .~ scriptWitnesses | ||||||||||
| & L.auxDataTxL .~ L.maybeToStrictMaybe (toAuxiliaryData (txMetadata bc) (txAuxScripts bc)) | ||||||||||
| & L.isValidTxL .~ scriptValidity | ||||||||||
| Right $ | ||||||||||
| UnsignedTx $ | ||||||||||
| L.mkBasicTx eraSpecificTxBody | ||||||||||
| & L.witsTxL .~ scriptWitnesses | ||||||||||
| & L.auxDataTxL .~ L.maybeToStrictMaybe (toAuxiliaryData (txMetadata bc) (txAuxScripts bc)) | ||||||||||
| & L.isValidTxL .~ scriptValidity | ||||||||||
|
|
||||||||||
| convTxIns :: [(TxIn, AnyWitness era)] -> Set L.TxIn | ||||||||||
| convTxIns inputs = | ||||||||||
|
|
@@ -283,19 +303,23 @@ convPParamsToScriptIntegrityHash | |||||||||
| -> L.Redeemers (LedgerEra era) | ||||||||||
| -> L.TxDats (LedgerEra era) | ||||||||||
| -> Set Plutus.Language | ||||||||||
| -> StrictMaybe L.ScriptIntegrityHash | ||||||||||
| -> Either MakeUnsignedTxError (StrictMaybe L.ScriptIntegrityHash) | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Tbf we could make it run in |
||||||||||
| convPParamsToScriptIntegrityHash mTxProtocolParams redeemers datums languages = obtainCommonConstraints (useEra @era) $ do | ||||||||||
| pp <- L.maybeToStrictMaybe mTxProtocolParams | ||||||||||
| -- This logic is copied from ledger, because their code is not reusable | ||||||||||
| -- c.f. https://github.com/IntersectMBO/cardano-ledger/commit/5a975d9af507c9ee835a86d3bb77f3e2670ad228#diff-8236dfec9688f22550b91fc9a87af9915523ab9c5bd817218ecceec8ca7a789bR282 | ||||||||||
| let shouldCalculateHash = | ||||||||||
| not $ | ||||||||||
| null (redeemers ^. L.unRedeemersL) | ||||||||||
| && null (datums ^. L.unTxDatsL) | ||||||||||
| && null languages | ||||||||||
| guard shouldCalculateHash | ||||||||||
| let scriptIntegrity = L.ScriptIntegrity redeemers datums (Set.map (L.getLanguageView pp) languages) | ||||||||||
| pure $ L.hashScriptIntegrity scriptIntegrity | ||||||||||
| if shouldCalculateHash | ||||||||||
| then do | ||||||||||
| pp <- liftMaybe MakeUnsignedTxMissingProtocolParams mTxProtocolParams | ||||||||||
| pure $ | ||||||||||
| SJust $ | ||||||||||
| L.hashScriptIntegrity $ | ||||||||||
| L.ScriptIntegrity redeemers datums (Set.map (L.getLanguageView pp) languages) | ||||||||||
| else pure SNothing | ||||||||||
|
|
||||||||||
| convProposalProcedures | ||||||||||
| :: forall era | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.