Skip to content

Commit f85ab50

Browse files
Merge pull request #467 from mloit/tolerate1559
2 parents 5edab19 + 9d84b4a commit f85ab50

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Sources/web3swift/Transaction/EthereumTransaction.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public struct EthereumTransaction: CustomStringConvertible {
2929
get{
3030
if (self.r == BigUInt(0) && self.s == BigUInt(0)) {
3131
return self.v
32-
} else if (self.v == BigUInt(27) || self.v == BigUInt(28)) {
32+
} else if (self.v == BigUInt(27) || self.v == BigUInt(28) || self.v < BigUInt(35)) {
3333
return nil
3434
} else {
3535
return ((self.v - BigUInt(1)) / BigUInt(2)) - BigUInt(17)
@@ -125,11 +125,12 @@ public struct EthereumTransaction: CustomStringConvertible {
125125
} else if self.v >= 27 && self.v <= 30 {
126126
d = BigUInt(27)
127127
}
128-
if (self.chainID != nil && self.chainID != BigUInt(0)) {
129-
normalizedV = self.v - d - self.chainID! - self.chainID!
130-
} else if (inferedChainID != nil) {
131-
normalizedV = self.v - d - inferedChainID! - inferedChainID!
128+
if let testID = self.chainID, testID != BigUInt(0) && self.v >= (d + testID + testID) {
129+
normalizedV = self.v - d - testID - testID
130+
} else if let testID = inferedChainID, self.v >= (d + testID + testID) {
131+
normalizedV = self.v - d - testID - testID
132132
} else {
133+
if(d > v) { d = 0 }
133134
normalizedV = self.v - d
134135
}
135136
guard let vData = normalizedV.serialize().setLengthLeft(1) else {return nil}

Sources/web3swift/Web3/Web3+Structures.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,19 @@ extension EthereumTransaction:Decodable {
110110
case r
111111
case s
112112
case value
113+
case type // present in EIP-1559 transaction objects
113114
}
114115

115116
public init(from decoder: Decoder) throws {
116117
let options = try TransactionOptions(from: decoder)
117118
let container = try decoder.container(keyedBy: CodingKeys.self)
118119

120+
// test to see if it is a EIP-1559 wrapper
121+
if let envelope = try decodeHexToBigUInt(container, key: .type, allowOptional: true) {
122+
// if present and non-sero we are a new wrapper we can't decode
123+
if(envelope != BigInt(0)) { throw Web3Error.dataError }
124+
}
125+
119126
var data = try decodeHexToData(container, key: .data, allowOptional: true)
120127
if data != nil {
121128
self.data = data!

0 commit comments

Comments
 (0)