From 62f3e977b259717e8525333ce5c0d0cf752d12f1 Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Thu, 15 Dec 2022 14:54:04 +0700 Subject: [PATCH 01/23] This one fixing the ERC20 implementation bug, where `ERC20.transaction` never assigns to `Contract.transaction` for any given method that writes on chain. Obviously it's a bug spreading all over the `Token` implementation. So this fix should be applied to all `ERC*.swift` methods that returns `WriteOperation`. This is the special case of #712. Closes #711 --- Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift index d1aeba7ea..40fdef136 100644 --- a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift +++ b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift @@ -62,7 +62,6 @@ public class ERC20: IERC20, ERC20BaseProperties { } public func transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract self.transaction.from = from self.transaction.to = self.address self.transaction.callOnBlock = .latest @@ -80,12 +79,12 @@ public class ERC20: IERC20, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } + contract.transaction = transaction let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject] )! return tx } public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract self.transaction.from = from self.transaction.to = self.address self.transaction.callOnBlock = .latest @@ -103,7 +102,7 @@ public class ERC20: IERC20, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - + contract.transaction = transaction let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject] )! return tx } @@ -133,7 +132,6 @@ public class ERC20: IERC20, ERC20BaseProperties { } public func approve(from: EthereumAddress, spender: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract self.transaction.from = from self.transaction.to = self.address self.transaction.callOnBlock = .latest @@ -151,7 +149,7 @@ public class ERC20: IERC20, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - + contract.transaction = transaction let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject] )! return tx } From aa4d563c9e9954668a38066e8feaef26fa0676a4 Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Thu, 22 Dec 2022 14:58:30 +0700 Subject: [PATCH 02/23] Fixing review issues. --- Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift index 40fdef136..c35316753 100644 --- a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift +++ b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift @@ -108,7 +108,6 @@ public class ERC20: IERC20, ERC20BaseProperties { } public func setAllowance(from: EthereumAddress, to: EthereumAddress, newAmount: String) async throws -> WriteOperation { - let contract = self.contract self.transaction.from = from self.transaction.to = self.address self.transaction.callOnBlock = .latest @@ -126,7 +125,7 @@ public class ERC20: IERC20, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(newAmount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - + contract.transaction = transaction let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject] )! return tx } @@ -155,7 +154,6 @@ public class ERC20: IERC20, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - let contract = self.contract self.transaction.callOnBlock = .latest let result = try await contract .createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )! From 8f05fe35be1b51cfb1b394a91749811a31b25aad Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 09:23:32 +0100 Subject: [PATCH 03/23] Fix ERC721 --- .../web3swift/Tokens/ERC721/Web3+ERC721.swift | 59 +++++++++---------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift b/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift index 9a5887eab..3f8c0ac53 100644 --- a/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift +++ b/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift @@ -85,7 +85,6 @@ public class ERC721: IERC721 { } public func readProperties() async throws { - if self._hasReadProperties { return } @@ -128,56 +127,38 @@ public class ERC721: IERC721 { } public func transfer(from: EthereumAddress, to: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId] as [AnyObject])! return tx } public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject])! return tx } public func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject])! return tx } public func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt, data: [UInt8]) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, data] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, data] as [AnyObject])! return tx } public func approve(from: EthereumAddress, approved: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("approve", parameters: [approved, tokenId] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("approve", parameters: [approved, tokenId] as [AnyObject])! return tx } public func setApprovalForAll(from: EthereumAddress, operator user: EthereumAddress, approved: Bool) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved] as [AnyObject])! return tx } @@ -199,6 +180,20 @@ public class ERC721: IERC721 { } +// MARK: - Private + +extension ERC721 { + + private func updateTransactionAndContract(from: EthereumAddress) { + transaction.from = from + transaction.to = address + contract.transaction = transaction + } + +} + +// MARK: - IERC721Enumerable + extension ERC721: IERC721Enumerable { public func totalSupply() async throws -> BigUInt { @@ -227,6 +222,8 @@ extension ERC721: IERC721Enumerable { } +// MARK: - IERC721Metadata + // FIXME: Rewrite this to CodableTransaction extension ERC721: IERC721Metadata { From 96b6462db5c7935ed32ff94510483ba06c9e49d3 Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 09:25:46 +0100 Subject: [PATCH 04/23] Clean up --- .../web3swift/Tokens/ERC721/Web3+ERC721.swift | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift b/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift index 3f8c0ac53..786bda260 100644 --- a/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift +++ b/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift @@ -88,7 +88,6 @@ public class ERC721: IERC721 { if self._hasReadProperties { return } - let contract = self.contract guard contract.contract.address != nil else {return} self.transaction.callOnBlock = .latest @@ -103,16 +102,14 @@ public class ERC721: IERC721 { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data() )!.callContractMethod() 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 getOwner(tokenId: BigUInt) async throws -> EthereumAddress { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("ownerOf", parameters: [tokenId] as [AnyObject], extraData: Data() )!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -120,7 +117,7 @@ public class ERC721: IERC721 { public func getApproved(tokenId: BigUInt) async throws -> EthereumAddress { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getApproved", parameters: [tokenId] as [AnyObject], extraData: Data() )!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -163,15 +160,13 @@ public class ERC721: IERC721 { } public func isApprovedForAll(owner: EthereumAddress, operator user: EthereumAddress) async throws -> Bool { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user] as [AnyObject], extraData: Data() )!.callContractMethod() 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 contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data() )!.callContractMethod() guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -197,24 +192,21 @@ extension ERC721 { extension ERC721: IERC721Enumerable { public func totalSupply() async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() 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 tokenByIndex(index: BigUInt) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("tokenByIndex", parameters: [index] as [AnyObject], extraData: Data() )!.callContractMethod() 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 tokenOfOwnerByIndex(owner: EthereumAddress, index: BigUInt) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("tokenOfOwnerByIndex", parameters: [owner, index] as [AnyObject], extraData: Data() )!.callContractMethod() 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 @@ -228,24 +220,21 @@ extension ERC721: IERC721Enumerable { extension ERC721: IERC721Metadata { public func name() async throws -> String { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("name", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func symbol() async throws -> String { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("symbol", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func tokenURI(tokenId: BigUInt) async throws -> String { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("tokenURI", parameters: [tokenId] as [AnyObject], extraData: Data() )!.callContractMethod() guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res From 10f51bb891c2e0e30d26909a251f3aed383aa0ec Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 10:36:05 +0100 Subject: [PATCH 05/23] Fix ERC721x --- .../Tokens/ERC721x/Web3+ERC721x.swift | 67 +++++++------------ 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift b/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift index 7285b48c9..1d82fd28e 100644 --- a/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift +++ b/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift @@ -110,55 +110,37 @@ public class ERC721x: IERC721x { } public func transfer(from: EthereumAddress, to: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId] as [AnyObject] )! return tx } public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject] )! return tx } public func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject] )! return tx } public func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt, data: [UInt8]) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, data] as [AnyObject] )! return tx } public func approve(from: EthereumAddress, approved: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("approve", parameters: [approved, tokenId] as [AnyObject] )! return tx } public func setApprovalForAll(from: EthereumAddress, operator user: EthereumAddress, approved: Bool) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved] as [AnyObject] )! return tx } @@ -252,47 +234,44 @@ public class ERC721x: IERC721x { } func transfer(from: EthereumAddress, to: EthereumAddress, tokenId: BigUInt, quantity: BigUInt) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId, quantity] as [AnyObject] )! return tx } func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt, quantity: BigUInt) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId, quantity] as [AnyObject] )! return tx } func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt, amount: BigUInt) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount] as [AnyObject] )! return tx } func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt, amount: BigUInt, data: [UInt8]) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount, data] as [AnyObject] )! return tx } func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenIds: [BigUInt], amounts: [BigUInt], data: [UInt8]) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenIds, amounts, data] as [AnyObject] )! return tx } } + +// MARK: - Private + +extension ERC721x { + + private func updateTransactionAndContract(from: EthereumAddress) { + transaction.from = from + transaction.to = address + contract.transaction = transaction + } + +} From 68372edc40c55039a76ce4893083418d070ff5ad Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 10:38:05 +0100 Subject: [PATCH 06/23] Clean up --- .../Tokens/ERC721x/Web3+ERC721x.swift | 45 +++++++------------ 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift b/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift index 1d82fd28e..50bc7e648 100644 --- a/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift +++ b/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift @@ -73,9 +73,8 @@ public class ERC721x: IERC721x { if self._hasReadProperties { return } - let contract = self.contract guard contract.contract.address != nil else {return} - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest guard let tokenIdPromise = try await contract.createReadOperation("tokenId", parameters: [] as [AnyObject], extraData: Data())?.callContractMethod() else {return} @@ -86,24 +85,21 @@ public class ERC721x: IERC721x { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data() )!.callContractMethod() 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 getOwner(tokenId: BigUInt) async throws -> EthereumAddress { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("ownerOf", parameters: [tokenId] as [AnyObject], extraData: Data() )!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func getApproved(tokenId: BigUInt) async throws -> EthereumAddress { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getApproved", parameters: [tokenId] as [AnyObject], extraData: Data() )!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -146,88 +142,77 @@ public class ERC721x: IERC721x { } public func isApprovedForAll(owner: EthereumAddress, operator user: EthereumAddress) async throws -> Bool { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user] as [AnyObject], extraData: Data() )!.callContractMethod() 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 contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data() )!.callContractMethod() 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 totalSupply() async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() 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 tokenByIndex(index: BigUInt) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("tokenByIndex", parameters: [index] as [AnyObject], extraData: Data() )!.callContractMethod() 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 tokenOfOwnerByIndex(owner: EthereumAddress, index: BigUInt) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("tokenOfOwnerByIndex", parameters: [owner, index] as [AnyObject], extraData: Data() )!.callContractMethod() 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 name() async throws -> String { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("name", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func symbol() async throws -> String { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("symbol", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func tokenURI(tokenId: BigUInt) async throws -> String { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("tokenURI", parameters: [tokenId] as [AnyObject], extraData: Data() )!.callContractMethod() guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } func implementsERC721X() async throws -> Bool { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("implementsERC721X", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() 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 } func getBalance(account: EthereumAddress, tokenId: BigUInt) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account, tokenId] as [AnyObject], extraData: Data() )!.callContractMethod() 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 } func tokensOwned(account: EthereumAddress) async throws -> ([BigUInt], [BigUInt]) { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("tokensOwned", parameters: [account] as [AnyObject], extraData: Data() )!.callContractMethod() guard let res = result["0"] as? ([BigUInt], [BigUInt]) else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res From 7178a204099af143db62c86bdbe552246253c374 Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 10:45:17 +0100 Subject: [PATCH 07/23] Fix ERC777 --- .../web3swift/Tokens/ERC777/Web3+ERC777.swift | 153 +++++++----------- 1 file changed, 59 insertions(+), 94 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift index 4ef3be52f..18042ab4e 100644 --- a/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift +++ b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift @@ -57,43 +57,36 @@ public class ERC777: IERC777, ERC20BaseProperties { } public func getGranularity() async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("granularity", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() 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 getDefaultOperators() async throws -> [EthereumAddress] { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("defaultOperators", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() guard let res = result["0"] as? [EthereumAddress] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data() )!.callContractMethod() 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 contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data() )!.callContractMethod() 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 transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -105,16 +98,13 @@ public class ERC777: IERC777, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject])! return tx } public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -127,16 +117,13 @@ public class ERC777: IERC777, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject])! return tx } public func setAllowance(from: EthereumAddress, to: EthereumAddress, newAmount: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -149,13 +136,12 @@ public class ERC777: IERC777, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject])! return tx } public func totalSupply() async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() 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 @@ -163,39 +149,29 @@ public class ERC777: IERC777, ERC20BaseProperties { // ERC777 methods public func authorize(from: EthereumAddress, operator user: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - - let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] as [AnyObject] )! + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] as [AnyObject])! return tx } public func revoke(from: EthereumAddress, operator user: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - - let tx = contract.createWriteOperation("revokeOperator", parameters: [user] as [AnyObject] )! + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("revokeOperator", parameters: [user] as [AnyObject])! return tx } public func isOperatorFor(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperatorFor", parameters: [user, tokenHolder] as [AnyObject], extraData: Data() )!.callContractMethod() 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 send(from: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -207,16 +183,13 @@ public class ERC777: IERC777, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("send", parameters: [to, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("send", parameters: [to, value, data] as [AnyObject])! return tx } public func operatorSend(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String, data: [UInt8], operatorData: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -233,11 +206,8 @@ public class ERC777: IERC777, ERC20BaseProperties { } public func burn(from: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -249,16 +219,13 @@ public class ERC777: IERC777, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("burn", parameters: [value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("burn", parameters: [value, data] as [AnyObject])! return tx } public func operatorBurn(from: EthereumAddress, amount: String, originalOwner: EthereumAddress, data: [UInt8], operatorData: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -270,67 +237,53 @@ public class ERC777: IERC777, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("burn", parameters: [originalOwner, value, data, operatorData] as [AnyObject] )! + let tx = contract.createWriteOperation("burn", parameters: [originalOwner, value, data, operatorData] as [AnyObject])! return tx } public func canImplementInterfaceForAddress(interfaceHash: Data, addr: EthereumAddress) async throws -> Data { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("canImplementInterfaceForAddress", parameters: [interfaceHash, addr] as [AnyObject], extraData: Data() )!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func getInterfaceImplementer(addr: EthereumAddress, interfaceHash: Data) async throws -> EthereumAddress { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getInterfaceImplementer", parameters: [addr, interfaceHash] as [AnyObject], extraData: Data() )!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func setInterfaceImplementer(from: EthereumAddress, addr: EthereumAddress, interfaceHash: Data, implementer: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("setInterfaceImplementer", parameters: [addr, interfaceHash, implementer] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("setInterfaceImplementer", parameters: [addr, interfaceHash, implementer] as [AnyObject])! return tx } public func setManager(from: EthereumAddress, addr: EthereumAddress, newManager: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("setManager", parameters: [addr, newManager] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("setManager", parameters: [addr, newManager] as [AnyObject])! return tx } public func interfaceHash(interfaceName: String) async throws -> Data { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("interfaceHash", parameters: [interfaceName] as [AnyObject], extraData: Data() )!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } + // FIXME: might want to rename contract param here public func updateERC165Cache(from: EthereumAddress, contract: EthereumAddress, interfaceId: [UInt8]) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = self.contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId] as [AnyObject])! return tx } public func approve(from: EthereumAddress, spender: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -343,16 +296,28 @@ public class ERC777: IERC777, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject])! return tx } public func supportsInterface(interfaceID: String) async throws -> Bool { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data() )!.callContractMethod() 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 } } + +// MARK: - Private + +extension ERC777 { + + private func updateTransactionAndContract(from: EthereumAddress) { + transaction.from = from + transaction.to = address + contract.transaction = transaction + } + +} + From 2d38fd07a0a70d40484ab9be293675fd4d3870d3 Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 10:47:10 +0100 Subject: [PATCH 08/23] Fix ERC8888 --- .../web3swift/Tokens/ERC888/Web3+ERC888.swift | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift b/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift index 46a0dc8f0..99277c68d 100644 --- a/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift +++ b/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift @@ -39,31 +39,28 @@ public class ERC888: IERC888, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data() )!.callContractMethod() + transaction.callOnBlock = .latest + let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.from = from + transaction.to = address + transaction.callOnBlock = .latest + contract.transaction = transaction // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() 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")} decimals = decTyped - let intDecimals = Int(decimals) guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject])! return tx } From 0595214d1e8584867a69a625526e5962d56f7aa5 Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 10:57:27 +0100 Subject: [PATCH 09/23] Fix ERC1155 --- .../Tokens/ERC1155/Web3+ERC1155.swift | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift b/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift index 2ddb502a3..68190c615 100644 --- a/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift +++ b/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift @@ -67,9 +67,8 @@ public class ERC1155: IERC1155 { if self._hasReadProperties { return } - let contract = self.contract guard contract.contract.address != nil else {return} - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest guard let tokenIdPromise = try await contract.createReadOperation("id", parameters: [] as [AnyObject], extraData: Data())?.callContractMethod() else {return} @@ -80,31 +79,23 @@ public class ERC1155: IERC1155 { } public func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, id: BigUInt, value: BigUInt, data: [UInt8]) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, id, value, data] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, id, value, data] as [AnyObject])! return tx } public func safeBatchTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, ids: [BigUInt], values: [BigUInt], data: [UInt8]) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract - .createWriteOperation("safeBatchTransferFrom", parameters: [originalOwner, to, ids, values, data] as [AnyObject] )! + .createWriteOperation("safeBatchTransferFrom", parameters: [originalOwner, to, ids, values, data] as [AnyObject])! return tx } public func balanceOf(account: EthereumAddress, id: BigUInt) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract - .createReadOperation("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data() )! + .createReadOperation("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data())! .callContractMethod() - /* let result = try await contract .prepareToRead("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data() )! @@ -117,27 +108,34 @@ public class ERC1155: IERC1155 { } public func setApprovalForAll(from: EthereumAddress, operator user: EthereumAddress, approved: Bool, scope: Data) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved, scope] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved, scope] as [AnyObject])! return tx } public func isApprovedForAll(owner: EthereumAddress, operator user: EthereumAddress, scope: Data) async throws -> Bool { - let contract = self.contract - self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope] as [AnyObject], extraData: Data() )!.callContractMethod() + transaction.callOnBlock = .latest + let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope] as [AnyObject], extraData: Data())!.callContractMethod() 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 contract = self.contract - self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data() )!.callContractMethod() + transaction.callOnBlock = .latest + let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod() 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 } } + +// MARK: - Private + +extension ERC1155 { + + private func updateTransactionAndContract(from: EthereumAddress) { + transaction.from = from + transaction.to = address + contract.transaction = transaction + } + +} From 1f51147f8e6f4d753bcfac6d9fd54b7861e1cdcc Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 11:55:22 +0100 Subject: [PATCH 10/23] Fix ERC1376 --- .../Tokens/ERC1376/Web3+ERC1376.swift | 169 +++++++----------- 1 file changed, 64 insertions(+), 105 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift b/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift index f3570578b..a6fb8d54d 100644 --- a/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift +++ b/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift @@ -89,27 +89,22 @@ public class ERC1376: IERC1376, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data() )!.callContractMethod() + transaction.callOnBlock = .latest + let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 contract = self.contract - self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data() )!.callContractMethod() + transaction.callOnBlock = .latest + let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -121,16 +116,13 @@ public class ERC1376: IERC1376, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject])! return tx } public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -143,16 +135,13 @@ public class ERC1376: IERC1376, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject])! return tx } public func setAllowance(from: EthereumAddress, to: EthereumAddress, newAmount: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -165,16 +154,13 @@ public class ERC1376: IERC1376, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject])! return tx } public func approve(from: EthereumAddress, spender: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -187,24 +173,20 @@ public class ERC1376: IERC1376, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject])! return tx } public func totalSupply() async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + transaction.callOnBlock = .latest + let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 } func approve(from: EthereumAddress, spender: EthereumAddress, expectedValue: String, newValue: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -220,16 +202,13 @@ public class ERC1376: IERC1376, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, eValue, nValue] as [AnyObject] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, eValue, nValue] as [AnyObject])! return tx } func increaseAllowance(from: EthereumAddress, spender: EthereumAddress, value: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -242,16 +221,13 @@ public class ERC1376: IERC1376, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("increaseAllowance", parameters: [spender, amount] as [AnyObject] )! + let tx = contract.createWriteOperation("increaseAllowance", parameters: [spender, amount] as [AnyObject])! return tx } func decreaseAllowance(from: EthereumAddress, spender: EthereumAddress, value: String, strict: Bool) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -264,33 +240,26 @@ public class ERC1376: IERC1376, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("decreaseAllowance", parameters: [spender, amount, strict] as [AnyObject] )! + let tx = contract.createWriteOperation("decreaseAllowance", parameters: [spender, amount, strict] as [AnyObject])! return tx } func setERC20ApproveChecking(from: EthereumAddress, approveChecking: Bool) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("setERC20ApproveChecking", parameters: [approveChecking] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("setERC20ApproveChecking", parameters: [approveChecking] as [AnyObject])! return tx } func spendableAllowance(owner: EthereumAddress, spender: EthereumAddress) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("spendableAllowance", parameters: [owner, spender] as [AnyObject], extraData: Data() )!.callContractMethod() + transaction.callOnBlock = .latest + let result = try await contract.createReadOperation("spendableAllowance", parameters: [owner, spender] as [AnyObject], extraData: Data())!.callContractMethod() 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 } func transfer(from: EthereumAddress, data: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -302,16 +271,13 @@ public class ERC1376: IERC1376, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(data, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transfer", parameters: [value] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [value] as [AnyObject])! return tx } func transferAndCall(from: EthereumAddress, to: EthereumAddress, value: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -328,29 +294,22 @@ public class ERC1376: IERC1376, ERC20BaseProperties { } func nonceOf(owner: EthereumAddress) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("nonceOf", parameters: [owner] as [AnyObject], extraData: Data() )!.callContractMethod() 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 } func increaseNonce(from: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("increaseNonce", parameters: [] as [AnyObject] )! return tx } func delegateTransferAndCall(from: EthereumAddress, nonce: BigUInt, fee: BigUInt, gasAmount: BigUInt, to: EthereumAddress, value: String, data: [UInt8], mode: IERC1376DelegateMode, v: UInt8, r: Data, s: Data) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -370,46 +329,46 @@ public class ERC1376: IERC1376, ERC20BaseProperties { } func directDebit(debtor: EthereumAddress, receiver: EthereumAddress) async throws -> DirectDebit { - let contract = self.contract - self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("directDebit", parameters: [debtor, receiver] as [AnyObject], extraData: Data() )!.callContractMethod() + transaction.callOnBlock = .latest + let result = try await contract.createReadOperation("directDebit", parameters: [debtor, receiver] as [AnyObject], extraData: Data())!.callContractMethod() 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 } func setupDirectDebit(from: EthereumAddress, receiver: EthereumAddress, info: DirectDebitInfo) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("setupDirectDebit", parameters: [receiver, info] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("setupDirectDebit", parameters: [receiver, info] as [AnyObject])! return tx } func terminateDirectDebit(from: EthereumAddress, receiver: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("terminateDirectDebit", parameters: [receiver] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("terminateDirectDebit", parameters: [receiver] as [AnyObject])! return tx } func withdrawDirectDebit(from: EthereumAddress, debtor: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("withdrawDirectDebit", parameters: [debtor] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("withdrawDirectDebit", parameters: [debtor] as [AnyObject])! return tx } func withdrawDirectDebit(from: EthereumAddress, debtors: [EthereumAddress], strict: Bool) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("withdrawDirectDebit", parameters: [debtors, strict] as [AnyObject] )! + updateTransactionAndContract(from: from) + let tx = contract.createWriteOperation("withdrawDirectDebit", parameters: [debtors, strict] as [AnyObject])! return tx } } + +// MARK: - Private + +extension ERC1376 { + + private func updateTransactionAndContract(from: EthereumAddress) { + transaction.from = from + transaction.to = address + contract.transaction = transaction + } + +} + From 0932502407324968eda9d9e47521f9447de2032c Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 12:00:08 +0100 Subject: [PATCH 11/23] Fix ST20 --- Sources/web3swift/Tokens/ST20/Web3+ST20.swift | 84 ++++++++----------- 1 file changed, 33 insertions(+), 51 deletions(-) diff --git a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift index 71097eb27..bf50d0664 100644 --- a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift +++ b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift @@ -50,20 +50,15 @@ public class ST20: IST20, ERC20BaseProperties { } func tokenDetails() async throws -> [UInt32] { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("tokenDetails", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() guard let res = result["0"] as? [UInt32] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } func verifyTransfer(from: EthereumAddress, originalOwner: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -81,12 +76,8 @@ public class ST20: IST20, ERC20BaseProperties { } func mint(from: EthereumAddress, investor: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -104,12 +95,8 @@ public class ST20: IST20, ERC20BaseProperties { } public func burn(from: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -126,28 +113,22 @@ public class ST20: IST20, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data() )!.callContractMethod() 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 contract = self.contract - self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data() )!.callContractMethod() + transaction.callOnBlock = .latest + let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -164,12 +145,8 @@ public class ST20: IST20, ERC20BaseProperties { } public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -187,12 +164,8 @@ public class ST20: IST20, ERC20BaseProperties { } public func setAllowance(from: EthereumAddress, to: EthereumAddress, newAmount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -210,12 +183,8 @@ public class ST20: IST20, ERC20BaseProperties { } public func approve(from: EthereumAddress, spender: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -233,11 +202,24 @@ public class ST20: IST20, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() 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 } } + +// MARK: - Private + +extension ST20 { + + private func updateTransactionAndContract(from: EthereumAddress) { + transaction.from = from + transaction.to = address + contract.transaction = transaction + } + +} + + From 7c421d86b1a2d8589a7684f66098b64cc4dcc0ff Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 12:02:55 +0100 Subject: [PATCH 12/23] Delete all the blank spaces --- .../Tokens/ERC1155/Web3+ERC1155.swift | 2 +- .../Tokens/ERC1376/Web3+ERC1376.swift | 8 +- .../Tokens/ERC1400/Web3+ERC1400.swift | 100 +++++++++--------- .../Tokens/ERC1410/Web3+ERC1410.swift | 74 ++++++------- .../Tokens/ERC1594/Web3+ERC1594.swift | 30 +++--- .../Tokens/ERC1633/Web3+ERC1633.swift | 20 ++-- .../Tokens/ERC1643/Web3+ERC1643.swift | 22 ++-- .../Tokens/ERC1644/Web3+ERC1644.swift | 20 ++-- .../web3swift/Tokens/ERC20/Web3+ERC20.swift | 14 +-- .../web3swift/Tokens/ERC721/Web3+ERC721.swift | 22 ++-- .../Tokens/ERC721x/Web3+ERC721x.swift | 50 ++++----- .../web3swift/Tokens/ERC777/Web3+ERC777.swift | 22 ++-- Sources/web3swift/Tokens/ST20/Web3+ST20.swift | 20 ++-- .../Utils/ENS/ENSBaseRegistrar.swift | 12 +-- Sources/web3swift/Utils/ENS/ENSRegistry.swift | 14 +-- .../Utils/ENS/ENSReverseRegistrar.swift | 10 +- .../Utils/ENS/ETHRegistrarController.swift | 16 +-- 17 files changed, 228 insertions(+), 228 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift b/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift index 68190c615..7a8987be7 100644 --- a/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift +++ b/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift @@ -98,7 +98,7 @@ public class ERC1155: IERC1155 { .callContractMethod() /* let result = try await contract - .prepareToRead("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data() )! + .prepareToRead("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data())! .execute() .decodeData() diff --git a/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift b/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift index a6fb8d54d..9e92bc722 100644 --- a/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift +++ b/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift @@ -289,13 +289,13 @@ public class ERC1376: IERC1376, ERC20BaseProperties { guard let amount = Utilities.parseToBigUInt(value, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferAndCall", parameters: [to, amount, data] as [AnyObject] )! + let tx = contract.createWriteOperation("transferAndCall", parameters: [to, amount, data] as [AnyObject])! return tx } func nonceOf(owner: EthereumAddress) async throws -> BigUInt { transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -303,7 +303,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { func increaseNonce(from: EthereumAddress) throws -> WriteOperation { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) - let tx = contract.createWriteOperation("increaseNonce", parameters: [] as [AnyObject] )! + let tx = contract.createWriteOperation("increaseNonce", parameters: [] as [AnyObject])! return tx } @@ -324,7 +324,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { let modeValue = mode.rawValue - let tx = contract.createWriteOperation("delegateTransferAndCall", parameters: [nonce, fee, gasAmount, to, amount, data, modeValue, v, r, s] as [AnyObject] )! + let tx = contract.createWriteOperation("delegateTransferAndCall", parameters: [nonce, fee, gasAmount, to, amount, data, modeValue, v, r, s] as [AnyObject])! return tx } diff --git a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift index 98d98360f..080090ad1 100644 --- a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift +++ b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift @@ -88,7 +88,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { public func getBalance(account: EthereumAddress) async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -96,7 +96,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -118,7 +118,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject])! return tx } @@ -140,7 +140,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject])! return tx } @@ -162,14 +162,14 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject])! return tx } public func totalSupply() async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 } @@ -191,7 +191,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject])! return tx } @@ -199,7 +199,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { public func getDocument(name: Data) async throws -> (String, Data) { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("getDocument", parameters: [name] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("getDocument", parameters: [name] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? (String, Data) else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -209,14 +209,14 @@ public class ERC1400: IERC1400, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setDocument", parameters: [name, uri, documentHash] as [AnyObject] )! + let tx = contract.createWriteOperation("setDocument", parameters: [name, uri, documentHash] as [AnyObject])! return tx } public func balanceOfByPartition(partition: Data, tokenHolder: EthereumAddress) async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("balanceOfByPartition", parameters: [partition, tokenHolder] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("balanceOfByPartition", parameters: [partition, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 } @@ -224,7 +224,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { public func partitionsOf(tokenHolder: EthereumAddress) async throws -> [Data] { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("partitionsOf", parameters: [tokenHolder] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("partitionsOf", parameters: [tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [Data] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -247,7 +247,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferWithData", parameters: [to, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("transferWithData", parameters: [to, value, data] as [AnyObject])! return tx } @@ -269,7 +269,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFromWithData", parameters: [originalOwner, to, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFromWithData", parameters: [originalOwner, to, value, data] as [AnyObject])! return tx } @@ -291,7 +291,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferByPartition", parameters: [partition, to, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("transferByPartition", parameters: [partition, to, value, data] as [AnyObject])! return tx } @@ -313,14 +313,14 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("operatorTransferByPartition", parameters: [partition, originalOwner, to, value, data, operatorData] as [AnyObject] )! + let tx = contract.createWriteOperation("operatorTransferByPartition", parameters: [partition, originalOwner, to, value, data, operatorData] as [AnyObject])! return tx } public func isControllable() async throws -> Bool { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("isControllable", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("isControllable", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 } @@ -343,7 +343,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("controllerTransfer", parameters: [originalOwner, to, value, data, operatorData] as [AnyObject] )! + let tx = contract.createWriteOperation("controllerTransfer", parameters: [originalOwner, to, value, data, operatorData] as [AnyObject])! return tx } @@ -365,7 +365,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("controllerRedeem", parameters: [tokenHolder, value, data, operatorData] as [AnyObject] )! + let tx = contract.createWriteOperation("controllerRedeem", parameters: [tokenHolder, value, data, operatorData] as [AnyObject])! return tx } @@ -374,7 +374,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] as [AnyObject] )! + let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] as [AnyObject])! return tx } @@ -383,7 +383,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("revokeOperator", parameters: [user] as [AnyObject] )! + let tx = contract.createWriteOperation("revokeOperator", parameters: [user] as [AnyObject])! return tx } @@ -392,7 +392,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("authorizeOperatorByPartition", parameters: [partition, user] as [AnyObject] )! + let tx = contract.createWriteOperation("authorizeOperatorByPartition", parameters: [partition, user] as [AnyObject])! return tx } @@ -401,14 +401,14 @@ public class ERC1400: IERC1400, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("revokeOperatorByPartition", parameters: [partition, user] as [AnyObject] )! + let tx = contract.createWriteOperation("revokeOperatorByPartition", parameters: [partition, user] as [AnyObject])! return tx } public func isOperator(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("isOperator", parameters: [user, tokenHolder] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("isOperator", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 } @@ -416,7 +416,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { public func isOperatorForPartition(partition: Data, operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("isOperatorForPartition", parameters: [partition, user, tokenHolder] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("isOperatorForPartition", parameters: [partition, user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 } @@ -424,7 +424,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { public func isIssuable() async throws -> Bool { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("isIssuable", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("isIssuable", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 } @@ -447,7 +447,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("issue", parameters: [tokenHolder, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("issue", parameters: [tokenHolder, value, data] as [AnyObject])! return tx } @@ -469,7 +469,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("issueByPartition", parameters: [partition, tokenHolder, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("issueByPartition", parameters: [partition, tokenHolder, value, data] as [AnyObject])! return tx } @@ -491,7 +491,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("redeem", parameters: [value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("redeem", parameters: [value, data] as [AnyObject])! return tx } @@ -513,7 +513,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("redeemFrom", parameters: [tokenHolder, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("redeemFrom", parameters: [tokenHolder, value, data] as [AnyObject])! return tx } @@ -535,7 +535,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("redeemByPartition", parameters: [partition, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("redeemByPartition", parameters: [partition, value, data] as [AnyObject])! return tx } @@ -557,7 +557,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("operatorRedeemByPartition", parameters: [partition, tokenHolder, value, operatorData] as [AnyObject] )! + let tx = contract.createWriteOperation("operatorRedeemByPartition", parameters: [partition, tokenHolder, value, operatorData] as [AnyObject])! return tx } @@ -577,7 +577,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let result = try await contract.createReadOperation("canTransfer", parameters: [to, value, data] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("canTransfer", parameters: [to, value, data] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? ([UInt8], Data) else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -598,7 +598,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let result = try await contract.createReadOperation("canTransfer", parameters: [originalOwner, to, value, data] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("canTransfer", parameters: [originalOwner, to, value, data] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? ([UInt8], Data) else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -619,7 +619,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let result = try await contract.createReadOperation("canTransfer", parameters: [originalOwner, to, partition, value, data] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("canTransfer", parameters: [originalOwner, to, partition, value, data] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? ([UInt8], Data, Data) else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -629,7 +629,7 @@ extension ERC1400: IERC777 { public func canImplementInterfaceForAddress(interfaceHash: Data, addr: EthereumAddress) async throws -> Data { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("canImplementInterfaceForAddress", parameters: [interfaceHash, addr] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("canImplementInterfaceForAddress", parameters: [interfaceHash, addr] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -637,7 +637,7 @@ extension ERC1400: IERC777 { public func getInterfaceImplementer(addr: EthereumAddress, interfaceHash: Data) async throws -> EthereumAddress { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("getInterfaceImplementer", parameters: [addr, interfaceHash] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("getInterfaceImplementer", parameters: [addr, interfaceHash] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -647,7 +647,7 @@ extension ERC1400: IERC777 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setInterfaceImplementer", parameters: [addr, interfaceHash, implementer] as [AnyObject] )! + let tx = contract.createWriteOperation("setInterfaceImplementer", parameters: [addr, interfaceHash, implementer] as [AnyObject])! return tx } @@ -656,14 +656,14 @@ extension ERC1400: IERC777 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setManager", parameters: [addr, newManager] as [AnyObject] )! + let tx = contract.createWriteOperation("setManager", parameters: [addr, newManager] as [AnyObject])! return tx } public func interfaceHash(interfaceName: String) async throws -> Data { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("interfaceHash", parameters: [interfaceName] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("interfaceHash", parameters: [interfaceName] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -673,14 +673,14 @@ extension ERC1400: IERC777 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId] as [AnyObject] )! + let tx = contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId] as [AnyObject])! return tx } public func supportsInterface(interfaceID: String) async throws -> Bool { let contract = self.contract self.transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -688,7 +688,7 @@ extension ERC1400: IERC777 { public func getGranularity() async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("granularity", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("granularity", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() 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 } @@ -696,7 +696,7 @@ extension ERC1400: IERC777 { public func getDefaultOperators() async throws -> [EthereumAddress] { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("defaultOperators", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("defaultOperators", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [EthereumAddress] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -707,7 +707,7 @@ extension ERC1400: IERC777 { self.transaction.to = self.address self.transaction.callOnBlock = .latest - let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] as [AnyObject] )! + let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] as [AnyObject])! return tx } @@ -717,14 +717,14 @@ extension ERC1400: IERC777 { self.transaction.to = self.address self.transaction.callOnBlock = .latest - let tx = contract.createWriteOperation("revokeOperator", parameters: [user] as [AnyObject] )! + let tx = contract.createWriteOperation("revokeOperator", parameters: [user] as [AnyObject])! return tx } public func isOperatorFor(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("isOperatorFor", parameters: [user, tokenHolder] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("isOperatorFor", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 } @@ -746,7 +746,7 @@ extension ERC1400: IERC777 { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("send", parameters: [to, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("send", parameters: [to, value, data] as [AnyObject])! return tx } @@ -767,7 +767,7 @@ extension ERC1400: IERC777 { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("operatorSend", parameters: [originalOwner, to, value, data, operatorData] as [AnyObject] )! + let tx = contract.createWriteOperation("operatorSend", parameters: [originalOwner, to, value, data, operatorData] as [AnyObject])! return tx } @@ -788,7 +788,7 @@ extension ERC1400: IERC777 { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("burn", parameters: [value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("burn", parameters: [value, data] as [AnyObject])! return tx } @@ -809,7 +809,7 @@ extension ERC1400: IERC777 { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("burn", parameters: [originalOwner, value, data, operatorData] as [AnyObject] )! + let tx = contract.createWriteOperation("burn", parameters: [originalOwner, value, data, operatorData] as [AnyObject])! return tx } } diff --git a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift index 4551cd793..bdc453f9a 100644 --- a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift +++ b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift @@ -66,7 +66,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { public func getBalance(account: EthereumAddress) async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -74,7 +74,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -97,7 +97,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject])! return tx } @@ -120,7 +120,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject])! return tx } @@ -143,7 +143,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject])! return tx } @@ -151,7 +151,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 } @@ -175,7 +175,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject])! return tx } @@ -184,7 +184,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("balanceOfByPartition", parameters: [partition, tokenHolder] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("balanceOfByPartition", parameters: [partition, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 } @@ -192,7 +192,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { public func partitionsOf(tokenHolder: EthereumAddress) async throws -> [Data] { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("partitionsOf", parameters: [tokenHolder] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("partitionsOf", parameters: [tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [Data] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -216,7 +216,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferByPartition", parameters: [partition, to, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("transferByPartition", parameters: [partition, to, value, data] as [AnyObject])! return tx } @@ -239,7 +239,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("operatorTransferByPartition", parameters: [partition, originalOwner, to, value, data, operatorData] as [AnyObject] )! + let tx = contract.createWriteOperation("operatorTransferByPartition", parameters: [partition, originalOwner, to, value, data, operatorData] as [AnyObject])! return tx } @@ -259,7 +259,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let result = try await contract.createReadOperation("canTransfer", parameters: [originalOwner, to, partition, value, data] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("canTransfer", parameters: [originalOwner, to, partition, value, data] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? ([UInt8], Data, Data) else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -267,7 +267,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { public func isOperator(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("isOperator", parameters: [user, tokenHolder] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("isOperator", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 } @@ -275,7 +275,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { public func isOperatorForPartition(partition: Data, operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("isOperatorForPartition", parameters: [partition, user, tokenHolder] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("isOperatorForPartition", parameters: [partition, user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 } @@ -286,7 +286,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] as [AnyObject] )! + let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] as [AnyObject])! return tx } @@ -296,7 +296,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("revokeOperator", parameters: [user] as [AnyObject] )! + let tx = contract.createWriteOperation("revokeOperator", parameters: [user] as [AnyObject])! return tx } @@ -306,7 +306,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("authorizeOperatorByPartition", parameters: [partition, user] as [AnyObject] )! + let tx = contract.createWriteOperation("authorizeOperatorByPartition", parameters: [partition, user] as [AnyObject])! return tx } @@ -316,7 +316,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("revokeOperatorByPartition", parameters: [partition, user] as [AnyObject] )! + let tx = contract.createWriteOperation("revokeOperatorByPartition", parameters: [partition, user] as [AnyObject])! return tx } @@ -339,7 +339,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("issueByPartition", parameters: [partition, tokenHolder, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("issueByPartition", parameters: [partition, tokenHolder, value, data] as [AnyObject])! return tx } @@ -362,7 +362,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("redeemByPartition", parameters: [partition, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("redeemByPartition", parameters: [partition, value, data] as [AnyObject])! return tx } @@ -385,7 +385,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("operatorRedeemByPartition", parameters: [partition, tokenHolder, value, operatorData] as [AnyObject] )! + let tx = contract.createWriteOperation("operatorRedeemByPartition", parameters: [partition, tokenHolder, value, operatorData] as [AnyObject])! return tx } } @@ -394,7 +394,7 @@ extension ERC1410: IERC777 { public func canImplementInterfaceForAddress(interfaceHash: Data, addr: EthereumAddress) async throws -> Data { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("canImplementInterfaceForAddress", parameters: [interfaceHash, addr] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("canImplementInterfaceForAddress", parameters: [interfaceHash, addr] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -402,7 +402,7 @@ extension ERC1410: IERC777 { public func getInterfaceImplementer(addr: EthereumAddress, interfaceHash: Data) async throws -> EthereumAddress { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("getInterfaceImplementer", parameters: [addr, interfaceHash] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("getInterfaceImplementer", parameters: [addr, interfaceHash] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -412,7 +412,7 @@ extension ERC1410: IERC777 { self.transaction.from = from - let tx = contract.createWriteOperation("setInterfaceImplementer", parameters: [addr, interfaceHash, implementer] as [AnyObject] )! + let tx = contract.createWriteOperation("setInterfaceImplementer", parameters: [addr, interfaceHash, implementer] as [AnyObject])! return tx } @@ -421,14 +421,14 @@ extension ERC1410: IERC777 { self.transaction.from = from - let tx = contract.createWriteOperation("setManager", parameters: [addr, newManager] as [AnyObject] )! + let tx = contract.createWriteOperation("setManager", parameters: [addr, newManager] as [AnyObject])! return tx } public func interfaceHash(interfaceName: String) async throws -> Data { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("interfaceHash", parameters: [interfaceName] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("interfaceHash", parameters: [interfaceName] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -438,14 +438,14 @@ extension ERC1410: IERC777 { self.transaction.from = from - let tx = contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId] as [AnyObject] )! + let tx = contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId] as [AnyObject])! return tx } public func supportsInterface(interfaceID: String) async throws -> Bool { let contract = self.contract self.transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -456,7 +456,7 @@ extension ERC1410: IERC777 { self.transaction.from = from self.transaction.callOnBlock = .latest - let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] as [AnyObject] )! + let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] as [AnyObject])! return tx } @@ -466,14 +466,14 @@ extension ERC1410: IERC777 { self.transaction.from = from self.transaction.callOnBlock = .latest - let tx = contract.createWriteOperation("revokeOperator", parameters: [user] as [AnyObject] )! + let tx = contract.createWriteOperation("revokeOperator", parameters: [user] as [AnyObject])! return tx } public func isOperatorFor(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("isOperatorFor", parameters: [user, tokenHolder] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("isOperatorFor", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 } @@ -496,7 +496,7 @@ extension ERC1410: IERC777 { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("send", parameters: [to, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("send", parameters: [to, value, data] as [AnyObject])! return tx } @@ -518,7 +518,7 @@ extension ERC1410: IERC777 { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("operatorSend", parameters: [originalOwner, to, value, data, operatorData] as [AnyObject] )! + let tx = contract.createWriteOperation("operatorSend", parameters: [originalOwner, to, value, data, operatorData] as [AnyObject])! return tx } @@ -540,7 +540,7 @@ extension ERC1410: IERC777 { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("burn", parameters: [value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("burn", parameters: [value, data] as [AnyObject])! return tx } @@ -562,14 +562,14 @@ extension ERC1410: IERC777 { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("burn", parameters: [originalOwner, value, data, operatorData] as [AnyObject] )! + let tx = contract.createWriteOperation("burn", parameters: [originalOwner, value, data, operatorData] as [AnyObject])! return tx } public func getGranularity() async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("granularity", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("granularity", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() 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 } @@ -577,7 +577,7 @@ extension ERC1410: IERC777 { public func getDefaultOperators() async throws -> [EthereumAddress] { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("defaultOperators", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("defaultOperators", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [EthereumAddress] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } diff --git a/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift b/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift index de3bb5b41..faeb10614 100644 --- a/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift +++ b/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift @@ -56,7 +56,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { public func getBalance(account: EthereumAddress) async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -64,7 +64,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -87,7 +87,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject])! return tx } @@ -110,7 +110,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject])! return tx } @@ -133,7 +133,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject])! return tx } @@ -141,7 +141,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 } @@ -165,7 +165,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject])! return tx } @@ -189,7 +189,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferWithData", parameters: [to, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("transferWithData", parameters: [to, value, data] as [AnyObject])! return tx } @@ -212,14 +212,14 @@ public class ERC1594: IERC1594, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFromWithData", parameters: [originalOwner, to, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFromWithData", parameters: [originalOwner, to, value, data] as [AnyObject])! return tx } public func isIssuable() async throws -> Bool { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("isIssuable", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("isIssuable", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 } @@ -243,7 +243,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("issue", parameters: [tokenHolder, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("issue", parameters: [tokenHolder, value, data] as [AnyObject])! return tx } @@ -266,7 +266,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("redeem", parameters: [value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("redeem", parameters: [value, data] as [AnyObject])! return tx } @@ -289,7 +289,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("redeemFrom", parameters: [tokenHolder, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("redeemFrom", parameters: [tokenHolder, value, data] as [AnyObject])! return tx } @@ -309,7 +309,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let result = try await contract.createReadOperation("canTransfer", parameters: [to, value, data] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("canTransfer", parameters: [to, value, data] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? ([UInt8], Data) else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -330,7 +330,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let result = try await contract.createReadOperation("canTransfer", parameters: [originalOwner, to, value, data] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("canTransfer", parameters: [originalOwner, to, value, data] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? ([UInt8], Data) else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } diff --git a/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift index 7aae7e727..5d4546636 100644 --- a/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift +++ b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift @@ -43,7 +43,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { public func getBalance(account: EthereumAddress) async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -51,7 +51,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -74,7 +74,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject])! return tx } @@ -97,7 +97,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject])! return tx } @@ -120,14 +120,14 @@ public class ERC1633: IERC1633, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject])! return tx } public func totalSupply() async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 } @@ -151,14 +151,14 @@ public class ERC1633: IERC1633, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject])! return tx } func parentToken() async throws -> EthereumAddress { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("parentToken", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("parentToken", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -166,7 +166,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { func parentTokenId() async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("parentTokenId", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("parentTokenId", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() 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 } @@ -174,7 +174,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { public func supportsInterface(interfaceID: String) async throws -> Bool { let contract = self.contract self.transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } diff --git a/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift b/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift index be5cce528..d653d4f45 100644 --- a/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift +++ b/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift @@ -46,7 +46,7 @@ public class ERC1643: IERC1643, ERC20BaseProperties { public func getBalance(account: EthereumAddress) async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -54,7 +54,7 @@ public class ERC1643: IERC1643, ERC20BaseProperties { public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -77,7 +77,7 @@ public class ERC1643: IERC1643, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject])! return tx } @@ -100,7 +100,7 @@ public class ERC1643: IERC1643, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject])! return tx } @@ -123,14 +123,14 @@ public class ERC1643: IERC1643, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject])! return tx } public func totalSupply() async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 } @@ -154,7 +154,7 @@ public class ERC1643: IERC1643, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject])! return tx } @@ -162,7 +162,7 @@ public class ERC1643: IERC1643, ERC20BaseProperties { public func getDocument(name: Data) async throws -> (String, Data) { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("getDocument", parameters: [name] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("getDocument", parameters: [name] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? (String, Data) else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -173,7 +173,7 @@ public class ERC1643: IERC1643, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setDocument", parameters: [name, uri, documentHash] as [AnyObject] )! + let tx = contract.createWriteOperation("setDocument", parameters: [name, uri, documentHash] as [AnyObject])! return tx } @@ -183,14 +183,14 @@ public class ERC1643: IERC1643, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("removeDocument", parameters: [name] as [AnyObject] )! + let tx = contract.createWriteOperation("removeDocument", parameters: [name] as [AnyObject])! return tx } public func getAllDocuments() async throws -> [Data] { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("getAllDocuments", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("getAllDocuments", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [Data] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } diff --git a/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift b/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift index 98d3f60f4..383885e65 100644 --- a/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift +++ b/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift @@ -45,7 +45,7 @@ public class ERC1644: IERC1644, ERC20BaseProperties { public func getBalance(account: EthereumAddress) async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -53,7 +53,7 @@ public class ERC1644: IERC1644, ERC20BaseProperties { public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -76,7 +76,7 @@ public class ERC1644: IERC1644, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject])! return tx } @@ -99,7 +99,7 @@ public class ERC1644: IERC1644, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject])! return tx } @@ -122,14 +122,14 @@ public class ERC1644: IERC1644, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject])! return tx } public func totalSupply() async throws -> BigUInt { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 } @@ -153,7 +153,7 @@ public class ERC1644: IERC1644, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject])! return tx } @@ -161,7 +161,7 @@ public class ERC1644: IERC1644, ERC20BaseProperties { public func isControllable() async throws -> Bool { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("isControllable", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("isControllable", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 } @@ -185,7 +185,7 @@ public class ERC1644: IERC1644, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("controllerTransfer", parameters: [originalOwner, to, value, data, operatorData] as [AnyObject] )! + let tx = contract.createWriteOperation("controllerTransfer", parameters: [originalOwner, to, value, data, operatorData] as [AnyObject])! return tx } @@ -208,7 +208,7 @@ public class ERC1644: IERC1644, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("controllerRedeem", parameters: [tokenHolder, value, data, operatorData] as [AnyObject] )! + let tx = contract.createWriteOperation("controllerRedeem", parameters: [tokenHolder, value, data, operatorData] as [AnyObject])! return tx } } diff --git a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift index c35316753..a953c52ba 100644 --- a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift +++ b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift @@ -45,7 +45,7 @@ public class ERC20: IERC20, ERC20BaseProperties { let contract = self.contract self.transaction.callOnBlock = .latest let result = try await contract - .createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data() )! + .createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())! .callContractMethod() 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 @@ -55,7 +55,7 @@ public class ERC20: IERC20, ERC20BaseProperties { let contract = self.contract self.transaction.callOnBlock = .latest let result = try await contract - .createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data() )! + .createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())! .callContractMethod() 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 @@ -80,7 +80,7 @@ public class ERC20: IERC20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } contract.transaction = transaction - let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject])! return tx } @@ -103,7 +103,7 @@ public class ERC20: IERC20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } contract.transaction = transaction - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject])! return tx } @@ -126,7 +126,7 @@ public class ERC20: IERC20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } contract.transaction = transaction - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject])! return tx } @@ -149,14 +149,14 @@ public class ERC20: IERC20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } contract.transaction = transaction - let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject])! return tx } public func totalSupply() async throws -> BigUInt { self.transaction.callOnBlock = .latest let result = try await contract - .createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )! + .createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())! .callContractMethod() 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 diff --git a/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift b/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift index 786bda260..f7a7082a3 100644 --- a/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift +++ b/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift @@ -103,14 +103,14 @@ public class ERC721: IERC721 { public func getBalance(account: EthereumAddress) async throws -> BigUInt { transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 getOwner(tokenId: BigUInt) async throws -> EthereumAddress { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("ownerOf", parameters: [tokenId] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("ownerOf", parameters: [tokenId] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -118,7 +118,7 @@ public class ERC721: IERC721 { public func getApproved(tokenId: BigUInt) async throws -> EthereumAddress { let contract = self.contract transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("getApproved", parameters: [tokenId] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("getApproved", parameters: [tokenId] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -161,14 +161,14 @@ public class ERC721: IERC721 { public func isApprovedForAll(owner: EthereumAddress, operator user: EthereumAddress) async throws -> Bool { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user] as [AnyObject], extraData: Data())!.callContractMethod() 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 { transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -193,21 +193,21 @@ extension ERC721: IERC721Enumerable { public func totalSupply() async throws -> BigUInt { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 tokenByIndex(index: BigUInt) async throws -> BigUInt { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("tokenByIndex", parameters: [index] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("tokenByIndex", parameters: [index] as [AnyObject], extraData: Data())!.callContractMethod() 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 tokenOfOwnerByIndex(owner: EthereumAddress, index: BigUInt) async throws -> BigUInt { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("tokenOfOwnerByIndex", parameters: [owner, index] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("tokenOfOwnerByIndex", parameters: [owner, index] as [AnyObject], extraData: Data())!.callContractMethod() 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 } @@ -221,21 +221,21 @@ extension ERC721: IERC721Metadata { public func name() async throws -> String { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("name", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("name", parameters: [AnyObject](), extraData: Data())!.callContractMethod() guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func symbol() async throws -> String { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("symbol", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("symbol", parameters: [AnyObject](), extraData: Data())!.callContractMethod() guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func tokenURI(tokenId: BigUInt) async throws -> String { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("tokenURI", parameters: [tokenId] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("tokenURI", parameters: [tokenId] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } diff --git a/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift b/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift index 50bc7e648..b7f839287 100644 --- a/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift +++ b/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift @@ -86,165 +86,165 @@ public class ERC721x: IERC721x { public func getBalance(account: EthereumAddress) async throws -> BigUInt { transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 getOwner(tokenId: BigUInt) async throws -> EthereumAddress { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("ownerOf", parameters: [tokenId] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("ownerOf", parameters: [tokenId] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func getApproved(tokenId: BigUInt) async throws -> EthereumAddress { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("getApproved", parameters: [tokenId] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("getApproved", parameters: [tokenId] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func transfer(from: EthereumAddress, to: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation { updateTransactionAndContract(from: from) - let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId] as [AnyObject])! return tx } public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation { updateTransactionAndContract(from: from) - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject])! return tx } public func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation { updateTransactionAndContract(from: from) - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject])! return tx } public func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt, data: [UInt8]) throws -> WriteOperation { updateTransactionAndContract(from: from) - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, data] as [AnyObject] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, data] as [AnyObject])! return tx } public func approve(from: EthereumAddress, approved: EthereumAddress, tokenId: BigUInt) throws -> WriteOperation { updateTransactionAndContract(from: from) - let tx = contract.createWriteOperation("approve", parameters: [approved, tokenId] as [AnyObject] )! + let tx = contract.createWriteOperation("approve", parameters: [approved, tokenId] as [AnyObject])! return tx } public func setApprovalForAll(from: EthereumAddress, operator user: EthereumAddress, approved: Bool) throws -> WriteOperation { updateTransactionAndContract(from: from) - let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved] as [AnyObject] )! + let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved] as [AnyObject])! return tx } public func isApprovedForAll(owner: EthereumAddress, operator user: EthereumAddress) async throws -> Bool { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user] as [AnyObject], extraData: Data())!.callContractMethod() 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 { transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 totalSupply() async throws -> BigUInt { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 tokenByIndex(index: BigUInt) async throws -> BigUInt { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("tokenByIndex", parameters: [index] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("tokenByIndex", parameters: [index] as [AnyObject], extraData: Data())!.callContractMethod() 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 tokenOfOwnerByIndex(owner: EthereumAddress, index: BigUInt) async throws -> BigUInt { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("tokenOfOwnerByIndex", parameters: [owner, index] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("tokenOfOwnerByIndex", parameters: [owner, index] as [AnyObject], extraData: Data())!.callContractMethod() 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 name() async throws -> String { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("name", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("name", parameters: [AnyObject](), extraData: Data())!.callContractMethod() guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func symbol() async throws -> String { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("symbol", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("symbol", parameters: [AnyObject](), extraData: Data())!.callContractMethod() guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func tokenURI(tokenId: BigUInt) async throws -> String { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("tokenURI", parameters: [tokenId] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("tokenURI", parameters: [tokenId] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } func implementsERC721X() async throws -> Bool { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("implementsERC721X", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("implementsERC721X", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() 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 } func getBalance(account: EthereumAddress, tokenId: BigUInt) async throws -> BigUInt { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("balanceOf", parameters: [account, tokenId] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("balanceOf", parameters: [account, tokenId] as [AnyObject], extraData: Data())!.callContractMethod() 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 } func tokensOwned(account: EthereumAddress) async throws -> ([BigUInt], [BigUInt]) { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("tokensOwned", parameters: [account] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("tokensOwned", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? ([BigUInt], [BigUInt]) else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } func transfer(from: EthereumAddress, to: EthereumAddress, tokenId: BigUInt, quantity: BigUInt) throws -> WriteOperation { updateTransactionAndContract(from: from) - let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId, quantity] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId, quantity] as [AnyObject])! return tx } func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt, quantity: BigUInt) throws -> WriteOperation { updateTransactionAndContract(from: from) - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId, quantity] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId, quantity] as [AnyObject])! return tx } func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt, amount: BigUInt) throws -> WriteOperation { updateTransactionAndContract(from: from) - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount] as [AnyObject] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount] as [AnyObject])! return tx } func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenId: BigUInt, amount: BigUInt, data: [UInt8]) throws -> WriteOperation { updateTransactionAndContract(from: from) - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount, data] as [AnyObject] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount, data] as [AnyObject])! return tx } func safeTransferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, tokenIds: [BigUInt], amounts: [BigUInt], data: [UInt8]) throws -> WriteOperation { updateTransactionAndContract(from: from) - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenIds, amounts, data] as [AnyObject] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenIds, amounts, data] as [AnyObject])! return tx } } diff --git a/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift index 18042ab4e..aa1203161 100644 --- a/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift +++ b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift @@ -58,28 +58,28 @@ public class ERC777: IERC777, ERC20BaseProperties { public func getGranularity() async throws -> BigUInt { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("granularity", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("granularity", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() 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 getDefaultOperators() async throws -> [EthereumAddress] { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("defaultOperators", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("defaultOperators", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [EthereumAddress] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func getBalance(account: EthereumAddress) async throws -> BigUInt { transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 { transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -142,7 +142,7 @@ public class ERC777: IERC777, ERC20BaseProperties { public func totalSupply() async throws -> BigUInt { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 } @@ -164,7 +164,7 @@ public class ERC777: IERC777, ERC20BaseProperties { public func isOperatorFor(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("isOperatorFor", parameters: [user, tokenHolder] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("isOperatorFor", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 } @@ -201,7 +201,7 @@ public class ERC777: IERC777, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("operatorSend", parameters: [originalOwner, to, value, data, operatorData] as [AnyObject] )! + let tx = contract.createWriteOperation("operatorSend", parameters: [originalOwner, to, value, data, operatorData] as [AnyObject])! return tx } @@ -243,14 +243,14 @@ public class ERC777: IERC777, ERC20BaseProperties { public func canImplementInterfaceForAddress(interfaceHash: Data, addr: EthereumAddress) async throws -> Data { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("canImplementInterfaceForAddress", parameters: [interfaceHash, addr] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("canImplementInterfaceForAddress", parameters: [interfaceHash, addr] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func getInterfaceImplementer(addr: EthereumAddress, interfaceHash: Data) async throws -> EthereumAddress { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("getInterfaceImplementer", parameters: [addr, interfaceHash] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("getInterfaceImplementer", parameters: [addr, interfaceHash] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -269,7 +269,7 @@ public class ERC777: IERC777, ERC20BaseProperties { public func interfaceHash(interfaceName: String) async throws -> Data { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("interfaceHash", parameters: [interfaceName] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("interfaceHash", parameters: [interfaceName] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -302,7 +302,7 @@ public class ERC777: IERC777, ERC20BaseProperties { public func supportsInterface(interfaceID: String) async throws -> Bool { transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } diff --git a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift index bf50d0664..0eef7edc9 100644 --- a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift +++ b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift @@ -51,7 +51,7 @@ public class ST20: IST20, ERC20BaseProperties { func tokenDetails() async throws -> [UInt32] { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("tokenDetails", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("tokenDetails", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [UInt32] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } @@ -71,7 +71,7 @@ public class ST20: IST20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("verifyTransfer", parameters: [originalOwner, to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("verifyTransfer", parameters: [originalOwner, to, value] as [AnyObject])! return tx } @@ -90,7 +90,7 @@ public class ST20: IST20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("mint", parameters: [investor, value] as [AnyObject] )! + let tx = contract.createWriteOperation("mint", parameters: [investor, value] as [AnyObject])! return tx } @@ -108,13 +108,13 @@ public class ST20: IST20, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("burn", parameters: [value] as [AnyObject] )! + let tx = contract.createWriteOperation("burn", parameters: [value] as [AnyObject])! return tx } public func getBalance(account: EthereumAddress) async throws -> BigUInt { transaction.callOnBlock = .latest - 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())!.callContractMethod() 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 } @@ -140,7 +140,7 @@ public class ST20: IST20, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject])! return tx } @@ -159,7 +159,7 @@ public class ST20: IST20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject])! return tx } @@ -178,7 +178,7 @@ public class ST20: IST20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject])! return tx } @@ -197,13 +197,13 @@ public class ST20: IST20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject])! return tx } public func totalSupply() async throws -> BigUInt { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 } diff --git a/Sources/web3swift/Utils/ENS/ENSBaseRegistrar.swift b/Sources/web3swift/Utils/ENS/ENSBaseRegistrar.swift index 744ffa61b..6158b941e 100644 --- a/Sources/web3swift/Utils/ENS/ENSBaseRegistrar.swift +++ b/Sources/web3swift/Utils/ENS/ENSBaseRegistrar.swift @@ -36,7 +36,7 @@ public extension ENS { public func addController(from: EthereumAddress, controllerAddress: EthereumAddress) throws -> WriteOperation { defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("addController", parameters: [controllerAddress as AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("addController", parameters: [controllerAddress as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} return transaction } @@ -44,7 +44,7 @@ public extension ENS { public func removeController(from: EthereumAddress, controllerAddress: EthereumAddress) throws -> WriteOperation { defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("removeController", parameters: [controllerAddress as AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("removeController", parameters: [controllerAddress as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} return transaction } @@ -52,12 +52,12 @@ public extension ENS { public func setResolver(from: EthereumAddress, resolverAddress: EthereumAddress) throws -> WriteOperation { defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("setResolver", parameters: [resolverAddress as AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("setResolver", parameters: [resolverAddress as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} return transaction } public func getNameExpirity(name: BigUInt) async throws -> BigUInt { - guard let transaction = self.contract.createReadOperation("nameExpires", parameters: [name as AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createReadOperation("nameExpires", parameters: [name as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.callContractMethod() else {throw Web3Error.processingError(desc: "Can't call transaction")} guard let expirity = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Can't get answer")} return expirity @@ -65,7 +65,7 @@ public extension ENS { @available(*, message: "This function should not be used to check if a name can be registered by a user. To check if a name can be registered by a user, check name availablility via the controller") public func isNameAvailable(name: BigUInt) async throws -> Bool { - guard let transaction = self.contract.createReadOperation("available", parameters: [name as AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createReadOperation("available", parameters: [name as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.callContractMethod() else {throw Web3Error.processingError(desc: "Can't call transaction")} guard let available = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Can't get answer")} return available @@ -74,7 +74,7 @@ public extension ENS { public func reclaim(from: EthereumAddress, record: BigUInt) throws -> WriteOperation { defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("reclaim", parameters: [record as AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("reclaim", parameters: [record as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} return transaction } diff --git a/Sources/web3swift/Utils/ENS/ENSRegistry.swift b/Sources/web3swift/Utils/ENS/ENSRegistry.swift index 587684eb8..a75f09389 100644 --- a/Sources/web3swift/Utils/ENS/ENSRegistry.swift +++ b/Sources/web3swift/Utils/ENS/ENSRegistry.swift @@ -48,7 +48,7 @@ public extension ENS { public func getOwner(node: String) async throws -> EthereumAddress { guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.registryContract.createReadOperation("owner", parameters: [nameHash as AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.registryContract.createReadOperation("owner", parameters: [nameHash as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.callContractMethod() else {throw Web3Error.processingError(desc: "Can't call transaction")} guard let address = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "No address in result")} return address @@ -56,7 +56,7 @@ public extension ENS { public func getResolver(forDomain domain: String) async throws -> Resolver { guard let nameHash = NameHash.nameHash(domain) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.registryContract.createReadOperation("resolver", parameters: [nameHash as AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.registryContract.createReadOperation("resolver", parameters: [nameHash as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.callContractMethod() else {throw Web3Error.processingError(desc: "Can't call transaction")} guard let resolverAddress = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "No address in result")} return Resolver(web3: self.web3, resolverContractAddress: resolverAddress) @@ -64,7 +64,7 @@ public extension ENS { public func getTTL(node: String) async throws -> BigUInt { guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.registryContract.createReadOperation("ttl", parameters: [nameHash as AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.registryContract.createReadOperation("ttl", parameters: [nameHash as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.callContractMethod() else {throw Web3Error.processingError(desc: "Can't call transaction")} guard let ans = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "No answer in result")} return ans @@ -77,7 +77,7 @@ public extension ENS { options.to = contractAddress } guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.registryContract.createWriteOperation("setOwner", parameters: [nameHash, owner] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.registryContract.createWriteOperation("setOwner", parameters: [nameHash, owner] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")} return result } @@ -90,7 +90,7 @@ public extension ENS { } guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} guard let labelHash = NameHash.nameHash(label) else {throw Web3Error.processingError(desc: "Failed to get label hash")} - guard let transaction = self.registryContract.createWriteOperation("setSubnodeOwner", parameters: [nameHash, labelHash, owner] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.registryContract.createWriteOperation("setSubnodeOwner", parameters: [nameHash, labelHash, owner] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")} return result } @@ -102,7 +102,7 @@ public extension ENS { options.to = contractAddress } guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.registryContract.createWriteOperation("setResolver", parameters: [nameHash, resolver] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.registryContract.createWriteOperation("setResolver", parameters: [nameHash, resolver] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")} return result } @@ -114,7 +114,7 @@ public extension ENS { options.to = contractAddress } guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.registryContract.createWriteOperation("setTTL", parameters: [nameHash, ttl] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.registryContract.createWriteOperation("setTTL", parameters: [nameHash, ttl] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")} return result } diff --git a/Sources/web3swift/Utils/ENS/ENSReverseRegistrar.swift b/Sources/web3swift/Utils/ENS/ENSReverseRegistrar.swift index 1ba0baa24..c65b4f667 100644 --- a/Sources/web3swift/Utils/ENS/ENSReverseRegistrar.swift +++ b/Sources/web3swift/Utils/ENS/ENSReverseRegistrar.swift @@ -33,33 +33,33 @@ public extension ENS { public func claimAddress(from: EthereumAddress, owner: EthereumAddress) throws -> WriteOperation { defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("claim", parameters: [owner as AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("claim", parameters: [owner as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} return transaction } public func claimAddressWithResolver(from: EthereumAddress, owner: EthereumAddress, resolver: EthereumAddress) throws -> WriteOperation { defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("claimWithResolver", parameters: [owner, resolver] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("claimWithResolver", parameters: [owner, resolver] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} return transaction } public func setName(from: EthereumAddress, name: String) throws -> WriteOperation { defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("setName", parameters: [name] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("setName", parameters: [name] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} return transaction } public func getReverseRecordName(address: EthereumAddress) async throws -> Data { - guard let transaction = self.contract.createReadOperation("node", parameters: [address] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createReadOperation("node", parameters: [address] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.callContractMethod() else {throw Web3Error.processingError(desc: "Can't call transaction")} guard let name = result["0"] as? Data else {throw Web3Error.processingError(desc: "Can't get answer")} return name } public func getDefaultResolver() async throws -> EthereumAddress { - guard let transaction = self.contract.createReadOperation("defaultResolver", parameters: [] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createReadOperation("defaultResolver", parameters: [] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.callContractMethod() else {throw Web3Error.processingError(desc: "Can't call transaction")} guard let address = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Can't get answer")} return address diff --git a/Sources/web3swift/Utils/ENS/ETHRegistrarController.swift b/Sources/web3swift/Utils/ENS/ETHRegistrarController.swift index f684e3692..1003c4f66 100644 --- a/Sources/web3swift/Utils/ENS/ETHRegistrarController.swift +++ b/Sources/web3swift/Utils/ENS/ETHRegistrarController.swift @@ -31,28 +31,28 @@ public extension ENS { } public func getRentPrice(name: String, duration: UInt) async throws -> BigUInt { - guard let transaction = self.contract.createReadOperation("rentPrice", parameters: [name, duration] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createReadOperation("rentPrice", parameters: [name, duration] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.callContractMethod() else {throw Web3Error.processingError(desc: "Can't call transaction")} guard let price = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Can't get answer")} return price } public func checkNameValidity(name: String) async throws -> Bool { - guard let transaction = self.contract.createReadOperation("valid", parameters: [name] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createReadOperation("valid", parameters: [name] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.callContractMethod() else {throw Web3Error.processingError(desc: "Can't call transaction")} guard let valid = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Can't get answer")} return valid } public func isNameAvailable(name: String) async throws -> Bool { - guard let transaction = self.contract.createReadOperation("available", parameters: [name as AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createReadOperation("available", parameters: [name as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.callContractMethod() else {throw Web3Error.processingError(desc: "Can't call transaction")} guard let available = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Can't get answer")} return available } public func calculateCommitmentHash(name: String, owner: EthereumAddress, secret: String) async throws -> Data { - guard let transaction = self.contract.createReadOperation("makeCommitment", parameters: [name, owner.address, secret] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createReadOperation("makeCommitment", parameters: [name, owner.address, secret] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.callContractMethod() else {throw Web3Error.processingError(desc: "Can't call transaction")} guard let hash = result["0"] as? Data else {throw Web3Error.processingError(desc: "Can't get answer")} return hash @@ -61,7 +61,7 @@ public extension ENS { public func sumbitCommitment(from: EthereumAddress, commitment: Data) throws -> WriteOperation { defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("commit", parameters: [commitment as AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("commit", parameters: [commitment as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} return transaction } @@ -70,7 +70,7 @@ public extension ENS { defaultOptions.value = amount defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("register", parameters: [name, owner.address, duration, secret] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("register", parameters: [name, owner.address, duration, secret] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} return transaction } @@ -79,7 +79,7 @@ public extension ENS { defaultOptions.value = amount defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("renew", parameters: [name, duration] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("renew", parameters: [name, duration] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError} return transaction } @@ -87,7 +87,7 @@ public extension ENS { public func withdraw(from: EthereumAddress) throws -> WriteOperation { defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("withdraw", parameters: [AnyObject](), extraData: Data() ) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("withdraw", parameters: [AnyObject](), extraData: Data()) else {throw Web3Error.transactionSerializationError} return transaction } } From 7ea58df6eb5f19e208063b5c3e4ba3b3e4bcd503 Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 12:05:33 +0100 Subject: [PATCH 13/23] Fix security token --- .../Tokens/ST20/Web3+SecurityToken.swift | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift b/Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift index a7670f124..087e42768 100644 --- a/Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift +++ b/Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift @@ -100,7 +100,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { transaction.from = from transaction.to = self.address transaction.callOnBlock = .latest - + contract.transaction = transaction // get the decimals manually let callResult = try await contract.createReadOperation("decimals")!.callContractMethod() var decimals = BigUInt(0) @@ -119,7 +119,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { transaction.from = from transaction.to = self.address transaction.callOnBlock = .latest - + contract.transaction = transaction // get the decimals manually let callResult = try await contract.createReadOperation("decimals")!.callContractMethod() var decimals = BigUInt(0) @@ -138,7 +138,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { transaction.from = from transaction.to = self.address transaction.callOnBlock = .latest - + contract.transaction = transaction // get the decimals manually let callResult = try await contract.createReadOperation("decimals")!.callContractMethod() var decimals = BigUInt(0) @@ -171,7 +171,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { transaction.from = from transaction.to = self.address transaction.callOnBlock = .latest - + contract.transaction = transaction // get the decimals manually let callResult = try await contract.createReadOperation("decimals")!.callContractMethod() var decimals = BigUInt(0) @@ -190,7 +190,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { transaction.from = from transaction.to = self.address transaction.callOnBlock = .latest - + contract.transaction = transaction // get the decimals manually let callResult = try await contract.createReadOperation("decimals")!.callContractMethod() var decimals = BigUInt(0) @@ -209,7 +209,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { transaction.from = from transaction.to = self.address transaction.callOnBlock = .latest - + contract.transaction = transaction // get the decimals manually let callResult = try await contract.createReadOperation("decimals")!.callContractMethod() var decimals = BigUInt(0) @@ -228,7 +228,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { transaction.from = from transaction.to = self.address transaction.callOnBlock = .latest - + contract.transaction = transaction // get the decimals manually let callResult = try await contract.createReadOperation("decimals")!.callContractMethod() var decimals = BigUInt(0) @@ -254,6 +254,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { transaction.from = from transaction.to = self.address transaction.callOnBlock = .latest + contract.transaction = transaction return contract.createWriteOperation("renounceOwnership", parameters: [AnyObject]() )! } @@ -261,6 +262,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { transaction.from = from transaction.to = self.address transaction.callOnBlock = .latest + contract.transaction = transaction return contract.createWriteOperation("transferOwnership", parameters: [newOwner] as [AnyObject])! } @@ -333,6 +335,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { transaction.from = from transaction.to = self.address transaction.callOnBlock = .latest + contract.transaction = transaction return contract.createWriteOperation("createCheckpoint", parameters: [AnyObject]() )! } From 1845f4886600fbd780f0ae323d77e980a5f75380 Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 12:20:33 +0100 Subject: [PATCH 14/23] Remove blank lines at eof --- Sources/web3swift/Tokens/ST20/Web3+ST20.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift index 0eef7edc9..dcbffb71a 100644 --- a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift +++ b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift @@ -221,5 +221,3 @@ extension ST20 { } } - - From ccc06c3ae897377f944b745426ca7ec8da198038 Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 12:20:42 +0100 Subject: [PATCH 15/23] Fix ERC1643 --- .../Tokens/ERC1643/Web3+ERC1643.swift | 72 ++++++++----------- 1 file changed, 28 insertions(+), 44 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift b/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift index d653d4f45..5216ffe05 100644 --- a/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift +++ b/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift @@ -44,28 +44,22 @@ public class ERC1643: IERC1643, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -82,12 +76,8 @@ public class ERC1643: IERC1643, ERC20BaseProperties { } public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -105,12 +95,8 @@ public class ERC1643: IERC1643, ERC20BaseProperties { } public func setAllowance(from: EthereumAddress, to: EthereumAddress, newAmount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -128,20 +114,15 @@ public class ERC1643: IERC1643, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 approve(from: EthereumAddress, spender: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -160,38 +141,41 @@ public class ERC1643: IERC1643, ERC20BaseProperties { // ERC1643 methods public func getDocument(name: Data) async throws -> (String, Data) { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getDocument", parameters: [name] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? (String, Data) else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func setDocument(from: EthereumAddress, name: Data, uri: String, documentHash: Data) throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("setDocument", parameters: [name, uri, documentHash] as [AnyObject])! return tx } public func removeDocument(from: EthereumAddress, name: Data) throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("removeDocument", parameters: [name] as [AnyObject])! return tx } public func getAllDocuments() async throws -> [Data] { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getAllDocuments", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [Data] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } } + +// MARK: - Private + +extension ERC1643 { + + private func updateTransactionAndContract(from: EthereumAddress) { + transaction.from = from + transaction.to = address + contract.transaction = transaction + } + +} + From 19e8a864e0712f7b737baa53603c8a5c233818dc Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 12:20:51 +0100 Subject: [PATCH 16/23] Fix ERC1644 --- .../Tokens/ERC1644/Web3+ERC1644.swift | 72 ++++++++----------- 1 file changed, 28 insertions(+), 44 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift b/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift index 383885e65..fe8b4e20f 100644 --- a/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift +++ b/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift @@ -43,28 +43,22 @@ public class ERC1644: IERC1644, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -81,12 +75,8 @@ public class ERC1644: IERC1644, ERC20BaseProperties { } public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -104,12 +94,8 @@ public class ERC1644: IERC1644, ERC20BaseProperties { } public func setAllowance(from: EthereumAddress, to: EthereumAddress, newAmount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -127,20 +113,15 @@ public class ERC1644: IERC1644, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 approve(from: EthereumAddress, spender: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -159,20 +140,15 @@ public class ERC1644: IERC1644, ERC20BaseProperties { // ERC1644 public func isControllable() async throws -> Bool { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isControllable", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 controllerTransfer(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String, data: [UInt8], operatorData: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -190,12 +166,8 @@ public class ERC1644: IERC1644, ERC20BaseProperties { } public func controllerRedeem(from: EthereumAddress, tokenHolder: EthereumAddress, amount: String, data: [UInt8], operatorData: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -212,3 +184,15 @@ public class ERC1644: IERC1644, ERC20BaseProperties { return tx } } + +// MARK: - Private + +extension ERC1644 { + + private func updateTransactionAndContract(from: EthereumAddress) { + transaction.from = from + transaction.to = address + contract.transaction = transaction + } + +} From 70529052fbcdca7130ef514309fef69fcd157535 Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 12:27:32 +0100 Subject: [PATCH 17/23] Delete all the self's --- .../Tokens/ERC1410/Web3+ERC1410.swift | 60 +++++++++---------- .../Tokens/ERC1594/Web3+ERC1594.swift | 30 +++++----- .../Tokens/ERC1633/Web3+ERC1633.swift | 20 +++---- .../web3swift/Tokens/ERC20/Web3+ERC20.swift | 14 ++--- .../web3swift/Tokens/ERC721/Web3+ERC721.swift | 2 +- 5 files changed, 63 insertions(+), 63 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift index bdc453f9a..78ebaa81c 100644 --- a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift +++ b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift @@ -65,7 +65,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { public func getBalance(account: EthereumAddress) async throws -> BigUInt { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -73,7 +73,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -84,7 +84,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -106,7 +106,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -129,7 +129,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -150,7 +150,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { public func totalSupply() async throws -> BigUInt { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 @@ -161,7 +161,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -183,7 +183,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { public func balanceOfByPartition(partition: Data, tokenHolder: EthereumAddress) async throws -> BigUInt { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOfByPartition", parameters: [partition, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -191,7 +191,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { public func partitionsOf(tokenHolder: EthereumAddress) async throws -> [Data] { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("partitionsOf", parameters: [tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [Data] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -202,7 +202,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -225,7 +225,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -245,7 +245,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { public func canTransferByPartition(originalOwner: EthereumAddress, to: EthereumAddress, partition: Data, amount: String, data: [UInt8]) async throws -> ([UInt8], Data, Data) { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -266,7 +266,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { public func isOperator(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperator", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -274,7 +274,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { public func isOperatorForPartition(partition: Data, operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperatorForPartition", parameters: [partition, user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -325,7 +325,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -348,7 +348,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -371,7 +371,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -393,7 +393,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { extension ERC1410: IERC777 { public func canImplementInterfaceForAddress(interfaceHash: Data, addr: EthereumAddress) async throws -> Data { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("canImplementInterfaceForAddress", parameters: [interfaceHash, addr] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -401,7 +401,7 @@ extension ERC1410: IERC777 { public func getInterfaceImplementer(addr: EthereumAddress, interfaceHash: Data) async throws -> EthereumAddress { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getInterfaceImplementer", parameters: [addr, interfaceHash] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -427,7 +427,7 @@ extension ERC1410: IERC777 { public func interfaceHash(interfaceName: String) async throws -> Data { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("interfaceHash", parameters: [interfaceName] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -444,7 +444,7 @@ extension ERC1410: IERC777 { public func supportsInterface(interfaceID: String) async throws -> Bool { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -454,7 +454,7 @@ extension ERC1410: IERC777 { let contract = self.contract self.transaction.from = from - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] as [AnyObject])! return tx @@ -464,7 +464,7 @@ extension ERC1410: IERC777 { let contract = self.contract self.transaction.from = from - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let tx = contract.createWriteOperation("revokeOperator", parameters: [user] as [AnyObject])! return tx @@ -472,7 +472,7 @@ extension ERC1410: IERC777 { public func isOperatorFor(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperatorFor", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -483,7 +483,7 @@ extension ERC1410: IERC777 { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -505,7 +505,7 @@ extension ERC1410: IERC777 { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -527,7 +527,7 @@ extension ERC1410: IERC777 { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -549,7 +549,7 @@ extension ERC1410: IERC777 { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -568,7 +568,7 @@ extension ERC1410: IERC777 { public func getGranularity() async throws -> BigUInt { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("granularity", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -576,7 +576,7 @@ extension ERC1410: IERC777 { public func getDefaultOperators() async throws -> [EthereumAddress] { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("defaultOperators", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [EthereumAddress] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res diff --git a/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift b/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift index faeb10614..e9315b8fd 100644 --- a/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift +++ b/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift @@ -55,7 +55,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { public func getBalance(account: EthereumAddress) async throws -> BigUInt { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -63,7 +63,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -74,7 +74,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -96,7 +96,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -119,7 +119,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -140,7 +140,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { public func totalSupply() async throws -> BigUInt { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 @@ -151,7 +151,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -175,7 +175,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -198,7 +198,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -218,7 +218,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { public func isIssuable() async throws -> Bool { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isIssuable", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 @@ -229,7 +229,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -252,7 +252,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -275,7 +275,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -295,7 +295,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { public func canTransfer(to: EthereumAddress, amount: String, data: [UInt8]) async throws -> ([UInt8], Data) { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -316,7 +316,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { public func canTransferFrom(originalOwner: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) async throws -> ([UInt8], Data) { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() diff --git a/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift index 5d4546636..84dff549d 100644 --- a/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift +++ b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift @@ -42,7 +42,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { public func getBalance(account: EthereumAddress) async throws -> BigUInt { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -50,7 +50,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -61,7 +61,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -83,7 +83,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -106,7 +106,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -126,7 +126,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { public func totalSupply() async throws -> BigUInt { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 @@ -137,7 +137,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -157,7 +157,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { func parentToken() async throws -> EthereumAddress { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("parentToken", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -165,7 +165,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { func parentTokenId() async throws -> BigUInt { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("parentTokenId", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -173,7 +173,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { public func supportsInterface(interfaceID: String) async throws -> Bool { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod() 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 diff --git a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift index a953c52ba..1529ec06c 100644 --- a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift +++ b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift @@ -43,7 +43,7 @@ public class ERC20: IERC20, ERC20BaseProperties { public func getBalance(account: EthereumAddress) async throws -> BigUInt { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract .createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())! .callContractMethod() @@ -53,7 +53,7 @@ public class ERC20: IERC20, ERC20BaseProperties { public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt { let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract .createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())! .callContractMethod() @@ -64,7 +64,7 @@ public class ERC20: IERC20, ERC20BaseProperties { public func transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract @@ -87,7 +87,7 @@ public class ERC20: IERC20, ERC20BaseProperties { public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String) async throws -> WriteOperation { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract @@ -110,7 +110,7 @@ public class ERC20: IERC20, ERC20BaseProperties { public func setAllowance(from: EthereumAddress, to: EthereumAddress, newAmount: String) async throws -> WriteOperation { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract @@ -133,7 +133,7 @@ public class ERC20: IERC20, ERC20BaseProperties { public func approve(from: EthereumAddress, spender: EthereumAddress, amount: String) async throws -> WriteOperation { self.transaction.from = from self.transaction.to = self.address - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract @@ -154,7 +154,7 @@ public class ERC20: IERC20, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract .createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())! .callContractMethod() diff --git a/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift b/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift index f7a7082a3..aa55b5ab9 100644 --- a/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift +++ b/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift @@ -89,7 +89,7 @@ public class ERC721: IERC721 { return } guard contract.contract.address != nil else {return} - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest async let tokenIdPromise = contract.createReadOperation("tokenId", parameters: [AnyObject](), extraData: Data())?.callContractMethod() From 05c946f2fe468644a2f7716833b827a54c666008 Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 12:27:41 +0100 Subject: [PATCH 18/23] Fix ERC1400 --- .../Tokens/ERC1400/Web3+ERC1400.swift | 269 ++++++------------ 1 file changed, 87 insertions(+), 182 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift index 080090ad1..0e43236a6 100644 --- a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift +++ b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift @@ -86,27 +86,22 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -123,11 +118,8 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -145,11 +137,8 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func setAllowance(from: EthereumAddress, to: EthereumAddress, newAmount: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -167,18 +156,15 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 approve(from: EthereumAddress, spender: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -197,44 +183,35 @@ public class ERC1400: IERC1400, ERC20BaseProperties { // ERC1400 methods public func getDocument(name: Data) async throws -> (String, Data) { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getDocument", parameters: [name] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? (String, Data) else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func setDocument(from: EthereumAddress, name: Data, uri: String, documentHash: Data) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("setDocument", parameters: [name, uri, documentHash] as [AnyObject])! return tx } public func balanceOfByPartition(partition: Data, tokenHolder: EthereumAddress) async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOfByPartition", parameters: [partition, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 partitionsOf(tokenHolder: EthereumAddress) async throws -> [Data] { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("partitionsOf", parameters: [tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [Data] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func transferWithData(from: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -252,11 +229,8 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func transferFromWithData(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -274,11 +248,8 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func transferByPartition(partition: Data, from: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -296,11 +267,8 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func operatorTransferByPartition(partition: Data, from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String, data: [UInt8], operatorData: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -318,19 +286,15 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func isControllable() async throws -> Bool { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isControllable", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 controllerTransfer(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String, data: [UInt8], operatorData: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -348,11 +312,8 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func controllerRedeem(from: EthereumAddress, tokenHolder: EthereumAddress, amount: String, data: [UInt8], operatorData: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -370,71 +331,53 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func authorizeOperator(from: EthereumAddress, operator user: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] as [AnyObject])! return tx } public func revokeOperator(from: EthereumAddress, operator user: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("revokeOperator", parameters: [user] as [AnyObject])! return tx } public func authorizeOperatorByPartition(from: EthereumAddress, partition: Data, operator user: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("authorizeOperatorByPartition", parameters: [partition, user] as [AnyObject])! return tx } public func revokeOperatorByPartition(from: EthereumAddress, partition: Data, operator user: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("revokeOperatorByPartition", parameters: [partition, user] as [AnyObject])! return tx } public func isOperator(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperator", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 isOperatorForPartition(partition: Data, operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperatorForPartition", parameters: [partition, user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 isIssuable() async throws -> Bool { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isIssuable", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 issue(from: EthereumAddress, tokenHolder: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -452,11 +395,8 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func issueByPartition(from: EthereumAddress, partition: Data, tokenHolder: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -474,11 +414,8 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func redeem(from: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -496,11 +433,8 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func redeemFrom(from: EthereumAddress, tokenHolder: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -518,11 +452,8 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func redeemByPartition(from: EthereumAddress, partition: Data, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -540,11 +471,8 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func operatorRedeemByPartition(from: EthereumAddress, partition: Data, tokenHolder: EthereumAddress, amount: String, operatorData: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -562,8 +490,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func canTransfer(to: EthereumAddress, amount: String, data: [UInt8]) async throws -> ([UInt8], Data) { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -583,8 +510,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func canTransferFrom(originalOwner: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) async throws -> ([UInt8], Data) { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -604,8 +530,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func canTransferByPartition(originalOwner: EthereumAddress, to: EthereumAddress, partition: Data, amount: String, data: [UInt8]) async throws -> ([UInt8], Data, Data) { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -627,114 +552,89 @@ public class ERC1400: IERC1400, ERC20BaseProperties { extension ERC1400: IERC777 { public func canImplementInterfaceForAddress(interfaceHash: Data, addr: EthereumAddress) async throws -> Data { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("canImplementInterfaceForAddress", parameters: [interfaceHash, addr] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func getInterfaceImplementer(addr: EthereumAddress, interfaceHash: Data) async throws -> EthereumAddress { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getInterfaceImplementer", parameters: [addr, interfaceHash] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func setInterfaceImplementer(from: EthereumAddress, addr: EthereumAddress, interfaceHash: Data, implementer: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("setInterfaceImplementer", parameters: [addr, interfaceHash, implementer] as [AnyObject])! return tx } public func setManager(from: EthereumAddress, addr: EthereumAddress, newManager: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("setManager", parameters: [addr, newManager] as [AnyObject])! return tx } public func interfaceHash(interfaceName: String) async throws -> Data { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("interfaceHash", parameters: [interfaceName] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func updateERC165Cache(from: EthereumAddress, contract: EthereumAddress, interfaceId: [UInt8]) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - - let tx = contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId] as [AnyObject])! + updateTransactionAndContract(from: from) + let tx = self.contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId] as [AnyObject])! return tx } public func supportsInterface(interfaceID: String) async throws -> Bool { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod() 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 getGranularity() async throws -> BigUInt { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("granularity", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() 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 getDefaultOperators() async throws -> [EthereumAddress] { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("defaultOperators", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [EthereumAddress] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func authorize(from: EthereumAddress, operator user: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] as [AnyObject])! return tx } public func revoke(from: EthereumAddress, operator user: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("revokeOperator", parameters: [user] as [AnyObject])! return tx } public func isOperatorFor(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { - let contract = self.contract - self.transaction.callOnBlock = .latest + transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperatorFor", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 send(from: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -751,11 +651,8 @@ extension ERC1400: IERC777 { } public func operatorSend(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String, data: [UInt8], operatorData: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -772,11 +669,8 @@ extension ERC1400: IERC777 { } public func burn(from: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -793,11 +687,8 @@ extension ERC1400: IERC777 { } public func operatorBurn(from: EthereumAddress, amount: String, originalOwner: EthereumAddress, data: [UInt8], operatorData: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - self.transaction.from = from - self.transaction.to = self.address - self.transaction.callOnBlock = .latest - + transaction.callOnBlock = .latest + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -813,3 +704,17 @@ extension ERC1400: IERC777 { return tx } } + +// MARK: - Private + +extension ERC1400 { + + private func updateTransactionAndContract(from: EthereumAddress) { + transaction.from = from + transaction.to = address + contract.transaction = transaction + } + +} + + From dc621fd6309b72c2ce13be2dffcaa2d14d2987e7 Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 12:31:50 +0100 Subject: [PATCH 19/23] Fix ERC1410 --- .../Tokens/ERC1400/Web3+ERC1400.swift | 2 - .../Tokens/ERC1410/Web3+ERC1410.swift | 158 ++++-------------- 2 files changed, 35 insertions(+), 125 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift index 0e43236a6..1196fbf46 100644 --- a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift +++ b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift @@ -716,5 +716,3 @@ extension ERC1400 { } } - - diff --git a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift index 78ebaa81c..bc6788026 100644 --- a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift +++ b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift @@ -64,7 +64,6 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -72,7 +71,6 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -80,12 +78,8 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -102,12 +96,8 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -125,12 +115,8 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func setAllowance(from: EthereumAddress, to: EthereumAddress, newAmount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -148,8 +134,6 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - let contract = self.contract - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -157,12 +141,8 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func approve(from: EthereumAddress, spender: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -181,8 +161,6 @@ public class ERC1410: IERC1410, ERC20BaseProperties { // ERC1410 methods public func balanceOfByPartition(partition: Data, tokenHolder: EthereumAddress) async throws -> BigUInt { - let contract = self.contract - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOfByPartition", parameters: [partition, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -190,7 +168,6 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func partitionsOf(tokenHolder: EthereumAddress) async throws -> [Data] { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("partitionsOf", parameters: [tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [Data] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -198,12 +175,8 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func transferByPartition(partition: Data, from: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -221,12 +194,8 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func operatorTransferByPartition(partition: Data, from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String, data: [UInt8], operatorData: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -244,7 +213,6 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func canTransferByPartition(originalOwner: EthereumAddress, to: EthereumAddress, partition: Data, amount: String, data: [UInt8]) async throws -> ([UInt8], Data, Data) { - let contract = self.contract transaction.callOnBlock = .latest // get the decimals manually @@ -265,7 +233,6 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func isOperator(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperator", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -273,7 +240,6 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func isOperatorForPartition(partition: Data, operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperatorForPartition", parameters: [partition, user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -281,52 +247,32 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func authorizeOperator(from: EthereumAddress, operator user: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] as [AnyObject])! return tx } public func revokeOperator(from: EthereumAddress, operator user: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("revokeOperator", parameters: [user] as [AnyObject])! return tx } public func authorizeOperatorByPartition(from: EthereumAddress, partition: Data, operator user: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("authorizeOperatorByPartition", parameters: [partition, user] as [AnyObject])! return tx } public func revokeOperatorByPartition(from: EthereumAddress, partition: Data, operator user: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("revokeOperatorByPartition", parameters: [partition, user] as [AnyObject])! return tx } public func issueByPartition(from: EthereumAddress, partition: Data, tokenHolder: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -344,12 +290,8 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func redeemByPartition(from: EthereumAddress, partition: Data, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -367,12 +309,8 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func operatorRedeemByPartition(from: EthereumAddress, partition: Data, tokenHolder: EthereumAddress, amount: String, operatorData: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -392,7 +330,6 @@ public class ERC1410: IERC1410, ERC20BaseProperties { extension ERC1410: IERC777 { public func canImplementInterfaceForAddress(interfaceHash: Data, addr: EthereumAddress) async throws -> Data { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("canImplementInterfaceForAddress", parameters: [interfaceHash, addr] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -400,7 +337,6 @@ extension ERC1410: IERC777 { } public func getInterfaceImplementer(addr: EthereumAddress, interfaceHash: Data) async throws -> EthereumAddress { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getInterfaceImplementer", parameters: [addr, interfaceHash] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -408,25 +344,18 @@ extension ERC1410: IERC777 { } public func setInterfaceImplementer(from: EthereumAddress, addr: EthereumAddress, interfaceHash: Data, implementer: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("setInterfaceImplementer", parameters: [addr, interfaceHash, implementer] as [AnyObject])! return tx } public func setManager(from: EthereumAddress, addr: EthereumAddress, newManager: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("setManager", parameters: [addr, newManager] as [AnyObject])! return tx } public func interfaceHash(interfaceName: String) async throws -> Data { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("interfaceHash", parameters: [interfaceName] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -434,16 +363,12 @@ extension ERC1410: IERC777 { } public func updateERC165Cache(from: EthereumAddress, contract: EthereumAddress, interfaceId: [UInt8]) throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - - let tx = contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId] as [AnyObject])! + updateTransactionAndContract(from: from) + let tx = self.contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId] as [AnyObject])! return tx } public func supportsInterface(interfaceID: String) async throws -> Bool { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -451,27 +376,20 @@ extension ERC1410: IERC777 { } public func authorize(from: EthereumAddress, operator user: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] as [AnyObject])! return tx } public func revoke(from: EthereumAddress, operator user: EthereumAddress) throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) let tx = contract.createWriteOperation("revokeOperator", parameters: [user] as [AnyObject])! return tx } public func isOperatorFor(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperatorFor", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -479,12 +397,8 @@ extension ERC1410: IERC777 { } public func send(from: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -501,12 +415,8 @@ extension ERC1410: IERC777 { } public func operatorSend(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String, data: [UInt8], operatorData: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -523,12 +433,8 @@ extension ERC1410: IERC777 { } public func burn(from: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -545,12 +451,8 @@ extension ERC1410: IERC777 { } public func operatorBurn(from: EthereumAddress, amount: String, originalOwner: EthereumAddress, data: [UInt8], operatorData: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -567,7 +469,6 @@ extension ERC1410: IERC777 { } public func getGranularity() async throws -> BigUInt { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("granularity", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -575,10 +476,21 @@ extension ERC1410: IERC777 { } public func getDefaultOperators() async throws -> [EthereumAddress] { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("defaultOperators", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [EthereumAddress] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } } + +// MARK: - Private + +extension ERC1410 { + + private func updateTransactionAndContract(from: EthereumAddress) { + transaction.from = from + transaction.to = address + contract.transaction = transaction + } + +} From 8e89ff453f9978c3888759316d3daf9318e2cb39 Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 12:37:33 +0100 Subject: [PATCH 20/23] Fix ERC1594 --- .../Tokens/ERC1594/Web3+ERC1594.swift | 73 ++++++------------- 1 file changed, 21 insertions(+), 52 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift b/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift index e9315b8fd..525ecd36f 100644 --- a/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift +++ b/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift @@ -54,7 +54,6 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -62,7 +61,6 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -70,12 +68,8 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -92,12 +86,8 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -115,12 +105,8 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func setAllowance(from: EthereumAddress, to: EthereumAddress, newAmount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -138,8 +124,6 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - let contract = self.contract - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -147,12 +131,8 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func approve(from: EthereumAddress, spender: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -171,12 +151,8 @@ public class ERC1594: IERC1594, ERC20BaseProperties { // ERC1594 public func transferWithData(from: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -194,12 +170,8 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func transferFromWithData(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -217,7 +189,6 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func isIssuable() async throws -> Bool { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isIssuable", parameters: [AnyObject](), extraData: Data())!.callContractMethod() guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -225,12 +196,8 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func issue(from: EthereumAddress, tokenHolder: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -248,12 +215,8 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func redeem(from: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -271,12 +234,8 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func redeemFrom(from: EthereumAddress, tokenHolder: EthereumAddress, amount: String, data: [UInt8]) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -294,7 +253,6 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func canTransfer(to: EthereumAddress, amount: String, data: [UInt8]) async throws -> ([UInt8], Data) { - let contract = self.contract transaction.callOnBlock = .latest // get the decimals manually @@ -315,7 +273,6 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func canTransferFrom(originalOwner: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) async throws -> ([UInt8], Data) { - let contract = self.contract transaction.callOnBlock = .latest // get the decimals manually @@ -335,3 +292,15 @@ public class ERC1594: IERC1594, ERC20BaseProperties { return res } } + +// MARK: - Private + +extension ERC1594 { + + private func updateTransactionAndContract(from: EthereumAddress) { + transaction.from = from + transaction.to = address + contract.transaction = transaction + } + +} From 3adf0a9cbacdf8057143591bbcc5f40e5b933d1f Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 12:37:40 +0100 Subject: [PATCH 21/23] Fix ERC1633 --- .../Tokens/ERC1633/Web3+ERC1633.swift | 42 +++++++------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift index 84dff549d..b50121477 100644 --- a/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift +++ b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift @@ -41,7 +41,6 @@ public class ERC1633: IERC1633, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -49,7 +48,6 @@ public class ERC1633: IERC1633, ERC20BaseProperties { } public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -57,12 +55,8 @@ public class ERC1633: IERC1633, ERC20BaseProperties { } public func transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -79,12 +73,8 @@ public class ERC1633: IERC1633, ERC20BaseProperties { } public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -102,12 +92,8 @@ public class ERC1633: IERC1633, ERC20BaseProperties { } public func setAllowance(from: EthereumAddress, to: EthereumAddress, newAmount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -125,7 +111,6 @@ public class ERC1633: IERC1633, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -133,12 +118,8 @@ public class ERC1633: IERC1633, ERC20BaseProperties { } public func approve(from: EthereumAddress, spender: EthereumAddress, amount: String) async throws -> WriteOperation { - let contract = self.contract - - self.transaction.from = from - self.transaction.to = self.address transaction.callOnBlock = .latest - + updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -156,7 +137,6 @@ public class ERC1633: IERC1633, ERC20BaseProperties { } func parentToken() async throws -> EthereumAddress { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("parentToken", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -164,7 +144,6 @@ public class ERC1633: IERC1633, ERC20BaseProperties { } func parentTokenId() async throws -> BigUInt { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("parentTokenId", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -172,7 +151,6 @@ public class ERC1633: IERC1633, ERC20BaseProperties { } public func supportsInterface(interfaceID: String) async throws -> Bool { - let contract = self.contract transaction.callOnBlock = .latest let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} @@ -180,3 +158,15 @@ public class ERC1633: IERC1633, ERC20BaseProperties { } } + +// MARK: - Private + +extension ERC1633 { + + private func updateTransactionAndContract(from: EthereumAddress) { + transaction.from = from + transaction.to = address + contract.transaction = transaction + } + +} From 89a9c5d60f207674a245424fa16829d7d970a817 Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 22 Dec 2022 12:47:27 +0100 Subject: [PATCH 22/23] Fix some warnings in tests --- .../localTests/AdvancedABIv2Tests.swift | 15 +++++---------- .../localTests/PersonalSignatureTests.swift | 3 +-- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Tests/web3swiftTests/localTests/AdvancedABIv2Tests.swift b/Tests/web3swiftTests/localTests/AdvancedABIv2Tests.swift index 1be8abb35..f9bc88ef2 100755 --- a/Tests/web3swiftTests/localTests/AdvancedABIv2Tests.swift +++ b/Tests/web3swiftTests/localTests/AdvancedABIv2Tests.swift @@ -44,8 +44,7 @@ class AdvancedABIv2Tests: LocalTestCase { // MARK: Read data from ABI flow // MARK: - Encoding ABI Data flow let tx = contract.createReadOperation("testSingle") - let testSingle = try await tx!.callContractMethod() - + let _ = try await tx!.callContractMethod() } func testAdvancedABIv2staticArray() async throws { @@ -80,8 +79,7 @@ class AdvancedABIv2Tests: LocalTestCase { // MARK: Read data from ABI flow // MARK: - Encoding ABI Data flow let tx = contract.createReadOperation("testStaticArray") - let testStaticArray = try await tx!.callContractMethod() - + let _ = try await tx!.callContractMethod() } func testAdvancedABIv2dynamicArray() async throws { @@ -115,8 +113,7 @@ class AdvancedABIv2Tests: LocalTestCase { contract = web3.contract(abiString, at: receipt.contractAddress, abiVersion: 2)! let tx = contract.createReadOperation("testDynArray") - let testDynArray = try await tx!.callContractMethod() - + let _ = try await tx!.callContractMethod() } func testAdvancedABIv2dynamicArrayOfStrings() async throws { @@ -151,8 +148,7 @@ class AdvancedABIv2Tests: LocalTestCase { // MARK: Read data from ABI flow // MARK: - Encoding ABI Data flow let tx = contract.createReadOperation("testDynOfDyn") - let testDynOfDyn = try await tx!.callContractMethod() - + let _ = try await tx!.callContractMethod() } func testAdvancedABIv2staticArrayOfStrings() async throws { @@ -187,8 +183,7 @@ class AdvancedABIv2Tests: LocalTestCase { // MARK: Read data from ABI flow // MARK: - Encoding ABI Data flow let tx = contract.createReadOperation("testStOfDyn") - let testStOfDyn = try await tx!.callContractMethod() - + let _ = try await tx!.callContractMethod() } func testEmptyArrayDecoding() async throws { diff --git a/Tests/web3swiftTests/localTests/PersonalSignatureTests.swift b/Tests/web3swiftTests/localTests/PersonalSignatureTests.swift index 141b23b0d..852137efd 100755 --- a/Tests/web3swiftTests/localTests/PersonalSignatureTests.swift +++ b/Tests/web3swiftTests/localTests/PersonalSignatureTests.swift @@ -44,8 +44,7 @@ class PersonalSignatureTests: XCTestCase { Thread.sleep(forTimeInterval: 1.0) let receipt = try await web3.eth.transactionReceipt(txHash) - - + switch receipt.status { case .notYetProcessed: return From a20b1c4891e58795091514f1f36835af49ba21f8 Mon Sep 17 00:00:00 2001 From: JD Date: Tue, 10 Jan 2023 17:29:05 +0100 Subject: [PATCH 23/23] Remove obsolete setting of call on block --- .../Tokens/ERC1155/Web3+ERC1155.swift | 4 ---- .../Tokens/ERC1376/Web3+ERC1376.swift | 5 ---- .../Tokens/ERC1400/Web3+ERC1400.swift | 23 ------------------- .../Tokens/ERC1410/Web3+ERC1410.swift | 15 ------------ .../Tokens/ERC1594/Web3+ERC1594.swift | 9 -------- .../Tokens/ERC1633/Web3+ERC1633.swift | 6 ----- .../Tokens/ERC1643/Web3+ERC1643.swift | 5 ---- .../Tokens/ERC1644/Web3+ERC1644.swift | 4 ---- .../web3swift/Tokens/ERC20/Web3+ERC20.swift | 5 ---- .../web3swift/Tokens/ERC721/Web3+ERC721.swift | 13 ----------- .../web3swift/Tokens/ERC777/Web3+ERC777.swift | 10 -------- .../web3swift/Tokens/ERC888/Web3+ERC888.swift | 1 - Sources/web3swift/Tokens/ST20/Web3+ST20.swift | 4 ---- 13 files changed, 104 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift b/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift index 7a8987be7..3cc91263e 100644 --- a/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift +++ b/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift @@ -68,7 +68,6 @@ public class ERC1155: IERC1155 { return } guard contract.contract.address != nil else {return} - transaction.callOnBlock = .latest guard let tokenIdPromise = try await contract.createReadOperation("id", parameters: [] as [AnyObject], extraData: Data())?.callContractMethod() else {return} @@ -92,7 +91,6 @@ public class ERC1155: IERC1155 { } public func balanceOf(account: EthereumAddress, id: BigUInt) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract .createReadOperation("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data())! .callContractMethod() @@ -114,14 +112,12 @@ public class ERC1155: IERC1155 { } public func isApprovedForAll(owner: EthereumAddress, operator user: EthereumAddress, scope: Data) async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope] as [AnyObject], extraData: Data())!.callContractMethod() 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 { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod() 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 diff --git a/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift b/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift index 9e92bc722..8b5a7b34d 100644 --- a/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift +++ b/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift @@ -89,14 +89,12 @@ public class ERC1376: IERC1376, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -178,7 +176,6 @@ public class ERC1376: IERC1376, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 @@ -294,7 +291,6 @@ public class ERC1376: IERC1376, ERC20BaseProperties { } func nonceOf(owner: EthereumAddress) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("nonceOf", parameters: [owner] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -329,7 +325,6 @@ public class ERC1376: IERC1376, ERC20BaseProperties { } func directDebit(debtor: EthereumAddress, receiver: EthereumAddress) async throws -> DirectDebit { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("directDebit", parameters: [debtor, receiver] as [AnyObject], extraData: Data())!.callContractMethod() 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 diff --git a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift index 1196fbf46..fbdbb48bb 100644 --- a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift +++ b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift @@ -86,14 +86,12 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -156,7 +154,6 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 @@ -183,7 +180,6 @@ public class ERC1400: IERC1400, ERC20BaseProperties { // ERC1400 methods public func getDocument(name: Data) async throws -> (String, Data) { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getDocument", parameters: [name] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? (String, Data) else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -196,14 +192,12 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func balanceOfByPartition(partition: Data, tokenHolder: EthereumAddress) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOfByPartition", parameters: [partition, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 partitionsOf(tokenHolder: EthereumAddress) async throws -> [Data] { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("partitionsOf", parameters: [tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [Data] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -286,7 +280,6 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func isControllable() async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isControllable", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 @@ -355,21 +348,18 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func isOperator(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperator", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 isOperatorForPartition(partition: Data, operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperatorForPartition", parameters: [partition, user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 isIssuable() async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isIssuable", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 @@ -490,8 +480,6 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func canTransfer(to: EthereumAddress, amount: String, data: [UInt8]) async throws -> ([UInt8], Data) { - transaction.callOnBlock = .latest - // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -510,8 +498,6 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func canTransferFrom(originalOwner: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) async throws -> ([UInt8], Data) { - transaction.callOnBlock = .latest - // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -530,8 +516,6 @@ public class ERC1400: IERC1400, ERC20BaseProperties { } public func canTransferByPartition(originalOwner: EthereumAddress, to: EthereumAddress, partition: Data, amount: String, data: [UInt8]) async throws -> ([UInt8], Data, Data) { - transaction.callOnBlock = .latest - // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -552,14 +536,12 @@ public class ERC1400: IERC1400, ERC20BaseProperties { extension ERC1400: IERC777 { public func canImplementInterfaceForAddress(interfaceHash: Data, addr: EthereumAddress) async throws -> Data { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("canImplementInterfaceForAddress", parameters: [interfaceHash, addr] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func getInterfaceImplementer(addr: EthereumAddress, interfaceHash: Data) async throws -> EthereumAddress { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getInterfaceImplementer", parameters: [addr, interfaceHash] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -578,7 +560,6 @@ extension ERC1400: IERC777 { } public func interfaceHash(interfaceName: String) async throws -> Data { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("interfaceHash", parameters: [interfaceName] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -591,21 +572,18 @@ extension ERC1400: IERC777 { } public func supportsInterface(interfaceID: String) async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod() 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 getGranularity() async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("granularity", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() 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 getDefaultOperators() async throws -> [EthereumAddress] { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("defaultOperators", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [EthereumAddress] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -626,7 +604,6 @@ extension ERC1400: IERC777 { } public func isOperatorFor(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperatorFor", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 diff --git a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift index bc6788026..5cc788487 100644 --- a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift +++ b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift @@ -64,14 +64,12 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -134,7 +132,6 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 @@ -161,14 +158,12 @@ public class ERC1410: IERC1410, ERC20BaseProperties { // ERC1410 methods public func balanceOfByPartition(partition: Data, tokenHolder: EthereumAddress) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOfByPartition", parameters: [partition, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 partitionsOf(tokenHolder: EthereumAddress) async throws -> [Data] { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("partitionsOf", parameters: [tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [Data] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -213,8 +208,6 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func canTransferByPartition(originalOwner: EthereumAddress, to: EthereumAddress, partition: Data, amount: String, data: [UInt8]) async throws -> ([UInt8], Data, Data) { - transaction.callOnBlock = .latest - // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -233,14 +226,12 @@ public class ERC1410: IERC1410, ERC20BaseProperties { } public func isOperator(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperator", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 isOperatorForPartition(partition: Data, operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperatorForPartition", parameters: [partition, user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -330,14 +321,12 @@ public class ERC1410: IERC1410, ERC20BaseProperties { extension ERC1410: IERC777 { public func canImplementInterfaceForAddress(interfaceHash: Data, addr: EthereumAddress) async throws -> Data { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("canImplementInterfaceForAddress", parameters: [interfaceHash, addr] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func getInterfaceImplementer(addr: EthereumAddress, interfaceHash: Data) async throws -> EthereumAddress { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getInterfaceImplementer", parameters: [addr, interfaceHash] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -356,7 +345,6 @@ extension ERC1410: IERC777 { } public func interfaceHash(interfaceName: String) async throws -> Data { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("interfaceHash", parameters: [interfaceName] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -390,7 +378,6 @@ extension ERC1410: IERC777 { } public func isOperatorFor(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperatorFor", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -469,14 +456,12 @@ extension ERC1410: IERC777 { } public func getGranularity() async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("granularity", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() 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 getDefaultOperators() async throws -> [EthereumAddress] { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("defaultOperators", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [EthereumAddress] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res diff --git a/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift b/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift index 525ecd36f..0bba895bf 100644 --- a/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift +++ b/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift @@ -54,21 +54,18 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation { - transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() @@ -124,7 +121,6 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 @@ -189,7 +185,6 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func isIssuable() async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isIssuable", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 @@ -253,8 +248,6 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func canTransfer(to: EthereumAddress, amount: String, data: [UInt8]) async throws -> ([UInt8], Data) { - transaction.callOnBlock = .latest - // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) @@ -273,8 +266,6 @@ public class ERC1594: IERC1594, ERC20BaseProperties { } public func canTransferFrom(originalOwner: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) async throws -> ([UInt8], Data) { - transaction.callOnBlock = .latest - // get the decimals manually let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() var decimals = BigUInt(0) diff --git a/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift index b50121477..79f8219a9 100644 --- a/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift +++ b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift @@ -41,14 +41,12 @@ public class ERC1633: IERC1633, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -111,7 +109,6 @@ public class ERC1633: IERC1633, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 @@ -137,21 +134,18 @@ public class ERC1633: IERC1633, ERC20BaseProperties { } func parentToken() async throws -> EthereumAddress { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("parentToken", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } func parentTokenId() async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("parentTokenId", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() 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 supportsInterface(interfaceID: String) async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod() 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 diff --git a/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift b/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift index 5216ffe05..3885a1cf4 100644 --- a/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift +++ b/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift @@ -44,14 +44,12 @@ public class ERC1643: IERC1643, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -114,7 +112,6 @@ public class ERC1643: IERC1643, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 @@ -141,7 +138,6 @@ public class ERC1643: IERC1643, ERC20BaseProperties { // ERC1643 methods public func getDocument(name: Data) async throws -> (String, Data) { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getDocument", parameters: [name] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? (String, Data) else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -160,7 +156,6 @@ public class ERC1643: IERC1643, ERC20BaseProperties { } public func getAllDocuments() async throws -> [Data] { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getAllDocuments", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [Data] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res diff --git a/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift b/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift index fe8b4e20f..b1921794d 100644 --- a/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift +++ b/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift @@ -43,14 +43,12 @@ public class ERC1644: IERC1644, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -113,7 +111,6 @@ public class ERC1644: IERC1644, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 @@ -140,7 +137,6 @@ public class ERC1644: IERC1644, ERC20BaseProperties { // ERC1644 public func isControllable() async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isControllable", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 diff --git a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift index 1529ec06c..36ea8c26f 100644 --- a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift +++ b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift @@ -42,8 +42,6 @@ public class ERC20: IERC20, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - let contract = self.contract - transaction.callOnBlock = .latest let result = try await contract .createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())! .callContractMethod() @@ -52,8 +50,6 @@ public class ERC20: IERC20, ERC20BaseProperties { } public func getAllowance(originalOwner: EthereumAddress, delegate: EthereumAddress) async throws -> BigUInt { - let contract = self.contract - transaction.callOnBlock = .latest let result = try await contract .createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())! .callContractMethod() @@ -154,7 +150,6 @@ public class ERC20: IERC20, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract .createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())! .callContractMethod() diff --git a/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift b/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift index aa55b5ab9..a946b2deb 100644 --- a/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift +++ b/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift @@ -89,7 +89,6 @@ public class ERC721: IERC721 { return } guard contract.contract.address != nil else {return} - transaction.callOnBlock = .latest async let tokenIdPromise = contract.createReadOperation("tokenId", parameters: [AnyObject](), extraData: Data())?.callContractMethod() @@ -102,22 +101,18 @@ public class ERC721: IERC721 { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 getOwner(tokenId: BigUInt) async throws -> EthereumAddress { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("ownerOf", parameters: [tokenId] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func getApproved(tokenId: BigUInt) async throws -> EthereumAddress { - let contract = self.contract - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getApproved", parameters: [tokenId] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -160,14 +155,12 @@ public class ERC721: IERC721 { } public func isApprovedForAll(owner: EthereumAddress, operator user: EthereumAddress) async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user] as [AnyObject], extraData: Data())!.callContractMethod() 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 { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -192,21 +185,18 @@ extension ERC721 { extension ERC721: IERC721Enumerable { public func totalSupply() async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 tokenByIndex(index: BigUInt) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("tokenByIndex", parameters: [index] as [AnyObject], extraData: Data())!.callContractMethod() 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 tokenOfOwnerByIndex(owner: EthereumAddress, index: BigUInt) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("tokenOfOwnerByIndex", parameters: [owner, index] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -220,21 +210,18 @@ extension ERC721: IERC721Enumerable { extension ERC721: IERC721Metadata { public func name() async throws -> String { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("name", parameters: [AnyObject](), extraData: Data())!.callContractMethod() guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func symbol() async throws -> String { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("symbol", parameters: [AnyObject](), extraData: Data())!.callContractMethod() guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func tokenURI(tokenId: BigUInt) async throws -> String { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("tokenURI", parameters: [tokenId] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? String else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res diff --git a/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift index aa1203161..3af0acdef 100644 --- a/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift +++ b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift @@ -57,28 +57,24 @@ public class ERC777: IERC777, ERC20BaseProperties { } public func getGranularity() async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("granularity", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() 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 getDefaultOperators() async throws -> [EthereumAddress] { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("defaultOperators", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [EthereumAddress] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -141,7 +137,6 @@ public class ERC777: IERC777, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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 @@ -163,7 +158,6 @@ public class ERC777: IERC777, ERC20BaseProperties { } public func isOperatorFor(operator user: EthereumAddress, tokenHolder: EthereumAddress) async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("isOperatorFor", parameters: [user, tokenHolder] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -242,14 +236,12 @@ public class ERC777: IERC777, ERC20BaseProperties { } public func canImplementInterfaceForAddress(interfaceHash: Data, addr: EthereumAddress) async throws -> Data { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("canImplementInterfaceForAddress", parameters: [interfaceHash, addr] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res } public func getInterfaceImplementer(addr: EthereumAddress, interfaceHash: Data) async throws -> EthereumAddress { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("getInterfaceImplementer", parameters: [addr, interfaceHash] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -268,7 +260,6 @@ public class ERC777: IERC777, ERC20BaseProperties { } public func interfaceHash(interfaceName: String) async throws -> Data { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("interfaceHash", parameters: [interfaceName] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? Data else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -301,7 +292,6 @@ public class ERC777: IERC777, ERC20BaseProperties { } public func supportsInterface(interfaceID: String) async throws -> Bool { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data())!.callContractMethod() 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 diff --git a/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift b/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift index 99277c68d..65d472e54 100644 --- a/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift +++ b/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift @@ -39,7 +39,6 @@ public class ERC888: IERC888, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 diff --git a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift index dcbffb71a..c6da4b9c6 100644 --- a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift +++ b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift @@ -50,7 +50,6 @@ public class ST20: IST20, ERC20BaseProperties { } func tokenDetails() async throws -> [UInt32] { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("tokenDetails", parameters: [] as [AnyObject], extraData: Data())!.callContractMethod() guard let res = result["0"] as? [UInt32] else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")} return res @@ -113,14 +112,12 @@ public class ST20: IST20, ERC20BaseProperties { } public func getBalance(account: EthereumAddress) async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject], extraData: Data())!.callContractMethod() 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 { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate] as [AnyObject], extraData: Data())!.callContractMethod() 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 @@ -202,7 +199,6 @@ public class ST20: IST20, ERC20BaseProperties { } public func totalSupply() async throws -> BigUInt { - transaction.callOnBlock = .latest let result = try await contract.createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data())!.callContractMethod() 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