Skip to content
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

Extra HashableScriptData in TxBody for PK inputs and reference inputs with hashed datums. #637

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ substituteExecutionUnits
:: (ScriptWitness witctx era -> Either (TxBodyErrorAutoBalance era) (ScriptWitness witctx era))
-> Witness witctx era
-> Either (TxBodyErrorAutoBalance era) (Witness witctx era)
adjustWitness _ (KeyWitness ctx) = Right $ KeyWitness ctx
adjustWitness _ (KeyWitness ctx witness') = Right $ KeyWitness ctx witness'
adjustWitness g (ScriptWitness ctx witness') = ScriptWitness ctx <$> g witness'

mapScriptWitnessesCertificates
Expand Down
20 changes: 20 additions & 0 deletions cardano-api/internal/Cardano/Api/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ module Cardano.Api.Script
, WitCtxStake
, WitCtx (..)
, ScriptWitness (..)
, PrivateKeyWitness (..)
, Witness (..)
, KeyWitnessInCtx (..)
, ScriptWitnessInCtx (..)
, IsScriptWitnessInCtx (..)
, ScriptDatum (..)
, KeyDatum (..)
, ScriptRedeemer
, scriptWitnessScript

Expand Down Expand Up @@ -722,6 +724,15 @@ data ScriptWitness witctx era where

deriving instance Show (ScriptWitness witctx era)

data PrivateKeyWitness witctx era where
PrivateKeyWitness
:: KeyDatum witctx
-> PrivateKeyWitness witctx era
Comment on lines +727 to +730
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this not a GADT? I know there are lots of them floating around but we are actually moving away from using GADTs when not needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes i can. I basically just mimicked how other types around were defined. But indeed GADTs are not necessary there.


deriving instance Show (PrivateKeyWitness witctx era)

deriving instance Eq (PrivateKeyWitness witctx era)

-- The GADT in the SimpleScriptWitness constructor requires a custom instance
instance Eq (ScriptWitness witctx era) where
(==)
Expand Down Expand Up @@ -773,6 +784,14 @@ deriving instance Eq (ScriptDatum witctx)

deriving instance Show (ScriptDatum witctx)

data KeyDatum witctx where
KeyDatumForTxIn :: Maybe HashableScriptData -> KeyDatum WitCtxTxIn
NoKeyDatumForStake :: KeyDatum WitCtxStake
Comment on lines +787 to +789
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this not a GADT? I know there are lots of them floating around but we are actually moving away from using GADTs when not needed.


deriving instance Eq (KeyDatum witctx)

deriving instance Show (KeyDatum witctx)

-- We cannot always extract a script from a script witness due to reference scripts.
-- Reference scripts exist in the UTxO, so without access to the UTxO we cannot
-- retrieve the script.
Expand Down Expand Up @@ -803,6 +822,7 @@ scriptWitnessScript (PlutusScriptWitness _ _ (PReferenceScript _ _) _ _ _) =
data Witness witctx era where
KeyWitness
:: KeyWitnessInCtx witctx
-> PrivateKeyWitness witctx era
-> Witness witctx era
ScriptWitness
:: ScriptWitnessInCtx witctx
Expand Down
51 changes: 47 additions & 4 deletions cardano-api/internal/Cardano/Api/Tx/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,7 @@ createTransactionBody sbe bc =
shelleyBasedEraConstraints sbe $ do
let era = toCardanoEra sbe
apiTxOuts = txOuts bc
apiTxIns = txIns bc
apiScriptWitnesses = collectTxBodyScriptWitnesses sbe bc
apiScriptValidity = txScriptValidity bc
apiMintValue = txMintValue bc
Expand All @@ -1621,7 +1622,7 @@ createTransactionBody sbe bc =
txAuxData = toAuxiliaryData sbe (txMetadata bc) (txAuxScripts bc)
scripts = convScripts apiScriptWitnesses
languages = convLanguages apiScriptWitnesses
sData = convScriptData sbe apiTxOuts apiScriptWitnesses
sData = convScriptData sbe apiTxIns apiTxOuts apiScriptWitnesses
proposalProcedures = convProposalProcedures $ maybe TxProposalProceduresNone unFeatured (txProposalProcedures bc)
votingProcedures = convVotingProcedures $ maybe TxVotingProceduresNone unFeatured (txVotingProcedures bc)
currentTreasuryValue = Ledger.maybeToStrictMaybe $ unFeatured =<< txCurrentTreasuryValue bc
Expand Down Expand Up @@ -2416,10 +2417,11 @@ convScripts scriptWitnesses =
convScriptData
:: ()
=> ShelleyBasedEra era
-> TxIns build era
-> [TxOut CtxTx era]
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
-> TxBodyScriptData era
convScriptData sbe txOuts scriptWitnesses =
convScriptData sbe txIns txOuts scriptWitnesses =
caseShelleyToMaryOrAlonzoEraOnwards
(const TxBodyNoScriptData)
( \w ->
Expand Down Expand Up @@ -2460,6 +2462,17 @@ convScriptData sbe txOuts scriptWitnesses =
) <-
scriptWitnesses
]
++ [ d
| ( _
, BuildTxWith
( KeyWitness
_
(PrivateKeyWitness (KeyDatumForTxIn (Just d)))
)
) <-
txIns
]

in TxBodyScriptData w datums redeemers
)
sbe
Expand Down Expand Up @@ -2763,6 +2776,16 @@ makeShelleyTransactionBody
) <-
witnesses
]
++ [ d
| ( _
, BuildTxWith
( KeyWitness
_
(PrivateKeyWitness (KeyDatumForTxIn (Just d)))
)
) <-
txIns
]

redeemers :: Alonzo.Redeemers StandardAlonzo
redeemers =
Expand Down Expand Up @@ -2886,7 +2909,17 @@ makeShelleyTransactionBody
) <-
witnesses
]

++ [ d
| ( _
, BuildTxWith
( KeyWitness
_
(PrivateKeyWitness (KeyDatumForTxIn (Just d)))
)
) <-
txIns
]

redeemers :: Alonzo.Redeemers StandardBabbage
redeemers =
Alonzo.Redeemers $
Expand Down Expand Up @@ -3024,7 +3057,17 @@ makeShelleyTransactionBody
) <-
witnesses
]

++ [ d
| ( _
, BuildTxWith
( KeyWitness
_
(PrivateKeyWitness (KeyDatumForTxIn (Just d)))
)
) <-
txIns
]

redeemers :: Alonzo.Redeemers StandardConway
redeemers =
Alonzo.Redeemers $
Expand Down
Loading