44//
55
66import Foundation
7+ import BigInt
78
89public struct EthereumBlockInfo : Equatable {
910 public var number : EthereumBlock
1011 public var timestamp : Date
1112 public var transactions : [ String ]
13+ public var gasLimit : BigUInt
14+ public var gasUsed : BigUInt
15+ public var baseFeePerGas : BigUInt ?
1216}
1317
1418extension EthereumBlockInfo : Codable {
1519 enum CodingKeys : CodingKey {
1620 case number
1721 case timestamp
1822 case transactions
23+ case gasLimit
24+ case gasUsed
25+ case baseFeePerGas
1926 }
2027
2128 public init ( from decoder: Decoder ) throws {
@@ -33,10 +40,25 @@ extension EthereumBlockInfo: Codable {
3340 guard let transactions = try ? container. decode ( [ String ] . self, forKey: . transactions) else {
3441 throw JSONRPCError . decodingError
3542 }
43+
44+ guard let gasLimit = try ? container. decode ( String . self, forKey: . gasLimit) else {
45+ throw JSONRPCError . decodingError
46+ }
47+
48+ guard let gasUsed = try ? container. decode ( String . self, forKey: . gasUsed) else {
49+ throw JSONRPCError . decodingError
50+ }
51+
52+ let baseFeePerGas = try ? container. decode ( String . self, forKey: . baseFeePerGas)
3653
3754 self . number = number
3855 self . timestamp = Date ( timeIntervalSince1970: timestamp)
3956 self . transactions = transactions
57+ self . gasLimit = BigUInt ( hex: gasLimit) ?? BigUInt ( 0 )
58+ self . gasUsed = BigUInt ( hex: gasUsed) ?? BigUInt ( 0 )
59+ if let baseFee = baseFeePerGas {
60+ self . baseFeePerGas = BigUInt ( hex: baseFee)
61+ }
4062 }
4163
4264 public func encode( to encoder: Encoder ) throws {
@@ -45,5 +67,10 @@ extension EthereumBlockInfo: Codable {
4567 try container. encode ( number, forKey: . number)
4668 try container. encode ( Int ( timestamp. timeIntervalSince1970) . web3. hexString, forKey: . timestamp)
4769 try container. encode ( transactions, forKey: . transactions)
70+ try container. encode ( gasLimit. web3. hexString, forKey: . gasLimit)
71+ try container. encode ( gasUsed. web3. hexString, forKey: . gasUsed)
72+ if let baseFee = baseFeePerGas {
73+ try container. encode ( baseFee. web3. hexString, forKey: . baseFeePerGas)
74+ }
4875 }
4976}
0 commit comments