@@ -9,20 +9,25 @@ module Cardano.CLI.Tx
9
9
, NewTxFile (.. )
10
10
, prettyAddress
11
11
, readByronTx
12
+ , normalByronTxToGenTx
12
13
, txSpendGenesisUTxOByronPBFT
13
14
, issueGenesisUTxOExpenditure
14
15
, txSpendUTxOByronPBFT
15
16
, issueUTxOExpenditure
16
17
, nodeSubmitTx
18
+
19
+ -- TODO: remove when they are exported from the ledger
20
+ , fromCborTxAux
21
+ , toCborTxAux
17
22
)
18
23
where
19
24
20
- import Prelude (error , show )
21
- import Cardano.Prelude hiding (option , show , trace , (%) )
25
+ import Prelude (error )
26
+ import Cardano.Prelude hiding (option , trace , (%) )
22
27
23
- import Codec.Serialise (deserialiseOrFail )
24
- import Control.Monad.Trans.Except.Extra (left , right )
28
+ import Control.Monad.Trans.Except.Extra (right )
25
29
import qualified Data.ByteString.Lazy as LB
30
+ import qualified Data.ByteString as B
26
31
import qualified Data.Map.Strict as Map
27
32
import Data.String (IsString )
28
33
import Data.Text (Text )
@@ -31,10 +36,11 @@ import Formatting ((%), sformat)
31
36
32
37
import Control.Tracer (traceWith , stdoutTracer )
33
38
39
+ import qualified Cardano.Binary as Binary
40
+
34
41
import Cardano.Chain.Common (Address )
35
42
import qualified Cardano.Chain.Common as Common
36
43
import Cardano.Chain.Genesis as Genesis
37
- import qualified Cardano.Chain.MempoolPayload as CC.Mempool
38
44
import Cardano.Chain.UTxO ( mkTxAux , annotateTxAux
39
45
, Tx (.. ), TxId , TxIn , TxOut )
40
46
import qualified Cardano.Chain.UTxO as UTxO
@@ -77,9 +83,14 @@ prettyAddress addr = sformat
77
83
readByronTx :: TxFile -> IO (GenTx ByronBlock )
78
84
readByronTx (TxFile fp) = do
79
85
txBS <- LB. readFile fp
80
- case deserialiseOrFail txBS of
86
+ case fromCborTxAux txBS of
81
87
Left e -> throwIO $ TxDeserialisationFailed fp e
82
- Right tx -> pure tx
88
+ Right tx -> pure (normalByronTxToGenTx tx)
89
+
90
+ -- | The 'GenTx' is all the kinds of transactions that can be submitted
91
+ -- and \"normal\" Byron transactions are just one of the kinds.
92
+ normalByronTxToGenTx :: UTxO. ATxAux ByteString -> GenTx ByronBlock
93
+ normalByronTxToGenTx tx' = Byron. ByronTx (Byron. byronIdTx tx') tx'
83
94
84
95
-- | Given a Tx id, produce a UTxO Tx input witness, by signing it
85
96
-- with respect to a given protocol magic.
@@ -139,10 +150,9 @@ txSpendGenesisUTxOByronPBFT
139
150
-> SigningKey
140
151
-> Address
141
152
-> NonEmpty TxOut
142
- -> GenTx ByronBlock
153
+ -> UTxO. ATxAux ByteString
143
154
txSpendGenesisUTxOByronPBFT gc sk genAddr outs =
144
- Byron. fromMempoolPayload
145
- $ CC.Mempool. MempoolTx $ annotateTxAux $ mkTxAux tx (pure wit)
155
+ annotateTxAux $ mkTxAux tx (pure wit)
146
156
where
147
157
tx = UnsafeTx (pure txIn) outs txattrs
148
158
@@ -167,7 +177,7 @@ issueGenesisUTxOExpenditure
167
177
-> Update
168
178
-> Protocol
169
179
-> Crypto. SigningKey
170
- -> ExceptT RealPBFTError IO (GenTx ByronBlock )
180
+ -> ExceptT RealPBFTError IO (UTxO. ATxAux ByteString )
171
181
issueGenesisUTxOExpenditure
172
182
genRichAddr
173
183
outs
@@ -182,14 +192,9 @@ issueGenesisUTxOExpenditure
182
192
sk =
183
193
withRealPBFT gHash genFile nMagic sigThresh delCertFp sKeyFp update ptcl
184
194
$ \ (Consensus. ProtocolRealPBFT gc _ _ _ _)-> do
185
- case txSpendGenesisUTxOByronPBFT gc sk genRichAddr outs of
186
- tx@ (ByronTx txid _) -> do
187
- putStrLn $ sformat (" TxId: " % Crypto. hashHexF) txid
188
- right tx
189
- x -> left . InvariantViolation
190
- . T. pack
191
- $ " A non-ByronTx GenTx out of 'txSpendUTxOByronPBFT': "
192
- <> show x
195
+ let tx = txSpendGenesisUTxOByronPBFT gc sk genRichAddr outs
196
+ traceWith stdoutTracer (" TxId: " ++ condense (Byron. byronIdTx tx))
197
+ right tx
193
198
194
199
-- | Generate a transaction from given Tx inputs to outputs,
195
200
-- signed by the given key.
@@ -198,10 +203,9 @@ txSpendUTxOByronPBFT
198
203
-> SigningKey
199
204
-> NonEmpty TxIn
200
205
-> NonEmpty TxOut
201
- -> GenTx ByronBlock
206
+ -> UTxO. ATxAux ByteString
202
207
txSpendUTxOByronPBFT gc sk ins outs =
203
- Byron. fromMempoolPayload
204
- $ CC.Mempool. MempoolTx $ annotateTxAux $ mkTxAux tx (pure wit)
208
+ annotateTxAux $ mkTxAux tx (pure wit)
205
209
where
206
210
tx = UnsafeTx ins outs txattrs
207
211
@@ -223,7 +227,7 @@ issueUTxOExpenditure
223
227
-> Update
224
228
-> Protocol
225
229
-> Crypto. SigningKey
226
- -> ExceptT RealPBFTError IO (GenTx ByronBlock )
230
+ -> ExceptT RealPBFTError IO (UTxO. ATxAux ByteString )
227
231
issueUTxOExpenditure
228
232
ins
229
233
outs
@@ -238,15 +242,9 @@ issueUTxOExpenditure
238
242
key = do
239
243
withRealPBFT gHash genFile nMagic sigThresh delCertFp sKeyFp update ptcl $
240
244
\ (Consensus. ProtocolRealPBFT gc _ _ _ _)-> do
241
- case txSpendUTxOByronPBFT gc key ins outs of
242
- tx@ (ByronTx txid _) -> do
243
- putStrLn $ sformat (" TxId: " % Crypto. hashHexF) txid
244
- pure tx
245
- x ->
246
- left . InvariantViolation
247
- . T. pack
248
- $ " A non-ByronTx GenTx out of 'txSpendUTxOByronPBFT': "
249
- <> show x
245
+ let tx = txSpendUTxOByronPBFT gc key ins outs
246
+ traceWith stdoutTracer (" TxId: " ++ condense (Byron. byronIdTx tx))
247
+ pure tx
250
248
251
249
-- | Submit a transaction to a node specified by topology info.
252
250
nodeSubmitTx
@@ -283,3 +281,17 @@ nodeSubmitTx
283
281
(node topology)
284
282
gentx
285
283
stdoutTracer
284
+
285
+ -- TODO: remove these local definitions when the updated ledger lib is available
286
+ fromCborTxAux :: LB. ByteString -> Either Binary. DecoderError (UTxO. ATxAux B. ByteString )
287
+ fromCborTxAux lbs =
288
+ fmap (annotationBytes lbs)
289
+ $ Binary. decodeFullDecoder " Cardano.Chain.UTxO.TxAux.fromCborTxAux"
290
+ Binary. fromCBOR lbs
291
+ where
292
+ annotationBytes :: Functor f => LB. ByteString -> f Binary. ByteSpan -> f B. ByteString
293
+ annotationBytes bytes = fmap (LB. toStrict . Binary. slice bytes)
294
+
295
+ toCborTxAux :: UTxO. ATxAux ByteString -> LB. ByteString
296
+ toCborTxAux = LB. fromStrict . UTxO. aTaAnnotation -- The ByteString anotation is the CBOR encoded version.
297
+
0 commit comments