@@ -12,12 +12,7 @@ public struct EIP1559Envelope: EIP2718Envelope {
1212
1313 // common parameters for any transaction
1414 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
2116 public var to : EthereumAddress
2217 public var value : BigUInt
2318 public var data : Data
@@ -46,8 +41,6 @@ public struct EIP1559Envelope: EIP2718Envelope {
4641 public var maxFeePerGas : BigUInt
4742 public var accessList : [ AccessListEntry ] // from EIP-2930
4843
49- private var internalChainID : BigUInt
50-
5144 // for CustomStringConvertible
5245 public var description : String {
5346 var toReturn = " "
@@ -66,6 +59,35 @@ public struct EIP1559Envelope: EIP2718Envelope {
6659 toReturn += " s: " + String( self . s) + " \n "
6760 return toReturn
6861 }
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+
6991}
7092
7193extension EIP1559Envelope {
@@ -94,7 +116,7 @@ extension EIP1559Envelope {
94116 guard container. contains ( . v) , container. contains ( . r) , container. contains ( . s) else { return nil }
95117
96118 // 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
98120 self . nonce = try container. decodeHex ( BigUInt . self, forKey: . nonce)
99121
100122 let list = try ? container. decode ( [ AccessListEntry ] . self, forKey: . accessList)
@@ -160,7 +182,7 @@ extension EIP1559Envelope {
160182 guard let sData = rlpItem [ RlpKey . sig_s. rawValue] !. data else { return nil }
161183 // swiftlint:enable force_unwrapping
162184
163- self . internalChainID = BigUInt ( chainData)
185+ self . chainID = BigUInt ( chainData)
164186 self . nonce = BigUInt ( nonceData)
165187 self . maxPriorityFeePerGas = BigUInt ( maxPriorityData)
166188 self . maxFeePerGas = BigUInt ( maxFeeData)
@@ -211,23 +233,20 @@ extension EIP1559Envelope {
211233 }
212234
213235 public init ( to: EthereumAddress , nonce: BigUInt ? = nil ,
214- chainID: BigUInt ? = nil , value: BigUInt ? = nil , data: Data ,
215236 v: BigUInt = 1 , r: BigUInt = 0 , s: BigUInt = 0 ,
216- options : TransactionOptions ? = nil ) {
237+ parameters : EthereumParameters ? = nil ) {
217238 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 ( )
222243 self . v = v
223244 self . r = r
224245 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 ?? [ ]
231250 }
232251
233252 // memberwise
@@ -238,7 +257,7 @@ extension EIP1559Envelope {
238257 v: BigUInt = 1 , r: BigUInt = 0 , s: BigUInt = 0 ) {
239258 self . to = to
240259 self . nonce = nonce
241- self . internalChainID = chainID
260+ self . chainID = chainID
242261 self . value = value
243262 self . data = data
244263 self . maxPriorityFeePerGas = maxPriorityFeePerGas
@@ -261,25 +280,13 @@ extension EIP1559Envelope {
261280 self . accessList = options. accessList ?? self . accessList
262281 }
263282
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-
276283 public func encode( for type: EncodeType = . transaction) -> Data ? {
277284 let fields : [ AnyObject ]
278285 let list = accessList. map { $0. encodeAsList ( ) as AnyObject }
279286
280287 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 ]
283290 }
284291 guard var result = RLP . encode ( fields) else { return nil }
285292 result. insert ( UInt8 ( self . type. rawValue) , at: 0 )
@@ -297,7 +304,7 @@ extension EIP1559Envelope {
297304 var params = TransactionParameters ( from: from? . address. lowercased ( ) , to: toString)
298305 let typeEncoding = String ( UInt8 ( self . type. rawValue) , radix: 16 ) . addHexPrefix ( )
299306 params. type = typeEncoding
300- let chainEncoding = self . internalChainID . abiEncode ( bits: 256 )
307+ let chainEncoding = self . chainID . abiEncode ( bits: 256 )
301308 params. chainID = chainEncoding? . toHexString ( ) . addHexPrefix ( ) . stripLeadingZeroes ( )
302309 var accessEncoding : [ TransactionParameters . AccessListEntry ] = [ ]
303310 for listEntry in self . accessList {
0 commit comments