Skip to content

Commit 4e49d11

Browse files
committed
propagate Async changes
1 parent d88a493 commit 4e49d11

37 files changed

+705
-815
lines changed

Sources/web3swift/HookedFunctions/Web3+BrowserFunctions.swift

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import BigInt
99

1010
extension web3.BrowserFunctions {
1111

12-
public func getAccounts() -> [String]? {
12+
public func getAccounts() async -> [String]? {
1313
do {
14-
let accounts = try self.web3.eth.getAccounts()
14+
let accounts = try await self.web3.eth.getAccounts()
1515
return accounts.compactMap({$0.address})
1616
} catch {
1717
return [String]()
1818
}
1919
}
2020

21-
public func getCoinbase() -> String? {
22-
guard let addresses = self.getAccounts() else {return nil}
21+
public func getCoinbase() async -> String? {
22+
guard let addresses = await self.getAccounts() else {return nil}
2323
guard addresses.count > 0 else {return nil}
2424
return addresses[0]
2525
}
@@ -69,7 +69,7 @@ extension web3.BrowserFunctions {
6969
return Web3.Utils.publicToAddressString(publicKey)
7070
}
7171

72-
public func sendTransaction(_ transactionJSON: [String: Any], password: String = "web3swift") -> [String: Any]? {
72+
public func sendTransaction(_ transactionJSON: [String: Any], password: String = "web3swift") async -> [String: Any]? {
7373
do {
7474
let jsonData: Data = try JSONSerialization.data(withJSONObject: transactionJSON, options: [])
7575
let transaction: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
@@ -80,20 +80,20 @@ extension web3.BrowserFunctions {
8080
transactionOptions.value = options.value ?? 0
8181
transactionOptions.gasLimit = options.gasLimit ?? .automatic
8282
transactionOptions.gasPrice = options.gasPrice ?? .automatic
83-
return self.sendTransaction(transaction, transactionOptions: transactionOptions, password: password)
83+
return await self.sendTransaction(transaction, transactionOptions: transactionOptions, password: password)
8484
} catch { return nil }
8585
}
8686

87-
public func sendTransaction(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions, password: String = "web3swift") -> [String: Any]? {
87+
public func sendTransaction(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions, password: String = "web3swift") async -> [String: Any]? {
8888
do {
89-
let result = try self.web3.eth.sendTransaction(transaction, transactionOptions: transactionOptions, password: password)
89+
let result = try await self.web3.eth.sendTransaction(transaction, transactionOptions: transactionOptions, password: password)
9090
return ["txhash": result.hash]
9191
} catch {
9292
return nil
9393
}
9494
}
9595

96-
public func estimateGas(_ transactionJSON: [String: Any]) -> BigUInt? {
96+
public func estimateGas(_ transactionJSON: [String: Any]) async -> BigUInt? {
9797
do {
9898
let jsonData: Data = try JSONSerialization.data(withJSONObject: transactionJSON, options: [])
9999
let transaction: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
@@ -104,39 +104,39 @@ extension web3.BrowserFunctions {
104104
transactionOptions.value = options.value ?? 0
105105
transactionOptions.gasLimit = .automatic
106106
transactionOptions.gasPrice = options.gasPrice ?? .automatic
107-
return self.estimateGas(transaction, transactionOptions: transactionOptions)
107+
return await self.estimateGas(transaction, transactionOptions: transactionOptions)
108108
} catch { return nil }
109109
}
110110

111-
public func estimateGas(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions) -> BigUInt? {
111+
public func estimateGas(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions) async -> BigUInt? {
112112
do {
113-
let result = try self.web3.eth.estimateGas(transaction, transactionOptions: transactionOptions)
113+
let result = try await self.web3.eth.estimateGas(transaction, transactionOptions: transactionOptions)
114114
return result
115115
} catch {
116116
return nil
117117
}
118118
}
119119

120-
public func prepareTxForApproval(_ transactionJSON: [String: Any]) -> (transaction: EthereumTransaction?, options: TransactionOptions?) {
120+
public func prepareTxForApproval(_ transactionJSON: [String: Any]) async -> (transaction: EthereumTransaction?, options: TransactionOptions?) {
121121
do {
122122
let jsonData: Data = try JSONSerialization.data(withJSONObject: transactionJSON, options: [])
123123
let transaction: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
124124
let options: TransactionOptions = try JSONDecoder().decode(TransactionOptions.self, from: jsonData)
125-
return try self.prepareTxForApproval(transaction, options: options)
125+
return try await self.prepareTxForApproval(transaction, options: options)
126126
} catch {
127127
return (nil, nil)
128128
}
129129
}
130130

131-
public func prepareTxForApproval(_ trans: EthereumTransaction, options opts: TransactionOptions) throws -> (transaction: EthereumTransaction?, options: TransactionOptions?) {
131+
public func prepareTxForApproval(_ trans: EthereumTransaction, options opts: TransactionOptions) async throws -> (transaction: EthereumTransaction?, options: TransactionOptions?) {
132132
do {
133133
var transaction = trans
134134
var options = opts
135135
guard let _ = options.from else {return (nil, nil)}
136-
let gasPrice = try self.web3.eth.getGasPrice()
136+
let gasPrice = try await self.web3.eth.getGasPrice()
137137
transaction.gasPrice = gasPrice
138138
options.gasPrice = .manual(gasPrice)
139-
guard let gasEstimate = self.estimateGas(transaction, transactionOptions: options) else {return (nil, nil)}
139+
guard let gasEstimate = await self.estimateGas(transaction, transactionOptions: options) else {return (nil, nil)}
140140
transaction.gasLimit = gasEstimate
141141
options.gasLimit = .limited(gasEstimate)
142142
print(transaction)
@@ -146,7 +146,7 @@ extension web3.BrowserFunctions {
146146
}
147147
}
148148

149-
public func signTransaction(_ transactionJSON: [String: Any], password: String = "web3swift") -> String? {
149+
public func signTransaction(_ transactionJSON: [String: Any], password: String = "web3swift") async -> String? {
150150
do {
151151
let jsonData: Data = try JSONSerialization.data(withJSONObject: transactionJSON, options: [])
152152
let transaction: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
@@ -162,11 +162,11 @@ extension web3.BrowserFunctions {
162162
} else {
163163
transactionOptions.nonce = .pending
164164
}
165-
return self.signTransaction(transaction, transactionOptions: transactionOptions, password: password)
165+
return await self.signTransaction(transaction, transactionOptions: transactionOptions, password: password)
166166
} catch { return nil }
167167
}
168168

169-
public func signTransaction(_ trans: EthereumTransaction, transactionOptions: TransactionOptions, password: String = "web3swift") -> String? {
169+
public func signTransaction(_ trans: EthereumTransaction, transactionOptions: TransactionOptions, password: String = "web3swift") async -> String? {
170170
do {
171171
var transaction = trans
172172
guard let from = transactionOptions.from else {return nil}
@@ -178,23 +178,23 @@ extension web3.BrowserFunctions {
178178
case .manual(let gasPrice):
179179
transaction.gasPrice = gasPrice
180180
default:
181-
let gasPrice = try self.web3.eth.getGasPrice()
181+
let gasPrice = try await self.web3.eth.getGasPrice()
182182
transaction.gasPrice = gasPrice
183183
}
184184

185185
switch gasLimitPolicy {
186186
case .manual(let gasLimit):
187187
transaction.gasLimit = gasLimit
188188
default:
189-
let gasLimit = try self.web3.eth.estimateGas(transaction, transactionOptions: transactionOptions)
189+
let gasLimit = try await self.web3.eth.estimateGas(transaction, transactionOptions: transactionOptions)
190190
transaction.gasLimit = gasLimit
191191
}
192192

193193
switch noncePolicy {
194194
case .manual(let nonce):
195195
transaction.nonce = nonce
196196
default:
197-
let nonce = try self.web3.eth.getTransactionCount(address: from, onBlock: "pending")
197+
let nonce = try await self.web3.eth.getTransactionCount(address: from, onBlock: "pending")
198198
transaction.nonce = nonce
199199
}
200200

Sources/web3swift/Promises/Promise+Web3+Eth+SendRawTransaction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension web3.Eth {
3030
}
3131
let result = TransactionSendingResult(transaction: transaction, hash: value)
3232
for hook in self.web3.postSubmissionHooks {
33-
hook.queue.async {
33+
Task {
3434
hook.function(result)
3535
}
3636
}

Sources/web3swift/Promises/Promise+Web3+Eth+SendTransaction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extension web3.Eth {
4848
}
4949
let result = TransactionSendingResult(transaction: assembledTransaction, hash: value)
5050
for hook in self.web3.postSubmissionHooks {
51-
hook.queue.async {
51+
Task {
5252
hook.function(result)
5353
}
5454
}

Sources/web3swift/Tokens/ERC165/Web3+ERC165.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ import Foundation
1111
// Standard Interface Detection
1212
protocol IERC165 {
1313

14-
func supportsInterface(interfaceID: String) throws -> Bool
14+
func supportsInterface(interfaceID: String) async throws -> Bool
1515

1616
}

0 commit comments

Comments
 (0)