@@ -54,9 +54,10 @@ public struct CodableTransaction {
54
54
set { envelope. value = newValue }
55
55
}
56
56
57
- // MARK: - Ruins signing and decoding tests if tied to envelop
58
- /// any additional data for the transaction
59
- public var data : Data
57
+ public var data : Data {
58
+ get { return envelope. data }
59
+ set { envelope. data = newValue }
60
+ }
60
61
61
62
// MARK: - Properties transaction type related either sends to a node if exist
62
63
@@ -94,7 +95,15 @@ public struct CodableTransaction {
94
95
public var callOnBlock : BlockNumber ?
95
96
96
97
/// access list for contract execution (EIP-2930 and EIP-1559 only)
97
- public var accessList : [ AccessListEntry ] ?
98
+ public var accessList : [ AccessListEntry ] ? {
99
+ get {
100
+ ( envelope as? EIP2930Compatible ) ? . accessList
101
+ }
102
+ set {
103
+ var eip2930Compatible = ( envelope as? EIP2930Compatible )
104
+ eip2930Compatible? . accessList = newValue ?? [ ]
105
+ }
106
+ }
98
107
99
108
// MARK: - Properties to contract encode/sign data only
100
109
@@ -172,8 +181,6 @@ public struct CodableTransaction {
172
181
public init ? ( rawValue: Data ) {
173
182
guard let env = EnvelopeFactory . createEnvelope ( rawValue: rawValue) else { return nil }
174
183
self . envelope = env
175
- // FIXME: This is duplication and should be fixed.
176
- data = Data ( )
177
184
}
178
185
179
186
/// - Returns: a raw bytestream of the transaction, encoded according to the transactionType
@@ -205,8 +212,6 @@ extension CodableTransaction: Codable {
205
212
public init ( from decoder: Decoder ) throws {
206
213
guard let env = try EnvelopeFactory . createEnvelope ( from: decoder) else { throw Web3Error . dataError }
207
214
self . envelope = env
208
- // FIXME: This is duplication and should be fixed.
209
- data = Data ( )
210
215
211
216
// capture any metadata that might be present
212
217
self . meta = try TransactionMetadata ( from: decoder)
@@ -281,7 +286,7 @@ extension CodableTransaction {
281
286
/// - nonce: nonce for this transaction (default 0)
282
287
/// - chainID: chainId the transaction belongs to (default: type specific)
283
288
/// - value: Native value for the transaction (default 0)
284
- /// - data: Payload data for the transaction (required )
289
+ /// - data: Payload data for the transaction (default 0 bytes )
285
290
/// - v: signature v parameter (default 1) - will get set properly once signed
286
291
/// - r: signature r parameter (default 0) - will get set properly once signed
287
292
/// - s: signature s parameter (default 0) - will get set properly once signed
@@ -290,12 +295,9 @@ extension CodableTransaction {
290
295
chainID: BigUInt = 0 , value: BigUInt = 0 , data: Data = Data ( ) ,
291
296
gasLimit: BigUInt = 0 , maxFeePerGas: BigUInt ? = nil , maxPriorityFeePerGas: BigUInt ? = nil , gasPrice: BigUInt ? = nil ,
292
297
accessList: [ AccessListEntry ] ? = nil , v: BigUInt = 1 , r: BigUInt = 0 , s: BigUInt = 0 ) {
293
- // FIXME: This is duplication and should be fixed.
294
- self . data = data
295
- self . accessList = accessList
296
- self . callOnBlock = . latest
298
+ callOnBlock = . latest
297
299
298
- self . envelope = EnvelopeFactory . createEnvelope ( type: type, to: to, nonce: nonce, chainID: chainID, value: value, data: data, gasLimit: gasLimit, maxFeePerGas: maxFeePerGas, maxPriorityFeePerGas: maxPriorityFeePerGas, gasPrice: gasPrice, accessList: accessList, v: v, r: r, s: s)
300
+ envelope = EnvelopeFactory . createEnvelope ( type: type, to: to, nonce: nonce, chainID: chainID, value: value, data: data, gasLimit: gasLimit, maxFeePerGas: maxFeePerGas, maxPriorityFeePerGas: maxPriorityFeePerGas, gasPrice: gasPrice, accessList: accessList, v: v, r: r, s: s)
299
301
}
300
302
}
301
303
0 commit comments