@@ -12,12 +12,7 @@ public struct EIP1559Envelope: EIP2718Envelope {
12
12
13
13
// common parameters for any transaction
14
14
public var nonce : BigUInt = 0
15
- public var chainID : BigUInt ? {
16
- get { return internalChainID }
17
- // swiftlint:disable force_unwrapping
18
- set ( newID) { if newID != nil { internalChainID = newID! } }
19
- // swiftlint:enable force_unwrapping
20
- }
15
+ public var chainID : BigUInt
21
16
public var to : EthereumAddress
22
17
public var value : BigUInt
23
18
public var data : Data
@@ -46,8 +41,6 @@ public struct EIP1559Envelope: EIP2718Envelope {
46
41
public var maxFeePerGas : BigUInt
47
42
public var accessList : [ AccessListEntry ] // from EIP-2930
48
43
49
- private var internalChainID : BigUInt
50
-
51
44
// for CustomStringConvertible
52
45
public var description : String {
53
46
var toReturn = " "
@@ -66,6 +59,35 @@ public struct EIP1559Envelope: EIP2718Envelope {
66
59
toReturn += " s: " + String( self . s) + " \n "
67
60
return toReturn
68
61
}
62
+
63
+ public var parameters : EthereumParameters {
64
+ get {
65
+ return EthereumParameters (
66
+ type: type,
67
+ to: to,
68
+ nonce: nonce,
69
+ chainID: chainID,
70
+ value: value,
71
+ data: data,
72
+ gasLimit: gasLimit,
73
+ maxFeePerGas: maxFeePerGas,
74
+ maxPriorityFeePerGas: maxPriorityFeePerGas,
75
+ accessList: accessList
76
+ )
77
+ }
78
+ set ( val) {
79
+ nonce = val. nonce ?? nonce
80
+ chainID = val. chainID ?? chainID
81
+ to = val. to ?? to
82
+ value = val. value ?? value
83
+ data = val. data ?? data
84
+ gasLimit = val. gasLimit ?? gasLimit
85
+ maxFeePerGas = val. maxFeePerGas ?? maxFeePerGas
86
+ maxPriorityFeePerGas = val. maxPriorityFeePerGas ?? maxPriorityFeePerGas
87
+ accessList = val. accessList ?? accessList
88
+ }
89
+ }
90
+
69
91
}
70
92
71
93
extension EIP1559Envelope {
@@ -94,7 +116,7 @@ extension EIP1559Envelope {
94
116
guard container. contains ( . v) , container. contains ( . r) , container. contains ( . s) else { return nil }
95
117
96
118
// everything we need is present, so we should only have to throw from here
97
- self . internalChainID = try container. decodeHexIfPresent ( BigUInt . self, forKey: . chainId) ?? 0
119
+ self . chainID = try container. decodeHexIfPresent ( BigUInt . self, forKey: . chainId) ?? 0
98
120
self . nonce = try container. decodeHex ( BigUInt . self, forKey: . nonce)
99
121
100
122
let list = try ? container. decode ( [ AccessListEntry ] . self, forKey: . accessList)
@@ -160,7 +182,7 @@ extension EIP1559Envelope {
160
182
guard let sData = rlpItem [ RlpKey . sig_s. rawValue] !. data else { return nil }
161
183
// swiftlint:enable force_unwrapping
162
184
163
- self . internalChainID = BigUInt ( chainData)
185
+ self . chainID = BigUInt ( chainData)
164
186
self . nonce = BigUInt ( nonceData)
165
187
self . maxPriorityFeePerGas = BigUInt ( maxPriorityData)
166
188
self . maxFeePerGas = BigUInt ( maxFeeData)
@@ -211,23 +233,20 @@ extension EIP1559Envelope {
211
233
}
212
234
213
235
public init ( to: EthereumAddress , nonce: BigUInt ? = nil ,
214
- chainID: BigUInt ? = nil , value: BigUInt ? = nil , data: Data ,
215
236
v: BigUInt = 1 , r: BigUInt = 0 , s: BigUInt = 0 ,
216
- options : TransactionOptions ? = nil ) {
237
+ parameters : EthereumParameters ? = nil ) {
217
238
self . to = to
218
- self . nonce = nonce ?? options ? . resolveNonce ( 0 ) ?? 0
219
- self . internalChainID = chainID ?? 0
220
- self . value = value ?? options ? . value ?? 0
221
- self . data = data
239
+ self . nonce = nonce ?? parameters ? . nonce ?? 0
240
+ self . chainID = parameters ? . chainID ?? 0
241
+ self . value = parameters ? . value ?? 0
242
+ self . data = parameters ? . data ?? Data ( )
222
243
self . v = v
223
244
self . r = r
224
245
self . s = s
225
- // decode gas options, if present
226
- self . maxPriorityFeePerGas = options? . resolveMaxPriorityFeePerGas ( 0 ) ?? 0
227
- self . maxFeePerGas = options? . resolveMaxFeePerGas ( 0 ) ?? 0
228
- self . gasLimit = options? . resolveGasLimit ( 0 ) ?? 0
229
- // get the access list, if present
230
- self . accessList = options? . accessList ?? [ ]
246
+ self . maxPriorityFeePerGas = parameters? . maxPriorityFeePerGas ?? 0
247
+ self . maxFeePerGas = parameters? . maxFeePerGas ?? 0
248
+ self . gasLimit = parameters? . gasLimit ?? 0
249
+ self . accessList = parameters? . accessList ?? [ ]
231
250
}
232
251
233
252
// memberwise
@@ -238,7 +257,7 @@ extension EIP1559Envelope {
238
257
v: BigUInt = 1 , r: BigUInt = 0 , s: BigUInt = 0 ) {
239
258
self . to = to
240
259
self . nonce = nonce
241
- self . internalChainID = chainID
260
+ self . chainID = chainID
242
261
self . value = value
243
262
self . data = data
244
263
self . maxPriorityFeePerGas = maxPriorityFeePerGas
@@ -261,25 +280,13 @@ extension EIP1559Envelope {
261
280
self . accessList = options. accessList ?? self . accessList
262
281
}
263
282
264
- public func getOptions( ) -> TransactionOptions {
265
- var options = TransactionOptions ( )
266
- options. nonce = . manual( self . nonce)
267
- options. maxPriorityFeePerGas = . manual( self . maxPriorityFeePerGas)
268
- options. maxFeePerGas = . manual( self . maxFeePerGas)
269
- options. gasLimit = . manual( self . gasLimit)
270
- options. value = self . nonce
271
- options. to = self . to
272
- options. accessList = self . accessList
273
- return options
274
- }
275
-
276
283
public func encode( for type: EncodeType = . transaction) -> Data ? {
277
284
let fields : [ AnyObject ]
278
285
let list = accessList. map { $0. encodeAsList ( ) as AnyObject }
279
286
280
287
switch type {
281
- case . transaction: fields = [ internalChainID , nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to. addressData, value, data, list, v, r, s] as [ AnyObject ]
282
- case . signature: fields = [ internalChainID , nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to. addressData, value, data, list] as [ AnyObject ]
288
+ case . transaction: fields = [ chainID , nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to. addressData, value, data, list, v, r, s] as [ AnyObject ]
289
+ case . signature: fields = [ chainID , nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to. addressData, value, data, list] as [ AnyObject ]
283
290
}
284
291
guard var result = RLP . encode ( fields) else { return nil }
285
292
result. insert ( UInt8 ( self . type. rawValue) , at: 0 )
@@ -297,7 +304,7 @@ extension EIP1559Envelope {
297
304
var params = TransactionParameters ( from: from? . address. lowercased ( ) , to: toString)
298
305
let typeEncoding = String ( UInt8 ( self . type. rawValue) , radix: 16 ) . addHexPrefix ( )
299
306
params. type = typeEncoding
300
- let chainEncoding = self . internalChainID . abiEncode ( bits: 256 )
307
+ let chainEncoding = self . chainID . abiEncode ( bits: 256 )
301
308
params. chainID = chainEncoding? . toHexString ( ) . addHexPrefix ( ) . stripLeadingZeroes ( )
302
309
var accessEncoding : [ TransactionParameters . AccessListEntry ] = [ ]
303
310
for listEntry in self . accessList {
0 commit comments