From ec81451c9944b08166e6069f5041c113135bd887 Mon Sep 17 00:00:00 2001 From: Anton Grigorev Date: Sat, 15 Dec 2018 02:45:39 +0300 Subject: [PATCH] Revert "Added erc1400 precompiled contract" --- web3swift.xcodeproj/project.pbxproj | 11 - .../ERC1400/Web3+ERC1400.swift | 522 ------------------ 2 files changed, 533 deletions(-) delete mode 100644 web3swift/PrecompiledContracts/ERC1400/Web3+ERC1400.swift diff --git a/web3swift.xcodeproj/project.pbxproj b/web3swift.xcodeproj/project.pbxproj index ee386164f..afbfbdfd6 100755 --- a/web3swift.xcodeproj/project.pbxproj +++ b/web3swift.xcodeproj/project.pbxproj @@ -212,7 +212,6 @@ E228BED021A4C89F0085268C /* Web3Legacy+Eth.swift in Sources */ = {isa = PBXBuildFile; fileRef = E228BEC921A4C89E0085268C /* Web3Legacy+Eth.swift */; }; E228BED121A4C89F0085268C /* Web3Legacy+Instance.swift in Sources */ = {isa = PBXBuildFile; fileRef = E228BECA21A4C89F0085268C /* Web3Legacy+Instance.swift */; }; E228BED221A4C89F0085268C /* Web3Legacy+Instance.swift in Sources */ = {isa = PBXBuildFile; fileRef = E228BECA21A4C89F0085268C /* Web3Legacy+Instance.swift */; }; - E279C9EC21C316D90081695F /* Web3+ERC1400.swift in Sources */ = {isa = PBXBuildFile; fileRef = E279C9EB21C316D90081695F /* Web3+ERC1400.swift */; }; E279C9EF21C46A140081695F /* Web3+ERC165.swift in Sources */ = {isa = PBXBuildFile; fileRef = E279C9EE21C46A140081695F /* Web3+ERC165.swift */; }; E2DCA653218C875100F94FBA /* web3swift_ENS_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A7B2782143C978004CD2C7 /* web3swift_ENS_Tests.swift */; }; E2DCA654218C879900F94FBA /* ENS.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2E668CD214F8A7B00C3CC2D /* ENS.swift */; }; @@ -395,7 +394,6 @@ E23B5ADC20EA685D00DC7F32 /* web3swift_EIP67_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = web3swift_EIP67_Tests.swift; sourceTree = ""; }; E23B5AE020EA695400DC7F32 /* web3swift_rinkeby_personalSignature_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = web3swift_rinkeby_personalSignature_Tests.swift; sourceTree = ""; }; E23B5AE220EA69B900DC7F32 /* web3swift_numberFormattingUtil_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = web3swift_numberFormattingUtil_Tests.swift; sourceTree = ""; }; - E279C9EB21C316D90081695F /* Web3+ERC1400.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+ERC1400.swift"; sourceTree = ""; }; E279C9EE21C46A140081695F /* Web3+ERC165.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+ERC165.swift"; sourceTree = ""; }; E2C590752152835400FF53D3 /* JSONRPCrequestDispatcher+ObjC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "JSONRPCrequestDispatcher+ObjC.swift"; sourceTree = ""; }; E2E94C5F217788E0005F54A0 /* Web3+ERC721.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+ERC721.swift"; sourceTree = ""; }; @@ -617,7 +615,6 @@ 8159C50921343EF900197B91 /* PrecompiledContracts */ = { isa = PBXGroup; children = ( - E279C9EA21C316BE0081695F /* ERC1400 */, 9196A68921B9F0B100852ED0 /* ERC777 */, E279C9ED21C3F2970081695F /* ERC165 */, E2E94C5E2177886C005F54A0 /* ERC721 */, @@ -963,13 +960,6 @@ path = Classes; sourceTree = ""; }; - E279C9EA21C316BE0081695F /* ERC1400 */ = { - isa = PBXGroup; - children = ( - E279C9EB21C316D90081695F /* Web3+ERC1400.swift */, - ); - path = ERC1400; - sourceTree = ""; E279C9ED21C3F2970081695F /* ERC165 */ = { isa = PBXGroup; children = ( @@ -1260,7 +1250,6 @@ 81C0FCF720441A1D00D82FAF /* TransactionSigner.swift in Sources */, 8125F06920499AC300A0F2FE /* BloomFilter.swift in Sources */, 810B0F9A1FEC446B00CF0DA2 /* Web3+JSONRPC.swift in Sources */, - E279C9EC21C316D90081695F /* Web3+ERC1400.swift in Sources */, 81195AB020D7FF8500ABC6B1 /* Promise+Web3+Contract+GetIndexedEvents.swift in Sources */, 81EB1E4B208173D7003BD47F /* Web3+Personal.swift in Sources */, E228BE7821A4492B0085268C /* Web3Legacy+BrowserFunctions.swift in Sources */, diff --git a/web3swift/PrecompiledContracts/ERC1400/Web3+ERC1400.swift b/web3swift/PrecompiledContracts/ERC1400/Web3+ERC1400.swift deleted file mode 100644 index daf5b0c19..000000000 --- a/web3swift/PrecompiledContracts/ERC1400/Web3+ERC1400.swift +++ /dev/null @@ -1,522 +0,0 @@ -// -// Web3+ERC1400.swift -// web3swift-iOS -// -// Created by Anton Grigorev on 14/12/2018. -// Copyright © 2018 The Matter Inc. All rights reserved. -// - -import Foundation -import BigInt -import EthereumAddress -import PromiseKit - -// ERC1400 = ERC20 + IERC1400 -protocol IERC1400 { - - // Document Management - func getDocument(name: Data) throws -> (String, Data) - func setDocument(from: EthereumAddress, name: Data, uri: String, documentHash: Data) throws -> WriteTransaction - - // Token Information - func balanceOfByPartition(partition: Data, tokenHolder: EthereumAddress) throws -> BigUInt - func partitionsOf(tokenHolder: EthereumAddress) throws -> [Data] - - // Transfers - func transferWithData(from: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) throws -> WriteTransaction - func transferFromWithData(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String, data: [UInt8]) throws -> WriteTransaction - - // Partition Token Transfers - func transferByPartition(partition: Data, from: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) throws -> WriteTransaction - func operatorTransferByPartition(partition: Data, from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String, data: [UInt8], operatorData: [UInt8]) throws -> WriteTransaction - - // Controller Operation - func isControllable() throws -> Bool - func controllerTransfer(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String, data: [UInt8], operatorData: [UInt8]) throws -> WriteTransaction - func controllerRedeem(from: EthereumAddress, tokenHolder: EthereumAddress, amount: String, data: [UInt8], operatorData: [UInt8]) throws -> WriteTransaction - - // Operator Management - func authorizeOperator(from: EthereumAddress, operator user: EthereumAddress) throws -> WriteTransaction - func revokeOperator(from: EthereumAddress, operator user: EthereumAddress) throws -> WriteTransaction - func authorizeOperatorByPartition(from: EthereumAddress, partition: Data, operator user: EthereumAddress) throws -> WriteTransaction - func revokeOperatorByPartition(from: EthereumAddress, partition: Data, operator user: EthereumAddress) throws -> WriteTransaction - - // Operator Information - func isOperator(operator user: EthereumAddress, tokenHolder: EthereumAddress) throws -> Bool - func isOperatorForPartition(partition: Data, operator user: EthereumAddress, tokenHolder: EthereumAddress) throws -> Bool - - // Token Issuance - func isIssuable() throws -> Bool - func issue(from: EthereumAddress, tokenHolder: EthereumAddress, amount: String, data: [UInt8]) throws -> WriteTransaction - func issueByPartition(from: EthereumAddress, partition: Data, tokenHolder: EthereumAddress, amount: String, data: [UInt8]) throws -> WriteTransaction - - // Token Redemption - func redeem(from: EthereumAddress, amount: String, data: [UInt8]) throws -> WriteTransaction - func redeemFrom(from: EthereumAddress, tokenHolder: EthereumAddress, amount: String, data: [UInt8]) throws -> WriteTransaction - func redeemByPartition(from: EthereumAddress, partition: Data, amount: String, data: [UInt8]) throws -> WriteTransaction - func operatorRedeemByPartition(from: EthereumAddress, partition: Data, tokenHolder: EthereumAddress, amount: String, operatorData: [UInt8]) throws -> WriteTransaction - - // Transfer Validity - func canTransfer(to: EthereumAddress, amount: String, data: [UInt8]) throws -> ([UInt8], Data) - func canTransferFrom(originalOwner: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) throws -> ([UInt8], Data) - func canTransferByPartition(originalOwner: EthereumAddress, to: EthereumAddress, partition: Data, amount: String, data: [UInt8]) throws -> ([UInt8], Data, Data) -} - -// This namespace contains functions to work with ERC1400 tokens. -// variables are lazyly evaluated or global token information (name, ticker, total supply) -// can be imperatively read and saved -public class ERC1400: ERC20, IERC1400 { - public func getDocument(name: Data) throws -> (String, Data) { - let contract = self.contract - var transactionOptions = TransactionOptions() - transactionOptions.callOnBlock = .latest - let result = try contract.read("getDocument", parameters: [name] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.call(transactionOptions: transactionOptions) - 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 -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - - let tx = contract.write("setDocument", parameters: [name, uri, documentHash] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func balanceOfByPartition(partition: Data, tokenHolder: EthereumAddress) throws -> BigUInt { - let contract = self.contract - var transactionOptions = TransactionOptions() - transactionOptions.callOnBlock = .latest - let result = try contract.read("balanceOfByPartition", parameters: [partition, tokenHolder] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.call(transactionOptions: transactionOptions) - 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) throws -> [Data] { - let contract = self.contract - var transactionOptions = TransactionOptions() - transactionOptions.callOnBlock = .latest - let result = try contract.read("partitionsOf", parameters: [tokenHolder] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.call(transactionOptions: transactionOptions) - 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]) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - basicOptions.callOnBlock = .latest - - // get the decimals manually - let callResult = try contract.read("decimals", transactionOptions: basicOptions)!.call() - var decimals = BigUInt(0) - guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { - throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")} - decimals = decTyped - - let intDecimals = Int(decimals) - guard let value = Web3.Utils.parseToBigUInt(amount, decimals: intDecimals) else { - throw Web3Error.inputError(desc: "Can not parse inputted amount") - } - - let tx = contract.write("transferWithData", parameters: [to, value, data] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func transferFromWithData(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String, data: [UInt8]) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - basicOptions.callOnBlock = .latest - - // get the decimals manually - let callResult = try contract.read("decimals", transactionOptions: basicOptions)!.call() - var decimals = BigUInt(0) - guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { - throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")} - decimals = decTyped - - let intDecimals = Int(decimals) - guard let value = Web3.Utils.parseToBigUInt(amount, decimals: intDecimals) else { - throw Web3Error.inputError(desc: "Can not parse inputted amount") - } - - let tx = contract.write("transferFromWithData", parameters: [originalOwner, to, value, data] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func transferByPartition(partition: Data, from: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - basicOptions.callOnBlock = .latest - - // get the decimals manually - let callResult = try contract.read("decimals", transactionOptions: basicOptions)!.call() - var decimals = BigUInt(0) - guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { - throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")} - decimals = decTyped - - let intDecimals = Int(decimals) - guard let value = Web3.Utils.parseToBigUInt(amount, decimals: intDecimals) else { - throw Web3Error.inputError(desc: "Can not parse inputted amount") - } - - let tx = contract.write("transferByPartition", parameters: [partition, to, value, data] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func operatorTransferByPartition(partition: Data, from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String, data: [UInt8], operatorData: [UInt8]) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - basicOptions.callOnBlock = .latest - - // get the decimals manually - let callResult = try contract.read("decimals", transactionOptions: basicOptions)!.call() - var decimals = BigUInt(0) - guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { - throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")} - decimals = decTyped - - let intDecimals = Int(decimals) - guard let value = Web3.Utils.parseToBigUInt(amount, decimals: intDecimals) else { - throw Web3Error.inputError(desc: "Can not parse inputted amount") - } - - let tx = contract.write("operatorTransferByPartition", parameters: [partition, originalOwner, to, value, data, operatorData] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func isControllable() throws -> Bool { - let contract = self.contract - var transactionOptions = TransactionOptions() - transactionOptions.callOnBlock = .latest - let result = try contract.read("isControllable", parameters: [AnyObject](), extraData: Data(), transactionOptions: self.transactionOptions)!.call(transactionOptions: transactionOptions) - 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]) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - basicOptions.callOnBlock = .latest - - // get the decimals manually - let callResult = try contract.read("decimals", transactionOptions: basicOptions)!.call() - var decimals = BigUInt(0) - guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { - throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")} - decimals = decTyped - - let intDecimals = Int(decimals) - guard let value = Web3.Utils.parseToBigUInt(amount, decimals: intDecimals) else { - throw Web3Error.inputError(desc: "Can not parse inputted amount") - } - - let tx = contract.write("controllerTransfer", parameters: [originalOwner, to, value, data, operatorData] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func controllerRedeem(from: EthereumAddress, tokenHolder: EthereumAddress, amount: String, data: [UInt8], operatorData: [UInt8]) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - basicOptions.callOnBlock = .latest - - // get the decimals manually - let callResult = try contract.read("decimals", transactionOptions: basicOptions)!.call() - var decimals = BigUInt(0) - guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { - throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")} - decimals = decTyped - - let intDecimals = Int(decimals) - guard let value = Web3.Utils.parseToBigUInt(amount, decimals: intDecimals) else { - throw Web3Error.inputError(desc: "Can not parse inputted amount") - } - - let tx = contract.write("controllerRedeem", parameters: [tokenHolder, value, data, operatorData] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func authorizeOperator(from: EthereumAddress, operator user: EthereumAddress) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - - let tx = contract.write("authorizeOperator", parameters: [user] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func revokeOperator(from: EthereumAddress, operator user: EthereumAddress) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - - let tx = contract.write("revokeOperator", parameters: [user] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func authorizeOperatorByPartition(from: EthereumAddress, partition: Data, operator user: EthereumAddress) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - - let tx = contract.write("authorizeOperatorByPartition", parameters: [partition, user] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func revokeOperatorByPartition(from: EthereumAddress, partition: Data, operator user: EthereumAddress) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - - let tx = contract.write("revokeOperatorByPartition", parameters: [partition, user] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func isOperator(operator user: EthereumAddress, tokenHolder: EthereumAddress) throws -> Bool { - let contract = self.contract - var transactionOptions = TransactionOptions() - transactionOptions.callOnBlock = .latest - let result = try contract.read("isOperator", parameters: [user, tokenHolder] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.call(transactionOptions: transactionOptions) - 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) throws -> Bool { - let contract = self.contract - var transactionOptions = TransactionOptions() - transactionOptions.callOnBlock = .latest - let result = try contract.read("isOperatorForPartition", parameters: [partition, user, tokenHolder] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.call(transactionOptions: transactionOptions) - 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() throws -> Bool { - let contract = self.contract - var transactionOptions = TransactionOptions() - transactionOptions.callOnBlock = .latest - let result = try contract.read("isIssuable", parameters: [AnyObject](), extraData: Data(), transactionOptions: self.transactionOptions)!.call(transactionOptions: transactionOptions) - 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]) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - basicOptions.callOnBlock = .latest - - // get the decimals manually - let callResult = try contract.read("decimals", transactionOptions: basicOptions)!.call() - var decimals = BigUInt(0) - guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { - throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")} - decimals = decTyped - - let intDecimals = Int(decimals) - guard let value = Web3.Utils.parseToBigUInt(amount, decimals: intDecimals) else { - throw Web3Error.inputError(desc: "Can not parse inputted amount") - } - - let tx = contract.write("issue", parameters: [tokenHolder, value, data] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func issueByPartition(from: EthereumAddress, partition: Data, tokenHolder: EthereumAddress, amount: String, data: [UInt8]) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - basicOptions.callOnBlock = .latest - - // get the decimals manually - let callResult = try contract.read("decimals", transactionOptions: basicOptions)!.call() - var decimals = BigUInt(0) - guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { - throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")} - decimals = decTyped - - let intDecimals = Int(decimals) - guard let value = Web3.Utils.parseToBigUInt(amount, decimals: intDecimals) else { - throw Web3Error.inputError(desc: "Can not parse inputted amount") - } - - let tx = contract.write("issueByPartition", parameters: [partition, tokenHolder, value, data] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func redeem(from: EthereumAddress, amount: String, data: [UInt8]) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - basicOptions.callOnBlock = .latest - - // get the decimals manually - let callResult = try contract.read("decimals", transactionOptions: basicOptions)!.call() - var decimals = BigUInt(0) - guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { - throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")} - decimals = decTyped - - let intDecimals = Int(decimals) - guard let value = Web3.Utils.parseToBigUInt(amount, decimals: intDecimals) else { - throw Web3Error.inputError(desc: "Can not parse inputted amount") - } - - let tx = contract.write("redeem", parameters: [value, data] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func redeemFrom(from: EthereumAddress, tokenHolder: EthereumAddress, amount: String, data: [UInt8]) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - basicOptions.callOnBlock = .latest - - // get the decimals manually - let callResult = try contract.read("decimals", transactionOptions: basicOptions)!.call() - var decimals = BigUInt(0) - guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { - throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")} - decimals = decTyped - - let intDecimals = Int(decimals) - guard let value = Web3.Utils.parseToBigUInt(amount, decimals: intDecimals) else { - throw Web3Error.inputError(desc: "Can not parse inputted amount") - } - - let tx = contract.write("redeemFrom", parameters: [tokenHolder, value, data] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func redeemByPartition(from: EthereumAddress, partition: Data, amount: String, data: [UInt8]) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - basicOptions.callOnBlock = .latest - - // get the decimals manually - let callResult = try contract.read("decimals", transactionOptions: basicOptions)!.call() - var decimals = BigUInt(0) - guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { - throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")} - decimals = decTyped - - let intDecimals = Int(decimals) - guard let value = Web3.Utils.parseToBigUInt(amount, decimals: intDecimals) else { - throw Web3Error.inputError(desc: "Can not parse inputted amount") - } - - let tx = contract.write("redeemByPartition", parameters: [partition, value, data] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func operatorRedeemByPartition(from: EthereumAddress, partition: Data, tokenHolder: EthereumAddress, amount: String, operatorData: [UInt8]) throws -> WriteTransaction { - let contract = self.contract - var basicOptions = TransactionOptions() - basicOptions.from = from - basicOptions.to = self.address - basicOptions.callOnBlock = .latest - - // get the decimals manually - let callResult = try contract.read("decimals", transactionOptions: basicOptions)!.call() - var decimals = BigUInt(0) - guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { - throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")} - decimals = decTyped - - let intDecimals = Int(decimals) - guard let value = Web3.Utils.parseToBigUInt(amount, decimals: intDecimals) else { - throw Web3Error.inputError(desc: "Can not parse inputted amount") - } - - let tx = contract.write("operatorRedeemByPartition", parameters: [partition, tokenHolder, value, operatorData] as [AnyObject], transactionOptions: basicOptions)! - return tx - } - - public func canTransfer(to: EthereumAddress, amount: String, data: [UInt8]) throws -> ([UInt8], Data) { - let contract = self.contract - var transactionOptions = TransactionOptions() - transactionOptions.callOnBlock = .latest - - // get the decimals manually - let callResult = try contract.read("decimals", transactionOptions: transactionOptions)!.call() - var decimals = BigUInt(0) - guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { - throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")} - decimals = decTyped - - let intDecimals = Int(decimals) - guard let value = Web3.Utils.parseToBigUInt(amount, decimals: intDecimals) else { - throw Web3Error.inputError(desc: "Can not parse inputted amount") - } - - let result = try contract.read("canTransfer", parameters: [to, value, data] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.call(transactionOptions: transactionOptions) - 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 - } - - public func canTransferFrom(originalOwner: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) throws -> ([UInt8], Data) { - let contract = self.contract - var transactionOptions = TransactionOptions() - transactionOptions.callOnBlock = .latest - - // get the decimals manually - let callResult = try contract.read("decimals", transactionOptions: transactionOptions)!.call() - var decimals = BigUInt(0) - guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { - throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")} - decimals = decTyped - - let intDecimals = Int(decimals) - guard let value = Web3.Utils.parseToBigUInt(amount, decimals: intDecimals) else { - throw Web3Error.inputError(desc: "Can not parse inputted amount") - } - - let result = try contract.read("canTransfer", parameters: [originalOwner, to, value, data] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.call(transactionOptions: transactionOptions) - 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 - } - - public func canTransferByPartition(originalOwner: EthereumAddress, to: EthereumAddress, partition: Data, amount: String, data: [UInt8]) throws -> ([UInt8], Data, Data) { - let contract = self.contract - var transactionOptions = TransactionOptions() - transactionOptions.callOnBlock = .latest - - // get the decimals manually - let callResult = try contract.read("decimals", transactionOptions: transactionOptions)!.call() - var decimals = BigUInt(0) - guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { - throw Web3Error.inputError(desc: "Contract may be not ERC20 compatible, can not get decimals")} - decimals = decTyped - - let intDecimals = Int(decimals) - guard let value = Web3.Utils.parseToBigUInt(amount, decimals: intDecimals) else { - throw Web3Error.inputError(desc: "Can not parse inputted amount") - } - - let result = try contract.read("canTransfer", parameters: [originalOwner, to, partition, value, data] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.call(transactionOptions: transactionOptions) - 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 - } -}