Skip to content

Commit 1035db1

Browse files
chore: merged with develop-4.0
2 parents 5ebb1d9 + f0905c2 commit 1035db1

29 files changed

+322
-313
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ web3.eth.send(transaction)
129129
let contract = web3.contract(Web3.Utils.erc20ABI, at: receipt.contractAddress!)!
130130
let readOp = contract.createReadOperation("name")!
131131
readOp.transaction.from = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")
132-
let response = try await readTX.callContractMethod()
132+
let response = try await readTX.call()
133133
```
134134

135135
### Write Transaction and call smart contract method

Sources/web3swift/Operations/ReadOperation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class ReadOperation {
3535
}
3636

3737
// TODO: Remove type erasing here, some broad wide protocol should be added instead
38-
public func callContractMethod() async throws -> [String: Any] {
38+
public func call() async throws -> [String: Any] {
3939
// MARK: Read data from ABI flow
4040
// FIXME: This should be dropped, and after `execute()` call, just to decode raw data.
4141
let data: Data = try await self.web3.eth.callTransaction(transaction)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public class ERC1155: IERC1155 {
7171
}
7272
guard contract.contract.address != nil else { return }
7373

74-
guard let tokenIdPromise = try await contract.createReadOperation("id")?.callContractMethod() else { return }
74+
guard let tokenIdPromise = try await contract.createReadOperation("id")?.call() else { return }
7575

7676
guard let tokenId = tokenIdPromise["0"] as? BigUInt else { return }
7777
self._tokenId = tokenId
@@ -95,7 +95,7 @@ public class ERC1155: IERC1155 {
9595
public func balanceOf(account: EthereumAddress, id: BigUInt) async throws -> BigUInt {
9696
let result = try await contract
9797
.createReadOperation("balanceOf", parameters: [account, id])!
98-
.callContractMethod()
98+
.call()
9999
guard let res = result["0"] as? BigUInt else { throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node") }
100100
return res
101101
}
@@ -107,14 +107,14 @@ public class ERC1155: IERC1155 {
107107
}
108108

109109
public func isApprovedForAll(owner: EthereumAddress, operator user: EthereumAddress, scope: Data) async throws -> Bool {
110-
let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope])!.callContractMethod()
110+
let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope])!.call()
111111

112112
guard let res = result["0"] as? Bool else { throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node") }
113113
return res
114114
}
115115

116116
public func supportsInterface(interfaceID: String) async throws -> Bool {
117-
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID])!.callContractMethod()
117+
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID])!.call()
118118

119119
guard let res = result["0"] as? Bool else { throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node") }
120120
return res

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

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
8989
}
9090

9191
public func getBalance(account: EthereumAddress) async throws -> BigUInt {
92-
let result = try await contract.createReadOperation("balanceOf", parameters: [account])!.callContractMethod()
92+
let result = try await contract.createReadOperation("balanceOf", parameters: [account])!.call()
9393

9494
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
9595
return res
9696
}
9797

9898
public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt {
99-
let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate])!.callContractMethod()
99+
let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate])!.call()
100100

101101
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
102102
return res
@@ -106,7 +106,8 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
106106
transaction.callOnBlock = .latest
107107
updateTransactionAndContract(from: from)
108108
// get the decimals manually
109-
let callResult = try await contract.createReadOperation("decimals")!.callContractMethod()
109+
let callResult = try await contract.createReadOperation("decimals")!.call()
110+
110111
var decimals = BigUInt(0)
111112
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
112113
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -124,7 +125,8 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
124125
transaction.callOnBlock = .latest
125126
updateTransactionAndContract(from: from)
126127
// get the decimals manually
127-
let callResult = try await contract.createReadOperation("decimals")!.callContractMethod()
128+
let callResult = try await contract.createReadOperation("decimals")!.call()
129+
128130
var decimals = BigUInt(0)
129131
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
130132
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -142,7 +144,8 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
142144
transaction.callOnBlock = .latest
143145
updateTransactionAndContract(from: from)
144146
// get the decimals manually
145-
let callResult = try await contract.createReadOperation("decimals")!.callContractMethod()
147+
let callResult = try await contract.createReadOperation("decimals")!.call()
148+
146149
var decimals = BigUInt(0)
147150
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
148151
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -160,7 +163,8 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
160163
transaction.callOnBlock = .latest
161164
updateTransactionAndContract(from: from)
162165
// get the decimals manually
163-
let callResult = try await contract.createReadOperation("decimals")!.callContractMethod()
166+
let callResult = try await contract.createReadOperation("decimals")!.call()
167+
164168
var decimals = BigUInt(0)
165169
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
166170
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -175,7 +179,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
175179
}
176180

177181
public func totalSupply() async throws -> BigUInt {
178-
let result = try await contract.createReadOperation("totalSupply")!.callContractMethod()
182+
let result = try await contract.createReadOperation("totalSupply")!.call()
179183

180184
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
181185
return res
@@ -185,7 +189,8 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
185189
transaction.callOnBlock = .latest
186190
updateTransactionAndContract(from: from)
187191
// get the decimals manually
188-
let callResult = try await contract.createReadOperation("decimals")!.callContractMethod()
192+
let callResult = try await contract.createReadOperation("decimals")!.call()
193+
189194
var decimals = BigUInt(0)
190195
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
191196
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -206,7 +211,8 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
206211
transaction.callOnBlock = .latest
207212
updateTransactionAndContract(from: from)
208213
// get the decimals manually
209-
let callResult = try await contract.createReadOperation("decimals")!.callContractMethod()
214+
let callResult = try await contract.createReadOperation("decimals")!.call()
215+
210216
var decimals = BigUInt(0)
211217
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
212218
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -224,7 +230,8 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
224230
transaction.callOnBlock = .latest
225231
updateTransactionAndContract(from: from)
226232
// get the decimals manually
227-
let callResult = try await contract.createReadOperation("decimals")!.callContractMethod()
233+
let callResult = try await contract.createReadOperation("decimals")!.call()
234+
228235
var decimals = BigUInt(0)
229236
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
230237
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -246,7 +253,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
246253

247254
func spendableAllowance(owner: EthereumAddress, spender: EthereumAddress) async throws -> BigUInt {
248255
transaction.callOnBlock = .latest
249-
let result = try await contract.createReadOperation("spendableAllowance", parameters: [owner, spender])!.callContractMethod()
256+
let result = try await contract.createReadOperation("spendableAllowance", parameters: [owner, spender])!.call()
250257

251258
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
252259
return res
@@ -256,7 +263,8 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
256263
transaction.callOnBlock = .latest
257264
updateTransactionAndContract(from: from)
258265
// get the decimals manually
259-
let callResult = try await contract.createReadOperation("decimals")!.callContractMethod()
266+
let callResult = try await contract.createReadOperation("decimals")!.call()
267+
260268
var decimals = BigUInt(0)
261269
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
262270
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -274,7 +282,8 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
274282
transaction.callOnBlock = .latest
275283
updateTransactionAndContract(from: from)
276284
// get the decimals manually
277-
let callResult = try await contract.createReadOperation("decimals")!.callContractMethod()
285+
let callResult = try await contract.createReadOperation("decimals")!.call()
286+
278287
var decimals = BigUInt(0)
279288
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
280289
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -289,7 +298,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
289298
}
290299

291300
func nonceOf(owner: EthereumAddress) async throws -> BigUInt {
292-
let result = try await contract.createReadOperation("nonceOf", parameters: [owner])!.callContractMethod()
301+
let result = try await contract.createReadOperation("nonceOf", parameters: [owner])!.call()
293302

294303
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
295304
return res
@@ -306,7 +315,8 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
306315
transaction.callOnBlock = .latest
307316
updateTransactionAndContract(from: from)
308317
// get the decimals manually
309-
let callResult = try await contract.createReadOperation("decimals")!.callContractMethod()
318+
let callResult = try await contract.createReadOperation("decimals")!.call()
319+
310320
var decimals = BigUInt(0)
311321
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
312322
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -323,7 +333,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
323333
}
324334

325335
func directDebit(debtor: EthereumAddress, receiver: EthereumAddress) async throws -> DirectDebit {
326-
let result = try await contract.createReadOperation("directDebit", parameters: [debtor, receiver])!.callContractMethod()
336+
let result = try await contract.createReadOperation("directDebit", parameters: [debtor, receiver])!.call()
327337

328338
guard let res = result["0"] as? DirectDebit else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
329339
return res

0 commit comments

Comments
 (0)