@@ -10,9 +10,10 @@ module Testnet.Process.Cli.Transaction
10
10
, retrieveTransactionId
11
11
, SignedTx
12
12
, TxBody
13
- , TxOutAddress (.. )
13
+ , TxOutAddress (.. )
14
14
, VoteFile
15
- ) where
15
+ )
16
+ where
16
17
17
18
import Cardano.Api hiding (Certificate , TxBody )
18
19
import Cardano.Api.Experimental (Some (.. ))
@@ -29,83 +30,93 @@ import GHC.IO.Exception (ExitCode (..))
29
30
import GHC.Stack
30
31
import System.FilePath ((</>) )
31
32
33
+ import Hedgehog (MonadTest )
34
+ import qualified Hedgehog.Extras as H
35
+
32
36
import Testnet.Components.Query (EpochStateView , findLargestUtxoForPaymentKey )
33
37
import Testnet.Process.Run (execCli' )
34
38
import Testnet.Start.Types (anyEraToString )
35
39
import Testnet.Types
36
40
37
- import Hedgehog (MonadTest )
38
- import qualified Hedgehog.Extras as H
39
-
40
41
-- Transaction signing
41
42
data VoteFile
42
43
43
44
data TxBody
44
45
45
46
data SignedTx
46
47
47
- data ReferenceScriptJSON
48
+ data ScriptJSON
48
49
49
- data TxOutAddress = PubKeyAddress PaymentKeyInfo
50
- | ReferenceScriptAddress ( File ReferenceScriptJSON In )
51
- -- ^ The output will be created at the script address
52
- -- and the output will include the reference script.
50
+ data TxOutAddress
51
+ = PubKeyAddress PaymentKeyInfo
52
+ | -- | The output will be created at the script address.
53
+ ScriptAddress ( File ScriptJSON In )
53
54
54
55
-- | Calls @cardano-cli@ to build a simple ADA transfer transaction to
55
- -- the specified outputs of the specified amount of ADA. In the case of
56
- -- a reference script address, the output will be created at the
57
- -- corresponding script address, and the output will contain the reference
58
- -- script.
56
+ -- the specified outputs of the specified amount of ADA. Destination
57
+ -- address may be specified as a 'PaymentKeyInfo' or with a script file.
58
+ -- For each output, an extra optional script file may be provided, and
59
+ -- if provided, the script provided will be published in that output
60
+ -- as a reference script.
59
61
--
60
62
-- Returns the generated @File TxBody In@ file path to the created unsigned
61
63
-- transaction file.
62
64
mkSpendOutputsOnlyTx
63
- :: HasCallStack
64
- => Typeable era
65
- => H. MonadAssertion m
66
- => MonadTest m
67
- => MonadCatch m
68
- => MonadIO m
69
- => H. ExecConfig -- ^ Specifies the CLI execution configuration.
70
- -> EpochStateView -- ^ Current epoch state view for transaction building. It can be obtained
71
- -- using the 'getEpochStateView' function.
72
- -> ShelleyBasedEra era -- ^ Witness for the current Cardano era.
73
- -> FilePath -- ^ Base directory path where the unsigned transaction file will be stored.
74
- -> String -- ^ Prefix for the output unsigned transaction file name. The extension will be @.txbody@.
75
- -> PaymentKeyInfo -- ^ Payment key pair used for paying the transaction.
76
- -> [(TxOutAddress , Coin )] -- ^ List of pairs of transaction output addresses and amounts.
65
+ :: (HasCallStack , Typeable era , H. MonadAssertion m , MonadTest m , MonadCatch m , MonadIO m )
66
+ => H. ExecConfig
67
+ -- ^ Specifies the CLI execution configuration.
68
+ -> EpochStateView
69
+ -- ^ Current epoch state view for transaction building. It can be obtained
70
+ -- using the 'getEpochStateView' function.
71
+ -> ShelleyBasedEra era
72
+ -- ^ Witness for the current Cardano era.
73
+ -> FilePath
74
+ -- ^ Base directory path where the unsigned transaction file will be stored.
75
+ -> String
76
+ -- ^ Prefix for the output unsigned transaction file name. The extension will be @.txbody@.
77
+ -> PaymentKeyInfo
78
+ -- ^ Payment key pair used for paying the transaction.
79
+ -> [(TxOutAddress , Coin , Maybe (File ScriptJSON In ))]
80
+ -- ^ List of tuples with transaction output addresses, amounts, and reference scripts.
77
81
-> m (File TxBody In )
78
82
mkSpendOutputsOnlyTx execConfig epochStateView sbe work prefix srcWallet txOutputs = do
79
-
80
83
txIn <- findLargestUtxoForPaymentKey epochStateView sbe srcWallet
81
84
fixedTxOuts :: [String ] <- computeTxOuts
82
- void $ execCli' execConfig $ mconcat
83
- [ [ anyEraToString cEra, " transaction" , " build"
84
- , " --change-address" , srcAddress
85
- , " --tx-in" , T. unpack $ renderTxIn txIn
86
- ]
87
- , fixedTxOuts
88
- , [ " --out-file" , unFile txBody
89
- ]
90
- ]
85
+ void $ execCli' execConfig $
86
+ mconcat
87
+ [ [ anyEraToString cEra
88
+ , " transaction" , " build"
89
+ , " --change-address" , srcAddress
90
+ , " --tx-in" , T. unpack $ renderTxIn txIn
91
+ ]
92
+ , fixedTxOuts
93
+ , [ " --out-file" , unFile txBody
94
+ ]
95
+ ]
91
96
return txBody
92
- where
93
- era = toCardanoEra sbe
94
- cEra = AnyCardanoEra era
95
- txBody = File (work </> prefix <> " .txbody" )
96
- srcAddress = T. unpack $ paymentKeyInfoAddr srcWallet
97
- computeTxOuts = concat <$> sequence
97
+ where
98
+ era = toCardanoEra sbe
99
+ cEra = AnyCardanoEra era
100
+ txBody = File (work </> prefix <> " .txbody" )
101
+ srcAddress = T. unpack $ paymentKeyInfoAddr srcWallet
102
+ computeTxOuts =
103
+ concat <$> sequence
98
104
[ case txOut of
99
105
PubKeyAddress dstWallet ->
100
- return [" --tx-out" , T. unpack (paymentKeyInfoAddr dstWallet) <> " +" ++ show (unCoin amount) ]
101
- ReferenceScriptAddress (File referenceScriptJSON) -> do
102
- scriptAddress <- execCli' execConfig [ anyEraToString cEra, " address" , " build"
103
- , " --payment-script-file" , referenceScriptJSON
104
- ]
105
- return [ " --tx-out" , scriptAddress <> " +" ++ show (unCoin amount)
106
- , " --tx-out-reference-script-file" , referenceScriptJSON
107
- ]
108
- | (txOut, amount) <- txOutputs
106
+ return [" --tx-out" , T. unpack (paymentKeyInfoAddr dstWallet) <> " +" ++ show (unCoin amount)]
107
+ ScriptAddress (File referenceScriptJSON) -> do
108
+ scriptAddress <-
109
+ execCli'
110
+ execConfig
111
+ [ anyEraToString cEra
112
+ , " address" , " build"
113
+ , " --payment-script-file" , referenceScriptJSON
114
+ ]
115
+ return
116
+ ( [" --tx-out" , scriptAddress <> " +" ++ show (unCoin amount)]
117
+ <> maybe [] (\ (File newRefScript) -> [" --tx-out-reference-script-file" , newRefScript]) mNewRefScript
118
+ )
119
+ | (txOut, amount, mNewRefScript) <- txOutputs
109
120
]
110
121
111
122
-- | Calls @cardano-cli@ to build a simple ADA transfer transaction to
@@ -131,7 +142,7 @@ mkSimpleSpendOutputsOnlyTx
131
142
-> Coin -- ^ Amount of ADA to transfer (in Lovelace).
132
143
-> m (File TxBody In )
133
144
mkSimpleSpendOutputsOnlyTx execConfig epochStateView sbe work prefix srcWallet dstWallet amount =
134
- mkSpendOutputsOnlyTx execConfig epochStateView sbe work prefix srcWallet [(PubKeyAddress dstWallet, amount)]
145
+ mkSpendOutputsOnlyTx execConfig epochStateView sbe work prefix srcWallet [(PubKeyAddress dstWallet, amount, Nothing )]
135
146
136
147
-- | Calls @cardano-cli@ to signs a transaction body using the specified key pairs.
137
148
--
0 commit comments