@@ -49,15 +49,15 @@ module Cardano.Node.Emulator.Generators(
4949 splitVal ,
5050 validateMockchain ,
5151 signAll ,
52- signTx ,
5352 CW. knownAddresses ,
5453 CW. knownPaymentPublicKeys ,
5554 CW. knownPaymentPrivateKeys ,
5655 CW. knownPaymentKeys ,
5756 knownXPrvs ,
5857 alwaysSucceedPolicy ,
5958 alwaysSucceedPolicyId ,
60- someTokenValue
59+ someTokenValue ,
60+ emptyTxBodyContent
6161 ) where
6262
6363import Control.Monad (guard , replicateM )
@@ -86,15 +86,14 @@ import Cardano.Crypto.Wallet qualified as Crypto
8686import Cardano.Node.Emulator.Params (Params (pSlotConfig ))
8787import Cardano.Node.Emulator.TimeSlot (SlotConfig )
8888import Cardano.Node.Emulator.TimeSlot qualified as TimeSlot
89- import Cardano.Node.Emulator.Validation (fromPlutusTxSigned , validateCardanoTx )
89+ import Cardano.Node.Emulator.Validation (validateCardanoTx )
9090import Control.Lens.Lens ((<&>) )
9191import Data.Functor (($>) )
9292import Data.String (fromString )
9393import Gen.Cardano.Api.Typed (genTxIn )
94- import Ledger (CardanoTx (CardanoApiTx ), Interval , MintingPolicy (getMintingPolicy ),
94+ import Ledger (CardanoTx (CardanoEmulatorEraTx ), Interval , MintingPolicy (getMintingPolicy ),
9595 POSIXTime (POSIXTime , getPOSIXTime ), POSIXTimeRange , Passphrase (Passphrase ),
9696 PaymentPrivateKey (unPaymentPrivateKey ), PaymentPubKey , Slot (Slot ), SlotRange ,
97- SomeCardanoApiTx (CardanoApiEmulatorEraTx ),
9897 TxInType (ConsumePublicKeyAddress , ConsumeSimpleScriptAddress , ScriptAddress ), TxInput , TxInputType ,
9998 TxOut , TxOutRef (TxOutRef ), ValidationErrorInPhase , addCardanoTxSignature , maxFee , minAdaTxOutEstimated ,
10099 minLovelaceTxOutEstimated , pubKeyTxOut , txOutValue , validatorHash )
@@ -163,11 +162,10 @@ genMockchain' gm = do
163162 slotCfg <- genSlotConfig
164163 (txn, ot) <- genInitialTransaction gm
165164 let params = def { pSlotConfig = slotCfg }
166- signedTx = signTx params mempty txn
167165 -- There is a problem that txId of emulator tx and tx of cardano tx are different.
168166 -- We convert the emulator tx to cardano tx here to get the correct transaction id
169167 -- because later we anyway will use the converted cardano tx so the utxo should match it.
170- tid = Tx. getCardanoTxId signedTx
168+ tid = Tx. getCardanoTxId txn
171169 pure Mockchain {
172170 mockchainInitialTxPool = [txn],
173171 mockchainUtxo = Map. fromList $ first (TxOutRef tid) <$> zip [0 .. ] ot,
@@ -188,6 +186,27 @@ genInitialTransaction g = do
188186 (body, o) <- initialTxBody g
189187 (,o) <$> makeTx body
190188
189+ emptyTxBodyContent :: C. TxBodyContent C. BuildTx C. BabbageEra
190+ emptyTxBodyContent = C. TxBodyContent
191+ { txIns = []
192+ , txInsCollateral = C. TxInsCollateralNone
193+ , txMintValue = C. TxMintNone
194+ , txFee = C. toCardanoFee 0
195+ , txOuts = []
196+ , txProtocolParams = C. BuildTxWith $ Just $ C. fromLedgerPParams C. ShelleyBasedEraBabbage def
197+ , txInsReference = C. TxInsReferenceNone
198+ , txTotalCollateral = C. TxTotalCollateralNone
199+ , txReturnCollateral = C. TxReturnCollateralNone
200+ , txValidityRange = ( C. TxValidityNoLowerBound
201+ , C. TxValidityNoUpperBound C. ValidityNoUpperBoundInBabbageEra )
202+ , txScriptValidity = C. TxScriptValidityNone
203+ , txExtraKeyWits = C. TxExtraKeyWitnessesNone
204+ , txMetadata = C. TxMetadataNone
205+ , txAuxScripts = C. TxAuxScriptsNone
206+ , txWithdrawals = C. TxWithdrawalsNone
207+ , txCertificates = C. TxCertificatesNone
208+ , txUpdateProposal = C. TxUpdateProposalNone
209+ }
191210
192211initialTxBody ::
193212 GeneratorModel
@@ -198,27 +217,9 @@ initialTxBody GeneratorModel{..} = do
198217 -- we use a generated tx in input it's unbalanced but it's "fine" as we don't validate this tx
199218 txIns <- map (, C. BuildTxWith (C. KeyWitness C. KeyWitnessForSpending ))
200219 <$> Gen. list (Range. constant 1 10 ) genTxIn
201- pure (C. TxBodyContent
202- { txIns
203- , txInsCollateral = C. TxInsCollateralNone
204- , txMintValue = C. TxMintNone
205- , txFee = C. toCardanoFee 0
206- , txOuts = Tx. getTxOut <$> o
207- -- unused:
208- , txProtocolParams = C. BuildTxWith $ Just $ C. fromLedgerPParams C. ShelleyBasedEraBabbage def
209- , txInsReference = C. TxInsReferenceNone
210- , txTotalCollateral = C. TxTotalCollateralNone
211- , txReturnCollateral = C. TxReturnCollateralNone
212- , txValidityRange = ( C. TxValidityNoLowerBound
213- , C. TxValidityNoUpperBound C. ValidityNoUpperBoundInBabbageEra )
214- , txScriptValidity = C. TxScriptValidityNone
215- , txExtraKeyWits = C. TxExtraKeyWitnessesNone
216- , txMetadata = C. TxMetadataNone
217- , txAuxScripts = C. TxAuxScriptsNone
218- , txWithdrawals = C. TxWithdrawalsNone
219-
220- , txCertificates = C. TxCertificatesNone
221- , txUpdateProposal = C. TxUpdateProposalNone
220+ pure (emptyTxBodyContent
221+ { C. txIns
222+ , C. txOuts = Tx. getTxOut <$> o
222223 }, o)
223224
224225-- | Generate a valid transaction, using the unspent outputs provided.
@@ -269,7 +270,7 @@ makeTx
269270 -> m CardanoTx
270271makeTx bodyContent = do
271272 txBody <- either (fail . (" Can't create TxBody" <> ) . show ) pure $ C. makeTransactionBody bodyContent
272- pure $ signAll $ CardanoApiTx $ CardanoApiEmulatorEraTx $ C. Tx txBody []
273+ pure $ signAll $ CardanoEmulatorEraTx $ C. Tx txBody []
273274
274275-- | Generate a valid transaction, using the unspent outputs provided.
275276-- Fails if the there are no unspent outputs, or if the total value
@@ -333,27 +334,12 @@ genValidTransactionBodySpending' g ins totalVal = do
333334 (fail " Cannot gen collateral" )
334335 (failOnCardanoError . (C. toCardanoTxInsCollateral . map toTxInput . flip take ins . fromIntegral ))
335336 (gmMaxCollateralInputs g)
336- pure $ C. TxBodyContent
337- { txIns
338- , txInsCollateral
339- , txMintValue
340- , txFee = C. toCardanoFee fee'
341- , txOuts = Tx. getTxOut <$> txOutputs
342- -- unused:
343- , txProtocolParams = C. BuildTxWith $ Just $ C. fromLedgerPParams C. ShelleyBasedEraBabbage def
344- , txInsReference = C. TxInsReferenceNone
345- , txTotalCollateral = C. TxTotalCollateralNone
346- , txReturnCollateral = C. TxReturnCollateralNone
347- , txValidityRange = ( C. TxValidityNoLowerBound
348- , C. TxValidityNoUpperBound C. ValidityNoUpperBoundInBabbageEra )
349- , txScriptValidity = C. TxScriptValidityNone
350- , txExtraKeyWits = C. TxExtraKeyWitnessesNone
351- , txMetadata = C. TxMetadataNone
352- , txAuxScripts = C. TxAuxScriptsNone
353- , txWithdrawals = C. TxWithdrawalsNone
354-
355- , txCertificates = C. TxCertificatesNone
356- , txUpdateProposal = C. TxUpdateProposalNone
337+ pure $ emptyTxBodyContent
338+ { C. txIns
339+ , C. txInsCollateral
340+ , C. txMintValue
341+ , C. txFee = C. toCardanoFee fee'
342+ , C. txOuts = Tx. getTxOut <$> txOutputs
357343 }
358344 where
359345 -- | Translate TxIn to TxInput taking out data witnesses if present.
@@ -379,18 +365,11 @@ genValidTransactionBodySpending' g ins totalVal = do
379365 toTxInType Tx. ConsumePublicKeyAddress = Tx. TxConsumePublicKeyAddress
380366 toTxInType (Tx. ScriptAddress valOrRef rd dat) = Tx. TxScriptAddress rd (first validatorHash valOrRef) $ fmap datumHash dat
381367
382- signTx :: Params -> Map TxOutRef TxOut -> CardanoTx -> CardanoTx
383- signTx params utxo = let
384- cUtxoIndex = either (error . show ) id $ fromPlutusIndex (Index. UtxoIndex utxo)
385- in Tx. onCardanoTx
386- (\ t -> fromPlutusTxSigned params cUtxoIndex t CW. knownPaymentKeys)
387- Tx. CardanoApiTx
388-
389368-- | Validate a transaction in a mockchain.
390369validateMockchain :: Mockchain -> CardanoTx -> Maybe Ledger. ValidationErrorInPhase
391370validateMockchain (Mockchain _ utxo params) tx = result where
392371 cUtxoIndex = either (error . show ) id $ fromPlutusIndex (Index. UtxoIndex utxo)
393- result = leftToMaybe $ validateCardanoTx params 1 cUtxoIndex (signTx params utxo tx)
372+ result = leftToMaybe $ validateCardanoTx params 1 cUtxoIndex tx
394373
395374-- | Generate an 'Interval where the lower bound if less or equal than the
396375-- upper bound.
0 commit comments