Skip to content

Commit 7f83ea2

Browse files
committed
- Remove "Result" everywhere
- Make Podfile more explicit
1 parent 7a2178d commit 7f83ea2

File tree

8 files changed

+52
-88
lines changed

8 files changed

+52
-88
lines changed

web3swift.podspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ s.swift_version = '4.1'
1717
s.module_name = 'Web3swift'
1818
s.ios.deployment_target = "9.0"
1919
s.osx.deployment_target = "10.11"
20-
s.source_files = "web3swift/**/*.{h,swift}",
21-
s.exclude_files = "web3swift/ObjectiveCbridge/Classes/*.{swift}", "web3swift/Utils/Classes/ENS.swift", "web3swift/Utils/Classes/ENSResolver.swift"
22-
s.public_header_files = "web3swift/**/*.{h}"
20+
s.source_files = "web3swift/{PrecompiledContracts,Promises,Web3,Contract,KeystoreManager,Transaction,Convenience}/Classes/*.{h,swift}", "web3swift/Utils/Classes/{EIP67Code, EIP681}.swift", "web3swift/HookedFunctions/Classes/Web3+Wallet.swift", "web3swift/web3swift.h"
21+
s.public_header_files = "web3swift/web3swift.h"
2322
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
2423

2524
s.frameworks = 'CoreImage'

web3swift/HookedFunctions/Classes/Web3+BrowserFunctions.swift

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,22 @@ extension web3.BrowserFunctions {
111111
return self.prepareTxForApproval(transaction, options: options)
112112
}
113113

114-
public func prepareTxForApproval(_ trans: EthereumTransaction, options opts: Web3Options) -> (transaction: EthereumTransaction?, options: Web3Options?) {
115-
var transaction = trans
116-
var options = opts
117-
guard let _ = options.from else {return (nil, nil)}
118-
let gasPriceResult = self.web3.eth.getGasPrice()
119-
if case .failure(_) = gasPriceResult {
114+
public func prepareTxForApproval(_ trans: EthereumTransaction, options opts: Web3Options) throws -> (transaction: EthereumTransaction?, options: Web3Options?) {
115+
do {
116+
var transaction = trans
117+
var options = opts
118+
guard let _ = options.from else {return (nil, nil)}
119+
let gasPrice = try self.web3.eth.getGasPrice()
120+
transaction.gasPrice = gasPrice
121+
options.gasPrice = gasPrice
122+
guard let gasEstimate = self.estimateGas(transaction, options: options) else {return (nil, nil)}
123+
transaction.gasLimit = gasEstimate
124+
options.gasLimit = gasEstimate
125+
print(transaction)
126+
return (transaction, options)
127+
} catch {
120128
return (nil, nil)
121129
}
122-
transaction.gasPrice = gasPriceResult.value!
123-
options.gasPrice = gasPriceResult.value!
124-
guard let gasEstimate = self.estimateGas(transaction, options: options) else {return (nil, nil)}
125-
transaction.gasLimit = gasEstimate
126-
options.gasLimit = gasEstimate
127-
print(transaction)
128-
return (transaction, options)
129130
}
130131

131132
public func signTransaction(_ transactionJSON: [String: Any], password: String = "web3swift") -> String? {

web3swift/Web3/Classes/Web3+Personal.swift

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ extension web3.Personal {
2424
- important: This call is synchronous
2525

2626
*/
27-
public func signPersonalMessage(message: Data, from: EthereumAddress, password:String = "web3swift") -> Result<Data, Web3Error> {
28-
do {
29-
let result = try self.signPersonalMessagePromise(message: message, from: from, password: password).wait()
30-
return Result(result)
31-
} catch {
32-
return Result.failure(error as! Web3Error)
33-
}
27+
public func signPersonalMessage(message: Data, from: EthereumAddress, password:String = "web3swift") throws -> Data {
28+
let result = try self.signPersonalMessagePromise(message: message, from: from, password: password).wait()
29+
return result
3430
}
3531

3632
/**
@@ -47,13 +43,9 @@ extension web3.Personal {
4743
- important: This call is synchronous. Does nothing if private keys are stored locally.
4844

4945
*/
50-
public func unlockAccount(account: EthereumAddress, password:String = "web3swift", seconds: UInt64 = 300) -> Result<Bool, Web3Error> {
51-
do {
52-
let result = try self.unlockAccountPromise(account: account).wait()
53-
return Result(result)
54-
} catch {
55-
return Result.failure(error as! Web3Error)
56-
}
46+
public func unlockAccount(account: EthereumAddress, password:String = "web3swift", seconds: UInt64 = 300) throws -> Bool {
47+
let result = try self.unlockAccountPromise(account: account).wait()
48+
return result
5749
}
5850

5951
/**
@@ -67,11 +59,11 @@ extension web3.Personal {
6759
- Result object
6860

6961
*/
70-
public func ecrecover(personalMessage: Data, signature: Data) -> Result<EthereumAddress, Web3Error> {
62+
public func ecrecover(personalMessage: Data, signature: Data) throws -> EthereumAddress {
7163
guard let recovered = Web3.Utils.personalECRecover(personalMessage, signature: signature) else {
72-
return Result.failure(Web3Error.dataError)
64+
throw Web3Error.dataError
7365
}
74-
return Result(recovered)
66+
return recovered
7567
}
7668

7769
/**
@@ -85,10 +77,10 @@ extension web3.Personal {
8577
- Result object
8678

8779
*/
88-
public func ecrecover(hash: Data, signature: Data) -> Result<EthereumAddress, Web3Error> {
80+
public func ecrecover(hash: Data, signature: Data) throws -> EthereumAddress {
8981
guard let recovered = Web3.Utils.hashECRecover(hash: hash, signature: signature) else {
90-
return Result.failure(Web3Error.dataError)
82+
throw Web3Error.dataError
9183
}
92-
return Result(recovered)
84+
return recovered
9385
}
9486
}

web3swift/Web3/Classes/Web3+TxPool.swift

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,18 @@ import Foundation
88
import BigInt
99

1010
extension web3.TxPool {
11-
public func getInspect() -> Result<[String:[String:[String:String]]], Web3Error> {
12-
do {
13-
let result = try self.getInspectPromise().wait()
14-
return Result(result)
15-
} catch {
16-
if let err = error as? Web3Error {
17-
return Result.failure(err)
18-
}
19-
return Result.failure(Web3Error.generalError(err: error))
20-
}
11+
public func getInspect() throws -> [String:[String:[String:String]]] {
12+
let result = try self.getInspectPromise().wait()
13+
return result
2114
}
2215

23-
public func getStatus() -> Result<TxPoolStatus, Web3Error> {
24-
do {
25-
let result = try self.getStatusPromise().wait()
26-
return Result(result)
27-
} catch {
28-
if let err = error as? Web3Error {
29-
return Result.failure(err)
30-
}
31-
return Result.failure(Web3Error.generalError(err: error))
32-
}
16+
public func getStatus() throws -> TxPoolStatus {
17+
let result = try self.getStatusPromise().wait()
18+
return result
3319
}
3420

35-
public func getContent() -> Result<TxPoolContent, Web3Error> {
36-
do {
37-
let result = try self.getContentPromise().wait()
38-
return Result(result)
39-
} catch {
40-
if let err = error as? Web3Error {
41-
return Result.failure(err)
42-
}
43-
return Result.failure(Web3Error.generalError(err: error))
44-
}
21+
public func getContent() throws -> TxPoolContent {
22+
let result = try self.getContentPromise().wait()
23+
return result
4524
}
4625
}

web3swift/Web3/Classes/Web3.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,24 @@ public struct Web3 {
7777
}
7878

7979
struct ResultUnwrapper {
80-
static func getResponse(_ response: [String: Any]?) -> Result<Any, Web3Error> {
80+
static func getResponse(_ response: [String: Any]?) throws -> Any {
8181
guard response != nil, let res = response else {
82-
return Result.failure(Web3Error.connectionError)
82+
throw Web3Error.connectionError
8383
}
8484
if let error = res["error"] {
8585
if let errString = error as? String {
86-
return Result.failure(Web3Error.nodeError(desc: errString))
86+
throw Web3Error.nodeError(desc: errString)
8787
} else if let errDict = error as? [String:Any] {
8888
if errDict["message"] != nil, let descr = errDict["message"]! as? String {
89-
return Result.failure(Web3Error.nodeError(desc: descr))
89+
throw Web3Error.nodeError(desc: descr)
9090
}
9191
}
92-
return Result.failure(Web3Error.unknownError)
92+
throw Web3Error.unknownError
9393
}
9494
guard let result = res["result"] else {
95-
return Result.failure(Web3Error.dataError)
95+
throw Web3Error.dataError
9696
}
97-
return Result(result)
97+
return result
9898
}
9999
}
100100

web3swift/web3swift-Bridging-Header.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
//
2-
// web3swift-Bridging-Header.h
31
// web3swift
42
//
5-
// Created by Alexander Vlasov on 08.08.2018.
6-
// Copyright © 2018 Bankex Foundation. All rights reserved.
3+
// Created by Alex Vlasov.
4+
// Copyright © 2018 Alex Vlasov. All rights reserved.
75
//
86

97
#ifndef web3swift_Bridging_Header_h

web3swift/web3swift.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
//
2-
// web3swift.h
31
// web3swift
42
//
5-
// Created by Petr Korolev on 06/12/2017.
6-
// Copyright © 2017 Bankex Foundation. All rights reserved.
3+
// Created by Alex Vlasov.
4+
// Copyright © 2018 Alex Vlasov. All rights reserved.
75
//
86

97
#if TARGET_OS_IPHONE

web3swiftTests/web3swift_rinkeby_personalSignature_Tests.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,21 @@ import EthereumAddress
1515
class web3swift_rinkeby_personalSignature_Tests: XCTestCase {
1616

1717

18-
func testPersonalSignature() {
18+
func testPersonalSignature() throws {
1919
let web3 = Web3.InfuraRinkebyWeb3()
2020
let tempKeystore = try! EthereumKeystoreV3(password: "")
2121
let keystoreManager = KeystoreManager([tempKeystore!])
2222
web3.addKeystoreManager(keystoreManager)
2323
let message = "Hello World"
2424
let expectedAddress = keystoreManager.addresses![0]
2525
print(expectedAddress)
26-
let signRes = web3.personal.signPersonalMessage(message: message.data(using: .utf8)!, from: expectedAddress, password: "")
27-
guard case .success(let signature) = signRes else {return XCTFail()}
26+
let signature = try web3.personal.signPersonalMessage(message: message.data(using: .utf8)!, from: expectedAddress, password: "")
2827
let unmarshalledSignature = SECP256K1.unmarshalSignature(signatureData: signature)!
2928
print("V = " + String(unmarshalledSignature.v))
3029
print("R = " + Data(unmarshalledSignature.r).toHexString())
3130
print("S = " + Data(unmarshalledSignature.s).toHexString())
3231
print("Personal hash = " + Web3.Utils.hashPersonalMessage(message.data(using: .utf8)!)!.toHexString())
33-
let recoveredSigner = web3.personal.ecrecover(personalMessage: message.data(using: .utf8)!, signature: signature)
34-
guard case .success(let signer) = recoveredSigner else {return XCTFail()}
32+
let signer = try web3.personal.ecrecover(personalMessage: message.data(using: .utf8)!, signature: signature)
3533
XCTAssert(expectedAddress == signer, "Failed to sign personal message")
3634
}
3735

@@ -43,8 +41,7 @@ class web3swift_rinkeby_personalSignature_Tests: XCTestCase {
4341
let message = "Hello World"
4442
let expectedAddress = keystoreManager.addresses![0]
4543
print(expectedAddress)
46-
let signRes = web3.personal.signPersonalMessage(message: message.data(using: .utf8)!, from: expectedAddress, password: "")
47-
guard case .success(let signature) = signRes else {return XCTFail()}
44+
let signature = try web3.personal.signPersonalMessage(message: message.data(using: .utf8)!, from: expectedAddress, password: "")
4845
let unmarshalledSignature = SECP256K1.unmarshalSignature(signatureData: signature)!
4946
print("V = " + String(unmarshalledSignature.v))
5047
print("R = " + Data(unmarshalledSignature.r).toHexString())

0 commit comments

Comments
 (0)