Skip to content

Commit 763ed34

Browse files
Merge pull request #735 from albertopeam/feature/rename-callContractMethod
Renamed callContractMethod to call for ReadOperation
2 parents 50d0d83 + 39eafd6 commit 763ed34

28 files changed

+263
-263
lines changed

README.md

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

130130
### 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

4040
// MARK: Read data from ABI flow
4141
// FIXME: This should be dropped, and after `execute()` call, just to decode raw data.

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

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

72-
guard let tokenIdPromise = try await contract.createReadOperation("id", parameters: [] as [AnyObject], extraData: Data())?.callContractMethod() else {return}
72+
guard let tokenIdPromise = try await contract.createReadOperation("id", parameters: [] as [AnyObject], extraData: Data())?.call() else {return}
7373

7474
guard let tokenId = tokenIdPromise["0"] as? BigUInt else {return}
7575
self._tokenId = tokenId
@@ -93,7 +93,7 @@ public class ERC1155: IERC1155 {
9393
public func balanceOf(account: EthereumAddress, id: BigUInt) async throws -> BigUInt {
9494
let result = try await contract
9595
.createReadOperation("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data())!
96-
.callContractMethod()
96+
.call()
9797
/*
9898
let result = try await contract
9999
.prepareToRead("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data())!
@@ -112,13 +112,13 @@ public class ERC1155: IERC1155 {
112112
}
113113

114114
public func isApprovedForAll(owner: EthereumAddress, operator user: EthereumAddress, scope: Data) async throws -> Bool {
115-
let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope] as [AnyObject], extraData: Data())!.callContractMethod()
115+
let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope] as [AnyObject], extraData: Data())!.call()
116116
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
117117
return res
118118
}
119119

120120
public func supportsInterface(interfaceID: String) async throws -> Bool {
121-
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod()
121+
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.call()
122122
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
123123
return res
124124
}

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ 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] as [AnyObject], extraData: Data())!.callContractMethod()
92+
let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.call()
9393
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
9494
return res
9595
}
9696

9797
public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt {
98-
let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod()
98+
let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.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
}
@@ -104,7 +104,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
104104
transaction.callOnBlock = .latest
105105
updateTransactionAndContract(from: from)
106106
// get the decimals manually
107-
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
107+
let callResult = try await contract.createReadOperation("decimals" )!.call()
108108
var decimals = BigUInt(0)
109109
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
110110
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -122,7 +122,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
122122
transaction.callOnBlock = .latest
123123
updateTransactionAndContract(from: from)
124124
// get the decimals manually
125-
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
125+
let callResult = try await contract.createReadOperation("decimals" )!.call()
126126
var decimals = BigUInt(0)
127127
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
128128
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -141,7 +141,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
141141
transaction.callOnBlock = .latest
142142
updateTransactionAndContract(from: from)
143143
// get the decimals manually
144-
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
144+
let callResult = try await contract.createReadOperation("decimals" )!.call()
145145
var decimals = BigUInt(0)
146146
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
147147
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -160,7 +160,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
160160
transaction.callOnBlock = .latest
161161
updateTransactionAndContract(from: from)
162162
// get the decimals manually
163-
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
163+
let callResult = try await contract.createReadOperation("decimals" )!.call()
164164
var decimals = BigUInt(0)
165165
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
166166
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -176,7 +176,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
176176
}
177177

178178
public func totalSupply() async throws -> BigUInt {
179-
let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod()
179+
let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.call()
180180
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
181181
return res
182182
}
@@ -185,7 +185,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
185185
transaction.callOnBlock = .latest
186186
updateTransactionAndContract(from: from)
187187
// get the decimals manually
188-
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
188+
let callResult = try await contract.createReadOperation("decimals" )!.call()
189189
var decimals = BigUInt(0)
190190
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
191191
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -207,7 +207,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
207207
transaction.callOnBlock = .latest
208208
updateTransactionAndContract(from: from)
209209
// get the decimals manually
210-
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
210+
let callResult = try await contract.createReadOperation("decimals" )!.call()
211211
var decimals = BigUInt(0)
212212
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
213213
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -226,7 +226,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
226226
transaction.callOnBlock = .latest
227227
updateTransactionAndContract(from: from)
228228
// get the decimals manually
229-
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
229+
let callResult = try await contract.createReadOperation("decimals" )!.call()
230230
var decimals = BigUInt(0)
231231
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
232232
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -249,7 +249,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
249249

250250
func spendableAllowance(owner: EthereumAddress, spender: EthereumAddress) async throws -> BigUInt {
251251
transaction.callOnBlock = .latest
252-
let result = try await contract.createReadOperation("spendableAllowance", parameters: [owner, spender] as [AnyObject], extraData: Data())!.callContractMethod()
252+
let result = try await contract.createReadOperation("spendableAllowance", parameters: [owner, spender] as [AnyObject], extraData: Data())!.call()
253253
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
254254
return res
255255
}
@@ -258,7 +258,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
258258
transaction.callOnBlock = .latest
259259
updateTransactionAndContract(from: from)
260260
// get the decimals manually
261-
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
261+
let callResult = try await contract.createReadOperation("decimals" )!.call()
262262
var decimals = BigUInt(0)
263263
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
264264
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -276,7 +276,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
276276
transaction.callOnBlock = .latest
277277
updateTransactionAndContract(from: from)
278278
// get the decimals manually
279-
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
279+
let callResult = try await contract.createReadOperation("decimals" )!.call()
280280
var decimals = BigUInt(0)
281281
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
282282
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -291,7 +291,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
291291
}
292292

293293
func nonceOf(owner: EthereumAddress) async throws -> BigUInt {
294-
let result = try await contract.createReadOperation("nonceOf", parameters: [owner] as [AnyObject], extraData: Data())!.callContractMethod()
294+
let result = try await contract.createReadOperation("nonceOf", parameters: [owner] as [AnyObject], extraData: Data())!.call()
295295
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
296296
return res
297297
}
@@ -307,7 +307,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
307307
transaction.callOnBlock = .latest
308308
updateTransactionAndContract(from: from)
309309
// get the decimals manually
310-
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
310+
let callResult = try await contract.createReadOperation("decimals" )!.call()
311311
var decimals = BigUInt(0)
312312
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
313313
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
@@ -325,7 +325,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
325325
}
326326

327327
func directDebit(debtor: EthereumAddress, receiver: EthereumAddress) async throws -> DirectDebit {
328-
let result = try await contract.createReadOperation("directDebit", parameters: [debtor, receiver] as [AnyObject], extraData: Data())!.callContractMethod()
328+
let result = try await contract.createReadOperation("directDebit", parameters: [debtor, receiver] as [AnyObject], extraData: Data())!.call()
329329
guard let res = result["0"] as? DirectDebit else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
330330
return res
331331
}

0 commit comments

Comments
 (0)