Skip to content

Commit 481f365

Browse files
committed
Add posibility to provide actual datums for hashes in reference inputs
1 parent ed1b363 commit 481f365

File tree

8 files changed

+177
-86
lines changed

8 files changed

+177
-86
lines changed

cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs

+25-19
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ where
144144

145145
import Cardano.Api hiding (txIns)
146146
import qualified Cardano.Api as Api
147-
import qualified Cardano.Api.Experimental as Exp
147+
import qualified Cardano.Api.Experimental as Exp
148148
import Cardano.Api.Byron (KeyWitness (ByronKeyWitness),
149149
WitnessNetworkIdOrByronAddress (..))
150150
import qualified Cardano.Api.Byron as Byron
@@ -965,11 +965,17 @@ genTxInsCollateral =
965965
]
966966
)
967967

968-
genTxInsReference :: CardanoEra era -> Gen (TxInsReference era)
968+
genTxInsReference
969+
:: Applicative (BuildTxWith build)
970+
=> CardanoEra era
971+
-> Gen (TxInsReference build era)
969972
genTxInsReference =
970973
caseByronToAlonzoOrBabbageEraOnwards
971974
(const (pure TxInsReferenceNone))
972-
(\w -> TxInsReference w <$> Gen.list (Range.linear 0 10) genTxIn)
975+
(\w -> do
976+
txIns <- Gen.list (Range.linear 0 10) genTxIn
977+
pure $ TxInsReference w txIns mempty
978+
)
973979

974980
genTxReturnCollateral :: ShelleyBasedEra era -> Gen (TxReturnCollateral CtxTx era)
975981
genTxReturnCollateral era =
@@ -1022,7 +1028,7 @@ genWitnessesByron = Gen.list (Range.constant 1 10) genByronKeyWitness
10221028

10231029
-- | This generator validates generated 'TxBodyContent' and backtracks when the generated body
10241030
-- fails the validation. That also means that it is quite slow.
1025-
genValidTxBody :: Typeable era
1031+
genValidTxBody :: Typeable era
10261032
=> ShelleyBasedEra era
10271033
-> Gen (TxBody era, TxBodyContent BuildTx era) -- ^ validated 'TxBody' and 'TxBodyContent'
10281034
genValidTxBody sbe =
@@ -1036,7 +1042,7 @@ genValidTxBody sbe =
10361042
-- | Partial! This function will throw an error when the generated transaction is invalid.
10371043
genTxBody :: (HasCallStack, Typeable era) => ShelleyBasedEra era -> Gen (TxBody era)
10381044
genTxBody era = do
1039-
res <- Api.createTransactionBody era <$> genTxBodyContent era
1045+
res <- Api.createTransactionBody era mempty <$> genTxBodyContent era
10401046
case res of
10411047
Left err -> error (docToString (prettyError err))
10421048
Right txBody -> pure txBody
@@ -1135,7 +1141,7 @@ genShelleyBootstrapWitness sbe =
11351141
<*> (fst <$> genValidTxBody sbe)
11361142
<*> genSigningKey AsByronKey
11371143

1138-
1144+
11391145
genShelleyKeyWitness
11401146
:: ()
11411147
=> Typeable era
@@ -1385,39 +1391,39 @@ genTreasuryDonation :: ConwayEraOnwards era -> Gen L.Coin
13851391
genTreasuryDonation _era = Q.arbitrary
13861392

13871393
genWitnessable :: L.AlonzoEraScript era => Gen (Exp.Witnessable Exp.TxInItem era)
1388-
genWitnessable = Exp.WitTxIn <$> genTxIn
1394+
genWitnessable = Exp.WitTxIn <$> genTxIn
13891395

13901396
genMintWitnessable :: L.AlonzoEraScript era => Gen (Exp.Witnessable Exp.MintItem era)
1391-
genMintWitnessable = Exp.WitMint <$> genPolicyId <*> genPolicyAssets
1397+
genMintWitnessable = Exp.WitMint <$> genPolicyId <*> genPolicyAssets
13921398

1393-
genIndexedPlutusScriptWitness
1394-
:: L.AlonzoEraScript (ShelleyLedgerEra era)
1399+
genIndexedPlutusScriptWitness
1400+
:: L.AlonzoEraScript (ShelleyLedgerEra era)
13951401
=> Gen (Exp.IndexedPlutusScriptWitness Exp.TxInItem L.PlutusV3 Exp.SpendingScript (ShelleyLedgerEra era))
13961402
genIndexedPlutusScriptWitness = do
13971403
index <- Gen.word32 $ Range.linear 1 10
13981404
witnessable <- genWitnessable
1399-
Exp.IndexedPlutusScriptWitness
1405+
Exp.IndexedPlutusScriptWitness
14001406
<$> genWitnessable
14011407
<*> genPlutusPurpose index witnessable
1402-
<*> genPlutusScriptWitness
1408+
<*> genPlutusScriptWitness
14031409

1404-
genPlutusPurpose
1405-
:: Word32
1406-
-> Exp.Witnessable thing (ShelleyLedgerEra era)
1410+
genPlutusPurpose
1411+
:: Word32
1412+
-> Exp.Witnessable thing (ShelleyLedgerEra era)
14071413
-> Gen (L.PlutusPurpose L.AsIx (ShelleyLedgerEra era))
14081414
genPlutusPurpose index wit = return $ Exp.toPlutusScriptPurpose index wit
14091415

14101416
genPlutusScriptWitness :: Gen (Exp.PlutusScriptWitness L.PlutusV3 purpose era)
1411-
genPlutusScriptWitness = do
1417+
genPlutusScriptWitness = do
14121418
let l = Exp.toPlutusSLanguage PlutusScriptV3
1413-
Exp.PlutusScriptWitness l . Exp.PReferenceScript
1419+
Exp.PlutusScriptWitness l . Exp.PReferenceScript
14141420
<$> genTxIn
14151421
<*> genPlutusScriptDatum
14161422
<*> genHashableScriptData
1417-
<*> genExecutionUnits
1423+
<*> genExecutionUnits
14181424

14191425
genPlutusScriptDatum :: Gen (Exp.PlutusScriptDatum lang purpose)
1420-
genPlutusScriptDatum = return Exp.NoScriptDatum
1426+
genPlutusScriptDatum = return Exp.NoScriptDatum
14211427

14221428
-- | This generator does not generate a valid witness - just a random one.
14231429
genScriptWitnessForStake :: ShelleyBasedEra era -> Gen (Api.ScriptWitness WitCtxStake era)

cardano-api/src/Cardano/Api/Internal/Experimental/Tx.hs

+5-2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ import Cardano.Api.Internal.ReexposeLedger (StrictMaybe (..), maybeToStrictMaybe
134134
import Cardano.Api.Internal.ReexposeLedger qualified as L
135135
import Cardano.Api.Internal.Tx.Body
136136
import Cardano.Api.Internal.Tx.Sign
137+
import Cardano.Api.Internal.Tx.UTxO (UTxO)
137138

138139
import Cardano.Crypto.Hash qualified as Hash
139140
import Cardano.Ledger.Alonzo.TxBody qualified as L
@@ -162,14 +163,16 @@ newtype UnsignedTxError
162163

163164
makeUnsignedTx
164165
:: Era era
166+
-> UTxO era
167+
-- ^ UTXO for reference inputs
165168
-> TxBodyContent BuildTx era
166169
-> Either TxBodyError (UnsignedTx era)
167-
makeUnsignedTx era bc = obtainCommonConstraints era $ do
170+
makeUnsignedTx era utxo bc = obtainCommonConstraints era $ do
168171
let sbe = convert era
169172
aeon = convert era
170173
TxScriptWitnessRequirements languages scripts datums redeemers <-
171174
shelleyBasedEraConstraints sbe $
172-
collectTxBodyScriptWitnessRequirements (convert era) bc
175+
collectTxBodyScriptWitnessRequirements (convert era) utxo bc
173176

174177
-- cardano-api types
175178
let apiTxOuts = txOuts bc

cardano-api/src/Cardano/Api/Internal/Fees.hs

+8-3
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ estimateBalancedTxBody
596596
first TxFeeEstimationxBodyError $ -- TODO: impossible to fail now
597597
createTransactionBody
598598
sbe
599+
mempty
599600
txbodycontent1
600601
{ txFee = TxFeeExplicit sbe maxLovelaceFee
601602
, txOuts =
@@ -638,6 +639,7 @@ estimateBalancedTxBody
638639
first TxFeeEstimationxBodyError $ -- TODO: impossible to fail now
639640
createTransactionBody
640641
sbe
642+
mempty
641643
txbodycontent1
642644
{ txFee = TxFeeExplicit sbe fee
643645
, txReturnCollateral = retColl
@@ -678,7 +680,7 @@ estimateBalancedTxBody
678680
first TxFeeEstimationFinalConstructionError $ -- TODO: impossible to fail now. We need to implement a function
679681
-- that simply creates a transaction body because we have already
680682
-- validated the transaction body earlier within makeTransactionBodyAutoBalance
681-
createTransactionBody sbe finalTxBodyContent
683+
createTransactionBody sbe mempty finalTxBodyContent
682684
return
683685
( BalancedTxBody
684686
finalTxBodyContent
@@ -1365,7 +1367,7 @@ makeTransactionBodyAutoBalance
13651367
-- 3. update tx with fees
13661368
-- 4. balance the transaction and update tx change output
13671369

1368-
txbodyForChange <- first TxBodyError $ createTransactionBody sbe txbodycontent
1370+
txbodyForChange <- first TxBodyError $ createTransactionBody sbe utxo txbodycontent
13691371
let initialChangeTxOutValue =
13701372
evaluateTransactionBalance sbe pp poolids stakeDelegDeposits drepDelegDeposits utxo txbodyForChange
13711373
initialChangeTxOut =
@@ -1387,6 +1389,7 @@ makeTransactionBodyAutoBalance
13871389
first TxBodyError
13881390
$ createTransactionBody
13891391
sbe
1392+
utxo
13901393
$ txbodycontent
13911394
& modTxOuts
13921395
(<> [initialChangeTxOut])
@@ -1425,6 +1428,7 @@ makeTransactionBodyAutoBalance
14251428
first TxBodyError $ -- TODO: impossible to fail now
14261429
createTransactionBody
14271430
sbe
1431+
utxo
14281432
txbodycontent1
14291433
{ txFee = TxFeeExplicit sbe maxLovelaceFee
14301434
, txOuts =
@@ -1472,6 +1476,7 @@ makeTransactionBodyAutoBalance
14721476
first TxBodyError $ -- TODO: impossible to fail now
14731477
createTransactionBody
14741478
sbe
1479+
utxo
14751480
txbodycontent1
14761481
{ txFee = TxFeeExplicit sbe fee
14771482
, txReturnCollateral = retColl
@@ -1504,7 +1509,7 @@ makeTransactionBodyAutoBalance
15041509
first TxBodyError $ -- TODO: impossible to fail now. We need to implement a function
15051510
-- that simply creates a transaction body because we have already
15061511
-- validated the transaction body earlier within makeTransactionBodyAutoBalance
1507-
createTransactionBody sbe finalTxBodyContent
1512+
createTransactionBody sbe utxo finalTxBodyContent
15081513
return
15091514
( BalancedTxBody
15101515
finalTxBodyContent

0 commit comments

Comments
 (0)