From d5df8e22c36b839c4596af0a2a62645768392c8b Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Fri, 13 Jan 2023 17:30:32 +0200 Subject: [PATCH 01/49] 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/49] 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/49] 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/49] 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/49] 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/49] 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/49] 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/49] 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/49] 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/49] 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/49] 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/49] 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/49] 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 8af8fa5fb7c3880e59b96b157bbd9ee0012e986f Mon Sep 17 00:00:00 2001 From: albertopeam Date: Wed, 18 Jan 2023 23:11:40 +0100 Subject: [PATCH 14/49] added backticks to BIP44 doc. replaced String with EthereumAddress in TransactionChecker --- Sources/Web3Core/KeystoreManager/BIP44.swift | 10 +++---- .../EtherscanTransactionChecker.swift | 11 ++++++-- .../localTests/BIP44Tests.swift | 4 +-- .../EtherscanTransactionCheckerTests.swift | 27 ++++++++++--------- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/Sources/Web3Core/KeystoreManager/BIP44.swift b/Sources/Web3Core/KeystoreManager/BIP44.swift index d0d701e5d..9a80a396c 100644 --- a/Sources/Web3Core/KeystoreManager/BIP44.swift +++ b/Sources/Web3Core/KeystoreManager/BIP44.swift @@ -7,9 +7,9 @@ import Foundation public protocol BIP44 { /** - Derive an ``HDNode`` based on the provided path. The function will throw ``BIP44Error.warning`` if it was invoked with throwOnWarning equal to - `true` and the root key doesn't have a previous child with at least one transaction. If it is invoked with throwOnError equal to `false` the child node will be - derived directly using the derive function of ``HDNode``. This function needs to query the blockchain history when throwOnWarning is `true`, so it can throw + Derive an ``HDNode`` based on the provided path. The function will throw ``BIP44Error.warning`` if it was invoked with `throwOnWarning` equal to + `true` and the root key doesn't have a previous child with at least one transaction. If it is invoked with `throwOnWarning` equal to `false` the child node will be + derived directly using the derive function of ``HDNode``. This function needs to query the blockchain history when `throwOnWarning` is `true`, so it can throw network errors. - Parameter path: valid BIP44 path. - Parameter throwOnWarning: `true` to use @@ -41,7 +41,7 @@ public protocol TransactionChecker { - Throws: any error related to query the blockchain provider - Returns: `true` if the address has at least one transaction, `false` otherwise */ - func hasTransactions(address: String) async throws -> Bool + func hasTransactions(ethereumAddress: EthereumAddress) async throws -> Bool } extension HDNode: BIP44 { @@ -62,7 +62,7 @@ extension HDNode: BIP44 { if let searchPath = path.newPath(account: searchAccount, addressIndex: searchAddressIndex), let childNode = derive(path: searchPath, derivePrivateKey: true), let ethAddress = Utilities.publicToAddress(childNode.publicKey) { - hasTransactions = try await transactionChecker.hasTransactions(address: ethAddress.address) + hasTransactions = try await transactionChecker.hasTransactions(ethereumAddress: ethAddress) if hasTransactions { break } diff --git a/Sources/Web3Core/KeystoreManager/EtherscanTransactionChecker.swift b/Sources/Web3Core/KeystoreManager/EtherscanTransactionChecker.swift index 93318d151..1b0353285 100644 --- a/Sources/Web3Core/KeystoreManager/EtherscanTransactionChecker.swift +++ b/Sources/Web3Core/KeystoreManager/EtherscanTransactionChecker.swift @@ -8,6 +8,7 @@ import Foundation public struct EtherscanTransactionChecker: TransactionChecker { private let urlSession: URLSessionProxy private let apiKey: String + private let successRange = 200..<300 public init(urlSession: URLSession, apiKey: String) { self.urlSession = URLSessionProxyImplementation(urlSession: urlSession) @@ -19,13 +20,16 @@ public struct EtherscanTransactionChecker: TransactionChecker { self.apiKey = apiKey } - public func hasTransactions(address: String) async throws -> Bool { - let urlString = "https://api.etherscan.io/api?module=account&action=txlist&address=\(address)&startblock=0&page=1&offset=1&sort=asc&apikey=\(apiKey)" + public func hasTransactions(ethereumAddress: EthereumAddress) async throws -> Bool { + let urlString = "https://api.etherscan.io/api?module=account&action=txlist&address=\(ethereumAddress.address)&startblock=0&page=1&offset=1&sort=asc&apikey=\(apiKey)" guard let url = URL(string: urlString) else { throw EtherscanTransactionCheckerError.invalidUrl(url: urlString) } let request = URLRequest(url: url) let result = try await urlSession.data(for: request) + if let httpResponse = result.1 as? HTTPURLResponse, !successRange.contains(httpResponse.statusCode) { + throw EtherscanTransactionCheckerError.network(statusCode: httpResponse.statusCode) + } let response = try JSONDecoder().decode(Response.self, from: result.0) return !response.result.isEmpty } @@ -40,11 +44,14 @@ extension EtherscanTransactionChecker { public enum EtherscanTransactionCheckerError: LocalizedError, Equatable { case invalidUrl(url: String) + case network(statusCode: Int) public var errorDescription: String? { switch self { case let .invalidUrl(url): return "Couldn't create URL(string: \(url))" + case let .network(statusCode): + return "Network error, statusCode: \(statusCode)" } } } diff --git a/Tests/web3swiftTests/localTests/BIP44Tests.swift b/Tests/web3swiftTests/localTests/BIP44Tests.swift index 400a2f6bb..95aa115e9 100644 --- a/Tests/web3swiftTests/localTests/BIP44Tests.swift +++ b/Tests/web3swiftTests/localTests/BIP44Tests.swift @@ -192,8 +192,8 @@ private final class MockTransactionChecker: TransactionChecker { var addresses: [String] = .init() var results: [Bool] = .init() - func hasTransactions(address: String) async throws -> Bool { - addresses.append(address) + func hasTransactions(ethereumAddress: EthereumAddress) async throws -> Bool { + addresses.append(ethereumAddress.address) return results.removeFirst() } } diff --git a/Tests/web3swiftTests/remoteTests/EtherscanTransactionCheckerTests.swift b/Tests/web3swiftTests/remoteTests/EtherscanTransactionCheckerTests.swift index 68d91f933..c58d2fa44 100644 --- a/Tests/web3swiftTests/remoteTests/EtherscanTransactionCheckerTests.swift +++ b/Tests/web3swiftTests/remoteTests/EtherscanTransactionCheckerTests.swift @@ -9,12 +9,12 @@ import XCTest final class EtherscanTransactionCheckerTests: XCTestCase { private var testApiKey: String { "4HVPVMV1PN6NGZDFXZIYKEZRP53IA41KVC" } private var vitaliksAddress: String { "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B" } - private var emptyAddress: String { "0x1BeY3KhtHpfATH5Yqxz9d8Z1XbqZFSXtK7" } + private var emptyAddress: String { "0x3a0cd085155dc74cdddf3196f23c8cec9b217dd8" } func testHasTransactions() async throws { let sut = EtherscanTransactionChecker(urlSession: URLSession.shared, apiKey: testApiKey) - - let result = try await sut.hasTransactions(address: vitaliksAddress) + + let result = try await sut.hasTransactions(ethereumAddress: try XCTUnwrap(EthereumAddress(vitaliksAddress))) XCTAssertTrue(result) } @@ -22,7 +22,8 @@ final class EtherscanTransactionCheckerTests: XCTestCase { func testHasNotTransactions() async throws { let sut = EtherscanTransactionChecker(urlSession: URLSession.shared, apiKey: testApiKey) - let result = try await sut.hasTransactions(address: emptyAddress) + let ethAddr = try XCTUnwrap(EthereumAddress(emptyAddress)) + let result = try await sut.hasTransactions(ethereumAddress: ethAddr) XCTAssertFalse(result) } @@ -33,31 +34,31 @@ final class EtherscanTransactionCheckerTests: XCTestCase { urlSessionMock.response = (Data(), try XCTUnwrap(HTTPURLResponse(url: try XCTUnwrap(URL(string: "https://")), statusCode: 500, httpVersion: nil, headerFields: nil))) let sut = EtherscanTransactionChecker(urlSession: urlSessionMock, apiKey: testApiKey) - _ = try await sut.hasTransactions(address: vitaliksAddress) + _ = try await sut.hasTransactions(ethereumAddress: try XCTUnwrap(EthereumAddress(vitaliksAddress))) XCTFail("Network must throw an error") - } catch { - XCTAssertTrue(true) + } catch let EtherscanTransactionCheckerError.network(statusCode) { + XCTAssertEqual(statusCode, 500) } } func testInitURLError() async throws { do { - let sut = EtherscanTransactionChecker(urlSession: URLSessionMock(), apiKey: testApiKey) + let sut = EtherscanTransactionChecker(urlSession: URLSessionMock(), apiKey: " ") - _ = try await sut.hasTransactions(address: " ") + _ = try await sut.hasTransactions(ethereumAddress: try XCTUnwrap(EthereumAddress(vitaliksAddress))) XCTFail("URL init must throw an error") - } catch { - XCTAssertTrue(error is EtherscanTransactionCheckerError) + } catch EtherscanTransactionCheckerError.invalidUrl { + XCTAssertTrue(true) } } func testWrongApiKey() async throws { do { - let sut = EtherscanTransactionChecker(urlSession: URLSession.shared, apiKey: "") + let sut = EtherscanTransactionChecker(urlSession: URLSession.shared, apiKey: "-") - _ = try await sut.hasTransactions(address: "") + _ = try await sut.hasTransactions(ethereumAddress: try XCTUnwrap(EthereumAddress(vitaliksAddress))) XCTFail("API not returns a valid response") } catch DecodingError.typeMismatch { From be6c5854885fd14cbea46e3e97b93176bd391e90 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Sun, 22 Jan 2023 18:05:40 +0200 Subject: [PATCH 15/49] 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 } } From 32638cd140d9f3b368062ccb0173569553414663 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu <36865532+JeneaVranceanu@users.noreply.github.com> Date: Mon, 23 Jan 2023 11:43:56 +0200 Subject: [PATCH 16/49] ci: enabling tests for PRs targeting v4 PRs that target develop-4.0 branch will now run tests in CI. --- .github/workflows/{macOS-12.yml => macOS-tests.yml} | 4 ++++ 1 file changed, 4 insertions(+) rename .github/workflows/{macOS-12.yml => macOS-tests.yml} (82%) diff --git a/.github/workflows/macOS-12.yml b/.github/workflows/macOS-tests.yml similarity index 82% rename from .github/workflows/macOS-12.yml rename to .github/workflows/macOS-tests.yml index f94e4be06..6d3e1bbb7 100644 --- a/.github/workflows/macOS-12.yml +++ b/.github/workflows/macOS-tests.yml @@ -7,6 +7,8 @@ on: - develop - hotfix - unstable + # Temporary develop-X.Y.Z branches may be added and removed from here as we release new versions + - develop-4.0 paths: - Packag*.swift - web3swift.podspec @@ -20,6 +22,8 @@ on: - master - develop - unstable + # Temporary develop-X.Y.Z branches may be added and removed from here as we release new versions + - develop-4.0 env: DEVELOPER_DIR: /Applications/Xcode_14.1.app/Contents/Developer From e1fcc4d041ade75429a1edbfc3f22bde975d65e1 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu <36865532+JeneaVranceanu@users.noreply.github.com> Date: Mon, 23 Jan 2023 16:53:02 +0200 Subject: [PATCH 17/49] fix: removed unstable and develop-4.0 from push rule of CI --- .github/workflows/macOS-tests.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/macOS-tests.yml b/.github/workflows/macOS-tests.yml index 6d3e1bbb7..9d2e1c690 100644 --- a/.github/workflows/macOS-tests.yml +++ b/.github/workflows/macOS-tests.yml @@ -6,9 +6,6 @@ on: - master - develop - hotfix - - unstable - # Temporary develop-X.Y.Z branches may be added and removed from here as we release new versions - - develop-4.0 paths: - Packag*.swift - web3swift.podspec From 1486d88149ff6bdb6ac6d470e3f752bb8c4bd2fd Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 29 Jan 2023 18:56:33 +0100 Subject: [PATCH 18/49] Upgrade GitHub Action checkout https://github.com/actions/checkout/releases --- .github/workflows/macOS-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macOS-tests.yml b/.github/workflows/macOS-tests.yml index 9d2e1c690..749ce9e55 100644 --- a/.github/workflows/macOS-tests.yml +++ b/.github/workflows/macOS-tests.yml @@ -33,7 +33,7 @@ jobs: group: spm-${{ github.run_id }} cancel-in-progress: false steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Resolve dependencies run: swift package resolve - name: Build From 3850262e34a8d763c2a9129925b7a4839d88e9cb Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 29 Jan 2023 19:02:51 +0100 Subject: [PATCH 19/49] Fix typos discovered by codespell https://pypi.org/project/codespell --- CHANGELOG.md | 12 ++++---- README.md | 4 +-- Sources/Core/EthereumABI/ABIElements.swift | 6 ++-- .../Web3Core/Contract/ContractProtocol.swift | 4 +-- .../Web3Core/EthereumABI/ABIDecoding.swift | 2 +- .../Web3Core/EthereumABI/ABIElements.swift | 4 +-- .../EthereumABI/Sequence+ABIExtension.swift | 2 +- .../EthereumAddress/EthereumAddress.swift | 2 +- .../EthereumNetwork/Request/APIRequest.swift | 10 +++---- .../RequestParameter+Encodable.swift | 4 +-- .../Utility/HexDecodableProtocols.swift | 2 +- Sources/Web3Core/KeystoreManager/IBAN.swift | 4 +-- Sources/Web3Core/Oracle/GasOracle.swift | 4 +-- .../Transaction/CodableTransaction.swift | 10 +++---- .../Envelope/AbstractEnvelope.swift | 6 ++-- .../Envelope/EIP1559Envelope.swift | 2 +- .../Envelope/EnvelopeFactory.swift | 2 +- .../Transaction/Envelope/LegacyEnvelope.swift | 4 +-- .../Transaction/EventfilterParameters.swift | 4 +-- .../Transaction/TransactionMetadata.swift | 2 +- .../Utility/Decodable+Extensions.swift | 12 ++++---- .../Web3Core/Utility/String+Extension.swift | 2 +- Sources/Web3Core/Utility/Utilities.swift | 12 ++++---- Sources/secp256k1/ecmult_impl.h | 2 +- Sources/secp256k1/include/secp256k1.h | 2 +- .../Tokens/ERC20/ERC20BaseProperties.swift | 2 +- Sources/web3swift/Utils/EIP/EIP712.swift | 4 +-- Sources/web3swift/Utils/ENS/NameHash.swift | 2 +- Sources/web3swift/Web3/Web3+Contract.swift | 4 +-- Sources/web3swift/Web3/Web3+Personal.swift | 2 +- Sources/web3swift/Web3/Web3.swift | 4 +-- .../localTests/ABIEncoderTest.swift | 2 +- .../localTests/BasicLocalNodeTests.swift | 2 +- .../localTests/EIP1559BlockTests.swift | 28 +++++++++---------- .../localTests/ERC20ClassTests.swift | 2 +- .../localTests/TransactionsTests.swift | 4 +-- .../remoteTests/InfuraTests.swift | 4 +-- .../remoteTests/RemoteParsingTests.swift | 22 +++++++-------- 38 files changed, 101 insertions(+), 101 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6da5dbfb2..d1fef400b 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,7 +83,7 @@ - `subscribeOnLogs` method with specific contract address is not working!!!! [\#366](https://github.com/skywinder/web3swift/issues/366) - EthereumContract with Custom ABI returns nil [\#342](https://github.com/skywinder/web3swift/issues/342) - Error on running tests [\#290](https://github.com/skywinder/web3swift/issues/290) -- Serialisation of BIP32 misplaced address postition [\#257](https://github.com/skywinder/web3swift/issues/257) +- Serialisation of BIP32 misplaced address position [\#257](https://github.com/skywinder/web3swift/issues/257) - Xcode 10.2.1 carthage update hangs while building web3swift.xcodeproj [\#197](https://github.com/skywinder/web3swift/issues/197) **Closed issues:** @@ -118,7 +118,7 @@ - @ravi-ranjan-oodles thanks for the update. [\#329](https://github.com/skywinder/web3swift/issues/329) - Issue in Uploading to Test Flight [\#328](https://github.com/skywinder/web3swift/issues/328) - Update CryptoSwift podspec [\#322](https://github.com/skywinder/web3swift/issues/322) -- cann't open DApp, such as "https://uniswap.tokenpocket.pro/\#/swap" [\#321](https://github.com/skywinder/web3swift/issues/321) +- can't open DApp, such as "https://uniswap.tokenpocket.pro/\#/swap" [\#321](https://github.com/skywinder/web3swift/issues/321) - CryptoSwift version is too low to work properly in Xcode12.5 [\#318](https://github.com/skywinder/web3swift/issues/318) - web3swift.Web3Error.processingError\(desc: "Failed to fetch gas estimate"\)(BSC Chain) [\#317](https://github.com/skywinder/web3swift/issues/317) - Quick simple steps for minting ERC20 or ERC721 tokens [\#314](https://github.com/skywinder/web3swift/issues/314) @@ -126,7 +126,7 @@ - I can't find func 'Web3.InfuraKovanWeb3\(\)' [\#311](https://github.com/skywinder/web3swift/issues/311) - web3 instance error: Variable used within its own initial value [\#310](https://github.com/skywinder/web3swift/issues/310) - Failed to fetch gas estimate when sending erc20 [\#307](https://github.com/skywinder/web3swift/issues/307) -- DApp browser cann't open Uniswap in a right way [\#304](https://github.com/skywinder/web3swift/issues/304) +- DApp browser can't open Uniswap in a right way [\#304](https://github.com/skywinder/web3swift/issues/304) - Update cocoapods bigint to 5.0 [\#288](https://github.com/skywinder/web3swift/issues/288) - When I use getBlockByNumber , hash Unable to check [\#287](https://github.com/skywinder/web3swift/issues/287) - How to parse the return value of read transaction [\#284](https://github.com/skywinder/web3swift/issues/284) @@ -231,7 +231,7 @@ - policy [\#247](https://github.com/skywinder/web3swift/pull/247) ([BaldyAsh](https://github.com/BaldyAsh)) - Fix dependencies, build [\#245](https://github.com/skywinder/web3swift/pull/245) ([BaldyAsh](https://github.com/BaldyAsh)) - chore: update ENS Registry migration [\#243](https://github.com/skywinder/web3swift/pull/243) ([aranhaagency](https://github.com/aranhaagency)) -- improtant notice update [\#232](https://github.com/skywinder/web3swift/pull/232) ([skywinder](https://github.com/skywinder)) +- important notice update [\#232](https://github.com/skywinder/web3swift/pull/232) ([skywinder](https://github.com/skywinder)) - Add Alice Wallet to project list [\#230](https://github.com/skywinder/web3swift/pull/230) ([lmcmz](https://github.com/lmcmz)) - Update Extensions.swift [\#225](https://github.com/skywinder/web3swift/pull/225) ([kocherovets](https://github.com/kocherovets)) - correct gasLimit [\#222](https://github.com/skywinder/web3swift/pull/222) ([luqz](https://github.com/luqz)) @@ -249,10 +249,10 @@ **Closed issues:** - BigInt 3.1 [\#207](https://github.com/skywinder/web3swift/issues/207) -- recevied transaction id from geth node server but not able to see that transaction id at etherscan.io [\#200](https://github.com/skywinder/web3swift/issues/200) +- received transaction id from geth node server but not able to see that transaction id at etherscan.io [\#200](https://github.com/skywinder/web3swift/issues/200) - How do I fetch information such as balance, decimal,symbol and name of ERC20token ? [\#199](https://github.com/skywinder/web3swift/issues/199) - Starscream 3.1.0 not compatible with Swift 5.0 [\#195](https://github.com/skywinder/web3swift/issues/195) -- How to Connect infuraWebsocket and subsribe perticular event in swift? [\#193](https://github.com/skywinder/web3swift/issues/193) +- How to Connect infuraWebsocket and subsribe particular event in swift? [\#193](https://github.com/skywinder/web3swift/issues/193) - Use of unresolved identifier 'Wallet' [\#192](https://github.com/skywinder/web3swift/issues/192) - V in Signed Message Hash not being calculated properly [\#191](https://github.com/skywinder/web3swift/issues/191) - Not possible to calculate fast, normal and cheap transaction fee ? [\#190](https://github.com/skywinder/web3swift/issues/190) diff --git a/README.md b/README.md index 92c686767..43fbc8ec7 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # web3swift **web3swift** is an iOS toolbelt for interaction with the Ethereum network. -## Social medias +## Social media [Join our discord](https://discord.gg/8bHCNmhS7x) or [Telegram](https://t.me/web3swift) if you need support or want to contribute to web3swift development! ![matter-github-swift](https://github.com/web3swift-team/web3swift/blob/develop/web3swift-logo.png) @@ -57,7 +57,7 @@ - [x] 🕵️‍♂️ Possibility to **add or remove "middleware" that intercepts**, modifies and even **cancel transaction** workflow on stages "before assembly", "after assembly" and "before submission" - [x] ✅**Literally following the standards** (BIP, EIP, etc): - [x] **[BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) (HD Wallets), [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) (Seed phrases), [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) (Key generation prefixes)** -- [x] **[EIP-20](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md)** (Standart interface for tokens - ERC-20), **[EIP-67](https://github.com/ethereum/EIPs/issues/67)** (Standard URI scheme), **[EIP-155](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md)** (Replay attacks protection), **[EIP-2718](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2718.md)** (Typed Transaction Envelope), **[EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md)** (Gas Fee market change) +- [x] **[EIP-20](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md)** (Standard interface for tokens - ERC-20), **[EIP-67](https://github.com/ethereum/EIPs/issues/67)** (Standard URI scheme), **[EIP-155](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md)** (Replay attacks protection), **[EIP-2718](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2718.md)** (Typed Transaction Envelope), **[EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md)** (Gas Fee market change) - [x] **And many others** *(For details about this EIP's look at [Documentation page](https://github.com/web3swift-team/web3swift/blob/master/Documentation/))*: EIP-681, EIP-721, EIP-165, EIP-777, EIP-820, EIP-888, EIP-1400, EIP-1410, EIP-1594, EIP-1643, EIP-1644, EIP-1633, EIP-721, EIP-1155, EIP-1376, ST-20 - [x] **RLP encoding** - [x] Base58 encoding scheme diff --git a/Sources/Core/EthereumABI/ABIElements.swift b/Sources/Core/EthereumABI/ABIElements.swift index c947f6159..f3795bf8d 100755 --- a/Sources/Core/EthereumABI/ABIElements.swift +++ b/Sources/Core/EthereumABI/ABIElements.swift @@ -280,7 +280,7 @@ extension ABI.Element.Function { var returnArray = [String: Any]() - // set infomation + // set information returnArray["_abortedByRequire"] = true returnArray["_errorMessageFromRequire"] = message @@ -340,8 +340,8 @@ extension ABI.Element.Constructor { /// Generic input decoding function. /// - Parameters: -/// - rawData: data to decode. Must match the followin criteria: `data.count == 0 || data.count % 32 == 4`. -/// - methodEncoding: 4 bytes represeting method signature like `0xFFffFFff`. Can be ommited to avoid checking method encoding. +/// - rawData: data to decode. Must match the following criteria: `data.count == 0 || data.count % 32 == 4`. +/// - methodEncoding: 4 bytes representing method signature like `0xFFffFFff`. Can be omitted to avoid checking method encoding. /// - inputs: expected input types. Order must be the same as in function declaration. /// - Returns: decoded dictionary of input arguments mapped to their indices and arguments' names if these are not empty. /// If decoding of at least one argument fails, `rawData` size is invalid or `methodEncoding` doesn't match - `nil` is returned. diff --git a/Sources/Web3Core/Contract/ContractProtocol.swift b/Sources/Web3Core/Contract/ContractProtocol.swift index 9302cbc8e..2f191be1b 100755 --- a/Sources/Web3Core/Contract/ContractProtocol.swift +++ b/Sources/Web3Core/Contract/ContractProtocol.swift @@ -116,7 +116,7 @@ public protocol ContractProtocol { /// - bytecode: bytecode to deploy. /// - constructor: constructor of the smart contract bytecode is related to. Used to encode `parameters`. /// - parameters: parameters for `constructor`. - /// - extraData: any extra data. It can be encoded input arguments for a constuctor but then you should set `constructor` and + /// - extraData: any extra data. It can be encoded input arguments for a constructor but then you should set `constructor` and /// `parameters` to be `nil`. /// - Returns: Encoded data for a given parameters, which is should be assigned to ``CodableTransaction.data`` property func deploy(bytecode: Data, @@ -185,7 +185,7 @@ public protocol ContractProtocol { extension ContractProtocol { /// Overloading of ``ContractProtocol/deploy(bytecode:constructor:parameters:extraData:)`` to allow - /// omitting evertyhing but `bytecode`. + /// omitting everything but `bytecode`. /// /// See ``ContractProtocol/deploy(bytecode:constructor:parameters:extraData:)`` for details. func deploy(_ bytecode: Data, diff --git a/Sources/Web3Core/EthereumABI/ABIDecoding.swift b/Sources/Web3Core/EthereumABI/ABIDecoding.swift index 7dad9179f..57b25aa1a 100755 --- a/Sources/Web3Core/EthereumABI/ABIDecoding.swift +++ b/Sources/Web3Core/EthereumABI/ABIDecoding.swift @@ -196,7 +196,7 @@ extension ABIDecoder { let dataSlice = data[pointer ..< pointer + type.memoryUsage] let bn = BigUInt(dataSlice) if bn > UInt64.max || bn >= data.count { - // there are ERC20 contracts that use bytes32 intead of string. Let's be optimistic and return some data + // there are ERC20 contracts that use bytes32 instead of string. Let's be optimistic and return some data if case .string = type { let nextElement = pointer + type.memoryUsage let preambula = BigUInt(32).abiEncode(bits: 256)! diff --git a/Sources/Web3Core/EthereumABI/ABIElements.swift b/Sources/Web3Core/EthereumABI/ABIElements.swift index aadf61b9a..10118b64e 100755 --- a/Sources/Web3Core/EthereumABI/ABIElements.swift +++ b/Sources/Web3Core/EthereumABI/ABIElements.swift @@ -438,8 +438,8 @@ extension ABI.Element.Constructor { /// Generic input decoding function. /// - Parameters: -/// - rawData: data to decode. Must match the followin criteria: `data.count == 0 || data.count % 32 == 4`. -/// - methodEncoding: 4 bytes represeting method signature like `0xFFffFFff`. Can be ommited to avoid checking method encoding. +/// - rawData: data to decode. Must match the following criteria: `data.count == 0 || data.count % 32 == 4`. +/// - methodEncoding: 4 bytes representing method signature like `0xFFffFFff`. Can be omitted to avoid checking method encoding. /// - inputs: expected input types. Order must be the same as in function declaration. /// - Returns: decoded dictionary of input arguments mapped to their indices and arguments' names if these are not empty. /// If decoding of at least one argument fails, `rawData` size is invalid or `methodEncoding` doesn't match - `nil` is returned. diff --git a/Sources/Web3Core/EthereumABI/Sequence+ABIExtension.swift b/Sources/Web3Core/EthereumABI/Sequence+ABIExtension.swift index c13fb9f15..1d2f32744 100644 --- a/Sources/Web3Core/EthereumABI/Sequence+ABIExtension.swift +++ b/Sources/Web3Core/EthereumABI/Sequence+ABIExtension.swift @@ -63,7 +63,7 @@ public extension Sequence where Element == ABI.Element { /// Filters out ``ABI/Element/Constructor``. /// If there are multiple of them the first encountered will be returned and if there are none a default constructor will be returned /// that accepts no input parameters. - /// - Returns: the first ``ABI/Element/Constructor`` or default contructor with no input parameters. + /// - Returns: the first ``ABI/Element/Constructor`` or default constructor with no input parameters. func getConstructor() -> ABI.Element.Constructor { for case let .constructor(constructor) in self { return constructor diff --git a/Sources/Web3Core/EthereumAddress/EthereumAddress.swift b/Sources/Web3Core/EthereumAddress/EthereumAddress.swift index ba703f78e..2e8d0ef45 100755 --- a/Sources/Web3Core/EthereumAddress/EthereumAddress.swift +++ b/Sources/Web3Core/EthereumAddress/EthereumAddress.swift @@ -91,7 +91,7 @@ public struct EthereumAddress: Equatable { } /// In swift structs it's better to implement initializers in extension -/// Since it's make available syntetized initializer then for free. +/// Since it's make available synthesized initializer then for free. extension EthereumAddress { public init?(_ addressString: String, type: AddressType = .normal, ignoreChecksum: Bool = false) { switch type { diff --git a/Sources/Web3Core/EthereumNetwork/Request/APIRequest.swift b/Sources/Web3Core/EthereumNetwork/Request/APIRequest.swift index 39d9cae4d..cb057da7e 100644 --- a/Sources/Web3Core/EthereumNetwork/Request/APIRequest.swift +++ b/Sources/Web3Core/EthereumNetwork/Request/APIRequest.swift @@ -95,7 +95,7 @@ public enum APIRequest { /// Estimate required gas amount for transaction /// - Parameters: /// - TransactionParameters: parameters of planned transaction - /// - BlockNumber: block where it should be evalueated + /// - BlockNumber: block where it should be evaluated case estimateGas(CodableTransaction, BlockNumber) /// Send raw transaction @@ -114,7 +114,7 @@ public enum APIRequest { case getTransactionByHash(Hash) /// Get transaction receipt - /// - Paramters: + /// - Parameters: /// - Hash: transaction hash ID case getTransactionReceipt(Hash) @@ -134,7 +134,7 @@ public enum APIRequest { /// Mostly could be used for intreacting with a contracts, but also could be used for simple transaction sending /// - Parameters: /// - TransactionParameters: transaction to be sent into chain - /// - BlockNumber: block where it should be evalueated + /// - BlockNumber: block where it should be evaluated case call(CodableTransaction, BlockNumber) /// Get a transaction counts on a given block @@ -149,7 +149,7 @@ public enum APIRequest { /// Get a balance of a given address /// - Parameters: - /// - Address: address which balance would be recieved + /// - Address: address which balance would be received /// - BlockNumber: block to check case getBalance(Address, BlockNumber) @@ -190,7 +190,7 @@ public enum APIRequest { /// - BlockNumber: Highest block of the requested range. /// - [Double]: A monotonically increasing list of percentile values. /// For each block in the requested range, the transactions will be sorted in ascending order - /// by effective tip per gas and the coresponding effective tip for the percentile will be determined, accounting for gas consumed." + /// by effective tip per gas and the corresponding effective tip for the percentile will be determined, accounting for gas consumed." case feeHistory(BigUInt, BlockNumber, [Double]) // MARK: - Personal Ethereum API diff --git a/Sources/Web3Core/EthereumNetwork/RequestParameter/RequestParameter+Encodable.swift b/Sources/Web3Core/EthereumNetwork/RequestParameter/RequestParameter+Encodable.swift index 2a99dd1e0..a683d5fdc 100644 --- a/Sources/Web3Core/EthereumNetwork/RequestParameter/RequestParameter+Encodable.swift +++ b/Sources/Web3Core/EthereumNetwork/RequestParameter/RequestParameter+Encodable.swift @@ -9,7 +9,7 @@ import Foundation extension RequestParameter: Encodable { /** - This encoder encodes `RequestParameter` assotiated value ignoring self value + This encoder encodes `RequestParameter` associated value ignoring self value This is required to encode mixed types array, like @@ -48,7 +48,7 @@ extension RequestParameter: Encodable { case is CodableTransaction.Type: try enumContainer.encode(rawValue as! CodableTransaction) case is EventFilterParameters.Type: try enumContainer.encode(rawValue as! EventFilterParameters) - default: break /// can't be executed, coz possible `self.rawValue` types are strictly defined in it's inplementation.` + default: break /// can't be executed, coz possible `self.rawValue` types are strictly defined in it's implementation.` } // swiftlint:enable force_cast } diff --git a/Sources/Web3Core/EthereumNetwork/Utility/HexDecodableProtocols.swift b/Sources/Web3Core/EthereumNetwork/Utility/HexDecodableProtocols.swift index fede66d34..b4c57ca39 100644 --- a/Sources/Web3Core/EthereumNetwork/Utility/HexDecodableProtocols.swift +++ b/Sources/Web3Core/EthereumNetwork/Utility/HexDecodableProtocols.swift @@ -17,7 +17,7 @@ extension String: APIResultType { } /// /// You better not use it in any other part of a bit of code except `APIResponse` decoding. /// -/// This protocols intention is to work around that Ethereum API cases, when almost all numbers are comming as strings. +/// This protocols intention is to work around that Ethereum API cases, when almost all numbers are coming as strings. /// More than that their notation (e.g. 0x12d) are don't fit with the default Numeric decoders behaviours. /// So to work around that for generic cases we're going to force decode `APIResponse.result` field as `String` /// and then initiate it diff --git a/Sources/Web3Core/KeystoreManager/IBAN.swift b/Sources/Web3Core/KeystoreManager/IBAN.swift index 604f7dce7..164ff319f 100755 --- a/Sources/Web3Core/KeystoreManager/IBAN.swift +++ b/Sources/Web3Core/KeystoreManager/IBAN.swift @@ -64,9 +64,9 @@ public struct IBAN { internal static func decodeToInts(_ iban: String) -> String { let uppercasedIBAN = iban.replacingOccurrences(of: " ", with: "").uppercased() - let begining = String(uppercasedIBAN[0..<4]) + let beginning = String(uppercasedIBAN[0..<4]) let end = String(uppercasedIBAN[4...]) - let IBAN = end + begining + let IBAN = end + beginning var arrayOfInts = [Int]() for ch in IBAN { guard let dataPoint = String(ch).data(using: .ascii) else {return ""} diff --git a/Sources/Web3Core/Oracle/GasOracle.swift b/Sources/Web3Core/Oracle/GasOracle.swift index 2819f5adc..dee933f01 100644 --- a/Sources/Web3Core/Oracle/GasOracle.swift +++ b/Sources/Web3Core/Oracle/GasOracle.swift @@ -101,7 +101,7 @@ final public class Oracle { private func suggestTipValue() async throws -> [BigUInt] { var rearrengedArray: [[BigUInt]] = [] - /// reaarange `[[min, middle, max]]` to `[[min], [middle], [max]]` + /// rearrange `[[min, middle, max]]` to `[[min], [middle], [max]]` try await suggestGasValues().reward .forEach { percentiles in percentiles.enumerated().forEach { index, percentile in @@ -139,7 +139,7 @@ final public class Oracle { default: throw Web3Error.valueError(desc: "Unable to use '\(block)' policy to resolve block number to calculate gas fee suggestion.") } - /// checking if latest block number is greather than number of blocks to take in account + /// checking if latest block number is greater than number of blocks to take in account /// we're ignoring case when `latestBlockNumber` == `blockCount` since it's unlikely case /// which we could neglect guard latestBlockNumber > blockCount else { return [] } diff --git a/Sources/Web3Core/Transaction/CodableTransaction.swift b/Sources/Web3Core/Transaction/CodableTransaction.swift index 19f5773fe..b478dc0f0 100644 --- a/Sources/Web3Core/Transaction/CodableTransaction.swift +++ b/Sources/Web3Core/Transaction/CodableTransaction.swift @@ -11,7 +11,7 @@ import BigInt /// While most fields in this struct are optional, they are not necessarily /// optional for the type of transaction they apply to. public struct CodableTransaction { - /// internal acccess only. The transaction envelope object itself that contains all the transaction data + /// internal access only. The transaction envelope object itself that contains all the transaction data /// and type specific implementation internal var envelope: AbstractEnvelope @@ -73,7 +73,7 @@ public struct CodableTransaction { set { return envelope.gasLimit = newValue } } - /// the price per gas unit for the tranaction (Legacy and EIP-2930 only) + /// the price per gas unit for the transaction (Legacy and EIP-2930 only) public var gasPrice: BigUInt? { get { return envelope.gasPrice } set { return envelope.gasPrice = newValue } @@ -147,7 +147,7 @@ public struct CodableTransaction { /// Signs the transaction /// - /// This method signs transaction iteself and not related to contract call data signing. + /// This method signs transaction itself and not related to contract call data signing. /// - Parameters: /// - privateKey: the private key to use for signing /// - useExtraEntropy: boolean whether to use extra entropy when signing (default false) @@ -265,7 +265,7 @@ extension CodableTransaction: Codable { } extension CodableTransaction: CustomStringConvertible { - /// required by CustomString convertable + /// required by CustomString convertible /// returns a string description for the transaction and its data public var description: String { var toReturn = "" @@ -290,7 +290,7 @@ extension CodableTransaction { /// - v: signature v parameter (default 1) - will get set properly once signed /// - r: signature r parameter (default 0) - will get set properly once signed /// - s: signature s parameter (default 0) - will get set properly once signed - /// - parameters: EthereumParameters object containing additional parametrs for the transaction like gas + /// - parameters: EthereumParameters object containing additional parameters for the transaction like gas public init(type: TransactionType? = nil, to: EthereumAddress, nonce: BigUInt = 0, chainID: BigUInt = 0, value: BigUInt = 0, data: Data = Data(), gasLimit: BigUInt = 0, maxFeePerGas: BigUInt? = nil, maxPriorityFeePerGas: BigUInt? = nil, gasPrice: BigUInt? = nil, diff --git a/Sources/Web3Core/Transaction/Envelope/AbstractEnvelope.swift b/Sources/Web3Core/Transaction/Envelope/AbstractEnvelope.swift index 5bb32c104..7986cddb1 100644 --- a/Sources/Web3Core/Transaction/Envelope/AbstractEnvelope.swift +++ b/Sources/Web3Core/Transaction/Envelope/AbstractEnvelope.swift @@ -60,8 +60,8 @@ public enum EncodeType { /// Protocol definition for all transaction envelope types /// All envelopes must conform to this protocol to work with `CodableTransaction` -/// each implememtation holds all the type specific data -/// and implments the type specific encoding/decoding +/// each implementation holds all the type specific data +/// and implements the type specific encoding/decoding protocol AbstractEnvelope: CustomStringConvertible { // possibly add Codable? /// The type of transaction this envelope represents @@ -115,7 +115,7 @@ protocol AbstractEnvelope: CustomStringConvertible { // possibly add Codable? // for Decodable support /// initializer for creating an `CodableTransaction` with the Decodable protocol /// will return an new `CodableTransaction` object on success - /// thows a `Web3.dataError` if an error occurs while trying to decode a value + /// throws a `Web3.dataError` if an error occurs while trying to decode a value /// returns nil if a required field is not found in the decoder stream init?(from decoder: Decoder) throws // Decodable Protocol diff --git a/Sources/Web3Core/Transaction/Envelope/EIP1559Envelope.swift b/Sources/Web3Core/Transaction/Envelope/EIP1559Envelope.swift index 052b931d9..71a5beba9 100644 --- a/Sources/Web3Core/Transaction/Envelope/EIP1559Envelope.swift +++ b/Sources/Web3Core/Transaction/Envelope/EIP1559Envelope.swift @@ -45,7 +45,7 @@ public struct EIP1559Envelope: EIP2718Envelope, EIP2930Compatible { /// all exceed funds will be returned to the sender. /// /// If amount of this will be **lower** than sum of `Block.baseFeePerGas` and `maxPriorityFeePerGas` - /// miner will recieve amount calculated by the following equation: `maxFeePerGas - Block.baseFeePerGas` + /// miner will receive amount calculated by the following equation: `maxFeePerGas - Block.baseFeePerGas` /// where 'Block' is the block that the transaction will be included. public var maxFeePerGas: BigUInt? public var accessList: [AccessListEntry] // from EIP-2930 diff --git a/Sources/Web3Core/Transaction/Envelope/EnvelopeFactory.swift b/Sources/Web3Core/Transaction/Envelope/EnvelopeFactory.swift index 7fa3b0e9c..4e2f22749 100644 --- a/Sources/Web3Core/Transaction/Envelope/EnvelopeFactory.swift +++ b/Sources/Web3Core/Transaction/Envelope/EnvelopeFactory.swift @@ -74,7 +74,7 @@ public struct EnvelopeFactory { /// - v: signature v parameter (default 1) - will get set properly once signed /// - r: signature r parameter (default 0) - will get set properly once signed /// - s: signature s parameter (default 0) - will get set properly once signed - /// - options: TransactionParameters containing additional parametrs for the transaction like gas + /// - options: TransactionParameters containing additional parameters for the transaction like gas /// - Returns: a new envelope of type dictated by 'type' static func createEnvelope(type: TransactionType? = nil, to: EthereumAddress, nonce: BigUInt, chainID: BigUInt, value: BigUInt, data: Data, diff --git a/Sources/Web3Core/Transaction/Envelope/LegacyEnvelope.swift b/Sources/Web3Core/Transaction/Envelope/LegacyEnvelope.swift index 121ecb63b..a33df7c6e 100644 --- a/Sources/Web3Core/Transaction/Envelope/LegacyEnvelope.swift +++ b/Sources/Web3Core/Transaction/Envelope/LegacyEnvelope.swift @@ -35,7 +35,7 @@ public struct LegacyEnvelope: AbstractEnvelope { // legacy chainID Mechanism private var explicitChainID: BigUInt? // set directly or via options - // private var impliedChainID: BigUInt? // we calculate this once, or when explicitely asked to + // private var impliedChainID: BigUInt? // we calculate this once, or when explicitly asked to private var impliedChainID: BigUInt? { if r == 0 && s == 0 { return v } if v == 27 || v == 28 || v < 35 { return nil } @@ -54,7 +54,7 @@ public struct LegacyEnvelope: AbstractEnvelope { toReturn += "Data: " + self.data.toHexString().addHexPrefix().lowercased() + "\n" toReturn += "Resolved chainID: " + String(describing: self.chainID) + "\n" toReturn += "- Intrinsic chainID: " + String(describing: self.explicitChainID) + "\n" - toReturn += "- Infered chainID: " + String(describing: self.impliedChainID) + "\n" + toReturn += "- Inferred chainID: " + String(describing: self.impliedChainID) + "\n" toReturn += "v: " + String(self.v) + "\n" toReturn += "r: " + String(self.r) + "\n" toReturn += "s: " + String(self.s) + "\n" diff --git a/Sources/Web3Core/Transaction/EventfilterParameters.swift b/Sources/Web3Core/Transaction/EventfilterParameters.swift index bb959c9c3..7459f2dda 100755 --- a/Sources/Web3Core/Transaction/EventfilterParameters.swift +++ b/Sources/Web3Core/Transaction/EventfilterParameters.swift @@ -101,7 +101,7 @@ extension EventFilterParameters { var rawValue: String { switch self { case let .string(string): - // Assiciated value can contain only String or nil, both of them always encoded as a JSON could be represented as String again. + // Associated value can contain only String or nil, both of them always encoded as a JSON could be represented as String again. return String(data: try! JSONEncoder().encode(string), encoding: .utf8)! case let .strings(strings): return strings!.textRepresentation @@ -112,7 +112,7 @@ extension EventFilterParameters { extension EventFilterParameters: APIRequestParameterType { } -// - Why don't you develope some JSON composer to just send a server request, Yaroslav? +// - Why don't you develop some JSON composer to just send a server request, Yaroslav? // - Indeed, see no reason, why should i pass this. // Oh i wish to look deep in the Vitaliks eyes someday. extension Array where Element == EventFilterParameters.Topic? { diff --git a/Sources/Web3Core/Transaction/TransactionMetadata.swift b/Sources/Web3Core/Transaction/TransactionMetadata.swift index 28b6508d0..f70334290 100644 --- a/Sources/Web3Core/Transaction/TransactionMetadata.swift +++ b/Sources/Web3Core/Transaction/TransactionMetadata.swift @@ -44,7 +44,7 @@ public extension TransactionMetadata { } /// since metadata realistically can only come when a transaction is created from - /// JSON returned by a node, we only provide an intializer from JSON + /// JSON returned by a node, we only provide an initializer from JSON init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) diff --git a/Sources/Web3Core/Utility/Decodable+Extensions.swift b/Sources/Web3Core/Utility/Decodable+Extensions.swift index 0029df3cd..bd520b3fa 100644 --- a/Sources/Web3Core/Utility/Decodable+Extensions.swift +++ b/Sources/Web3Core/Utility/Decodable+Extensions.swift @@ -27,7 +27,7 @@ extension KeyedDecodingContainer { /// /// Currently this method supports only `Data.Type`, `BigUInt.Type`, `Date.Type`, `UInt.Type` /// - /// - Parameter type: Generic type `T` wich conforms to `DecodableFromHex` protocol + /// - Parameter type: Generic type `T` which conforms to `DecodableFromHex` protocol /// - Parameter key: The key that the decoded value is associated with. /// - Returns: A decoded value of type `T` /// - throws: `Web3Error.dataError` if value associated with key are unable to be initialized as `DecodableFromHex`. @@ -41,7 +41,7 @@ extension KeyedDecodingContainer { /// /// Currently this method supports only `Data.Type`, `BigUInt.Type`, `Date.Type`, `UInt.Type` /// - /// - Parameter type: Array of a generic type `T` wich conforms to `DecodableFromHex` protocol + /// - Parameter type: Array of a generic type `T` which conforms to `DecodableFromHex` protocol /// - Parameter key: The key that the decoded value is associated with. /// - Returns: A decoded value of type `[T]` /// - throws: `Web3Error.dataError` if value associated with key are unable to be initialized as `[[DecodableFromHex]]`. @@ -55,7 +55,7 @@ extension KeyedDecodingContainer { /// /// Currently this method supports only `Data.Type`, `BigUInt.Type`, `Date.Type`, `EthereumAddress`, `UInt.Type` /// - /// - Parameter type: Array of a generic type `T` wich conforms to `DecodableFromHex` protocol + /// - Parameter type: Array of a generic type `T` which conforms to `DecodableFromHex` protocol /// - Parameter key: The key that the decoded value is associated with. /// - Returns: A decoded value of type `[[T]]` /// - throws: `Web3Error.dataError` if value associated with key are unable to be initialized as `[[DecodableFromHex]]`. @@ -69,7 +69,7 @@ extension KeyedDecodingContainer { /// /// Currently this method supports only `Data.Type`, `BigUInt.Type`, `Date.Type`, `UInt.Type` /// - /// - Parameter type: Generic type `T` wich conforms to `DecodableFromHex` protocol + /// - Parameter type: Generic type `T` which conforms to `DecodableFromHex` protocol /// - Parameter key: The key that the decoded value is associated with. /// - Returns: A decoded value of type `T`, or nil if key is not present /// - throws: `Web3Error.dataError` if value associated with key are unable to be initialized as `DecodableFromHex`. @@ -84,7 +84,7 @@ extension UnkeyedDecodingContainer { /// /// Currently this method supports only `Data.Type`, `BigUInt.Type`, `Date.Type`, `EthereumAddress` /// - /// - Parameter type: Generic type `T` wich conforms to `DecodableFromHex` protocol + /// - Parameter type: Generic type `T` which conforms to `DecodableFromHex` protocol /// - Parameter key: The key that the decoded value is associated with. /// - Returns: A decoded value of type `BigUInt` /// - throws: `Web3Error.dataError` if value associated with key are unable to be initialized as `[DecodableFromHex]`. @@ -102,7 +102,7 @@ extension UnkeyedDecodingContainer { /// /// Currently this method supports only `Data.Type`, `BigUInt.Type`, `Date.Type`, `EthereumAddress` /// - /// - Parameter type: Generic type `T` wich conforms to `DecodableFromHex` protocol + /// - Parameter type: Generic type `T` which conforms to `DecodableFromHex` protocol /// - Parameter key: The key that the decoded value is associated with. /// - Returns: A decoded value of type `BigUInt` /// - throws: `Web3Error.dataError` if value associated with key are unable to be initialized as `[[DecodableFromHex]]`. diff --git a/Sources/Web3Core/Utility/String+Extension.swift b/Sources/Web3Core/Utility/String+Extension.swift index cf7537663..f63e077da 100755 --- a/Sources/Web3Core/Utility/String+Extension.swift +++ b/Sources/Web3Core/Utility/String+Extension.swift @@ -86,7 +86,7 @@ extension String { /// Strips leading zeroes from a HEX string. /// ONLY HEX string format is supported. - /// - Returns: string with stripped leading zeroes (and 0x prefix) or unchaged string. + /// - Returns: string with stripped leading zeroes (and 0x prefix) or unchanged string. func stripLeadingZeroes() -> String { let hex = addHexPrefix() guard let matcher = try? NSRegularExpression(pattern: "^(?0x)(?0+)(?[0-9a-fA-F]*)$", diff --git a/Sources/Web3Core/Utility/Utilities.swift b/Sources/Web3Core/Utility/Utilities.swift index 7b0557f6a..5a71cdd04 100644 --- a/Sources/Web3Core/Utility/Utilities.swift +++ b/Sources/Web3Core/Utility/Utilities.swift @@ -19,17 +19,17 @@ public struct Utilities { guard let decompressedKey = SECP256K1.combineSerializedPublicKeys(keys: [publicKey], outputCompressed: false) else {return nil} return publicToAddressData(decompressedKey) } - var stipped = publicKey - if stipped.count == 65 { - if stipped[0] != 4 { + var stripped = publicKey + if stripped.count == 65 { + if stripped[0] != 4 { return nil } - stipped = stipped[1...64] + stripped = stripped[1...64] } - if stipped.count != 64 { + if stripped.count != 64 { return nil } - let sha3 = stipped.sha3(.keccak256) + let sha3 = stripped.sha3(.keccak256) let addressData = sha3[12...31] return addressData } diff --git a/Sources/secp256k1/ecmult_impl.h b/Sources/secp256k1/ecmult_impl.h index feab1b741..61a5ffd23 100755 --- a/Sources/secp256k1/ecmult_impl.h +++ b/Sources/secp256k1/ecmult_impl.h @@ -339,7 +339,7 @@ static void secp256k1_ecmult_strauss_wnaf(const secp256k1_ecmult_context *ctx, c secp256k1_ge tmpa; secp256k1_fe Z; #ifdef USE_ENDOMORPHISM - /* Splitted G factors. */ + /* Split G factors. */ secp256k1_scalar ng_1, ng_128; int wnaf_ng_1[129]; int bits_ng_1 = 0; diff --git a/Sources/secp256k1/include/secp256k1.h b/Sources/secp256k1/include/secp256k1.h index ea2bc0155..c1fc13fac 100755 --- a/Sources/secp256k1/include/secp256k1.h +++ b/Sources/secp256k1/include/secp256k1.h @@ -399,7 +399,7 @@ SECP256K1_API int secp256k1_ecdsa_signature_serialize_compact( /** Verify an ECDSA signature. * * Returns: 1: correct signature - * 0: incorrect or unparseable signature + * 0: incorrect or unparsable signature * Args: ctx: a secp256k1 context object, initialized for verification. * In: sig: the signature being verified (cannot be NULL) * msg32: the 32-byte message hash being verified (cannot be NULL) diff --git a/Sources/web3swift/Tokens/ERC20/ERC20BaseProperties.swift b/Sources/web3swift/Tokens/ERC20/ERC20BaseProperties.swift index e0d861fe7..806a038ee 100644 --- a/Sources/web3swift/Tokens/ERC20/ERC20BaseProperties.swift +++ b/Sources/web3swift/Tokens/ERC20/ERC20BaseProperties.swift @@ -7,7 +7,7 @@ import Foundation -/// Declares common properties of an [ERC-20](https://eips.ethereum.org/EIPS/eip-20) complient smart contract. +/// Declares common properties of an [ERC-20](https://eips.ethereum.org/EIPS/eip-20) compliant smart contract. /// Default implementation of access to these properties is declared in the extension of this protocol. public protocol ERC20BaseProperties: AnyObject { var basePropertiesProvider: ERC20BasePropertiesProvider { get } diff --git a/Sources/web3swift/Utils/EIP/EIP712.swift b/Sources/web3swift/Utils/EIP/EIP712.swift index 4cb913ffd..1bb65436f 100644 --- a/Sources/web3swift/Utils/EIP/EIP712.swift +++ b/Sources/web3swift/Utils/EIP/EIP712.swift @@ -100,7 +100,7 @@ fileprivate extension EIP712Hashable { } func encodePrimaryType() -> String { - let parametrs: [String] = Mirror(reflecting: self).children.compactMap { key, value in + let parameters: [String] = Mirror(reflecting: self).children.compactMap { key, value in guard let key = key else { return nil } func checkIfValueIsNil(value: Any) -> Bool { @@ -127,7 +127,7 @@ fileprivate extension EIP712Hashable { } return typeName + " " + key } - return name + "(" + parametrs.joined(separator: ",") + ")" + return name + "(" + parameters.joined(separator: ",") + ")" } } diff --git a/Sources/web3swift/Utils/ENS/NameHash.swift b/Sources/web3swift/Utils/ENS/NameHash.swift index 723da72c4..c6e58412e 100755 --- a/Sources/web3swift/Utils/ENS/NameHash.swift +++ b/Sources/web3swift/Utils/ENS/NameHash.swift @@ -8,7 +8,7 @@ import CryptoSwift public struct NameHash { public static func normalizeDomainName(_ domain: String) -> String? { - // TODO use ICU4C library later for domain name normalization, althoug f**k it for now, it's few megabytes large piece + // TODO use ICU4C library later for domain name normalization, although f**k it for now, it's few megabytes large piece let normalized = domain.lowercased() return normalized } diff --git a/Sources/web3swift/Web3/Web3+Contract.swift b/Sources/web3swift/Web3/Web3+Contract.swift index ebb9bc41a..76285887c 100755 --- a/Sources/web3swift/Web3/Web3+Contract.swift +++ b/Sources/web3swift/Web3/Web3+Contract.swift @@ -78,7 +78,7 @@ extension Web3 { // FIXME: Actually this is not rading contract or smth, this is about composing appropriate binary data to iterate with it later. // FIXME: Rewrite this to CodableTransaction /// Creates and object responsible for calling a particular function of the contract. If method name is not found in ABI - returns nil. - /// If extraData is supplied it is appended to encoded function parameters. Can be usefull if one wants to call + /// If extraData is supplied it is appended to encoded function parameters. Can be useful if one wants to call /// the function not listed in ABI. "Parameters" should be an array corresponding to the list of parameters of the function. /// Elements of "parameters" can be other arrays or instances of String, Data, BigInt, BigUInt, Int or EthereumAddress. /// @@ -99,7 +99,7 @@ extension Web3 { // FIXME: Rewrite this to CodableTransaction /// Creates and object responsible for calling a particular function of the contract. If method name is not found in ABI - returns nil. - /// If extraData is supplied it is appended to encoded function parameters. Can be usefull if one wants to call + /// If extraData is supplied it is appended to encoded function parameters. Can be useful if one wants to call /// the function not listed in ABI. "Parameters" should be an array corresponding to the list of parameters of the function. /// Elements of "parameters" can be other arrays or instances of String, Data, BigInt, BigUInt, Int or EthereumAddress. /// diff --git a/Sources/web3swift/Web3/Web3+Personal.swift b/Sources/web3swift/Web3/Web3+Personal.swift index 3949fcd7f..f83d328b8 100755 --- a/Sources/web3swift/Web3/Web3+Personal.swift +++ b/Sources/web3swift/Web3/Web3+Personal.swift @@ -34,7 +34,7 @@ extension Web3.Personal { - parameters: - account: EthereumAddress of the account to unlock - password: Password to use for the account - - seconds: Time inteval before automatic account lock by Ethereum node + - seconds: Time interval before automatic account lock by Ethereum node - returns: - Result object diff --git a/Sources/web3swift/Web3/Web3.swift b/Sources/web3swift/Web3/Web3.swift index 29c881130..e8b1a72df 100755 --- a/Sources/web3swift/Web3/Web3.swift +++ b/Sources/web3swift/Web3/Web3.swift @@ -6,14 +6,14 @@ import Foundation import Web3Core -/// An arbitary Web3 object. Is used only to construct provider bound fully functional object by either supplying provider URL +/// An arbitrary Web3 object. Is used only to construct provider bound fully functional object by either supplying provider URL /// or using pre-coded Infura nodes extension Web3 { /// Initialized provider-bound Web3 instance using a provider's URL. Under the hood it performs a synchronous call to get /// the Network ID for EIP155 purposes public static func new(_ providerURL: URL, network: Networks = .Mainnet) async throws -> Web3 { - // FIXME: Change this hardcoded value to dynamicly fethed from a Node + // FIXME: Change this hardcoded value to dynamically fethed from a Node guard let provider = await Web3HttpProvider(providerURL, network: network) else { throw Web3Error.inputError(desc: "Wrong provider - should be Web3HttpProvider with endpoint scheme http or https") } diff --git a/Tests/web3swiftTests/localTests/ABIEncoderTest.swift b/Tests/web3swiftTests/localTests/ABIEncoderTest.swift index 4b50fdecd..3f69fb2db 100644 --- a/Tests/web3swiftTests/localTests/ABIEncoderTest.swift +++ b/Tests/web3swiftTests/localTests/ABIEncoderTest.swift @@ -30,7 +30,7 @@ class ABIEncoderTest: XCTestCase { hex = try ABIEncoder.soliditySha3("Hello!%").toHexString().addHexPrefix() assert(hex == "0x661136a4267dba9ccdf6bfddb7c00e714de936674c4bdb065a531cf1cb15c7fc") - // This is not JS. '234' (with single or double qoutes) will be a String, not any kind of number. + // This is not JS. '234' (with single or double quotes) will be a String, not any kind of number. // From Web3JS docs:> web3.utils.soliditySha3('234'); // auto detects: uint256 hex = try ABIEncoder.soliditySha3(0xea).toHexString().addHexPrefix() diff --git a/Tests/web3swiftTests/localTests/BasicLocalNodeTests.swift b/Tests/web3swiftTests/localTests/BasicLocalNodeTests.swift index e71641ee3..632c4c755 100755 --- a/Tests/web3swiftTests/localTests/BasicLocalNodeTests.swift +++ b/Tests/web3swiftTests/localTests/BasicLocalNodeTests.swift @@ -2,7 +2,7 @@ // Created by Alex Vlasov. // Copyright © 2018 Alex Vlasov. All rights reserved. // -// TODO: Replace `XCTAssert` with more explicite `XCTAssertEqual`, where Applicable +// TODO: Replace `XCTAssert` with more explicit `XCTAssertEqual`, where Applicable import XCTest import CryptoSwift import BigInt diff --git a/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift b/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift index e41c55e3f..26f567017 100644 --- a/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift +++ b/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift @@ -57,8 +57,8 @@ class EIP1559BlockTests: LocalTestCase { (40_000_000, 12_965_000, 39_960_938, false) // Lower limit -1 ] - headerArray.forEach { (touple: (parentGasLimit: BigUInt, parentNumber: BigUInt, currentGasLimit: BigUInt, is1559: Bool)) in - let parent = Block(number: touple.parentNumber, + headerArray.forEach { (tuple: (parentGasLimit: BigUInt, parentNumber: BigUInt, currentGasLimit: BigUInt, is1559: Bool)) in + let parent = Block(number: tuple.parentNumber, hash: uselessBlockPart.hash, parentHash: uselessBlockPart.parentHash, nonce: uselessBlockPart.nonce, @@ -72,14 +72,14 @@ class EIP1559BlockTests: LocalTestCase { totalDifficulty: uselessBlockPart.totalDifficulty, extraData: uselessBlockPart.extraData, size: uselessBlockPart.size, - gasLimit: touple.parentGasLimit, - gasUsed: touple.parentGasLimit / 2, + gasLimit: tuple.parentGasLimit, + gasUsed: tuple.parentGasLimit / 2, baseFeePerGas: Web3.InitialBaseFee, timestamp: uselessBlockPart.timestamp, transactions: uselessBlockPart.transactions, uncles: uselessBlockPart.uncles) - let current = Block(number: touple.parentNumber + 1, + let current = Block(number: tuple.parentNumber + 1, hash: uselessBlockPart.hash, parentHash: uselessBlockPart.parentHash, nonce: uselessBlockPart.nonce, @@ -93,16 +93,16 @@ class EIP1559BlockTests: LocalTestCase { totalDifficulty: uselessBlockPart.totalDifficulty, extraData: uselessBlockPart.extraData, size: uselessBlockPart.size, - gasLimit: touple.currentGasLimit, - gasUsed: touple.currentGasLimit / 2, + gasLimit: tuple.currentGasLimit, + gasUsed: tuple.currentGasLimit / 2, baseFeePerGas: Web3.InitialBaseFee, timestamp: uselessBlockPart.timestamp, transactions: uselessBlockPart.transactions, uncles: uselessBlockPart.uncles) - if touple.is1559 { + if tuple.is1559 { XCTAssertTrue(Web3.isEip1559Block(parent: parent, current: current), - "Shoult not fail, got parent: \(parent.gasLimit), current: \(current.gasLimit)") + "Should not fail, got parent: \(parent.gasLimit), current: \(current.gasLimit)") } else { XCTAssertFalse(Web3.isEip1559Block(parent: parent, current: current), "Should fail, got parent: \(parent.gasLimit), current: \(current.gasLimit)") @@ -124,8 +124,8 @@ class EIP1559BlockTests: LocalTestCase { (Web3.InitialBaseFee, 12_965_000, 20000000, 11000000, 1012500000) // current above target ] - headerArray.forEach { (touple: (parentBaseFee: BigUInt, parentNumber: BigUInt, parentGasLimit: BigUInt, parentGasUsed: BigUInt, expectedBaseFee: BigUInt)) in - let parent = Block(number: touple.parentNumber, + headerArray.forEach { (tuple: (parentBaseFee: BigUInt, parentNumber: BigUInt, parentGasLimit: BigUInt, parentGasUsed: BigUInt, expectedBaseFee: BigUInt)) in + let parent = Block(number: tuple.parentNumber, hash: uselessBlockPart.hash, parentHash: uselessBlockPart.parentHash, nonce: uselessBlockPart.nonce, @@ -139,8 +139,8 @@ class EIP1559BlockTests: LocalTestCase { totalDifficulty: uselessBlockPart.totalDifficulty, extraData: uselessBlockPart.extraData, size: uselessBlockPart.size, - gasLimit: touple.parentGasLimit, - gasUsed: touple.parentGasUsed, + gasLimit: tuple.parentGasLimit, + gasUsed: tuple.parentGasUsed, baseFeePerGas: Web3.InitialBaseFee, timestamp: uselessBlockPart.timestamp, transactions: uselessBlockPart.transactions, @@ -148,7 +148,7 @@ class EIP1559BlockTests: LocalTestCase { let calculatedBaseFee = Web3.calcBaseFee(parent) - XCTAssertEqual(calculatedBaseFee, touple.expectedBaseFee, "Base fee calculation fails: should be \(touple.expectedBaseFee), got: \(String(describing: calculatedBaseFee))") + XCTAssertEqual(calculatedBaseFee, tuple.expectedBaseFee, "Base fee calculation fails: should be \(tuple.expectedBaseFee), got: \(String(describing: calculatedBaseFee))") } } } diff --git a/Tests/web3swiftTests/localTests/ERC20ClassTests.swift b/Tests/web3swiftTests/localTests/ERC20ClassTests.swift index c9ba5b75e..9c95addca 100755 --- a/Tests/web3swiftTests/localTests/ERC20ClassTests.swift +++ b/Tests/web3swiftTests/localTests/ERC20ClassTests.swift @@ -22,7 +22,7 @@ class ERC20ClassTests: LocalTestCase { } /// We had an issue with multiple async reads performed at the same point in time /// sometimes returning wrong values (actually values of each other). - /// The issue is most likely related to async/await feautre of Swift. + /// The issue is most likely related to async/await feature of Swift. /// Due to that was decided to add a loop to execute the same async calls that checks the same ERC20 properties /// multiple times. All calls must succeed. /// Each run executes 3 async read operations. diff --git a/Tests/web3swiftTests/localTests/TransactionsTests.swift b/Tests/web3swiftTests/localTests/TransactionsTests.swift index 02a560b2f..7dd9a8e65 100755 --- a/Tests/web3swiftTests/localTests/TransactionsTests.swift +++ b/Tests/web3swiftTests/localTests/TransactionsTests.swift @@ -594,7 +594,7 @@ class TransactionsTests: XCTestCase { } // ***** Legacy Tests ***** - // TODO: Replace `XCTAssert` with more explicite `XCTAssertEqual`, where Applicable + // TODO: Replace `XCTAssert` with more explicit `XCTAssertEqual`, where Applicable func testDirectTransaction() throws { do { @@ -657,7 +657,7 @@ class TransactionsTests: XCTestCase { let details = try await web3.eth.transactionDetails(txHash) - // FIXME: Reenable this test. + // FIXME: Re-enable this test. // XCTAssertEqual(details.transaction.gasLimit, BigUInt(78423)) } catch Web3Error.nodeError(let descr) { guard descr == "insufficient funds for gas * price + value" else {return XCTFail()} diff --git a/Tests/web3swiftTests/remoteTests/InfuraTests.swift b/Tests/web3swiftTests/remoteTests/InfuraTests.swift index 88d630f45..c53020293 100755 --- a/Tests/web3swiftTests/remoteTests/InfuraTests.swift +++ b/Tests/web3swiftTests/remoteTests/InfuraTests.swift @@ -94,7 +94,7 @@ class InfuraTests: XCTestCase { // let web3 = Web3.InfuraRinkebyWeb3(accessToken: Constants.infuraToken) // let contract = web3.contract(jsonString, at: contractAddress, abiVersion: 2) // guard let eventParser = contract?.createEventParser("Deposit", filter: nil) else {return XCTFail()} -// let pres = try eventParser.parseBlockByNumber(UInt64(2138657)) -// XCTAssert(pres.count == 1) +// let present = try eventParser.parseBlockByNumber(UInt64(2138657)) +// XCTAssert(present.count == 1) // } } diff --git a/Tests/web3swiftTests/remoteTests/RemoteParsingTests.swift b/Tests/web3swiftTests/remoteTests/RemoteParsingTests.swift index e42e2b2e0..b4b272b20 100755 --- a/Tests/web3swiftTests/remoteTests/RemoteParsingTests.swift +++ b/Tests/web3swiftTests/remoteTests/RemoteParsingTests.swift @@ -25,18 +25,18 @@ class RemoteParsingTests: XCTestCase { // // guard let eventParser = contract?.createEventParser("Transfer", filter: nil) else {return XCTFail()} // -// let pres = try eventParser.parseBlockByNumber(UInt64(5200088)) +// let present = try eventParser.parseBlockByNumber(UInt64(5200088)) // -// XCTAssert(pres.count == 1) +// XCTAssert(present.count == 1) // -// let decoded = pres[0].decodedResult +// let decoded = present[0].decodedResult // // XCTAssert(decoded["name"] as! String == "Transfer") // XCTAssert(decoded["_to"] as! EthereumAddress == EthereumAddress("0xa5dcf6e0fee38f635c4a8d50d90e24400ed547d2")!) // XCTAssert(decoded["_from"] as! EthereumAddress == EthereumAddress("0xdbf493e8d7db835192c02b992bd1ab72e96fd2e3")!) // XCTAssert(decoded["_value"] as! BigUInt == BigUInt("3946fe37ffce3a0000", radix: 16)!) -// XCTAssert(pres[0].contractAddress == EthereumAddress("0x45245bc59219eeaaf6cd3f382e078a461ff9de7b")!) -// XCTAssert(pres[0].transactionReceipt!.transactionHash.toHexString().addHexPrefix() == "0xcb235e8c6ecda032bc82c1084d2159ab82e7e4de35be703da6e80034bc577673") +// XCTAssert(present[0].contractAddress == EthereumAddress("0x45245bc59219eeaaf6cd3f382e078a461ff9de7b")!) +// XCTAssert(present[0].transactionReceipt!.transactionHash.toHexString().addHexPrefix() == "0xcb235e8c6ecda032bc82c1084d2159ab82e7e4de35be703da6e80034bc577673") // } // func testEventParsing2usingABIv2() throws { @@ -44,8 +44,8 @@ class RemoteParsingTests: XCTestCase { // let web3 = Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) // let contract = web3.contract(jsonString, at: nil, abiVersion: 2) // guard let eventParser = contract?.createEventParser("Transfer", filter: nil) else {return XCTFail()} -// let pres = try eventParser.parseBlockByNumber(UInt64(5200120)) -// XCTAssert(pres.count == 81) +// let present = try eventParser.parseBlockByNumber(UInt64(5200120)) +// XCTAssert(present.count == 81) // } // func testEventParsing3usingABIv2() throws { @@ -62,8 +62,8 @@ class RemoteParsingTests: XCTestCase { // } // // for i in currentBlockAsInt-1 ... currentBlockAsInt { -// let pres = try eventParser.parseBlockByNumber(i) -// for p in pres { +// let present = try eventParser.parseBlockByNumber(i) +// for p in present { // + "\n") // // .addHexPrefix() + "\n") @@ -82,8 +82,8 @@ class RemoteParsingTests: XCTestCase { // filter.addresses = [EthereumAddress("0x53066cddbc0099eb6c96785d9b3df2aaeede5da3")!] // filter.parameterFilters = [([EthereumAddress("0xefdcf2c36f3756ce7247628afdb632fa4ee12ec5")!] as [EventFilterable]), ([EthereumAddress("0xd5395c132c791a7f46fa8fc27f0ab6bacd824484")!] as [EventFilterable])] // guard let eventParser = contract?.createEventParser("Transfer", filter: filter) else {return XCTFail()} -// let pres = try eventParser.parseBlockByNumber(UInt64(5200120)) -// XCTAssert(pres.count == 1) +// let present = try eventParser.parseBlockByNumber(UInt64(5200120)) +// XCTAssert(present.count == 1) // //TODO: - Make following assert //// with filter would be //// [web3swift_iOS.EventLog(address: web3swift_iOS.EthereumAddress(_address: "0x53066cddbc0099eb6c96785d9b3df2aaeede5da3", type: web3swift_iOS.EthereumAddress.AddressType.normal), data: 32 bytes, logIndex: 132, removed: false, topics: [32 bytes, 32 bytes, 32 bytes])], status: web3swift_iOS.TransactionReceipt.TXStatus.ok, logsBloom: Optional(web3swift_iOS.EthereumBloomFilter(bytes: 256 bytes))), contractAddress: web3swift_iOS.EthereumAddress(_address: "0x53066cddbc0099eb6c96785d9b3df2aaeede5da3", type: web3swift_iOS.EthereumAddress.AddressType.normal), decodedResult: ["name": "Transfer", "1": web3swift_iOS.EthereumAddress(_address: "0xd5395c132c791a7f46fa8fc27f0ab6bacd824484", type: web3swift_iOS.EthereumAddress.AddressType.normal), "_from": web3swift_iOS.EthereumAddress(_address: "0xefdcf2c36f3756ce7247628afdb632fa4ee12ec5", type: web3swift_iOS.EthereumAddress.AddressType.normal), "_to": web3swift_iOS.EthereumAddress(_address: "0xd5395c132c791a7f46fa8fc27f0ab6bacd824484", type: web3swift_iOS.EthereumAddress.AddressType.normal), "2": 5000000000000000000, "0": web3swift_iOS.EthereumAddress(_address: "0xefdcf2c36f3756ce7247628afdb632fa4ee12ec5", type: web3swift_iOS.EthereumAddress.AddressType.normal), "_value": 5000000000000000000])] From fb796ea8d60849a242743f0a882581f335a2607b Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Jan 2023 15:15:54 +0100 Subject: [PATCH 20/49] Make typos in code --- Sources/Web3Core/KeystoreManager/IBAN.swift | 4 +-- Sources/Web3Core/Utility/Utilities.swift | 12 ++++---- Sources/web3swift/Utils/EIP/EIP712.swift | 4 +-- .../localTests/EIP1559BlockTests.swift | 28 +++++++++---------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Sources/Web3Core/KeystoreManager/IBAN.swift b/Sources/Web3Core/KeystoreManager/IBAN.swift index 164ff319f..604f7dce7 100755 --- a/Sources/Web3Core/KeystoreManager/IBAN.swift +++ b/Sources/Web3Core/KeystoreManager/IBAN.swift @@ -64,9 +64,9 @@ public struct IBAN { internal static func decodeToInts(_ iban: String) -> String { let uppercasedIBAN = iban.replacingOccurrences(of: " ", with: "").uppercased() - let beginning = String(uppercasedIBAN[0..<4]) + let begining = String(uppercasedIBAN[0..<4]) let end = String(uppercasedIBAN[4...]) - let IBAN = end + beginning + let IBAN = end + begining var arrayOfInts = [Int]() for ch in IBAN { guard let dataPoint = String(ch).data(using: .ascii) else {return ""} diff --git a/Sources/Web3Core/Utility/Utilities.swift b/Sources/Web3Core/Utility/Utilities.swift index 5a71cdd04..7b0557f6a 100644 --- a/Sources/Web3Core/Utility/Utilities.swift +++ b/Sources/Web3Core/Utility/Utilities.swift @@ -19,17 +19,17 @@ public struct Utilities { guard let decompressedKey = SECP256K1.combineSerializedPublicKeys(keys: [publicKey], outputCompressed: false) else {return nil} return publicToAddressData(decompressedKey) } - var stripped = publicKey - if stripped.count == 65 { - if stripped[0] != 4 { + var stipped = publicKey + if stipped.count == 65 { + if stipped[0] != 4 { return nil } - stripped = stripped[1...64] + stipped = stipped[1...64] } - if stripped.count != 64 { + if stipped.count != 64 { return nil } - let sha3 = stripped.sha3(.keccak256) + let sha3 = stipped.sha3(.keccak256) let addressData = sha3[12...31] return addressData } diff --git a/Sources/web3swift/Utils/EIP/EIP712.swift b/Sources/web3swift/Utils/EIP/EIP712.swift index 1bb65436f..4cb913ffd 100644 --- a/Sources/web3swift/Utils/EIP/EIP712.swift +++ b/Sources/web3swift/Utils/EIP/EIP712.swift @@ -100,7 +100,7 @@ fileprivate extension EIP712Hashable { } func encodePrimaryType() -> String { - let parameters: [String] = Mirror(reflecting: self).children.compactMap { key, value in + let parametrs: [String] = Mirror(reflecting: self).children.compactMap { key, value in guard let key = key else { return nil } func checkIfValueIsNil(value: Any) -> Bool { @@ -127,7 +127,7 @@ fileprivate extension EIP712Hashable { } return typeName + " " + key } - return name + "(" + parameters.joined(separator: ",") + ")" + return name + "(" + parametrs.joined(separator: ",") + ")" } } diff --git a/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift b/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift index 26f567017..e41c55e3f 100644 --- a/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift +++ b/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift @@ -57,8 +57,8 @@ class EIP1559BlockTests: LocalTestCase { (40_000_000, 12_965_000, 39_960_938, false) // Lower limit -1 ] - headerArray.forEach { (tuple: (parentGasLimit: BigUInt, parentNumber: BigUInt, currentGasLimit: BigUInt, is1559: Bool)) in - let parent = Block(number: tuple.parentNumber, + headerArray.forEach { (touple: (parentGasLimit: BigUInt, parentNumber: BigUInt, currentGasLimit: BigUInt, is1559: Bool)) in + let parent = Block(number: touple.parentNumber, hash: uselessBlockPart.hash, parentHash: uselessBlockPart.parentHash, nonce: uselessBlockPart.nonce, @@ -72,14 +72,14 @@ class EIP1559BlockTests: LocalTestCase { totalDifficulty: uselessBlockPart.totalDifficulty, extraData: uselessBlockPart.extraData, size: uselessBlockPart.size, - gasLimit: tuple.parentGasLimit, - gasUsed: tuple.parentGasLimit / 2, + gasLimit: touple.parentGasLimit, + gasUsed: touple.parentGasLimit / 2, baseFeePerGas: Web3.InitialBaseFee, timestamp: uselessBlockPart.timestamp, transactions: uselessBlockPart.transactions, uncles: uselessBlockPart.uncles) - let current = Block(number: tuple.parentNumber + 1, + let current = Block(number: touple.parentNumber + 1, hash: uselessBlockPart.hash, parentHash: uselessBlockPart.parentHash, nonce: uselessBlockPart.nonce, @@ -93,16 +93,16 @@ class EIP1559BlockTests: LocalTestCase { totalDifficulty: uselessBlockPart.totalDifficulty, extraData: uselessBlockPart.extraData, size: uselessBlockPart.size, - gasLimit: tuple.currentGasLimit, - gasUsed: tuple.currentGasLimit / 2, + gasLimit: touple.currentGasLimit, + gasUsed: touple.currentGasLimit / 2, baseFeePerGas: Web3.InitialBaseFee, timestamp: uselessBlockPart.timestamp, transactions: uselessBlockPart.transactions, uncles: uselessBlockPart.uncles) - if tuple.is1559 { + if touple.is1559 { XCTAssertTrue(Web3.isEip1559Block(parent: parent, current: current), - "Should not fail, got parent: \(parent.gasLimit), current: \(current.gasLimit)") + "Shoult not fail, got parent: \(parent.gasLimit), current: \(current.gasLimit)") } else { XCTAssertFalse(Web3.isEip1559Block(parent: parent, current: current), "Should fail, got parent: \(parent.gasLimit), current: \(current.gasLimit)") @@ -124,8 +124,8 @@ class EIP1559BlockTests: LocalTestCase { (Web3.InitialBaseFee, 12_965_000, 20000000, 11000000, 1012500000) // current above target ] - headerArray.forEach { (tuple: (parentBaseFee: BigUInt, parentNumber: BigUInt, parentGasLimit: BigUInt, parentGasUsed: BigUInt, expectedBaseFee: BigUInt)) in - let parent = Block(number: tuple.parentNumber, + headerArray.forEach { (touple: (parentBaseFee: BigUInt, parentNumber: BigUInt, parentGasLimit: BigUInt, parentGasUsed: BigUInt, expectedBaseFee: BigUInt)) in + let parent = Block(number: touple.parentNumber, hash: uselessBlockPart.hash, parentHash: uselessBlockPart.parentHash, nonce: uselessBlockPart.nonce, @@ -139,8 +139,8 @@ class EIP1559BlockTests: LocalTestCase { totalDifficulty: uselessBlockPart.totalDifficulty, extraData: uselessBlockPart.extraData, size: uselessBlockPart.size, - gasLimit: tuple.parentGasLimit, - gasUsed: tuple.parentGasUsed, + gasLimit: touple.parentGasLimit, + gasUsed: touple.parentGasUsed, baseFeePerGas: Web3.InitialBaseFee, timestamp: uselessBlockPart.timestamp, transactions: uselessBlockPart.transactions, @@ -148,7 +148,7 @@ class EIP1559BlockTests: LocalTestCase { let calculatedBaseFee = Web3.calcBaseFee(parent) - XCTAssertEqual(calculatedBaseFee, tuple.expectedBaseFee, "Base fee calculation fails: should be \(tuple.expectedBaseFee), got: \(String(describing: calculatedBaseFee))") + XCTAssertEqual(calculatedBaseFee, touple.expectedBaseFee, "Base fee calculation fails: should be \(touple.expectedBaseFee), got: \(String(describing: calculatedBaseFee))") } } } From 04b3cfef90db278e1c4f9dcc515b93842902f9bf Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Jan 2023 15:35:08 +0100 Subject: [PATCH 21/49] Let's spell stripped correctly --- Sources/Web3Core/Utility/Utilities.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Web3Core/Utility/Utilities.swift b/Sources/Web3Core/Utility/Utilities.swift index 7b0557f6a..5a71cdd04 100644 --- a/Sources/Web3Core/Utility/Utilities.swift +++ b/Sources/Web3Core/Utility/Utilities.swift @@ -19,17 +19,17 @@ public struct Utilities { guard let decompressedKey = SECP256K1.combineSerializedPublicKeys(keys: [publicKey], outputCompressed: false) else {return nil} return publicToAddressData(decompressedKey) } - var stipped = publicKey - if stipped.count == 65 { - if stipped[0] != 4 { + var stripped = publicKey + if stripped.count == 65 { + if stripped[0] != 4 { return nil } - stipped = stipped[1...64] + stripped = stripped[1...64] } - if stipped.count != 64 { + if stripped.count != 64 { return nil } - let sha3 = stipped.sha3(.keccak256) + let sha3 = stripped.sha3(.keccak256) let addressData = sha3[12...31] return addressData } From 987fa5e1c71b0a10d92662ff522654dc5a87c633 Mon Sep 17 00:00:00 2001 From: august Date: Wed, 1 Feb 2023 15:11:24 +0800 Subject: [PATCH 22/49] remove module_name from Web3Core.podspec --- Web3Core.podspec | 1 - 1 file changed, 1 deletion(-) diff --git a/Web3Core.podspec b/Web3Core.podspec index 80873eece..20828cdf8 100644 --- a/Web3Core.podspec +++ b/Web3Core.podspec @@ -3,7 +3,6 @@ Pod::Spec.new do |spec| spec.name = 'Web3Core' spec.version = '3.0.6' - spec.module_name = 'Core' spec.ios.deployment_target = "13.0" spec.osx.deployment_target = "10.15" spec.license = { :type => 'Apache License 2.0', :file => 'LICENSE.md' } From be3f55a1cc1a88531cc620378d130bbb3031a49a Mon Sep 17 00:00:00 2001 From: august Date: Wed, 1 Feb 2023 15:24:20 +0800 Subject: [PATCH 23/49] update Web3Core.spec source file path --- Web3Core.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Web3Core.podspec b/Web3Core.podspec index 20828cdf8..d0ded29c5 100644 --- a/Web3Core.podspec +++ b/Web3Core.podspec @@ -15,5 +15,5 @@ Pod::Spec.new do |spec| spec.dependency 'secp256k1.c', '~> 0.1' spec.dependency 'BigInt', '~> 5.2.0' # no newer version in pods. spec.dependency 'CryptoSwift', '~> 1.5.1' - spec.source_files = "Sources/Core/**/*.swift" + spec.source_files = "Sources/Web3Core/**/*.swift" end From 58b2e4fc9c982e14f852e85ae510247a96a08f44 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Wed, 1 Feb 2023 18:08:53 +0200 Subject: [PATCH 24/49] feat: convertToData handles Bool --- Sources/Web3Core/EthereumABI/ABIEncoding.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/Web3Core/EthereumABI/ABIEncoding.swift b/Sources/Web3Core/EthereumABI/ABIEncoding.swift index f62177ec8..727196a10 100755 --- a/Sources/Web3Core/EthereumABI/ABIEncoding.swift +++ b/Sources/Web3Core/EthereumABI/ABIEncoding.swift @@ -98,7 +98,7 @@ public struct ABIEncoder { /// Attempts to convert given object into `Data`. /// Used as a part of ABI encoding process. - /// Supported types are `Data`, `String`, `[UInt8]`, ``EthereumAddress`` and `[IntegerLiteralType]`. + /// Supported types are `Data`, `String`, `[UInt8]`, ``EthereumAddress``, `[IntegerLiteralType]` and `Bool`. /// 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. @@ -123,6 +123,8 @@ public struct ABIEncoder { bytesArray.append(UInt8(el)) } return Data(bytesArray) + case let b as Bool: + return b ? Data([UInt8(1)]) : Data(count: 1) default: return nil } From 5edb12d24106f53fdcddcace3aff397599749ec9 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 1 Feb 2023 17:35:18 +0100 Subject: [PATCH 25/49] chore: Let's spell parameters correctly (#745) --- Sources/web3swift/Utils/EIP/EIP712.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/web3swift/Utils/EIP/EIP712.swift b/Sources/web3swift/Utils/EIP/EIP712.swift index 4cb913ffd..1bb65436f 100644 --- a/Sources/web3swift/Utils/EIP/EIP712.swift +++ b/Sources/web3swift/Utils/EIP/EIP712.swift @@ -100,7 +100,7 @@ fileprivate extension EIP712Hashable { } func encodePrimaryType() -> String { - let parametrs: [String] = Mirror(reflecting: self).children.compactMap { key, value in + let parameters: [String] = Mirror(reflecting: self).children.compactMap { key, value in guard let key = key else { return nil } func checkIfValueIsNil(value: Any) -> Bool { @@ -127,7 +127,7 @@ fileprivate extension EIP712Hashable { } return typeName + " " + key } - return name + "(" + parametrs.joined(separator: ",") + ")" + return name + "(" + parameters.joined(separator: ",") + ")" } } From 60d789605ca60266a74aaf1d6bf7499ca6f75da8 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 1 Feb 2023 17:35:53 +0100 Subject: [PATCH 26/49] chore: Let's spell beginning correctly (#746) --- Sources/Web3Core/KeystoreManager/IBAN.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Web3Core/KeystoreManager/IBAN.swift b/Sources/Web3Core/KeystoreManager/IBAN.swift index 604f7dce7..164ff319f 100755 --- a/Sources/Web3Core/KeystoreManager/IBAN.swift +++ b/Sources/Web3Core/KeystoreManager/IBAN.swift @@ -64,9 +64,9 @@ public struct IBAN { internal static func decodeToInts(_ iban: String) -> String { let uppercasedIBAN = iban.replacingOccurrences(of: " ", with: "").uppercased() - let begining = String(uppercasedIBAN[0..<4]) + let beginning = String(uppercasedIBAN[0..<4]) let end = String(uppercasedIBAN[4...]) - let IBAN = end + begining + let IBAN = end + beginning var arrayOfInts = [Int]() for ch in IBAN { guard let dataPoint = String(ch).data(using: .ascii) else {return ""} From 4ec728f5a2d102b1b7409d1baa6323a01140f6bd Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu <36865532+JeneaVranceanu@users.noreply.github.com> Date: Wed, 1 Feb 2023 19:18:28 +0200 Subject: [PATCH 27/49] chore: refactoring of func publicToAddressData and docs --- Sources/Web3Core/Utility/Utilities.swift | 42 ++++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/Sources/Web3Core/Utility/Utilities.swift b/Sources/Web3Core/Utility/Utilities.swift index 5a71cdd04..3d347e79a 100644 --- a/Sources/Web3Core/Utility/Utilities.swift +++ b/Sources/Web3Core/Utility/Utilities.swift @@ -10,34 +10,39 @@ import BigInt public struct Utilities { - /// Convert a public key to the corresponding EthereumAddress. Accepts public keys in compressed (33 bytes), non-compressed (65 bytes) - /// or raw concat(X, Y) (64 bytes) format. + /// Convert a public key to the corresponding ``EthereumAddress``. Accepts public keys in compressed (33 bytes), uncompressed (65 bytes) + /// or uncompressed without prefix (64 bytes) format. /// - /// Returns 20 bytes of address data. + /// - Parameter publicKey: compressed 33, non-compressed (65 bytes) or non-compressed without prefix (64 bytes) + /// - Returns: 20 bytes of address data. static func publicToAddressData(_ publicKey: Data) -> Data? { + var publicKey = publicKey if publicKey.count == 33 { - guard let decompressedKey = SECP256K1.combineSerializedPublicKeys(keys: [publicKey], outputCompressed: false) else {return nil} - return publicToAddressData(decompressedKey) - } - var stripped = publicKey - if stripped.count == 65 { - if stripped[0] != 4 { + guard (publicKey[0] == 2 || publicKey[0] == 3), + let decompressedKey = SECP256K1.combineSerializedPublicKeys(keys: [publicKey], outputCompressed: false) else { return nil } - stripped = stripped[1...64] + publicKey = decompressedKey } - if stripped.count != 64 { + + if publicKey.count == 65 { + guard publicKey[0] == 4 else { + return nil + } + publicKey = publicKey[1...64] + } else if publicKey.count != 64 { return nil } - let sha3 = stripped.sha3(.keccak256) + let sha3 = publicKey.sha3(.keccak256) let addressData = sha3[12...31] return addressData } - /// Convert a public key to the corresponding EthereumAddress. Accepts public keys in compressed (33 bytes), non-compressed (65 bytes) - /// or raw concat(X, Y) (64 bytes) format. + /// Convert a public key to the corresponding ``EthereumAddress``. Accepts public keys in compressed (33 bytes), uncompressed (65 bytes) + /// or uncompressed without prefix (64 bytes) format. /// - /// Returns the EthereumAddress object. + /// - Parameter publicKey: compressed 33, non-compressed (65 bytes) or non-compressed without prefix (64 bytes) + /// - Returns: `EthereumAddress` object. public static func publicToAddress(_ publicKey: Data) -> EthereumAddress? { guard let addressData = publicToAddressData(publicKey) else {return nil} let address = addressData.toHexString().addHexPrefix().lowercased() @@ -50,10 +55,11 @@ public struct Utilities { return publicKey } - /// Convert a public key to the corresponding EthereumAddress. Accepts public keys in compressed (33 bytes), non-compressed (65 bytes) - /// or raw concat(X, Y) (64 bytes) format. + /// Convert a public key to the corresponding ``EthereumAddress``. Accepts public keys in compressed (33 bytes), uncompressed (65 bytes) + /// or uncompressed without prefix (64 bytes) format. /// - /// Returns a 0x prefixed hex string. + /// - Parameter publicKey: compressed 33, non-compressed (65 bytes) or non-compressed without prefix (64 bytes) + /// - Returns: `0x` prefixed hex string. public static func publicToAddressString(_ publicKey: Data) -> String? { guard let addressData = Utilities.publicToAddressData(publicKey) else {return nil} let address = addressData.toHexString().addHexPrefix().lowercased() From 600b8834c62b2df8c36d0a436c726eff6ba13847 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Wed, 1 Feb 2023 19:22:18 +0200 Subject: [PATCH 28/49] test: added test cases for `func publicToAddress` --- .../localTests/UtilitiesTests.swift | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Tests/web3swiftTests/localTests/UtilitiesTests.swift b/Tests/web3swiftTests/localTests/UtilitiesTests.swift index 53a6761fc..5751afde0 100644 --- a/Tests/web3swiftTests/localTests/UtilitiesTests.swift +++ b/Tests/web3swiftTests/localTests/UtilitiesTests.swift @@ -47,4 +47,39 @@ class UtilitiesTests: XCTestCase { XCTAssertEqual(test.input.decimals, test.output) } } + + func testPublicKeyWithNoPrefixToAddress() throws { + var address = Utilities.publicToAddress(Data.fromHex("0x18ed2e1ec629e2d3dae7be1103d4f911c24e0c80e70038f5eb5548245c475f504c220d01e1ca419cb1ba4b3393b615e99dd20aa6bf071078f70fd949008e7411")!)?.address + XCTAssertEqual(address, "0x28828f43df370651AC5A6cFd02fBD0885Fbb3c00") + address = Utilities.publicToAddress(Data.fromHex("0x52972572d465d016d4c501887b8df303eee3ed602c056b1eb09260dfa0da0ab288742f4dc97d9edb6fd946babc002fdfb06f26caf117b9405ed79275763fdb1c")!)?.address + XCTAssertEqual(address, "0x6eDBe1F6D48FbF1b053D6c9FA7997C710B84f55F") + } + + func testPublicKeyWithPrefixToAddress() throws { + var address = Utilities.publicToAddress(Data.fromHex("0x0418ed2e1ec629e2d3dae7be1103d4f911c24e0c80e70038f5eb5548245c475f504c220d01e1ca419cb1ba4b3393b615e99dd20aa6bf071078f70fd949008e7411")!)?.address + XCTAssertEqual(address, "0x28828f43df370651AC5A6cFd02fBD0885Fbb3c00") + address = Utilities.publicToAddress(Data.fromHex("0x0452972572d465d016d4c501887b8df303eee3ed602c056b1eb09260dfa0da0ab288742f4dc97d9edb6fd946babc002fdfb06f26caf117b9405ed79275763fdb1c")!)?.address + XCTAssertEqual(address, "0x6eDBe1F6D48FbF1b053D6c9FA7997C710B84f55F") + } + + func testPublicKeyWithInvalidPrefixToAddress() throws { + var address = Utilities.publicToAddress(Data.fromHex("0x0318ed2e1ec629e2d3dae7be1103d4f911c24e0c80e70038f5eb5548245c475f504c220d01e1ca419cb1ba4b3393b615e99dd20aa6bf071078f70fd949008e7411")!)?.address + XCTAssertEqual(address, nil) + address = Utilities.publicToAddress(Data.fromHex("0x0152972572d465d016d4c501887b8df303eee3ed602c056b1eb09260dfa0da0ab288742f4dc97d9edb6fd946babc002fdfb06f26caf117b9405ed79275763fdb1c")!)?.address + XCTAssertEqual(address, nil) + } + + func testCompressedPublicKeyToAddress() throws { + var address = Utilities.publicToAddress(Data.fromHex("0x0318ed2e1ec629e2d3dae7be1103d4f911c24e0c80e70038f5eb5548245c475f50")!)?.address + XCTAssertEqual(address, "0x28828f43df370651AC5A6cFd02fBD0885Fbb3c00") + address = Utilities.publicToAddress(Data.fromHex("0x0252972572d465d016d4c501887b8df303eee3ed602c056b1eb09260dfa0da0ab2")!)?.address + XCTAssertEqual(address, "0x6eDBe1F6D48FbF1b053D6c9FA7997C710B84f55F") + } + + func testCompressedPublicKeyWithInvalidPrefixToAddress() throws { + var address = Utilities.publicToAddress(Data.fromHex("0x0718ed2e1ec629e2d3dae7be1103d4f911c24e0c80e70038f5eb5548245c475f50")!)?.address + XCTAssertEqual(address, nil) + address = Utilities.publicToAddress(Data.fromHex("0x0852972572d465d016d4c501887b8df303eee3ed602c056b1eb09260dfa0da0ab2")!)?.address + XCTAssertEqual(address, nil) + } } From 83491520b76973e7f60e25f75812826ed59a10fb Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 1 Feb 2023 18:25:56 +0100 Subject: [PATCH 29/49] chore: Let's spell tuple correctly (#748) --- .../localTests/EIP1559BlockTests.swift | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift b/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift index e41c55e3f..e99dc837b 100644 --- a/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift +++ b/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift @@ -57,8 +57,8 @@ class EIP1559BlockTests: LocalTestCase { (40_000_000, 12_965_000, 39_960_938, false) // Lower limit -1 ] - headerArray.forEach { (touple: (parentGasLimit: BigUInt, parentNumber: BigUInt, currentGasLimit: BigUInt, is1559: Bool)) in - let parent = Block(number: touple.parentNumber, + headerArray.forEach { (tuple: (parentGasLimit: BigUInt, parentNumber: BigUInt, currentGasLimit: BigUInt, is1559: Bool)) in + let parent = Block(number: tuple.parentNumber, hash: uselessBlockPart.hash, parentHash: uselessBlockPart.parentHash, nonce: uselessBlockPart.nonce, @@ -72,14 +72,14 @@ class EIP1559BlockTests: LocalTestCase { totalDifficulty: uselessBlockPart.totalDifficulty, extraData: uselessBlockPart.extraData, size: uselessBlockPart.size, - gasLimit: touple.parentGasLimit, - gasUsed: touple.parentGasLimit / 2, + gasLimit: tuple.parentGasLimit, + gasUsed: tuple.parentGasLimit / 2, baseFeePerGas: Web3.InitialBaseFee, timestamp: uselessBlockPart.timestamp, transactions: uselessBlockPart.transactions, uncles: uselessBlockPart.uncles) - let current = Block(number: touple.parentNumber + 1, + let current = Block(number: tuple.parentNumber + 1, hash: uselessBlockPart.hash, parentHash: uselessBlockPart.parentHash, nonce: uselessBlockPart.nonce, @@ -93,14 +93,14 @@ class EIP1559BlockTests: LocalTestCase { totalDifficulty: uselessBlockPart.totalDifficulty, extraData: uselessBlockPart.extraData, size: uselessBlockPart.size, - gasLimit: touple.currentGasLimit, - gasUsed: touple.currentGasLimit / 2, + gasLimit: tuple.currentGasLimit, + gasUsed: tuple.currentGasLimit / 2, baseFeePerGas: Web3.InitialBaseFee, timestamp: uselessBlockPart.timestamp, transactions: uselessBlockPart.transactions, uncles: uselessBlockPart.uncles) - if touple.is1559 { + if tuple.is1559 { XCTAssertTrue(Web3.isEip1559Block(parent: parent, current: current), "Shoult not fail, got parent: \(parent.gasLimit), current: \(current.gasLimit)") } else { @@ -124,8 +124,8 @@ class EIP1559BlockTests: LocalTestCase { (Web3.InitialBaseFee, 12_965_000, 20000000, 11000000, 1012500000) // current above target ] - headerArray.forEach { (touple: (parentBaseFee: BigUInt, parentNumber: BigUInt, parentGasLimit: BigUInt, parentGasUsed: BigUInt, expectedBaseFee: BigUInt)) in - let parent = Block(number: touple.parentNumber, + headerArray.forEach { (tuple: (parentBaseFee: BigUInt, parentNumber: BigUInt, parentGasLimit: BigUInt, parentGasUsed: BigUInt, expectedBaseFee: BigUInt)) in + let parent = Block(number: tuple.parentNumber, hash: uselessBlockPart.hash, parentHash: uselessBlockPart.parentHash, nonce: uselessBlockPart.nonce, @@ -139,8 +139,8 @@ class EIP1559BlockTests: LocalTestCase { totalDifficulty: uselessBlockPart.totalDifficulty, extraData: uselessBlockPart.extraData, size: uselessBlockPart.size, - gasLimit: touple.parentGasLimit, - gasUsed: touple.parentGasUsed, + gasLimit: tuple.parentGasLimit, + gasUsed: tuple.parentGasUsed, baseFeePerGas: Web3.InitialBaseFee, timestamp: uselessBlockPart.timestamp, transactions: uselessBlockPart.transactions, @@ -148,7 +148,7 @@ class EIP1559BlockTests: LocalTestCase { let calculatedBaseFee = Web3.calcBaseFee(parent) - XCTAssertEqual(calculatedBaseFee, touple.expectedBaseFee, "Base fee calculation fails: should be \(touple.expectedBaseFee), got: \(String(describing: calculatedBaseFee))") + XCTAssertEqual(calculatedBaseFee, tuple.expectedBaseFee, "Base fee calculation fails: should be \(tuple.expectedBaseFee), got: \(String(describing: calculatedBaseFee))") } } } From 44e5965fc057d59fa3b3d84a982f535b00ce5d09 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Wed, 1 Feb 2023 22:18:43 +0200 Subject: [PATCH 30/49] fix: attempt to encode uint with a negative value results in a crash --- Sources/Web3Core/EthereumABI/ABIEncoding.swift | 16 ++++------------ .../localTests/ABIEncoderTest.swift | 10 ++++++++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Sources/Web3Core/EthereumABI/ABIEncoding.swift b/Sources/Web3Core/EthereumABI/ABIEncoding.swift index f62177ec8..6005214a0 100755 --- a/Sources/Web3Core/EthereumABI/ABIEncoding.swift +++ b/Sources/Web3Core/EthereumABI/ABIEncoding.swift @@ -218,19 +218,11 @@ public struct ABIEncoder { public static func encodeSingleType(type: ABI.Element.ParameterType, value: AnyObject) -> Data? { switch type { case .uint: - if let biguint = convertToBigUInt(value) { - return biguint.abiEncode(bits: 256) - } - if let bigint = convertToBigInt(value) { - return bigint.abiEncode(bits: 256) - } + let biguint = convertToBigUInt(value) + return biguint == nil ? nil : biguint!.abiEncode(bits: 256) case .int: - if let biguint = convertToBigUInt(value) { - return biguint.abiEncode(bits: 256) - } - if let bigint = convertToBigInt(value) { - return bigint.abiEncode(bits: 256) - } + let bigint = convertToBigInt(value) + return bigint == nil ? nil : bigint!.abiEncode(bits: 256) case .address: if let string = value as? String { guard let address = EthereumAddress(string) else {return nil} diff --git a/Tests/web3swiftTests/localTests/ABIEncoderTest.swift b/Tests/web3swiftTests/localTests/ABIEncoderTest.swift index 3f69fb2db..73fabe701 100644 --- a/Tests/web3swiftTests/localTests/ABIEncoderTest.swift +++ b/Tests/web3swiftTests/localTests/ABIEncoderTest.swift @@ -14,6 +14,16 @@ import BigInt class ABIEncoderTest: XCTestCase { + func testEncodeInt() { + XCTAssertEqual(ABIEncoder.encodeSingleType(type: .int(bits: 32), value: -10 as AnyObject)?.toHexString(), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6") + XCTAssertEqual(ABIEncoder.encodeSingleType(type: .int(bits: 32), value: 10 as AnyObject)?.toHexString(), "000000000000000000000000000000000000000000000000000000000000000a") + } + + func testEncodeUInt() { + XCTAssertEqual(ABIEncoder.encodeSingleType(type: .uint(bits: 32), value: -10 as AnyObject), nil) + XCTAssertEqual(ABIEncoder.encodeSingleType(type: .uint(bits: 32), value: 10 as AnyObject)?.toHexString(), "000000000000000000000000000000000000000000000000000000000000000a") + } + func testSoliditySha3() throws { var hex = try ABIEncoder.soliditySha3(true).toHexString().addHexPrefix() assert(hex == "0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2") From b32bcb3f24684af247b6a336a92099c3af03bf59 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 2 Feb 2023 00:22:57 +0100 Subject: [PATCH 31/49] GitHub Actions: Add codespell to find typos Use https://github.com/codespell-project/actions-codespell to discover typos like #743, #745, #746, #747, #748 --- .github/workflows/macOS-tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/macOS-tests.yml b/.github/workflows/macOS-tests.yml index 749ce9e55..b9da49623 100644 --- a/.github/workflows/macOS-tests.yml +++ b/.github/workflows/macOS-tests.yml @@ -34,6 +34,10 @@ jobs: cancel-in-progress: false steps: - uses: actions/checkout@v3 + - uses: codespell-project/actions-codespell@v1 + with: + ignore_words_list: ans,deriver,inout,packag + skip: "*.js,*WordLists.swift" - name: Resolve dependencies run: swift package resolve - name: Build From 239f17c0e47f84ac3e425452a1ec917657176245 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 2 Feb 2023 00:26:09 +0100 Subject: [PATCH 32/49] pip install codespell --- .github/workflows/macOS-tests.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/macOS-tests.yml b/.github/workflows/macOS-tests.yml index b9da49623..5ca4f97b0 100644 --- a/.github/workflows/macOS-tests.yml +++ b/.github/workflows/macOS-tests.yml @@ -34,10 +34,9 @@ jobs: cancel-in-progress: false steps: - uses: actions/checkout@v3 - - uses: codespell-project/actions-codespell@v1 - with: - ignore_words_list: ans,deriver,inout,packag - skip: "*.js,*WordLists.swift" + - run: | + pip install codespell + codespell --count --ignore-words-list=ans,deriver,inout,packag --skip="*.js,*WordLists.swift" - name: Resolve dependencies run: swift package resolve - name: Build From 3f1f80a09ee6d73442053bd2edbdb8aff383ae61 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 2 Feb 2023 00:28:00 +0100 Subject: [PATCH 33/49] Update macOS-tests.yml --- .github/workflows/macOS-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macOS-tests.yml b/.github/workflows/macOS-tests.yml index 5ca4f97b0..707ea5278 100644 --- a/.github/workflows/macOS-tests.yml +++ b/.github/workflows/macOS-tests.yml @@ -35,7 +35,7 @@ jobs: steps: - uses: actions/checkout@v3 - run: | - pip install codespell + pip3 install codespell || python3 -m pip install codespell codespell --count --ignore-words-list=ans,deriver,inout,packag --skip="*.js,*WordLists.swift" - name: Resolve dependencies run: swift package resolve From 2af0c29d31f74ec30558543f7cfc1646e4ee5a3c Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 2 Feb 2023 00:31:03 +0100 Subject: [PATCH 34/49] Update macOS-tests.yml --- .github/workflows/macOS-tests.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/macOS-tests.yml b/.github/workflows/macOS-tests.yml index 707ea5278..9c842cd4f 100644 --- a/.github/workflows/macOS-tests.yml +++ b/.github/workflows/macOS-tests.yml @@ -34,8 +34,10 @@ jobs: cancel-in-progress: false steps: - uses: actions/checkout@v3 - - run: | - pip3 install codespell || python3 -m pip install codespell + - name: Discover typos + run: | + pip3 install --upgrade pip + pip3 install codespell codespell --count --ignore-words-list=ans,deriver,inout,packag --skip="*.js,*WordLists.swift" - name: Resolve dependencies run: swift package resolve From 7226a7957027b939663116e67a5afbabdec8a426 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 2 Feb 2023 00:32:22 +0100 Subject: [PATCH 35/49] Let's spell should correctly --- Tests/web3swiftTests/localTests/EIP1559BlockTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift b/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift index e99dc837b..26f567017 100644 --- a/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift +++ b/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift @@ -102,7 +102,7 @@ class EIP1559BlockTests: LocalTestCase { if tuple.is1559 { XCTAssertTrue(Web3.isEip1559Block(parent: parent, current: current), - "Shoult not fail, got parent: \(parent.gasLimit), current: \(current.gasLimit)") + "Should not fail, got parent: \(parent.gasLimit), current: \(current.gasLimit)") } else { XCTAssertFalse(Web3.isEip1559Block(parent: parent, current: current), "Should fail, got parent: \(parent.gasLimit), current: \(current.gasLimit)") From 1ac6df5b9b0ccb100c5b43d264938e96ab8a5c74 Mon Sep 17 00:00:00 2001 From: august Date: Thu, 2 Feb 2023 11:08:32 +0800 Subject: [PATCH 36/49] update podspec version --- Web3Core.podspec | 2 +- web3swift.podspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Web3Core.podspec b/Web3Core.podspec index d0ded29c5..df71e5207 100644 --- a/Web3Core.podspec +++ b/Web3Core.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |spec| spec.compiler_flags = '-DCOCOAPODS' spec.name = 'Web3Core' - spec.version = '3.0.6' + spec.version = '3.1.0' spec.ios.deployment_target = "13.0" spec.osx.deployment_target = "10.15" spec.license = { :type => 'Apache License 2.0', :file => 'LICENSE.md' } diff --git a/web3swift.podspec b/web3swift.podspec index 48d930d88..475718533 100755 --- a/web3swift.podspec +++ b/web3swift.podspec @@ -1,4 +1,4 @@ -WEB3CORE_VERSION ||= '3.0.6' +WEB3CORE_VERSION ||= '3.1.0' Pod::Spec.new do |spec| spec.name = 'web3swift' From 08f3d00d0c71f0120e1e14723e3d901d131e2df0 Mon Sep 17 00:00:00 2001 From: JD Date: Thu, 2 Feb 2023 12:22:56 +0100 Subject: [PATCH 37/49] Delete again --- Sources/Core/EthereumABI/ABIElements.swift | 394 --------------------- 1 file changed, 394 deletions(-) delete mode 100755 Sources/Core/EthereumABI/ABIElements.swift diff --git a/Sources/Core/EthereumABI/ABIElements.swift b/Sources/Core/EthereumABI/ABIElements.swift deleted file mode 100755 index 8d01d6f5b..000000000 --- a/Sources/Core/EthereumABI/ABIElements.swift +++ /dev/null @@ -1,394 +0,0 @@ -// -// Created by Alex Vlasov on 25/10/2018. -// Copyright © 2018 Alex Vlasov. All rights reserved. -// - -import Foundation -import BigInt - -public extension ABI { - struct Input: Decodable { - public var name: String? - public var type: String - public var indexed: Bool? - public var components: [Input]? - } - - struct Output: Decodable { - public var name: String? - public var type: String - public var components: [Output]? - } - - struct Record: Decodable { - public var name: String? - public var type: String? - public var payable: Bool? - public var constant: Bool? - public var stateMutability: String? - public var inputs: [ABI.Input]? - public var outputs: [ABI.Output]? - public var anonymous: Bool? - } - - enum Element { - public enum ArraySize { // bytes for convenience - case staticSize(UInt64) - case dynamicSize - case notArray - } - - case function(Function) - case constructor(Constructor) - case fallback(Fallback) - case event(Event) - case receive(Receive) - case error(EthError) - - public enum StateMutability { - case payable - case mutating - case view - case pure - - var isConstant: Bool { - switch self { - case .payable: - return false - case .mutating: - return false - default: - return true - } - } - - var isPayable: Bool { - switch self { - case .payable: - return true - default: - return false - } - } - } - - public struct InOut { - public let name: String - public let type: ParameterType - - public init(name: String, type: ParameterType) { - self.name = name - self.type = type - } - } - - public struct Function { - public let name: String? - public let inputs: [InOut] - public let outputs: [InOut] - public let stateMutability: StateMutability? = nil - public let constant: Bool - public let payable: Bool - - public init(name: String?, inputs: [InOut], outputs: [InOut], constant: Bool, payable: Bool) { - self.name = name - self.inputs = inputs - self.outputs = outputs - self.constant = constant - self.payable = payable - } - } - - public struct Constructor { - public let inputs: [InOut] - public let constant: Bool - public let payable: Bool - public init(inputs: [InOut], constant: Bool, payable: Bool) { - self.inputs = inputs - self.constant = constant - self.payable = payable - } - } - - public struct Fallback { - public let constant: Bool - public let payable: Bool - - public init(constant: Bool, payable: Bool) { - self.constant = constant - self.payable = payable - } - } - - public struct Event { - public let name: String - public let inputs: [Input] - public let anonymous: Bool - - public init(name: String, inputs: [Input], anonymous: Bool) { - self.name = name - self.inputs = inputs - self.anonymous = anonymous - } - - public struct Input { - public let name: String - public let type: ParameterType - public let indexed: Bool - - public init(name: String, type: ParameterType, indexed: Bool) { - self.name = name - self.type = type - self.indexed = indexed - } - } - } - public struct Receive { - public let payable: Bool - public let inputs: [InOut] - - public init(inputs: [InOut], payable: Bool) { - self.inputs = inputs - self.payable = payable - } - } - /// Custom structured error type available since solidity 0.8.4 - public struct EthError { - public let name: String - public let inputs: [Input] - - public struct Input { - public let name: String - public let type: ParameterType - - public init(name: String, type: ParameterType) { - self.name = name - self.type = type - } - } - } - } -} - -// MARK: - Function parameters encoding - -extension ABI.Element { - public func encodeParameters(_ parameters: [Any]) -> Data? { - switch self { - case .constructor(let constructor): - return constructor.encodeParameters(parameters) - case .event: - return nil - case .fallback: - return nil - case .function(let function): - return function.encodeParameters(parameters) - case .receive: - return nil - case .error: - return nil - } - } -} - -extension ABI.Element.Constructor { - public func encodeParameters(_ parameters: [Any]) -> Data? { - guard parameters.count == inputs.count else { return nil } - return ABIEncoder.encode(types: inputs, values: parameters) - } -} - -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: [Any]) -> Data? { - guard parameters.count == inputs.count, - let data = ABIEncoder.encode(types: inputs, values: parameters) else { return nil } - return methodEncoding + data - } -} - -// MARK: - Event logs decoding - -extension ABI.Element.Event { - public func decodeReturnedLogs(eventLogTopics: [Data], eventLogData: Data) -> [String: Any]? { - guard let eventContent = ABIDecoder.decodeLog(event: self, eventLogTopics: eventLogTopics, eventLogData: eventLogData) else {return nil} - return eventContent - } -} - -// MARK: - Function input/output decoding - -extension ABI.Element { - public func decodeReturnData(_ data: Data) -> [String: Any]? { - switch self { - case .constructor: - return nil - case .event: - return nil - case .fallback: - return nil - case .function(let function): - return function.decodeReturnData(data) - case .receive: - return nil - case .error: - return nil - } - } - - public func decodeInputData(_ data: Data) -> [String: Any]? { - guard data.count == 0 || data.count % 32 == 4 else { return nil } - - switch self { - case .constructor(let constructor): - return constructor.decodeInputData(data) - case .event: - return nil - case .fallback: - return nil - case .function(let function): - return function.decodeInputData(data) - case .receive: - return nil - case .error: - return nil - } - } -} - -extension ABI.Element.Function { - public func decodeInputData(_ rawData: Data) -> [String: Any]? { - return Core.decodeInputData(rawData, methodEncoding: methodEncoding, inputs: inputs) - } - - public func decodeReturnData(_ data: Data) -> [String: Any]? { - // the response size greater than equal 100 bytes, when read function aborted by "require" statement. - // if "require" statement has no message argument, the response is empty (0 byte). - if data.bytes.count >= 100 { - let check00_31 = BigUInt("08C379A000000000000000000000000000000000000000000000000000000000", radix: 16)! - let check32_63 = BigUInt("0000002000000000000000000000000000000000000000000000000000000000", radix: 16)! - - // check data[00-31] and data[32-63] - if check00_31 == BigUInt(data[0...31]) && check32_63 == BigUInt(data[32...63]) { - // data.bytes[64-67] contains the length of require message - let len = (Int(data.bytes[64])<<24) | (Int(data.bytes[65])<<16) | (Int(data.bytes[66])<<8) | Int(data.bytes[67]) - - let message = String(bytes: data.bytes[68..<(68+len)], encoding: .utf8)! - - var returnArray = [String: Any]() - - // set information - returnArray["_abortedByRequire"] = true - returnArray["_errorMessageFromRequire"] = message - - // set empty values - for i in 0 ..< outputs.count { - let name = "\(i)" - returnArray[name] = outputs[i].type.emptyValue - if outputs[i].name != "" { - returnArray[outputs[i].name] = outputs[i].type.emptyValue - } - } - - return returnArray - } - } - - var returnArray = [String: Any]() - - // the "require" statement with no message argument will be caught here - if data.count == 0 && outputs.count == 1 { - let name = "0" - let value = outputs[0].type.emptyValue - returnArray[name] = value - if outputs[0].name != "" { - returnArray[outputs[0].name] = value - } - } else { - guard outputs.count * 32 <= data.count else { return nil } - - var i = 0 - guard let values = ABIDecoder.decode(types: outputs, data: data) else { return nil } - for output in outputs { - let name = "\(i)" - returnArray[name] = values[i] - if output.name != "" { - returnArray[output.name] = values[i] - } - i = i + 1 - } - // set a flag to detect the request succeeded - } - - if returnArray.isEmpty { - return nil - } - - returnArray["_success"] = true - return returnArray - } -} - -extension ABI.Element.Constructor { - public func decodeInputData(_ rawData: Data) -> [String: Any]? { - return Core.decodeInputData(rawData, inputs: inputs) - } -} - -/// Generic input decoding function. -/// - Parameters: -/// - rawData: data to decode. Must match the following criteria: `data.count == 0 || data.count % 32 == 4`. -/// - methodEncoding: 4 bytes representing method signature like `0xFFffFFff`. Can be omitted to avoid checking method encoding. -/// - inputs: expected input types. Order must be the same as in function declaration. -/// - Returns: decoded dictionary of input arguments mapped to their indices and arguments' names if these are not empty. -/// If decoding of at least one argument fails, `rawData` size is invalid or `methodEncoding` doesn't match - `nil` is returned. -private func decodeInputData(_ rawData: Data, - methodEncoding: Data? = nil, - inputs: [ABI.Element.InOut]) -> [String: Any]? { - let data: Data - let sig: Data? - - switch rawData.count % 32 { - case 0: - sig = nil - data = Data() - break - case 4: - sig = rawData[0 ..< 4] - data = Data(rawData[4 ..< rawData.count]) - default: - return nil - } - - if methodEncoding != nil && sig != nil && sig != methodEncoding { - return nil - } - - var returnArray = [String: Any]() - - if data.count == 0 && inputs.count == 1 { - let name = "0" - let value = inputs[0].type.emptyValue - returnArray[name] = value - if inputs[0].name != "" { - returnArray[inputs[0].name] = value - } - } else { - guard inputs.count * 32 <= data.count else { return nil } - - var i = 0 - guard let values = ABIDecoder.decode(types: inputs, data: data) else {return nil} - for input in inputs { - let name = "\(i)" - returnArray[name] = values[i] - if input.name != "" { - returnArray[input.name] = values[i] - } - i = i + 1 - } - } - return returnArray -} From e29826325c1b0f60731064cc3ba1f66471e71d33 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 2 Feb 2023 23:50:35 +0100 Subject: [PATCH 38/49] =?UTF-8?q?Let=E2=80=99s=20spell=20parameters=20corr?= =?UTF-8?q?ectly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/web3swift/Utils/EIP/EIP681.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/web3swift/Utils/EIP/EIP681.swift b/Sources/web3swift/Utils/EIP/EIP681.swift index 1882420a4..264dc5d37 100755 --- a/Sources/web3swift/Utils/EIP/EIP681.swift +++ b/Sources/web3swift/Utils/EIP/EIP681.swift @@ -240,7 +240,7 @@ extension Web3 { // 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. + /// Note: that ENS addresses as parameters 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. From 61a8f6cbaec1cc237cc79daf58373e505ee55ed5 Mon Sep 17 00:00:00 2001 From: Vaishali Desai Date: Sun, 5 Feb 2023 20:55:33 +0000 Subject: [PATCH 39/49] swapped the order of spm and cocoapods --- README.md | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index ad57bfe93..dad6960ea 100755 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ - [Core features](#core-features) - [Installation](#installation) - - [CocoaPods](#cocoapods) - [Swift Package](#swift-package) + - [CocoaPods](#cocoapods) - [Example usage](#example-usage) - [Send Ether](#send-ether) - [Contract read method](#contract-read-method) @@ -66,6 +66,24 @@ ## Installation +### Swift Package +The [Swift Package Manager](https://swift.org/package-manager/ "") is a tool for automating the distribution of Swift code and is integrated into the swift compiler. + +Once you have your Swift package set up, adding Alamofire as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`. +```swift +dependencies: [ + .package(url: "https://github.com/web3swift-team/web3swift.git", .upToNextMajor(from: "3.0.0")) +] +``` + +## Example usage +In the imports section: + +```swift +import web3swift +import Web3Core +``` + ### CocoaPods [CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command: @@ -91,23 +109,6 @@ Then, run the following command: $ pod install ``` -### Swift Package -The [Swift Package Manager](https://swift.org/package-manager/ "") is a tool for automating the distribution of Swift code and is integrated into the swift compiler. - -Once you have your Swift package set up, adding Alamofire as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`. -```swift -dependencies: [ - .package(url: "https://github.com/web3swift-team/web3swift.git", .upToNextMajor(from: "3.0.0")) -] -``` - -## Example usage -In the imports section: - -```swift -import web3swift -import Web3Core -``` ### Send Ether ```swift From 6d226237f673aec9bdf9aeae81aebc192257cd1d Mon Sep 17 00:00:00 2001 From: Vaishali Desai Date: Sun, 5 Feb 2023 20:55:42 +0000 Subject: [PATCH 40/49] added warning for cocoapods --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index dad6960ea..4d47fde1c 100755 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ Then, run the following command: $ pod install ``` +> **WARNING**: CocoaPods is a powerful tool for managing dependencies in iOS development, but it also has some limitations that need to be considered such as its limited control over dependencies, lack of transparency, complex setup and slow performance. ### Send Ether ```swift From 66558d3e640243b9d94456b72f97483d3e34fb60 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu <36865532+JeneaVranceanu@users.noreply.github.com> Date: Mon, 6 Feb 2023 00:21:04 +0200 Subject: [PATCH 41/49] fix: README SPM - mention web3swift instead of Alamofire --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d47fde1c..72583cfee 100755 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ ### Swift Package The [Swift Package Manager](https://swift.org/package-manager/ "") is a tool for automating the distribution of Swift code and is integrated into the swift compiler. -Once you have your Swift package set up, adding Alamofire as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`. +Once you have your Swift package set up, adding `web3swift` as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`. ```swift dependencies: [ .package(url: "https://github.com/web3swift-team/web3swift.git", .upToNextMajor(from: "3.0.0")) From d1ba3706b73542fb395ef6ca65760a4883a66492 Mon Sep 17 00:00:00 2001 From: Vaishali Desai Date: Mon, 6 Feb 2023 19:12:17 +0000 Subject: [PATCH 42/49] Updated recommended words --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 72583cfee..e5b0d26dd 100755 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ ## Installation -### Swift Package +### Swift Package (Recommended) The [Swift Package Manager](https://swift.org/package-manager/ "") is a tool for automating the distribution of Swift code and is integrated into the swift compiler. Once you have your Swift package set up, adding `web3swift` as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`. @@ -109,7 +109,7 @@ Then, run the following command: $ pod install ``` -> **WARNING**: CocoaPods is a powerful tool for managing dependencies in iOS development, but it also has some limitations that need to be considered such as its limited control over dependencies, lack of transparency, complex setup and slow performance. +> **WARNING**: CocoaPods is a powerful tool for managing dependencies in iOS development, but it also has some limitations that need to be considered such as its limited control over dependencies, lack of transparency, complex setup and slow performance. We highly recommend using SPM first as using CocoaPods will delay new updates and bug fixes being delivered to you. ### Send Ether ```swift From 61e2f01c88677bea04a49309eececd8692e73520 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu <36865532+JeneaVranceanu@users.noreply.github.com> Date: Mon, 6 Feb 2023 21:49:09 +0200 Subject: [PATCH 43/49] chore: a few clarifications --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e5b0d26dd..5b4cf4c5d 100755 --- a/README.md +++ b/README.md @@ -67,9 +67,9 @@ ## Installation ### Swift Package (Recommended) -The [Swift Package Manager](https://swift.org/package-manager/ "") is a tool for automating the distribution of Swift code and is integrated into the swift compiler. +The [Swift Package Manager](https://swift.org/package-manager/ "") is a tool for automating the distribution of Swift code that is well integrated with Swift build system. -Once you have your Swift package set up, adding `web3swift` as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`. +Once you have your Swift project set up, adding `web3swift` as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`. ```swift dependencies: [ .package(url: "https://github.com/web3swift-team/web3swift.git", .upToNextMajor(from: "3.0.0")) From 592d6ce616c7418abb28f3d1ab69c9137110acc3 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu <36865532+JeneaVranceanu@users.noreply.github.com> Date: Mon, 6 Feb 2023 21:54:35 +0200 Subject: [PATCH 44/49] chore: fixed wrong update; added explanation reference about adding packages --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b4cf4c5d..ed5d31cb8 100755 --- a/README.md +++ b/README.md @@ -69,13 +69,16 @@ ### Swift Package (Recommended) The [Swift Package Manager](https://swift.org/package-manager/ "") is a tool for automating the distribution of Swift code that is well integrated with Swift build system. -Once you have your Swift project set up, adding `web3swift` as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`. +Once you have your Swift package set up, adding `web3swift` as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`. ```swift dependencies: [ .package(url: "https://github.com/web3swift-team/web3swift.git", .upToNextMajor(from: "3.0.0")) ] ``` +Or if your project is not a package follow these guidelines on [how to add a Swift Package to your Xcode project](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app). + + ## Example usage In the imports section: From 081a552887850ab1883a33e112fdb70eaa0adb0b Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Tue, 7 Feb 2023 19:23:48 +0700 Subject: [PATCH 45/49] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ed5d31cb8..f7f7187be 100755 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ Then, run the following command: $ pod install ``` -> **WARNING**: CocoaPods is a powerful tool for managing dependencies in iOS development, but it also has some limitations that need to be considered such as its limited control over dependencies, lack of transparency, complex setup and slow performance. We highly recommend using SPM first as using CocoaPods will delay new updates and bug fixes being delivered to you. +> **WARNING**: CocoaPods is a powerful tool for managing dependencies in iOS development, but it also has some limitations that preventing us of providing first class support there. We highly recommend using SPM first as using CocoaPods will delay new updates and bug fixes being delivered to you. ### Send Ether ```swift From b0425af20ff307c0e0784b0ff56dad154d444d5c Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Tue, 7 Feb 2023 20:08:03 +0700 Subject: [PATCH 46/49] Moved the `decodeInputData(:methodEncoding:inputs)` method into `ABI.Element` type thus it prevents Cocoapods to build. --- .../Web3Core/EthereumABI/ABIElements.swift | 102 +++++++++--------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/Sources/Web3Core/EthereumABI/ABIElements.swift b/Sources/Web3Core/EthereumABI/ABIElements.swift index 7db0ca31a..1b04d0f23 100755 --- a/Sources/Web3Core/EthereumABI/ABIElements.swift +++ b/Sources/Web3Core/EthereumABI/ABIElements.swift @@ -262,7 +262,7 @@ extension ABI.Element { extension ABI.Element.Function { public func decodeInputData(_ rawData: Data) -> [String: Any]? { - return Web3Core.decodeInputData(rawData, methodEncoding: methodEncoding, inputs: inputs) + return ABI.Element.decodeInputData(rawData, methodEncoding: methodEncoding, inputs: inputs) } /// Decodes data returned by a function call. Able to decode `revert(string)`, `revert CustomError(...)` and `require(expression, string)` calls. @@ -432,61 +432,63 @@ extension ABI.Element.Function { extension ABI.Element.Constructor { public func decodeInputData(_ rawData: Data) -> [String: Any]? { - return Web3Core.decodeInputData(rawData, inputs: inputs) + return ABI.Element.decodeInputData(rawData, inputs: inputs) } } -/// Generic input decoding function. -/// - Parameters: -/// - rawData: data to decode. Must match the following criteria: `data.count == 0 || data.count % 32 == 4`. -/// - methodEncoding: 4 bytes representing method signature like `0xFFffFFff`. Can be omitted to avoid checking method encoding. -/// - inputs: expected input types. Order must be the same as in function declaration. -/// - Returns: decoded dictionary of input arguments mapped to their indices and arguments' names if these are not empty. -/// If decoding of at least one argument fails, `rawData` size is invalid or `methodEncoding` doesn't match - `nil` is returned. -private func decodeInputData(_ rawData: Data, - methodEncoding: Data? = nil, - inputs: [ABI.Element.InOut]) -> [String: Any]? { - let data: Data - let sig: Data? - - switch rawData.count % 32 { - case 0: - sig = nil - data = Data() - break - case 4: - sig = rawData[0 ..< 4] - data = Data(rawData[4 ..< rawData.count]) - default: - return nil - } +extension ABI.Element { + /// Generic input decoding function. + /// - Parameters: + /// - rawData: data to decode. Must match the following criteria: `data.count == 0 || data.count % 32 == 4`. + /// - methodEncoding: 4 bytes representing method signature like `0xFFffFFff`. Can be omitted to avoid checking method encoding. + /// - inputs: expected input types. Order must be the same as in function declaration. + /// - Returns: decoded dictionary of input arguments mapped to their indices and arguments' names if these are not empty. + /// If decoding of at least one argument fails, `rawData` size is invalid or `methodEncoding` doesn't match - `nil` is returned. + static private func decodeInputData(_ rawData: Data, + methodEncoding: Data? = nil, + inputs: [ABI.Element.InOut]) -> [String: Any]? { + let data: Data + let sig: Data? + + switch rawData.count % 32 { + case 0: + sig = nil + data = Data() + break + case 4: + sig = rawData[0 ..< 4] + data = Data(rawData[4 ..< rawData.count]) + default: + return nil + } - if methodEncoding != nil && sig != nil && sig != methodEncoding { - return nil - } + if methodEncoding != nil && sig != nil && sig != methodEncoding { + return nil + } - var returnArray = [String: Any]() + var returnArray = [String: Any]() - if data.count == 0 && inputs.count == 1 { - let name = "0" - let value = inputs[0].type.emptyValue - returnArray[name] = value - if inputs[0].name != "" { - returnArray[inputs[0].name] = value - } - } else { - guard inputs.count * 32 <= data.count else { return nil } - - var i = 0 - guard let values = ABIDecoder.decode(types: inputs, data: data) else {return nil} - for input in inputs { - let name = "\(i)" - returnArray[name] = values[i] - if input.name != "" { - returnArray[input.name] = values[i] + if data.count == 0 && inputs.count == 1 { + let name = "0" + let value = inputs[0].type.emptyValue + returnArray[name] = value + if inputs[0].name != "" { + returnArray[inputs[0].name] = value + } + } else { + guard inputs.count * 32 <= data.count else { return nil } + + var i = 0 + guard let values = ABIDecoder.decode(types: inputs, data: data) else {return nil} + for input in inputs { + let name = "\(i)" + returnArray[name] = values[i] + if input.name != "" { + returnArray[input.name] = values[i] + } + i = i + 1 } - i = i + 1 } + return returnArray } - return returnArray -} +} \ No newline at end of file From ae022a758b54970da0af8769417445b9f119949e Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Tue, 7 Feb 2023 20:44:39 +0700 Subject: [PATCH 47/49] Fixes due to PR review. --- Sources/Web3Core/EthereumABI/ABIElements.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Web3Core/EthereumABI/ABIElements.swift b/Sources/Web3Core/EthereumABI/ABIElements.swift index 1b04d0f23..e2ca9202b 100755 --- a/Sources/Web3Core/EthereumABI/ABIElements.swift +++ b/Sources/Web3Core/EthereumABI/ABIElements.swift @@ -262,7 +262,7 @@ extension ABI.Element { extension ABI.Element.Function { public func decodeInputData(_ rawData: Data) -> [String: Any]? { - return ABI.Element.decodeInputData(rawData, methodEncoding: methodEncoding, inputs: inputs) + return ABIDecoder.decodeInputData(rawData, methodEncoding: methodEncoding, inputs: inputs) } /// Decodes data returned by a function call. Able to decode `revert(string)`, `revert CustomError(...)` and `require(expression, string)` calls. @@ -432,11 +432,11 @@ extension ABI.Element.Function { extension ABI.Element.Constructor { public func decodeInputData(_ rawData: Data) -> [String: Any]? { - return ABI.Element.decodeInputData(rawData, inputs: inputs) + return ABIDecoder.decodeInputData(rawData, inputs: inputs) } } -extension ABI.Element { +extension ABIDecoder { /// Generic input decoding function. /// - Parameters: /// - rawData: data to decode. Must match the following criteria: `data.count == 0 || data.count % 32 == 4`. @@ -444,7 +444,7 @@ extension ABI.Element { /// - inputs: expected input types. Order must be the same as in function declaration. /// - Returns: decoded dictionary of input arguments mapped to their indices and arguments' names if these are not empty. /// If decoding of at least one argument fails, `rawData` size is invalid or `methodEncoding` doesn't match - `nil` is returned. - static private func decodeInputData(_ rawData: Data, + static func decodeInputData(_ rawData: Data, methodEncoding: Data? = nil, inputs: [ABI.Element.InOut]) -> [String: Any]? { let data: Data From 1c226f0b4ceacc0cbed92aa2c9d93d626553b89f Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu <36865532+JeneaVranceanu@users.noreply.github.com> Date: Tue, 7 Feb 2023 23:16:04 +0200 Subject: [PATCH 48/49] chore: web3swift.podspec - version set to 3.1.1 --- web3swift.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web3swift.podspec b/web3swift.podspec index 475718533..50da01f53 100755 --- a/web3swift.podspec +++ b/web3swift.podspec @@ -1,4 +1,4 @@ -WEB3CORE_VERSION ||= '3.1.0' +WEB3CORE_VERSION ||= '3.1.1' Pod::Spec.new do |spec| spec.name = 'web3swift' From c09e631f815524ee8bfd1769e8be9bfac53db5b0 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu <36865532+JeneaVranceanu@users.noreply.github.com> Date: Tue, 7 Feb 2023 23:16:07 +0200 Subject: [PATCH 49/49] chore: Web3Core.podspec - version set to 3.1.1 --- Web3Core.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Web3Core.podspec b/Web3Core.podspec index df71e5207..0da2cabc9 100644 --- a/Web3Core.podspec +++ b/Web3Core.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |spec| spec.compiler_flags = '-DCOCOAPODS' spec.name = 'Web3Core' - spec.version = '3.1.0' + spec.version = '3.1.1' spec.ios.deployment_target = "13.0" spec.osx.deployment_target = "10.15" spec.license = { :type => 'Apache License 2.0', :file => 'LICENSE.md' }