@@ -2,8 +2,8 @@ use std::{collections::HashMap, fmt::Debug};
2
2
3
3
use fuel_tx:: {
4
4
field:: {
5
- GasPrice , Inputs , Maturity , Outputs , Script as ScriptField , ScriptData , ScriptGasLimit ,
6
- Witnesses ,
5
+ GasPrice , Inputs , Maturity , MintAmount , MintAssetId , Outputs , Script as ScriptField ,
6
+ ScriptData , ScriptGasLimit , Witnesses ,
7
7
} ,
8
8
input:: {
9
9
coin:: { CoinPredicate , CoinSigned } ,
@@ -12,7 +12,7 @@ use fuel_tx::{
12
12
} ,
13
13
} ,
14
14
Buildable , Bytes32 , Cacheable , Chargeable , ConsensusParameters , Create , FormatValidityChecks ,
15
- Input , Output , Salt as FuelSalt , Script , StorageSlot , Transaction as FuelTransaction ,
15
+ Input , Mint , Output , Salt as FuelSalt , Script , StorageSlot , Transaction as FuelTransaction ,
16
16
TransactionFee , UniqueIdentifier , Witness ,
17
17
} ;
18
18
use fuel_types:: { AssetId , ChainId } ;
@@ -24,8 +24,56 @@ use crate::{
24
24
types:: { bech32:: Bech32Address , errors:: error, Result } ,
25
25
} ;
26
26
27
- #[ derive( Default , Debug , Copy , Clone ) ]
27
+ #[ derive( Default , Debug , Clone , PartialEq , Eq ) ]
28
+ pub struct MintTransaction {
29
+ tx : Box < Mint > ,
30
+ }
31
+
32
+ impl From < MintTransaction > for FuelTransaction {
33
+ fn from ( mint : MintTransaction ) -> Self {
34
+ ( * mint. tx ) . into ( )
35
+ }
36
+ }
37
+
38
+ impl From < MintTransaction > for Mint {
39
+ fn from ( tx : MintTransaction ) -> Self {
40
+ * tx. tx
41
+ }
42
+ }
43
+
44
+ impl From < Mint > for MintTransaction {
45
+ fn from ( tx : Mint ) -> Self {
46
+ Self { tx : Box :: new ( tx) }
47
+ }
48
+ }
49
+
50
+ impl MintTransaction {
51
+ pub fn check_without_signatures (
52
+ & self ,
53
+ block_height : u32 ,
54
+ consensus_parameters : & ConsensusParameters ,
55
+ ) -> Result < ( ) > {
56
+ Ok ( self
57
+ . tx
58
+ . check_without_signatures ( block_height. into ( ) , consensus_parameters) ?)
59
+ }
60
+ #[ must_use]
61
+ pub fn id ( & self , chain_id : ChainId ) -> Bytes32 {
62
+ self . tx . id ( & chain_id)
63
+ }
28
64
65
+ #[ must_use]
66
+ pub fn mint_asset_id ( & self ) -> & AssetId {
67
+ self . tx . mint_asset_id ( )
68
+ }
69
+
70
+ #[ must_use]
71
+ pub fn mint_amount ( & self ) -> u64 {
72
+ * self . tx . mint_amount ( )
73
+ }
74
+ }
75
+
76
+ #[ derive( Default , Debug , Copy , Clone ) ]
29
77
//ANCHOR: tx_policies_struct
30
78
pub struct TxPolicies {
31
79
gas_price : Option < u64 > ,
@@ -101,12 +149,13 @@ impl TxPolicies {
101
149
102
150
use fuel_tx:: field:: { BytecodeLength , BytecodeWitnessIndex , Salt , StorageSlots } ;
103
151
104
- use super :: coin_type_id:: CoinTypeId ;
152
+ use crate :: types :: coin_type_id:: CoinTypeId ;
105
153
106
154
#[ derive( Debug , Clone ) ]
107
155
pub enum TransactionType {
108
156
Script ( ScriptTransaction ) ,
109
157
Create ( CreateTransaction ) ,
158
+ Mint ( MintTransaction ) ,
110
159
}
111
160
112
161
pub trait EstimablePredicates {
@@ -171,149 +220,7 @@ impl From<TransactionType> for FuelTransaction {
171
220
match value {
172
221
TransactionType :: Script ( tx) => tx. into ( ) ,
173
222
TransactionType :: Create ( tx) => tx. into ( ) ,
174
- }
175
- }
176
- }
177
-
178
- impl EstimablePredicates for TransactionType {
179
- fn estimate_predicates ( & mut self , consensus_parameters : & ConsensusParameters ) -> Result < ( ) > {
180
- match self {
181
- TransactionType :: Script ( tx) => tx. estimate_predicates ( consensus_parameters) ,
182
- TransactionType :: Create ( tx) => tx. estimate_predicates ( consensus_parameters) ,
183
- }
184
- }
185
- }
186
-
187
- impl GasValidation for TransactionType {
188
- fn validate_gas ( & self , min_gas_price : u64 , gas_used : u64 ) -> Result < ( ) > {
189
- match self {
190
- TransactionType :: Script ( tx) => tx. validate_gas ( min_gas_price, gas_used) ,
191
- TransactionType :: Create ( tx) => tx. validate_gas ( min_gas_price, gas_used) ,
192
- }
193
- }
194
- }
195
-
196
- impl Transaction for TransactionType {
197
- fn fee_checked_from_tx (
198
- & self ,
199
- consensus_parameters : & ConsensusParameters ,
200
- ) -> Option < TransactionFee > {
201
- match self {
202
- TransactionType :: Script ( tx) => tx. fee_checked_from_tx ( consensus_parameters) ,
203
- TransactionType :: Create ( tx) => tx. fee_checked_from_tx ( consensus_parameters) ,
204
- }
205
- }
206
-
207
- fn max_gas ( & self , consensus_parameters : & ConsensusParameters ) -> u64 {
208
- match self {
209
- TransactionType :: Script ( tx) => tx. max_gas ( consensus_parameters) ,
210
- TransactionType :: Create ( tx) => tx. max_gas ( consensus_parameters) ,
211
- }
212
- }
213
-
214
- fn check_without_signatures (
215
- & self ,
216
- block_height : u32 ,
217
- consensus_parameters : & ConsensusParameters ,
218
- ) -> Result < ( ) > {
219
- match self {
220
- TransactionType :: Script ( tx) => {
221
- tx. check_without_signatures ( block_height, consensus_parameters)
222
- }
223
- TransactionType :: Create ( tx) => {
224
- tx. check_without_signatures ( block_height, consensus_parameters)
225
- }
226
- }
227
- }
228
-
229
- fn id ( & self , chain_id : ChainId ) -> Bytes32 {
230
- match self {
231
- TransactionType :: Script ( tx) => tx. id ( chain_id) ,
232
- TransactionType :: Create ( tx) => tx. id ( chain_id) ,
233
- }
234
- }
235
-
236
- fn maturity ( & self ) -> u32 {
237
- match self {
238
- TransactionType :: Script ( tx) => tx. maturity ( ) ,
239
- TransactionType :: Create ( tx) => tx. maturity ( ) ,
240
- }
241
- }
242
-
243
- fn with_maturity ( self , maturity : u32 ) -> Self {
244
- match self {
245
- TransactionType :: Script ( tx) => TransactionType :: Script ( tx. with_maturity ( maturity) ) ,
246
- TransactionType :: Create ( tx) => TransactionType :: Create ( tx. with_maturity ( maturity) ) ,
247
- }
248
- }
249
-
250
- fn gas_price ( & self ) -> u64 {
251
- match self {
252
- TransactionType :: Script ( tx) => tx. gas_price ( ) ,
253
- TransactionType :: Create ( tx) => tx. gas_price ( ) ,
254
- }
255
- }
256
-
257
- fn with_gas_price ( self , gas_price : u64 ) -> Self {
258
- match self {
259
- TransactionType :: Script ( tx) => TransactionType :: Script ( tx. with_gas_price ( gas_price) ) ,
260
- TransactionType :: Create ( tx) => TransactionType :: Create ( tx. with_gas_price ( gas_price) ) ,
261
- }
262
- }
263
-
264
- fn metered_bytes_size ( & self ) -> usize {
265
- match self {
266
- TransactionType :: Script ( tx) => tx. metered_bytes_size ( ) ,
267
- TransactionType :: Create ( tx) => tx. metered_bytes_size ( ) ,
268
- }
269
- }
270
-
271
- fn inputs ( & self ) -> & Vec < Input > {
272
- match self {
273
- TransactionType :: Script ( tx) => tx. inputs ( ) ,
274
- TransactionType :: Create ( tx) => tx. inputs ( ) ,
275
- }
276
- }
277
-
278
- fn outputs ( & self ) -> & Vec < Output > {
279
- match self {
280
- TransactionType :: Script ( tx) => tx. outputs ( ) ,
281
- TransactionType :: Create ( tx) => tx. outputs ( ) ,
282
- }
283
- }
284
-
285
- fn witnesses ( & self ) -> & Vec < Witness > {
286
- match self {
287
- TransactionType :: Script ( tx) => tx. witnesses ( ) ,
288
- TransactionType :: Create ( tx) => tx. witnesses ( ) ,
289
- }
290
- }
291
-
292
- fn is_using_predicates ( & self ) -> bool {
293
- match self {
294
- TransactionType :: Script ( tx) => tx. is_using_predicates ( ) ,
295
- TransactionType :: Create ( tx) => tx. is_using_predicates ( ) ,
296
- }
297
- }
298
-
299
- fn precompute ( & mut self , chain_id : & ChainId ) -> Result < ( ) > {
300
- match self {
301
- TransactionType :: Script ( tx) => tx. precompute ( chain_id) ,
302
- TransactionType :: Create ( tx) => tx. precompute ( chain_id) ,
303
- }
304
- }
305
-
306
- fn append_witness ( & mut self , witness : Witness ) -> usize {
307
- match self {
308
- TransactionType :: Script ( tx) => tx. append_witness ( witness) ,
309
- TransactionType :: Create ( tx) => tx. append_witness ( witness) ,
310
- }
311
- }
312
-
313
- fn used_coins ( & self ) -> HashMap < ( Bech32Address , AssetId ) , Vec < CoinTypeId > > {
314
- match self {
315
- TransactionType :: Script ( tx) => tx. used_coins ( ) ,
316
- TransactionType :: Create ( tx) => tx. used_coins ( ) ,
223
+ TransactionType :: Mint ( tx) => tx. into ( ) ,
317
224
}
318
225
}
319
226
}
0 commit comments