Skip to content

Renamed callContractMethod to call for ReadOperation #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ web3.eth.send(transaction)
let contract = web3.contract(Web3.Utils.erc20ABI, at: receipt.contractAddress!)!
let readOp = contract.createReadOperation("name")!
readOp.transaction.from = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")
let response = try await readTX.callContractMethod()
let response = try await readTX.call()
```

### Write Transaction and call smart contract method
Expand Down
2 changes: 1 addition & 1 deletion Sources/web3swift/Operations/ReadOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ReadOperation {
}

// TODO: Remove type erasing here, some broad wide protocol should be added instead
public func callContractMethod() async throws -> [String: Any] {
public func call() async throws -> [String: Any] {

// MARK: Read data from ABI flow
// FIXME: This should be dropped, and after `execute()` call, just to decode raw data.
Expand Down
8 changes: 4 additions & 4 deletions Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class ERC1155: IERC1155 {
}
guard contract.contract.address != nil else {return}

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

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

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

public func supportsInterface(interfaceID: String) async throws -> Bool {
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod()
let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.call()
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
return res
}
Expand Down
32 changes: 16 additions & 16 deletions Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
}

public func getBalance(account: EthereumAddress) async throws -> BigUInt {
let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod()
let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.call()
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
return res
}

public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt {
let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod()
let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.call()
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
return res
}
Expand All @@ -104,7 +104,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
transaction.callOnBlock = .latest
updateTransactionAndContract(from: from)
// get the decimals manually
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
let callResult = try await contract.createReadOperation("decimals" )!.call()
var decimals = BigUInt(0)
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
Expand All @@ -122,7 +122,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
transaction.callOnBlock = .latest
updateTransactionAndContract(from: from)
// get the decimals manually
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
let callResult = try await contract.createReadOperation("decimals" )!.call()
var decimals = BigUInt(0)
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
Expand All @@ -141,7 +141,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
transaction.callOnBlock = .latest
updateTransactionAndContract(from: from)
// get the decimals manually
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
let callResult = try await contract.createReadOperation("decimals" )!.call()
var decimals = BigUInt(0)
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
Expand All @@ -160,7 +160,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
transaction.callOnBlock = .latest
updateTransactionAndContract(from: from)
// get the decimals manually
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
let callResult = try await contract.createReadOperation("decimals" )!.call()
var decimals = BigUInt(0)
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
Expand All @@ -176,7 +176,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
}

public func totalSupply() async throws -> BigUInt {
let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod()
let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.call()
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
return res
}
Expand All @@ -185,7 +185,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
transaction.callOnBlock = .latest
updateTransactionAndContract(from: from)
// get the decimals manually
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
let callResult = try await contract.createReadOperation("decimals" )!.call()
var decimals = BigUInt(0)
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
Expand All @@ -207,7 +207,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
transaction.callOnBlock = .latest
updateTransactionAndContract(from: from)
// get the decimals manually
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
let callResult = try await contract.createReadOperation("decimals" )!.call()
var decimals = BigUInt(0)
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
Expand All @@ -226,7 +226,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
transaction.callOnBlock = .latest
updateTransactionAndContract(from: from)
// get the decimals manually
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
let callResult = try await contract.createReadOperation("decimals" )!.call()
var decimals = BigUInt(0)
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
Expand All @@ -249,7 +249,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {

func spendableAllowance(owner: EthereumAddress, spender: EthereumAddress) async throws -> BigUInt {
transaction.callOnBlock = .latest
let result = try await contract.createReadOperation("spendableAllowance", parameters: [owner, spender] as [AnyObject], extraData: Data())!.callContractMethod()
let result = try await contract.createReadOperation("spendableAllowance", parameters: [owner, spender] as [AnyObject], extraData: Data())!.call()
guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
return res
}
Expand All @@ -258,7 +258,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
transaction.callOnBlock = .latest
updateTransactionAndContract(from: from)
// get the decimals manually
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
let callResult = try await contract.createReadOperation("decimals" )!.call()
var decimals = BigUInt(0)
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
Expand All @@ -276,7 +276,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
transaction.callOnBlock = .latest
updateTransactionAndContract(from: from)
// get the decimals manually
let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod()
let callResult = try await contract.createReadOperation("decimals" )!.call()
var decimals = BigUInt(0)
guard let dec = callResult["0"], let decTyped = dec as? BigUInt else {
throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")}
Expand All @@ -291,7 +291,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties {
}

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

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