Skip to content

Commit

Permalink
Omit field updates that use default values
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Mar 6, 2023
1 parent 2c77631 commit f85ef25
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,15 @@ dummyTxSizeInEra metadata = case createAndValidateTransactionBody dummyTx of
Left err -> error $ "metaDataSize " ++ show err
where
dummyTx :: TxBodyContent BuildTx era
dummyTx = (defaultTxBodyContent @BuildTx @era)
dummyTx = defaultValue
{ txIns =
[ ( TxIn "dbaff4e270cfb55612d9e2ac4658a27c79da4a5271c6f90853042d1403733810" (TxIx 0)
, BuildTxWith $ KeyWitness KeyWitnessForSpending
)
]
, txInsCollateral = TxInsCollateralNone
, txInsReference = TxInsReferenceNone
, txOuts = []
, txFee = mkTxFee 0
, txValidityRange = (TxValidityNoLowerBound, mkTxValidityUpperBound 0)
, txMetadata = metadata
, txAuxScripts = TxAuxScriptsNone
, txExtraKeyWits = TxExtraKeyWitnessesNone
, txProtocolParams = BuildTxWith Nothing
, txWithdrawals = TxWithdrawalsNone
, txCertificates = TxCertificatesNone
, txUpdateProposal = TxUpdateProposalNone
, txMintValue = TxMintNone
, txScriptValidity = TxScriptValidityNone
, txReturnCollateral = TxReturnCollateralNone
, txTotalCollateral = TxTotalCollateralNone
}

dummyTxSize :: forall era . IsShelleyBasedEra era => AsType era -> Maybe TxMetadata -> Int
Expand Down
15 changes: 1 addition & 14 deletions bench/tx-generator/src/Cardano/TxGenerator/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,11 @@ mkGenesisTransaction key ttl fee txins txouts
(`signShelleyTransaction` [WitnessGenesisUTxOKey key])
(createAndValidateTransactionBody txBodyContent)
where
txBodyContent = (defaultTxBodyContent @BuildTx @era)
txBodyContent = defaultValue
{ txIns = zip txins $ repeat $ BuildTxWith $ KeyWitness KeyWitnessForSpending
, txInsCollateral = TxInsCollateralNone
, txInsReference = TxInsReferenceNone
, txOuts = txouts
, txFee = mkTxFee fee
, txValidityRange = (TxValidityNoLowerBound, mkTxValidityUpperBound ttl)
, txMetadata = TxMetadataNone
, txAuxScripts = TxAuxScriptsNone
, txExtraKeyWits = TxExtraKeyWitnessesNone
, txProtocolParams = BuildTxWith Nothing
, txWithdrawals = TxWithdrawalsNone
, txCertificates = TxCertificatesNone
, txUpdateProposal = TxUpdateProposalNone
, txMintValue = TxMintNone
, txScriptValidity = TxScriptValidityNone
, txReturnCollateral = TxReturnCollateralNone
, txTotalCollateral = TxTotalCollateralNone
}

castKey :: SigningKey PaymentKey -> SigningKey GenesisUTxOKey
Expand Down
12 changes: 1 addition & 11 deletions bench/tx-generator/src/Cardano/TxGenerator/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,14 @@ genTx protocolParameters (collateral, collFunds) fee metadata inFunds outputs
(createAndValidateTransactionBody txBodyContent)
where
allKeys = mapMaybe getFundKey $ inFunds ++ collFunds
txBodyContent = (defaultTxBodyContent @BuildTx @era)
txBodyContent = defaultValue
{ txIns = map (\f -> (getFundTxIn f, BuildTxWith $ getFundWitness f)) inFunds
, txInsCollateral = collateral
, txInsReference = TxInsReferenceNone
, txOuts = outputs
, txFee = fee
, txValidityRange = (TxValidityNoLowerBound, upperBound)
, txMetadata = metadata
, txAuxScripts = TxAuxScriptsNone
, txExtraKeyWits = TxExtraKeyWitnessesNone
, txProtocolParams = BuildTxWith $ Just protocolParameters
, txWithdrawals = TxWithdrawalsNone
, txCertificates = TxCertificatesNone
, txUpdateProposal = TxUpdateProposalNone
, txMintValue = TxMintNone
, txScriptValidity = TxScriptValidityNone
, txReturnCollateral = TxReturnCollateralNone
, txTotalCollateral = TxTotalCollateralNone
}

upperBound :: TxValidityUpperBound era
Expand Down
24 changes: 5 additions & 19 deletions cardano-api/src/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3110,25 +3110,11 @@ makeByronTransactionBody TxBodyContent { txIns, txOuts } = do
getByronTxBodyContent :: Annotated Byron.Tx ByteString
-> TxBodyContent ViewTx ByronEra
getByronTxBodyContent (Annotated Byron.UnsafeTx{txInputs, txOutputs} _) =
(defaultTxBodyContent @ViewTx @ByronEra)
{ txIns = [ (fromByronTxIn input, ViewTx) | input <- toList txInputs]
, txInsCollateral = TxInsCollateralNone
, txInsReference = TxInsReferenceNone
, txOuts = fromByronTxOut <$> toList txOutputs
, txReturnCollateral = TxReturnCollateralNone
, txTotalCollateral = TxTotalCollateralNone
, txFee = TxFeeImplicit TxFeesImplicitInByronEra
, txValidityRange = (TxValidityNoLowerBound, TxValidityNoUpperBound ValidityNoUpperBoundInByronEra)
, txMetadata = TxMetadataNone
, txAuxScripts = TxAuxScriptsNone
, txExtraKeyWits = TxExtraKeyWitnessesNone
, txProtocolParams = ViewTx
, txWithdrawals = TxWithdrawalsNone
, txCertificates = TxCertificatesNone
, txUpdateProposal = TxUpdateProposalNone
, txMintValue = TxMintNone
, txScriptValidity = TxScriptValidityNone
}
defaultValue
{ txIns = [(fromByronTxIn input, ViewTx) | input <- toList txInputs]
, txOuts = fromByronTxOut <$> toList txOutputs
, txFee = TxFeeImplicit TxFeesImplicitInByronEra
}

convTxIns :: TxIns BuildTx era -> Set (Shelley.TxIn StandardCrypto)
convTxIns txIns = Set.fromList (map (toShelleyTxIn . fst) txIns)
Expand Down

0 comments on commit f85ef25

Please sign in to comment.