Skip to content

Commit 11ab291

Browse files
committed
Workaround for Oracle using gasPrice value provided from nodes for EIP-1159 transactions, even though EIP-1159 transactions do not have a gasPrice field
1 parent 51970c7 commit 11ab291

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Sources/web3swift/Transaction/EIP1559Envelope.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public struct EIP1559Envelope: EIP2718Envelope {
4141
public var maxFeePerGas: BigUInt
4242
public var accessList: [AccessListEntry] // from EIP-2930
4343

44+
/// EIP-1159 trnsactions do not have a gasPrice parameter
45+
/// However, it appears that some nodes report a gasPrice, even for EIP-1159 transactions
46+
/// thus for a temporary workaround we capture and store gasPrice if initialized from a JSON transaction
47+
/// decided form a node. This is currently needed for Oracle to work
48+
private var gasPrice: BigUInt = 0
49+
4450
// for CustomStringConvertible
4551
public var description: String {
4652
var toReturn = ""
@@ -70,6 +76,9 @@ public struct EIP1559Envelope: EIP2718Envelope {
7076
value: value,
7177
data: data,
7278
gasLimit: gasLimit,
79+
// MARK: workaround for gasPrice coming from nodes for EIP-1159 - this allows Oracle to work for now
80+
gasPrice: gasPrice,
81+
7382
maxFeePerGas: maxFeePerGas,
7483
maxPriorityFeePerGas: maxPriorityFeePerGas,
7584
accessList: accessList
@@ -85,6 +94,8 @@ public struct EIP1559Envelope: EIP2718Envelope {
8594
maxFeePerGas = val.maxFeePerGas ?? maxFeePerGas
8695
maxPriorityFeePerGas = val.maxPriorityFeePerGas ?? maxPriorityFeePerGas
8796
accessList = val.accessList ?? accessList
97+
// MARK: workaround for gasPrice coming from nodes for EIP-1159 - this allows Oracle to work for now
98+
gasPrice = val.gasPrice ?? gasPrice
8899
}
89100
}
90101

@@ -106,6 +117,8 @@ extension EIP1559Envelope {
106117
case v
107118
case r
108119
case s
120+
// MARK: workaround for gasPrice coming from nodes for EIP-1159 - this allows Oracle to work for now
121+
case gasPrice
109122
}
110123

111124
public init?(from decoder: Decoder) throws {
@@ -133,6 +146,10 @@ extension EIP1559Envelope {
133146
// swiftlint:enable force_unwrapping
134147
self.to = ethAddr
135148
}
149+
150+
// MARK: workaround for gasPrice coming from nodes for EIP-1159 - this allows Oracle to work for now
151+
self.gasPrice = try container.decodeHexIfPresent(BigUInt.self, forKey: .gasPrice) ?? 5000000000
152+
136153
self.value = try container.decodeHexIfPresent(BigUInt.self, forKey: .value) ?? 0
137154
self.maxPriorityFeePerGas = try container.decodeHexIfPresent(BigUInt.self, forKey: .maxPriorityFeePerGas) ?? 0
138155
self.maxFeePerGas = try container.decodeHexIfPresent(BigUInt.self, forKey: .maxFeePerGas) ?? 0

Sources/web3swift/Transaction/EthereumTransaction.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,10 @@ extension EthereumTransaction {
330330
guard let env = self.envelope as? EIP2930Envelope else { preconditionFailure("Unable to downcast to EIP2930Envelope") }
331331
return env.parameters.gasPrice ?? 0
332332
case .eip1559:
333-
preconditionFailure("EIP1559Envelope has no member gasPrice")
333+
// MARK: workaround for gasPrice coming from nodes for EIP-1159 - this allows Oracle to work for now
334+
guard let env = self.envelope as? EIP1559Envelope else { preconditionFailure("Unable to downcast to EIP1559Envelope") }
335+
return env.parameters.gasPrice ?? 0
336+
// preconditionFailure("EIP1559Envelope has no member gasPrice")
334337
}
335338
}
336339
set(value) {

0 commit comments

Comments
 (0)