From d5df8e22c36b839c4596af0a2a62645768392c8b Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Fri, 13 Jan 2023 17:30:32 +0200 Subject: [PATCH 01/14] fix: removed the use of AnyObject in all places possible - replaced with Any --- .../WalletViewController.swift | 12 +- README.md | 2 +- Sources/Core/EthereumABI/ABIElements.swift | 6 +- .../Web3Core/Contract/ContractProtocol.swift | 16 +- .../Web3Core/EthereumABI/ABIDecoding.swift | 48 +++--- .../Web3Core/EthereumABI/ABIElements.swift | 6 +- .../Web3Core/EthereumABI/ABIEncoding.swift | 46 +++--- Sources/Web3Core/RLP/RLP.swift | 8 +- .../Envelope/EIP1559Envelope.swift | 8 +- .../Envelope/EIP2930Envelope.swift | 12 +- .../Transaction/Envelope/LegacyEnvelope.swift | 8 +- Sources/web3swift/Browser/browser.js | 14 +- .../web3swift/Operations/ReadOperation.swift | 2 +- .../Tokens/ERC1155/Web3+ERC1155.swift | 16 +- .../Tokens/ERC1376/Web3+ERC1376.swift | 44 +++--- .../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 +-- .../Tokens/ERC20/ERC20BaseProperties.swift | 2 +- .../web3swift/Tokens/ERC20/Web3+ERC20.swift | 14 +- .../web3swift/Tokens/ERC721/Web3+ERC721.swift | 36 ++--- .../Tokens/ERC721x/Web3+ERC721x.swift | 52 +++---- .../web3swift/Tokens/ERC777/Web3+ERC777.swift | 46 +++--- .../web3swift/Tokens/ERC888/Web3+ERC888.swift | 4 +- Sources/web3swift/Tokens/ST20/Web3+ST20.swift | 22 +-- .../Tokens/ST20/Web3+SecurityToken.swift | 36 ++--- Sources/web3swift/Utils/EIP/EIP67Code.swift | 2 +- Sources/web3swift/Utils/EIP/EIP681.swift | 42 +++--- Sources/web3swift/Utils/EIP/EIP712.swift | 8 +- .../Utils/ENS/ENSBaseRegistrar.swift | 12 +- Sources/web3swift/Utils/ENS/ENSRegistry.swift | 14 +- Sources/web3swift/Utils/ENS/ENSResolver.swift | 28 ++-- .../Utils/ENS/ENSReverseRegistrar.swift | 10 +- .../Utils/ENS/ETHRegistrarController.swift | 16 +- Sources/web3swift/Web3/Web3+Contract.swift | 6 +- Sources/web3swift/Web3/Web3+Utils.swift | 2 +- .../localTests/ABIEncoderTest.swift | 138 +++++++++--------- .../localTests/AdvancedABIv2Tests.swift | 8 +- .../localTests/BasicLocalNodeTests.swift | 4 +- .../localTests/EIP681Tests.swift | 28 ++-- .../localTests/EIP712Tests.swift | 8 +- .../localTests/ERC20Tests.swift | 4 +- .../localTests/EthereumContractTest.swift | 6 +- .../localTests/PersonalSignatureTests.swift | 4 +- .../localTests/PromisesTests.swift | 8 +- .../ST20AndSecurityTokenTests.swift | 14 +- .../localTests/TestHelpers.swift | 4 +- .../localTests/UncategorizedTests.swift | 4 +- .../web3swiftTests/localTests/UserCases.swift | 4 +- 52 files changed, 555 insertions(+), 545 deletions(-) diff --git a/Example/myWeb3Wallet/myWeb3Wallet/ViewControllers/WalletController/WalletViewController.swift b/Example/myWeb3Wallet/myWeb3Wallet/ViewControllers/WalletController/WalletViewController.swift index 1326f3e7a..c766c5758 100644 --- a/Example/myWeb3Wallet/myWeb3Wallet/ViewControllers/WalletController/WalletViewController.swift +++ b/Example/myWeb3Wallet/myWeb3Wallet/ViewControllers/WalletController/WalletViewController.swift @@ -89,13 +89,13 @@ class WalletViewController: UIViewController { let manager = KeystoreManager([myWeb3KeyStore]) let address = keystore?.addresses?.first #if DEBUG - print("Address :::>>>>> ", address as Any) - print("Address :::>>>>> ", manager.addresses as Any) + print("Address :::>>>>> ", address) + print("Address :::>>>>> ", manager.addresses) #endif let walletAddress = manager.addresses?.first?.address self.walletAddressLabel.text = walletAddress ?? "0x" - print(walletAddress as Any) + print(walletAddress) } else { print("error") } @@ -115,7 +115,7 @@ class WalletViewController: UIViewController { } func importWalletWith(mnemonics: String) { let walletAddress = try? BIP32Keystore(mnemonics: mnemonics , prefixPath: "m/44'/77777'/0'/0") - print(walletAddress?.addresses as Any) + print(walletAddress?.addresses) self.walletAddressLabel.text = "\(walletAddress?.addresses?.first?.address ?? "0x")" } @@ -137,7 +137,7 @@ extension WalletViewController { self._mnemonics = tMnemonics print(_mnemonics) let tempWalletAddress = try? BIP32Keystore(mnemonics: self._mnemonics , prefixPath: "m/44'/77777'/0'/0") - print(tempWalletAddress?.addresses?.first?.address as Any) + print(tempWalletAddress?.addresses?.first?.address) guard let walletAddress = tempWalletAddress?.addresses?.first else { self.showAlertMessage(title: "", message: "We are unable to create wallet", actionName: "Ok") return @@ -145,7 +145,7 @@ extension WalletViewController { self._walletAddress = walletAddress.address let privateKey = try tempWalletAddress?.UNSAFE_getPrivateKeyData(password: "", account: walletAddress) #if DEBUG - print(privateKey as Any, "Is the private key") + print(privateKey, "Is the private key") #endif let keyData = try? JSONEncoder().encode(tempWalletAddress?.keystoreParams) FileManager.default.createFile(atPath: userDir + "/keystore"+"/key.json", contents: keyData, attributes: nil) diff --git a/README.md b/README.md index 92c686767..9ed1c18c5 100755 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ let response = try await readTX.callContractMethod() let abiString = "[]" // some ABI string let bytecode = Data.fromHex("") // some ABI bite sequence let contract = web3.contract(abiString, at: nil, abiVersion: 2)! -let parameters = [...] as [AnyObject] +let parameters: [Any] = [...] let deployOp = contract.prepareDeploy(bytecode: bytecode, constructor: contract.contract.constructor, parameters: parameters)! deployOp.transaction.from = "" // your address deployOp.transaction.gasLimitPolicy = .manual(3000000) diff --git a/Sources/Core/EthereumABI/ABIElements.swift b/Sources/Core/EthereumABI/ABIElements.swift index c947f6159..2e18b9dcb 100755 --- a/Sources/Core/EthereumABI/ABIElements.swift +++ b/Sources/Core/EthereumABI/ABIElements.swift @@ -173,7 +173,7 @@ public extension ABI { // MARK: - Function parameters encoding extension ABI.Element { - public func encodeParameters(_ parameters: [AnyObject]) -> Data? { + public func encodeParameters(_ parameters: [Any]) -> Data? { switch self { case .constructor(let constructor): return constructor.encodeParameters(parameters) @@ -192,7 +192,7 @@ extension ABI.Element { } extension ABI.Element.Constructor { - public func encodeParameters(_ parameters: [AnyObject]) -> Data? { + public func encodeParameters(_ parameters: [Any]) -> Data? { guard parameters.count == inputs.count else { return nil } return ABIEncoder.encode(types: inputs, values: parameters) } @@ -203,7 +203,7 @@ extension ABI.Element.Function { /// Encode parameters of a given contract method /// - Parameter parameters: Parameters to pass to Ethereum contract /// - Returns: Encoded data - public func encodeParameters(_ parameters: [AnyObject]) -> Data? { + public func encodeParameters(_ parameters: [Any]) -> Data? { guard parameters.count == inputs.count, let data = ABIEncoder.encode(types: inputs, values: parameters) else { return nil } return methodEncoding + data diff --git a/Sources/Web3Core/Contract/ContractProtocol.swift b/Sources/Web3Core/Contract/ContractProtocol.swift index 9302cbc8e..33e25884d 100755 --- a/Sources/Web3Core/Contract/ContractProtocol.swift +++ b/Sources/Web3Core/Contract/ContractProtocol.swift @@ -35,7 +35,7 @@ import BigInt /// let inputArgsTypes: [ABI.Element.InOut] = [.init(name: "firstArgument", type: ABI.Element.ParameterType.string), /// .init(name: "secondArgument", type: ABI.Element.ParameterType.uint(bits: 256))] /// let constructor = ABI.Element.Constructor(inputs: inputArgsTypes, constant: false, payable: payable) -/// let constructorArguments = ["This is the array of constructor arguments", 10_000] as [AnyObject] +/// let constructorArguments = ["This is the array of constructor arguments", 10_000] /// /// contract.deploy(bytecode: smartContractBytecode, /// constructor: constructor, @@ -48,7 +48,7 @@ import BigInt /// /// ```swift /// let contract = EthereumContract(abiString) -/// let constructorArguments = ["This is the array of constructor arguments", 10_000] as [AnyObject] +/// let constructorArguments = ["This is the array of constructor arguments", 10_000] /// /// contract.deploy(bytecode: smartContractBytecode, /// constructor: contract.constructor, @@ -121,7 +121,7 @@ public protocol ContractProtocol { /// - Returns: Encoded data for a given parameters, which is should be assigned to ``CodableTransaction.data`` property func deploy(bytecode: Data, constructor: ABI.Element.Constructor?, - parameters: [AnyObject]?, + parameters: [Any]?, extraData: Data?) -> Data? /// Creates function call transaction with data set as `method` encoded with given `parameters`. @@ -134,7 +134,7 @@ public protocol ContractProtocol { /// - parameters: method input arguments; /// - extraData: additional data to append at the end of `transaction.data` field; /// - Returns: transaction object if `method` was found and `parameters` were successfully encoded. - func method(_ method: String, parameters: [AnyObject], extraData: Data?) -> Data? + func method(_ method: String, parameters: [Any], extraData: Data?) -> Data? /// Decode output data of a function. /// - Parameters: @@ -190,7 +190,7 @@ extension ContractProtocol { /// See ``ContractProtocol/deploy(bytecode:constructor:parameters:extraData:)`` for details. func deploy(_ bytecode: Data, constructor: ABI.Element.Constructor? = nil, - parameters: [AnyObject]? = nil, + parameters: [Any]? = nil, extraData: Data? = nil) -> Data? { deploy(bytecode: bytecode, constructor: constructor, @@ -203,7 +203,7 @@ extension ContractProtocol { /// /// See ``ContractProtocol/method(_:parameters:extraData:)`` for details. func method(_ method: String = "fallback", - parameters: [AnyObject]? = nil, + parameters: [Any]? = nil, extraData: Data? = nil) -> Data? { self.method(method, parameters: parameters ?? [], extraData: extraData) } @@ -222,7 +222,7 @@ extension DefaultContractProtocol { // MARK: Writing Data flow public func deploy(bytecode: Data, constructor: ABI.Element.Constructor?, - parameters: [AnyObject]?, + parameters: [Any]?, extraData: Data?) -> Data? { var fullData = bytecode @@ -258,7 +258,7 @@ extension DefaultContractProtocol { /// - data: parameters + extraData /// - params: EthereumParameters with no contract method call encoded data. public func method(_ method: String, - parameters: [AnyObject], + parameters: [Any], extraData: Data?) -> Data? { // MARK: - Encoding ABI Data flow if method == "fallback" { diff --git a/Sources/Web3Core/EthereumABI/ABIDecoding.swift b/Sources/Web3Core/EthereumABI/ABIDecoding.swift index 7dad9179f..adcb77b09 100755 --- a/Sources/Web3Core/EthereumABI/ABIDecoding.swift +++ b/Sources/Web3Core/EthereumABI/ABIDecoding.swift @@ -9,15 +9,15 @@ import BigInt public struct ABIDecoder { } extension ABIDecoder { - public static func decode(types: [ABI.Element.InOut], data: Data) -> [AnyObject]? { + public static func decode(types: [ABI.Element.InOut], data: Data) -> [Any]? { let params = types.compactMap { el -> ABI.Element.ParameterType in return el.type } return decode(types: params, data: data) } - public static func decode(types: [ABI.Element.ParameterType], data: Data) -> [AnyObject]? { - var toReturn = [AnyObject]() + public static func decode(types: [ABI.Element.ParameterType], data: Data) -> [Any]? { + var toReturn = [Any]() var consumed: UInt64 = 0 for i in 0 ..< types.count { let (v, c) = decodeSingleType(type: types[i], data: data, pointer: consumed) @@ -29,7 +29,7 @@ extension ABIDecoder { return toReturn } - public static func decodeSingleType(type: ABI.Element.ParameterType, data: Data, pointer: UInt64 = 0) -> (value: AnyObject?, bytesConsumed: UInt64?) { + public static func decodeSingleType(type: ABI.Element.ParameterType, data: Data, pointer: UInt64 = 0) -> (value: Any?, bytesConsumed: UInt64?) { let (elData, nextPtr) = followTheData(type: type, data: data, pointer: pointer) guard let elementItself = elData, let nextElementPointer = nextPtr else { return (nil, nil) @@ -40,18 +40,18 @@ extension ABIDecoder { let mod = BigUInt(1) << bits let dataSlice = elementItself[0 ..< 32] let v = BigUInt(dataSlice) % mod - return (v as AnyObject, type.memoryUsage) + return (v, type.memoryUsage) case .int(let bits): guard elementItself.count >= 32 else {break} let mod = BigInt(1) << bits let dataSlice = elementItself[0 ..< 32] let v = BigInt.fromTwosComplement(data: dataSlice) % mod - return (v as AnyObject, type.memoryUsage) + return (v, type.memoryUsage) case .address: guard elementItself.count >= 32 else {break} let dataSlice = elementItself[12 ..< 32] let address = EthereumAddress(dataSlice) - return (address as AnyObject, type.memoryUsage) + return (address, type.memoryUsage) case .bool: guard elementItself.count >= 32 else {break} let dataSlice = elementItself[0 ..< 32] @@ -60,17 +60,17 @@ extension ABIDecoder { v == BigUInt(32) || v == BigUInt(28) || v == BigUInt(1) { - return (true as AnyObject, type.memoryUsage) + return (true, type.memoryUsage) } else if v == BigUInt(35) || v == BigUInt(31) || v == BigUInt(27) || v == BigUInt(0) { - return (false as AnyObject, type.memoryUsage) + return (false, type.memoryUsage) } case .bytes(let length): guard elementItself.count >= 32 else {break} let dataSlice = elementItself[0 ..< length] - return (dataSlice as AnyObject, type.memoryUsage) + return (dataSlice, type.memoryUsage) case .string: guard elementItself.count >= 32 else {break} var dataSlice = elementItself[0 ..< 32] @@ -78,14 +78,14 @@ extension ABIDecoder { guard elementItself.count >= 32+length else {break} dataSlice = elementItself[32 ..< 32 + length] guard let string = String(data: dataSlice, encoding: .utf8) else {break} - return (string as AnyObject, type.memoryUsage) + return (string, type.memoryUsage) case .dynamicBytes: guard elementItself.count >= 32 else {break} var dataSlice = elementItself[0 ..< 32] let length = UInt64(BigUInt(dataSlice)) guard elementItself.count >= 32+length else {break} dataSlice = elementItself[32 ..< 32 + length] - return (dataSlice as AnyObject, nextElementPointer) + return (dataSlice, nextElementPointer) case .array(type: let subType, length: let length): switch type.arraySize { case .dynamicSize: @@ -97,14 +97,14 @@ extension ABIDecoder { guard elementItself.count >= 32 + subType.memoryUsage*length else {break} dataSlice = elementItself[32 ..< 32 + subType.memoryUsage*length] var subpointer: UInt64 = 32 - var toReturn = [AnyObject]() + var toReturn = [Any]() for _ in 0 ..< length { let (v, c) = decodeSingleType(type: subType, data: elementItself, pointer: subpointer) guard let valueUnwrapped = v, let consumedUnwrapped = c else {break} toReturn.append(valueUnwrapped) subpointer = subpointer + consumedUnwrapped } - return (toReturn as AnyObject, type.memoryUsage) + return (toReturn, type.memoryUsage) } else { // in principle is true for tuple[], so will work for string[] too guard elementItself.count >= 32 else {break} @@ -113,7 +113,7 @@ extension ABIDecoder { guard elementItself.count >= 32 else {break} dataSlice = Data(elementItself[32 ..< elementItself.count]) var subpointer: UInt64 = 0 - var toReturn = [AnyObject]() + var toReturn = [Any]() for _ in 0 ..< length { let (v, c) = decodeSingleType(type: subType, data: dataSlice, pointer: subpointer) guard let valueUnwrapped = v, let consumedUnwrapped = c else {break} @@ -124,11 +124,11 @@ extension ABIDecoder { subpointer = consumedUnwrapped // need to go by nextElementPointer } } - return (toReturn as AnyObject, nextElementPointer) + return (toReturn, nextElementPointer) } case .staticSize(let staticLength): guard length == staticLength else {break} - var toReturn = [AnyObject]() + var toReturn = [Any]() var consumed: UInt64 = 0 for _ in 0 ..< length { let (v, c) = decodeSingleType(type: subType, data: elementItself, pointer: consumed) @@ -137,15 +137,15 @@ extension ABIDecoder { consumed = consumed + consumedUnwrapped } if subType.isStatic { - return (toReturn as AnyObject, consumed) + return (toReturn, consumed) } else { - return (toReturn as AnyObject, nextElementPointer) + return (toReturn, nextElementPointer) } case .notArray: break } case .tuple(types: let subTypes): - var toReturn = [AnyObject]() + var toReturn = [Any]() var consumed: UInt64 = 0 for i in 0 ..< subTypes.count { let (v, c) = decodeSingleType(type: subTypes[i], data: elementItself, pointer: consumed) @@ -173,14 +173,14 @@ extension ABIDecoder { } } if type.isStatic { - return (toReturn as AnyObject, consumed) + return (toReturn, consumed) } else { - return (toReturn as AnyObject, nextElementPointer) + return (toReturn, nextElementPointer) } case .function: guard elementItself.count >= 32 else {break} let dataSlice = elementItself[8 ..< 32] - return (dataSlice as AnyObject, type.memoryUsage) + return (dataSlice, type.memoryUsage) } return (nil, nil) } @@ -236,7 +236,7 @@ extension ABIDecoder { return inp.type } guard logs.count == indexedInputs.count + 1 else {return nil} - var indexedValues = [AnyObject]() + var indexedValues = [Any]() for i in 0 ..< indexedInputs.count { let data = logs[i+1] let input = indexedInputs[i] diff --git a/Sources/Web3Core/EthereumABI/ABIElements.swift b/Sources/Web3Core/EthereumABI/ABIElements.swift index aadf61b9a..6a1e80716 100755 --- a/Sources/Web3Core/EthereumABI/ABIElements.swift +++ b/Sources/Web3Core/EthereumABI/ABIElements.swift @@ -174,7 +174,7 @@ public extension ABI { // MARK: - Function parameters encoding extension ABI.Element { - public func encodeParameters(_ parameters: [AnyObject]) -> Data? { + public func encodeParameters(_ parameters: [Any]) -> Data? { switch self { case .constructor(let constructor): return constructor.encodeParameters(parameters) @@ -193,7 +193,7 @@ extension ABI.Element { } extension ABI.Element.Constructor { - public func encodeParameters(_ parameters: [AnyObject]) -> Data? { + public func encodeParameters(_ parameters: [Any]) -> Data? { guard parameters.count == inputs.count else { return nil } return ABIEncoder.encode(types: inputs, values: parameters) } @@ -204,7 +204,7 @@ extension ABI.Element.Function { /// Encode parameters of a given contract method /// - Parameter parameters: Parameters to pass to Ethereum contract /// - Returns: Encoded data - public func encodeParameters(_ parameters: [AnyObject]) -> Data? { + public func encodeParameters(_ parameters: [Any]) -> Data? { guard parameters.count == inputs.count, let data = ABIEncoder.encode(types: inputs, values: parameters) else { return nil } return methodEncoding + data diff --git a/Sources/Web3Core/EthereumABI/ABIEncoding.swift b/Sources/Web3Core/EthereumABI/ABIEncoding.swift index f62177ec8..7a73c2477 100755 --- a/Sources/Web3Core/EthereumABI/ABIEncoding.swift +++ b/Sources/Web3Core/EthereumABI/ABIEncoding.swift @@ -12,7 +12,7 @@ public struct ABIEncoder { /// All negative values will return `nil`. /// - Parameter value: an arbitrary object. /// - Returns: converted value or `nil` if types is not support or initialization failed. - public static func convertToBigUInt(_ value: AnyObject) -> BigUInt? { + public static func convertToBigUInt(_ value: Any) -> BigUInt? { switch value { case let v as BigUInt: return v @@ -60,7 +60,7 @@ public struct ABIEncoder { /// Supported types are `BigUInt`, `BigInt`, `String` as hex and decimal, `UInt[8-64]`, `Int[8-64]` and `Data`. /// - Parameter value: an arbitrary object. /// - Returns: converted value or `nil` if types is not support or initialization failed. - public static func convertToBigInt(_ value: AnyObject) -> BigInt? { + public static func convertToBigInt(_ value: Any) -> BigInt? { switch value { case let v as BigUInt: return BigInt(v) @@ -102,7 +102,7 @@ public struct ABIEncoder { /// Note: if `String` has `0x` prefix an attempt to interpret it as a hexadecimal number will take place. Otherwise, UTF-8 bytes are returned. /// - Parameter value: any object. /// - Returns: `Data` representation of an object ready for ABI encoding. - public static func convertToData(_ value: AnyObject) -> Data? { + public static func convertToData(_ value: Any) -> Data? { switch value { case let d as Data: return d @@ -137,7 +137,7 @@ public struct ABIEncoder { /// - Returns: ABI encoded data, e.g. function call parameters. Returns `nil` if: /// - `types.count != values.count`; /// - encoding of at least one value has failed (e.g. type mismatch). - public static func encode(types: [ABI.Element.InOut], values: [AnyObject]) -> Data? { + public static func encode(types: [ABI.Element.InOut], values: [Any]) -> Data? { guard types.count == values.count else {return nil} let params = types.compactMap { el -> ABI.Element.ParameterType in return el.type @@ -153,7 +153,7 @@ public struct ABIEncoder { /// - Returns: ABI encoded data, e.g. function call parameters. Returns `nil` if: /// - `types.count != values.count`; /// - encoding of at least one value has failed (e.g. type mismatch). - public static func encode(types: [ABI.Element.ParameterType], values: [AnyObject]) -> Data? { + public static func encode(types: [ABI.Element.ParameterType], values: [Any]) -> Data? { guard types.count == values.count else {return nil} var tails = [Data]() var heads = [Data]() @@ -195,7 +195,7 @@ public struct ABIEncoder { /// /// **It does not add the data offset for dynamic types!!** To return single value **with data offset** use the following instead: /// ```swift - /// ABIEncoder.encode(types: [type], values: [value] as [AnyObject]) + /// ABIEncoder.encode(types: [type], values: [value]) /// ``` /// Almost identical to use of `web3.eth.abi.encodeParameter` in web3.js. /// Calling `web3.eth.abi.encodeParameter('string','test')` in web3.js will return the following: @@ -204,7 +204,7 @@ public struct ABIEncoder { /// 0000000000000000000000000000000000000000000000000000000000000004 /// 7465737400000000000000000000000000000000000000000000000000000000 /// ``` - /// but calling `ABIEncoder.encodeSingleType(type: .string, value: "test" as AnyObject)` will return: + /// but calling `ABIEncoder.encodeSingleType(type: .string, value: "test")` will return: /// ``` /// 0x0000000000000000000000000000000000000000000000000000000000000004 /// 7465737400000000000000000000000000000000000000000000000000000000 @@ -215,7 +215,7 @@ public struct ABIEncoder { /// - Returns: ABI encoded data, e.g. function call parameters. Returns `nil` if: /// - `types.count != values.count`; /// - encoding has failed (e.g. type mismatch). - public static func encodeSingleType(type: ABI.Element.ParameterType, value: AnyObject) -> Data? { + public static func encodeSingleType(type: ABI.Element.ParameterType, value: Any) -> Data? { switch type { case .uint: if let biguint = convertToBigUInt(value) { @@ -283,7 +283,7 @@ public struct ABIEncoder { switch type.arraySize { case .dynamicSize: guard length == 0 else {break} - guard let val = value as? [AnyObject] else {break} + guard let val = value as? [Any] else {break} guard let lengthEncoding = BigUInt(val.count).abiEncode(bits: 256) else {break} if subType.isStatic { // work in a previous context @@ -330,7 +330,7 @@ public struct ABIEncoder { } case .staticSize(let staticLength): guard staticLength != 0 else {break} - guard let val = value as? [AnyObject] else {break} + guard let val = value as? [Any] else {break} guard staticLength == val.count else {break} if subType.isStatic { // work in a previous context @@ -375,7 +375,7 @@ public struct ABIEncoder { case .tuple(types: let subTypes): var tails = [Data]() var heads = [Data]() - guard let val = value as? [AnyObject] else {break} + guard let val = value as? [Any] else {break} for i in 0 ..< subTypes.count { let enc = encodeSingleType(type: subTypes[i], value: val[i]) guard let encoding = enc else {return nil} @@ -444,7 +444,7 @@ public extension ABIEncoder { } } - /// Using AnyObject any number can be represented as Bool and Bool can be represented as number. + /// Using Any any number can be represented as Bool and Bool can be represented as number. /// That will lead to invalid hash output. DO NOT USE THIS FUNCTION. /// This function will exist to intentionally throw an error that will raise awareness that the hash output can be potentially, /// and most likely will be, wrong. @@ -471,26 +471,26 @@ public extension ABIEncoder { if let v = value as? Bool { return Data(v ? [0b1] : [0b0]) } else if let v = value as? Int { - return ABIEncoder.convertToData(BigInt(exactly: v)?.abiEncode(bits: 256)! as AnyObject)! + return ABIEncoder.convertToData(BigInt(exactly: v)?.abiEncode(bits: 256)!)! } else if let v = value as? Int8 { - return ABIEncoder.convertToData(BigInt(exactly: v)?.abiEncode(bits: 8) as AnyObject)! + return ABIEncoder.convertToData(BigInt(exactly: v)?.abiEncode(bits: 8))! } else if let v = value as? Int16 { - return ABIEncoder.convertToData(BigInt(exactly: v)?.abiEncode(bits: 16)! as AnyObject)! + return ABIEncoder.convertToData(BigInt(exactly: v)?.abiEncode(bits: 16)!)! } else if let v = value as? Int32 { - return ABIEncoder.convertToData(BigInt(exactly: v)?.abiEncode(bits: 32)! as AnyObject)! + return ABIEncoder.convertToData(BigInt(exactly: v)?.abiEncode(bits: 32)!)! } else if let v = value as? Int64 { - return ABIEncoder.convertToData(BigInt(exactly: v)?.abiEncode(bits: 64)! as AnyObject)! + return ABIEncoder.convertToData(BigInt(exactly: v)?.abiEncode(bits: 64)!)! } else if let v = value as? UInt { - return ABIEncoder.convertToData(BigUInt(exactly: v)?.abiEncode(bits: 256)! as AnyObject)! + return ABIEncoder.convertToData(BigUInt(exactly: v)?.abiEncode(bits: 256)!)! } else if let v = value as? UInt8 { - return ABIEncoder.convertToData(BigUInt(exactly: v)?.abiEncode(bits: 8)! as AnyObject)! + return ABIEncoder.convertToData(BigUInt(exactly: v)?.abiEncode(bits: 8)!)! } else if let v = value as? UInt16 { - return ABIEncoder.convertToData(BigUInt(exactly: v)?.abiEncode(bits: 16)! as AnyObject)! + return ABIEncoder.convertToData(BigUInt(exactly: v)?.abiEncode(bits: 16)!)! } else if let v = value as? UInt32 { - return ABIEncoder.convertToData(BigUInt(exactly: v)?.abiEncode(bits: 32)! as AnyObject)! + return ABIEncoder.convertToData(BigUInt(exactly: v)?.abiEncode(bits: 32)!)! } else if let v = value as? UInt64 { - return ABIEncoder.convertToData(BigUInt(exactly: v)?.abiEncode(bits: 64)! as AnyObject)! - } else if let data = ABIEncoder.convertToData(value as AnyObject) { + return ABIEncoder.convertToData(BigUInt(exactly: v)?.abiEncode(bits: 64)!)! + } else if let data = ABIEncoder.convertToData(value) { return data } throw Web3Error.inputError(desc: "SoliditySha3: `abiEncode` accepts an Int/UInt (any of 8, 16, 32, 64 bits long), decimal or hexadecimal string, Bool, Data, [UInt8], EthereumAddress, [IntegerLiteralType], BigInt or BigUInt instance. Given value is of type \(type(of: value)).") diff --git a/Sources/Web3Core/RLP/RLP.swift b/Sources/Web3Core/RLP/RLP.swift index 588432db7..8200401c2 100755 --- a/Sources/Web3Core/RLP/RLP.swift +++ b/Sources/Web3Core/RLP/RLP.swift @@ -18,7 +18,7 @@ public struct RLP { static var length56 = BigUInt(UInt(56)) static var lengthMax = (BigUInt(UInt(1)) << 256) - internal static func encode(_ element: AnyObject) -> Data? { + internal static func encode(_ element: Any) -> Data? { if let string = element as? String { return encode(string) @@ -112,14 +112,14 @@ public struct RLP { return encoded.bytes[0] } - // FIXME: Make encode generic to avoid casting it's argument to [AnyObject] - internal static func encode(_ elements: [AnyObject]) -> Data? { + // FIXME: Make encode generic to avoid casting it's argument to [Any] + internal static func encode(_ elements: [Any]) -> Data? { var encodedData = Data() for e in elements { if let encoded = encode(e) { encodedData.append(encoded) } else { - guard let asArray = e as? [AnyObject] else {return nil} + guard let asArray = e as? [Any] else {return nil} guard let encoded = encode(asArray) else {return nil} encodedData.append(encoded) } diff --git a/Sources/Web3Core/Transaction/Envelope/EIP1559Envelope.swift b/Sources/Web3Core/Transaction/Envelope/EIP1559Envelope.swift index 673af57ce..18eb2cf26 100644 --- a/Sources/Web3Core/Transaction/Envelope/EIP1559Envelope.swift +++ b/Sources/Web3Core/Transaction/Envelope/EIP1559Envelope.swift @@ -245,14 +245,14 @@ extension EIP1559Envelope { // } public func encode(for type: EncodeType = .transaction) -> Data? { - let fields: [AnyObject] - let list = accessList.map { $0.encodeAsList() as AnyObject } + let fields: [Any] + let list = accessList.map { $0.encodeAsList() } switch type { case .transaction: - fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list, v, r, s] as [AnyObject] + fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list, v, r, s] case .signature: - fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list] as [AnyObject] + fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list] } guard var result = RLP.encode(fields) else { return nil } result.insert(UInt8(self.type.rawValue), at: 0) diff --git a/Sources/Web3Core/Transaction/Envelope/EIP2930Envelope.swift b/Sources/Web3Core/Transaction/Envelope/EIP2930Envelope.swift index fe4bcfb46..d0f3a2c58 100644 --- a/Sources/Web3Core/Transaction/Envelope/EIP2930Envelope.swift +++ b/Sources/Web3Core/Transaction/Envelope/EIP2930Envelope.swift @@ -206,14 +206,14 @@ extension EIP2930Envelope { } public func encode(for type: EncodeType = .transaction) -> Data? { - let fields: [AnyObject] - let list = accessList.map { $0.encodeAsList() as AnyObject } + let fields: [Any] + let list = accessList.map { $0.encodeAsList() } switch type { case .transaction: - fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list, v, r, s] as [AnyObject] + fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list, v, r, s] case .signature: - fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list] as [AnyObject] + fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list] } guard var result = RLP.encode(fields) else { return nil } result.insert(UInt8(self.type.rawValue), at: 0) @@ -310,7 +310,7 @@ public struct AccessListEntry: CustomStringConvertible, Codable { } } - public func encodeAsList() -> [AnyObject]? { + public func encodeAsList() -> [Any]? { var storage: [Data] = [] for key in storageKeys { @@ -318,7 +318,7 @@ public struct AccessListEntry: CustomStringConvertible, Codable { storage.append(keyData) } - return [address.address as AnyObject, storage as AnyObject] + return [address.address, storage] } // FIXME: THIS NOT WORKING!!! diff --git a/Sources/Web3Core/Transaction/Envelope/LegacyEnvelope.swift b/Sources/Web3Core/Transaction/Envelope/LegacyEnvelope.swift index b1c2c7e4c..f38a69ecc 100644 --- a/Sources/Web3Core/Transaction/Envelope/LegacyEnvelope.swift +++ b/Sources/Web3Core/Transaction/Envelope/LegacyEnvelope.swift @@ -192,15 +192,15 @@ extension LegacyEnvelope { // } public func encode(for type: EncodeType = .transaction) -> Data? { - let fields: [AnyObject] + let fields: [Any] switch type { case .transaction: - fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, v, r, s] as [AnyObject] + fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, v, r, s] case .signature: if let chainID = chainID, chainID != 0 { - fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, chainID, BigUInt(0), BigUInt(0)] as [AnyObject] + fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, chainID, BigUInt(0), BigUInt(0)] } else { - fields = [nonce, gasPrice, gasLimit, to.addressData, value, data] as [AnyObject] + fields = [nonce, gasPrice, gasLimit, to.addressData, value, data] } } return RLP.encode(fields) diff --git a/Sources/web3swift/Browser/browser.js b/Sources/web3swift/Browser/browser.js index 6f7d8ea26..88b5c8e4a 100644 --- a/Sources/web3swift/Browser/browser.js +++ b/Sources/web3swift/Browser/browser.js @@ -5379,7 +5379,7 @@ * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`. * The iteratee must complete with a boolean value as its result. * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon as any + * @param {Function} [callback] - A callback which is called as soon * iteratee returns `true`, or after all the `iteratee` functions have finished. * Result will be the first item in the array that passes the truth test * (iteratee) or the value `undefined` if none passed. Invoked with @@ -5412,7 +5412,7 @@ * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`. * The iteratee must complete with a boolean value as its result. * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon as any + * @param {Function} [callback] - A callback which is called as soon * iteratee returns `true`, or after all the `iteratee` functions have finished. * Result will be the first item in the array that passes the truth test * (iteratee) or the value `undefined` if none passed. Invoked with @@ -5434,7 +5434,7 @@ * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`. * The iteratee must complete with a boolean value as its result. * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon as any + * @param {Function} [callback] - A callback which is called as soon * iteratee returns `true`, or after all the `iteratee` functions have finished. * Result will be the first item in the array that passes the truth test * (iteratee) or the value `undefined` if none passed. Invoked with @@ -7297,7 +7297,7 @@ * in the collections in parallel. * The iteratee should complete with a boolean `result` value. * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon as any + * @param {Function} [callback] - A callback which is called as soon * iteratee returns `true`, or after all the iteratee functions have finished. * Result will be either `true` or `false` depending on the values of the async * tests. Invoked with (err, result). @@ -7329,7 +7329,7 @@ * in the collections in parallel. * The iteratee should complete with a boolean `result` value. * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon as any + * @param {Function} [callback] - A callback which is called as soon * iteratee returns `true`, or after all the iteratee functions have finished. * Result will be either `true` or `false` depending on the values of the async * tests. Invoked with (err, result). @@ -7351,7 +7351,7 @@ * in the collections in series. * The iteratee should complete with a boolean `result` value. * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon as any + * @param {Function} [callback] - A callback which is called as soon * iteratee returns `true`, or after all the iteratee functions have finished. * Result will be either `true` or `false` depending on the values of the async * tests. Invoked with (err, result). @@ -68348,4 +68348,4 @@ //# sourceURL=/Users/alexvlasov/Blockchain/web3swift/web3swiftJSProxy/wk.bridge.js },{}]},{},[1]); - \ No newline at end of file + diff --git a/Sources/web3swift/Operations/ReadOperation.swift b/Sources/web3swift/Operations/ReadOperation.swift index 937ab2b14..04eb275bb 100755 --- a/Sources/web3swift/Operations/ReadOperation.swift +++ b/Sources/web3swift/Operations/ReadOperation.swift @@ -42,7 +42,7 @@ public class ReadOperation { let data: Data = try await self.web3.eth.callTransaction(transaction) if self.method == "fallback" { let resultHex = data.toHexString().addHexPrefix() - return ["result": resultHex as Any] + return ["result": resultHex] } guard let decodedData = self.contract.decodeReturnData(self.method, data: data) else { throw Web3Error.processingError(desc: "Can not decode returned parameters") diff --git a/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift b/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift index 2ddb502a3..c03245a53 100644 --- a/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift +++ b/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift @@ -71,7 +71,7 @@ public class ERC1155: IERC1155 { guard contract.contract.address != nil else {return} self.transaction.callOnBlock = .latest - guard let tokenIdPromise = try await contract.createReadOperation("id", parameters: [] as [AnyObject], extraData: Data())?.callContractMethod() else {return} + guard let tokenIdPromise = try await contract.createReadOperation("id", parameters: [], extraData: Data())?.callContractMethod() else {return} guard let tokenId = tokenIdPromise["0"] as? BigUInt else {return} self._tokenId = tokenId @@ -84,7 +84,7 @@ public class ERC1155: IERC1155 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, id, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, id, value, data] )! return tx } @@ -94,7 +94,7 @@ public class ERC1155: IERC1155 { self.transaction.to = self.address let tx = contract - .createWriteOperation("safeBatchTransferFrom", parameters: [originalOwner, to, ids, values, data] as [AnyObject] )! + .createWriteOperation("safeBatchTransferFrom", parameters: [originalOwner, to, ids, values, data] )! return tx } @@ -102,12 +102,12 @@ public class ERC1155: IERC1155 { let contract = self.contract self.transaction.callOnBlock = .latest let result = try await contract - .createReadOperation("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data() )! + .createReadOperation("balanceOf", parameters: [account, id], extraData: Data() )! .callContractMethod() /* let result = try await contract - .prepareToRead("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data() )! + .prepareToRead("balanceOf", parameters: [account, id], extraData: Data() )! .execute() .decodeData() @@ -121,14 +121,14 @@ public class ERC1155: IERC1155 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved, scope] as [AnyObject] )! + let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved, scope] )! 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() + let result = try await contract.createReadOperation("isApprovedForAll", parameters: [owner, user, scope], 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 } @@ -136,7 +136,7 @@ public class ERC1155: IERC1155 { 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], 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 f3570578b..766a08c76 100644 --- a/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift +++ b/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift @@ -91,7 +91,7 @@ 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() + let result = try await contract.createReadOperation("balanceOf", parameters: [account], 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 } @@ -99,7 +99,7 @@ public class ERC1376: IERC1376, 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], 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 } @@ -121,7 +121,7 @@ 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] )! return tx } @@ -143,7 +143,7 @@ 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] )! return tx } @@ -165,7 +165,7 @@ 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] )! return tx } @@ -187,14 +187,14 @@ 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] )! 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: [Any](), 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,7 +220,7 @@ 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] )! return tx } @@ -242,7 +242,7 @@ 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] )! return tx } @@ -264,7 +264,7 @@ 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] )! return tx } @@ -273,14 +273,14 @@ public class ERC1376: IERC1376, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setERC20ApproveChecking", parameters: [approveChecking] as [AnyObject] )! + let tx = contract.createWriteOperation("setERC20ApproveChecking", parameters: [approveChecking] )! 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() + let result = try await contract.createReadOperation("spendableAllowance", parameters: [owner, spender], 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 } @@ -302,7 +302,7 @@ 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] )! return tx } @@ -323,14 +323,14 @@ 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] )! return tx } func nonceOf(owner: EthereumAddress) async throws -> BigUInt { let contract = self.contract self.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], 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 } @@ -341,7 +341,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { self.transaction.to = self.address self.transaction.callOnBlock = .latest - let tx = contract.createWriteOperation("increaseNonce", parameters: [] as [AnyObject] )! + let tx = contract.createWriteOperation("increaseNonce", parameters: [] )! return tx } @@ -365,14 +365,14 @@ 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] )! return tx } 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() + let result = try await contract.createReadOperation("directDebit", parameters: [debtor, receiver], 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 } @@ -382,7 +382,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setupDirectDebit", parameters: [receiver, info] as [AnyObject] )! + let tx = contract.createWriteOperation("setupDirectDebit", parameters: [receiver, info] )! return tx } @@ -391,7 +391,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("terminateDirectDebit", parameters: [receiver] as [AnyObject] )! + let tx = contract.createWriteOperation("terminateDirectDebit", parameters: [receiver] )! return tx } @@ -400,7 +400,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("withdrawDirectDebit", parameters: [debtor] as [AnyObject] )! + let tx = contract.createWriteOperation("withdrawDirectDebit", parameters: [debtor] )! return tx } @@ -409,7 +409,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("withdrawDirectDebit", parameters: [debtors, strict] as [AnyObject] )! + let tx = contract.createWriteOperation("withdrawDirectDebit", parameters: [debtors, strict] )! return tx } } diff --git a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift index 98d98360f..a700d0fbf 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], 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], 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] )! 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] )! 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] )! 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: [Any](), 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] )! 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], 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] )! 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], 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], 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] )! 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] )! 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] )! 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] )! 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: [Any](), 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] )! 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] )! 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] )! 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] )! 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] )! 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] )! 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], 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], 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: [Any](), 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] )! 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] )! 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] )! 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] )! 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] )! 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] )! 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], 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], 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], 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], 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], 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] )! 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] )! 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], 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] )! 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], 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: [], 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: [], 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] )! 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] )! 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], 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] )! 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] )! 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] )! 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] )! return tx } } diff --git a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift index 4551cd793..f77011da9 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], 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], 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] )! 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] )! 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] )! 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: [Any](), 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] )! 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], 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], 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] )! 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] )! 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], 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], 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], 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] )! 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] )! 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] )! 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] )! 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] )! 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] )! 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] )! 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], 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], 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] )! 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] )! 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], 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] )! 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], 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] )! 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] )! 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], 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] )! 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] )! 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] )! 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] )! 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: [], 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: [], 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..e02bd6b18 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], 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], 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] )! 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] )! 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] )! 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: [Any](), 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] )! 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] )! 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] )! 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: [Any](), 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] )! 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] )! 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] )! 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], 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], 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..40480c564 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], 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], 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] )! 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] )! 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] )! 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: [Any](), 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] )! 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: [], 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: [], 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], 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..6227c19c7 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], 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], 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] )! 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] )! 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] )! 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: [Any](), 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] )! 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], 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] )! 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] )! 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: [], 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..7e4cdf580 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], 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], 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] )! 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] )! 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] )! 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: [Any](), 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] )! 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: [Any](), 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] )! 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] )! return tx } } diff --git a/Sources/web3swift/Tokens/ERC20/ERC20BaseProperties.swift b/Sources/web3swift/Tokens/ERC20/ERC20BaseProperties.swift index e0d861fe7..6146d467e 100644 --- a/Sources/web3swift/Tokens/ERC20/ERC20BaseProperties.swift +++ b/Sources/web3swift/Tokens/ERC20/ERC20BaseProperties.swift @@ -9,7 +9,7 @@ import Foundation /// Declares common properties of an [ERC-20](https://eips.ethereum.org/EIPS/eip-20) complient smart contract. /// Default implementation of access to these properties is declared in the extension of this protocol. -public protocol ERC20BaseProperties: AnyObject { +public protocol ERC20BaseProperties: Any { var basePropertiesProvider: ERC20BasePropertiesProvider { get } var contract: Web3.Contract { get } var name: String? { get } diff --git a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift index d1aeba7ea..aa20848cb 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], 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], 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 { 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] )! return tx } @@ -104,7 +104,7 @@ public class ERC20: IERC20, 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] )! return tx } @@ -128,7 +128,7 @@ public class ERC20: IERC20, 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] )! return tx } @@ -152,7 +152,7 @@ public class ERC20: IERC20, 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] )! return tx } @@ -160,7 +160,7 @@ public class ERC20: IERC20, ERC20BaseProperties { let contract = self.contract self.transaction.callOnBlock = .latest let result = try await contract - .createReadOperation("totalSupply", parameters: [AnyObject](), extraData: Data() )! + .createReadOperation("totalSupply", parameters: [Any](), 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 9a5887eab..2892ac4f0 100644 --- a/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift +++ b/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift @@ -93,7 +93,7 @@ public class ERC721: IERC721 { guard contract.contract.address != nil else {return} self.transaction.callOnBlock = .latest - async let tokenIdPromise = contract.createReadOperation("tokenId", parameters: [AnyObject](), extraData: Data())?.callContractMethod() + async let tokenIdPromise = contract.createReadOperation("tokenId", parameters: [Any](), extraData: Data())?.callContractMethod() guard let tokenIdResult = try await tokenIdPromise else {return} guard let tokenId = tokenIdResult["0"] as? BigUInt else {return} @@ -106,7 +106,7 @@ public class ERC721: IERC721 { 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], 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 +114,7 @@ public class ERC721: IERC721 { public func getOwner(tokenId: BigUInt) async throws -> EthereumAddress { let contract = self.contract self.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], 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 } @@ -122,7 +122,7 @@ public class ERC721: IERC721 { public func getApproved(tokenId: BigUInt) async throws -> EthereumAddress { let contract = self.contract self.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], 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 } @@ -132,7 +132,7 @@ public class ERC721: IERC721 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId] )! return tx } @@ -141,7 +141,7 @@ public class ERC721: IERC721 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId] )! return tx } @@ -150,7 +150,7 @@ public class ERC721: IERC721 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId] )! return tx } @@ -159,7 +159,7 @@ public class ERC721: IERC721 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, data] as [AnyObject] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, data] )! return tx } @@ -168,7 +168,7 @@ public class ERC721: IERC721 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("approve", parameters: [approved, tokenId] as [AnyObject] )! + let tx = contract.createWriteOperation("approve", parameters: [approved, tokenId] )! return tx } @@ -177,14 +177,14 @@ public class ERC721: IERC721 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved] as [AnyObject] )! + let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved] )! return tx } public func isApprovedForAll(owner: EthereumAddress, operator user: EthereumAddress) async throws -> Bool { let contract = self.contract self.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], 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,7 +192,7 @@ public class ERC721: IERC721 { 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() + let result = try await contract.createReadOperation("supportsInterface", parameters: [interfaceID], 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 } @@ -204,7 +204,7 @@ extension ERC721: IERC721Enumerable { 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: [Any](), 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 } @@ -212,7 +212,7 @@ extension ERC721: IERC721Enumerable { public func tokenByIndex(index: BigUInt) async throws -> BigUInt { let contract = self.contract self.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], 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,7 +220,7 @@ extension ERC721: IERC721Enumerable { public func tokenOfOwnerByIndex(owner: EthereumAddress, index: BigUInt) async throws -> BigUInt { let contract = self.contract self.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], 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 } @@ -233,7 +233,7 @@ extension ERC721: IERC721Metadata { public func name() async throws -> String { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("name", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("name", parameters: [Any](), 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 } @@ -241,7 +241,7 @@ extension ERC721: IERC721Metadata { public func symbol() async throws -> String { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("symbol", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("symbol", parameters: [Any](), 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 } @@ -249,7 +249,7 @@ extension ERC721: IERC721Metadata { public func tokenURI(tokenId: BigUInt) async throws -> String { let contract = self.contract self.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], 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 7285b48c9..941e68824 100644 --- a/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift +++ b/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift @@ -77,7 +77,7 @@ public class ERC721x: IERC721x { guard contract.contract.address != nil else {return} self.transaction.callOnBlock = .latest - guard let tokenIdPromise = try await contract.createReadOperation("tokenId", parameters: [] as [AnyObject], extraData: Data())?.callContractMethod() else {return} + guard let tokenIdPromise = try await contract.createReadOperation("tokenId", parameters: [], extraData: Data())?.callContractMethod() else {return} guard let tokenId = tokenIdPromise["0"] as? BigUInt else {return} self._tokenId = tokenId @@ -88,7 +88,7 @@ public class ERC721x: IERC721x { 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], 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 ERC721x: IERC721x { public func getOwner(tokenId: BigUInt) async throws -> EthereumAddress { let contract = self.contract self.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], 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 } @@ -104,7 +104,7 @@ public class ERC721x: IERC721x { public func getApproved(tokenId: BigUInt) async throws -> EthereumAddress { let contract = self.contract self.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], 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 } @@ -114,7 +114,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId] )! return tx } @@ -123,7 +123,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId] )! return tx } @@ -132,7 +132,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId] as [AnyObject] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId] )! return tx } @@ -141,7 +141,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, data] as [AnyObject] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, data] )! return tx } @@ -150,7 +150,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("approve", parameters: [approved, tokenId] as [AnyObject] )! + let tx = contract.createWriteOperation("approve", parameters: [approved, tokenId] )! return tx } @@ -159,14 +159,14 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved] as [AnyObject] )! + let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved] )! return tx } public func isApprovedForAll(owner: EthereumAddress, operator user: EthereumAddress) async throws -> Bool { let contract = self.contract self.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], 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 } @@ -174,7 +174,7 @@ public class ERC721x: IERC721x { 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], 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 } @@ -182,7 +182,7 @@ public class ERC721x: IERC721x { 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: [Any](), 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 } @@ -190,7 +190,7 @@ public class ERC721x: IERC721x { public func tokenByIndex(index: BigUInt) async throws -> BigUInt { let contract = self.contract self.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], 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 } @@ -198,7 +198,7 @@ public class ERC721x: IERC721x { public func tokenOfOwnerByIndex(owner: EthereumAddress, index: BigUInt) async throws -> BigUInt { let contract = self.contract self.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], 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 } @@ -206,7 +206,7 @@ public class ERC721x: IERC721x { public func name() async throws -> String { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("name", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("name", parameters: [Any](), 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 } @@ -214,7 +214,7 @@ public class ERC721x: IERC721x { public func symbol() async throws -> String { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("symbol", parameters: [AnyObject](), extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("symbol", parameters: [Any](), 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 } @@ -222,7 +222,7 @@ public class ERC721x: IERC721x { public func tokenURI(tokenId: BigUInt) async throws -> String { let contract = self.contract self.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], 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 } @@ -230,7 +230,7 @@ public class ERC721x: IERC721x { func implementsERC721X() async throws -> Bool { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("implementsERC721X", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("implementsERC721X", parameters: [], 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 } @@ -238,7 +238,7 @@ public class ERC721x: IERC721x { func getBalance(account: EthereumAddress, tokenId: BigUInt) async throws -> BigUInt { let contract = self.contract self.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], 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 } @@ -246,7 +246,7 @@ public class ERC721x: IERC721x { func tokensOwned(account: EthereumAddress) async throws -> ([BigUInt], [BigUInt]) { let contract = self.contract self.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], 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 } @@ -256,7 +256,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId, quantity] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId, quantity] )! return tx } @@ -265,7 +265,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId, quantity] as [AnyObject] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId, quantity] )! return tx } @@ -274,7 +274,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount] as [AnyObject] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount] )! return tx } @@ -283,7 +283,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount, data] as [AnyObject] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount, data] )! return tx } @@ -292,7 +292,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenIds, amounts, data] as [AnyObject] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenIds, amounts, data] )! return tx } } diff --git a/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift index 4ef3be52f..5e297f367 100644 --- a/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift +++ b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift @@ -59,7 +59,7 @@ public class ERC777: IERC777, ERC20BaseProperties { 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: [], 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 } @@ -67,7 +67,7 @@ public class ERC777: IERC777, ERC20BaseProperties { 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: [], 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 } @@ -75,7 +75,7 @@ public class ERC777: IERC777, 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], 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 } @@ -83,7 +83,7 @@ public class ERC777: IERC777, 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], 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 } @@ -105,7 +105,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("transfer", parameters: [to, value] as [AnyObject] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value] )! return tx } @@ -127,7 +127,7 @@ 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] )! return tx } @@ -149,14 +149,14 @@ 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] )! 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: [Any](), 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 } @@ -168,7 +168,7 @@ public class ERC777: IERC777, ERC20BaseProperties { 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] )! return tx } @@ -178,14 +178,14 @@ public class ERC777: IERC777, ERC20BaseProperties { 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] )! 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], 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 } @@ -207,7 +207,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("send", parameters: [to, value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("send", parameters: [to, value, data] )! return tx } @@ -228,7 +228,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] )! return tx } @@ -249,7 +249,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("burn", parameters: [value, data] as [AnyObject] )! + let tx = contract.createWriteOperation("burn", parameters: [value, data] )! return tx } @@ -270,14 +270,14 @@ 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] )! return tx } 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], 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 } @@ -285,7 +285,7 @@ public class ERC777: IERC777, ERC20BaseProperties { 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], 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 } @@ -295,7 +295,7 @@ public class ERC777: IERC777, ERC20BaseProperties { 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] )! return tx } @@ -304,14 +304,14 @@ public class ERC777: IERC777, ERC20BaseProperties { 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] )! 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], 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 } @@ -321,7 +321,7 @@ public class ERC777: IERC777, ERC20BaseProperties { 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] )! return tx } @@ -343,14 +343,14 @@ 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] )! 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], 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 46a0dc8f0..4ff2e9c5f 100644 --- a/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift +++ b/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift @@ -41,7 +41,7 @@ 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() + let result = try await contract.createReadOperation("balanceOf", parameters: [account], 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 ERC888: IERC888, 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] )! return tx } diff --git a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift index 71097eb27..66cfc8dd6 100644 --- a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift +++ b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift @@ -52,7 +52,7 @@ public class ST20: IST20, ERC20BaseProperties { func tokenDetails() async throws -> [UInt32] { let contract = self.contract self.transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("tokenDetails", parameters: [] as [AnyObject], extraData: Data() )!.callContractMethod() + let result = try await contract.createReadOperation("tokenDetails", parameters: [], 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 } @@ -76,7 +76,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] )! return tx } @@ -99,7 +99,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] )! return tx } @@ -121,14 +121,14 @@ 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] )! return tx } 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], 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 } @@ -136,7 +136,7 @@ public class ST20: IST20, 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], 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 } @@ -159,7 +159,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] )! return tx } @@ -182,7 +182,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] )! return tx } @@ -205,7 +205,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] )! return tx } @@ -228,14 +228,14 @@ 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] )! 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: [Any](), 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+SecurityToken.swift b/Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift index a7670f124..772dc0da8 100644 --- a/Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift +++ b/Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift @@ -112,7 +112,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - return contract.createWriteOperation("verifyTransfer", parameters: [originalOwner, to, value] as [AnyObject])! + return contract.createWriteOperation("verifyTransfer", parameters: [originalOwner, to, value])! } func mint(from: EthereumAddress, investor: EthereumAddress, amount: String) async throws -> WriteOperation { @@ -131,7 +131,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - return contract.createWriteOperation("mint", parameters: [investor, value] as [AnyObject])! + return contract.createWriteOperation("mint", parameters: [investor, value])! } public func burn(from: EthereumAddress, amount: String) async throws -> WriteOperation { @@ -150,19 +150,19 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - return contract.createWriteOperation("burn", parameters: [value] as [AnyObject])! + return contract.createWriteOperation("burn", parameters: [value])! } public func getBalance(account: EthereumAddress) async throws -> BigUInt { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject])!.callContractMethod() + let result = try await contract.createReadOperation("balanceOf", parameters: [account])!.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])!.callContractMethod() + let result = try await contract.createReadOperation("allowance", parameters: [originalOwner, delegate])!.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 +183,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - return contract.createWriteOperation("transfer", parameters: [to, value] as [AnyObject])! + return contract.createWriteOperation("transfer", parameters: [to, value])! } public func transferFrom(from: EthereumAddress, to: EthereumAddress, originalOwner: EthereumAddress, amount: String) async throws -> WriteOperation { @@ -202,7 +202,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - return contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] as [AnyObject])! + return contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value])! } public func setAllowance(from: EthereumAddress, to: EthereumAddress, newAmount: String) async throws -> WriteOperation { @@ -221,7 +221,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(newAmount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - return contract.createWriteOperation("setAllowance", parameters: [to, value] as [AnyObject])! + return contract.createWriteOperation("setAllowance", parameters: [to, value])! } public func approve(from: EthereumAddress, spender: EthereumAddress, amount: String) async throws -> WriteOperation { @@ -240,7 +240,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { guard let value = Utilities.parseToBigUInt(amount, decimals: intDecimals) else { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - return contract.createWriteOperation("approve", parameters: [spender, value] as [AnyObject])! + return contract.createWriteOperation("approve", parameters: [spender, value])! } public func totalSupply() async throws -> BigUInt { @@ -254,14 +254,14 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { transaction.from = from transaction.to = self.address transaction.callOnBlock = .latest - return contract.createWriteOperation("renounceOwnership", parameters: [AnyObject]() )! + return contract.createWriteOperation("renounceOwnership", parameters: [Any]() )! } public func transferOwnership(from: EthereumAddress, newOwner: EthereumAddress) throws -> WriteOperation { transaction.from = from transaction.to = self.address transaction.callOnBlock = .latest - return contract.createWriteOperation("transferOwnership", parameters: [newOwner] as [AnyObject])! + return contract.createWriteOperation("transferOwnership", parameters: [newOwner])! } public func currentCheckpointId() async throws -> BigUInt { @@ -287,21 +287,21 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { public func investors(index: UInt) async throws -> [EthereumAddress] { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("investors", parameters: [index] as [AnyObject])!.callContractMethod() + let result = try await contract.createReadOperation("investors", parameters: [index])!.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 checkPermission(delegate: EthereumAddress, module: EthereumAddress, perm: [UInt32]) async throws -> Bool { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("checkPermission", parameters: [delegate, module, perm] as [AnyObject])!.callContractMethod() + let result = try await contract.createReadOperation("checkPermission", parameters: [delegate, module, perm])!.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 getModule(moduleType: UInt8, moduleIndex: UInt8) async throws -> ([UInt32], EthereumAddress) { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("getModule", parameters: [moduleType, moduleIndex] as [AnyObject])!.callContractMethod() + let result = try await contract.createReadOperation("getModule", parameters: [moduleType, moduleIndex])!.callContractMethod() guard let moduleList = result["0"] as? [UInt32] else { throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node") } guard let moduleAddress = result["1"] as? EthereumAddress else { throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node") } return (moduleList, moduleAddress) @@ -309,7 +309,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { public func getModuleByName(moduleType: UInt8, name: [UInt32]) async throws -> ([UInt32], EthereumAddress) { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("getModuleByName", parameters: [moduleType, name] as [AnyObject])!.callContractMethod() + let result = try await contract.createReadOperation("getModuleByName", parameters: [moduleType, name])!.callContractMethod() guard let moduleList = result["0"] as? [UInt32] else { throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node") } guard let moduleAddress = result["1"] as? EthereumAddress else { throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node") } return (moduleList, moduleAddress) @@ -317,14 +317,14 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { public func totalSupplyAt(checkpointId: BigUInt) async throws -> BigUInt { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("totalSupplyAt", parameters: [checkpointId] as [AnyObject])!.callContractMethod() + let result = try await contract.createReadOperation("totalSupplyAt", parameters: [checkpointId])!.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 balanceOfAt(investor: EthereumAddress, checkpointId: BigUInt) async throws -> BigUInt { transaction.callOnBlock = .latest - let result = try await contract.createReadOperation("balanceOfAt", parameters: [investor, checkpointId] as [AnyObject])!.callContractMethod() + let result = try await contract.createReadOperation("balanceOfAt", parameters: [investor, checkpointId])!.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 } @@ -333,7 +333,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { transaction.from = from transaction.to = self.address transaction.callOnBlock = .latest - return contract.createWriteOperation("createCheckpoint", parameters: [AnyObject]() )! + return contract.createWriteOperation("createCheckpoint", parameters: [Any]() )! } public func getInvestorsLength() async throws -> BigUInt { diff --git a/Sources/web3swift/Utils/EIP/EIP67Code.swift b/Sources/web3swift/Utils/EIP/EIP67Code.swift index 49f4e887c..38e95b112 100755 --- a/Sources/web3swift/Utils/EIP/EIP67Code.swift +++ b/Sources/web3swift/Utils/EIP/EIP67Code.swift @@ -22,7 +22,7 @@ extension Web3 { } public struct Function { public var method: String - public var parameters: [(ABI.Element.ParameterType, AnyObject)] + public var parameters: [(ABI.Element.ParameterType, Any)] public func toString() -> String? { let encoding = method + "(" + parameters.map({ el -> String in diff --git a/Sources/web3swift/Utils/EIP/EIP681.swift b/Sources/web3swift/Utils/EIP/EIP681.swift index 62a05a509..c15ffd41f 100755 --- a/Sources/web3swift/Utils/EIP/EIP681.swift +++ b/Sources/web3swift/Utils/EIP/EIP681.swift @@ -23,9 +23,9 @@ extension Web3 { public struct EIP681Code { public struct EIP681Parameter { public var type: ABI.Element.ParameterType - public var value: AnyObject + public var value: Any - public init(type: ABI.Element.ParameterType, value: AnyObject) { + public init(type: ABI.Element.ParameterType, value: Any) { self.type = type self.value = value } @@ -90,7 +90,7 @@ extension Web3 { public struct EIP681CodeEncoder { public static func encodeFunctionArgument(_ inputType: ABI.Element.ParameterType, - _ rawValue: AnyObject) -> String? { + _ rawValue: Any) -> String? { switch inputType { case .address: if let ethAddress = rawValue as? EthereumAddress { @@ -209,7 +209,7 @@ extension Web3 { } return nil case let .array(type, length): - if let array = rawValue as? [AnyObject] { + if let array = rawValue as? [Any] { let mappedArray = array.compactMap { object in encodeFunctionArgument(type, object) } @@ -350,58 +350,58 @@ extension Web3 { _ rawValue: String, chainID: BigUInt, inputNumber: Int) async -> FunctionArgument? { - var nativeValue: AnyObject? + var nativeValue: Any? switch inputType { case .address: let val = EIP681Code.TargetAddress(rawValue) switch val { case .ethereumAddress(let ethereumAddress): - nativeValue = ethereumAddress as AnyObject + nativeValue = ethereumAddress case .ensAddress(let ens): do { let web = await Web3(provider: InfuraProvider(Networks.fromInt(UInt(chainID)) ?? Networks.Mainnet)!) let ensModel = ENS(web3: web) try await ensModel?.setENSResolver(withDomain: ens) let address = try await ensModel?.getAddress(forNode: ens) - nativeValue = address as AnyObject + nativeValue = address } catch { return nil } } case .uint(bits: _): if let val = BigUInt(rawValue, radix: 10) { - nativeValue = val as AnyObject + nativeValue = val } else if let val = BigUInt(rawValue.stripHexPrefix(), radix: 16) { - nativeValue = val as AnyObject + nativeValue = val } case .int(bits: _): if let val = BigInt(rawValue, radix: 10) { - nativeValue = val as AnyObject + nativeValue = val } else if let val = BigInt(rawValue.stripHexPrefix(), radix: 16) { - nativeValue = val as AnyObject + nativeValue = val } case .string: - nativeValue = rawValue as AnyObject + nativeValue = rawValue case .dynamicBytes: if let val = Data.fromHex(rawValue) { - nativeValue = val as AnyObject + nativeValue = val } else if let val = rawValue.data(using: .utf8) { - nativeValue = val as AnyObject + nativeValue = val } case .bytes(length: _): if let val = Data.fromHex(rawValue) { - nativeValue = val as AnyObject + nativeValue = val } else if let val = rawValue.data(using: .utf8) { - nativeValue = val as AnyObject + nativeValue = val } case .bool: switch rawValue { case "true", "True", "TRUE", "1": - nativeValue = true as AnyObject + nativeValue = true case "false", "False", "FALSE", "0": - nativeValue = false as AnyObject + nativeValue = false default: - nativeValue = true as AnyObject + nativeValue = true } case let .array(type, length): var rawValues: [String] = [] @@ -420,7 +420,7 @@ extension Web3 { rawValues = rawValue.split(separator: ",").map { String($0) } } - var nativeValueArray: [AnyObject] = [] + var nativeValueArray: [Any] = [] for value in rawValues { let intermidiateValue = await parseFunctionArgument(type, @@ -433,7 +433,7 @@ extension Web3 { nativeValueArray.append(intermidiateValue) } } - nativeValue = nativeValueArray as AnyObject + nativeValue = nativeValueArray guard nativeValueArray.count == rawValues.count && (length == 0 || UInt64(rawValues.count) == length) else { return nil } diff --git a/Sources/web3swift/Utils/EIP/EIP712.swift b/Sources/web3swift/Utils/EIP/EIP712.swift index 4cb913ffd..a10b20864 100644 --- a/Sources/web3swift/Utils/EIP/EIP712.swift +++ b/Sources/web3swift/Utils/EIP/EIP712.swift @@ -38,7 +38,6 @@ public extension EIP712Hashable { } func hash() throws -> Data { - typealias SolidityValue = (value: Any, type: ABI.Element.ParameterType) var parameters: [Data] = [typehash] for case let (_, field) in Mirror(reflecting: self).children { let result: Data @@ -48,14 +47,15 @@ public extension EIP712Hashable { case let data as EIP712.Bytes: result = data.sha3(.keccak256) case is EIP712.UInt8: - result = ABIEncoder.encodeSingleType(type: .uint(bits: 8), value: field as AnyObject)! + result = ABIEncoder.encodeSingleType(type: .uint(bits: 8), value: field)! case is EIP712.UInt256: - result = ABIEncoder.encodeSingleType(type: .uint(bits: 256), value: field as AnyObject)! + result = ABIEncoder.encodeSingleType(type: .uint(bits: 256), value: field)! case is EIP712.Address: - result = ABIEncoder.encodeSingleType(type: .address, value: field as AnyObject)! + result = ABIEncoder.encodeSingleType(type: .address, value: field)! case let hashable as EIP712Hashable: result = try hashable.hash() default: + /// Cast to `AnyObject` is required. Otherwise, `nil` value will fail this condition. if (field as AnyObject) is NSNull { continue } else { diff --git a/Sources/web3swift/Utils/ENS/ENSBaseRegistrar.swift b/Sources/web3swift/Utils/ENS/ENSBaseRegistrar.swift index 744ffa61b..b5bee7973 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], 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], 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], 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], 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], 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], 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..725de6ef9 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], 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], 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], 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], 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], 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], 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], 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/ENSResolver.swift b/Sources/web3swift/Utils/ENS/ENSResolver.swift index 5147ab4e4..620d4acbc 100755 --- a/Sources/web3swift/Utils/ENS/ENSResolver.swift +++ b/Sources/web3swift/Utils/ENS/ENSResolver.swift @@ -76,7 +76,7 @@ public extension ENS { } public func supportsInterface(interfaceID: String) async throws -> Bool { - guard let transaction = self.resolverContract.createReadOperation("supportsInterface", parameters: [interfaceID as AnyObject]) else { + guard let transaction = self.resolverContract.createReadOperation("supportsInterface", parameters: [interfaceID]) else { throw Web3Error.transactionSerializationError } guard let result = try? await transaction.callContractMethod() else { @@ -90,7 +90,7 @@ public extension ENS { public func interfaceImplementer(forNode node: String, interfaceID: String) async throws -> EthereumAddress { guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.resolverContract.createReadOperation("interfaceImplementer", parameters: [nameHash, interfaceID] as [AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.resolverContract.createReadOperation("interfaceImplementer", parameters: [nameHash, interfaceID]) 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 address")} return address @@ -98,7 +98,7 @@ public extension ENS { public func getAddress(forNode 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.resolverContract.createReadOperation("addr", parameters: [nameHash as AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.resolverContract.createReadOperation("addr", parameters: [nameHash]) 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 address")} return address @@ -110,14 +110,14 @@ public extension ENS { var options = options ?? defaultOptions options.to = self.resolverContractAddress guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.resolverContract.createWriteOperation("setAddr", parameters: [nameHash, address] as [AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.resolverContract.createWriteOperation("setAddr", parameters: [nameHash, address]) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")} return result } public func getCanonicalName(forNode node: String) async throws -> String { guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.resolverContract.createReadOperation("name", parameters: [nameHash as AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.resolverContract.createReadOperation("name", parameters: [nameHash]) 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? String else {throw Web3Error.processingError(desc: "Can't get name")} return name @@ -129,14 +129,14 @@ public extension ENS { var options = options ?? defaultOptions options.to = self.resolverContractAddress guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.resolverContract.createWriteOperation("setName", parameters: [nameHash, name] as [AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.resolverContract.createWriteOperation("setName", parameters: [nameHash, name]) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")} return result } func getContentHash(forNode node: String) async throws -> Data { guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.resolverContract.createReadOperation("contenthash", parameters: [nameHash] as [AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.resolverContract.createReadOperation("contenthash", parameters: [nameHash]) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.callContractMethod() else {throw Web3Error.processingError(desc: "Can't call transaction")} guard let content = result["0"] as? Data else {throw Web3Error.processingError(desc: "Can't get content")} return content @@ -148,7 +148,7 @@ public extension ENS { var options = options ?? defaultOptions options.to = self.resolverContractAddress guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.resolverContract.createWriteOperation("setContenthash", parameters: [nameHash, hash] as [AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.resolverContract.createWriteOperation("setContenthash", parameters: [nameHash, hash]) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")} return result @@ -156,7 +156,7 @@ public extension ENS { public func getContractABI(forNode node: String, contentType: ENS.Resolver.ContentType) async throws -> (BigUInt, Data) { guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.resolverContract.createReadOperation("ABI", parameters: [nameHash, contentType.rawValue] as [AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.resolverContract.createReadOperation("ABI", parameters: [nameHash, contentType.rawValue]) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.callContractMethod() else {throw Web3Error.processingError(desc: "Can't call transaction")} guard let encoding = result["0"] as? BigUInt else {throw Web3Error.processingError(desc: "Can't get encoding")} guard let data = result["1"] as? Data else {throw Web3Error.processingError(desc: "Can't get data")} @@ -169,14 +169,14 @@ public extension ENS { var options = options ?? defaultOptions options.to = self.resolverContractAddress guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.resolverContract.createWriteOperation("setABI", parameters: [nameHash, contentType.rawValue, data] as [AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.resolverContract.createWriteOperation("setABI", parameters: [nameHash, contentType.rawValue, 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 } public func getPublicKey(forNode node: String) async throws -> PublicKey { guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.resolverContract.createReadOperation("pubkey", parameters: [nameHash as AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.resolverContract.createReadOperation("pubkey", parameters: [nameHash]) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.callContractMethod() else {throw Web3Error.processingError(desc: "Can't call transaction")} guard let x = result["x"] as? Data else {throw Web3Error.processingError(desc: "Can't get x")} guard let y = result["y"] as? Data else {throw Web3Error.processingError(desc: "Can't get y")} @@ -191,14 +191,14 @@ public extension ENS { options.to = self.resolverContractAddress let pubkeyWithoutPrefix = publicKey.getComponentsWithoutPrefix() guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.resolverContract.createWriteOperation("setPubkey", parameters: [nameHash, pubkeyWithoutPrefix.x, pubkeyWithoutPrefix.y] as [AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.resolverContract.createWriteOperation("setPubkey", parameters: [nameHash, pubkeyWithoutPrefix.x, pubkeyWithoutPrefix.y]) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")} return result } public func getTextData(forNode node: String, key: String) async throws -> String { guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.resolverContract.createReadOperation("text", parameters: [nameHash, key] as [AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.resolverContract.createReadOperation("text", parameters: [nameHash, key]) else {throw Web3Error.transactionSerializationError} guard let result = try? await transaction.callContractMethod() else {throw Web3Error.processingError(desc: "Can't call transaction")} guard let text = result["0"] as? String else {throw Web3Error.processingError(desc: "Can't get text")} return text @@ -210,7 +210,7 @@ public extension ENS { var options = options ?? defaultOptions options.to = self.resolverContractAddress guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")} - guard let transaction = self.resolverContract.createWriteOperation("setText", parameters: [nameHash, key, value] as [AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.resolverContract.createWriteOperation("setText", parameters: [nameHash, key, value]) 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..8d9a39194 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], 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], 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], 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], 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: [], 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..c64dd03da 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], 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], 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], 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], 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], 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], 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], 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: [Any](), extraData: Data() ) else {throw Web3Error.transactionSerializationError} return transaction } } diff --git a/Sources/web3swift/Web3/Web3+Contract.swift b/Sources/web3swift/Web3/Web3+Contract.swift index ebb9bc41a..da59285ed 100755 --- a/Sources/web3swift/Web3/Web3+Contract.swift +++ b/Sources/web3swift/Web3/Web3+Contract.swift @@ -53,7 +53,7 @@ extension Web3 { /// Returns a "Transaction intermediate" object. public func prepareDeploy(bytecode: Data, constructor: ABI.Element.Constructor? = nil, - parameters: [AnyObject]? = nil, + parameters: [Any]? = nil, extraData: Data? = nil) -> WriteOperation? { // MARK: Writing Data flow guard let data = self.contract.deploy(bytecode: bytecode, @@ -83,7 +83,7 @@ extension Web3 { /// Elements of "parameters" can be other arrays or instances of String, Data, BigInt, BigUInt, Int or EthereumAddress. /// /// Returns a "Transaction intermediate" object. - public func createReadOperation(_ method: String = "fallback", parameters: [AnyObject] = [AnyObject](), extraData: Data = Data()) -> ReadOperation? { + public func createReadOperation(_ method: String = "fallback", parameters: [Any] = [Any](), extraData: Data = Data()) -> ReadOperation? { // MARK: - Encoding ABI Data flow guard let data = contract.method(method, parameters: parameters, extraData: extraData) else { return nil } @@ -104,7 +104,7 @@ extension Web3 { /// Elements of "parameters" can be other arrays or instances of String, Data, BigInt, BigUInt, Int or EthereumAddress. /// /// Returns a "Transaction intermediate" object. - public func createWriteOperation(_ method: String = "fallback", parameters: [AnyObject] = [AnyObject](), extraData: Data = Data()) -> WriteOperation? { + public func createWriteOperation(_ method: String = "fallback", parameters: [Any] = [Any](), extraData: Data = Data()) -> WriteOperation? { guard let data = contract.method(method, parameters: parameters, extraData: extraData) else { return nil } transaction.data = data if let network = web3.provider.network { diff --git a/Sources/web3swift/Web3/Web3+Utils.swift b/Sources/web3swift/Web3/Web3+Utils.swift index e58005fd1..a5a3310b9 100755 --- a/Sources/web3swift/Web3/Web3+Utils.swift +++ b/Sources/web3swift/Web3/Web3+Utils.swift @@ -23,7 +23,7 @@ extension Web3.Utils { // /// and the nonce of this address // public static func calculateContractAddress(from: EthereumAddress, nonce: BigUInt) -> EthereumAddress? { // guard let normalizedAddress = from.addressData.setLengthLeft(32) else {return nil} - // guard let data = RLP.encode([normalizedAddress, nonce] as [AnyObject]) else {return nil} + // guard let data = RLP.encode([normalizedAddress, nonce]) else {return nil} // guard let contractAddressData = Utilities.sha3(data)?[12..<32] else {return nil} // guard let contractAddress = EthereumAddress(Data(contractAddressData)) else {return nil} // return contractAddress diff --git a/Tests/web3swiftTests/localTests/ABIEncoderTest.swift b/Tests/web3swiftTests/localTests/ABIEncoderTest.swift index 4b50fdecd..efe0348a5 100644 --- a/Tests/web3swiftTests/localTests/ABIEncoderTest.swift +++ b/Tests/web3swiftTests/localTests/ABIEncoderTest.swift @@ -103,7 +103,7 @@ class ABIEncoderTest: XCTestCase { } func testAbiEncodingEmptyValues() { - let zeroBytes = ABIEncoder.encode(types: [ABI.Element.InOut](), values: [AnyObject]())! + let zeroBytes = ABIEncoder.encode(types: [ABI.Element.InOut](), values: [Any]())! XCTAssert(zeroBytes.count == 0) let functionWithNoInput = ABI.Element.Function(name: "testFunction", @@ -117,69 +117,69 @@ class ABIEncoderTest: XCTestCase { } func testConvertToBigInt() { - XCTAssertEqual(ABIEncoder.convertToBigInt(BigInt(-29390909).serialize() as AnyObject), -29390909) - XCTAssertEqual(ABIEncoder.convertToBigInt(Data.fromHex("00FF")! as AnyObject), 255) - XCTAssertEqual(ABIEncoder.convertToBigInt(BigInt(-29390909) as AnyObject), -29390909) - XCTAssertEqual(ABIEncoder.convertToBigInt(BigUInt(29390909) as AnyObject), 29390909) - XCTAssertEqual(ABIEncoder.convertToBigInt(UInt(123) as AnyObject), 123) - XCTAssertEqual(ABIEncoder.convertToBigInt(UInt8(254) as AnyObject), 254) - XCTAssertEqual(ABIEncoder.convertToBigInt(UInt16(9090) as AnyObject), 9090) - XCTAssertEqual(ABIEncoder.convertToBigInt(UInt32(747474) as AnyObject), 747474) - XCTAssertEqual(ABIEncoder.convertToBigInt(UInt64(45222) as AnyObject), 45222) - XCTAssertEqual(ABIEncoder.convertToBigInt(Int(123) as AnyObject), 123) - XCTAssertEqual(ABIEncoder.convertToBigInt(Int8(127) as AnyObject), 127) - XCTAssertEqual(ABIEncoder.convertToBigInt(Int16(9090) as AnyObject), 9090) - XCTAssertEqual(ABIEncoder.convertToBigInt(Int32(83888) as AnyObject), 83888) - XCTAssertEqual(ABIEncoder.convertToBigInt(Int64(45222) as AnyObject), 45222) - XCTAssertEqual(ABIEncoder.convertToBigInt(Int(-32213) as AnyObject), -32213) - XCTAssertEqual(ABIEncoder.convertToBigInt(Int8(-10) as AnyObject), -10) - XCTAssertEqual(ABIEncoder.convertToBigInt(Int16(-32000) as AnyObject), -32000) - XCTAssertEqual(ABIEncoder.convertToBigInt(Int32(-50050500) as AnyObject), -50050500) - XCTAssertEqual(ABIEncoder.convertToBigInt(Int64(-2) as AnyObject), -2) - XCTAssertEqual(ABIEncoder.convertToBigInt("10" as AnyObject), 10) - XCTAssertEqual(ABIEncoder.convertToBigInt("-10" as AnyObject), -10) - XCTAssertEqual(ABIEncoder.convertToBigInt("FF" as AnyObject), 255) - XCTAssertEqual(ABIEncoder.convertToBigInt("-FF" as AnyObject), -255) - XCTAssertEqual(ABIEncoder.convertToBigInt("0xFF" as AnyObject), 255) - XCTAssertEqual(ABIEncoder.convertToBigInt(" 10 " as AnyObject), 10) - XCTAssertEqual(ABIEncoder.convertToBigInt(" -10 " as AnyObject), -10) - XCTAssertEqual(ABIEncoder.convertToBigInt(" FF " as AnyObject), 255) - XCTAssertEqual(ABIEncoder.convertToBigInt(" -FF " as AnyObject), -255) - XCTAssertEqual(ABIEncoder.convertToBigInt(" 0xFF " as AnyObject), 255) + XCTAssertEqual(ABIEncoder.convertToBigInt(BigInt(-29390909).serialize()), -29390909) + XCTAssertEqual(ABIEncoder.convertToBigInt(Data.fromHex("00FF")!), 255) + XCTAssertEqual(ABIEncoder.convertToBigInt(BigInt(-29390909)), -29390909) + XCTAssertEqual(ABIEncoder.convertToBigInt(BigUInt(29390909)), 29390909) + XCTAssertEqual(ABIEncoder.convertToBigInt(UInt(123)), 123) + XCTAssertEqual(ABIEncoder.convertToBigInt(UInt8(254)), 254) + XCTAssertEqual(ABIEncoder.convertToBigInt(UInt16(9090)), 9090) + XCTAssertEqual(ABIEncoder.convertToBigInt(UInt32(747474)), 747474) + XCTAssertEqual(ABIEncoder.convertToBigInt(UInt64(45222)), 45222) + XCTAssertEqual(ABIEncoder.convertToBigInt(Int(123)), 123) + XCTAssertEqual(ABIEncoder.convertToBigInt(Int8(127)), 127) + XCTAssertEqual(ABIEncoder.convertToBigInt(Int16(9090)), 9090) + XCTAssertEqual(ABIEncoder.convertToBigInt(Int32(83888)), 83888) + XCTAssertEqual(ABIEncoder.convertToBigInt(Int64(45222)), 45222) + XCTAssertEqual(ABIEncoder.convertToBigInt(Int(-32213)), -32213) + XCTAssertEqual(ABIEncoder.convertToBigInt(Int8(-10)), -10) + XCTAssertEqual(ABIEncoder.convertToBigInt(Int16(-32000)), -32000) + XCTAssertEqual(ABIEncoder.convertToBigInt(Int32(-50050500)), -50050500) + XCTAssertEqual(ABIEncoder.convertToBigInt(Int64(-2)), -2) + XCTAssertEqual(ABIEncoder.convertToBigInt("10"), 10) + XCTAssertEqual(ABIEncoder.convertToBigInt("-10"), -10) + XCTAssertEqual(ABIEncoder.convertToBigInt("FF"), 255) + XCTAssertEqual(ABIEncoder.convertToBigInt("-FF"), -255) + XCTAssertEqual(ABIEncoder.convertToBigInt("0xFF"), 255) + XCTAssertEqual(ABIEncoder.convertToBigInt(" 10 "), 10) + XCTAssertEqual(ABIEncoder.convertToBigInt(" -10 "), -10) + XCTAssertEqual(ABIEncoder.convertToBigInt(" FF "), 255) + XCTAssertEqual(ABIEncoder.convertToBigInt(" -FF "), -255) + XCTAssertEqual(ABIEncoder.convertToBigInt(" 0xFF "), 255) } func testConvertToBigUInt() { /// When negative value is serialized the first byte represents sign when decoding as a signed number. /// Unsigned numbers treat the first byte as just another byte of a number, not a sign. - XCTAssertEqual(ABIEncoder.convertToBigUInt(BigInt(-29390909).serialize() as AnyObject), 4324358205) - XCTAssertEqual(ABIEncoder.convertToBigUInt(Data.fromHex("00FF")! as AnyObject), 255) - XCTAssertEqual(ABIEncoder.convertToBigUInt(BigInt(-29390909) as AnyObject), nil) - XCTAssertEqual(ABIEncoder.convertToBigUInt(BigUInt(29390909) as AnyObject), 29390909) - XCTAssertEqual(ABIEncoder.convertToBigUInt(UInt(123) as AnyObject), 123) - XCTAssertEqual(ABIEncoder.convertToBigUInt(UInt8(254) as AnyObject), 254) - XCTAssertEqual(ABIEncoder.convertToBigUInt(UInt16(9090) as AnyObject), 9090) - XCTAssertEqual(ABIEncoder.convertToBigUInt(UInt32(747474) as AnyObject), 747474) - XCTAssertEqual(ABIEncoder.convertToBigUInt(UInt64(45222) as AnyObject), 45222) - XCTAssertEqual(ABIEncoder.convertToBigUInt(Int(123) as AnyObject), 123) - XCTAssertEqual(ABIEncoder.convertToBigUInt(Int8(127) as AnyObject), 127) - XCTAssertEqual(ABIEncoder.convertToBigUInt(Int16(9090) as AnyObject), 9090) - XCTAssertEqual(ABIEncoder.convertToBigUInt(Int32(83888) as AnyObject), 83888) - XCTAssertEqual(ABIEncoder.convertToBigUInt(Int64(45222) as AnyObject), 45222) - XCTAssertEqual(ABIEncoder.convertToBigUInt(Int(-32213) as AnyObject), nil) - XCTAssertEqual(ABIEncoder.convertToBigUInt(Int8(-10) as AnyObject), nil) - XCTAssertEqual(ABIEncoder.convertToBigUInt(Int16(-32000) as AnyObject), nil) - XCTAssertEqual(ABIEncoder.convertToBigUInt(Int32(-50050500) as AnyObject), nil) - XCTAssertEqual(ABIEncoder.convertToBigUInt(Int64(-2) as AnyObject), nil) - XCTAssertEqual(ABIEncoder.convertToBigUInt("10" as AnyObject), 10) - XCTAssertEqual(ABIEncoder.convertToBigUInt("-10" as AnyObject), nil) - XCTAssertEqual(ABIEncoder.convertToBigUInt("FF" as AnyObject), 255) - XCTAssertEqual(ABIEncoder.convertToBigUInt("-FF" as AnyObject), nil) - XCTAssertEqual(ABIEncoder.convertToBigUInt("0xFF" as AnyObject), 255) - XCTAssertEqual(ABIEncoder.convertToBigUInt(" 10 " as AnyObject), 10) - XCTAssertEqual(ABIEncoder.convertToBigUInt(" -10 " as AnyObject), nil) - XCTAssertEqual(ABIEncoder.convertToBigUInt(" FF " as AnyObject), 255) - XCTAssertEqual(ABIEncoder.convertToBigUInt(" -FF " as AnyObject), nil) - XCTAssertEqual(ABIEncoder.convertToBigUInt(" 0xFF " as AnyObject), 255) + XCTAssertEqual(ABIEncoder.convertToBigUInt(BigInt(-29390909).serialize()), 4324358205) + XCTAssertEqual(ABIEncoder.convertToBigUInt(Data.fromHex("00FF")!), 255) + XCTAssertEqual(ABIEncoder.convertToBigUInt(BigInt(-29390909)), nil) + XCTAssertEqual(ABIEncoder.convertToBigUInt(BigUInt(29390909)), 29390909) + XCTAssertEqual(ABIEncoder.convertToBigUInt(UInt(123)), 123) + XCTAssertEqual(ABIEncoder.convertToBigUInt(UInt8(254)), 254) + XCTAssertEqual(ABIEncoder.convertToBigUInt(UInt16(9090)), 9090) + XCTAssertEqual(ABIEncoder.convertToBigUInt(UInt32(747474)), 747474) + XCTAssertEqual(ABIEncoder.convertToBigUInt(UInt64(45222)), 45222) + XCTAssertEqual(ABIEncoder.convertToBigUInt(Int(123)), 123) + XCTAssertEqual(ABIEncoder.convertToBigUInt(Int8(127)), 127) + XCTAssertEqual(ABIEncoder.convertToBigUInt(Int16(9090)), 9090) + XCTAssertEqual(ABIEncoder.convertToBigUInt(Int32(83888)), 83888) + XCTAssertEqual(ABIEncoder.convertToBigUInt(Int64(45222)), 45222) + XCTAssertEqual(ABIEncoder.convertToBigUInt(Int(-32213)), nil) + XCTAssertEqual(ABIEncoder.convertToBigUInt(Int8(-10)), nil) + XCTAssertEqual(ABIEncoder.convertToBigUInt(Int16(-32000)), nil) + XCTAssertEqual(ABIEncoder.convertToBigUInt(Int32(-50050500)), nil) + XCTAssertEqual(ABIEncoder.convertToBigUInt(Int64(-2)), nil) + XCTAssertEqual(ABIEncoder.convertToBigUInt("10"), 10) + XCTAssertEqual(ABIEncoder.convertToBigUInt("-10"), nil) + XCTAssertEqual(ABIEncoder.convertToBigUInt("FF"), 255) + XCTAssertEqual(ABIEncoder.convertToBigUInt("-FF"), nil) + XCTAssertEqual(ABIEncoder.convertToBigUInt("0xFF"), 255) + XCTAssertEqual(ABIEncoder.convertToBigUInt(" 10 "), 10) + XCTAssertEqual(ABIEncoder.convertToBigUInt(" -10 "), nil) + XCTAssertEqual(ABIEncoder.convertToBigUInt(" FF "), 255) + XCTAssertEqual(ABIEncoder.convertToBigUInt(" -FF "), nil) + XCTAssertEqual(ABIEncoder.convertToBigUInt(" 0xFF "), 255) } /// When dynamic types (string, non-fixed size array, dynamic bytes) are encoded @@ -187,15 +187,15 @@ class ABIEncoderTest: XCTestCase { /// how much bytes should be skipped from the beginning of the resulting byte array to reach the /// value of the dynamic type. func testDynamicTypesDataOffset() { - var hexData = ABIEncoder.encode(types: [.string], values: ["test"] as [AnyObject])?.toHexString() + var hexData = ABIEncoder.encode(types: [.string], values: ["test"])?.toHexString() XCTAssertEqual(hexData?[0..<64], "0000000000000000000000000000000000000000000000000000000000000020") XCTAssertEqual(hexData, "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000047465737400000000000000000000000000000000000000000000000000000000") - hexData = ABIEncoder.encode(types: [.array(type: .uint(bits: 8), length: 0)], values: [[1,2,3,4]] as [AnyObject])?.toHexString() + hexData = ABIEncoder.encode(types: [.array(type: .uint(bits: 8), length: 0)], values: [[1,2,3,4]])?.toHexString() XCTAssertEqual(hexData?[0..<64], "0000000000000000000000000000000000000000000000000000000000000020") XCTAssertEqual(hexData, "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004") // This one shouldn't have data offset - hexData = ABIEncoder.encode(types: [.array(type: .uint(bits: 8), length: 4)], values: [[1,2,3,4]] as [AnyObject])?.toHexString() + hexData = ABIEncoder.encode(types: [.array(type: .uint(bits: 8), length: 4)], values: [[1,2,3,4]])?.toHexString() // First 32 bytes are the first value from the array XCTAssertEqual(hexData?[0..<64], "0000000000000000000000000000000000000000000000000000000000000001") XCTAssertEqual(hexData, "0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004") @@ -204,7 +204,7 @@ class ABIEncoderTest: XCTestCase { .bool, .array(type: .uint(bits: 8), length: 0), .bytes(length: 2)] - let values: [AnyObject] = [10, false, [1,2,3,4], Data(count: 2)] as [AnyObject] + let values: [Any] = [10, false, [1,2,3,4], Data(count: 2)] hexData = ABIEncoder.encode(types: types, values: values)?.toHexString() XCTAssertEqual(hexData?[128..<192], "0000000000000000000000000000000000000000000000000000000000000080") XCTAssertEqual(hexData, "000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004") @@ -212,22 +212,22 @@ class ABIEncoderTest: XCTestCase { /// Test for the expected output when encoding dynamic types. func testAbiEncodingDynamicTypes() { - var encodedValue = ABIEncoder.encode(types: [.dynamicBytes], values: [Data.fromHex("6761766f66796f726b")!] as [AnyObject])!.toHexString() + var encodedValue = ABIEncoder.encode(types: [.dynamicBytes], values: [Data.fromHex("6761766f66796f726b")!])!.toHexString() XCTAssertEqual(encodedValue, "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000096761766f66796f726b0000000000000000000000000000000000000000000000") - encodedValue = ABIEncoder.encode(types: [.dynamicBytes], values: [Data.fromHex("731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b")!] as [AnyObject])!.toHexString() + encodedValue = ABIEncoder.encode(types: [.dynamicBytes], values: [Data.fromHex("731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b")!])!.toHexString() XCTAssertEqual(encodedValue, "00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b") - encodedValue = ABIEncoder.encode(types: [.dynamicBytes], values: [Data.fromHex("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1")!] as [AnyObject])!.toHexString() + encodedValue = ABIEncoder.encode(types: [.dynamicBytes], values: [Data.fromHex("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1")!])!.toHexString() XCTAssertEqual(encodedValue, "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000009ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff100") - encodedValue = ABIEncoder.encode(types: [.dynamicBytes], values: [Data.fromHex("c3a40000c3a4")!] as [AnyObject])!.toHexString() + encodedValue = ABIEncoder.encode(types: [.dynamicBytes], values: [Data.fromHex("c3a40000c3a4")!])!.toHexString() XCTAssertEqual(encodedValue, "00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006c3a40000c3a40000000000000000000000000000000000000000000000000000") - encodedValue = ABIEncoder.encode(types: [.string], values: ["gavofyork"] as [AnyObject])!.toHexString() + encodedValue = ABIEncoder.encode(types: [.string], values: ["gavofyork"])!.toHexString() XCTAssertEqual(encodedValue, "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000096761766f66796f726b0000000000000000000000000000000000000000000000") - encodedValue = ABIEncoder.encode(types: [.string], values: ["Heeäööä👅D34ɝɣ24Єͽ-.,äü+#/"] as [AnyObject])!.toHexString() + encodedValue = ABIEncoder.encode(types: [.string], values: ["Heeäööä👅D34ɝɣ24Єͽ-.,äü+#/"])!.toHexString() XCTAssertEqual(encodedValue, "00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000026486565c3a4c3b6c3b6c3a4f09f9185443334c99dc9a33234d084cdbd2d2e2cc3a4c3bc2b232f0000000000000000000000000000000000000000000000000000") } } diff --git a/Tests/web3swiftTests/localTests/AdvancedABIv2Tests.swift b/Tests/web3swiftTests/localTests/AdvancedABIv2Tests.swift index 1be8abb35..c5ce050d9 100755 --- a/Tests/web3swiftTests/localTests/AdvancedABIv2Tests.swift +++ b/Tests/web3swiftTests/localTests/AdvancedABIv2Tests.swift @@ -56,7 +56,7 @@ class AdvancedABIv2Tests: LocalTestCase { let allAddresses = try await web3.eth.ownedAccounts() var contract = web3.contract(abiString, at: nil, abiVersion: 2)! - let parameters = [] as [AnyObject] + let parameters: [Any] = [] // MARK: Writing Data flow let deployTx = contract.prepareDeploy(bytecode: bytecode, parameters: parameters)! deployTx.transaction.from = allAddresses[0] @@ -92,7 +92,7 @@ class AdvancedABIv2Tests: LocalTestCase { let allAddresses = try await web3.eth.ownedAccounts() var contract = web3.contract(abiString, at: nil, abiVersion: 2)! - let parameters = [] as [AnyObject] + let parameters: [Any] = [] // MARK: Writing Data flow let deployTx = contract.prepareDeploy(bytecode: bytecode, parameters: parameters)! deployTx.transaction.from = allAddresses[0] @@ -127,7 +127,7 @@ class AdvancedABIv2Tests: LocalTestCase { let allAddresses = try await web3.eth.ownedAccounts() var contract = web3.contract(abiString, at: nil, abiVersion: 2)! - let parameters = [] as [AnyObject] + let parameters: [Any] = [] // MARK: Writing Data flow let deployTx = contract.prepareDeploy(bytecode: bytecode, parameters: parameters)! deployTx.transaction.from = allAddresses[0] @@ -163,7 +163,7 @@ class AdvancedABIv2Tests: LocalTestCase { let allAddresses = try await web3.eth.ownedAccounts() var contract = web3.contract(abiString, at: nil, abiVersion: 2)! - let parameters = [] as [AnyObject] + let parameters: [Any] = [] // MARK: Writing Data flow let deployTx = contract.prepareDeploy(bytecode: bytecode, parameters: parameters)! deployTx.transaction.from = allAddresses[0] diff --git a/Tests/web3swiftTests/localTests/BasicLocalNodeTests.swift b/Tests/web3swiftTests/localTests/BasicLocalNodeTests.swift index e71641ee3..fbb85e68b 100755 --- a/Tests/web3swiftTests/localTests/BasicLocalNodeTests.swift +++ b/Tests/web3swiftTests/localTests/BasicLocalNodeTests.swift @@ -21,7 +21,7 @@ class BasicLocalNodeTests: LocalTestCase { let contract = web3.contract(abiString, at: nil, abiVersion: 2)! - let parameters = [] as [AnyObject] + let parameters: [Any] = [] let deployTx = contract.prepareDeploy(bytecode: bytecode, parameters: parameters)! deployTx.transaction.from = allAddresses[0] let policies = Policies(gasLimitPolicy: .manual(3000000)) @@ -48,7 +48,7 @@ class BasicLocalNodeTests: LocalTestCase { let sendToAddress = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")! let contract = web3.contract(Web3.Utils.coldWalletABI, at: sendToAddress, abiVersion: 2)! - let parameters = [] as [AnyObject] + let parameters: [Any] = [] let sendTx = contract.createWriteOperation("fallback", parameters: parameters)! let valueToSend = try XCTUnwrap(Utilities.parseToBigUInt("1.0", units: .ether)) diff --git a/Tests/web3swiftTests/localTests/EIP681Tests.swift b/Tests/web3swiftTests/localTests/EIP681Tests.swift index 2f347bf59..cabd53fa2 100755 --- a/Tests/web3swiftTests/localTests/EIP681Tests.swift +++ b/Tests/web3swiftTests/localTests/EIP681Tests.swift @@ -93,6 +93,11 @@ class EIP681Tests: XCTestCase { XCTAssertEqual(address, testAddress) } + guard eip681Code.parameters.count > 1 else { + XCTFail("'eip681Code.parameters.count' must be at least 2.") + return + } + XCTAssertEqual(eip681Code.functionName, "transfer") XCTAssertEqual(eip681Code.parameters[0].type, .address) /// `eip681Code.parameters[0].value` is not checked as it's fetched from remote and is unknown. @@ -115,6 +120,11 @@ class EIP681Tests: XCTestCase { XCTAssertEqual(address, testAddress) } + guard eip681Code.parameters.count > 1 else { + XCTFail("'eip681Code.parameters.count' must be at least 2.") + return + } + XCTAssertEqual(eip681Code.functionName, "transfer") XCTAssertEqual(eip681Code.parameters[0].type, .address) /// `eip681Code.parameters[0].value` is not checked as it's fetched from remote and is unknown. @@ -284,24 +294,24 @@ class EIP681Tests: XCTestCase { eip681Link.functionName = "setData" eip681Link.parameters = [Web3.EIP681Code.EIP681Parameter(type: .array(type: .bytes(length: 32), length: 0), value: [Data.fromHex("0x1234789565875498655487123478956587549865548712347895658754980000")!, - Data.fromHex("0x1234789565875498655487123478956587549865548712347895658754986554")!] as AnyObject), + Data.fromHex("0x1234789565875498655487123478956587549865548712347895658754986554")!]), Web3.EIP681Code.EIP681Parameter(type: .array(type: .dynamicBytes, length: 0), value: [Data.fromHex("0x12345607")!, - Data.fromHex("0x8965abcdef")!] as AnyObject), + Data.fromHex("0x8965abcdef")!]), Web3.EIP681Code.EIP681Parameter(type: .uint(bits: 256), - value: 98986565 as AnyObject), + value: 98986565), Web3.EIP681Code.EIP681Parameter(type: .int(bits: 256), - value: 155445566 as AnyObject), + value: 155445566), Web3.EIP681Code.EIP681Parameter(type: .address, - value: EthereumAddress("0x9aBbDB06A61cC686BD635484439549D45c2449cc")! as AnyObject), + value: EthereumAddress("0x9aBbDB06A61cC686BD635484439549D45c2449cc")!), Web3.EIP681Code.EIP681Parameter(type: .bytes(length: 5), - value: "0x9aBbDB06A6" as AnyObject), + value: "0x9aBbDB06A6"), Web3.EIP681Code.EIP681Parameter(type: .bytes(length: 3), - value: Data.fromHex("0x9aBbDB")! as AnyObject), + value: Data.fromHex("0x9aBbDB")!), Web3.EIP681Code.EIP681Parameter(type: .dynamicBytes, - value: Data.fromHex("0x11009aBbDB87879898656545")! as AnyObject), + value: Data.fromHex("0x11009aBbDB87879898656545")!), Web3.EIP681Code.EIP681Parameter(type: .string, - value: "this is EIP681 query parameter string" as AnyObject)] + value: "this is EIP681 query parameter string")] let unencodedResult = "ethereum:0x9aBbDB06A61cC686BD635484439549D45c2449cc/setData?bytes32[]=[0x1234789565875498655487123478956587549865548712347895658754980000,0x1234789565875498655487123478956587549865548712347895658754986554]&bytes[]=[0x12345607,0x8965abcdef]&uint256=98986565&int256=155445566&address=0x9aBbDB06A61cC686BD635484439549D45c2449cc&bytes5=0x9abbdb06a6&bytes3=0x9abbdb&bytes=0x11009abbdb87879898656545&string=this is EIP681 query parameter string" diff --git a/Tests/web3swiftTests/localTests/EIP712Tests.swift b/Tests/web3swiftTests/localTests/EIP712Tests.swift index 538c651cf..3f527d2cf 100644 --- a/Tests/web3swiftTests/localTests/EIP712Tests.swift +++ b/Tests/web3swiftTests/localTests/EIP712Tests.swift @@ -17,8 +17,8 @@ class EIP712Tests: LocalTestCase { payable: false) let object = ABI.Element.function(function) let safeTxData = object.encodeParameters([ - EthereumAddress("0x41B5844f4680a8C38fBb695b7F9CFd1F64474a72")! as AnyObject, - amountLinen as AnyObject + EthereumAddress("0x41B5844f4680a8C38fBb695b7F9CFd1F64474a72")!, + amountLinen ])! let operation: EIP712.UInt8 = 1 let safeTxGas = EIP712.UInt256(250000) @@ -68,8 +68,8 @@ class EIP712Tests: LocalTestCase { payable: false) let object = ABI.Element.function(function) let safeTxData = object.encodeParameters([ - EthereumAddress("0x41B5844f4680a8C38fBb695b7F9CFd1F64474a72")! as AnyObject, - amount as AnyObject + EthereumAddress("0x41B5844f4680a8C38fBb695b7F9CFd1F64474a72")!, + amount ])! let operation: EIP712.UInt8 = 1 let safeTxGas = EIP712.UInt256(250000) diff --git a/Tests/web3swiftTests/localTests/ERC20Tests.swift b/Tests/web3swiftTests/localTests/ERC20Tests.swift index 231719d51..f79ae933f 100755 --- a/Tests/web3swiftTests/localTests/ERC20Tests.swift +++ b/Tests/web3swiftTests/localTests/ERC20Tests.swift @@ -26,7 +26,7 @@ class ERC20Tests: LocalTestCase { let addressOfUser = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")! let contract = web3.contract(Web3.Utils.erc20ABI, at: receipt.contractAddress!, abiVersion: 2)! - guard let readTX = contract.createReadOperation("balanceOf", parameters: [addressOfUser] as [AnyObject]) else {return XCTFail()} + guard let readTX = contract.createReadOperation("balanceOf", parameters: [addressOfUser]) else {return XCTFail()} readTX.transaction.from = addressOfUser let tokenBalance = try await readTX.callContractMethod() guard let bal = tokenBalance["0"] as? BigUInt else {return XCTFail()} @@ -49,7 +49,7 @@ class ERC20Tests: LocalTestCase { // let method = "transfer" // let tx = contract.write( // method, -// parameters: [toAddress, amount] as [AnyObject], +// parameters: [toAddress, amount], // extraData: Data(), // transaction: options)! // } diff --git a/Tests/web3swiftTests/localTests/EthereumContractTest.swift b/Tests/web3swiftTests/localTests/EthereumContractTest.swift index 06251e388..be6c6cd4f 100644 --- a/Tests/web3swiftTests/localTests/EthereumContractTest.swift +++ b/Tests/web3swiftTests/localTests/EthereumContractTest.swift @@ -65,10 +65,10 @@ class EthereumContractTest: LocalTestCase { func test_encodeMethodBasedOnNameWithParameters() async throws { let web3 = try await Web3.new(LocalTestCase.url) let contract = try XCTUnwrap(web3.contract(EthereumContractTest.overloadedFunctionsABI, at: EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B"))) - let parameters: [AnyObject] = [ + let parameters: [Any] = [ [Data.randomBytes(length: 32), Data.randomBytes(length: 32)], [Data.randomBytes(length: 32), Data.randomBytes(length: 32)] - ] as [AnyObject] + ] let functionNameWithParameters = "setData(bytes32[],bytes[])" let transaction = contract.createWriteOperation(functionNameWithParameters, parameters: parameters) XCTAssertNotNil(transaction) @@ -88,7 +88,7 @@ class EthereumContractTest: LocalTestCase { func test_encodeMethodBasedOnHexSignature() async throws { let web3 = try await Web3.new(LocalTestCase.url) let contract = try XCTUnwrap(web3.contract(EthereumContractTest.overloadedFunctionsABI, at: EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B"))) - let parameters: [AnyObject] = [Data.randomBytes(length: 32), Data.randomBytes(length: 32)] as [AnyObject] + let parameters: [Any] = [Data.randomBytes(length: 32), Data.randomBytes(length: 32)] let functionSignature = getFuncSignature("setData(bytes32,bytes)") let transaction = contract.createWriteOperation(functionSignature, parameters: parameters) XCTAssertNotNil(transaction) diff --git a/Tests/web3swiftTests/localTests/PersonalSignatureTests.swift b/Tests/web3swiftTests/localTests/PersonalSignatureTests.swift index 141b23b0d..a46bb4b28 100755 --- a/Tests/web3swiftTests/localTests/PersonalSignatureTests.swift +++ b/Tests/web3swiftTests/localTests/PersonalSignatureTests.swift @@ -65,13 +65,13 @@ class PersonalSignatureTests: XCTestCase { // Calling contract contract = web3.contract(abiString, at: receipt.contractAddress!)! - var tx = contract.createReadOperation("hashPersonalMessage", parameters: [message as AnyObject]) + var tx = contract.createReadOperation("hashPersonalMessage", parameters: [message]) tx?.transaction.from = expectedAddress var result = try await tx!.callContractMethod() guard let hash = result["hash"]! as? Data else { return XCTFail() } XCTAssert(Utilities.hashPersonalMessage(message.data(using: .utf8)!)! == hash) - tx = contract.createReadOperation("recoverSigner", parameters: [message, unmarshalledSignature.v, Data(unmarshalledSignature.r), Data(unmarshalledSignature.s)] as [AnyObject]) + tx = contract.createReadOperation("recoverSigner", parameters: [message, unmarshalledSignature.v, Data(unmarshalledSignature.r), Data(unmarshalledSignature.s)]) tx?.transaction.from = expectedAddress result = try await tx!.callContractMethod() guard let signer = result["signer"]! as? EthereumAddress else { return XCTFail() } diff --git a/Tests/web3swiftTests/localTests/PromisesTests.swift b/Tests/web3swiftTests/localTests/PromisesTests.swift index 8063003d9..434c6389c 100755 --- a/Tests/web3swiftTests/localTests/PromisesTests.swift +++ b/Tests/web3swiftTests/localTests/PromisesTests.swift @@ -41,7 +41,7 @@ // let allAddresses = try await web3.eth.ownedAccounts() // let contract = web3.contract(Web3.Utils.estimateGasTestABI, at: nil, abiVersion: 2)! // -// let parameters = [] as [AnyObject] +// let parameters = [] // let deployTx = contract.deploy(bytecode: bytecode, parameters: parameters)! // deployTx.transaction.from = allAddresses[0] // deployTx.transaction.gasLimitPolicy = .manual(3000000) @@ -80,7 +80,7 @@ // // // MARK: Writing Data flow // guard let tx1 = contract.write("test", -// parameters: [amount1] as [AnyObject], +// parameters: [amount1], // extraData: Data(), // transaction: options) else { // return @@ -93,7 +93,7 @@ // // // MARK: Writing Data flow // guard let tx2 = contract.write("test", -// parameters: [amount2] as [AnyObject], +// parameters: [amount2], // extraData: Data(), // transaction: options) else { // return @@ -122,7 +122,7 @@ // let token = web3.contract(Web3.Utils.erc20ABI, at: receipt.contractAddress, abiVersion: 2)! // // let userAddress = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")! -// let tokenBalance = try await token.read("balanceOf", parameters: [userAddress] as [AnyObject])!.decodedData() +// let tokenBalance = try await token.read("balanceOf", parameters: [userAddress])!.decodedData() // guard let bal = tokenBalance["0"] as? BigUInt else {return XCTFail()} // ) // } diff --git a/Tests/web3swiftTests/localTests/ST20AndSecurityTokenTests.swift b/Tests/web3swiftTests/localTests/ST20AndSecurityTokenTests.swift index 84782bbeb..285b2641f 100644 --- a/Tests/web3swiftTests/localTests/ST20AndSecurityTokenTests.swift +++ b/Tests/web3swiftTests/localTests/ST20AndSecurityTokenTests.swift @@ -37,11 +37,11 @@ class ST20AndSecurityTokenTests: XCTestCase { } switch function.name { case "symbol": - return ABIEncoder.encode(types: [.string], values: [expectedSymbol] as [AnyObject])! + return ABIEncoder.encode(types: [.string], values: [expectedSymbol])! case "name": - return ABIEncoder.encode(types: [.string], values: [expectedName] as [AnyObject])! + return ABIEncoder.encode(types: [.string], values: [expectedName])! case "decimals": - return ABIEncoder.encode(types: [.uint(bits: 8)], values: [expectedDecimals] as [AnyObject])! + return ABIEncoder.encode(types: [.uint(bits: 8)], values: [expectedDecimals])! default: // Unexpected function called XCTFail("Called function '\(String(describing: function.name))' which wasn't supposed to be called.") @@ -71,12 +71,12 @@ class ST20AndSecurityTokenTests: XCTestCase { case "balanceOf": let address = function.decodeInputData(transaction.data)?["0"] as? EthereumAddress XCTAssertEqual(address, userAddress) - return ABIEncoder.encode(types: [.uint(bits: 256)], values: [expectedBalance] as [AnyObject])! + return ABIEncoder.encode(types: [.uint(bits: 256)], values: [expectedBalance])! case "allowance": let transactionInput = function.decodeInputData(transaction.data) XCTAssertEqual(transactionInput?["0"] as? EthereumAddress, userAddress) XCTAssertEqual(transactionInput?["1"] as? EthereumAddress, delegate) - return ABIEncoder.encode(types: [.uint(bits: 256)], values: [expectedAllowance] as [AnyObject])! + return ABIEncoder.encode(types: [.uint(bits: 256)], values: [expectedAllowance])! default: // Unexpected function called XCTFail("Called function '\(String(describing: function.name))' which wasn't supposed to be called.") @@ -98,7 +98,7 @@ class ST20AndSecurityTokenTests: XCTestCase { return Data() } if function.name == "investorCount" { - return ABIEncoder.encode(types: [.uint(bits: 256)], values: [expectedNumberOfInvestors] as [AnyObject])! + return ABIEncoder.encode(types: [.uint(bits: 256)], values: [expectedNumberOfInvestors])! } // Unexpected function called XCTFail("Called function '\(String(describing: function.name))' which wasn't supposed to be called.") @@ -119,7 +119,7 @@ class ST20AndSecurityTokenTests: XCTestCase { } switch function.name { case "granularity": - return ABIEncoder.encode(types: [.uint(bits: 256)], values: [expectedGranularity] as [AnyObject])! + return ABIEncoder.encode(types: [.uint(bits: 256)], values: [expectedGranularity])! default: // Unexpected function called XCTFail("Called function '\(String(describing: function.name))' which wasn't supposed to be called.") diff --git a/Tests/web3swiftTests/localTests/TestHelpers.swift b/Tests/web3swiftTests/localTests/TestHelpers.swift index 674771ec9..ce049fce4 100644 --- a/Tests/web3swiftTests/localTests/TestHelpers.swift +++ b/Tests/web3swiftTests/localTests/TestHelpers.swift @@ -22,12 +22,12 @@ class TestHelpers { let contract = web3.contract(abiString, at: nil, abiVersion: 2)! // FIXME: This should be zipped, because Arrays don't guarantee it's elements order - let parameters = [ + let parameters: [Any] = [ "web3swift", "w3s", EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")!, 1024 - ] as [AnyObject] + ] let deployTx = contract.prepareDeploy(bytecode: bytecode, constructor: contract.contract.constructor, parameters: parameters)! diff --git a/Tests/web3swiftTests/localTests/UncategorizedTests.swift b/Tests/web3swiftTests/localTests/UncategorizedTests.swift index dc5600da9..2dbebb775 100755 --- a/Tests/web3swiftTests/localTests/UncategorizedTests.swift +++ b/Tests/web3swiftTests/localTests/UncategorizedTests.swift @@ -116,7 +116,7 @@ class UncategorizedTests: XCTestCase { XCTAssert(contract != nil) let allMethods = contract!.contract.allMethods let userDeviceCount = try await contract! - .createReadOperation("userDeviceCount", parameters: [addr as AnyObject])? + .createReadOperation("userDeviceCount", parameters: [addr])? .callContractMethod() let totalUsers = try await contract! @@ -124,7 +124,7 @@ class UncategorizedTests: XCTestCase { .callContractMethod() let user = try await contract! - .createReadOperation("users", parameters: [0 as AnyObject])? + .createReadOperation("users", parameters: [0])? .callContractMethod() diff --git a/Tests/web3swiftTests/localTests/UserCases.swift b/Tests/web3swiftTests/localTests/UserCases.swift index 49a95184f..c6377dda9 100755 --- a/Tests/web3swiftTests/localTests/UserCases.swift +++ b/Tests/web3swiftTests/localTests/UserCases.swift @@ -22,7 +22,7 @@ class UserCases: XCTestCase { let (web3, _, receipt, abiString) = try await TestHelpers.localDeployERC20() let account = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")! let contract = web3.contract(abiString, at: receipt.contractAddress!)! - let readTransaction = contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject])! + let readTransaction = contract.createReadOperation("balanceOf", parameters: [account])! readTransaction.transaction.from = account let response = try await readTransaction.callContractMethod() let balance = response["0"] as? BigUInt @@ -76,7 +76,7 @@ class UserCases: XCTestCase { let allAddresses = try await web3.eth.ownedAccounts() let contract = web3.contract(Web3.Utils.estimateGasTestABI, at: nil, abiVersion: 2)! - let parameters = [AnyObject]() + let parameters = [Any]() let deployTx = contract.prepareDeploy(bytecode: bytecode, parameters: parameters)! deployTx.transaction.from = allAddresses[0] let policies = Policies(gasLimitPolicy: .manual(3000000)) From 79886de7bf6312120428d030262198f6ba4a1e39 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Sat, 14 Jan 2023 00:18:39 +0200 Subject: [PATCH 02/14] fix: ERC20BaseProperties are back to inherit from AnyObject (restricting protocol to classes) --- Sources/web3swift/Tokens/ERC20/ERC20BaseProperties.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/web3swift/Tokens/ERC20/ERC20BaseProperties.swift b/Sources/web3swift/Tokens/ERC20/ERC20BaseProperties.swift index 6146d467e..e0d861fe7 100644 --- a/Sources/web3swift/Tokens/ERC20/ERC20BaseProperties.swift +++ b/Sources/web3swift/Tokens/ERC20/ERC20BaseProperties.swift @@ -9,7 +9,7 @@ import Foundation /// Declares common properties of an [ERC-20](https://eips.ethereum.org/EIPS/eip-20) complient smart contract. /// Default implementation of access to these properties is declared in the extension of this protocol. -public protocol ERC20BaseProperties: Any { +public protocol ERC20BaseProperties: AnyObject { var basePropertiesProvider: ERC20BasePropertiesProvider { get } var contract: Web3.Contract { get } var name: String? { get } From 65349803fcd90ab8a83dd1f5425ebdb29a114adb Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Sat, 14 Jan 2023 00:18:59 +0200 Subject: [PATCH 03/14] fix: some spacing and docs fixed --- .../Web3Core/Contract/ContractProtocol.swift | 4 +- Sources/web3swift/Browser/browser.js | 16 ++--- .../Tokens/ERC1155/Web3+ERC1155.swift | 6 +- .../Tokens/ERC1376/Web3+ERC1376.swift | 32 +++++----- .../Tokens/ERC1400/Web3+ERC1400.swift | 60 +++++++++---------- .../Tokens/ERC1410/Web3+ERC1410.swift | 44 +++++++------- .../Tokens/ERC1594/Web3+ERC1594.swift | 18 +++--- .../Tokens/ERC1633/Web3+ERC1633.swift | 8 +-- .../Tokens/ERC1643/Web3+ERC1643.swift | 12 ++-- .../Tokens/ERC1644/Web3+ERC1644.swift | 12 ++-- .../web3swift/Tokens/ERC20/Web3+ERC20.swift | 8 +-- .../web3swift/Tokens/ERC721/Web3+ERC721.swift | 12 ++-- .../Tokens/ERC721x/Web3+ERC721x.swift | 22 +++---- .../web3swift/Tokens/ERC777/Web3+ERC777.swift | 26 ++++---- .../web3swift/Tokens/ERC888/Web3+ERC888.swift | 2 +- Sources/web3swift/Tokens/ST20/Web3+ST20.swift | 14 ++--- 16 files changed, 148 insertions(+), 148 deletions(-) diff --git a/Sources/Web3Core/Contract/ContractProtocol.swift b/Sources/Web3Core/Contract/ContractProtocol.swift index 33e25884d..f85819379 100755 --- a/Sources/Web3Core/Contract/ContractProtocol.swift +++ b/Sources/Web3Core/Contract/ContractProtocol.swift @@ -35,7 +35,7 @@ import BigInt /// let inputArgsTypes: [ABI.Element.InOut] = [.init(name: "firstArgument", type: ABI.Element.ParameterType.string), /// .init(name: "secondArgument", type: ABI.Element.ParameterType.uint(bits: 256))] /// let constructor = ABI.Element.Constructor(inputs: inputArgsTypes, constant: false, payable: payable) -/// let constructorArguments = ["This is the array of constructor arguments", 10_000] +/// let constructorArguments: [Any] = ["This is the array of constructor arguments", 10_000] /// /// contract.deploy(bytecode: smartContractBytecode, /// constructor: constructor, @@ -48,7 +48,7 @@ import BigInt /// /// ```swift /// let contract = EthereumContract(abiString) -/// let constructorArguments = ["This is the array of constructor arguments", 10_000] +/// let constructorArguments: [Any] = ["This is the array of constructor arguments", 10_000] /// /// contract.deploy(bytecode: smartContractBytecode, /// constructor: contract.constructor, diff --git a/Sources/web3swift/Browser/browser.js b/Sources/web3swift/Browser/browser.js index 88b5c8e4a..ea4090662 100644 --- a/Sources/web3swift/Browser/browser.js +++ b/Sources/web3swift/Browser/browser.js @@ -5379,7 +5379,7 @@ * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`. * The iteratee must complete with a boolean value as its result. * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon + * @param {Function} [callback] - A callback which is called as soon as any * iteratee returns `true`, or after all the `iteratee` functions have finished. * Result will be the first item in the array that passes the truth test * (iteratee) or the value `undefined` if none passed. Invoked with @@ -5412,7 +5412,7 @@ * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`. * The iteratee must complete with a boolean value as its result. * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon + * @param {Function} [callback] - A callback which is called as soon as any * iteratee returns `true`, or after all the `iteratee` functions have finished. * Result will be the first item in the array that passes the truth test * (iteratee) or the value `undefined` if none passed. Invoked with @@ -5434,7 +5434,7 @@ * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`. * The iteratee must complete with a boolean value as its result. * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon + * @param {Function} [callback] - A callback which is called as soon as any * iteratee returns `true`, or after all the `iteratee` functions have finished. * Result will be the first item in the array that passes the truth test * (iteratee) or the value `undefined` if none passed. Invoked with @@ -7297,7 +7297,7 @@ * in the collections in parallel. * The iteratee should complete with a boolean `result` value. * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon + * @param {Function} [callback] - A callback which is called as soon as any * iteratee returns `true`, or after all the iteratee functions have finished. * Result will be either `true` or `false` depending on the values of the async * tests. Invoked with (err, result). @@ -7329,7 +7329,7 @@ * in the collections in parallel. * The iteratee should complete with a boolean `result` value. * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon + * @param {Function} [callback] - A callback which is called as soon as any * iteratee returns `true`, or after all the iteratee functions have finished. * Result will be either `true` or `false` depending on the values of the async * tests. Invoked with (err, result). @@ -7351,7 +7351,7 @@ * in the collections in series. * The iteratee should complete with a boolean `result` value. * Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called as soon + * @param {Function} [callback] - A callback which is called as soon as any * iteratee returns `true`, or after all the iteratee functions have finished. * Result will be either `true` or `false` depending on the values of the async * tests. Invoked with (err, result). @@ -41538,7 +41538,7 @@ addUnderlyingListener( fullEventName, predicateEvent, - jsonPathCompiler( match[2] ) + jsonPathCompiler( match[2]) ); } } @@ -41566,7 +41566,7 @@ */ addListener = varArgs(function( eventId, parameters ){ - if( oboeApi[eventId] ) { + if( oboeApi[eventId]) { // for events added as .on(event, callback), if there is a // .event() equivalent with special behaviour , pass through diff --git a/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift b/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift index c03245a53..c09c6920a 100644 --- a/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift +++ b/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift @@ -84,7 +84,7 @@ public class ERC1155: IERC1155 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, id, value, data] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, id, value, data])! return tx } @@ -94,7 +94,7 @@ public class ERC1155: IERC1155 { self.transaction.to = self.address let tx = contract - .createWriteOperation("safeBatchTransferFrom", parameters: [originalOwner, to, ids, values, data] )! + .createWriteOperation("safeBatchTransferFrom", parameters: [originalOwner, to, ids, values, data])! return tx } @@ -121,7 +121,7 @@ public class ERC1155: IERC1155 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved, scope] )! + let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved, scope])! return tx } diff --git a/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift b/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift index 766a08c76..9e541edb2 100644 --- a/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift +++ b/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift @@ -121,7 +121,7 @@ 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] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value])! return tx } @@ -143,7 +143,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value])! return tx } @@ -165,7 +165,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value])! return tx } @@ -187,7 +187,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, value] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value])! return tx } @@ -220,7 +220,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, eValue, nValue] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, eValue, nValue])! return tx } @@ -242,7 +242,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("increaseAllowance", parameters: [spender, amount] )! + let tx = contract.createWriteOperation("increaseAllowance", parameters: [spender, amount])! return tx } @@ -264,7 +264,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("decreaseAllowance", parameters: [spender, amount, strict] )! + let tx = contract.createWriteOperation("decreaseAllowance", parameters: [spender, amount, strict])! return tx } @@ -273,7 +273,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setERC20ApproveChecking", parameters: [approveChecking] )! + let tx = contract.createWriteOperation("setERC20ApproveChecking", parameters: [approveChecking])! return tx } @@ -302,7 +302,7 @@ 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] )! + let tx = contract.createWriteOperation("transfer", parameters: [value])! return tx } @@ -323,7 +323,7 @@ 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] )! + let tx = contract.createWriteOperation("transferAndCall", parameters: [to, amount, data])! return tx } @@ -341,7 +341,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { self.transaction.to = self.address self.transaction.callOnBlock = .latest - let tx = contract.createWriteOperation("increaseNonce", parameters: [] )! + let tx = contract.createWriteOperation("increaseNonce", parameters: [])! return tx } @@ -365,7 +365,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] )! + let tx = contract.createWriteOperation("delegateTransferAndCall", parameters: [nonce, fee, gasAmount, to, amount, data, modeValue, v, r, s])! return tx } @@ -382,7 +382,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setupDirectDebit", parameters: [receiver, info] )! + let tx = contract.createWriteOperation("setupDirectDebit", parameters: [receiver, info])! return tx } @@ -391,7 +391,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("terminateDirectDebit", parameters: [receiver] )! + let tx = contract.createWriteOperation("terminateDirectDebit", parameters: [receiver])! return tx } @@ -400,7 +400,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("withdrawDirectDebit", parameters: [debtor] )! + let tx = contract.createWriteOperation("withdrawDirectDebit", parameters: [debtor])! return tx } @@ -409,7 +409,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("withdrawDirectDebit", parameters: [debtors, strict] )! + let tx = contract.createWriteOperation("withdrawDirectDebit", parameters: [debtors, strict])! return tx } } diff --git a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift index a700d0fbf..cb6641c3f 100644 --- a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift +++ b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift @@ -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] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value])! 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] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value])! return tx } @@ -162,7 +162,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value])! return tx } @@ -209,7 +209,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setDocument", parameters: [name, uri, documentHash] )! + let tx = contract.createWriteOperation("setDocument", parameters: [name, uri, documentHash])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("transferWithData", parameters: [to, value, data])! 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] )! + let tx = contract.createWriteOperation("transferFromWithData", parameters: [originalOwner, to, value, data])! 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] )! + let tx = contract.createWriteOperation("transferByPartition", parameters: [partition, to, value, data])! return tx } @@ -313,7 +313,7 @@ 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] )! + let tx = contract.createWriteOperation("operatorTransferByPartition", parameters: [partition, originalOwner, to, value, data, operatorData])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("controllerTransfer", parameters: [originalOwner, to, value, data, operatorData])! 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] )! + let tx = contract.createWriteOperation("controllerRedeem", parameters: [tokenHolder, value, data, operatorData])! 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] )! + let tx = contract.createWriteOperation("authorizeOperator", parameters: [user])! 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] )! + let tx = contract.createWriteOperation("revokeOperator", parameters: [user])! 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] )! + let tx = contract.createWriteOperation("authorizeOperatorByPartition", parameters: [partition, user])! return tx } @@ -401,7 +401,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("revokeOperatorByPartition", parameters: [partition, user] )! + let tx = contract.createWriteOperation("revokeOperatorByPartition", parameters: [partition, user])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("issue", parameters: [tokenHolder, value, data])! 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] )! + let tx = contract.createWriteOperation("issueByPartition", parameters: [partition, tokenHolder, value, data])! 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] )! + let tx = contract.createWriteOperation("redeem", parameters: [value, data])! 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] )! + let tx = contract.createWriteOperation("redeemFrom", parameters: [tokenHolder, value, data])! 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] )! + let tx = contract.createWriteOperation("redeemByPartition", parameters: [partition, value, data])! 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] )! + let tx = contract.createWriteOperation("operatorRedeemByPartition", parameters: [partition, tokenHolder, value, operatorData])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("setInterfaceImplementer", parameters: [addr, interfaceHash, implementer])! return tx } @@ -656,7 +656,7 @@ extension ERC1400: IERC777 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setManager", parameters: [addr, newManager] )! + let tx = contract.createWriteOperation("setManager", parameters: [addr, newManager])! return tx } @@ -673,7 +673,7 @@ extension ERC1400: IERC777 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId] )! + let tx = contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId])! return tx } @@ -707,7 +707,7 @@ extension ERC1400: IERC777 { self.transaction.to = self.address self.transaction.callOnBlock = .latest - let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] )! + let tx = contract.createWriteOperation("authorizeOperator", parameters: [user])! return tx } @@ -717,7 +717,7 @@ extension ERC1400: IERC777 { self.transaction.to = self.address self.transaction.callOnBlock = .latest - let tx = contract.createWriteOperation("revokeOperator", parameters: [user] )! + let tx = contract.createWriteOperation("revokeOperator", parameters: [user])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("send", parameters: [to, value, data])! 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] )! + let tx = contract.createWriteOperation("operatorSend", parameters: [originalOwner, to, value, data, operatorData])! 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] )! + let tx = contract.createWriteOperation("burn", parameters: [value, data])! 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] )! + let tx = contract.createWriteOperation("burn", parameters: [originalOwner, value, data, operatorData])! return tx } } diff --git a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift index f77011da9..8cdac8bec 100644 --- a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift +++ b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift @@ -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] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value])! 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] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value])! 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] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("transferByPartition", parameters: [partition, to, value, data])! 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] )! + let tx = contract.createWriteOperation("operatorTransferByPartition", parameters: [partition, originalOwner, to, value, data, operatorData])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("authorizeOperator", parameters: [user])! 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] )! + let tx = contract.createWriteOperation("revokeOperator", parameters: [user])! 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] )! + let tx = contract.createWriteOperation("authorizeOperatorByPartition", parameters: [partition, user])! 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] )! + let tx = contract.createWriteOperation("revokeOperatorByPartition", parameters: [partition, user])! 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] )! + let tx = contract.createWriteOperation("issueByPartition", parameters: [partition, tokenHolder, value, data])! 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] )! + let tx = contract.createWriteOperation("redeemByPartition", parameters: [partition, value, data])! 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] )! + let tx = contract.createWriteOperation("operatorRedeemByPartition", parameters: [partition, tokenHolder, value, operatorData])! return tx } } @@ -412,7 +412,7 @@ extension ERC1410: IERC777 { self.transaction.from = from - let tx = contract.createWriteOperation("setInterfaceImplementer", parameters: [addr, interfaceHash, implementer] )! + let tx = contract.createWriteOperation("setInterfaceImplementer", parameters: [addr, interfaceHash, implementer])! return tx } @@ -421,7 +421,7 @@ extension ERC1410: IERC777 { self.transaction.from = from - let tx = contract.createWriteOperation("setManager", parameters: [addr, newManager] )! + let tx = contract.createWriteOperation("setManager", parameters: [addr, newManager])! return tx } @@ -438,7 +438,7 @@ extension ERC1410: IERC777 { self.transaction.from = from - let tx = contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId] )! + let tx = contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId])! return tx } @@ -456,7 +456,7 @@ extension ERC1410: IERC777 { self.transaction.from = from self.transaction.callOnBlock = .latest - let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] )! + let tx = contract.createWriteOperation("authorizeOperator", parameters: [user])! return tx } @@ -466,7 +466,7 @@ extension ERC1410: IERC777 { self.transaction.from = from self.transaction.callOnBlock = .latest - let tx = contract.createWriteOperation("revokeOperator", parameters: [user] )! + let tx = contract.createWriteOperation("revokeOperator", parameters: [user])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("send", parameters: [to, value, data])! 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] )! + let tx = contract.createWriteOperation("operatorSend", parameters: [originalOwner, to, value, data, operatorData])! 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] )! + let tx = contract.createWriteOperation("burn", parameters: [value, data])! return tx } @@ -562,7 +562,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: [originalOwner, value, data, operatorData] )! + let tx = contract.createWriteOperation("burn", parameters: [originalOwner, value, data, operatorData])! return tx } diff --git a/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift b/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift index e02bd6b18..ee7cf108a 100644 --- a/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift +++ b/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift @@ -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] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value])! 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] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value])! 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] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value])! 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] )! + let tx = contract.createWriteOperation("transferWithData", parameters: [to, value, data])! return tx } @@ -212,7 +212,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFromWithData", parameters: [originalOwner, to, value, data] )! + let tx = contract.createWriteOperation("transferFromWithData", parameters: [originalOwner, to, value, data])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("issue", parameters: [tokenHolder, value, data])! 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] )! + let tx = contract.createWriteOperation("redeem", parameters: [value, data])! 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] )! + let tx = contract.createWriteOperation("redeemFrom", parameters: [tokenHolder, value, data])! return tx } diff --git a/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift index 40480c564..2482eebfc 100644 --- a/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift +++ b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift @@ -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] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value])! 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] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value])! return tx } @@ -120,7 +120,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value])! return tx } @@ -151,7 +151,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, value] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value])! return tx } diff --git a/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift b/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift index 6227c19c7..cab883a75 100644 --- a/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift +++ b/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift @@ -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] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value])! 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] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value])! return tx } @@ -123,7 +123,7 @@ public class ERC1643: IERC1643, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("setDocument", parameters: [name, uri, documentHash])! return tx } @@ -183,7 +183,7 @@ public class ERC1643: IERC1643, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("removeDocument", parameters: [name] )! + let tx = contract.createWriteOperation("removeDocument", parameters: [name])! return tx } diff --git a/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift b/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift index 7e4cdf580..ba5e98f5a 100644 --- a/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift +++ b/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift @@ -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] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value])! 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] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value])! return tx } @@ -122,7 +122,7 @@ public class ERC1644: IERC1644, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value])! return tx } @@ -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] )! + let tx = contract.createWriteOperation("controllerTransfer", parameters: [originalOwner, to, value, data, operatorData])! 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] )! + let tx = contract.createWriteOperation("controllerRedeem", parameters: [tokenHolder, value, data, operatorData])! return tx } } diff --git a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift index aa20848cb..3b7d9f3c3 100644 --- a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift +++ b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift @@ -80,7 +80,7 @@ public class ERC20: IERC20, 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] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value])! return tx } @@ -104,7 +104,7 @@ public class ERC20: IERC20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value])! return tx } @@ -128,7 +128,7 @@ public class ERC20: IERC20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value])! return tx } @@ -152,7 +152,7 @@ public class ERC20: IERC20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, value] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value])! return tx } diff --git a/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift b/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift index 2892ac4f0..9425185d9 100644 --- a/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift +++ b/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift @@ -132,7 +132,7 @@ public class ERC721: IERC721 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId])! return tx } @@ -141,7 +141,7 @@ public class ERC721: IERC721 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId])! return tx } @@ -150,7 +150,7 @@ public class ERC721: IERC721 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId])! return tx } @@ -159,7 +159,7 @@ public class ERC721: IERC721 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, data] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, data])! return tx } @@ -168,7 +168,7 @@ public class ERC721: IERC721 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("approve", parameters: [approved, tokenId] )! + let tx = contract.createWriteOperation("approve", parameters: [approved, tokenId])! return tx } @@ -177,7 +177,7 @@ public class ERC721: IERC721 { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved] )! + let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved])! return tx } diff --git a/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift b/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift index 941e68824..e730f58c7 100644 --- a/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift +++ b/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift @@ -114,7 +114,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId])! return tx } @@ -123,7 +123,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId])! return tx } @@ -132,7 +132,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId])! return tx } @@ -141,7 +141,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, data] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, data])! return tx } @@ -150,7 +150,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("approve", parameters: [approved, tokenId] )! + let tx = contract.createWriteOperation("approve", parameters: [approved, tokenId])! return tx } @@ -159,7 +159,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved] )! + let tx = contract.createWriteOperation("setApprovalForAll", parameters: [user, approved])! return tx } @@ -256,7 +256,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId, quantity] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, tokenId, quantity])! return tx } @@ -265,7 +265,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId, quantity] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, tokenId, quantity])! return tx } @@ -274,7 +274,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount])! return tx } @@ -283,7 +283,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount, data] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenId, amount, data])! return tx } @@ -292,7 +292,7 @@ public class ERC721x: IERC721x { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenIds, amounts, data] )! + let tx = contract.createWriteOperation("safeTransferFrom", parameters: [originalOwner, to, tokenIds, amounts, data])! return tx } } diff --git a/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift index 5e297f367..6333c3600 100644 --- a/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift +++ b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift @@ -105,7 +105,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("transfer", parameters: [to, value] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value])! return tx } @@ -127,7 +127,7 @@ public class ERC777: IERC777, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value])! return tx } @@ -149,7 +149,7 @@ public class ERC777: IERC777, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value])! return tx } @@ -168,7 +168,7 @@ public class ERC777: IERC777, ERC20BaseProperties { self.transaction.to = self.address self.transaction.callOnBlock = .latest - let tx = contract.createWriteOperation("authorizeOperator", parameters: [user] )! + let tx = contract.createWriteOperation("authorizeOperator", parameters: [user])! return tx } @@ -178,7 +178,7 @@ public class ERC777: IERC777, ERC20BaseProperties { self.transaction.to = self.address self.transaction.callOnBlock = .latest - let tx = contract.createWriteOperation("revokeOperator", parameters: [user] )! + let tx = contract.createWriteOperation("revokeOperator", parameters: [user])! return tx } @@ -207,7 +207,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("send", parameters: [to, value, data] )! + let tx = contract.createWriteOperation("send", parameters: [to, value, data])! return tx } @@ -228,7 +228,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] )! + let tx = contract.createWriteOperation("operatorSend", parameters: [originalOwner, to, value, data, operatorData])! return tx } @@ -249,7 +249,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("burn", parameters: [value, data] )! + let tx = contract.createWriteOperation("burn", parameters: [value, data])! return tx } @@ -270,7 +270,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("burn", parameters: [originalOwner, value, data, operatorData] )! + let tx = contract.createWriteOperation("burn", parameters: [originalOwner, value, data, operatorData])! return tx } @@ -295,7 +295,7 @@ public class ERC777: IERC777, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setInterfaceImplementer", parameters: [addr, interfaceHash, implementer] )! + let tx = contract.createWriteOperation("setInterfaceImplementer", parameters: [addr, interfaceHash, implementer])! return tx } @@ -304,7 +304,7 @@ public class ERC777: IERC777, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("setManager", parameters: [addr, newManager] )! + let tx = contract.createWriteOperation("setManager", parameters: [addr, newManager])! return tx } @@ -321,7 +321,7 @@ public class ERC777: IERC777, ERC20BaseProperties { self.transaction.from = from self.transaction.to = self.address - let tx = contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId] )! + let tx = contract.createWriteOperation("updateERC165Cache", parameters: [contract, interfaceId])! return tx } @@ -343,7 +343,7 @@ public class ERC777: IERC777, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, value] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value])! return tx } diff --git a/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift b/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift index 4ff2e9c5f..f687c0a32 100644 --- a/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift +++ b/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift @@ -63,7 +63,7 @@ public class ERC888: IERC888, 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] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value])! return tx } diff --git a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift index 66cfc8dd6..8c2f82e68 100644 --- a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift +++ b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift @@ -76,7 +76,7 @@ public class ST20: IST20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("verifyTransfer", parameters: [originalOwner, to, value] )! + let tx = contract.createWriteOperation("verifyTransfer", parameters: [originalOwner, to, value])! return tx } @@ -99,7 +99,7 @@ public class ST20: IST20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("mint", parameters: [investor, value] )! + let tx = contract.createWriteOperation("mint", parameters: [investor, value])! return tx } @@ -121,7 +121,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("burn", parameters: [value] )! + let tx = contract.createWriteOperation("burn", parameters: [value])! return tx } @@ -159,7 +159,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] )! + let tx = contract.createWriteOperation("transfer", parameters: [to, value])! return tx } @@ -182,7 +182,7 @@ public class ST20: IST20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value] )! + let tx = contract.createWriteOperation("transferFrom", parameters: [originalOwner, to, value])! return tx } @@ -205,7 +205,7 @@ public class ST20: IST20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("setAllowance", parameters: [to, value] )! + let tx = contract.createWriteOperation("setAllowance", parameters: [to, value])! return tx } @@ -228,7 +228,7 @@ public class ST20: IST20, ERC20BaseProperties { throw Web3Error.inputError(desc: "Can not parse inputted amount") } - let tx = contract.createWriteOperation("approve", parameters: [spender, value] )! + let tx = contract.createWriteOperation("approve", parameters: [spender, value])! return tx } From 15f777023eaea683fd13fbb511c18c998bb5a983 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Sat, 14 Jan 2023 13:48:20 +0200 Subject: [PATCH 04/14] fix: Networks.fromInt must not return optional --- Sources/Web3Core/Structure/Event+Protocol.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Web3Core/Structure/Event+Protocol.swift b/Sources/Web3Core/Structure/Event+Protocol.swift index 87f361a08..aef5e3cd2 100755 --- a/Sources/Web3Core/Structure/Event+Protocol.swift +++ b/Sources/Web3Core/Structure/Event+Protocol.swift @@ -77,7 +77,7 @@ public enum Networks { static let allValues = [Mainnet, Ropsten, Kovan, Rinkeby] - public static func fromInt(_ networkID: UInt) -> Networks? { + public static func fromInt(_ networkID: UInt) -> Networks { switch networkID { case 1: return Networks.Mainnet From a49f771e4939e70d3ff2c794a3ba663ef09cba22 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Sat, 14 Jan 2023 13:50:15 +0200 Subject: [PATCH 05/14] fix: EIP681 - when parsing arguments chain ID must be defaulted to Mainnet instead of 0 --- Sources/web3swift/Utils/EIP/EIP681.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/web3swift/Utils/EIP/EIP681.swift b/Sources/web3swift/Utils/EIP/EIP681.swift index 7dde9af76..730085e6a 100755 --- a/Sources/web3swift/Utils/EIP/EIP681.swift +++ b/Sources/web3swift/Utils/EIP/EIP681.swift @@ -289,7 +289,7 @@ extension Web3 { guard let rawValue = comp.value, let functionArgument = await parseFunctionArgument(inputType, rawValue.trimmingCharacters(in: .whitespacesAndNewlines), - chainID: code.chainID ?? 0, + chainID: code.chainID, inputNumber: inputNumber) else { continue } @@ -348,7 +348,7 @@ extension Web3 { private static func parseFunctionArgument(_ inputType: ABI.Element.ParameterType, _ rawValue: String, - chainID: BigUInt, + chainID: BigUInt? = Networks.Mainnet.chainID, inputNumber: Int) async -> FunctionArgument? { var nativeValue: Any? switch inputType { @@ -359,7 +359,7 @@ extension Web3 { nativeValue = ethereumAddress case .ensAddress(let ens): do { - let web = await Web3(provider: InfuraProvider(Networks.fromInt(UInt(chainID)) ?? Networks.Mainnet)!) + let web = await Web3(provider: InfuraProvider(chainID == nil ? .Mainnet : .fromInt(UInt(chainID!)))!) let ensModel = ENS(web3: web) try await ensModel?.setENSResolver(withDomain: ens) let address = try await ensModel?.getAddress(forNode: ens) From af664691becb69b01a639c1a741e83d3d186d0c6 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Sat, 14 Jan 2023 16:44:37 +0200 Subject: [PATCH 06/14] chore: removed redundant `parameters: []` in read operation --- Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift | 2 +- Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift | 2 +- Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift | 4 ++-- Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift | 4 ++-- Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift | 4 ++-- Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift | 2 +- Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift | 4 ++-- Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift | 4 ++-- Sources/web3swift/Tokens/ST20/Web3+ST20.swift | 2 +- Sources/web3swift/Utils/ENS/ENSReverseRegistrar.swift | 2 +- Tests/web3swiftTests/localTests/UncategorizedTests.swift | 2 +- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift b/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift index 2e731cad3..9c2d5ed01 100644 --- a/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift +++ b/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift @@ -69,7 +69,7 @@ public class ERC1155: IERC1155 { } guard contract.contract.address != nil else {return} - guard let tokenIdPromise = try await contract.createReadOperation("id", parameters: [])?.callContractMethod() else {return} + guard let tokenIdPromise = try await contract.createReadOperation("id")?.callContractMethod() else {return} guard let tokenId = tokenIdPromise["0"] as? BigUInt else {return} self._tokenId = tokenId diff --git a/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift b/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift index 714d52a42..876af62e0 100644 --- a/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift +++ b/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift @@ -298,7 +298,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { func increaseNonce(from: EthereumAddress) throws -> WriteOperation { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) - let tx = contract.createWriteOperation("increaseNonce", parameters: [])! + let tx = contract.createWriteOperation("increaseNonce")! return tx } diff --git a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift index f099c2de1..1ba479a6f 100644 --- a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift +++ b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift @@ -596,14 +596,14 @@ extension ERC1400: IERC777 { } public func getGranularity() async throws -> BigUInt { - let result = try await contract.createReadOperation("granularity", parameters: [])!.callContractMethod() + let result = try await contract.createReadOperation("granularity")!.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 result = try await contract.createReadOperation("defaultOperators", parameters: [])!.callContractMethod() + let result = try await contract.createReadOperation("defaultOperators")!.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/ERC1410/Web3+ERC1410.swift b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift index 5b5f1b886..9e0b4acfb 100644 --- a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift +++ b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift @@ -474,14 +474,14 @@ extension ERC1410: IERC777 { } public func getGranularity() async throws -> BigUInt { - let result = try await contract.createReadOperation("granularity", parameters: [])!.callContractMethod() + let result = try await contract.createReadOperation("granularity")!.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 result = try await contract.createReadOperation("defaultOperators", parameters: [])!.callContractMethod() + let result = try await contract.createReadOperation("defaultOperators")!.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/ERC1633/Web3+ERC1633.swift b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift index 19f8a6f6e..ec98b95c8 100644 --- a/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift +++ b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift @@ -138,14 +138,14 @@ public class ERC1633: IERC1633, ERC20BaseProperties { } func parentToken() async throws -> EthereumAddress { - let result = try await contract.createReadOperation("parentToken", parameters: [])!.callContractMethod() + let result = try await contract.createReadOperation("parentToken")!.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 { - let result = try await contract.createReadOperation("parentTokenId", parameters: [])!.callContractMethod() + let result = try await contract.createReadOperation("parentTokenId")!.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/ERC1643/Web3+ERC1643.swift b/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift index e1fc3828d..2cb0ec869 100644 --- a/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift +++ b/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift @@ -161,7 +161,7 @@ public class ERC1643: IERC1643, ERC20BaseProperties { } public func getAllDocuments() async throws -> [Data] { - let result = try await contract.createReadOperation("getAllDocuments", parameters: [])!.callContractMethod() + let result = try await contract.createReadOperation("getAllDocuments")!.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/ERC721x/Web3+ERC721x.swift b/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift index 62e8d9297..bce547e12 100644 --- a/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift +++ b/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift @@ -76,7 +76,7 @@ public class ERC721x: IERC721x { guard contract.contract.address != nil else {return} transaction.callOnBlock = .latest - guard let tokenIdPromise = try await contract.createReadOperation("tokenId", parameters: [])?.callContractMethod() else {return} + guard let tokenIdPromise = try await contract.createReadOperation("tokenId")?.callContractMethod() else {return} guard let tokenId = tokenIdPromise["0"] as? BigUInt else {return} self._tokenId = tokenId @@ -201,7 +201,7 @@ public class ERC721x: IERC721x { } func implementsERC721X() async throws -> Bool { - let result = try await contract.createReadOperation("implementsERC721X", parameters: [])!.callContractMethod() + let result = try await contract.createReadOperation("implementsERC721X")!.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/ERC777/Web3+ERC777.swift b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift index 81f33ae31..c9a5fd125 100644 --- a/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift +++ b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift @@ -57,14 +57,14 @@ public class ERC777: IERC777, ERC20BaseProperties { } public func getGranularity() async throws -> BigUInt { - let result = try await contract.createReadOperation("granularity", parameters: [])!.callContractMethod() + let result = try await contract.createReadOperation("granularity")!.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 result = try await contract.createReadOperation("defaultOperators", parameters: [])!.callContractMethod() + let result = try await contract.createReadOperation("defaultOperators")!.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/ST20/Web3+ST20.swift b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift index 645daf42f..41b5ded7c 100644 --- a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift +++ b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift @@ -50,7 +50,7 @@ public class ST20: IST20, ERC20BaseProperties { } func tokenDetails() async throws -> [UInt32] { - let result = try await contract.createReadOperation("tokenDetails", parameters: [])!.callContractMethod() + let result = try await contract.createReadOperation("tokenDetails")!.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 diff --git a/Sources/web3swift/Utils/ENS/ENSReverseRegistrar.swift b/Sources/web3swift/Utils/ENS/ENSReverseRegistrar.swift index 651f835bb..0fb8ef20a 100644 --- a/Sources/web3swift/Utils/ENS/ENSReverseRegistrar.swift +++ b/Sources/web3swift/Utils/ENS/ENSReverseRegistrar.swift @@ -66,7 +66,7 @@ public extension ENS { } public func getDefaultResolver() async throws -> EthereumAddress { - guard let transaction = self.contract.createReadOperation("defaultResolver", parameters: []) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createReadOperation("defaultResolver") 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")} diff --git a/Tests/web3swiftTests/localTests/UncategorizedTests.swift b/Tests/web3swiftTests/localTests/UncategorizedTests.swift index 2dbebb775..ccd1056b1 100755 --- a/Tests/web3swiftTests/localTests/UncategorizedTests.swift +++ b/Tests/web3swiftTests/localTests/UncategorizedTests.swift @@ -120,7 +120,7 @@ class UncategorizedTests: XCTestCase { .callContractMethod() let totalUsers = try await contract! - .createReadOperation("totalUsers", parameters: [])? + .createReadOperation("totalUsers")? .callContractMethod() let user = try await contract! From 922da4148223ee5d95405a1e800969784de28268 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Sat, 14 Jan 2023 16:47:58 +0200 Subject: [PATCH 07/14] fix: spacings --- Sources/web3swift/Browser/browser.js | 5 ++--- Tests/web3swiftTests/localTests/EIP1559BlockTests.swift | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/web3swift/Browser/browser.js b/Sources/web3swift/Browser/browser.js index ea4090662..8cffd18b1 100644 --- a/Sources/web3swift/Browser/browser.js +++ b/Sources/web3swift/Browser/browser.js @@ -41538,7 +41538,7 @@ addUnderlyingListener( fullEventName, predicateEvent, - jsonPathCompiler( match[2]) + jsonPathCompiler( match[2] ) ); } } @@ -41566,7 +41566,7 @@ */ addListener = varArgs(function( eventId, parameters ){ - if( oboeApi[eventId]) { + if( oboeApi[eventId] ) { // for events added as .on(event, callback), if there is a // .event() equivalent with special behaviour , pass through @@ -68348,4 +68348,3 @@ //# sourceURL=/Users/alexvlasov/Blockchain/web3swift/web3swiftJSProxy/wk.bridge.js },{}]},{},[1]); - diff --git a/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift b/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift index e41c55e3f..a729ff117 100644 --- a/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift +++ b/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift @@ -18,7 +18,7 @@ class EIP1559BlockTests: LocalTestCase { logsBloom: EthereumBloomFilter(Data(from: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")!), // "logsBloom": transactionsRoot: Data(from: "0x3a1b03875115b79539e5bd33fb00d8f7b7cd61929d5a3c574f507b8acf415bee")!, // "transactionsRoot": stateRoot: Data(from: "0xf1133199d44695dfa8fd1bcfe424d82854b5cebef75bddd7e40ea94cda515bcb")!, // "stateRoot": - miner: EthereumAddress( Data(from: "0x8888f1f195afa192cfee860698584c030f4c9db1")!)!, // "miner": + miner: EthereumAddress(Data(from: "0x8888f1f195afa192cfee860698584c030f4c9db1")!)!, // "miner": difficulty: BigUInt(21345678965432), // "difficulty": totalDifficulty: BigUInt(324567845321), // "totalDifficulty": size: BigUInt(616), // "size": From 03f139523ccda57be310edbea23cea31557fa75c Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Sat, 14 Jan 2023 18:06:27 +0200 Subject: [PATCH 08/14] chore: removed spacing in `" )` --- .../Tokens/ERC1376/Web3+ERC1376.swift | 20 ++++---- .../Tokens/ERC1400/Web3+ERC1400.swift | 46 +++++++++---------- .../Tokens/ERC1410/Web3+ERC1410.swift | 28 +++++------ .../Tokens/ERC1594/Web3+ERC1594.swift | 22 ++++----- .../Tokens/ERC1633/Web3+ERC1633.swift | 8 ++-- .../Tokens/ERC1643/Web3+ERC1643.swift | 8 ++-- .../Tokens/ERC1644/Web3+ERC1644.swift | 12 ++--- .../web3swift/Tokens/ERC20/Web3+ERC20.swift | 8 ++-- .../web3swift/Tokens/ERC777/Web3+ERC777.swift | 16 +++---- .../web3swift/Tokens/ERC888/Web3+ERC888.swift | 2 +- Sources/web3swift/Tokens/ST20/Web3+ST20.swift | 14 +++--- .../Tokens/ST20/Web3+SecurityToken.swift | 4 +- 12 files changed, 94 insertions(+), 94 deletions(-) diff --git a/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift b/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift index 876af62e0..80a4f796b 100644 --- a/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift +++ b/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift @@ -106,7 +106,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -124,7 +124,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -142,7 +142,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -160,7 +160,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -185,7 +185,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -206,7 +206,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -224,7 +224,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -256,7 +256,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -274,7 +274,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -306,7 +306,7 @@ public class ERC1376: IERC1376, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} diff --git a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift index 1ba479a6f..df0874a93 100644 --- a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift +++ b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift @@ -103,7 +103,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -122,7 +122,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -141,7 +141,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -167,7 +167,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -214,7 +214,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -233,7 +233,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -252,7 +252,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -271,7 +271,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -297,7 +297,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -316,7 +316,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -380,7 +380,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -399,7 +399,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -418,7 +418,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -437,7 +437,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -456,7 +456,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -475,7 +475,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -492,7 +492,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { public func canTransfer(to: EthereumAddress, amount: String, data: [UInt8]) async throws -> ([UInt8], Data) { // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + 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")} @@ -511,7 +511,7 @@ public class ERC1400: IERC1400, ERC20BaseProperties { public func canTransferFrom(originalOwner: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) async throws -> ([UInt8], Data) { // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + 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")} @@ -530,7 +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) { // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + 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")} @@ -634,7 +634,7 @@ extension ERC1400: IERC777 { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -653,7 +653,7 @@ extension ERC1400: IERC777 { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -672,7 +672,7 @@ extension ERC1400: IERC777 { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -691,7 +691,7 @@ extension ERC1400: IERC777 { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} diff --git a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift index 9e0b4acfb..ed947f435 100644 --- a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift +++ b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift @@ -81,7 +81,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -100,7 +100,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -119,7 +119,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -145,7 +145,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -179,7 +179,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -198,7 +198,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -215,7 +215,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { public func canTransferByPartition(originalOwner: EthereumAddress, to: EthereumAddress, partition: Data, amount: String, data: [UInt8]) async throws -> ([UInt8], Data, Data) { // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + 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")} @@ -274,7 +274,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -293,7 +293,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -312,7 +312,7 @@ public class ERC1410: IERC1410, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -401,7 +401,7 @@ extension ERC1410: IERC777 { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -420,7 +420,7 @@ extension ERC1410: IERC777 { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -439,7 +439,7 @@ extension ERC1410: IERC777 { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -458,7 +458,7 @@ extension ERC1410: IERC777 { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} diff --git a/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift b/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift index 931c7aef2..3e83074d8 100644 --- a/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift +++ b/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift @@ -70,7 +70,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { public func transfer(from: EthereumAddress, to: EthereumAddress, amount: String) async throws -> WriteOperation { updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + 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")} @@ -89,7 +89,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -108,7 +108,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -134,7 +134,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -154,7 +154,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -173,7 +173,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -199,7 +199,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -218,7 +218,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -237,7 +237,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -254,7 +254,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { public func canTransfer(to: EthereumAddress, amount: String, data: [UInt8]) async throws -> ([UInt8], Data) { // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + 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")} @@ -273,7 +273,7 @@ public class ERC1594: IERC1594, ERC20BaseProperties { public func canTransferFrom(originalOwner: EthereumAddress, to: EthereumAddress, amount: String, data: [UInt8]) async throws -> ([UInt8], Data) { // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + 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")} diff --git a/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift index ec98b95c8..e7551fce1 100644 --- a/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift +++ b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift @@ -58,7 +58,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -77,7 +77,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -96,7 +96,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -122,7 +122,7 @@ public class ERC1633: IERC1633, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} diff --git a/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift b/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift index 2cb0ec869..9e0c3fdec 100644 --- a/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift +++ b/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift @@ -61,7 +61,7 @@ public class ERC1643: IERC1643, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -80,7 +80,7 @@ public class ERC1643: IERC1643, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -99,7 +99,7 @@ public class ERC1643: IERC1643, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -125,7 +125,7 @@ public class ERC1643: IERC1643, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} diff --git a/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift b/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift index c1172dee2..1acaf69a1 100644 --- a/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift +++ b/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift @@ -60,7 +60,7 @@ public class ERC1644: IERC1644, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -79,7 +79,7 @@ public class ERC1644: IERC1644, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -98,7 +98,7 @@ public class ERC1644: IERC1644, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -124,7 +124,7 @@ public class ERC1644: IERC1644, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -151,7 +151,7 @@ public class ERC1644: IERC1644, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -170,7 +170,7 @@ public class ERC1644: IERC1644, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} diff --git a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift index 8e5336ec9..a3426f754 100644 --- a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift +++ b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift @@ -64,7 +64,7 @@ public class ERC20: IERC20, ERC20BaseProperties { // get the decimals manually let callResult = try await contract - .createReadOperation("decimals" )! + .createReadOperation("decimals")! .callContractMethod() var decimals = BigUInt(0) guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { @@ -88,7 +88,7 @@ public class ERC20: IERC20, ERC20BaseProperties { // get the decimals manually let callResult = try await contract - .createReadOperation("decimals" )! + .createReadOperation("decimals")! .callContractMethod() var decimals = BigUInt(0) guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { @@ -112,7 +112,7 @@ public class ERC20: IERC20, ERC20BaseProperties { // get the decimals manually let callResult = try await contract - .createReadOperation("decimals" )! + .createReadOperation("decimals")! .callContractMethod() var decimals = BigUInt(0) guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { @@ -136,7 +136,7 @@ public class ERC20: IERC20, ERC20BaseProperties { // get the decimals manually let callResult = try await contract - .createReadOperation("decimals" )! + .createReadOperation("decimals")! .callContractMethod() var decimals = BigUInt(0) guard let dec = callResult["0"], let decTyped = dec as? BigUInt else { diff --git a/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift index c9a5fd125..f7360d913 100644 --- a/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift +++ b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift @@ -88,7 +88,7 @@ public class ERC777: IERC777, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -106,7 +106,7 @@ public class ERC777: IERC777, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -125,7 +125,7 @@ public class ERC777: IERC777, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -172,7 +172,7 @@ public class ERC777: IERC777, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -190,7 +190,7 @@ public class ERC777: IERC777, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -208,7 +208,7 @@ public class ERC777: IERC777, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -226,7 +226,7 @@ public class ERC777: IERC777, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -284,7 +284,7 @@ public class ERC777: IERC777, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} diff --git a/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift b/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift index 77c0047b5..1f462b08e 100644 --- a/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift +++ b/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift @@ -51,7 +51,7 @@ public class ERC888: IERC888, ERC20BaseProperties { transaction.callOnBlock = .latest contract.transaction = transaction // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + 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")} diff --git a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift index 41b5ded7c..52f603380 100644 --- a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift +++ b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift @@ -60,7 +60,7 @@ public class ST20: IST20, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -79,7 +79,7 @@ public class ST20: IST20, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -98,7 +98,7 @@ public class ST20: IST20, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -131,7 +131,7 @@ public class ST20: IST20, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -150,7 +150,7 @@ public class ST20: IST20, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -169,7 +169,7 @@ public class ST20: IST20, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} @@ -188,7 +188,7 @@ public class ST20: IST20, ERC20BaseProperties { transaction.callOnBlock = .latest updateTransactionAndContract(from: from) // get the decimals manually - let callResult = try await contract.createReadOperation("decimals" )!.callContractMethod() + let callResult = try await contract.createReadOperation("decimals")!.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")} diff --git a/Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift b/Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift index 73d6bdde6..b7c4a513e 100644 --- a/Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift +++ b/Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift @@ -256,7 +256,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { transaction.callOnBlock = .latest contract.transaction = transaction - return contract.createWriteOperation("renounceOwnership" )! + return contract.createWriteOperation("renounceOwnership")! } @@ -341,7 +341,7 @@ public class SecurityToken: ISecurityToken, ERC20BaseProperties { transaction.callOnBlock = .latest contract.transaction = transaction - return contract.createWriteOperation("createCheckpoint" )! + return contract.createWriteOperation("createCheckpoint")! } From 8e925660cf4fa286989da3cc148f42ef0c770538 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Sat, 14 Jan 2023 18:15:22 +0200 Subject: [PATCH 09/14] fix: removed as AnyObject from ENS related code --- Sources/web3swift/Utils/ENS/ENSBaseRegistrar.swift | 12 ++++++------ Sources/web3swift/Utils/ENS/ENSRegistry.swift | 6 +++--- .../web3swift/Utils/ENS/ENSReverseRegistrar.swift | 2 +- .../web3swift/Utils/ENS/ETHRegistrarController.swift | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/web3swift/Utils/ENS/ENSBaseRegistrar.swift b/Sources/web3swift/Utils/ENS/ENSBaseRegistrar.swift index dfcdedf2f..6722bc736 100644 --- a/Sources/web3swift/Utils/ENS/ENSBaseRegistrar.swift +++ b/Sources/web3swift/Utils/ENS/ENSBaseRegistrar.swift @@ -37,7 +37,7 @@ public extension ENS { defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("addController", parameters: [controllerAddress as AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("addController", parameters: [controllerAddress]) else {throw Web3Error.transactionSerializationError} return transaction } @@ -47,7 +47,7 @@ public extension ENS { defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("removeController", parameters: [controllerAddress as AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("removeController", parameters: [controllerAddress]) else {throw Web3Error.transactionSerializationError} return transaction } @@ -57,13 +57,13 @@ public extension ENS { defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("setResolver", parameters: [resolverAddress as AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("setResolver", parameters: [resolverAddress]) 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]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createReadOperation("nameExpires", parameters: [name]) 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")} @@ -72,7 +72,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]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createReadOperation("available", parameters: [name]) 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")} @@ -83,7 +83,7 @@ public extension ENS { defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("reclaim", parameters: [record as AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("reclaim", parameters: [record]) else {throw Web3Error.transactionSerializationError} return transaction } diff --git a/Sources/web3swift/Utils/ENS/ENSRegistry.swift b/Sources/web3swift/Utils/ENS/ENSRegistry.swift index ce69986cd..bc5543f4f 100644 --- a/Sources/web3swift/Utils/ENS/ENSRegistry.swift +++ b/Sources/web3swift/Utils/ENS/ENSRegistry.swift @@ -49,7 +49,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]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.registryContract.createReadOperation("owner", parameters: [nameHash]) 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")} @@ -59,7 +59,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]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.registryContract.createReadOperation("resolver", parameters: [nameHash]) 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")} @@ -69,7 +69,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]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.registryContract.createReadOperation("ttl", parameters: [nameHash]) 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")} diff --git a/Sources/web3swift/Utils/ENS/ENSReverseRegistrar.swift b/Sources/web3swift/Utils/ENS/ENSReverseRegistrar.swift index 0fb8ef20a..7ec38529b 100644 --- a/Sources/web3swift/Utils/ENS/ENSReverseRegistrar.swift +++ b/Sources/web3swift/Utils/ENS/ENSReverseRegistrar.swift @@ -34,7 +34,7 @@ public extension ENS { defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("claim", parameters: [owner as AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("claim", parameters: [owner]) else {throw Web3Error.transactionSerializationError} return transaction } diff --git a/Sources/web3swift/Utils/ENS/ETHRegistrarController.swift b/Sources/web3swift/Utils/ENS/ETHRegistrarController.swift index 34f1bc747..602d5902c 100644 --- a/Sources/web3swift/Utils/ENS/ETHRegistrarController.swift +++ b/Sources/web3swift/Utils/ENS/ETHRegistrarController.swift @@ -45,7 +45,7 @@ public extension ENS { } public func isNameAvailable(name: String) async throws -> Bool { - guard let transaction = self.contract.createReadOperation("available", parameters: [name as AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createReadOperation("available", parameters: [name]) 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 @@ -62,7 +62,7 @@ public extension ENS { defaultOptions.from = from defaultOptions.to = self.address - guard let transaction = self.contract.createWriteOperation("commit", parameters: [commitment as AnyObject]) else {throw Web3Error.transactionSerializationError} + guard let transaction = self.contract.createWriteOperation("commit", parameters: [commitment]) else {throw Web3Error.transactionSerializationError} return transaction } From c448970d1055b287fa7df45ccab63a82ed974c94 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Sat, 14 Jan 2023 18:15:49 +0200 Subject: [PATCH 10/14] chore: replaced [Any]() with [] for default parameter value --- Sources/web3swift/Web3/Web3+Contract.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/web3swift/Web3/Web3+Contract.swift b/Sources/web3swift/Web3/Web3+Contract.swift index da59285ed..300ac7678 100755 --- a/Sources/web3swift/Web3/Web3+Contract.swift +++ b/Sources/web3swift/Web3/Web3+Contract.swift @@ -83,7 +83,7 @@ extension Web3 { /// Elements of "parameters" can be other arrays or instances of String, Data, BigInt, BigUInt, Int or EthereumAddress. /// /// Returns a "Transaction intermediate" object. - public func createReadOperation(_ method: String = "fallback", parameters: [Any] = [Any](), extraData: Data = Data()) -> ReadOperation? { + public func createReadOperation(_ method: String = "fallback", parameters: [Any] = [], extraData: Data = Data()) -> ReadOperation? { // MARK: - Encoding ABI Data flow guard let data = contract.method(method, parameters: parameters, extraData: extraData) else { return nil } @@ -104,7 +104,7 @@ extension Web3 { /// Elements of "parameters" can be other arrays or instances of String, Data, BigInt, BigUInt, Int or EthereumAddress. /// /// Returns a "Transaction intermediate" object. - public func createWriteOperation(_ method: String = "fallback", parameters: [Any] = [Any](), extraData: Data = Data()) -> WriteOperation? { + public func createWriteOperation(_ method: String = "fallback", parameters: [Any] = [], extraData: Data = Data()) -> WriteOperation? { guard let data = contract.method(method, parameters: parameters, extraData: extraData) else { return nil } transaction.data = data if let network = web3.provider.network { From 2bd330342ff96ecd4df94349190f11a4aea8aad9 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Sat, 14 Jan 2023 18:16:31 +0200 Subject: [PATCH 11/14] chore: test refactoring - checking for nullability by using XCTAssertNotNil --- Tests/web3swiftTests/localTests/ERC20Tests.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/web3swiftTests/localTests/ERC20Tests.swift b/Tests/web3swiftTests/localTests/ERC20Tests.swift index f79ae933f..f569640b5 100755 --- a/Tests/web3swiftTests/localTests/ERC20Tests.swift +++ b/Tests/web3swiftTests/localTests/ERC20Tests.swift @@ -26,10 +26,10 @@ class ERC20Tests: LocalTestCase { let addressOfUser = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")! let contract = web3.contract(Web3.Utils.erc20ABI, at: receipt.contractAddress!, abiVersion: 2)! - guard let readTX = contract.createReadOperation("balanceOf", parameters: [addressOfUser]) else {return XCTFail()} + guard let readTX = contract.createReadOperation("balanceOf", parameters: [addressOfUser]) else { return XCTFail() } readTX.transaction.from = addressOfUser - let tokenBalance = try await readTX.callContractMethod() - guard let bal = tokenBalance["0"] as? BigUInt else {return XCTFail()} + let tokenBalanceResponse = try await readTX.callContractMethod() + XCTAssertNotNil(tokenBalanceResponse["0"] as? BigUInt) } // FIXME: Make me work From ed43d2db481264e07544535db2a5f64211e25c67 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Sun, 15 Jan 2023 00:19:58 +0200 Subject: [PATCH 12/14] fix: RLP func encode for single value has named parameter It fixes the issue when trying to call func element() with [Any]. --- Sources/Web3Core/RLP/RLP.swift | 5 ++--- Tests/web3swiftTests/localTests/TransactionsTests.swift | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Sources/Web3Core/RLP/RLP.swift b/Sources/Web3Core/RLP/RLP.swift index 584f2914c..af5d8b29e 100755 --- a/Sources/Web3Core/RLP/RLP.swift +++ b/Sources/Web3Core/RLP/RLP.swift @@ -18,10 +18,9 @@ public struct RLP { static var length56 = BigUInt(UInt(56)) static var lengthMax = (BigUInt(UInt(1)) << 256) - internal static func encode(_ element: Any?) -> Data? { + internal static func encode(element: Any?) -> Data? { if let string = element as? String { return encode(string) - } else if let data = element as? Data { return encode(data) } else if let biguint = element as? BigUInt { @@ -115,7 +114,7 @@ public struct RLP { internal static func encode(_ elements: [Any?]) -> Data? { var encodedData = Data() for e in elements { - if let encoded = encode(e) { + if let encoded = encode(element: e) { encodedData.append(encoded) } else { guard let asArray = e as? [Any] else {return nil} diff --git a/Tests/web3swiftTests/localTests/TransactionsTests.swift b/Tests/web3swiftTests/localTests/TransactionsTests.swift index 99d102032..8471bbc1d 100755 --- a/Tests/web3swiftTests/localTests/TransactionsTests.swift +++ b/Tests/web3swiftTests/localTests/TransactionsTests.swift @@ -471,7 +471,6 @@ class TransactionsTests: XCTestCase { // check that we recovered the address correctly XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch") } catch { - return XCTFail(String(describing: error)) } } From a17a5bb7782e756b8db9ecce72718f133f0346a4 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Sun, 15 Jan 2023 01:00:55 +0200 Subject: [PATCH 13/14] fix: ENS parsing requires chainID if an ENS address is expected to be requested/decoded - we do not assume that client is using Ethereum Mainnet! According to EIP-681: chain_id is optional and contains the decimal chain ID, such that transactions on various test- and private networks can be requested. If no chain_id is present, the client's current network setting remains effective. In our case if no chainID is present we cannot validate ENS address and will not attempt to guess the network. --- Sources/web3swift/Utils/EIP/EIP681.swift | 5 +++-- Tests/web3swiftTests/localTests/EIP681Tests.swift | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Sources/web3swift/Utils/EIP/EIP681.swift b/Sources/web3swift/Utils/EIP/EIP681.swift index 730085e6a..2138da9d7 100755 --- a/Sources/web3swift/Utils/EIP/EIP681.swift +++ b/Sources/web3swift/Utils/EIP/EIP681.swift @@ -348,7 +348,7 @@ extension Web3 { private static func parseFunctionArgument(_ inputType: ABI.Element.ParameterType, _ rawValue: String, - chainID: BigUInt? = Networks.Mainnet.chainID, + chainID: BigUInt?, inputNumber: Int) async -> FunctionArgument? { var nativeValue: Any? switch inputType { @@ -358,8 +358,9 @@ extension Web3 { case .ethereumAddress(let ethereumAddress): nativeValue = ethereumAddress case .ensAddress(let ens): + guard let chainID = chainID else { return nil } do { - let web = await Web3(provider: InfuraProvider(chainID == nil ? .Mainnet : .fromInt(UInt(chainID!)))!) + let web = await Web3(provider: InfuraProvider(.fromInt(UInt(chainID)))!) let ensModel = ENS(web3: web) try await ensModel?.setENSResolver(withDomain: ens) let address = try await ensModel?.getAddress(forNode: ens) diff --git a/Tests/web3swiftTests/localTests/EIP681Tests.swift b/Tests/web3swiftTests/localTests/EIP681Tests.swift index cabd53fa2..1fbd027fc 100755 --- a/Tests/web3swiftTests/localTests/EIP681Tests.swift +++ b/Tests/web3swiftTests/localTests/EIP681Tests.swift @@ -83,7 +83,7 @@ class EIP681Tests: XCTestCase { func testENSParsing() async throws { let testAddress = "somename.eth" - let eip681Code = await Web3.EIP681CodeParser.parse("ethereum:\(testAddress)/transfer?address=somename.eth&uint256=1") + let eip681Code = await Web3.EIP681CodeParser.parse("ethereum:\(testAddress)@1/transfer?address=somename.eth&uint256=1") XCTAssert(eip681Code != nil) guard let eip681Code = eip681Code else { return } switch eip681Code.targetAddress { @@ -110,7 +110,7 @@ class EIP681Tests: XCTestCase { func testENSParsingWithEncoding() async throws { let testAddress = "somename.eth" - let eip681Code = await Web3.EIP681CodeParser.parse("ethereum:\(testAddress)/transfer?address=somename.eth&uint256=1".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!) + let eip681Code = await Web3.EIP681CodeParser.parse("ethereum:\(testAddress)@1/transfer?address=somename.eth&uint256=1".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!) XCTAssert(eip681Code != nil) guard let eip681Code = eip681Code else { return } switch eip681Code.targetAddress { From be6c5854885fd14cbea46e3e97b93176bd391e90 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Sun, 22 Jan 2023 18:05:40 +0200 Subject: [PATCH 14/14] chore: EIP681 docs + more descriptive log message --- Sources/web3swift/Utils/EIP/EIP681.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/web3swift/Utils/EIP/EIP681.swift b/Sources/web3swift/Utils/EIP/EIP681.swift index 2138da9d7..1882420a4 100755 --- a/Sources/web3swift/Utils/EIP/EIP681.swift +++ b/Sources/web3swift/Utils/EIP/EIP681.swift @@ -238,6 +238,12 @@ extension Web3 { return await parse(string) } + // TODO: throws errors instead of returning `nil` + /// Attempts to parse given string as EIP681 code. + /// Note: that ENS addresses as paramteres will be attempted to be resolved into Ethereum addresses. + /// Thus, make sure that given raw EIP681 code has chain ID set or default Ethereum Mainnet chan ID will be used instead. + /// - Parameter string: raw, encoded EIP681 code. + /// - Returns: parsed EIP681 code or `nil` is something has failed. public static func parse(_ string: String) async -> EIP681Code? { guard string.hasPrefix("ethereum:") else { return nil } let striped = string.components(separatedBy: "ethereum:") @@ -366,7 +372,7 @@ extension Web3 { let address = try await ensModel?.getAddress(forNode: ens) nativeValue = address } catch { - NSLog(error.localizedDescription) + NSLog("Failed to resolve ENS address (parameter nr \(inputNumber)). Error: \(error.localizedDescription)") return nil } }