File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ public struct EthereumTransaction: CustomStringConvertible {
29
29
get {
30
30
if ( self . r == BigUInt ( 0 ) && self . s == BigUInt ( 0 ) ) {
31
31
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 ) ) {
33
33
return nil
34
34
} else {
35
35
return ( ( self . v - BigUInt( 1 ) ) / BigUInt( 2 ) ) - BigUInt( 17 )
@@ -125,11 +125,12 @@ public struct EthereumTransaction: CustomStringConvertible {
125
125
} else if self . v >= 27 && self . v <= 30 {
126
126
d = BigUInt ( 27 )
127
127
}
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
132
132
} else {
133
+ if ( d > v) { d = 0 }
133
134
normalizedV = self . v - d
134
135
}
135
136
guard let vData = normalizedV. serialize ( ) . setLengthLeft ( 1 ) else { return nil }
Original file line number Diff line number Diff line change @@ -110,12 +110,19 @@ extension EthereumTransaction:Decodable {
110
110
case r
111
111
case s
112
112
case value
113
+ case type // present in EIP-1559 transaction objects
113
114
}
114
115
115
116
public init ( from decoder: Decoder ) throws {
116
117
let options = try TransactionOptions ( from: decoder)
117
118
let container = try decoder. container ( keyedBy: CodingKeys . self)
118
119
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
+
119
126
var data = try decodeHexToData ( container, key: . data, allowOptional: true )
120
127
if data != nil {
121
128
self . data = data!
You can’t perform that action at this time.
0 commit comments