@@ -17,7 +17,7 @@ extension TransactionOptions: Decodable {
17
17
case nonce
18
18
case callOnBlock
19
19
}
20
-
20
+
21
21
public init ( from decoder: Decoder ) throws {
22
22
let container = try decoder. container ( keyedBy: CodingKeys . self)
23
23
@@ -79,30 +79,30 @@ extension EthereumTransaction: Decodable {
79
79
case value
80
80
case type // present in EIP-1559 transaction objects
81
81
}
82
-
82
+
83
83
public init ( from decoder: Decoder ) throws {
84
84
let options = try TransactionOptions ( from: decoder)
85
85
let container = try decoder. container ( keyedBy: CodingKeys . self)
86
-
86
+
87
87
if let data = try ? container. decodeHex ( Data . self, forKey: . data) {
88
88
self . data = data
89
89
} else {
90
90
guard let data = try ? container. decodeHex ( Data . self, forKey: . input) else { throw Web3Error . dataError }
91
91
self . data = data
92
92
}
93
-
93
+
94
94
nonce = try container. decodeHex ( BigUInt . self, forKey: . nonce)
95
- v = try container. decodeHex ( BigUInt . self, forKey: . v)
95
+ v = try container. decodeHex ( BigUInt . self, forKey: . v)
96
96
r = try container. decodeHex ( BigUInt . self, forKey: . r)
97
97
s = try container. decodeHex ( BigUInt . self, forKey: . s)
98
-
99
- guard let to = options. to,
100
- let gasLimit = options. gasLimit,
98
+
99
+ guard let to = options. to,
100
+ let gasLimit = options. gasLimit,
101
101
let gasPrice = options. gasPrice else { throw Web3Error . dataError }
102
102
103
103
self . to = to
104
104
self . value = options. value
105
-
105
+
106
106
switch gasPrice {
107
107
case let . manual( gasPriceValue) :
108
108
self . gasPrice = gasPriceValue
@@ -129,17 +129,17 @@ public struct TransactionDetails: Decodable {
129
129
public var blockNumber : BigUInt ?
130
130
public var transactionIndex : BigUInt ?
131
131
public var transaction : EthereumTransaction
132
-
132
+
133
133
enum CodingKeys : String , CodingKey {
134
134
case blockHash
135
135
case blockNumber
136
136
case transactionIndex
137
137
}
138
-
138
+
139
139
public init ( from decoder: Decoder ) throws {
140
140
let container = try decoder. container ( keyedBy: CodingKeys . self)
141
141
self . blockNumber = try ? container. decodeHex ( BigUInt . self, forKey: . blockNumber)
142
- self . blockHash = try ? container. decodeHex ( Data . self, forKey: . blockHash)
142
+ self . blockHash = try ? container. decodeHex ( Data . self, forKey: . blockHash)
143
143
self . transactionIndex = try ? container. decodeHex ( BigUInt . self, forKey: . blockNumber)
144
144
self . transaction = try EthereumTransaction ( from: decoder)
145
145
}
@@ -156,15 +156,14 @@ public struct TransactionReceipt: Decodable {
156
156
public var logs : [ EventLog ]
157
157
public var status : TXStatus
158
158
public var logsBloom : EthereumBloomFilter ?
159
-
159
+
160
160
public enum TXStatus {
161
161
case ok
162
162
case failed
163
163
case notYetProcessed
164
164
}
165
-
166
- enum CodingKeys : String , CodingKey
167
- {
165
+
166
+ enum CodingKeys : String , CodingKey {
168
167
case blockHash
169
168
case blockNumber
170
169
case transactionHash
@@ -176,7 +175,7 @@ public struct TransactionReceipt: Decodable {
176
175
case logsBloom
177
176
case status
178
177
}
179
-
178
+
180
179
static func notProcessed( transactionHash: Data ) -> TransactionReceipt {
181
180
TransactionReceipt ( transactionHash: transactionHash, blockHash: Data ( ) , blockNumber: BigUInt ( 0 ) , transactionIndex: BigUInt ( 0 ) , contractAddress: nil , cumulativeGasUsed: BigUInt ( 0 ) , gasUsed: BigUInt ( 0 ) , logs: [ EventLog] ( ) , status: . notYetProcessed, logsBloom: nil )
182
181
}
@@ -187,26 +186,26 @@ extension TransactionReceipt {
187
186
let container = try decoder. container ( keyedBy: CodingKeys . self)
188
187
189
188
self . blockNumber = try container. decodeHex ( BigUInt . self, forKey: . blockNumber)
190
-
189
+
191
190
self . blockHash = try container. decodeHex ( Data . self, forKey: . blockHash)
192
-
191
+
193
192
self . transactionIndex = try container. decodeHex ( BigUInt . self, forKey: . transactionIndex)
194
-
193
+
195
194
self . transactionHash = try container. decodeHex ( Data . self, forKey: . transactionHash)
196
-
195
+
197
196
self . contractAddress = try ? container. decodeIfPresent ( EthereumAddress . self, forKey: . contractAddress)
198
-
197
+
199
198
self . cumulativeGasUsed = try container. decodeHex ( BigUInt . self, forKey: . cumulativeGasUsed)
200
-
199
+
201
200
self . gasUsed = try container. decodeHex ( BigUInt . self, forKey: . gasUsed)
202
-
203
- let status = try ? container. decodeHex ( BigUInt . self, forKey: . status)
201
+
202
+ let status = try ? container. decodeHex ( BigUInt . self, forKey: . status)
204
203
switch status {
205
- case nil : self . status = . notYetProcessed
206
- case 1 : self . status = . ok
207
- default : self . status = . failed
204
+ case nil : self . status = . notYetProcessed
205
+ case 1 : self . status = . ok
206
+ default : self . status = . failed
208
207
}
209
-
208
+
210
209
self . logs = try container. decode ( [ EventLog ] . self, forKey: . logs)
211
210
}
212
211
}
@@ -225,7 +224,7 @@ extension EthereumAddress: Codable {
225
224
}
226
225
}
227
226
228
- public struct EventLog : Decodable {
227
+ public struct EventLog : Decodable {
229
228
public var address : EthereumAddress
230
229
public var blockHash : Data
231
230
public var blockNumber : BigUInt
@@ -235,24 +234,22 @@ public struct EventLog : Decodable {
235
234
public var topics : [ Data ]
236
235
public var transactionHash : Data
237
236
public var transactionIndex : BigUInt
238
-
239
-
240
- // address = 0x53066cddbc0099eb6c96785d9b3df2aaeede5da3;
241
- // blockHash = 0x779c1f08f2b5252873f08fd6ec62d75bb54f956633bbb59d33bd7c49f1a3d389;
242
- // blockNumber = 0x4f58f8;
243
- // data = 0x0000000000000000000000000000000000000000000000004563918244f40000;
244
- // logIndex = 0x84;
245
- // removed = 0;
246
- // topics = (
247
- // 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,
248
- // 0x000000000000000000000000efdcf2c36f3756ce7247628afdb632fa4ee12ec5,
249
- // 0x000000000000000000000000d5395c132c791a7f46fa8fc27f0ab6bacd824484
250
- // );
251
- // transactionHash = 0x9f7bb2633abb3192d35f65e50a96f9f7ca878fa2ee7bf5d3fca489c0c60dc79a;
252
- // transactionIndex = 0x99;
253
-
254
- enum CodingKeys : String , CodingKey
255
- {
237
+
238
+ // address = 0x53066cddbc0099eb6c96785d9b3df2aaeede5da3;
239
+ // blockHash = 0x779c1f08f2b5252873f08fd6ec62d75bb54f956633bbb59d33bd7c49f1a3d389;
240
+ // blockNumber = 0x4f58f8;
241
+ // data = 0x0000000000000000000000000000000000000000000000004563918244f40000;
242
+ // logIndex = 0x84;
243
+ // removed = 0;
244
+ // topics = (
245
+ // 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,
246
+ // 0x000000000000000000000000efdcf2c36f3756ce7247628afdb632fa4ee12ec5,
247
+ // 0x000000000000000000000000d5395c132c791a7f46fa8fc27f0ab6bacd824484
248
+ // );
249
+ // transactionHash = 0x9f7bb2633abb3192d35f65e50a96f9f7ca878fa2ee7bf5d3fca489c0c60dc79a;
250
+ // transactionIndex = 0x99;
251
+
252
+ enum CodingKeys : String , CodingKey {
256
253
case address
257
254
case blockHash
258
255
case blockNumber
@@ -263,31 +260,31 @@ public struct EventLog : Decodable {
263
260
case transactionHash
264
261
case transactionIndex
265
262
}
266
-
263
+
267
264
public init ( from decoder: Decoder ) throws {
268
265
let container = try decoder. container ( keyedBy: CodingKeys . self)
269
-
266
+
270
267
let address = try container. decode ( EthereumAddress . self, forKey: . address)
271
268
self . address = address
272
-
269
+
273
270
self . blockNumber = try container. decodeHex ( BigUInt . self, forKey: . blockNumber)
274
-
271
+
275
272
self . blockHash = try container. decodeHex ( Data . self, forKey: . blockHash)
276
-
273
+
277
274
self . transactionIndex = try container. decodeHex ( BigUInt . self, forKey: . transactionIndex)
278
-
275
+
279
276
self . transactionHash = try container. decodeHex ( Data . self, forKey: . transactionHash)
280
-
277
+
281
278
self . data = try container. decodeHex ( Data . self, forKey: . data)
282
-
279
+
283
280
self . logIndex = try container. decodeHex ( BigUInt . self, forKey: . logIndex)
284
-
281
+
285
282
let removed = try ? container. decodeHex ( BigUInt . self, forKey: . removed)
286
283
self . removed = removed == 1 ? true : false
287
-
284
+
288
285
let topicsStrings = try container. decode ( [ String ] . self, forKey: . topics)
289
286
290
- self . topics = try topicsStrings. map {
287
+ self . topics = try topicsStrings. map {
291
288
guard let topic = Data . fromHex ( $0) else { throw Web3Error . dataError }
292
289
return topic
293
290
}
@@ -298,7 +295,7 @@ public enum TransactionInBlock: Decodable {
298
295
case hash( Data )
299
296
case transaction( EthereumTransaction )
300
297
case null
301
-
298
+
302
299
public init ( from decoder: Decoder ) throws {
303
300
let value = try decoder. singleValueContainer ( )
304
301
if let string = try ? value. decode ( String . self) {
@@ -337,7 +334,7 @@ public struct Block: Decodable {
337
334
public var timestamp : Date
338
335
public var transactions : [ TransactionInBlock ]
339
336
public var uncles : [ Data ]
340
-
337
+
341
338
enum CodingKeys : String , CodingKey {
342
339
case number
343
340
case hash
@@ -353,11 +350,11 @@ public struct Block: Decodable {
353
350
case totalDifficulty
354
351
case extraData
355
352
case size
356
-
353
+
357
354
case gasLimit
358
355
case gasUsed
359
356
case baseFeePerGas
360
-
357
+
361
358
case timestamp
362
359
case transactions
363
360
case uncles
@@ -411,11 +408,11 @@ extension Block {
411
408
}
412
409
}
413
410
414
- public struct EventParserResult : EventParserResultProtocol {
411
+ public struct EventParserResult : EventParserResultProtocol {
415
412
public var eventName : String
416
413
public var transactionReceipt : TransactionReceipt ?
417
414
public var contractAddress : EthereumAddress
418
- public var decodedResult : [ String : Any ]
415
+ public var decodedResult : [ String : Any ]
419
416
public var eventLog : EventLog ? = nil
420
417
}
421
418
@@ -424,10 +421,10 @@ public struct TransactionSendingResult {
424
421
public var hash : String
425
422
}
426
423
427
- public struct TxPoolStatus : Decodable {
424
+ public struct TxPoolStatus : Decodable {
428
425
public var pending : BigUInt
429
426
public var queued : BigUInt
430
-
427
+
431
428
enum CodingKeys : String , CodingKey {
432
429
case pending
433
430
case queued
@@ -442,15 +439,15 @@ public extension TxPoolStatus {
442
439
}
443
440
}
444
441
445
- public struct TxPoolContent : Decodable {
442
+ public struct TxPoolContent : Decodable {
446
443
public var pending : [ EthereumAddress : [ TxPoolContentForNonce ] ]
447
444
public var queued : [ EthereumAddress : [ TxPoolContentForNonce ] ]
448
-
445
+
449
446
enum CodingKeys : String , CodingKey {
450
447
case pending
451
448
case queued
452
449
}
453
-
450
+
454
451
fileprivate static func decodePoolContentForKey< T> ( container: KeyedDecodingContainer < T > , key: KeyedDecodingContainer < T > . Key ) throws -> [ EthereumAddress : [ TxPoolContentForNonce ] ] {
455
452
let raw = try container. nestedContainer ( keyedBy: AdditionalDataCodingKeys . self, forKey: key)
456
453
var result = [ EthereumAddress: [ TxPoolContentForNonce] ] ( )
@@ -481,14 +478,13 @@ public struct TxPoolContent : Decodable {
481
478
}
482
479
return result
483
480
}
484
-
485
-
481
+
486
482
fileprivate struct AdditionalDataCodingKeys : CodingKey {
487
483
var stringValue : String
488
484
init ? ( stringValue: String ) {
489
485
self . stringValue = stringValue
490
486
}
491
-
487
+
492
488
var intValue : Int ?
493
489
init ? ( intValue: Int ) {
494
490
return nil
0 commit comments