@@ -63,41 +63,46 @@ public struct Response: Decodable {
63
63
64
64
public struct TransactionHistoryRecord : Decodable {
65
65
66
- let id : String
67
- let hash : Data
68
- let block : BigUInt
69
- let addressFrom : EthereumAddress
70
- let addressTo : EthereumAddress
71
- let isoTime : String
72
- let type : TransactionType
73
- let status : TransactionStatus
74
- let error : String
75
- let isContract : Bool
76
- let isInner : Bool
77
- let value : BigUInt // in wei
78
- let token : Token
79
- let txFee : BigUInt // in wei
80
- let gasUsed : BigUInt // in wei
81
- let gasCost : BigUInt // in wei
66
+ public let id : String
67
+ public let hash : Data
68
+ public let block : BigUInt
69
+ public let addressFrom : EthereumAddress
70
+ public let addressTo : EthereumAddress
71
+ public let isoTime : String
72
+ public let type : TransactionType
73
+ public let status : TransactionStatus
74
+ public let error : String
75
+ public let isContract : Bool
76
+ public let isInner : Bool
77
+ public let value : BigUInt // in wei
78
+ public let token : Token
79
+ public let txFee : BigUInt // in wei
80
+ public let gasUsed : BigUInt // in wei
81
+ public let gasCost : BigUInt // in wei
82
82
83
83
public init ( from decoder: Decoder ) throws {
84
84
let container = try decoder. container ( keyedBy: CodingKeys . self)
85
85
id = try container. decode ( String . self, forKey: CodingKeys . id)
86
86
let hashString = try container. decode ( String . self, forKey: CodingKeys . hash)
87
- guard let hashData = hashString . interpretAsBinaryData ( ) else {
87
+ guard let hashData = Data . fromHex ( hashString ) else {
88
88
throw Web3Error . transactionSerializationError
89
89
}
90
90
hash = hashData
91
91
let intBlock = try container. decode ( UInt64 . self, forKey: CodingKeys . block)
92
92
block = BigUInt . init ( integerLiteral: intBlock)
93
- let stringAddressFrom = try container. decode ( String . self, forKey: CodingKeys . addressFrom)
94
- guard let nativeAddressFrom = EthereumAddress ( stringAddressFrom, type: . normal, ignoreChecksum: true ) else {
93
+ var stringAddressFrom = try container. decode ( String . self, forKey: CodingKeys . addressFrom)
94
+ if !stringAddressFrom. hasHexPrefix ( ) {
95
+ stringAddressFrom = stringAddressFrom. addHexPrefix ( )
96
+ }
97
+ guard let nativeAddressFrom = EthereumAddress ( stringAddressFrom) else {
95
98
throw Web3Error . transactionSerializationError
96
99
}
97
100
addressFrom = nativeAddressFrom
98
- let stringAddressTo = try container. decode ( String . self, forKey: CodingKeys . addressTo)
99
-
100
- guard let nativeAddressTo = EthereumAddress ( stringAddressTo, type: . normal, ignoreChecksum: true ) else {
101
+ var stringAddressTo = try container. decode ( String . self, forKey: CodingKeys . addressTo)
102
+ if !stringAddressTo. hasHexPrefix ( ) {
103
+ stringAddressTo = stringAddressTo. addHexPrefix ( )
104
+ }
105
+ guard let nativeAddressTo = EthereumAddress ( stringAddressTo) else {
101
106
throw Web3Error . transactionSerializationError
102
107
}
103
108
addressTo = nativeAddressTo
@@ -168,10 +173,10 @@ public struct TransactionHistoryRecord: Decodable {
168
173
}
169
174
170
175
public struct Token : Decodable {
171
- let address : EthereumAddress ?
172
- let name : String
173
- let symbol : String
174
- let decimal : Int
176
+ public let address : EthereumAddress ?
177
+ public let name : String
178
+ public let symbol : String
179
+ public let decimal : Int
175
180
176
181
enum CodingKeys : String , CodingKey {
177
182
case address = " addr "
0 commit comments