Skip to content

Commit 119d23c

Browse files
chore: intorduced EIP2930Compatible protocol to support easy access to accessList
1 parent 4fc15ad commit 119d23c

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

Sources/Core/Transaction/CodableTransaction.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,15 @@ public struct CodableTransaction {
9595
public var callOnBlock: BlockNumber?
9696

9797
/// access list for contract execution (EIP-2930 and EIP-1559 only)
98-
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+
}
99107

100108
// MARK: - Properties to contract encode/sign data only
101109

@@ -287,8 +295,6 @@ extension CodableTransaction {
287295
chainID: BigUInt = 0, value: BigUInt = 0, data: Data = Data(),
288296
gasLimit: BigUInt = 0, maxFeePerGas: BigUInt? = nil, maxPriorityFeePerGas: BigUInt? = nil, gasPrice: BigUInt? = nil,
289297
accessList: [AccessListEntry]? = nil, v: BigUInt = 1, r: BigUInt = 0, s: BigUInt = 0) {
290-
// TODO: accessList must be returned from envelope and not stored as a separate variable in CodableTransaction
291-
self.accessList = accessList
292298
callOnBlock = .latest
293299

294300
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)

Sources/Core/Transaction/Envelope/EIP1559Envelope.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import Foundation
88
import BigInt
99

10-
public struct EIP1559Envelope: EIP2718Envelope {
10+
public struct EIP1559Envelope: EIP2718Envelope, EIP2930Compatible {
1111
public let type: TransactionType = .eip1559
1212

1313
// common parameters for any transaction

Sources/Core/Transaction/Envelope/EIP2930Envelope.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import Foundation
88
import BigInt
99

10-
public struct EIP2930Envelope: EIP2718Envelope {
10+
public struct EIP2930Envelope: EIP2718Envelope, EIP2930Compatible {
1111
public let type: TransactionType = .eip2930
1212

1313
// common parameters for any transaction
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// EIP2930Compatible.swift
3+
//
4+
// Created by JeneaVranceanu on 10.11.2022.
5+
//
6+
7+
import Foundation
8+
9+
/// Protocol to support `EIP-2930` properties access
10+
public protocol EIP2930Compatible {
11+
var accessList: [AccessListEntry] { get set }
12+
}

0 commit comments

Comments
 (0)