Skip to content

Commit 004bad3

Browse files
authored
Merge pull request #206 from BANKEX/develop
Fix parsing transaction details and receipt when transaction was creating a contract
2 parents 6115fdf + 5987495 commit 004bad3

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

web3swift/Transaction/Classes/EthereumTransaction.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,6 @@ public struct EthereumTransaction: CustomStringConvertible {
271271
if (transaction.inferedChainID != nil && transaction.v >= BigUInt(37)) {
272272
transaction.chainID = inferedChainID
273273
}
274-
// let hash = json["hash"] as? String
275-
// if hash != nil {
276-
// let calculatedHash = transaction.hash
277-
// let receivedHash = Data.fromHex(hash!)
278-
// if (receivedHash != calculatedHash) {
279-
// print("hash mismatch, dat")
280-
// print(String(describing: transaction))
281-
// print(json)
282-
// return nil
283-
// }
284-
// }
285274
return transaction
286275
}
287276

web3swift/Web3/Classes/Web3+Structures.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ extension Web3Options:Decodable {
5656
let gasPrice = try decodeHexToBigUInt(container, key: .gasPrice)
5757
self.gasPrice = gasPrice
5858

59-
let toString = try container.decode(String.self, forKey: .to)
59+
let toString = try container.decode(String?.self, forKey: .to)
6060
var to: EthereumAddress?
61-
if toString == "0x" || toString == "0x0" {
61+
if toString == nil || toString == "0x" || toString == "0x0" {
6262
to = EthereumAddress.contractDeploymentAddress()
6363
} else {
64-
guard let ethAddr = EthereumAddress(toString) else {throw Web3Error.dataError}
64+
guard let addressString = toString else {throw Web3Error.dataError}
65+
guard let ethAddr = EthereumAddress(addressString) else {throw Web3Error.dataError}
6566
to = ethAddr
6667
}
6768
self.to = to

web3swiftTests/web3swift_User_cases.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,26 @@ class web3swift_User_cases: XCTestCase {
8484
XCTAssert(assembled.gasPrice == options.gasPrice)
8585
}
8686

87+
func testParseTransactionDetailsForContractCreation() {
88+
let web3 = Web3.InfuraMainnetWeb3()
89+
let details = web3.eth.getTransactionDetails("0x1c85b9b7f7c2cbdb3fa264f6b78b226360aa2084c48cf7869b756e0762bd851b")
90+
switch details {
91+
case .success(let details):
92+
print(details)
93+
XCTAssert(details.transaction.to == .contractDeploymentAddress())
94+
case .failure(let error):
95+
print(error)
96+
XCTFail()
97+
}
98+
let receipt = web3.eth.getTransactionReceipt("0x1c85b9b7f7c2cbdb3fa264f6b78b226360aa2084c48cf7869b756e0762bd851b")
99+
switch receipt {
100+
case .success(let receipt):
101+
print(receipt)
102+
XCTAssert(receipt.contractAddress != nil)
103+
case .failure(let error):
104+
print(error)
105+
XCTFail()
106+
}
107+
}
108+
87109
}

0 commit comments

Comments
 (0)