Skip to content

Commit

Permalink
Merge #4491
Browse files Browse the repository at this point in the history
4491: Separate IO from txBuild and txBuildRaw functions r=Jimbo4350 a=Jimbo4350

First step towards condensing modules responsible for reading and validating the things required for transaction construction. The end goal is to expose these modules via `cardano-api` so users can implement their own transaction construction and/or validation functions.

Co-authored-by: Jordan Millar <jordan.millar@iohk.io>
  • Loading branch information
iohk-bors[bot] and Jimbo4350 authored Oct 17, 2022
2 parents 85d0572 + 4e353f8 commit ab8d8d2
Show file tree
Hide file tree
Showing 4 changed files with 360 additions and 286 deletions.
2 changes: 2 additions & 0 deletions cardano-api/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

- Expose convenience functions `executeQueryCardanoMode`, `determineEra`, `constructBalancedTx` and `queryStateForBalancedTx` ([PR 4446](https://github.com/input-output-hk/cardano-node/pull/4446))

- Expand `BalancedTxBody` to include `TxBodyContent` ([PR 4491](https://github.com/input-output-hk/cardano-node/pull/4491))

### Bugs

- Allow reading text envelopes from pipes ([PR 4384](https://github.com/input-output-hk/cardano-node/pull/4384))
Expand Down
2 changes: 1 addition & 1 deletion cardano-api/src/Cardano/Api/Convenience/Construction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ constructBalancedTx
-> Either TxBodyErrorAutoBalance (Tx era)
constructBalancedTx eInMode txbodcontent changeAddr mOverrideWits utxo pparams
eraHistory systemStart stakePools shelleyWitSigningKeys = do
BalancedTxBody txbody _txBalanceOutput _fee
BalancedTxBody _ txbody _txBalanceOutput _fee
<- makeTransactionBodyAutoBalance
eInMode systemStart eraHistory
pparams stakePools utxo txbodcontent
Expand Down
12 changes: 8 additions & 4 deletions cardano-api/src/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ handleExUnitsErrors ScriptInvalid failuresMap exUnitsMap

data BalancedTxBody era
= BalancedTxBody
(TxBodyContent BuildTx era)
(TxBody era)
(TxOut CtxTx era) -- ^ Transaction balance (change output)
Lovelace -- ^ Estimated transaction fee
Expand Down Expand Up @@ -1025,17 +1026,20 @@ makeTransactionBodyAutoBalance eraInMode systemstart history pparams
-- fit within the encoding size we picked above when calculating the fee.
-- Yes this could be an over-estimate by a few bytes if the fee or change
-- would fit within 2^16-1. That's a possible optimisation.
txbody3 <-
first TxBodyError $ -- TODO: impossible to fail now
createAndValidateTransactionBody txbodycontent1 {
let finalTxBodyContent = txbodycontent1 {
txFee = TxFeeExplicit explicitTxFees fee,
txOuts = accountForNoChange
(TxOut changeaddr balance TxOutDatumNone ReferenceScriptNone)
(txOuts txbodycontent),
txReturnCollateral = retColl,
txTotalCollateral = reqCol
}
return (BalancedTxBody txbody3 (TxOut changeaddr balance TxOutDatumNone ReferenceScriptNone) fee)
txbody3 <-
first TxBodyError $ -- TODO: impossible to fail now. We need to implement a function
-- that simply creates a transaction body because we have already
-- validated the transaction body earlier within makeTransactionBodyAutoBalance
createAndValidateTransactionBody finalTxBodyContent
return (BalancedTxBody finalTxBodyContent txbody3 (TxOut changeaddr balance TxOutDatumNone ReferenceScriptNone) fee)
where
-- Essentially we check for the existence of collateral inputs. If they exist we
-- create a fictitious collateral return output. Why? Because we need to put dummy values
Expand Down
Loading

0 comments on commit ab8d8d2

Please sign in to comment.