Skip to content

Commit 64a7b74

Browse files
authored
Merge pull request #180 from BANKEX/develop
Bug fix
2 parents d1a32bc + ce1d082 commit 64a7b74

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

web3swift/BlockExplorer/Classes/BlockExplorer+GetTransactionHistory.swift

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,41 +63,46 @@ public struct Response: Decodable {
6363

6464
public struct TransactionHistoryRecord: Decodable {
6565

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
8282

8383
public init(from decoder: Decoder) throws {
8484
let container = try decoder.container(keyedBy: CodingKeys.self)
8585
id = try container.decode(String.self, forKey: CodingKeys.id)
8686
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 {
8888
throw Web3Error.transactionSerializationError
8989
}
9090
hash = hashData
9191
let intBlock = try container.decode(UInt64.self, forKey: CodingKeys.block)
9292
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 {
9598
throw Web3Error.transactionSerializationError
9699
}
97100
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 {
101106
throw Web3Error.transactionSerializationError
102107
}
103108
addressTo = nativeAddressTo
@@ -168,10 +173,10 @@ public struct TransactionHistoryRecord: Decodable {
168173
}
169174

170175
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
175180

176181
enum CodingKeys: String, CodingKey {
177182
case address = "addr"

web3swift/BlockExplorer/Classes/BlockExplorer.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@
99
import Foundation
1010

1111
public class BlockExplorer {
12-
public var urlStringList = "https://scan.bankex.com/api/list"
12+
public var urlStringList: String
13+
14+
public init() {
15+
urlStringList = "https://scan.bankex.com/api/list"
16+
}
1317
}

0 commit comments

Comments
 (0)