@@ -21,13 +21,13 @@ extension TransactionOptions: Decodable {
21
21
public init ( from decoder: Decoder ) throws {
22
22
let container = try decoder. container ( keyedBy: CodingKeys . self)
23
23
24
- if let gasLimit = try decodeHexToBigUInt ( container, key : . gas , allowOptional : true ) {
24
+ if let gasLimit = try ? container. decodeHex ( to : BigUInt . self , key : . gas ) {
25
25
self . gasLimit = . manual( gasLimit)
26
26
} else {
27
27
self . gasLimit = . automatic
28
28
}
29
29
30
- if let gasPrice = try decodeHexToBigUInt ( container, key : . gasPrice , allowOptional : true ) {
30
+ if let gasPrice = try ? container. decodeHex ( to : BigUInt . self , key : . gasPrice ) {
31
31
self . gasPrice = . manual( gasPrice)
32
32
} else {
33
33
self . gasPrice = . automatic
@@ -51,16 +51,15 @@ extension TransactionOptions: Decodable {
51
51
// }
52
52
self . from = from
53
53
54
- let value = try decodeHexToBigUInt ( container, key: . value)
55
- self . value = value
54
+ self . value = try container. decodeHex ( to: BigUInt . self, key: . value)
56
55
57
- if let nonce = try decodeHexToBigUInt ( container, key : . nonce , allowOptional : true ) {
56
+ if let nonce = try ? container. decodeHex ( to : BigUInt . self , key : . nonce ) {
58
57
self . nonce = . manual( nonce)
59
58
} else {
60
59
self . nonce = . pending
61
60
}
62
61
63
- if let callOnBlock = try decodeHexToBigUInt ( container, key : . callOnBlock , allowOptional : true ) {
62
+ if let callOnBlock = try ? container. decodeHex ( to : BigUInt . self , key : . callOnBlock ) {
64
63
self . callOnBlock = . exactBlockNumber( callOnBlock)
65
64
} else {
66
65
self . callOnBlock = . pending
@@ -86,14 +85,13 @@ extension EthereumTransaction: Decodable {
86
85
let container = try decoder. container ( keyedBy: CodingKeys . self)
87
86
88
87
// test to see if it is a EIP-1559 wrapper
89
- if let envelope = try decodeHexToBigUInt ( container, key : . type , allowOptional : true ) {
88
+ if let envelope = try ? container. decodeHex ( to : BigUInt . self , key : . type ) {
90
89
// if present and non-sero we are a new wrapper we can't decode
91
90
if envelope != BigInt ( 0 ) { throw Web3Error . dataError }
92
91
}
93
92
94
- var data = try decodeHexToData ( container, key: . data, allowOptional: true )
95
- if data != nil {
96
- self . data = data!
93
+ if let data = try ? container. decodeHex ( to: Data . self, key: . data) {
94
+ self . data = data
97
95
} else {
98
96
guard let data = try ? container. decodeHex ( to: Data . self, key: . input) else { throw Web3Error . dataError }
99
97
self . data = data
@@ -214,21 +212,6 @@ extension TransactionReceipt {
214
212
case 1 : self . status = . ok
215
213
default : self . status = . failed
216
214
}
217
-
218
- guard let cumulativeGasUsed = try decodeHexToBigUInt ( container, key: . cumulativeGasUsed) else { throw Web3Error . dataError}
219
- self . cumulativeGasUsed = cumulativeGasUsed
220
-
221
- guard let gasUsed = try decodeHexToBigUInt ( container, key: . gasUsed) else { throw Web3Error . dataError}
222
- self . gasUsed = gasUsed
223
-
224
- let status = try decodeHexToBigUInt ( container, key: . status, allowOptional: true )
225
- if status == nil {
226
- self . status = TXStatus . notYetProcessed
227
- } else if status == 1 {
228
- self . status = TXStatus . ok
229
- } else {
230
- self . status = TXStatus . failed
231
- }
232
215
233
216
self . logs = try container. decode ( [ EventLog ] . self, forKey: . logs)
234
217
}
0 commit comments