Skip to content

Commit

Permalink
some review remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Dec 30, 2024
1 parent cba75e6 commit 0d22df3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
24 changes: 12 additions & 12 deletions cardano-api/internal/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1450,12 +1450,12 @@ substituteExecutionUnits
redeemer
exunits

adjustWitness
adjustScriptWitness
:: (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 g (ScriptWitness ctx witness') = ScriptWitness ctx <$> g witness'
adjustScriptWitness _ (KeyWitness ctx) = Right $ KeyWitness ctx
adjustScriptWitness g (ScriptWitness ctx witness') = ScriptWitness ctx <$> g witness'

mapScriptWitnessesTxIns
:: [(TxIn, BuildTxWith BuildTx (Witness WitCtxTxIn era))]
Expand All @@ -1468,8 +1468,8 @@ substituteExecutionUnits
]
mappedScriptWitnesses =
[ (txin, BuildTxWith <$> wit')
| (ix, txin, wit) <- txInsToIndexed txins
, let wit' = adjustWitness (substituteExecUnits ix) wit
| (ix, txin, wit) <- indexTxIns txins
, let wit' = adjustScriptWitness (substituteExecUnits ix) wit
]
in traverse
(\(txIn, eWitness) -> (txIn,) <$> eWitness)
Expand All @@ -1488,8 +1488,8 @@ substituteExecutionUnits
]
mappedWithdrawals =
[ (addr, withdrawal, BuildTxWith <$> mappedWitness)
| (ix, addr, withdrawal, wit) <- txWithdrawalsToIndexed txWithdrawals'
, let mappedWitness = adjustWitness (substituteExecUnits ix) wit
| (ix, addr, withdrawal, wit) <- indexTxWithdrawals txWithdrawals'
, let mappedWitness = adjustScriptWitness (substituteExecUnits ix) wit
]
in TxWithdrawals supported
<$> traverse
Expand All @@ -1505,8 +1505,8 @@ substituteExecutionUnits
:: [(StakeCredential, Either (TxBodyErrorAutoBalance era) (Witness WitCtxStake era))]
mappedScriptWitnesses =
[ (stakeCred, witness')
| (ix, _, stakeCred, witness) <- txCertificatesToIndexed txCertificates'
, let witness' = adjustWitness (substituteExecUnits ix) witness
| (ix, _, stakeCred, witness) <- indexTxCertificates txCertificates'
, let witness' = adjustScriptWitness (substituteExecUnits ix) witness
]
in TxCertificates supported certs . BuildTxWith
<$> traverse
Expand All @@ -1524,7 +1524,7 @@ substituteExecutionUnits
mapScriptWitnessesVotes (Just (Featured era txVotingProcedures'@(TxVotingProcedures vProcedures (BuildTxWith _)))) = do
let eSubstitutedExecutionUnits =
[ (vote, updatedWitness)
| (ix, vote, witness) <- txVotingProceduresToIndexed txVotingProcedures'
| (ix, vote, witness) <- indexTxVotingProcedures txVotingProcedures'
, let updatedWitness = substituteExecUnits ix witness
]

Expand All @@ -1545,7 +1545,7 @@ substituteExecutionUnits
mapScriptWitnessesProposals (Just (Featured era txpp@(TxProposalProcedures osetProposalProcedures (BuildTxWith _)))) = do
let eSubstitutedExecutionUnits =
[ (proposal, updatedWitness)
| (ix, proposal, scriptWitness) <- txProposalProceduresToIndexed txpp
| (ix, proposal, scriptWitness) <- indexTxProposalProcedures txpp
, let updatedWitness = substituteExecUnits ix scriptWitness
]

Expand All @@ -1565,7 +1565,7 @@ substituteExecutionUnits
mapScriptWitnessesMinting txMintValue'@(TxMintValue w _) = do
let mappedScriptWitnesses =
[ (policyId, pure . (assetName',quantity,) <$> substitutedWitness)
| (ix, policyId, assetName', quantity, BuildTxWith witness) <- txMintValueToIndexed txMintValue'
| (ix, policyId, assetName', quantity, BuildTxWith witness) <- indexTxMintValue txMintValue'
, let substitutedWitness = BuildTxWith <$> substituteExecUnits ix witness
]
final <- Map.fromListWith (<>) <$> traverseScriptWitnesses mappedScriptWitnesses
Expand Down
58 changes: 29 additions & 29 deletions cardano-api/internal/Cardano/Api/Tx/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module Cardano.Api.Tx.Body
-- * Transaction inputs
, TxIn (..)
, TxIns
, txInsToIndexed
, indexTxIns
, TxIx (..)
, genesisUTxOPseudoTxIn
, getReferenceInputsSizeForTxIds
Expand Down Expand Up @@ -133,19 +133,19 @@ module Cardano.Api.Tx.Body
, TxAuxScripts (..)
, TxExtraKeyWitnesses (..)
, TxWithdrawals (..)
, txWithdrawalsToIndexed
, indexTxWithdrawals
, TxCertificates (..)
, txCertificatesToIndexed
, indexTxCertificates
, TxUpdateProposal (..)
, TxMintValue (..)
, txMintValueToValue
, txMintValueToIndexed
, indexTxMintValue
, TxVotingProcedures (..)
, mkTxVotingProcedures
, txVotingProceduresToIndexed
, indexTxVotingProcedures
, TxProposalProcedures (..)
, mkTxProposalProcedures
, txProposalProceduresToIndexed
, indexTxProposalProcedures
, convProposalProcedures

-- ** Building vs viewing transactions
Expand Down Expand Up @@ -939,10 +939,10 @@ type TxIns build era = [(TxIn, BuildTxWith build (Witness WitCtxTxIn era))]

-- | Index transaction inputs ordered by TxIn
-- See section 4.1 of https://github.com/intersectmbo/cardano-ledger/releases/latest/download/alonzo-ledger.pdf
txInsToIndexed
indexTxIns
:: TxIns BuildTx era
-> [(ScriptWitnessIndex, TxIn, Witness WitCtxTxIn era)]
txInsToIndexed txins =
indexTxIns txins =
[ (ScriptWitnessIndexTxIn ix, txIn, witness)
| (ix, (txIn, BuildTxWith witness)) <- zip [0 ..] $ orderTxIns txins
]
Expand Down Expand Up @@ -1259,11 +1259,11 @@ deriving instance Show (TxWithdrawals build era)

-- | Index the withdrawals with witnesses in the order of stake addresses.
-- See section 4.1 of https://github.com/intersectmbo/cardano-ledger/releases/latest/download/alonzo-ledger.pdf
txWithdrawalsToIndexed
indexTxWithdrawals
:: TxWithdrawals BuildTx era
-> [(ScriptWitnessIndex, StakeAddress, L.Coin, Witness WitCtxStake era)]
txWithdrawalsToIndexed TxWithdrawalsNone = []
txWithdrawalsToIndexed (TxWithdrawals _ withdrawals) =
indexTxWithdrawals TxWithdrawalsNone = []
indexTxWithdrawals (TxWithdrawals _ withdrawals) =
[ (ScriptWitnessIndexWithdrawal ix, addr, coin, witness)
| (ix, (addr, coin, BuildTxWith witness)) <- zip [0 ..] (orderStakeAddrs withdrawals)
]
Expand Down Expand Up @@ -1295,11 +1295,11 @@ deriving instance Show (TxCertificates build era)
-- | Index certificates with witnesses by the order they appear in the list (in the transaction). If there
-- are multiple witnesses for the credential, the last one is returned.
-- See section 4.1 of https://github.com/intersectmbo/cardano-ledger/releases/latest/download/alonzo-ledger.pdf
txCertificatesToIndexed
indexTxCertificates
:: TxCertificates BuildTx era
-> [(ScriptWitnessIndex, Certificate era, StakeCredential, Witness WitCtxStake era)]
txCertificatesToIndexed TxCertificatesNone = []
txCertificatesToIndexed (TxCertificates _ certs (BuildTxWith witnesses)) =
indexTxCertificates TxCertificatesNone = []
indexTxCertificates (TxCertificates _ certs (BuildTxWith witnesses)) =
[ (ScriptWitnessIndexCertificate ix, cert, stakeCred, wit)
| (ix, cert) <- zip [0 ..] certs
, stakeCred <- maybeToList (selectStakeCredentialWitness cert)
Expand Down Expand Up @@ -1351,7 +1351,7 @@ txMintValueToValue (TxMintValue _ policiesWithAssets) =

-- | Index the assets with witnesses in the order of policy ids.
-- See section 4.1 of https://github.com/intersectmbo/cardano-ledger/releases/latest/download/alonzo-ledger.pdf
txMintValueToIndexed
indexTxMintValue
:: TxMintValue build era
-> [ ( ScriptWitnessIndex
, PolicyId
Expand All @@ -1360,8 +1360,8 @@ txMintValueToIndexed
, BuildTxWith build (ScriptWitness WitCtxMint era)
)
]
txMintValueToIndexed TxMintNone = []
txMintValueToIndexed (TxMintValue _ policiesWithAssets) =
indexTxMintValue TxMintNone = []
indexTxMintValue (TxMintValue _ policiesWithAssets) =
[ (ScriptWitnessIndexMint ix, policyId', assetName', quantity, witness)
| (ix, (policyId', assets)) <- zip [0 ..] $ toList policiesWithAssets
, (assetName', quantity, witness) <- assets
Expand Down Expand Up @@ -1419,15 +1419,15 @@ mkTxVotingProcedures votingProcedures = do
listToMaybe $ Map.keys m

-- | Index voting procedures by the order of the votes ('Ord').
txVotingProceduresToIndexed
indexTxVotingProcedures
:: TxVotingProcedures BuildTx era
-> [ ( ScriptWitnessIndex
, L.Voter (Ledger.EraCrypto (ShelleyLedgerEra era))
, ScriptWitness WitCtxStake era
)
]
txVotingProceduresToIndexed TxVotingProceduresNone = []
txVotingProceduresToIndexed (TxVotingProcedures vProcedures (BuildTxWith sWitMap)) =
indexTxVotingProcedures TxVotingProceduresNone = []
indexTxVotingProcedures (TxVotingProcedures vProcedures (BuildTxWith sWitMap)) =
[ (ScriptWitnessIndexVoting $ fromIntegral index, vote, scriptWitness)
| let allVoteMap = L.unVotingProcedures vProcedures
, (vote, scriptWitness) <- toList sWitMap
Expand Down Expand Up @@ -1476,11 +1476,11 @@ mkTxProposalProcedures proposalsWithWitnessesList = do
(DList.snoc ps p, DList.snoc pws (p, w)) -- add a proposal both to the list and to the witnessed list

-- | Index proposal procedures by their order ('Ord').
txProposalProceduresToIndexed
indexTxProposalProcedures
:: TxProposalProcedures BuildTx era
-> [(ScriptWitnessIndex, L.ProposalProcedure (ShelleyLedgerEra era), ScriptWitness WitCtxStake era)]
txProposalProceduresToIndexed TxProposalProceduresNone = []
txProposalProceduresToIndexed txpp@(TxProposalProcedures _ (BuildTxWith witnesses)) = do
indexTxProposalProcedures TxProposalProceduresNone = []
indexTxProposalProcedures txpp@(TxProposalProcedures _ (BuildTxWith witnesses)) = do
let allProposalsList = toList $ convProposalProcedures txpp
[ (ScriptWitnessIndexProposing $ fromIntegral ix, proposal, scriptWitness)
| (proposal, scriptWitness) <- toList witnesses
Expand Down Expand Up @@ -3562,7 +3562,7 @@ collectTxBodyScriptWitnesses
-> [(ScriptWitnessIndex, AnyScriptWitness era)]
scriptWitnessesTxIns txIns' =
[ (ix, AnyScriptWitness witness)
| (ix, _, ScriptWitness _ witness) <- txInsToIndexed txIns'
| (ix, _, ScriptWitness _ witness) <- indexTxIns txIns'
]

scriptWitnessesWithdrawals
Expand All @@ -3571,7 +3571,7 @@ collectTxBodyScriptWitnesses
scriptWitnessesWithdrawals TxWithdrawalsNone = []
scriptWitnessesWithdrawals txw =
[ (ix, AnyScriptWitness witness)
| (ix, _, _, ScriptWitness _ witness) <- txWithdrawalsToIndexed txw
| (ix, _, _, ScriptWitness _ witness) <- indexTxWithdrawals txw
]

scriptWitnessesCertificates
Expand All @@ -3580,7 +3580,7 @@ collectTxBodyScriptWitnesses
scriptWitnessesCertificates TxCertificatesNone = []
scriptWitnessesCertificates txc =
[ (ix, AnyScriptWitness witness)
| (ix, _, _, ScriptWitness _ witness) <- txCertificatesToIndexed txc
| (ix, _, _, ScriptWitness _ witness) <- indexTxCertificates txc
]

scriptWitnessesMinting
Expand All @@ -3589,7 +3589,7 @@ collectTxBodyScriptWitnesses
scriptWitnessesMinting TxMintNone = []
scriptWitnessesMinting txMintValue' =
[ (ix, AnyScriptWitness witness)
| (ix, _, _, _, BuildTxWith witness) <- txMintValueToIndexed txMintValue'
| (ix, _, _, _, BuildTxWith witness) <- indexTxMintValue txMintValue'
]

scriptWitnessesVoting
Expand All @@ -3598,7 +3598,7 @@ collectTxBodyScriptWitnesses
scriptWitnessesVoting TxVotingProceduresNone = []
scriptWitnessesVoting txv =
[ (ix, AnyScriptWitness witness)
| (ix, _, witness) <- txVotingProceduresToIndexed txv
| (ix, _, witness) <- indexTxVotingProcedures txv
]

scriptWitnessesProposing
Expand All @@ -3607,7 +3607,7 @@ scriptWitnessesProposing
scriptWitnessesProposing TxProposalProceduresNone = []
scriptWitnessesProposing txp =
[ (ix, AnyScriptWitness witness)
| (ix, _, witness) <- txProposalProceduresToIndexed txp
| (ix, _, witness) <- indexTxProposalProcedures txp
]

-- TODO: Investigate if we need
Expand Down
2 changes: 1 addition & 1 deletion cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ module Cardano.Api
, TxUpdateProposal (..)
, TxMintValue (..)
, txMintValueToValue
, txMintValueToIndexed
, indexTxMintValue
, TxVotingProcedures (..)
, mkTxVotingProcedures
, TxProposalProcedures (..)
Expand Down

0 comments on commit 0d22df3

Please sign in to comment.