@@ -146,27 +146,28 @@ module Cardano.Api.Experimental.Tx
146146 )
147147where
148148
149- import Cardano.Api.Era.Internal.Core (ToCardanoEra (toCardanoEra ), forEraInEon )
150- import Cardano.Api.Era.Internal.Eon.Convert
149+ import Cardano.Api.Era.Internal.Core qualified as Api
151150import Cardano.Api.Era.Internal.Eon.ShelleyBasedEra
152- import Cardano.Api.Era.Internal.Feature
153151import Cardano.Api.Experimental.Era
154152import Cardano.Api.Experimental.Tx.Internal.AnyWitness
155- import Cardano.Api.Experimental.Tx.Internal.Body
153+ import Cardano.Api.Experimental.Tx.Internal.BodyContent.Old
154+ ( extractAllIndexedPlutusScriptWitnesses
155+ , makeUnsignedTx
156+ )
156157import Cardano.Api.Experimental.Tx.Internal.TxScriptWitnessRequirements
158+ import Cardano.Api.Experimental.Tx.Internal.Type
157159import Cardano.Api.HasTypeProxy (HasTypeProxy (.. ), Proxy , asType )
158- import Cardano.Api.Ledger.Internal.Reexport (StrictMaybe (.. ), maybeToStrictMaybe )
159160import Cardano.Api.Ledger.Internal.Reexport qualified as L
160161import Cardano.Api.Pretty (docToString , pretty )
162+ import Cardano.Api.ProtocolParameters
161163import Cardano.Api.Serialise.Raw
162164 ( SerialiseAsRawBytes (.. )
163165 , SerialiseAsRawBytesError (SerialiseAsRawBytesError )
164166 )
165- import Cardano.Api.Tx.Internal.Body
166167import Cardano.Api.Tx.Internal.Sign
167168
168169import Cardano.Crypto.Hash qualified as Hash
169- import Cardano.Ledger.Alonzo.TxBody qualified as L
170+ import Cardano.Ledger.Alonzo.Tx qualified as L
170171import Cardano.Ledger.Api qualified as L
171172import Cardano.Ledger.Binary qualified as Ledger
172173import Cardano.Ledger.Core qualified as Ledger
@@ -176,150 +177,11 @@ import Control.Exception (displayException)
176177import Data.Bifunctor (bimap )
177178import Data.ByteString.Lazy (fromStrict )
178179import Data.Set qualified as Set
179- import GHC.Exts (IsList (.. ))
180180import GHC.Stack
181181import Lens.Micro
182182
183- -- | A transaction that can contain everything
184- -- except key witnesses.
185- data UnsignedTx era
186- = L. EraTx (LedgerEra era ) => UnsignedTx (Ledger. Tx (LedgerEra era ))
187-
188- instance HasTypeProxy era => HasTypeProxy (UnsignedTx era ) where
189- data AsType (UnsignedTx era ) = AsUnsignedTx (AsType era )
190- proxyToAsType :: Proxy (UnsignedTx era ) -> AsType (UnsignedTx era )
191- proxyToAsType _ = AsUnsignedTx (asType @ era )
192-
193- instance
194- ( HasTypeProxy era
195- , L. EraTx (LedgerEra era )
196- )
197- => SerialiseAsRawBytes (UnsignedTx era )
198- where
199- serialiseToRawBytes (UnsignedTx tx) =
200- Ledger. serialize' (Ledger. eraProtVerHigh @ (LedgerEra era )) tx
201- deserialiseFromRawBytes _ =
202- bimap wrapError UnsignedTx
203- . Ledger. decodeFullAnnotator
204- (Ledger. eraProtVerHigh @ (LedgerEra era ))
205- " UnsignedTx"
206- Ledger. decCBOR
207- . fromStrict
208- where
209- wrapError
210- :: Ledger. DecoderError -> SerialiseAsRawBytesError
211- wrapError = SerialiseAsRawBytesError . displayException
212-
213- deriving instance Eq (UnsignedTx era )
214-
215- deriving instance Show (UnsignedTx era )
216-
217183newtype UnsignedTxError
218- = UnsignedTxError TxBodyError
219-
220- makeUnsignedTx
221- :: Era era
222- -> TxBodyContent BuildTx era
223- -> Either TxBodyError (UnsignedTx era )
224- makeUnsignedTx DijkstraEra _ = error " makeUnsignedTx: Dijkstra era not supported yet"
225- makeUnsignedTx era@ ConwayEra bc = obtainCommonConstraints era $ do
226- let sbe = convert era
227- aeon = convert era
228- TxScriptWitnessRequirements languages scripts datums redeemers <-
229- shelleyBasedEraConstraints sbe $
230- collectTxBodyScriptWitnessRequirements (convert era) bc
231-
232- -- cardano-api types
233- let apiTxOuts = txOuts bc
234- apiScriptValidity = txScriptValidity bc
235- apiMintValue = txMintValue bc
236- apiProtocolParameters = txProtocolParams bc
237- apiCollateralTxIns = txInsCollateral bc
238- apiReferenceInputs = txInsReference bc
239- apiExtraKeyWitnesses = txExtraKeyWits bc
240- apiReturnCollateral = txReturnCollateral bc
241- apiTotalCollateral = txTotalCollateral bc
242-
243- -- Ledger types
244- txins = convTxIns $ txIns bc
245- collTxIns = convCollateralTxIns apiCollateralTxIns
246- refTxIns = convReferenceInputs apiReferenceInputs
247- outs = convTxOuts sbe apiTxOuts
248- fee = convTransactionFee sbe $ txFee bc
249- withdrawals = convWithdrawals $ txWithdrawals bc
250- returnCollateral = convReturnCollateral sbe apiReturnCollateral
251- totalCollateral = convTotalCollateral apiTotalCollateral
252- certs = convCertificates sbe $ txCertificates bc
253- txAuxData = toAuxiliaryData sbe (txMetadata bc) (txAuxScripts bc)
254- scriptIntegrityHash =
255- convPParamsToScriptIntegrityHash
256- aeon
257- apiProtocolParameters
258- redeemers
259- datums
260- languages
261-
262- let setMint = convMintValue apiMintValue
263- setReqSignerHashes = convExtraKeyWitnesses apiExtraKeyWitnesses
264- ledgerTxBody =
265- L. mkBasicTxBody
266- & L. inputsTxBodyL .~ txins
267- & L. collateralInputsTxBodyL .~ collTxIns
268- & L. referenceInputsTxBodyL .~ refTxIns
269- & L. outputsTxBodyL .~ outs
270- & L. totalCollateralTxBodyL .~ totalCollateral
271- & L. collateralReturnTxBodyL .~ returnCollateral
272- & L. feeTxBodyL .~ fee
273- & L. vldtTxBodyL . L. invalidBeforeL .~ convValidityLowerBound (txValidityLowerBound bc)
274- & L. vldtTxBodyL . L. invalidHereAfterL .~ convValidityUpperBound sbe (txValidityUpperBound bc)
275- & L. reqSignerHashesTxBodyL .~ setReqSignerHashes
276- & L. scriptIntegrityHashTxBodyL .~ scriptIntegrityHash
277- & L. withdrawalsTxBodyL .~ withdrawals
278- & L. certsTxBodyL .~ certs
279- & L. mintTxBodyL .~ setMint
280- & L. auxDataHashTxBodyL .~ maybe SNothing (SJust . Ledger. hashTxAuxData) txAuxData
281-
282- scriptWitnesses =
283- L. mkBasicTxWits
284- & L. scriptTxWitsL
285- .~ fromList
286- [ (L. hashScript sw, sw)
287- | sw <- scripts
288- ]
289- & L. datsTxWitsL .~ datums
290- & L. rdmrsTxWitsL .~ redeemers
291-
292- let eraSpecificTxBody = eraSpecificLedgerTxBody era ledgerTxBody bc
293-
294- return . UnsignedTx $
295- L. mkBasicTx eraSpecificTxBody
296- & L. witsTxL .~ scriptWitnesses
297- & L. auxDataTxL .~ maybeToStrictMaybe (toAuxiliaryData sbe (txMetadata bc) (txAuxScripts bc))
298- & L. isValidTxL .~ txScriptValidityToIsValid apiScriptValidity
299-
300- eraSpecificLedgerTxBody
301- :: Era era
302- -> Ledger. TxBody (LedgerEra era )
303- -> TxBodyContent BuildTx era
304- -> Ledger. TxBody (LedgerEra era )
305- eraSpecificLedgerTxBody era ledgerbody bc =
306- body era
307- where
308- body e =
309- let propProcedures = txProposalProcedures bc
310- voteProcedures = txVotingProcedures bc
311- treasuryDonation = txTreasuryDonation bc
312- currentTresuryValue = txCurrentTreasuryValue bc
313- in obtainCommonConstraints e $
314- ledgerbody
315- & L. proposalProceduresTxBodyL
316- .~ convProposalProcedures (maybe TxProposalProceduresNone unFeatured propProcedures)
317- & L. votingProceduresTxBodyL
318- .~ convVotingProcedures (maybe TxVotingProceduresNone unFeatured voteProcedures)
319- & L. treasuryDonationTxBodyL
320- .~ maybe (L. Coin 0 ) unFeatured treasuryDonation
321- & L. currentTreasuryValueTxBodyL
322- .~ L. maybeToStrictMaybe (unFeatured =<< currentTresuryValue)
184+ = UnsignedTxError String
323185
324186hashTxBody
325187 :: L. HashAnnotated (Ledger. TxBody era ) L. EraIndependentTxBody
@@ -398,8 +260,8 @@ signTx era bootstrapWits shelleyKeyWits (UnsignedTx unsigned) =
398260convertTxBodyToUnsignedTx
399261 :: HasCallStack => ShelleyBasedEra era -> TxBody era -> UnsignedTx era
400262convertTxBodyToUnsignedTx sbe txbody =
401- forEraInEon
402- (toCardanoEra sbe)
263+ Api. forEraInEon
264+ (Api. toCardanoEra sbe)
403265 (error $ " convertTxBodyToUnsignedTx: Error - unsupported era " <> docToString (pretty sbe))
404266 ( \ w -> do
405267 let ShelleyTx _ unsignedLedgerTx = makeSignedTransaction [] txbody
0 commit comments