@@ -54,9 +54,10 @@ public struct CodableTransaction {
5454 set { envelope. value = newValue }
5555 }
5656
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+ }
6061
6162 // MARK: - Properties transaction type related either sends to a node if exist
6263
@@ -94,7 +95,15 @@ public struct CodableTransaction {
9495 public var callOnBlock : BlockNumber ?
9596
9697 /// 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+ }
98107
99108 // MARK: - Properties to contract encode/sign data only
100109
@@ -172,8 +181,6 @@ public struct CodableTransaction {
172181 public init ? ( rawValue: Data ) {
173182 guard let env = EnvelopeFactory . createEnvelope ( rawValue: rawValue) else { return nil }
174183 self . envelope = env
175- // FIXME: This is duplication and should be fixed.
176- data = Data ( )
177184 }
178185
179186 /// - Returns: a raw bytestream of the transaction, encoded according to the transactionType
@@ -205,8 +212,6 @@ extension CodableTransaction: Codable {
205212 public init ( from decoder: Decoder ) throws {
206213 guard let env = try EnvelopeFactory . createEnvelope ( from: decoder) else { throw Web3Error . dataError }
207214 self . envelope = env
208- // FIXME: This is duplication and should be fixed.
209- data = Data ( )
210215
211216 // capture any metadata that might be present
212217 self . meta = try TransactionMetadata ( from: decoder)
@@ -281,7 +286,7 @@ extension CodableTransaction {
281286 /// - nonce: nonce for this transaction (default 0)
282287 /// - chainID: chainId the transaction belongs to (default: type specific)
283288 /// - 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 )
285290 /// - v: signature v parameter (default 1) - will get set properly once signed
286291 /// - r: signature r parameter (default 0) - will get set properly once signed
287292 /// - s: signature s parameter (default 0) - will get set properly once signed
@@ -290,12 +295,9 @@ extension CodableTransaction {
290295 chainID: BigUInt = 0 , value: BigUInt = 0 , data: Data = Data ( ) ,
291296 gasLimit: BigUInt = 0 , maxFeePerGas: BigUInt ? = nil , maxPriorityFeePerGas: BigUInt ? = nil , gasPrice: BigUInt ? = nil ,
292297 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
297299
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)
299301 }
300302}
301303
0 commit comments