diff --git a/Sources/Core/Contract/ContractProtocol.swift b/Sources/Core/Contract/ContractProtocol.swift index bcf7d8aa8..a7a113961 100755 --- a/Sources/Core/Contract/ContractProtocol.swift +++ b/Sources/Core/Contract/ContractProtocol.swift @@ -69,7 +69,7 @@ import BigInt public protocol ContractProtocol { /// Address of the referenced smart contract. Can be set later, e.g. if the contract is deploying and address is not yet known. var address: EthereumAddress? {get set} - + /// All ABI elements like: events, functions, constructors and errors. var abi: [ABI.Element] {get} @@ -81,13 +81,13 @@ public protocol ContractProtocol { /// - and 4 bytes signature `0xffffffff` (expected to be lowercased). /// The mapping by name (e.g. `getData`) is the one most likely expected to return arrays with /// more than one entry due to the fact that solidity allows method overloading. - var methods: [String:[ABI.Element.Function]] {get} + var methods: [String: [ABI.Element.Function]] {get} /// All values from ``methods``. var allMethods: [ABI.Element.Function] {get} /// Events filtered from ``abi`` and mapped to their unchanged ``ABI/Element/Event/name``. - var events: [String:ABI.Element.Event] {get} + var events: [String: ABI.Element.Event] {get} /// All values from ``events``. var allEvents: [ABI.Element.Event] {get} @@ -277,11 +277,10 @@ extension DefaultContractProtocol { public func parseEvent(_ eventLog: EventLog) -> (eventName: String?, eventData: [String: Any]?) { for (eName, ev) in self.events { - if (!ev.anonymous) { + if !ev.anonymous { if eventLog.topics[0] != ev.topic { continue - } - else { + } else { let logTopics = eventLog.topics let logData = eventLog.data let parsed = ev.decodeReturnedLogs(eventLogTopics: logTopics, eventLogData: logData) diff --git a/Sources/Core/Contract/EthereumContract.swift b/Sources/Core/Contract/EthereumContract.swift index dc5a1b9ff..255fceecd 100755 --- a/Sources/Core/Contract/EthereumContract.swift +++ b/Sources/Core/Contract/EthereumContract.swift @@ -10,7 +10,7 @@ import BigInt /// constructor, errors and optional ``EthereumAddress`` that could be set later. public class EthereumContract: DefaultContractProtocol { - public var address: EthereumAddress? = nil + public var address: EthereumAddress? public let abi: [ABI.Element] public let methods: [String: [ABI.Element.Function]] @@ -40,7 +40,7 @@ public class EthereumContract: DefaultContractProtocol { public convenience required init(_ abiString: String, at: EthereumAddress? = nil) throws { let jsonData = abiString.data(using: .utf8) let abi = try JSONDecoder().decode([ABI.Record].self, from: jsonData!) - let abiNative = try abi.map({ (record) -> ABI.Element in + let abiNative = try abi.map({ record -> ABI.Element in return try record.parse() }) try self.init(abi: abiNative, at: at) diff --git a/Sources/Core/EthereumABI/ABIDecoding.swift b/Sources/Core/EthereumABI/ABIDecoding.swift index de334c787..21408b750 100755 --- a/Sources/Core/EthereumABI/ABIDecoding.swift +++ b/Sources/Core/EthereumABI/ABIDecoding.swift @@ -10,7 +10,7 @@ public struct ABIDecoder { } extension ABIDecoder { public static func decode(types: [ABI.Element.InOut], data: Data) -> [AnyObject]? { - let params = types.compactMap { (el) -> ABI.Element.ParameterType in + let params = types.compactMap { el -> ABI.Element.ParameterType in return el.type } return decode(types: params, data: data) @@ -118,10 +118,9 @@ extension ABIDecoder { let (v, c) = decodeSingleType(type: subType, data: dataSlice, pointer: subpointer) guard let valueUnwrapped = v, let consumedUnwrapped = c else {break} toReturn.append(valueUnwrapped) - if (subType.isStatic) { + if subType.isStatic { subpointer = subpointer + consumedUnwrapped - } - else { + } else { subpointer = consumedUnwrapped // need to go by nextElementPointer } } @@ -224,16 +223,16 @@ extension ABIDecoder { eventContent["name"]=event.name let logs = eventLogTopics let dataForProcessing = eventLogData - let indexedInputs = event.inputs.filter { (inp) -> Bool in + let indexedInputs = event.inputs.filter { inp -> Bool in return inp.indexed } - if (logs.count == 1 && indexedInputs.count > 0) { + if logs.count == 1 && indexedInputs.count > 0 { return nil } - let nonIndexedInputs = event.inputs.filter { (inp) -> Bool in + let nonIndexedInputs = event.inputs.filter { inp -> Bool in return !inp.indexed } - let nonIndexedTypes = nonIndexedInputs.compactMap { (inp) -> ABI.Element.ParameterType in + let nonIndexedTypes = nonIndexedInputs.compactMap { inp -> ABI.Element.ParameterType in return inp.type } guard logs.count == indexedInputs.count + 1 else {return nil} diff --git a/Sources/Core/EthereumABI/ABIElements.swift b/Sources/Core/EthereumABI/ABIElements.swift index 2e6b5d94f..ac111458b 100755 --- a/Sources/Core/EthereumABI/ABIElements.swift +++ b/Sources/Core/EthereumABI/ABIElements.swift @@ -156,11 +156,11 @@ public extension ABI { 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 @@ -177,15 +177,15 @@ extension ABI.Element { switch self { case .constructor(let constructor): return constructor.encodeParameters(parameters) - case .event(_): + case .event: return nil - case .fallback(_): + case .fallback: return nil case .function(let function): return function.encodeParameters(parameters) - case .receive(_): + case .receive: return nil - case .error(_): + case .error: return nil } } @@ -224,17 +224,17 @@ extension ABI.Element.Event { extension ABI.Element { public func decodeReturnData(_ data: Data) -> [String: Any]? { switch self { - case .constructor(_): + case .constructor: return nil - case .event(_): + case .event: return nil - case .fallback(_): + case .fallback: return nil case .function(let function): return function.decodeReturnData(data) - case .receive(_): + case .receive: return nil - case .error(_): + case .error: return nil } } @@ -245,15 +245,15 @@ extension ABI.Element { switch self { case .constructor(let constructor): return constructor.decodeInputData(data) - case .event(_): + case .event: return nil - case .fallback(_): + case .fallback: return nil case .function(let function): return function.decodeInputData(data) - case .receive(_): + case .receive: return nil - case .error(_): + case .error: return nil } } @@ -347,7 +347,7 @@ extension ABI.Element.Constructor { /// - 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. -fileprivate func decodeInputData(_ rawData: Data, +private func decodeInputData(_ rawData: Data, methodEncoding: Data? = nil, inputs: [ABI.Element.InOut]) -> [String: Any]? { let data: Data diff --git a/Sources/Core/EthereumABI/ABIEncoding.swift b/Sources/Core/EthereumABI/ABIEncoding.swift index a995365d8..61e5bd815 100755 --- a/Sources/Core/EthereumABI/ABIEncoding.swift +++ b/Sources/Core/EthereumABI/ABIEncoding.swift @@ -130,7 +130,6 @@ extension ABIEncoder { return nil } - /// Encode Elements In Out /// - Parameters: /// - types: Contract element InOut to encode @@ -138,13 +137,12 @@ extension ABIEncoder { /// - Returns: Encoded data public static func encode(types: [ABI.Element.InOut], values: [AnyObject]) -> Data? { guard types.count == values.count else {return nil} - let params = types.compactMap { (el) -> ABI.Element.ParameterType in + let params = types.compactMap { el -> ABI.Element.ParameterType in return el.type } return encode(types: params, values: values) } - /// Encode Elements Prarmeter Type /// - Parameters: /// - types: Contract parameters type to encode @@ -190,14 +188,14 @@ extension ABIEncoder { public static func encodeSingleType(type: ABI.Element.ParameterType, value: AnyObject) -> Data? { switch type { - case .uint(_): + case .uint: if let biguint = convertToBigUInt(value) { return biguint.abiEncode(bits: 256) } if let bigint = convertToBigInt(value) { return bigint.abiEncode(bits: 256) } - case .int(_): + case .int: if let biguint = convertToBigUInt(value) { return biguint.abiEncode(bits: 256) } @@ -218,7 +216,7 @@ extension ABIEncoder { } case .bool: if let bool = value as? Bool { - if (bool) { + if bool { return BigUInt(1).abiEncode(bits: 256) } else { return BigUInt(0).abiEncode(bits: 256) @@ -233,8 +231,7 @@ extension ABIEncoder { var dataGuess: Data? if string.hasHexPrefix() { dataGuess = Data.fromHex(string.lowercased().stripHexPrefix()) - } - else { + } else { dataGuess = string.data(using: .utf8) } guard let data = dataGuess else {break} diff --git a/Sources/Core/EthereumABI/ABIParameterTypes.swift b/Sources/Core/EthereumABI/ABIParameterTypes.swift index ca43bcbb0..eb536237e 100755 --- a/Sources/Core/EthereumABI/ABIParameterTypes.swift +++ b/Sources/Core/EthereumABI/ABIParameterTypes.swift @@ -28,16 +28,16 @@ extension ABI.Element { case .dynamicBytes: return false case .array(type: let type, length: let length): - if (length == 0) { + if length == 0 { return false } - if (!type.isStatic) { + if !type.isStatic { return false } return true case .tuple(types: let types): for t in types { - if (!t.isStatic) { + if !t.isStatic { return false } } @@ -60,7 +60,7 @@ extension ABI.Element { var isTuple: Bool { switch self { - case .tuple(_): + case .tuple: return true default: return false @@ -129,7 +129,7 @@ extension ABI.Element { var arraySize: ABI.Element.ArraySize { switch self { case .array(type: _, length: let length): - if (length == 0) { + if length == 0 { return ArraySize.dynamicSize } return ArraySize.staticSize(length) @@ -210,7 +210,7 @@ extension ABI.Element.ParameterType: ABIEncoding { case .function: return "function" case .array(type: let type, length: let length): - if (length == 0) { + if length == 0 { return "\(type.abiRepresentation)[]" } return "\(type.abiRepresentation)[\(length)]" @@ -235,7 +235,7 @@ extension ABI.Element.ParameterType: ABIValidation { return type.isValid case .tuple(types: let types): for t in types { - if (!t.isValid) { + if !t.isValid { return false } } diff --git a/Sources/Core/EthereumABI/ABIParsing.swift b/Sources/Core/EthereumABI/ABIParsing.swift index 47ee128c7..1e22e55f0 100755 --- a/Sources/Core/EthereumABI/ABIParsing.swift +++ b/Sources/Core/EthereumABI/ABIParsing.swift @@ -45,7 +45,7 @@ extension ABI.Record { } } -fileprivate func parseToElement(from abiRecord: ABI.Record, type: ABI.ElementType) throws -> ABI.Element { +private func parseToElement(from abiRecord: ABI.Record, type: ABI.ElementType) throws -> ABI.Element { switch type { case .function: let function = try parseFunction(abiRecord: abiRecord) @@ -69,13 +69,13 @@ fileprivate func parseToElement(from abiRecord: ABI.Record, type: ABI.ElementTyp } -fileprivate func parseFunction(abiRecord: ABI.Record) throws -> ABI.Element.Function { +private func parseFunction(abiRecord: ABI.Record) throws -> ABI.Element.Function { let inputs = try abiRecord.inputs?.map({ (input: ABI.Input) throws -> ABI.Element.InOut in let nativeInput = try input.parse() return nativeInput }) let abiInputs = inputs ?? [ABI.Element.InOut]() - let outputs = try abiRecord.outputs?.map({ (output:ABI.Output) throws -> ABI.Element.InOut in + let outputs = try abiRecord.outputs?.map({ (output: ABI.Output) throws -> ABI.Element.InOut in let nativeOutput = try output.parse() return nativeOutput }) @@ -87,14 +87,14 @@ fileprivate func parseFunction(abiRecord: ABI.Record) throws -> ABI.Element.Func return functionElement } -fileprivate func parseFallback(abiRecord: ABI.Record) throws -> ABI.Element.Fallback { +private func parseFallback(abiRecord: ABI.Record) throws -> ABI.Element.Fallback { let payable = (abiRecord.stateMutability == "payable" || abiRecord.payable == true) let constant = abiRecord.constant == true || abiRecord.stateMutability == "view" || abiRecord.stateMutability == "pure" let functionElement = ABI.Element.Fallback(constant: constant, payable: payable) return functionElement } -fileprivate func parseConstructor(abiRecord: ABI.Record) throws -> ABI.Element.Constructor { +private func parseConstructor(abiRecord: ABI.Record) throws -> ABI.Element.Constructor { let inputs = try abiRecord.inputs?.map({ (input: ABI.Input) throws -> ABI.Element.InOut in let nativeInput = try input.parse() return nativeInput @@ -105,7 +105,7 @@ fileprivate func parseConstructor(abiRecord: ABI.Record) throws -> ABI.Element.C return functionElement } -fileprivate func parseEvent(abiRecord: ABI.Record) throws -> ABI.Element.Event { +private func parseEvent(abiRecord: ABI.Record) throws -> ABI.Element.Event { let inputs = try abiRecord.inputs?.map({ (input: ABI.Input) throws -> ABI.Element.Event.Input in let nativeInput = try input.parseForEvent() return nativeInput @@ -117,7 +117,7 @@ fileprivate func parseEvent(abiRecord: ABI.Record) throws -> ABI.Element.Event { return functionElement } -fileprivate func parseReceive(abiRecord: ABI.Record) throws -> ABI.Element.Receive { +private func parseReceive(abiRecord: ABI.Record) throws -> ABI.Element.Receive { let inputs = try abiRecord.inputs?.map({ (input: ABI.Input) throws -> ABI.Element.InOut in let nativeInput = try input.parse() return nativeInput @@ -128,8 +128,8 @@ fileprivate func parseReceive(abiRecord: ABI.Record) throws -> ABI.Element.Recei return functionElement } -fileprivate func parseError(abiRecord:ABI.Record) throws -> ABI.Element.EthError { - let inputs = try abiRecord.inputs?.map({ (input:ABI.Input) throws -> ABI.Element.EthError.Input in +private func parseError(abiRecord: ABI.Record) throws -> ABI.Element.EthError { + let inputs = try abiRecord.inputs?.map({ (input: ABI.Input) throws -> ABI.Element.EthError.Input in let nativeInput = try input.parseForError() return nativeInput }) @@ -150,8 +150,7 @@ extension ABI.Input { let type = ABI.Element.ParameterType.tuple(types: components!) let nativeInput = ABI.Element.InOut(name: name, type: type) return nativeInput - } - else if case .array(type: .tuple(types: _), length: _) = parameterType { + } else if case .array(type: .tuple(types: _), length: _) = parameterType { let components = try self.components?.compactMap({ (inp: ABI.Input) throws -> ABI.Element.ParameterType in let input = try inp.parse() return input.type @@ -161,8 +160,7 @@ extension ABI.Input { let newType: ABI.Element.ParameterType = .array(type: tupleType, length: 0) let nativeInput = ABI.Element.InOut(name: name, type: newType) return nativeInput - } - else { + } else { let nativeInput = ABI.Element.InOut(name: name, type: parameterType) return nativeInput } @@ -174,11 +172,11 @@ extension ABI.Input { let indexed = self.indexed == true return ABI.Element.Event.Input(name: name, type: parameterType, indexed: indexed) } - + func parseForError() throws -> ABI.Element.EthError.Input { let name = self.name ?? "" let parameterType = try ABITypeParser.parseTypeString(self.type) - return ABI.Element.EthError.Input(name:name, type: parameterType) + return ABI.Element.EthError.Input(name: name, type: parameterType) } } diff --git a/Sources/Core/EthereumABI/ABITypeParser.swift b/Sources/Core/EthereumABI/ABITypeParser.swift index b111e9bd4..753c8788f 100755 --- a/Sources/Core/EthereumABI/ABITypeParser.swift +++ b/Sources/Core/EthereumABI/ABITypeParser.swift @@ -77,7 +77,7 @@ public struct ABITypeParser { type = baseType } tail = string.replacingCharacters(in: string.range(of: baseTypeString)!, with: "") - if (tail == "") { + if tail == "" { return (type, nil) } return recursiveParseArray(baseType: type!, string: tail) @@ -102,7 +102,7 @@ public struct ABITypeParser { type = baseType } tail = string.replacingCharacters(in: string.range(of: baseArrayString)!, with: "") - if (tail == "") { + if tail == "" { return (type, nil) } return recursiveParseArray(baseType: type!, string: tail) diff --git a/Sources/Core/EthereumABI/Sequence+ABIExtension.swift b/Sources/Core/EthereumABI/Sequence+ABIExtension.swift index fc72ad37b..c13fb9f15 100644 --- a/Sources/Core/EthereumABI/Sequence+ABIExtension.swift +++ b/Sources/Core/EthereumABI/Sequence+ABIExtension.swift @@ -16,7 +16,7 @@ public extension Sequence where Element == ABI.Element { /// Functions with ``ABI/Element/Function/name`` value being `nil` will be skipped. /// - Returns: dictionary of mapped functions. /// Throws an error if there are two functions in the sequence with exactly the same name and input parameters. - func getFunctions() throws -> [String:[ABI.Element.Function]]{ + func getFunctions() throws -> [String: [ABI.Element.Function]] { var functions = [String: [ABI.Element.Function]]() func appendFunction(_ key: String, _ value: ABI.Element.Function) { diff --git a/Sources/Core/EthereumAddress/EthereumAddress.swift b/Sources/Core/EthereumAddress/EthereumAddress.swift index 3756109a6..ba703f78e 100755 --- a/Sources/Core/EthereumAddress/EthereumAddress.swift +++ b/Sources/Core/EthereumAddress/EthereumAddress.swift @@ -72,7 +72,7 @@ public struct EthereumAddress: Equatable { let hashChar = String(hash[startIdx..= 8) { + if int >= 8 { ret += c.uppercased() } else { ret += c @@ -101,7 +101,7 @@ extension EthereumAddress { if !addressString.hasHexPrefix() { return nil } - if (!ignoreChecksum) { + if !ignoreChecksum { // check for checksum if data.toHexString() == addressString.stripHexPrefix() { self._address = data.toHexString().addHexPrefix() @@ -130,7 +130,7 @@ extension EthereumAddress { } } - public init?(_ addressData:Data, type: AddressType = .normal) { + public init?(_ addressData: Data, type: AddressType = .normal) { guard addressData.count == 20 else {return nil} self._address = addressData.toHexString().addHexPrefix() self.type = type diff --git a/Sources/Core/EthereumNetwork/Request/APIRequest+Methods.swift b/Sources/Core/EthereumNetwork/Request/APIRequest+Methods.swift index 127bd8e6b..463cd60d5 100644 --- a/Sources/Core/EthereumNetwork/Request/APIRequest+Methods.swift +++ b/Sources/Core/EthereumNetwork/Request/APIRequest+Methods.swift @@ -22,7 +22,7 @@ extension APIRequest { urlRequest.httpBody = call.encodedBody return urlRequest } - + public static func send(uRLRequest: URLRequest, with session: URLSession) async throws -> APIResponse { let (data, response) = try await session.data(for: uRLRequest) @@ -63,7 +63,7 @@ extension APIRequest { } /// JSON RPC Error object. See official specification https://www.jsonrpc.org/specification#error_object -fileprivate struct JsonRpcErrorObject: Decodable { +private struct JsonRpcErrorObject: Decodable { public let error: RpcError? class RpcError: Decodable { @@ -77,7 +77,7 @@ fileprivate struct JsonRpcErrorObject: Decodable { /// For error codes specification see chapter `5.1 Error object` /// https://www.jsonrpc.org/specification#error_object -fileprivate enum JsonRpcErrorCode { +private enum JsonRpcErrorCode { /// -32700 /// Invalid JSON was received by the server. An error occurred on the server while parsing the JSON case parseError @@ -109,7 +109,7 @@ fileprivate enum JsonRpcErrorCode { return "Invalid parameters" case .internalError: return "Internal error" - case .serverError(_): + case .serverError: return "Server error" } } diff --git a/Sources/Core/EthereumNetwork/Request/APIRequest.swift b/Sources/Core/EthereumNetwork/Request/APIRequest.swift index 383ac1140..39d9cae4d 100644 --- a/Sources/Core/EthereumNetwork/Request/APIRequest.swift +++ b/Sources/Core/EthereumNetwork/Request/APIRequest.swift @@ -82,53 +82,53 @@ public enum APIRequest { /// Gas price request case gasPrice - + /// Get last block number case blockNumber - + /// Get current network case getNetwork - + /// Get accounts case getAccounts - + /// Estimate required gas amount for transaction /// - Parameters: /// - TransactionParameters: parameters of planned transaction /// - BlockNumber: block where it should be evalueated case estimateGas(CodableTransaction, BlockNumber) - + /// Send raw transaction /// - Parameters: /// - Hash: String representation of a transaction data case sendRawTransaction(Hash) - + /// Send transaction object /// - Parameters: /// - TransactionParameters: transaction to be sent into chain case sendTransaction(CodableTransaction) - + /// Get transaction by hash /// - Parameters: /// - Hash: transaction hash ID case getTransactionByHash(Hash) - + /// Get transaction receipt /// - Paramters: /// - Hash: transaction hash ID case getTransactionReceipt(Hash) - + /// Get logs /// - Parameters: /// - EventFilterParameters: event filter parameters for interaction with node case getLogs(EventFilterParameters) - + /// Sign given string by users private key /// - Parameters: /// - Address: address where to sign /// - String: custom string to be signed case personalSign(Address, String) - + /// Call a given contract /// /// Mostly could be used for intreacting with a contracts, but also could be used for simple transaction sending @@ -136,7 +136,7 @@ public enum APIRequest { /// - TransactionParameters: transaction to be sent into chain /// - BlockNumber: block where it should be evalueated case call(CodableTransaction, BlockNumber) - + /// Get a transaction counts on a given block /// /// Consider that there's no out of the box way to get counts of all transactions sent by the address @@ -146,7 +146,7 @@ public enum APIRequest { /// - Address: address which is engaged in transaction /// - BlockNumber: block to check case getTransactionCount(Address, BlockNumber) - + /// Get a balance of a given address /// - Parameters: /// - Address: address which balance would be recieved @@ -166,13 +166,13 @@ public enum APIRequest { /// - Address: address what code to get /// - BlockNumber: block to check case getCode(Address, BlockNumber) - + /// Get block object by hash /// - Parameters: /// - Hash: Hash of the block to reach /// - Bool: Transaction included in block could be received as just array of their hashes or as Transaction objects, set true for latter. case getBlockByHash(Hash, Bool) - + /// Get block object by its number /// - Parameters: /// - Hash: Number of the block to reach @@ -195,7 +195,7 @@ public enum APIRequest { // MARK: - Personal Ethereum API // personal Namespace - https://geth.ethereum.org/docs/rpc/ns-personal - + /// Creates new account. /// /// Note: it becomes the new current unlocked account. There can only be one unlocked account at a time. diff --git a/Sources/Core/EthereumNetwork/Utility/HexDecodable+Extensions.swift b/Sources/Core/EthereumNetwork/Utility/HexDecodable+Extensions.swift index 31b78578f..27db82dee 100644 --- a/Sources/Core/EthereumNetwork/Utility/HexDecodable+Extensions.swift +++ b/Sources/Core/EthereumNetwork/Utility/HexDecodable+Extensions.swift @@ -19,9 +19,9 @@ extension BigUInt: LiteralInitiableFromString { } extension Data: LiteralInitiableFromString { public static func fromHex(_ hex: String) -> Data? { let string = hex.lowercased().stripHexPrefix() - let array = Array(hex: string) - if (array.count == 0) { - if (hex == "0x" || hex == "") { + let array = [UInt8](hex: string) + if array.count == 0 { + if hex == "0x" || hex == "" { return Data() } else { return nil diff --git a/Sources/Core/KeystoreManager/BIP32HDNode.swift b/Sources/Core/KeystoreManager/BIP32HDNode.swift index e442e90f9..fd86f1a54 100755 --- a/Sources/Core/KeystoreManager/BIP32HDNode.swift +++ b/Sources/Core/KeystoreManager/BIP32HDNode.swift @@ -23,7 +23,7 @@ extension UInt32 { } public class HDNode { - public struct HDversion{ + public struct HDversion { public var privatePrefix: Data = Data.fromHex("0x0488ADE4")! public var publicPrefix: Data = Data.fromHex("0x0488B21E")! public init() { @@ -31,7 +31,7 @@ public class HDNode { } } public var path: String? = "m" - public var privateKey: Data? = nil + public var privateKey: Data? public var publicKey: Data public var chaincode: Data public var depth: UInt8 @@ -123,7 +123,7 @@ extension HDNode { public func derive (index: UInt32, derivePrivateKey: Bool, hardened: Bool = false) -> HDNode? { if derivePrivateKey { if self.hasPrivate { // derive private key when is itself extended private key - var entropy: Array + var entropy: [UInt8] var trueIndex: UInt32 if index >= (UInt32(1) << 31) || hardened { trueIndex = index @@ -193,7 +193,7 @@ extension HDNode { return nil // derive private key when is itself extended public key (impossible) } } else { // deriving only the public key - var entropy: Array // derive public key when is itself public key + var entropy: [UInt8] // derive public key when is itself public key if index >= (UInt32(1) << 31) || hardened { return nil // no derivation of hardened public key from extended public key } else { @@ -270,7 +270,7 @@ extension HDNode { public func serialize(serializePublic: Bool = true, version: HDversion = HDversion()) -> Data? { var data = Data() - if (!serializePublic && !self.hasPrivate) {return nil} + if !serializePublic && !self.hasPrivate {return nil} if serializePublic { data.append(version.publicPrefix) } else { diff --git a/Sources/Core/KeystoreManager/BIP32Keystore.swift b/Sources/Core/KeystoreManager/BIP32Keystore.swift index 0059bed91..67a95e3ef 100755 --- a/Sources/Core/KeystoreManager/BIP32Keystore.swift +++ b/Sources/Core/KeystoreManager/BIP32Keystore.swift @@ -75,9 +75,9 @@ public class BIP32Keystore: AbstractKeystore { public init?(_ jsonData: Data) { guard var keystorePars = try? JSONDecoder().decode(KeystoreParamsBIP32.self, from: jsonData) else {return nil} - if (keystorePars.version != Self.KeystoreParamsBIP32Version) {return nil} - if (keystorePars.crypto.version != nil && keystorePars.crypto.version != "1") {return nil} - if (!keystorePars.isHDWallet) {return nil} + if keystorePars.version != Self.KeystoreParamsBIP32Version {return nil} + if keystorePars.crypto.version != nil && keystorePars.crypto.version != "1" {return nil} + if !keystorePars.isHDWallet {return nil} addressStorage = PathAddressStorage(pathAddressPairs: keystorePars.pathAddressPairs) @@ -92,7 +92,7 @@ public class BIP32Keystore: AbstractKeystore { guard var seed = BIP39.seedFromMmemonics(mnemonics, password: mnemonicsPassword, language: language) else { throw AbstractKeystoreError.noEntropyError } - defer{ + defer { Data.zero(&seed) } try self.init(seed: seed, password: password, prefixPath: prefixPath, aesMode: aesMode) @@ -158,14 +158,12 @@ public class BIP32Keystore: AbstractKeystore { throw AbstractKeystoreError.encryptionError("Failed to deserialize a root node") } let prefixPath = self.rootPrefix - var pathAppendix: String? = nil + var pathAppendix: String? if path.hasPrefix(prefixPath) { let upperIndex = (path.range(of: prefixPath)?.upperBound)! - if upperIndex < path.endIndex - { + if upperIndex < path.endIndex { pathAppendix = String(path[path.index(after: upperIndex)]) - } else - { + } else { throw AbstractKeystoreError.encryptionError("out of bounds") } @@ -204,10 +202,10 @@ public class BIP32Keystore: AbstractKeystore { } fileprivate func encryptDataToStorage(_ password: String, data: Data?, dkLen: Int = 32, N: Int = 4096, R: Int = 6, P: Int = 1, aesMode: String = "aes-128-cbc") throws { - if (data == nil) { + if data == nil { throw AbstractKeystoreError.encryptionError("Encryption without key data") } - if (data!.count != 82) { + if data!.count != 82 { throw AbstractKeystoreError.encryptionError("Invalid expected data length") } let saltLen = 32 @@ -299,7 +297,7 @@ public class BIP32Keystore: AbstractKeystore { default: hashVariant = nil } - guard (hashVariant != nil) else { + guard hashVariant != nil else { return nil } guard let c = keystorePars.crypto.kdfparams.c else { @@ -324,7 +322,7 @@ public class BIP32Keystore: AbstractKeystore { guard let cipherText = Data.fromHex(keystorePars.crypto.ciphertext) else { return nil } - guard (cipherText.count.isMultiple(of: 32)) else { + guard cipherText.count.isMultiple(of: 32) else { return nil } dataForMAC.append(cipherText) @@ -337,7 +335,7 @@ public class BIP32Keystore: AbstractKeystore { guard let IV = Data.fromHex(keystorePars.crypto.cipherparams.iv) else { return nil } - var decryptedPK: Array? + var decryptedPK: [UInt8]? switch cipher { case "aes-128-ctr": guard let aesCipher = try? AES(key: decryptionKey.bytes, blockMode: CTR(iv: IV.bytes), padding: .pkcs7) else { diff --git a/Sources/Core/KeystoreManager/BIP39.swift b/Sources/Core/KeystoreManager/BIP39.swift index 80271616a..a7966cdd3 100755 --- a/Sources/Core/KeystoreManager/BIP39.swift +++ b/Sources/Core/KeystoreManager/BIP39.swift @@ -70,7 +70,7 @@ public enum BIP39Language { public class BIP39 { - static public func generateMnemonicsFromEntropy(entropy: Data, language: BIP39Language = BIP39Language.english) -> String? { + static public func generateMnemonicsFromEntropy(entropy: Data, language: BIP39Language = BIP39Language.english) -> String? { guard entropy.count >= 16, entropy.count & 4 == 0 else {return nil} let checksum = entropy.sha256() let checksumBits = entropy.count*8/32 @@ -108,7 +108,7 @@ public class BIP39 { var bitString = "" for word in wordList { let idx = language.words.firstIndex(of: word) - if (idx == nil) { + if idx == nil { return nil } let idxAsInt = language.words.startIndex.distance(to: idx!) @@ -133,7 +133,7 @@ public class BIP39 { static public func seedFromMmemonics(_ mnemonics: String, password: String = "", language: BIP39Language = BIP39Language.english) -> Data? { let valid = BIP39.mnemonicsToEntropy(mnemonics, language: language) != nil - if (!valid) { + if !valid { return nil } guard let mnemData = mnemonics.decomposedStringWithCompatibilityMapping.data(using: .utf8) else {return nil} diff --git a/Sources/Core/KeystoreManager/EthereumKeystoreV3.swift b/Sources/Core/KeystoreManager/EthereumKeystoreV3.swift index 5c0373593..9f68dc2c8 100755 --- a/Sources/Core/KeystoreManager/EthereumKeystoreV3.swift +++ b/Sources/Core/KeystoreManager/EthereumKeystoreV3.swift @@ -55,10 +55,10 @@ public class EthereumKeystoreV3: AbstractKeystore { } public init?(_ keystoreParams: KeystoreParamsV3) { - if (keystoreParams.version != 3) { + if keystoreParams.version != 3 { return nil } - if (keystoreParams.crypto.version != nil && keystoreParams.crypto.version != "1") { + if keystoreParams.crypto.version != nil && keystoreParams.crypto.version != "1" { return nil } self.keystoreParams = keystoreParams @@ -90,7 +90,7 @@ public class EthereumKeystoreV3: AbstractKeystore { } fileprivate func encryptDataToStorage(_ password: String, keyData: Data?, dkLen: Int = 32, N: Int = 4096, R: Int = 6, P: Int = 1, aesMode: String = "aes-128-cbc") throws { - if (keyData == nil) { + if keyData == nil { throw AbstractKeystoreError.encryptionError("Encryption without key data") } let saltLen = 32 @@ -211,7 +211,7 @@ public class EthereumKeystoreV3: AbstractKeystore { guard let cipherText = Data.fromHex(keystoreParams.crypto.ciphertext) else { return nil } - if (cipherText.count != 32) { + if cipherText.count != 32 { return nil } dataForMAC.append(cipherText) @@ -224,7 +224,7 @@ public class EthereumKeystoreV3: AbstractKeystore { guard let IV = Data.fromHex(keystoreParams.crypto.cipherparams.iv) else { return nil } - var decryptedPK: Array? + var decryptedPK: [UInt8]? switch cipher { case "aes-128-ctr": guard let aesCipher = try? AES(key: decryptionKey.bytes, blockMode: CTR(iv: IV.bytes), padding: .noPadding) else { diff --git a/Sources/Core/KeystoreManager/IBAN.swift b/Sources/Core/KeystoreManager/IBAN.swift index 3db04250d..604f7dce7 100755 --- a/Sources/Core/KeystoreManager/IBAN.swift +++ b/Sources/Core/KeystoreManager/IBAN.swift @@ -28,7 +28,7 @@ public struct IBAN { } public var asset: String { - if (self.isIndirect) { + if self.isIndirect { return self.iban[4..<7] } else { return "" @@ -36,7 +36,7 @@ public struct IBAN { } public var institution: String { - if (self.isIndirect) { + if self.isIndirect { return self.iban[7..<11] } else { return "" @@ -78,7 +78,7 @@ public struct IBAN { arrayOfInts.append(code - 48) } } - let joinedString = arrayOfInts.map({ (intCh) -> String in + let joinedString = arrayOfInts.map({ intCh -> String in return String(intCh) }).joined() return joinedString @@ -101,7 +101,7 @@ public struct IBAN { guard match.count == 1 else { return false } - if (iban.hasPrefix("XE") && !noValidityCheck) { + if iban.hasPrefix("XE") && !noValidityCheck { let remainder = calculateChecksumMod97(decodeToInts(iban)) return remainder == 1 } else { diff --git a/Sources/Core/KeystoreManager/KeystoreManager.swift b/Sources/Core/KeystoreManager/KeystoreManager.swift index 8d6a09fc5..47a20494f 100755 --- a/Sources/Core/KeystoreManager/KeystoreManager.swift +++ b/Sources/Core/KeystoreManager/KeystoreManager.swift @@ -134,32 +134,32 @@ public class KeystoreManager: AbstractKeystore { } private init?(_ path: String, scanForHDwallets: Bool = false, suffix: String? = nil) throws { - if (scanForHDwallets) { + if scanForHDwallets { self.isHDKeystore = true } self.path = path let fileManager = FileManager.default var isDir: ObjCBool = false var exists = fileManager.fileExists(atPath: path, isDirectory: &isDir) - if (!exists && !isDir.boolValue) { + if !exists && !isDir.boolValue { try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil) exists = fileManager.fileExists(atPath: path, isDirectory: &isDir) } - if (!isDir.boolValue) { + if !isDir.boolValue { return nil } let allFiles = try fileManager.contentsOfDirectory(atPath: path) - if (suffix != nil) { + if suffix != nil { for file in allFiles where file.hasSuffix(suffix!) { var filePath = path - if (!path.hasSuffix("/")) { + if !path.hasSuffix("/") { filePath = path + "/" } filePath = filePath + file guard let content = fileManager.contents(atPath: filePath) else { continue } - if (!scanForHDwallets) { + if !scanForHDwallets { guard let keystore = EthereumKeystoreV3(content) else { continue } @@ -174,14 +174,14 @@ public class KeystoreManager: AbstractKeystore { } else { for file in allFiles { var filePath = path - if (!path.hasSuffix("/")) { + if !path.hasSuffix("/") { filePath = path + "/" } filePath = filePath + file guard let content = fileManager.contents(atPath: filePath) else { continue } - if (!scanForHDwallets) { + if !scanForHDwallets { guard let keystore = EthereumKeystoreV3(content) else { continue } diff --git a/Sources/Core/Oracle/GasOracle.swift b/Sources/Core/Oracle/GasOracle.swift index ccdc74402..fb66ece63 100644 --- a/Sources/Core/Oracle/GasOracle.swift +++ b/Sources/Core/Oracle/GasOracle.swift @@ -52,7 +52,6 @@ final public class Oracle { self.cacheTimeout = cacheTimeout } - /// Returning one dimensional array from two dimensional array /// /// We've got `[[min],[middle],[max]]` 2 dimensional array @@ -105,7 +104,7 @@ final public class Oracle { /// reaarange `[[min, middle, max]]` to `[[min], [middle], [max]]` try await suggestGasValues().reward .forEach { percentiles in - percentiles.enumerated().forEach { (index, percentile) in + percentiles.enumerated().forEach { index, percentile in /// if `rearrengedArray` have not that enough items /// as `percentiles` current item index if rearrengedArray.endIndex <= index { @@ -177,7 +176,6 @@ final public class Oracle { } } - public extension Oracle { // MARK: - Base Fee /// Soften baseFee amount diff --git a/Sources/Core/RLP/RLP.swift b/Sources/Core/RLP/RLP.swift index 30cf5c2bd..588432db7 100755 --- a/Sources/Core/RLP/RLP.swift +++ b/Sources/Core/RLP/RLP.swift @@ -24,8 +24,7 @@ public struct RLP { } else if let data = element as? Data { return encode(data) - } - else if let biguint = element as? BigUInt { + } else if let biguint = element as? BigUInt { return encode(biguint) } return nil @@ -56,7 +55,7 @@ public struct RLP { } internal static func encode(_ data: Data) -> Data? { - if (data.count == 1 && data.bytes[0] < UInt8(0x80)) { + if data.count == 1 && data.bytes[0] < UInt8(0x80) { return data } else { guard let length = encodeLength(data.count, offset: UInt8(0x80)) else {return nil} @@ -68,7 +67,7 @@ public struct RLP { } internal static func encodeLength(_ length: Int, offset: UInt8) -> Data? { - if (length < 0) { + if length < 0 { return nil } let bigintLength = BigUInt(UInt(length)) @@ -76,11 +75,11 @@ public struct RLP { } internal static func encodeLength(_ length: BigUInt, offset: UInt8) -> Data? { - if (length < length56) { + if length < length56 { let encodedLength = length + BigUInt(UInt(offset)) - guard (encodedLength.bitWidth <= 8) else {return nil} + guard encodedLength.bitWidth <= 8 else {return nil} return encodedLength.serialize() - } else if (length < lengthMax) { + } else if length < lengthMax { let encodedLength = length.serialize() let len = BigUInt(UInt(encodedLength.count)) guard let prefix = lengthToBinary(len) else {return nil} @@ -93,7 +92,7 @@ public struct RLP { } internal static func lengthToBinary(_ length: BigUInt) -> UInt8? { - if (length == 0) { + if length == 0 { return UInt8(0) } let divisor = BigUInt(256) @@ -102,7 +101,7 @@ public struct RLP { let suffix = length % divisor var prefixData = Data([prefix]) - if (prefix == UInt8(0)) { + if prefix == UInt8(0) { prefixData = Data() } let suffixData = suffix.serialize() @@ -114,19 +113,19 @@ public struct RLP { } // FIXME: Make encode generic to avoid casting it's argument to [AnyObject] - internal static func encode(_ elements: Array) -> Data? { + internal static func encode(_ elements: [AnyObject]) -> Data? { var encodedData = Data() for e in elements { if let encoded = encode(e) { encodedData.append(encoded) } else { - guard let asArray = e as? Array else {return nil} + guard let asArray = e as? [AnyObject] else {return nil} guard let encoded = encode(asArray) else {return nil} encodedData.append(encoded) } } guard var encodedLength = encodeLength(encodedData.count, offset: UInt8(0xc0)) else {return nil} - if (encodedLength != Data()) { + if encodedLength != Data() { encodedLength.append(encodedData) } return encodedLength @@ -158,7 +157,7 @@ public struct RLP { guard let slice = try? slice(data: bytesToParse, offset: offset, length: dataLength) else {return nil} guard let inside = decode(Data(slice)) else {return nil} switch inside.content { - case .data(_): + case .data: return nil default: outputArray.append(inside) @@ -190,9 +189,9 @@ public struct RLP { switch self.content { case .noItem: return false - case .data(_): + case .data: return true - case .list(_, _, _): + case .list: return false } } @@ -201,9 +200,9 @@ public struct RLP { switch self.content { case .noItem: return false - case .data(_): + case .data: return false - case .list(_, _, _): + case .list: return true } } @@ -211,7 +210,7 @@ public struct RLP { switch self.content { case .noItem: return nil - case .data(_): + case .data: return nil case .list(let list, _, _): return list.count @@ -247,7 +246,7 @@ public struct RLP { internal static func decodeLength(_ input: Data) -> (offset: BigUInt?, length: BigUInt?, type: RLPItem.UnderlyingType?) { do { let length = BigUInt(input.count) - if (length == BigUInt(0)) { + if length == BigUInt(0) { return (0, 0, .empty) } let prefixByte = input[0] @@ -301,7 +300,7 @@ public struct RLP { fileprivate extension Data { - var bytes: Array { + var bytes: [UInt8] { return Array(self) } } diff --git a/Sources/Core/Structure/Block/Block.swift b/Sources/Core/Structure/Block/Block.swift index a1182d8be..1cb587d2e 100644 --- a/Sources/Core/Structure/Block/Block.swift +++ b/Sources/Core/Structure/Block/Block.swift @@ -18,11 +18,11 @@ public struct Block { public var parentHash: Data public var nonce: Data? // MARK: This is optional in web3js but required in Ethereum JSON-RPC public var sha3Uncles: Data - public var logsBloom: EthereumBloomFilter? = nil // MARK: This is optional in web3js but required in Ethereum JSON-RPC + public var logsBloom: EthereumBloomFilter? // MARK: This is optional in web3js but required in Ethereum JSON-RPC public var transactionsRoot: Data public var stateRoot: Data public var receiptsRoot: Data - public var miner: EthereumAddress? = nil // MARK: This is NOT optional in web3js + public var miner: EthereumAddress? // MARK: This is NOT optional in web3js public var difficulty: BigUInt public var totalDifficulty: BigUInt public var extraData: Data @@ -104,4 +104,4 @@ extension Block: Decodable { } } -extension Block: APIResultType { } \ No newline at end of file +extension Block: APIResultType { } diff --git a/Sources/Core/Structure/Block/BlockNumber.swift b/Sources/Core/Structure/Block/BlockNumber.swift index 5c256065d..412b4d14c 100644 --- a/Sources/Core/Structure/Block/BlockNumber.swift +++ b/Sources/Core/Structure/Block/BlockNumber.swift @@ -9,7 +9,7 @@ import Foundation import BigInt public enum BlockNumber: CustomStringConvertible { - + case pending /// Latest block of a chain case latest diff --git a/Sources/Core/Structure/Event+Protocol.swift b/Sources/Core/Structure/Event+Protocol.swift index e7a66ef0a..87f361a08 100755 --- a/Sources/Core/Structure/Event+Protocol.swift +++ b/Sources/Core/Structure/Event+Protocol.swift @@ -21,9 +21,9 @@ public struct EventParserResult: EventParserResultProtocol { public var transactionReceipt: TransactionReceipt? public var contractAddress: EthereumAddress public var decodedResult: [String: Any] - public var eventLog: EventLog? = nil - - public init(eventName: String, transactionReceipt: TransactionReceipt? = nil, contractAddress: EthereumAddress, decodedResult: [String : Any], eventLog: EventLog? = nil) { + public var eventLog: EventLog? + + public init(eventName: String, transactionReceipt: TransactionReceipt? = nil, contractAddress: EthereumAddress, decodedResult: [String: Any], eventLog: EventLog? = nil) { self.eventName = eventName self.transactionReceipt = transactionReceipt self.contractAddress = contractAddress @@ -32,7 +32,6 @@ public struct EventParserResult: EventParserResultProtocol { } } - /// Protocol for generic Ethereum event parser public protocol EventParserProtocol { func parseTransaction(_ transaction: CodableTransaction) async throws -> [EventParserResultProtocol] diff --git a/Sources/Core/Structure/SECP256k1.swift b/Sources/Core/Structure/SECP256k1.swift index 787c5ee34..9b513cbf4 100755 --- a/Sources/Core/Structure/SECP256k1.swift +++ b/Sources/Core/Structure/SECP256k1.swift @@ -10,7 +10,7 @@ import Foundation import secp256k1 public struct SECP256K1 { - public struct UnmarshaledSignature{ + public struct UnmarshaledSignature { public var v: UInt8 = 0 public var r = Data(repeating: 0, count: 32) public var s = Data(repeating: 0, count: 32) @@ -27,7 +27,7 @@ extension SECP256K1 { static let context = secp256k1_context_create(UInt32(SECP256K1_CONTEXT_SIGN|SECP256K1_CONTEXT_VERIFY)) public static func signForRecovery(hash: Data, privateKey: Data, useExtraEntropy: Bool = false) -> (serializedSignature: Data?, rawSignature: Data?) { - if (hash.count != 32 || privateKey.count != 32) {return (nil, nil)} + if hash.count != 32 || privateKey.count != 32 {return (nil, nil)} if !SECP256K1.verifyPrivateKey(privateKey: privateKey) { return (nil, nil) } @@ -48,7 +48,7 @@ extension SECP256K1 { } public static func privateToPublic(privateKey: Data, compressed: Bool = false) -> Data? { - if (privateKey.count != 32) {return nil} + if privateKey.count != 32 {return nil} guard var publicKey = SECP256K1.privateKeyToPublicKey(privateKey: privateKey) else {return nil} guard let serializedKey = serializePublicKey(publicKey: &publicKey, compressed: compressed) else {return nil} return serializedKey @@ -69,7 +69,7 @@ extension SECP256K1 { storage.append(pubkey) } for i in 0 ..< numToCombine { - withUnsafePointer(to: &storage[i]) { (ptr) -> Void in + withUnsafePointer(to: &storage[i]) { ptr -> Void in arrayOfPointers.advanced(by: i).pointee = ptr } } @@ -110,7 +110,7 @@ extension SECP256K1 { } internal static func privateKeyToPublicKey(privateKey: Data) -> secp256k1_pubkey? { - if (privateKey.count != 32) {return nil} + if privateKey.count != 32 {return nil} var publicKey = secp256k1_pubkey() let result = privateKey.withUnsafeBytes { (pkRawBufferPointer: UnsafeRawBufferPointer) -> Int32? in if let pkRawPointer = pkRawBufferPointer.baseAddress, pkRawBufferPointer.count > 0 { @@ -130,7 +130,7 @@ extension SECP256K1 { public static func serializePublicKey(publicKey: inout secp256k1_pubkey, compressed: Bool = false) -> Data? { var keyLength = compressed ? 33 : 65 var serializedPubkey = Data(repeating: 0x00, count: keyLength) - let result = serializedPubkey.withUnsafeMutableBytes { (serializedPubkeyRawBuffPointer) -> Int32? in + let result = serializedPubkey.withUnsafeMutableBytes { serializedPubkeyRawBuffPointer -> Int32? in if let serializedPkRawPointer = serializedPubkeyRawBuffPointer.baseAddress, serializedPubkeyRawBuffPointer.count > 0 { let serializedPubkeyPointer = serializedPkRawPointer.assumingMemoryBound(to: UInt8.self) return withUnsafeMutablePointer(to: &keyLength, { (keyPtr: UnsafeMutablePointer) -> Int32 in @@ -222,9 +222,9 @@ extension SECP256K1 { guard let res = result, res != 0 else { return nil } - if (v == 0 || v == 27 || v == 31 || v == 35) { + if v == 0 || v == 27 || v == 31 || v == 35 { serializedSignature.append(0x1b) - } else if (v == 1 || v == 28 || v == 32 || v == 36) { + } else if v == 1 || v == 28 || v == 32 || v == 36 { serializedSignature.append(0x1c) } else { return nil @@ -233,7 +233,7 @@ extension SECP256K1 { } internal static func recoverableSign(hash: Data, privateKey: Data, useExtraEntropy: Bool = false) -> secp256k1_ecdsa_recoverable_signature? { - if (hash.count != 32 || privateKey.count != 32) { + if hash.count != 32 || privateKey.count != 32 { return nil } if !SECP256K1.verifyPrivateKey(privateKey: privateKey) { @@ -241,13 +241,13 @@ extension SECP256K1 { } var recoverableSignature: secp256k1_ecdsa_recoverable_signature = secp256k1_ecdsa_recoverable_signature() guard let extraEntropy = SECP256K1.randomBytes(length: 32) else {return nil} - let result = hash.withUnsafeBytes { (hashRBPointer) -> Int32? in + let result = hash.withUnsafeBytes { hashRBPointer -> Int32? in if let hashRPointer = hashRBPointer.baseAddress, hashRBPointer.count > 0 { let hashPointer = hashRPointer.assumingMemoryBound(to: UInt8.self) - return privateKey.withUnsafeBytes({ (privateKeyRBPointer) -> Int32? in + return privateKey.withUnsafeBytes({ privateKeyRBPointer -> Int32? in if let privateKeyRPointer = privateKeyRBPointer.baseAddress, privateKeyRBPointer.count > 0 { let privateKeyPointer = privateKeyRPointer.assumingMemoryBound(to: UInt8.self) - return extraEntropy.withUnsafeBytes({ (extraEntropyRBPointer) -> Int32? in + return extraEntropy.withUnsafeBytes({ extraEntropyRBPointer -> Int32? in if let extraEntropyRPointer = extraEntropyRBPointer.baseAddress, extraEntropyRBPointer.count > 0 { let extraEntropyPointer = extraEntropyRPointer.assumingMemoryBound(to: UInt8.self) return withUnsafeMutablePointer(to: &recoverableSignature, { (recSignaturePtr: UnsafeMutablePointer) -> Int32 in @@ -282,8 +282,8 @@ extension SECP256K1 { } public static func verifyPrivateKey(privateKey: Data) -> Bool { - if (privateKey.count != 32) {return false} - let result = privateKey.withUnsafeBytes { (privateKeyRBPointer) -> Int32? in + if privateKey.count != 32 {return false} + let result = privateKey.withUnsafeBytes { privateKeyRBPointer -> Int32? in if let privateKeyRPointer = privateKeyRBPointer.baseAddress, privateKeyRBPointer.count > 0 { let privateKeyPointer = privateKeyRPointer.assumingMemoryBound(to: UInt8.self) let res = secp256k1_ec_seckey_verify(context!, privateKeyPointer) @@ -312,7 +312,7 @@ extension SECP256K1 { } public static func unmarshalSignature(signatureData: Data) -> UnmarshaledSignature? { - if (signatureData.count != 65) {return nil} + if signatureData.count != 65 {return nil} let v = signatureData[64] let r = Data(signatureData[0..<32]) let s = Data(signatureData[32..<64]) @@ -338,7 +338,7 @@ extension SECP256K1 { internal static func randomBytes(length: Int) -> Data? { for _ in 0...1024 { var data = Data(repeating: 0, count: length) - let result = data.withUnsafeMutableBytes { (mutableRBBytes) -> Int32? in + let result = data.withUnsafeMutableBytes { mutableRBBytes -> Int32? in if let mutableRBytes = mutableRBBytes.baseAddress, mutableRBBytes.count > 0 { let mutableBytes = mutableRBytes.assumingMemoryBound(to: UInt8.self) return SecRandomCopyBytes(kSecRandomDefault, length, mutableBytes) diff --git a/Sources/Core/Transaction/CodableTransaction.swift b/Sources/Core/Transaction/CodableTransaction.swift index 288a82d5d..316e4ceb8 100644 --- a/Sources/Core/Transaction/CodableTransaction.swift +++ b/Sources/Core/Transaction/CodableTransaction.swift @@ -7,7 +7,6 @@ import Foundation import BigInt - /// Structure capable of carying the parameters for any transaction type. /// while all fields in this struct are optional, they are not necessarily /// optional for the type of transaction they apply to. @@ -264,7 +263,7 @@ extension CodableTransaction: Codable { if let accessList = accessList, !accessList.isEmpty { try containier.encode(accessList, forKey: .accessList) } - + if !gasLimit.isZero { try containier.encode(gasLimit.hexString, forKey: .gasLimit) } @@ -381,14 +380,8 @@ extension CodableTransaction { } } - - - - - } - extension CodableTransaction: CustomStringConvertible { /// required by CustomString convertable /// returns a string description for the transaction and its data @@ -418,7 +411,7 @@ extension CodableTransaction { /// - parameters: EthereumParameters object containing additional parametrs 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, + gasLimit: BigUInt = 0, maxFeePerGas: BigUInt? = nil, maxPriorityFeePerGas: BigUInt? = nil, gasPrice: BigUInt? = nil, accessList: [AccessListEntry]? = nil, v: BigUInt = 1, r: BigUInt = 0, s: BigUInt = 0) { // FIXME: This is duplication and should be fixed. self.data = data diff --git a/Sources/Core/Transaction/Envelope/AbstractEnvelope.swift b/Sources/Core/Transaction/Envelope/AbstractEnvelope.swift index 113ae37b8..5bb32c104 100644 --- a/Sources/Core/Transaction/Envelope/AbstractEnvelope.swift +++ b/Sources/Core/Transaction/Envelope/AbstractEnvelope.swift @@ -7,7 +7,6 @@ import Foundation import BigInt - /* AbstractEnvelope is the main protocol definition to enable support for different transaction types. it defines the basic parameters and methods required by all transaction types. @@ -92,7 +91,7 @@ protocol AbstractEnvelope: CustomStringConvertible { // possibly add Codable? /// the maximum tip to pay the miner (EIP-1559 only) var maxPriorityFeePerGas: BigUInt? { get set } - + /// Any encoded data accompanying the transaction var data: Data { get set } @@ -108,7 +107,7 @@ protocol AbstractEnvelope: CustomStringConvertible { // possibly add Codable? /// - Returns: the public key decoded from the signature data var publicKey: Data? { get } - + /// - Returns: a hash of the transaction suitable for signing var signatureHash: Data? { get } @@ -149,25 +148,25 @@ protocol AbstractEnvelope: CustomStringConvertible { // possibly add Codable? } extension AbstractEnvelope { - + var sender: EthereumAddress? { guard let publicKey = publicKey else { return nil } return Utilities.publicToAddress(publicKey) } - + mutating func clearSignatureData() { self.v = 1 self.r = 0 self.s = 0 } - + /// - Returns: a hash of the transaction suitable for signing var signatureHash: Data? { guard let encoded = self.encode(for: .signature) else { return nil } let hash = encoded.sha3(.keccak256) return hash } - + /// - Returns: the public key decoded from the signature data var publicKey: Data? { guard let sigData = self.getUnmarshalledSignatureData() else { return nil } @@ -182,4 +181,3 @@ extension AbstractEnvelope { return publicKey } } - diff --git a/Sources/Core/Transaction/Envelope/EIP1559Envelope.swift b/Sources/Core/Transaction/Envelope/EIP1559Envelope.swift index 2da61bf59..578c7e800 100644 --- a/Sources/Core/Transaction/Envelope/EIP1559Envelope.swift +++ b/Sources/Core/Transaction/Envelope/EIP1559Envelope.swift @@ -29,7 +29,7 @@ public struct EIP1559Envelope: EIP2718Envelope { // EIP-1559 specific parameters public var gasLimit: BigUInt - var gasPrice: BigUInt? = nil + var gasPrice: BigUInt? /// Value of the tip to the miner for transaction processing. /// diff --git a/Sources/Core/Transaction/Envelope/EIP2930Envelope.swift b/Sources/Core/Transaction/Envelope/EIP2930Envelope.swift index e58d3d176..628da7191 100644 --- a/Sources/Core/Transaction/Envelope/EIP2930Envelope.swift +++ b/Sources/Core/Transaction/Envelope/EIP2930Envelope.swift @@ -27,8 +27,8 @@ public struct EIP2930Envelope: EIP2718Envelope { public var accessList: [AccessListEntry] = [] public var publicKey: Data? - var maxFeePerGas: BigUInt? = nil - var maxPriorityFeePerGas: BigUInt? = nil + var maxFeePerGas: BigUInt? + var maxPriorityFeePerGas: BigUInt? // for CustomStringConvertible public var description: String { diff --git a/Sources/Core/Transaction/Envelope/LegacyEnvelope.swift b/Sources/Core/Transaction/Envelope/LegacyEnvelope.swift index 40c133ada..44513c585 100644 --- a/Sources/Core/Transaction/Envelope/LegacyEnvelope.swift +++ b/Sources/Core/Transaction/Envelope/LegacyEnvelope.swift @@ -30,8 +30,8 @@ public struct LegacyEnvelope: AbstractEnvelope { public var gasPrice: BigUInt? = 0 public var gasLimit: BigUInt = 0 - var maxFeePerGas: BigUInt? = nil - var maxPriorityFeePerGas: BigUInt? = nil + var maxFeePerGas: BigUInt? + var maxPriorityFeePerGas: BigUInt? // legacy chainID Mechanism private var explicitChainID: BigUInt? // set directly or via options @@ -205,7 +205,6 @@ extension LegacyEnvelope { return RLP.encode(fields) } - public func getUnmarshalledSignatureData() -> SECP256K1.UnmarshaledSignature? { if self.r == 0 && self.s == 0 { return nil } var normalizedV: BigUInt = 27 diff --git a/Sources/Core/Transaction/EventfilterParameters.swift b/Sources/Core/Transaction/EventfilterParameters.swift index 2db1e8b01..bb959c9c3 100755 --- a/Sources/Core/Transaction/EventfilterParameters.swift +++ b/Sources/Core/Transaction/EventfilterParameters.swift @@ -29,7 +29,7 @@ public struct EventFilterParameters: Encodable { public var toBlock: BlockNumber public var address: [EthereumAddress] public var topics: [Topic?] - + public init(fromBlock: BlockNumber = .latest, toBlock: BlockNumber = .latest, address: [EthereumAddress] = [], topics: [Topic?] = []) { self.fromBlock = fromBlock self.toBlock = toBlock @@ -94,7 +94,7 @@ extension EventFilterParameters { ] ``` */ - public enum Topic: Encodable { + public enum Topic: Encodable { case string(String?) case strings([Topic?]?) diff --git a/Sources/Core/Utility/Array+Extension.swift b/Sources/Core/Utility/Array+Extension.swift index f413ba4c8..1b0e78ce8 100755 --- a/Sources/Core/Utility/Array+Extension.swift +++ b/Sources/Core/Utility/Array+Extension.swift @@ -92,7 +92,6 @@ extension Array where Element: BinaryInteger { return BigUInt(self.reduce(0, +)) / BigUInt(self.count) } - /// Calculates percentile of dataset on which get called. /// - Parameter value: Percentile value. /// - Returns: Item from dataset that is belongs to given percentile, nil if dataset is empty. diff --git a/Sources/Core/Utility/Data+Extension.swift b/Sources/Core/Utility/Data+Extension.swift index 4bc94645d..6949f91be 100755 --- a/Sources/Core/Utility/Data+Extension.swift +++ b/Sources/Core/Utility/Data+Extension.swift @@ -57,7 +57,7 @@ extension Data { } return nil } - + public func bitsInRange(_ startingBit: Int, _ length: Int) -> UInt64? { // return max of 8 bytes for simplicity, non-public if startingBit + length / 8 > self.count, length > 64, startingBit > 0, length >= 1 {return nil} let bytes = self[(startingBit/8) ..< (startingBit+length+7)/8] diff --git a/Sources/Core/Utility/Decodable+Extensions.swift b/Sources/Core/Utility/Decodable+Extensions.swift index d191fdc1c..0029df3cd 100644 --- a/Sources/Core/Utility/Decodable+Extensions.swift +++ b/Sources/Core/Utility/Decodable+Extensions.swift @@ -98,7 +98,6 @@ extension UnkeyedDecodingContainer { return array } - /// Decodes a unkeyed value from Hex to `DecodableFromHex` /// /// Currently this method supports only `Data.Type`, `BigUInt.Type`, `Date.Type`, `EthereumAddress` diff --git a/Sources/Core/Utility/Encodable+Extensions.swift b/Sources/Core/Utility/Encodable+Extensions.swift index 96167e516..1981636e6 100644 --- a/Sources/Core/Utility/Encodable+Extensions.swift +++ b/Sources/Core/Utility/Encodable+Extensions.swift @@ -52,7 +52,6 @@ extension UnkeyedEncodingContainer { } } - public protocol EncodableToHex: Encodable { var hexString: String { get } } diff --git a/Sources/Core/Utility/NativeTypesEncoding+Extension.swift b/Sources/Core/Utility/NativeTypesEncoding+Extension.swift index 956acf28c..b71da43bb 100755 --- a/Sources/Core/Utility/NativeTypesEncoding+Extension.swift +++ b/Sources/Core/Utility/NativeTypesEncoding+Extension.swift @@ -9,13 +9,13 @@ import BigInt extension Data { func setLengthLeft(_ toBytes: UInt64, isNegative: Bool = false) -> Data? { let existingLength = UInt64(self.count) - if (existingLength == toBytes) { + if existingLength == toBytes { return Data(self) - } else if (existingLength > toBytes) { + } else if existingLength > toBytes { return nil } var data: Data - if (isNegative) { + if isNegative { data = Data(repeating: UInt8(255), count: Int(toBytes - existingLength)) } else { data = Data(repeating: UInt8(0), count: Int(toBytes - existingLength)) @@ -26,14 +26,14 @@ extension Data { func setLengthRight(_ toBytes: UInt64, isNegative: Bool = false) -> Data? { let existingLength = UInt64(self.count) - if (existingLength == toBytes) { + if existingLength == toBytes { return Data(self) - } else if (existingLength > toBytes) { + } else if existingLength > toBytes { return nil } var data: Data = Data() data.append(self) - if (isNegative) { + if isNegative { data.append(Data(repeating: UInt8(255), count: Int(toBytes - existingLength))) } else { data.append(Data(repeating: UInt8(0), count: Int(toBytes - existingLength))) @@ -44,7 +44,7 @@ extension Data { extension BigInt { func toTwosComplement() -> Data { - if (self.sign == BigInt.Sign.plus) { + if self.sign == BigInt.Sign.plus { return self.magnitude.serialize() } else { let serializedLength = self.magnitude.serialize().count @@ -77,7 +77,7 @@ extension BigInt { extension BigInt { static func fromTwosComplement(data: Data) -> BigInt { let isPositive = ((data[0] & 128) >> 7) == 0 - if (isPositive) { + if isPositive { let magnitude = BigUInt(data) return BigInt(magnitude) } else { diff --git a/Sources/Core/Utility/RIPEMD160+StackOveflow.swift b/Sources/Core/Utility/RIPEMD160+StackOveflow.swift index 831a24b26..dfb164baf 100755 --- a/Sources/Core/Utility/RIPEMD160+StackOveflow.swift +++ b/Sources/Core/Utility/RIPEMD160+StackOveflow.swift @@ -124,54 +124,54 @@ public struct RIPEMD160 { FF(&ee, aa, &bb, cc, dd, X[ 1], 14) FF(&dd, ee, &aa, bb, cc, X[ 2], 15) FF(&cc, dd, &ee, aa, bb, X[ 3], 12) - FF(&bb, cc, &dd, ee, aa, X[ 4], 5) - FF(&aa, bb, &cc, dd, ee, X[ 5], 8) - FF(&ee, aa, &bb, cc, dd, X[ 6], 7) - FF(&dd, ee, &aa, bb, cc, X[ 7], 9) + FF(&bb, cc, &dd, ee, aa, X[ 4], 5) + FF(&aa, bb, &cc, dd, ee, X[ 5], 8) + FF(&ee, aa, &bb, cc, dd, X[ 6], 7) + FF(&dd, ee, &aa, bb, cc, X[ 7], 9) FF(&cc, dd, &ee, aa, bb, X[ 8], 11) FF(&bb, cc, &dd, ee, aa, X[ 9], 13) FF(&aa, bb, &cc, dd, ee, X[10], 14) FF(&ee, aa, &bb, cc, dd, X[11], 15) - FF(&dd, ee, &aa, bb, cc, X[12], 6) - FF(&cc, dd, &ee, aa, bb, X[13], 7) - FF(&bb, cc, &dd, ee, aa, X[14], 9) - FF(&aa, bb, &cc, dd, ee, X[15], 8) + FF(&dd, ee, &aa, bb, cc, X[12], 6) + FF(&cc, dd, &ee, aa, bb, X[13], 7) + FF(&bb, cc, &dd, ee, aa, X[14], 9) + FF(&aa, bb, &cc, dd, ee, X[15], 8) /* round 2 */ - GG(&ee, aa, &bb, cc, dd, X[ 7], 7) - GG(&dd, ee, &aa, bb, cc, X[ 4], 6) - GG(&cc, dd, &ee, aa, bb, X[13], 8) + GG(&ee, aa, &bb, cc, dd, X[ 7], 7) + GG(&dd, ee, &aa, bb, cc, X[ 4], 6) + GG(&cc, dd, &ee, aa, bb, X[13], 8) GG(&bb, cc, &dd, ee, aa, X[ 1], 13) GG(&aa, bb, &cc, dd, ee, X[10], 11) - GG(&ee, aa, &bb, cc, dd, X[ 6], 9) - GG(&dd, ee, &aa, bb, cc, X[15], 7) + GG(&ee, aa, &bb, cc, dd, X[ 6], 9) + GG(&dd, ee, &aa, bb, cc, X[15], 7) GG(&cc, dd, &ee, aa, bb, X[ 3], 15) - GG(&bb, cc, &dd, ee, aa, X[12], 7) + GG(&bb, cc, &dd, ee, aa, X[12], 7) GG(&aa, bb, &cc, dd, ee, X[ 0], 12) GG(&ee, aa, &bb, cc, dd, X[ 9], 15) - GG(&dd, ee, &aa, bb, cc, X[ 5], 9) + GG(&dd, ee, &aa, bb, cc, X[ 5], 9) GG(&cc, dd, &ee, aa, bb, X[ 2], 11) - GG(&bb, cc, &dd, ee, aa, X[14], 7) + GG(&bb, cc, &dd, ee, aa, X[14], 7) GG(&aa, bb, &cc, dd, ee, X[11], 13) GG(&ee, aa, &bb, cc, dd, X[ 8], 12) /* round 3 */ HH(&dd, ee, &aa, bb, cc, X[ 3], 11) HH(&cc, dd, &ee, aa, bb, X[10], 13) - HH(&bb, cc, &dd, ee, aa, X[14], 6) - HH(&aa, bb, &cc, dd, ee, X[ 4], 7) + HH(&bb, cc, &dd, ee, aa, X[14], 6) + HH(&aa, bb, &cc, dd, ee, X[ 4], 7) HH(&ee, aa, &bb, cc, dd, X[ 9], 14) - HH(&dd, ee, &aa, bb, cc, X[15], 9) + HH(&dd, ee, &aa, bb, cc, X[15], 9) HH(&cc, dd, &ee, aa, bb, X[ 8], 13) HH(&bb, cc, &dd, ee, aa, X[ 1], 15) HH(&aa, bb, &cc, dd, ee, X[ 2], 14) - HH(&ee, aa, &bb, cc, dd, X[ 7], 8) + HH(&ee, aa, &bb, cc, dd, X[ 7], 8) HH(&dd, ee, &aa, bb, cc, X[ 0], 13) - HH(&cc, dd, &ee, aa, bb, X[ 6], 6) - HH(&bb, cc, &dd, ee, aa, X[13], 5) + HH(&cc, dd, &ee, aa, bb, X[ 6], 6) + HH(&bb, cc, &dd, ee, aa, X[13], 5) HH(&aa, bb, &cc, dd, ee, X[11], 12) - HH(&ee, aa, &bb, cc, dd, X[ 5], 7) - HH(&dd, ee, &aa, bb, cc, X[12], 5) + HH(&ee, aa, &bb, cc, dd, X[ 5], 7) + HH(&dd, ee, &aa, bb, cc, X[12], 5) /* round 4 */ II(&cc, dd, &ee, aa, bb, X[ 1], 11) @@ -180,124 +180,124 @@ public struct RIPEMD160 { II(&ee, aa, &bb, cc, dd, X[10], 15) II(&dd, ee, &aa, bb, cc, X[ 0], 14) II(&cc, dd, &ee, aa, bb, X[ 8], 15) - II(&bb, cc, &dd, ee, aa, X[12], 9) - II(&aa, bb, &cc, dd, ee, X[ 4], 8) - II(&ee, aa, &bb, cc, dd, X[13], 9) + II(&bb, cc, &dd, ee, aa, X[12], 9) + II(&aa, bb, &cc, dd, ee, X[ 4], 8) + II(&ee, aa, &bb, cc, dd, X[13], 9) II(&dd, ee, &aa, bb, cc, X[ 3], 14) - II(&cc, dd, &ee, aa, bb, X[ 7], 5) - II(&bb, cc, &dd, ee, aa, X[15], 6) - II(&aa, bb, &cc, dd, ee, X[14], 8) - II(&ee, aa, &bb, cc, dd, X[ 5], 6) - II(&dd, ee, &aa, bb, cc, X[ 6], 5) + II(&cc, dd, &ee, aa, bb, X[ 7], 5) + II(&bb, cc, &dd, ee, aa, X[15], 6) + II(&aa, bb, &cc, dd, ee, X[14], 8) + II(&ee, aa, &bb, cc, dd, X[ 5], 6) + II(&dd, ee, &aa, bb, cc, X[ 6], 5) II(&cc, dd, &ee, aa, bb, X[ 2], 12) /* round 5 */ - JJ(&bb, cc, &dd, ee, aa, X[ 4], 9) + JJ(&bb, cc, &dd, ee, aa, X[ 4], 9) JJ(&aa, bb, &cc, dd, ee, X[ 0], 15) - JJ(&ee, aa, &bb, cc, dd, X[ 5], 5) + JJ(&ee, aa, &bb, cc, dd, X[ 5], 5) JJ(&dd, ee, &aa, bb, cc, X[ 9], 11) - JJ(&cc, dd, &ee, aa, bb, X[ 7], 6) - JJ(&bb, cc, &dd, ee, aa, X[12], 8) + JJ(&cc, dd, &ee, aa, bb, X[ 7], 6) + JJ(&bb, cc, &dd, ee, aa, X[12], 8) JJ(&aa, bb, &cc, dd, ee, X[ 2], 13) JJ(&ee, aa, &bb, cc, dd, X[10], 12) - JJ(&dd, ee, &aa, bb, cc, X[14], 5) + JJ(&dd, ee, &aa, bb, cc, X[14], 5) JJ(&cc, dd, &ee, aa, bb, X[ 1], 12) JJ(&bb, cc, &dd, ee, aa, X[ 3], 13) JJ(&aa, bb, &cc, dd, ee, X[ 8], 14) JJ(&ee, aa, &bb, cc, dd, X[11], 11) - JJ(&dd, ee, &aa, bb, cc, X[ 6], 8) - JJ(&cc, dd, &ee, aa, bb, X[15], 5) - JJ(&bb, cc, &dd, ee, aa, X[13], 6) + JJ(&dd, ee, &aa, bb, cc, X[ 6], 8) + JJ(&cc, dd, &ee, aa, bb, X[15], 5) + JJ(&bb, cc, &dd, ee, aa, X[13], 6) /* parallel round 1 */ - JJJ(&aaa, bbb, &ccc, ddd, eee, X[ 5], 8) - JJJ(&eee, aaa, &bbb, ccc, ddd, X[14], 9) - JJJ(&ddd, eee, &aaa, bbb, ccc, X[ 7], 9) + JJJ(&aaa, bbb, &ccc, ddd, eee, X[ 5], 8) + JJJ(&eee, aaa, &bbb, ccc, ddd, X[14], 9) + JJJ(&ddd, eee, &aaa, bbb, ccc, X[ 7], 9) JJJ(&ccc, ddd, &eee, aaa, bbb, X[ 0], 11) JJJ(&bbb, ccc, &ddd, eee, aaa, X[ 9], 13) JJJ(&aaa, bbb, &ccc, ddd, eee, X[ 2], 15) JJJ(&eee, aaa, &bbb, ccc, ddd, X[11], 15) - JJJ(&ddd, eee, &aaa, bbb, ccc, X[ 4], 5) - JJJ(&ccc, ddd, &eee, aaa, bbb, X[13], 7) - JJJ(&bbb, ccc, &ddd, eee, aaa, X[ 6], 7) - JJJ(&aaa, bbb, &ccc, ddd, eee, X[15], 8) + JJJ(&ddd, eee, &aaa, bbb, ccc, X[ 4], 5) + JJJ(&ccc, ddd, &eee, aaa, bbb, X[13], 7) + JJJ(&bbb, ccc, &ddd, eee, aaa, X[ 6], 7) + JJJ(&aaa, bbb, &ccc, ddd, eee, X[15], 8) JJJ(&eee, aaa, &bbb, ccc, ddd, X[ 8], 11) JJJ(&ddd, eee, &aaa, bbb, ccc, X[ 1], 14) JJJ(&ccc, ddd, &eee, aaa, bbb, X[10], 14) JJJ(&bbb, ccc, &ddd, eee, aaa, X[ 3], 12) - JJJ(&aaa, bbb, &ccc, ddd, eee, X[12], 6) + JJJ(&aaa, bbb, &ccc, ddd, eee, X[12], 6) /* parallel round 2 */ - III(&eee, aaa, &bbb, ccc, ddd, X[ 6], 9) + III(&eee, aaa, &bbb, ccc, ddd, X[ 6], 9) III(&ddd, eee, &aaa, bbb, ccc, X[11], 13) III(&ccc, ddd, &eee, aaa, bbb, X[ 3], 15) - III(&bbb, ccc, &ddd, eee, aaa, X[ 7], 7) + III(&bbb, ccc, &ddd, eee, aaa, X[ 7], 7) III(&aaa, bbb, &ccc, ddd, eee, X[ 0], 12) - III(&eee, aaa, &bbb, ccc, ddd, X[13], 8) - III(&ddd, eee, &aaa, bbb, ccc, X[ 5], 9) + III(&eee, aaa, &bbb, ccc, ddd, X[13], 8) + III(&ddd, eee, &aaa, bbb, ccc, X[ 5], 9) III(&ccc, ddd, &eee, aaa, bbb, X[10], 11) - III(&bbb, ccc, &ddd, eee, aaa, X[14], 7) - III(&aaa, bbb, &ccc, ddd, eee, X[15], 7) + III(&bbb, ccc, &ddd, eee, aaa, X[14], 7) + III(&aaa, bbb, &ccc, ddd, eee, X[15], 7) III(&eee, aaa, &bbb, ccc, ddd, X[ 8], 12) - III(&ddd, eee, &aaa, bbb, ccc, X[12], 7) - III(&ccc, ddd, &eee, aaa, bbb, X[ 4], 6) + III(&ddd, eee, &aaa, bbb, ccc, X[12], 7) + III(&ccc, ddd, &eee, aaa, bbb, X[ 4], 6) III(&bbb, ccc, &ddd, eee, aaa, X[ 9], 15) III(&aaa, bbb, &ccc, ddd, eee, X[ 1], 13) III(&eee, aaa, &bbb, ccc, ddd, X[ 2], 11) /* parallel round 3 */ - HHH(&ddd, eee, &aaa, bbb, ccc, X[15], 9) - HHH(&ccc, ddd, &eee, aaa, bbb, X[ 5], 7) + HHH(&ddd, eee, &aaa, bbb, ccc, X[15], 9) + HHH(&ccc, ddd, &eee, aaa, bbb, X[ 5], 7) HHH(&bbb, ccc, &ddd, eee, aaa, X[ 1], 15) HHH(&aaa, bbb, &ccc, ddd, eee, X[ 3], 11) - HHH(&eee, aaa, &bbb, ccc, ddd, X[ 7], 8) - HHH(&ddd, eee, &aaa, bbb, ccc, X[14], 6) - HHH(&ccc, ddd, &eee, aaa, bbb, X[ 6], 6) + HHH(&eee, aaa, &bbb, ccc, ddd, X[ 7], 8) + HHH(&ddd, eee, &aaa, bbb, ccc, X[14], 6) + HHH(&ccc, ddd, &eee, aaa, bbb, X[ 6], 6) HHH(&bbb, ccc, &ddd, eee, aaa, X[ 9], 14) HHH(&aaa, bbb, &ccc, ddd, eee, X[11], 12) HHH(&eee, aaa, &bbb, ccc, ddd, X[ 8], 13) - HHH(&ddd, eee, &aaa, bbb, ccc, X[12], 5) + HHH(&ddd, eee, &aaa, bbb, ccc, X[12], 5) HHH(&ccc, ddd, &eee, aaa, bbb, X[ 2], 14) HHH(&bbb, ccc, &ddd, eee, aaa, X[10], 13) HHH(&aaa, bbb, &ccc, ddd, eee, X[ 0], 13) - HHH(&eee, aaa, &bbb, ccc, ddd, X[ 4], 7) - HHH(&ddd, eee, &aaa, bbb, ccc, X[13], 5) + HHH(&eee, aaa, &bbb, ccc, ddd, X[ 4], 7) + HHH(&ddd, eee, &aaa, bbb, ccc, X[13], 5) /* parallel round 4 */ GGG(&ccc, ddd, &eee, aaa, bbb, X[ 8], 15) - GGG(&bbb, ccc, &ddd, eee, aaa, X[ 6], 5) - GGG(&aaa, bbb, &ccc, ddd, eee, X[ 4], 8) + GGG(&bbb, ccc, &ddd, eee, aaa, X[ 6], 5) + GGG(&aaa, bbb, &ccc, ddd, eee, X[ 4], 8) GGG(&eee, aaa, &bbb, ccc, ddd, X[ 1], 11) GGG(&ddd, eee, &aaa, bbb, ccc, X[ 3], 14) GGG(&ccc, ddd, &eee, aaa, bbb, X[11], 14) - GGG(&bbb, ccc, &ddd, eee, aaa, X[15], 6) + GGG(&bbb, ccc, &ddd, eee, aaa, X[15], 6) GGG(&aaa, bbb, &ccc, ddd, eee, X[ 0], 14) - GGG(&eee, aaa, &bbb, ccc, ddd, X[ 5], 6) - GGG(&ddd, eee, &aaa, bbb, ccc, X[12], 9) + GGG(&eee, aaa, &bbb, ccc, ddd, X[ 5], 6) + GGG(&ddd, eee, &aaa, bbb, ccc, X[12], 9) GGG(&ccc, ddd, &eee, aaa, bbb, X[ 2], 12) - GGG(&bbb, ccc, &ddd, eee, aaa, X[13], 9) + GGG(&bbb, ccc, &ddd, eee, aaa, X[13], 9) GGG(&aaa, bbb, &ccc, ddd, eee, X[ 9], 12) - GGG(&eee, aaa, &bbb, ccc, ddd, X[ 7], 5) + GGG(&eee, aaa, &bbb, ccc, ddd, X[ 7], 5) GGG(&ddd, eee, &aaa, bbb, ccc, X[10], 15) - GGG(&ccc, ddd, &eee, aaa, bbb, X[14], 8) + GGG(&ccc, ddd, &eee, aaa, bbb, X[14], 8) /* parallel round 5 */ - FFF(&bbb, ccc, &ddd, eee, aaa, X[12] , 8) - FFF(&aaa, bbb, &ccc, ddd, eee, X[15] , 5) - FFF(&eee, aaa, &bbb, ccc, ddd, X[10] , 12) - FFF(&ddd, eee, &aaa, bbb, ccc, X[ 4] , 9) - FFF(&ccc, ddd, &eee, aaa, bbb, X[ 1] , 12) - FFF(&bbb, ccc, &ddd, eee, aaa, X[ 5] , 5) - FFF(&aaa, bbb, &ccc, ddd, eee, X[ 8] , 14) - FFF(&eee, aaa, &bbb, ccc, ddd, X[ 7] , 6) - FFF(&ddd, eee, &aaa, bbb, ccc, X[ 6] , 8) - FFF(&ccc, ddd, &eee, aaa, bbb, X[ 2] , 13) - FFF(&bbb, ccc, &ddd, eee, aaa, X[13] , 6) - FFF(&aaa, bbb, &ccc, ddd, eee, X[14] , 5) - FFF(&eee, aaa, &bbb, ccc, ddd, X[ 0] , 15) - FFF(&ddd, eee, &aaa, bbb, ccc, X[ 3] , 13) - FFF(&ccc, ddd, &eee, aaa, bbb, X[ 9] , 11) - FFF(&bbb, ccc, &ddd, eee, aaa, X[11] , 11) + FFF(&bbb, ccc, &ddd, eee, aaa, X[12], 8) + FFF(&aaa, bbb, &ccc, ddd, eee, X[15], 5) + FFF(&eee, aaa, &bbb, ccc, ddd, X[10], 12) + FFF(&ddd, eee, &aaa, bbb, ccc, X[ 4], 9) + FFF(&ccc, ddd, &eee, aaa, bbb, X[ 1], 12) + FFF(&bbb, ccc, &ddd, eee, aaa, X[ 5], 5) + FFF(&aaa, bbb, &ccc, ddd, eee, X[ 8], 14) + FFF(&eee, aaa, &bbb, ccc, ddd, X[ 7], 6) + FFF(&ddd, eee, &aaa, bbb, ccc, X[ 6], 8) + FFF(&ccc, ddd, &eee, aaa, bbb, X[ 2], 13) + FFF(&bbb, ccc, &ddd, eee, aaa, X[13], 6) + FFF(&aaa, bbb, &ccc, ddd, eee, X[14], 5) + FFF(&eee, aaa, &bbb, ccc, ddd, X[ 0], 15) + FFF(&ddd, eee, &aaa, bbb, ccc, X[ 3], 13) + FFF(&ccc, ddd, &eee, aaa, bbb, X[ 9], 11) + FFF(&bbb, ccc, &ddd, eee, aaa, X[11], 11) /* combine results */ MDbuf = (MDbuf.1 &+ cc &+ ddd, diff --git a/Sources/Core/Utility/String+Extension.swift b/Sources/Core/Utility/String+Extension.swift index 45a7ecbf3..8bbe1f688 100755 --- a/Sources/Core/Utility/String+Extension.swift +++ b/Sources/Core/Utility/String+Extension.swift @@ -105,7 +105,7 @@ extension String { func matchingStrings(regex: String) -> [[String]] { guard let regex = try? NSRegularExpression(pattern: regex, options: []) else { return [] } let nsString = self as NSString - let results = regex.matches(in: self, options: [], range: NSMakeRange(0, nsString.length)) + let results = regex.matches(in: self, options: [], range: NSRange(location: 0, length: nsString.length)) return results.map { result in (0.. Data? { - guard let publicKey = SECP256K1.privateToPublic(privateKey: privateKey, compressed: compressed) else {return nil} + guard let publicKey = SECP256K1.privateToPublic(privateKey: privateKey, compressed: compressed) else {return nil} 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. @@ -104,7 +102,7 @@ public struct Utilities { let unitDecimals = decimals guard let beforeDecPoint = BigUInt(components[0], radix: 10) else {return nil} var mainPart = beforeDecPoint*BigUInt(10).power(unitDecimals) - if (components.count == 2) { + if components.count == 2 { let numDigits = components[1].count guard numDigits <= unitDecimals else {return nil} guard let afterDecPoint = BigUInt(components[1], radix: 10) else {return nil} @@ -178,7 +176,7 @@ public struct Utilities { } else if fallbackToScientific { var firstDigit = 0 for char in fullPaddedRemainder { - if (char == "0") { + if char == "0" { firstDigit = firstDigit + 1 } else { let firstDecimalUnit = String(fullPaddedRemainder[firstDigit ..< firstDigit+1]) @@ -204,7 +202,7 @@ public struct Utilities { return fullRemainder + "e-" + String(firstDigit) } } - if (toDecimals == 0) { + if toDecimals == 0 { return String(quotient) } return String(quotient) + decimalSeparator + remainderPadded @@ -243,7 +241,6 @@ public struct Utilities { return Utilities.publicToAddress(publicKey) } - /// Recover the Ethereum address from recoverable secp256k1 signature. /// Takes a hash of some message. What message is hashed should be checked by user separately. /// @@ -285,7 +282,7 @@ public struct Utilities { /// Unmarshals a 65 byte recoverable EC signature into internal structure. static func unmarshalSignature(signatureData: Data) -> SECP256K1.UnmarshaledSignature? { - if (signatureData.count != 65) {return nil} + if signatureData.count != 65 {return nil} let bytes = signatureData.bytes let r = Array(bytes[0..<32]) let s = Array(bytes[32..<64]) diff --git a/Sources/Core/Web3Error/Web3Error.swift b/Sources/Core/Web3Error/Web3Error.swift index 1c5b5c03f..aaf021288 100644 --- a/Sources/Core/Web3Error/Web3Error.swift +++ b/Sources/Core/Web3Error/Web3Error.swift @@ -25,7 +25,6 @@ public enum Web3Error: Error { case generalError(err: Error) case unknownError - public var errorDescription: String { switch self { diff --git a/Sources/web3swift/Browser/Bridge.swift b/Sources/web3swift/Browser/Bridge.swift index 597277003..2aa9f593b 100644 --- a/Sources/web3swift/Browser/Bridge.swift +++ b/Sources/web3swift/Browser/Bridge.swift @@ -156,7 +156,7 @@ extension Bridge: WKScriptMessageHandler { return } if let callbackID = (body[MessageKey.callback] as? NSNumber) { - defaultHandler(name, body[MessageKey.parameters] as? [String: Any]) { [weak self] (results) in + defaultHandler(name, body[MessageKey.parameters] as? [String: Any]) { [weak self] results in guard let strongSelf = self else { return } @@ -165,7 +165,7 @@ extension Bridge: WKScriptMessageHandler { webView.st_dispatchBridgeEvent(Bridge.callbackEventName, parameters: ["id": callbackID], results: results, completionHandler: nil) } } else { - defaultHandler(name, body[MessageKey.parameters] as? [String: Any]) { (results) in + defaultHandler(name, body[MessageKey.parameters] as? [String: Any]) { _ in // Do Nothing } } @@ -173,7 +173,7 @@ extension Bridge: WKScriptMessageHandler { } if let callbackID = (body[MessageKey.callback] as? NSNumber) { - handler(body[MessageKey.parameters] as? [String: Any]) { [weak self] (results) in + handler(body[MessageKey.parameters] as? [String: Any]) { [weak self] results in guard let strongSelf = self else { return } @@ -182,7 +182,7 @@ extension Bridge: WKScriptMessageHandler { webView.st_dispatchBridgeEvent(Bridge.callbackEventName, parameters: ["id": callbackID], results: results, completionHandler: nil) } } else { - handler(body[MessageKey.parameters] as? [String: Any]) { (results) in + handler(body[MessageKey.parameters] as? [String: Any]) { _ in // Do Nothing } } @@ -239,7 +239,7 @@ fileprivate extension WKWebView { } else { // When JSON Not Serializable, Invoke with Default Parameters switch results { - case .success(_): + case .success: jsString = "(function() { var event = new CustomEvent('\(eventName)', {'detail': {'parameters': {}}}); document.dispatchEvent(event)}());" case .failure(let error): jsString = "(function() { var event = new CustomEvent('\(eventName)', {'detail': {'error': {'code': \(error.code), 'description': '\(error.description)'}}}); document.dispatchEvent(event)}());" diff --git a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+Call.swift b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+Call.swift index e6b7b5d86..c837c1ea0 100755 --- a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+Call.swift +++ b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+Call.swift @@ -6,7 +6,6 @@ import Foundation import Core - extension Web3.Eth { public func callTransaction(_ transaction: CodableTransaction) async throws -> Data { let request = APIRequest.call(transaction, transaction.callOnBlock ?? .latest) diff --git a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+EstimateGas.swift b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+EstimateGas.swift index 4d8388baa..7d1fa7578 100755 --- a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+EstimateGas.swift +++ b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+EstimateGas.swift @@ -7,7 +7,6 @@ import Foundation import BigInt import Core - extension Web3.Eth { public func estimateGas(for transaction: CodableTransaction, onBlock: BlockNumber = .latest) async throws -> BigUInt { let request = APIRequest.estimateGas(transaction, onBlock) diff --git a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+FeeHistory.swift b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+FeeHistory.swift index 434a6509a..d290140fc 100644 --- a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+FeeHistory.swift +++ b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+FeeHistory.swift @@ -8,7 +8,7 @@ import BigInt import Core extension Web3.Eth { - func feeHistory(blockCount: BigUInt, block: BlockNumber, percentiles:[Double]) async throws -> Oracle.FeeHistory { + func feeHistory(blockCount: BigUInt, block: BlockNumber, percentiles: [Double]) async throws -> Oracle.FeeHistory { let request = APIRequest.feeHistory(blockCount, block, percentiles) return try await APIRequest.sendRequest(with: web3.provider, for: request).result } diff --git a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetBlockByHash.swift b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetBlockByHash.swift index d8103091a..893d93a62 100755 --- a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetBlockByHash.swift +++ b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetBlockByHash.swift @@ -7,7 +7,6 @@ import Foundation import BigInt import Core - extension Web3.Eth { public func block(by hash: Data, fullTransactions: Bool = false) async throws -> Block { let request = APIRequest.getBlockByHash(hash.toHexString().addHexPrefix(), fullTransactions) diff --git a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetBlockByNumber.swift b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetBlockByNumber.swift index 2082a3fc5..6763df2cc 100755 --- a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetBlockByNumber.swift +++ b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetBlockByNumber.swift @@ -7,7 +7,6 @@ import Foundation import BigInt import Core - extension Web3.Eth { public func block(by hash: Hash, fullTransactions: Bool = false) async throws -> Block { let request = APIRequest.getBlockByHash(hash, fullTransactions) diff --git a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetBlockNumber.swift b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetBlockNumber.swift index c67796171..b63556897 100755 --- a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetBlockNumber.swift +++ b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetBlockNumber.swift @@ -7,7 +7,6 @@ import Foundation import BigInt import Core - extension Web3.Eth { public func blockNumber() async throws -> BigUInt { try await APIRequest.sendRequest(with: web3.provider, for: .blockNumber).result diff --git a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetCode.swift b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetCode.swift index 5e7c03e84..f17eda612 100644 --- a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetCode.swift +++ b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetCode.swift @@ -7,7 +7,7 @@ import Foundation import Core import BigInt -extension Web3.Eth { +extension Web3.Eth { public func code(for address: EthereumAddress, onBlock: BlockNumber = .latest) async throws -> Hash { let request = APIRequest.getCode(address.address, onBlock) return try await APIRequest.sendRequest(with: provider, for: request).result diff --git a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetGasPrice.swift b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetGasPrice.swift index 01d637211..e902e7736 100755 --- a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetGasPrice.swift +++ b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetGasPrice.swift @@ -7,7 +7,6 @@ import Foundation import BigInt import Core - extension Web3.Eth { public func gasPrice() async throws -> BigUInt { try await APIRequest.sendRequest(with: self.provider, for: .gasPrice).result diff --git a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetTransactionCount.swift b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetTransactionCount.swift index 91187a010..59ff77d35 100755 --- a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetTransactionCount.swift +++ b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetTransactionCount.swift @@ -7,7 +7,6 @@ import Foundation import BigInt import Core - extension Web3.Eth { public func getTransactionCount(for address: EthereumAddress, onBlock: BlockNumber = .latest) async throws -> BigUInt { let request = APIRequest.getTransactionCount(address.address, onBlock) diff --git a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+SendRawTransaction.swift b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+SendRawTransaction.swift index fb1cc1f4b..a74bed92f 100755 --- a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+SendRawTransaction.swift +++ b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+SendRawTransaction.swift @@ -6,7 +6,6 @@ import Foundation import Core - extension Web3.Eth { public func send(raw data: Data) async throws -> TransactionSendingResult { let request = APIRequest.sendRawTransaction(data.toHexString().addHexPrefix()) diff --git a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+SendTransaction.swift b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+SendTransaction.swift index 82e403c41..51f9fe86a 100644 --- a/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+SendTransaction.swift +++ b/Sources/web3swift/EthereumAPICalls/Ethereum/Eth+SendTransaction.swift @@ -8,7 +8,6 @@ import Foundation import BigInt import Core - extension Web3.Eth { public func send(_ transaction: CodableTransaction) async throws -> TransactionSendingResult { let request = APIRequest.sendTransaction(transaction) diff --git a/Sources/web3swift/EthereumAPICalls/Personal/Personal+Sign.swift b/Sources/web3swift/EthereumAPICalls/Personal/Personal+Sign.swift index fa8f6599a..24002e28e 100755 --- a/Sources/web3swift/EthereumAPICalls/Personal/Personal+Sign.swift +++ b/Sources/web3swift/EthereumAPICalls/Personal/Personal+Sign.swift @@ -7,7 +7,6 @@ import Foundation import BigInt import Core - extension Web3.Personal { public func signPersonal(message: Data, from: EthereumAddress, password: String) async throws -> Data { diff --git a/Sources/web3swift/EthereumAPICalls/Personal/Personal+UnlockAccount.swift b/Sources/web3swift/EthereumAPICalls/Personal/Personal+UnlockAccount.swift index b8cb5620a..a01267242 100755 --- a/Sources/web3swift/EthereumAPICalls/Personal/Personal+UnlockAccount.swift +++ b/Sources/web3swift/EthereumAPICalls/Personal/Personal+UnlockAccount.swift @@ -7,7 +7,6 @@ import Foundation import BigInt import Core - extension Web3.Personal { public func unlock(account: EthereumAddress, password: String, seconds: UInt = 300) async throws -> Bool { try await unlock(account: account.address, password: password, seconds: seconds) diff --git a/Sources/web3swift/HookedFunctions/Web3+Wallet.swift b/Sources/web3swift/HookedFunctions/Web3+Wallet.swift index 651c56ee5..0995c0172 100755 --- a/Sources/web3swift/HookedFunctions/Web3+Wallet.swift +++ b/Sources/web3swift/HookedFunctions/Web3+Wallet.swift @@ -51,8 +51,7 @@ extension Web3.Web3Wallet { public func signPersonalMessage(_ personalMessage: Data, account: EthereumAddress, password: String ) throws -> Data { do { - guard let keystoreManager = self.web3.provider.attachedKeystoreManager else - { + guard let keystoreManager = self.web3.provider.attachedKeystoreManager else { throw Web3Error.walletError } guard let data = try Web3Signer.signPersonalMessage(personalMessage, keystore: keystoreManager, account: account, password: password) else { diff --git a/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift b/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift index f5f2ce3ee..5542b970d 100644 --- a/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift +++ b/Sources/web3swift/Tokens/ERC1155/Web3+ERC1155.swift @@ -9,7 +9,6 @@ import Foundation import BigInt import Core - // Multi Token Standard // FIXME: Rewrite this to CodableTransaction protocol IERC1155: IERC165 { @@ -32,7 +31,7 @@ protocol IERC1155Metadata { public class ERC1155: IERC1155 { - private var _tokenId: BigUInt? = nil + private var _tokenId: BigUInt? private var _hasReadProperties: Bool = false public var transaction: CodableTransaction diff --git a/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift b/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift index 6f5e50cd8..cb3510db9 100644 --- a/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift +++ b/Sources/web3swift/Tokens/ERC1376/Web3+ERC1376.swift @@ -68,9 +68,9 @@ protocol IERC1376: IERC20 { // FIXME: Rewrite this to CodableTransaction public class ERC1376: IERC1376, ERC20BaseProperties { - internal var _name: String? = nil - internal var _symbol: String? = nil - internal var _decimals: UInt8? = nil + internal var _name: String? + internal var _symbol: String? + internal var _decimals: UInt8? internal var _hasReadProperties: Bool = false public var transaction: CodableTransaction diff --git a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift index 626275df2..a4a09aab8 100644 --- a/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift +++ b/Sources/web3swift/Tokens/ERC1400/Web3+ERC1400.swift @@ -8,7 +8,6 @@ import Foundation import BigInt import Core - // Security Token Standard protocol IERC1400: IERC20 { @@ -66,9 +65,9 @@ protocol IERC1400: IERC20 { // FIXME: Rewrite this to CodableTransaction public class ERC1400: IERC1400, ERC20BaseProperties { - internal var _name: String? = nil - internal var _symbol: String? = nil - internal var _decimals: UInt8? = nil + internal var _name: String? + internal var _symbol: String? + internal var _decimals: UInt8? internal var _hasReadProperties: Bool = false public var transaction: CodableTransaction diff --git a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift index 292827c15..46ed7f986 100644 --- a/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift +++ b/Sources/web3swift/Tokens/ERC1410/Web3+ERC1410.swift @@ -43,10 +43,10 @@ protocol IERC1410: IERC20 { // FIXME: Rewrite this to CodableTransaction public class ERC1410: IERC1410, ERC20BaseProperties { - internal var _name: String? = nil - internal var _symbol: String? = nil - internal var _decimals: UInt8? = nil - private var _totalSupply: BigUInt? = nil + internal var _name: String? + internal var _symbol: String? + internal var _decimals: UInt8? + private var _totalSupply: BigUInt? internal var _hasReadProperties: Bool = false public var transaction: CodableTransaction diff --git a/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift b/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift index a6b262ba3..d336dca41 100644 --- a/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift +++ b/Sources/web3swift/Tokens/ERC1594/Web3+ERC1594.swift @@ -33,9 +33,9 @@ protocol IERC1594: IERC20 { // FIXME: Rewrite this to CodableTransaction public class ERC1594: IERC1594, ERC20BaseProperties { - internal var _name: String? = nil - internal var _symbol: String? = nil - internal var _decimals: UInt8? = nil + internal var _name: String? + internal var _symbol: String? + internal var _decimals: UInt8? internal var _hasReadProperties: Bool = false public var transaction: CodableTransaction diff --git a/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift index 58454b734..8d5cac8e7 100644 --- a/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift +++ b/Sources/web3swift/Tokens/ERC1633/Web3+ERC1633.swift @@ -20,9 +20,9 @@ protocol IERC1633: IERC20, IERC165 { public class ERC1633: IERC1633, ERC20BaseProperties { - internal var _name: String? = nil - internal var _symbol: String? = nil - internal var _decimals: UInt8? = nil + internal var _name: String? + internal var _symbol: String? + internal var _decimals: UInt8? internal var _hasReadProperties: Bool = false public var transaction: CodableTransaction diff --git a/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift b/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift index 3534bf39b..87ac52811 100644 --- a/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift +++ b/Sources/web3swift/Tokens/ERC1643/Web3+ERC1643.swift @@ -23,9 +23,9 @@ protocol IERC1643: IERC20 { // FIXME: Rewrite this to CodableTransaction public class ERC1643: IERC1643, ERC20BaseProperties { - internal var _name: String? = nil - internal var _symbol: String? = nil - internal var _decimals: UInt8? = nil + internal var _name: String? + internal var _symbol: String? + internal var _decimals: UInt8? internal var _hasReadProperties: Bool = false public var transaction: CodableTransaction diff --git a/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift b/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift index 679d687a0..b003fe196 100644 --- a/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift +++ b/Sources/web3swift/Tokens/ERC1644/Web3+ERC1644.swift @@ -9,7 +9,6 @@ import Foundation import BigInt import Core - // Controller Token Operation Standard protocol IERC1644: IERC20 { @@ -23,9 +22,9 @@ protocol IERC1644: IERC20 { // FIXME: Rewrite this to CodableTransaction public class ERC1644: IERC1644, ERC20BaseProperties { - internal var _name: String? = nil - internal var _symbol: String? = nil - internal var _decimals: UInt8? = nil + internal var _name: String? + internal var _symbol: String? + internal var _decimals: UInt8? internal var _hasReadProperties: Bool = false public var transaction: CodableTransaction diff --git a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift index cc9c515f5..1fb4c3c08 100644 --- a/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift +++ b/Sources/web3swift/Tokens/ERC20/Web3+ERC20.swift @@ -7,7 +7,6 @@ import Foundation import BigInt import Core - // Token Standard protocol IERC20 { func getBalance(account: EthereumAddress) async throws -> BigUInt diff --git a/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift b/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift index 2c5ccfb23..d4e30b4ad 100644 --- a/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift +++ b/Sources/web3swift/Tokens/ERC721/Web3+ERC721.swift @@ -54,7 +54,7 @@ protocol IERC721Enumerable { // can be imperatively read and saved public class ERC721: IERC721 { - private var _tokenId: BigUInt? = nil + private var _tokenId: BigUInt? private var _hasReadProperties: Bool = false public var transaction: CodableTransaction @@ -99,7 +99,6 @@ public class ERC721: IERC721 { guard let tokenId = tokenIdResult["0"] as? BigUInt else {return} self._tokenId = tokenId - self._hasReadProperties = true } @@ -257,4 +256,3 @@ extension ERC721: IERC721Metadata { } } - diff --git a/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift b/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift index 863d4afb3..1e18f3053 100644 --- a/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift +++ b/Sources/web3swift/Tokens/ERC721x/Web3+ERC721x.swift @@ -37,7 +37,7 @@ protocol IERC721x: IERC721, IERC721Metadata, IERC721Enumerable { // FIXME: Rewrite this to CodableTransaction public class ERC721x: IERC721x { - private var _tokenId: BigUInt? = nil + private var _tokenId: BigUInt? private var _hasReadProperties: Bool = false public var transaction: CodableTransaction diff --git a/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift index 40e2bb42b..a015eefa9 100644 --- a/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift +++ b/Sources/web3swift/Tokens/ERC777/Web3+ERC777.swift @@ -8,7 +8,6 @@ import Foundation import BigInt import Core - // A New Advanced Token Standard protocol IERC777: IERC20, IERC820 { func getDefaultOperators() async throws -> [EthereumAddress] @@ -32,9 +31,9 @@ protocol IERC777: IERC20, IERC820 { // FIXME: Rewrite this to CodableTransaction public class ERC777: IERC777, ERC20BaseProperties { - internal var _name: String? = nil - internal var _symbol: String? = nil - internal var _decimals: UInt8? = nil + internal var _name: String? + internal var _symbol: String? + internal var _decimals: UInt8? internal var _hasReadProperties: Bool = false @@ -59,7 +58,6 @@ public class ERC777: IERC777, ERC20BaseProperties { self.abi = abi } - // Must be 18! public func decimals() async throws -> UInt8 { try await self.readProperties() diff --git a/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift b/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift index 158366a3f..bfd7aeb0a 100644 --- a/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift +++ b/Sources/web3swift/Tokens/ERC888/Web3+ERC888.swift @@ -18,9 +18,9 @@ protocol IERC888 { // FIXME: Rewrite this to CodableTransaction public class ERC888: IERC888, ERC20BaseProperties { - internal var _name: String? = nil - internal var _symbol: String? = nil - internal var _decimals: UInt8? = nil + internal var _name: String? + internal var _symbol: String? + internal var _decimals: UInt8? internal var _hasReadProperties: Bool = false public var transaction: CodableTransaction diff --git a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift index 748aca3e1..b61333460 100644 --- a/Sources/web3swift/Tokens/ST20/Web3+ST20.swift +++ b/Sources/web3swift/Tokens/ST20/Web3+ST20.swift @@ -29,9 +29,9 @@ protocol IST20: IERC20 { // FIXME: Rewrite this to CodableTransaction public class ST20: IST20, ERC20BaseProperties { - internal var _name: String? = nil - internal var _symbol: String? = nil - internal var _decimals: UInt8? = nil + internal var _name: String? + internal var _symbol: String? + internal var _decimals: UInt8? internal var _hasReadProperties: Bool = false diff --git a/Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift b/Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift index 112bd824b..17a1f6e38 100644 --- a/Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift +++ b/Sources/web3swift/Tokens/ST20/Web3+SecurityToken.swift @@ -64,9 +64,9 @@ protocol ISecurityToken: IST20, IOwnable { // FIXME: Rewrite this to CodableTransaction public class SecurityToken: ISecurityToken, ERC20BaseProperties { - internal var _name: String? = nil - internal var _symbol: String? = nil - internal var _decimals: UInt8? = nil + internal var _name: String? + internal var _symbol: String? + internal var _decimals: UInt8? internal var _hasReadProperties: Bool = false diff --git a/Sources/web3swift/Utils/EIP/EIP4361.swift b/Sources/web3swift/Utils/EIP/EIP4361.swift index 77b672b9e..d076f2e2c 100644 --- a/Sources/web3swift/Utils/EIP/EIP4361.swift +++ b/Sources/web3swift/Utils/EIP/EIP4361.swift @@ -10,8 +10,8 @@ import Core public typealias SIWE = EIP4361 -fileprivate let datetimePattern = "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(.[0-9]+)?(([Zz])|([+|-]([01][0-9]|2[0-3]):[0-5][0-9]))" -fileprivate let uriPattern = "(([^:?#\\s]+):)?(([^?#\\s]*))?([^?#\\s]*)(\\?([^#\\s]*))?(#(.*))?" +private let datetimePattern = "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(.[0-9]+)?(([Zz])|([+|-]([01][0-9]|2[0-3]):[0-5][0-9]))" +private let uriPattern = "(([^:?#\\s]+):)?(([^?#\\s]*))?([^?#\\s]*)(\\?([^#\\s]*))?(#(.*))?" /// Sign-In with Ethereum protocol and parser implementation. /// diff --git a/Sources/web3swift/Utils/EIP/EIP67Code.swift b/Sources/web3swift/Utils/EIP/EIP67Code.swift index 7cbfd0af3..307684dd4 100755 --- a/Sources/web3swift/Utils/EIP/EIP67Code.swift +++ b/Sources/web3swift/Utils/EIP/EIP67Code.swift @@ -25,7 +25,7 @@ extension Web3 { public var parameters: [(ABI.Element.ParameterType, AnyObject)] public func toString() -> String? { - let encoding = method + "(" + parameters.map({ (el) -> String in + let encoding = method + "(" + parameters.map({ el -> String in if let string = el.1 as? String { return el.0.abiRepresentation + " " + string } else if let number = el.1 as? BigUInt { diff --git a/Sources/web3swift/Utils/EIP/EIP681.swift b/Sources/web3swift/Utils/EIP/EIP681.swift index b635f6002..765c4626a 100755 --- a/Sources/web3swift/Utils/EIP/EIP681.swift +++ b/Sources/web3swift/Utils/EIP/EIP681.swift @@ -166,7 +166,7 @@ extension Web3 { } return nil case let .bytes(length): - var data: Data? = nil + var data: Data? if let bytes = rawValue as? Data { data = bytes } else if let bytes = rawValue as? [UInt8] { @@ -221,7 +221,7 @@ extension Web3 { } } return nil - case .tuple(_): + case .tuple: // TODO: implement! return nil default: return nil @@ -248,9 +248,9 @@ extension Web3 { let match = matcher.matches(in: encoding, options: NSRegularExpression.MatchingOptions.anchored, range: encoding.fullNSRange) guard match.count == 1 else {return nil} guard match[0].numberOfRanges == 5 else {return nil} - var addressString: String? = nil - var chainIDString: String? = nil - var tail: String? = nil + var addressString: String? + var chainIDString: String? + var tail: String? // if let payModifierRange = Range(match[0].range(at: 1), in: encoding) { // let payModifierString = String(encoding[payModifierRange]) // print(payModifierString) @@ -351,7 +351,7 @@ extension Web3 { _ rawValue: String, chainID: BigUInt, inputNumber: Int) async -> FunctionArgument? { - var nativeValue: AnyObject? = nil + var nativeValue: AnyObject? switch inputType { case .address: let val = EIP681Code.TargetAddress(rawValue) @@ -410,7 +410,7 @@ extension Web3 { guard let internalArrays = splitArrayOfArrays(rawValue), (length == 0 || UInt64(internalArrays.count) == length) else { return nil } rawValues = internalArrays - } else if case .tuple(_) = type { + } else if case .tuple = type { // TODO: implement! } else if case .string = type { guard let strings = splitArrayOfStrings(rawValue), @@ -438,7 +438,7 @@ extension Web3 { guard nativeValueArray.count == rawValues.count && (length == 0 || UInt64(rawValues.count) == length) else { return nil } - case .tuple(_): + case .tuple: // TODO: implement! return nil default: return nil @@ -460,9 +460,9 @@ extension Web3 { /// Dropping first and last square brackets. /// That modifies the upper bound value of the first match of `squareBracketRegex`. let rawValue = String(rawValue.dropFirst().dropLast()) - + // TODO: try replacing this manual parsing with JSONDecoder and RawRepresentable - + let squareBracketRegex = try! NSRegularExpression(pattern: "(\\[*)") let match = squareBracketRegex.firstMatch(in: rawValue, range: rawValue.fullNSRange) @@ -505,9 +505,9 @@ extension Web3 { private static func splitArrayOfStrings(_ rawValue: String) -> [String]? { /// Dropping first and last square brackets to exclude them from the first and the last separated element. let rawValue = String(rawValue.dropFirst().dropLast()) - + // TODO: try replacing this manual parsing with JSONDecoder and RawRepresentable - + let elementsBoundary = try! NSRegularExpression(pattern: "\",\"") var indices = Array(elementsBoundary .matches(in: rawValue, range: rawValue.fullNSRange) @@ -540,7 +540,7 @@ extension Web3 { } } -fileprivate class FunctionArgument { +private class FunctionArgument { let argType: ABI.Element.InOut let parameter: Web3.EIP681Code.EIP681Parameter diff --git a/Sources/web3swift/Utils/EIP/EIP712.swift b/Sources/web3swift/Utils/EIP/EIP712.swift index a059f4239..c5ca654be 100644 --- a/Sources/web3swift/Utils/EIP/EIP712.swift +++ b/Sources/web3swift/Utils/EIP/EIP712.swift @@ -17,8 +17,8 @@ public class EIP712 { } public struct EIP712Domain: EIP712Hashable { - public let chainId: EIP712.UInt256? - public let verifyingContract: EIP712.Address + public let chainId: EIP712.UInt256? + public let verifyingContract: EIP712.Address public init(chainId: EIP712.UInt256?, verifyingContract: EIP712.Address) { self.chainId = chainId self.verifyingContract = verifyingContract @@ -143,25 +143,25 @@ fileprivate extension EIP712Hashable { /// [`GnosisSafe.sol`](https://github.com/safe-global/safe-contracts/blob/main/contracts/GnosisSafe.sol#L126). public struct GnosisSafeTx: EIP712Hashable { /// Checksummed address - let to: EIP712.Address + let to: EIP712.Address /// Value in wei - let value: EIP712.UInt256 + let value: EIP712.UInt256 /// 0x prefixed hex string - let data: EIP712.Bytes + let data: EIP712.Bytes /// `0` CALL, `1` DELEGATE_CALL - let operation: EIP712.UInt8 + let operation: EIP712.UInt8 /// Max gas to use in the transaction - let safeTxGas: EIP712.UInt256 + let safeTxGas: EIP712.UInt256 /// Gast costs not related to the transaction execution (signature check, refund payment...) - let baseGas: EIP712.UInt256 + let baseGas: EIP712.UInt256 /// Gas price used for the refund calculation - let gasPrice: EIP712.UInt256 + let gasPrice: EIP712.UInt256 /// Token address, **must be checksummed**, (held by the Safe) to be used as a refund to the sender, if `null` is Ether - let gasToken: EIP712.Address + let gasToken: EIP712.Address /// Checksummed address of receiver of gas payment (or `null` if tx.origin) let refundReceiver: EIP712.Address /// Nonce of the Safe, transaction cannot be executed until Safe's nonce is not equal to this nonce - let nonce: EIP712.UInt256 + let nonce: EIP712.UInt256 public init(to: EIP712.Address, value: EIP712.UInt256, diff --git a/Sources/web3swift/Utils/ENS/ENS.swift b/Sources/web3swift/Utils/ENS/ENS.swift index d598d57e6..64fe7ec78 100755 --- a/Sources/web3swift/Utils/ENS/ENS.swift +++ b/Sources/web3swift/Utils/ENS/ENS.swift @@ -11,10 +11,10 @@ public class ENS { public let web3: Web3 public var registry: Registry - public var resolver: Resolver? = nil - public var baseRegistrar: BaseRegistrar? = nil - public var registrarController: ETHRegistrarController? = nil - public var reverseRegistrar: ReverseRegistrar? = nil + public var resolver: Resolver? + public var baseRegistrar: BaseRegistrar? + public var registrarController: ETHRegistrarController? + public var reverseRegistrar: ReverseRegistrar? public init?(web3: Web3) { self.web3 = web3 diff --git a/Sources/web3swift/Web3/Web3+EIP1559.swift b/Sources/web3swift/Web3/Web3+EIP1559.swift index 8689416f7..7eb5732de 100644 --- a/Sources/web3swift/Web3/Web3+EIP1559.swift +++ b/Sources/web3swift/Web3/Web3+EIP1559.swift @@ -79,7 +79,7 @@ public extension Web3 { let expectedBaseFeePerGas = parentBaseFee + baseFeePerGasDelta return expectedBaseFeePerGas - } else if parent.gasUsed < parentGasTarget { + } else if parent.gasUsed < parentGasTarget { // Otherwise if the parent block used less gas than its target, the baseFee should decrease. let gasUsedDelta = parentGasTarget - parent.gasUsed let baseFeePerGasDelta = parentBaseFee * gasUsedDelta / parentGasTarget / Web3.BaseFeeChangeDenominator diff --git a/Sources/web3swift/Web3/Web3+EventParser.swift b/Sources/web3swift/Web3/Web3+EventParser.swift index bf9a1125d..d6bc21640 100755 --- a/Sources/web3swift/Web3/Web3+EventParser.swift +++ b/Sources/web3swift/Web3/Web3+EventParser.swift @@ -7,7 +7,7 @@ import Foundation import BigInt import Core -//extension web3.web3contract { +// extension web3.web3contract { // /// An event parser to fetch events produced by smart-contract related transactions. Should not be constructed manually, but rather by calling the corresponding function on the web3contract object. // public struct EventParser: EventParserProtocol { // @@ -92,9 +92,9 @@ import Core // return result // } // } -//} +// } // -////extension web3.web3contract.EventParser { +//// extension web3.web3contract.EventParser { //// public func parseTransactionPromise(_ transaction: EthereumTransaction) async throws -> [EventParserResultProtocol] { //// guard let hash = transaction.hash else { //// throw Web3Error.processingError(desc: "Failed to get transaction hash") @@ -171,9 +171,9 @@ import Core // } // } // -//} +// } // -//extension web3.web3contract { +// extension web3.web3contract { // /** // *Fetches events by doing a lookup on "indexed" parameters of the event. Smart-contract developer can make some of event values "indexed" for such fast queries.* // @@ -237,4 +237,4 @@ import Core // return collected // } // } -//} +// } diff --git a/Sources/web3swift/Web3/Web3+Eventloop.swift b/Sources/web3swift/Web3/Web3+Eventloop.swift index 8cb9a1a35..258dc97b7 100755 --- a/Sources/web3swift/Web3/Web3+Eventloop.swift +++ b/Sources/web3swift/Web3/Web3+Eventloop.swift @@ -13,7 +13,7 @@ extension Web3.Eventloop { self.timer!.suspend() self.timer = nil } - + self.timer = RepeatingTimer(timeInterval: timeInterval) self.timer?.eventHandler = self.runnable self.timer?.resume() diff --git a/Sources/web3swift/Web3/Web3+HttpProvider.swift b/Sources/web3swift/Web3/Web3+HttpProvider.swift index b3db61b0f..a5bc7d07d 100755 --- a/Sources/web3swift/Web3/Web3+HttpProvider.swift +++ b/Sources/web3swift/Web3/Web3+HttpProvider.swift @@ -11,7 +11,7 @@ import Core public class Web3HttpProvider: Web3Provider { public var url: URL public var network: Networks? - public var attachedKeystoreManager: KeystoreManager? = nil + public var attachedKeystoreManager: KeystoreManager? public var session: URLSession = {() -> URLSession in let config = URLSessionConfiguration.default let urlSession = URLSession(configuration: config) diff --git a/Sources/web3swift/Web3/Web3+Instance.swift b/Sources/web3swift/Web3/Web3+Instance.swift index 5a798cb0a..1e54f5835 100755 --- a/Sources/web3swift/Web3/Web3+Instance.swift +++ b/Sources/web3swift/Web3/Web3+Instance.swift @@ -27,7 +27,7 @@ public class Web3 { /// Public web3.eth.* namespace. public var eth: Web3.Eth { - if (self.ethInstance != nil) { + if self.ethInstance != nil { return self.ethInstance! } self.ethInstance = Web3.Eth(provider: self.provider, web3: self) @@ -50,7 +50,7 @@ public class Web3 { /// Public web3.personal.* namespace. public var personal: Web3.Personal { - if (self.personalInstance != nil) { + if self.personalInstance != nil { return self.personalInstance! } self.personalInstance = Web3.Personal(provider: self.provider, web3: self) @@ -72,7 +72,7 @@ public class Web3 { /// Public web3.personal.* namespace. public var txPool: Web3.TxPool { - if (self.txPoolInstance != nil) { + if self.txPoolInstance != nil { return self.txPoolInstance! } self.txPoolInstance = Web3.TxPool(provider: self.provider, web3: self) @@ -94,7 +94,7 @@ public class Web3 { /// Public web3.wallet.* namespace. public var wallet: Web3.Web3Wallet { - if (self.walletInstance != nil) { + if self.walletInstance != nil { return self.walletInstance! } self.walletInstance = Web3.Web3Wallet(provider: self.provider, web3: self) @@ -115,7 +115,7 @@ public class Web3 { /// Public web3.browserFunctions.* namespace. public var browserFunctions: Web3.BrowserFunctions { - if (self.browserFunctionsInstance != nil) { + if self.browserFunctionsInstance != nil { return self.browserFunctionsInstance! } self.browserFunctionsInstance = Web3.BrowserFunctions(provider: self.provider, web3: self) @@ -137,7 +137,7 @@ public class Web3 { /// Public web3.browserFunctions.* namespace. public var eventLoop: Web3.Eventloop { - if (self.eventLoopInstance != nil) { + if self.eventLoopInstance != nil { return self.eventLoopInstance! } self.eventLoopInstance = Web3.Eventloop(provider: self.provider, web3: self) @@ -158,7 +158,7 @@ public class Web3 { var provider: Web3Provider // weak var web3: web3? var web3: Web3 - var timer: RepeatingTimer? = nil + var timer: RepeatingTimer? public var monitoredProperties: [MonitoredProperty] = [MonitoredProperty]() // public var monitoredContracts: [MonitoredContract] = [MonitoredContract]() @@ -173,7 +173,7 @@ public class Web3 { // // public typealias SubmissionHookFunction = (inout CodableTransaction) -> Bool - public typealias SubmissionResultHookFunction = (TransactionSendingResult) -> () + public typealias SubmissionResultHookFunction = (TransactionSendingResult) -> Void // public struct AssemblyHook { // public var function: AssemblyHookFunction diff --git a/Sources/web3swift/Web3/Web3+Utils.swift b/Sources/web3swift/Web3/Web3+Utils.swift index 02f30f4a0..39a33631e 100755 --- a/Sources/web3swift/Web3/Web3+Utils.swift +++ b/Sources/web3swift/Web3/Web3+Utils.swift @@ -4881,7 +4881,7 @@ extension Web3.Utils { ] """ - //function setAddr(bytes32 node, address addr) + // function setAddr(bytes32 node, address addr) public static var legacyResolverABI = """ [ { diff --git a/Sources/web3swift/Web3/Web3.swift b/Sources/web3swift/Web3/Web3.swift index ab2731a6e..96c89be42 100755 --- a/Sources/web3swift/Web3/Web3.swift +++ b/Sources/web3swift/Web3/Web3.swift @@ -25,7 +25,7 @@ extension Web3 { let infura = await InfuraProvider(Networks.Mainnet, accessToken: accessToken)! return Web3(provider: infura) } - + /// Initialized Web3 instance bound to Infura's goerli provider. public static func InfuraGoerliWeb3(accessToken: String? = nil) async -> Web3 { let infura = await InfuraProvider(Networks.Goerli, accessToken: accessToken)! diff --git a/Tests/web3swiftTests/localTests/ABIEncoderTest.swift b/Tests/web3swiftTests/localTests/ABIEncoderTest.swift index 0df8c3c84..9e36c9b4d 100644 --- a/Tests/web3swiftTests/localTests/ABIEncoderTest.swift +++ b/Tests/web3swiftTests/localTests/ABIEncoderTest.swift @@ -53,7 +53,6 @@ class ABIEncoderTest: XCTestCase { hex = try ABIEncoder.soliditySha3(EthereumAddress("0x407D73d8a49eeb85D32Cf465507dd71d507100c1")!).toHexString().addHexPrefix() assert(hex == "0x4e8ebbefa452077428f93c9520d3edd60594ff452a29ac7d2ccc11d47f3ab95b") - hex = try ABIEncoder.soliditySha3("Hello!%").toHexString().addHexPrefix() assert(hex == "0x661136a4267dba9ccdf6bfddb7c00e714de936674c4bdb065a531cf1cb15c7fc") @@ -82,7 +81,7 @@ class ABIEncoderTest: XCTestCase { func test_soliditySha3Fail_1() throws { var didFail = false do { - let _ = try ABIEncoder.soliditySha3([""] as [AnyObject]) + _ = try ABIEncoder.soliditySha3([""] as [AnyObject]) } catch { didFail = true } @@ -95,7 +94,7 @@ class ABIEncoderTest: XCTestCase { func test_soliditySha3Fail_2() throws { var didFail = false do { - let _ = try ABIEncoder.soliditySha3("" as AnyObject) + _ = try ABIEncoder.soliditySha3("" as AnyObject) } catch { didFail = true } diff --git a/Tests/web3swiftTests/localTests/AdvancedABIv2Tests.swift b/Tests/web3swiftTests/localTests/AdvancedABIv2Tests.swift index 873d90038..0b99fd8f4 100755 --- a/Tests/web3swiftTests/localTests/AdvancedABIv2Tests.swift +++ b/Tests/web3swiftTests/localTests/AdvancedABIv2Tests.swift @@ -201,7 +201,7 @@ class AdvancedABIv2Tests: LocalTestCase { // MARK: - Encoding ABI Data flow let tx = contract?.createReadOperation("empty") XCTAssertNotNil(tx) - let _ = try await tx!.callContractMethod() + _ = try await tx!.callContractMethod() } func testUserCase() async throws { @@ -214,7 +214,7 @@ class AdvancedABIv2Tests: LocalTestCase { // MARK: - Encoding ABI Data flow let tx = contract?.createReadOperation("getFlagData") XCTAssertNotNil(tx) - let _ = try await tx!.callContractMethod() + _ = try await tx!.callContractMethod() } } diff --git a/Tests/web3swiftTests/localTests/BasicLocalNodeTests.swift b/Tests/web3swiftTests/localTests/BasicLocalNodeTests.swift index 3445601ba..5d3e80188 100755 --- a/Tests/web3swiftTests/localTests/BasicLocalNodeTests.swift +++ b/Tests/web3swiftTests/localTests/BasicLocalNodeTests.swift @@ -80,7 +80,6 @@ class BasicLocalNodeTests: LocalTestCase { let details = try await web3.eth.transactionDetails(txHash) print(details) - let balanceAfterTo = try await web3.eth.getBalance(for: sendToAddress) let balanceAfterFrom = try await web3.eth.getBalance(for: allAddresses[0]) print("Balance after to: " + balanceAfterTo.description) diff --git a/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift b/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift index f9714360f..86a4fe15e 100644 --- a/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift +++ b/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift @@ -54,7 +54,7 @@ class EIP1559BlockTests: LocalTestCase { (40_000_000, 12_965_000, 40_039_061, true), // Upper limit (40_000_000, 12_965_000, 40_039_062, false), // Upper limit +1 (40_000_000, 12_965_000, 39_960_939, true), // lower limit - (40_000_000, 12_965_000, 39_960_938, false), // Lower limit -1 + (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 @@ -121,7 +121,7 @@ class EIP1559BlockTests: LocalTestCase { (Web3.InitialBaseFee, 12_964_999, 20000000, 10000000, Web3.InitialBaseFee), // parent is not London (Web3.InitialBaseFee, 12_965_000, 20000000, 10000000, Web3.InitialBaseFee), // current == target (Web3.InitialBaseFee, 12_965_000, 20000000, 9000000, 987500000), // current below target - (Web3.InitialBaseFee, 12_965_000, 20000000, 11000000, 1012500000), // current above target + (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 diff --git a/Tests/web3swiftTests/localTests/EIP681Tests.swift b/Tests/web3swiftTests/localTests/EIP681Tests.swift index 6c03d8f59..14480c59a 100755 --- a/Tests/web3swiftTests/localTests/EIP681Tests.swift +++ b/Tests/web3swiftTests/localTests/EIP681Tests.swift @@ -19,7 +19,7 @@ class EIP681Tests: XCTestCase { switch eip681Code.targetAddress { case .ethereumAddress(let address): XCTAssertEqual(address.address.lowercased(), testAddress) - case .ensAddress(_): + case .ensAddress: fatalError("Returned target address cannot be ENS address. It must be EthereumAddress.") } @@ -34,7 +34,7 @@ class EIP681Tests: XCTestCase { switch eip681Code.targetAddress { case .ethereumAddress(let address): XCTAssertEqual(address.address.lowercased(), testAddress) - case .ensAddress(_): + case .ensAddress: fatalError("Returned target address cannot be ENS address. It must be EthereumAddress.") } XCTAssertEqual(eip681Code.amount, BigUInt(2014000000000000000)) @@ -48,7 +48,7 @@ class EIP681Tests: XCTestCase { switch eip681Code.targetAddress { case .ethereumAddress(let address): XCTAssertEqual(address.address, testAddress) - case .ensAddress(_): + case .ensAddress: fatalError("Returned target address cannot be ENS address. It must be EthereumAddress.") } @@ -69,7 +69,7 @@ class EIP681Tests: XCTestCase { switch eip681Code.targetAddress { case .ethereumAddress(let address): XCTAssertEqual(address.address, testAddress) - case .ensAddress(_): + case .ensAddress: fatalError("Returned target address cannot be ENS address. It must be EthereumAddress.") } @@ -87,7 +87,7 @@ class EIP681Tests: XCTestCase { XCTAssert(eip681Code != nil) guard let eip681Code = eip681Code else { return } switch eip681Code.targetAddress { - case .ethereumAddress(_): + case .ethereumAddress: fatalError("Returned target address cannot be EthereumAddress. It must be ENS address.") case .ensAddress(let address): XCTAssertEqual(address, testAddress) @@ -109,7 +109,7 @@ class EIP681Tests: XCTestCase { XCTAssert(eip681Code != nil) guard let eip681Code = eip681Code else { return } switch eip681Code.targetAddress { - case .ethereumAddress(_): + case .ethereumAddress: fatalError("Returned target address cannot be EthereumAddress. It must be ENS address.") case .ensAddress(let address): XCTAssertEqual(address, testAddress) @@ -134,7 +134,7 @@ class EIP681Tests: XCTestCase { switch eip681Code.targetAddress { case .ethereumAddress(let address): XCTAssertEqual(address.address, testAddress) - case .ensAddress(_): + case .ensAddress: fatalError("Returned target address cannot be ENS address. It must be EthereumAddress.") } @@ -164,7 +164,7 @@ class EIP681Tests: XCTestCase { switch eip681Code.targetAddress { case .ethereumAddress(let address): XCTAssertEqual(address.address, testAddress) - case .ensAddress(_): + case .ensAddress: fatalError("Returned target address cannot be ENS address. It must be EthereumAddress.") } @@ -194,7 +194,7 @@ class EIP681Tests: XCTestCase { switch eip681Code.targetAddress { case .ethereumAddress(let address): XCTAssertEqual(address.address, testAddress) - case .ensAddress(_): + case .ensAddress: fatalError("Returned target address cannot be ENS address. It must be EthereumAddress.") } @@ -204,7 +204,7 @@ class EIP681Tests: XCTestCase { XCTAssertEqual(eip681Code.parameters[0].type, .array(type: .int(bits: 256), length: 0)) let data = eip681Code.parameters[0].value as? [BigInt] - XCTAssertEqual(data, Array(arrayLiteral: 1, 2, 5000, 3, 4, 10000)) + XCTAssertEqual(data, [BigInt](arrayLiteral: 1, 2, 5000, 3, 4, 10000)) } func testParsingOfArrayOfIntOfFixedLengthAsParameter() async throws { @@ -216,7 +216,7 @@ class EIP681Tests: XCTestCase { switch eip681Code.targetAddress { case .ethereumAddress(let address): XCTAssertEqual(address.address, testAddress) - case .ensAddress(_): + case .ensAddress: fatalError("Returned target address cannot be ENS address. It must be EthereumAddress.") } @@ -226,7 +226,7 @@ class EIP681Tests: XCTestCase { XCTAssertEqual(eip681Code.parameters[0].type, .array(type: .int(bits: 256), length: 3)) let data = eip681Code.parameters[0].value as? [BigInt] - XCTAssertEqual(data, Array(arrayLiteral: 1, 2, 5000)) + XCTAssertEqual(data, [BigInt](arrayLiteral: 1, 2, 5000)) } func testParsingQueryParameterFixedLengthArray() async throws { @@ -247,7 +247,7 @@ class EIP681Tests: XCTestCase { XCTAssertEqual(eip681Code!.parameters[0].type, .array(type: .string, length: 0)) var data = eip681Code!.parameters[0].value as? [String] - XCTAssertEqual(data, ["123","2,5000","wwweer2-=!"]) + XCTAssertEqual(data, ["123", "2,5000", "wwweer2-=!"]) eip681Code = await Web3.EIP681CodeParser.parse("ethereum:0x9aBbDB06A61cC686BD635484439549D45c2449cc@2828/functionName123?string[]=[123,2,5000,wwweer2-=!]") XCTAssert(eip681Code != nil) @@ -255,7 +255,7 @@ class EIP681Tests: XCTestCase { XCTAssertEqual(eip681Code!.parameters[0].type, .array(type: .string, length: 0)) data = eip681Code!.parameters[0].value as? [String] - XCTAssertEqual(data, ["123","2","5000","wwweer2-=!"]) + XCTAssertEqual(data, ["123", "2", "5000", "wwweer2-=!"]) } func testParsingQueryParameterArrayOfStringsArrays() async throws { @@ -265,8 +265,8 @@ class EIP681Tests: XCTestCase { XCTAssertEqual(eip681Code!.parameters[0].type, .array(type: .array(type: .string, length: 0), length: 0)) var data = eip681Code!.parameters[0].value as? [[String]] - XCTAssertEqual(data?[0], ["123","2,5000","wwweer2-=!"]) - XCTAssertEqual(data?[1], ["test1","demo"]) + XCTAssertEqual(data?[0], ["123", "2,5000", "wwweer2-=!"]) + XCTAssertEqual(data?[1], ["test1", "demo"]) eip681Code = await Web3.EIP681CodeParser.parse("ethereum:0x9aBbDB06A61cC686BD635484439549D45c2449cc@2828/functionName123?string[][]=[[123,2,5000,wwweer2-=!],[test1,demo]]") XCTAssert(eip681Code != nil) @@ -274,8 +274,8 @@ class EIP681Tests: XCTestCase { XCTAssertEqual(eip681Code!.parameters[0].type, .array(type: .array(type: .string, length: 0), length: 0)) data = eip681Code!.parameters[0].value as? [[String]] - XCTAssertEqual(data?[0], ["123","2","5000","wwweer2-=!"]) - XCTAssertEqual(data?[1], ["test1","demo"]) + XCTAssertEqual(data?[0], ["123", "2", "5000", "wwweer2-=!"]) + XCTAssertEqual(data?[1], ["test1", "demo"]) } func testMakeEIP681Link() async throws { diff --git a/Tests/web3swiftTests/localTests/ERC20Tests.swift b/Tests/web3swiftTests/localTests/ERC20Tests.swift index 653f40aee..8387fae2b 100755 --- a/Tests/web3swiftTests/localTests/ERC20Tests.swift +++ b/Tests/web3swiftTests/localTests/ERC20Tests.swift @@ -8,7 +8,7 @@ import Core @testable import web3swift -//TODO: refactor me +// TODO: refactor me class ERC20Tests: LocalTestCase { func testERC20name() async throws { diff --git a/Tests/web3swiftTests/localTests/EthereumContractTest.swift b/Tests/web3swiftTests/localTests/EthereumContractTest.swift index f418cc5a2..c0801131c 100644 --- a/Tests/web3swiftTests/localTests/EthereumContractTest.swift +++ b/Tests/web3swiftTests/localTests/EthereumContractTest.swift @@ -103,6 +103,6 @@ class EthereumContractTest: LocalTestCase { } } -fileprivate func getFuncSignature(_ string: String) -> String { +private func getFuncSignature(_ string: String) -> String { return String(string.sha3(.keccak256).prefix(8)).lowercased().addHexPrefix() } diff --git a/Tests/web3swiftTests/localTests/KeystoresTests.swift b/Tests/web3swiftTests/localTests/KeystoresTests.swift index 963c38972..4911c6c39 100755 --- a/Tests/web3swiftTests/localTests/KeystoresTests.swift +++ b/Tests/web3swiftTests/localTests/KeystoresTests.swift @@ -205,7 +205,6 @@ class KeystoresTests: LocalTestCase { // XCTAssert(Data(dataArray!).toHexString().addHexPrefix().lowercased() == "0x594256B0BD4D6C9F21A87F7BA5772A791A10E6110694F44365CD94670E57F1AECD797EF1D1001938719044C7F018026697845EB9AD97D97DE36AB8786AAB5096E7".lowercased()) // } - func testRIPEMD() throws { let data = "message digest".data(using: .ascii) let hash = try! RIPEMD160.hash(message: data!) @@ -272,13 +271,13 @@ class KeystoresTests: LocalTestCase { measure { let ks = try! EthereumKeystoreV3(privateKey: privateKey, password: "TEST")! let account = ks.addresses!.first! - let _ = try! ks.UNSAFE_getPrivateKeyData(password: "TEST", account: account) + _ = try! ks.UNSAFE_getPrivateKeyData(password: "TEST", account: account) } } func testSingleScryptDerivation() throws { let privateKey = Data.randomBytes(length: 32)! - let _ = try! EthereumKeystoreV3(privateKey: privateKey, password: "TEST")! + _ = try! EthereumKeystoreV3(privateKey: privateKey, password: "TEST")! } } diff --git a/Tests/web3swiftTests/localTests/LocalTestCase.swift b/Tests/web3swiftTests/localTests/LocalTestCase.swift index 2714e6c8d..1c61c7c6f 100644 --- a/Tests/web3swiftTests/localTests/LocalTestCase.swift +++ b/Tests/web3swiftTests/localTests/LocalTestCase.swift @@ -33,7 +33,7 @@ class LocalTestCase: XCTestCase { writeTX.transaction.gasPricePolicy = .manual(20000000000) for _ in block..<25 { - let _ = try! await writeTX.writeToChain(password: "") + _ = try! await writeTX.writeToChain(password: "") } } } diff --git a/Tests/web3swiftTests/localTests/PersonalSignatureTests.swift b/Tests/web3swiftTests/localTests/PersonalSignatureTests.swift index ca1114e41..7997f26fd 100755 --- a/Tests/web3swiftTests/localTests/PersonalSignatureTests.swift +++ b/Tests/web3swiftTests/localTests/PersonalSignatureTests.swift @@ -11,7 +11,7 @@ import Core @testable import web3swift class PersonalSignatureTests: XCTestCase { - + func testPersonalSignature() async throws { let web3 = try await Web3.new(LocalTestCase.url) let tempKeystore = try! EthereumKeystoreV3(password: "") @@ -29,7 +29,7 @@ class PersonalSignatureTests: XCTestCase { let signer = try web3.personal.ecrecover(personalMessage: message.data(using: .utf8)!, signature: signature) XCTAssert(expectedAddress == signer, "Failed to sign personal message") } - + // TODO: - write contract func testPersonalSignatureOnContract() async throws { let web3 = try await Web3.new(LocalTestCase.url) @@ -44,19 +44,19 @@ class PersonalSignatureTests: XCTestCase { deployTx.transaction.gasLimitPolicy = .manual(3000000) let deployResult = try await deployTx.writeToChain(password: "web3swift") let txHash = Data.fromHex(deployResult.hash.stripHexPrefix())! - + Thread.sleep(forTimeInterval: 1.0) - + let receipt = try await web3.eth.transactionReceipt(txHash) print(receipt) - + switch receipt.status { case .notYetProcessed: return default: break } - + // Signing let tempKeystore = try! EthereumKeystoreV3(password: "") let keystoreManager = KeystoreManager([tempKeystore!]) @@ -70,7 +70,7 @@ class PersonalSignatureTests: XCTestCase { print("R = " + Data(unmarshalledSignature.r).toHexString()) print("S = " + Data(unmarshalledSignature.s).toHexString()) print("Personal hash = " + Utilities.hashPersonalMessage(message.data(using: .utf8)!)!.toHexString()) - + // Calling contract contract = web3.contract(abiString, at: receipt.contractAddress!)! var tx = contract.createReadOperation("hashPersonalMessage", parameters: [message as AnyObject]) @@ -78,12 +78,12 @@ class PersonalSignatureTests: XCTestCase { 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?.transaction.from = expectedAddress result = try await tx!.callContractMethod() guard let signer = result["signer"]! as? EthereumAddress else { return XCTFail() } XCTAssert(signer == expectedAddress) } - + } diff --git a/Tests/web3swiftTests/localTests/PromisesTests.swift b/Tests/web3swiftTests/localTests/PromisesTests.swift index 5c6130d8b..735050ddd 100755 --- a/Tests/web3swiftTests/localTests/PromisesTests.swift +++ b/Tests/web3swiftTests/localTests/PromisesTests.swift @@ -3,13 +3,13 @@ //// Copyright © 2018 Alex Vlasov. All rights reserved. //// // -//import XCTest -//import Core -//import BigInt +// import XCTest +// import Core +// import BigInt // -//@testable import web3swift +// @testable import web3swift // -//class web3swiftPromisesTests: XCTestCase { +// class web3swiftPromisesTests: XCTestCase { // var urlSession : URLSession? // // func testGetBalancePromise() async throws { @@ -126,4 +126,4 @@ // guard let bal = tokenBalance["0"] as? BigUInt else {return XCTFail()} // print(String(bal)) // } -//} +// } diff --git a/Tests/web3swiftTests/localTests/TestHelpers.swift b/Tests/web3swiftTests/localTests/TestHelpers.swift index d1381f2b3..1af6a9667 100644 --- a/Tests/web3swiftTests/localTests/TestHelpers.swift +++ b/Tests/web3swiftTests/localTests/TestHelpers.swift @@ -16,11 +16,11 @@ class TestHelpers { static func localDeployERC20() async throws -> (Web3, TransactionSendingResult, TransactionReceipt, String) { let abiString = "[{\"inputs\":[{\"internalType\":\"string\",\"name\":\"name_\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"symbol_\",\"type\":\"string\"},{\"internalType\":\"address\",\"name\":\"mintRecipient\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"mintAmount\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"subtractedValue\",\"type\":\"uint256\"}],\"name\":\"decreaseAllowance\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"addedValue\",\"type\":\"uint256\"}],\"name\":\"increaseAllowance\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"mint\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]" let bytecode = Data.fromHex("60806040523480156200001157600080fd5b5060405162001f0c38038062001f0c8339818101604052810190620000379190620003af565b83600490805190602001906200004f9291906200025f565b508260059080519060200190620000689291906200025f565b5033600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16146200012b576000811162000125576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016200011c90620004ce565b60405180910390fd5b620001aa565b6000811115620001a957600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415620001a8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016200019f90620004ac565b60405180910390fd5b5b5b806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516200024d9190620004f0565b60405180910390a3505050506200079e565b8280546200026d90620005f1565b90600052602060002090601f016020900481019282620002915760008555620002dd565b82601f10620002ac57805160ff1916838001178555620002dd565b82800160010185558215620002dd579182015b82811115620002dc578251825591602001919060010190620002bf565b5b509050620002ec9190620002f0565b5090565b5b808211156200030b576000816000905550600101620002f1565b5090565b600062000326620003208462000536565b6200050d565b9050828152602081018484840111156200033f57600080fd5b6200034c848285620005bb565b509392505050565b60008151905062000365816200076a565b92915050565b600082601f8301126200037d57600080fd5b81516200038f8482602086016200030f565b91505092915050565b600081519050620003a98162000784565b92915050565b60008060008060808587031215620003c657600080fd5b600085015167ffffffffffffffff811115620003e157600080fd5b620003ef878288016200036b565b945050602085015167ffffffffffffffff8111156200040d57600080fd5b6200041b878288016200036b565b93505060406200042e8782880162000354565b9250506060620004418782880162000398565b91505092959194509250565b60006200045c6037836200056c565b91506200046982620006cc565b604082019050919050565b600062000483602e836200056c565b915062000490826200071b565b604082019050919050565b620004a681620005b1565b82525050565b60006020820190508181036000830152620004c7816200044d565b9050919050565b60006020820190508181036000830152620004e98162000474565b9050919050565b60006020820190506200050760008301846200049b565b92915050565b6000620005196200052c565b905062000527828262000627565b919050565b6000604051905090565b600067ffffffffffffffff8211156200055457620005536200068c565b5b6200055f82620006bb565b9050602081019050919050565b600082825260208201905092915050565b60006200058a8262000591565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b83811015620005db578082015181840152602081019050620005be565b83811115620005eb576000848401525b50505050565b600060028204905060018216806200060a57607f821691505b602082108114156200062157620006206200065d565b5b50919050565b6200063282620006bb565b810181811067ffffffffffffffff821117156200065457620006536200068c565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f45524332303a206d696e7420726563697069656e7420697320656d7074792c2060008201527f627574206d696e7420616d6f756e742069736e27742030000000000000000000602082015250565b7f45524332303a206d696e7420616d6f756e74206973203020746f206e6f6e2d6560008201527f6d70747920726563697069656e74000000000000000000000000000000000000602082015250565b62000775816200057d565b81146200078157600080fd5b50565b6200078f81620005b1565b81146200079b57600080fd5b50565b61175e80620007ae6000396000f3fe608060405234801561001057600080fd5b50600436106100cf5760003560e01c806340c10f191161008c578063a457c2d711610066578063a457c2d714610228578063a9059cbb14610258578063dd62ed3e14610288578063f2fde38b146102b8576100cf565b806340c10f19146101be57806370a08231146101da57806395d89b411461020a576100cf565b806306fdde03146100d4578063095ea7b3146100f257806318160ddd1461012257806323b872dd14610140578063313ce56714610170578063395093511461018e575b600080fd5b6100dc6102d4565b6040516100e9919061116c565b60405180910390f35b61010c60048036038101906101079190610f74565b610366565b6040516101199190611151565b60405180910390f35b61012a610384565b60405161013791906112ae565b60405180910390f35b61015a60048036038101906101559190610f25565b61038e565b6040516101679190611151565b60405180910390f35b610178610486565b60405161018591906112c9565b60405180910390f35b6101a860048036038101906101a39190610f74565b61048f565b6040516101b59190611151565b60405180910390f35b6101d860048036038101906101d39190610f74565b61053b565b005b6101f460048036038101906101ef9190610ec0565b6106fa565b60405161020191906112ae565b60405180910390f35b610212610742565b60405161021f919061116c565b60405180910390f35b610242600480360381019061023d9190610f74565b6107d4565b60405161024f9190611151565b60405180910390f35b610272600480360381019061026d9190610f74565b6108bf565b60405161027f9190611151565b60405180910390f35b6102a2600480360381019061029d9190610ee9565b6108dd565b6040516102af91906112ae565b60405180910390f35b6102d260048036038101906102cd9190610ec0565b610964565b005b6060600480546102e3906113de565b80601f016020809104026020016040519081016040528092919081815260200182805461030f906113de565b801561035c5780601f106103315761010080835404028352916020019161035c565b820191906000526020600020905b81548152906001019060200180831161033f57829003601f168201915b5050505050905090565b600061037a610373610a38565b8484610a40565b6001905092915050565b6000600254905090565b600061039b848484610c0b565b6000600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006103e6610a38565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082811015610466576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161045d9061120e565b60405180910390fd5b61047a85610472610a38565b858403610a40565b60019150509392505050565b60006012905090565b600061053161049c610a38565b8484600160006104aa610a38565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461052c9190611300565b610a40565b6001905092915050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146105cb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105c2906111ee565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561063b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106329061128e565b60405180910390fd5b806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546106899190611300565b925050819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516106ee91906112ae565b60405180910390a35050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b606060058054610751906113de565b80601f016020809104026020016040519081016040528092919081815260200182805461077d906113de565b80156107ca5780601f1061079f576101008083540402835291602001916107ca565b820191906000526020600020905b8154815290600101906020018083116107ad57829003601f168201915b5050505050905090565b600080600160006107e3610a38565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050828110156108a0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108979061126e565b60405180910390fd5b6108b46108ab610a38565b85858403610a40565b600191505092915050565b60006108d36108cc610a38565b8484610c0b565b6001905092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146109f4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109eb906111ee565b60405180910390fd5b80600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610ab0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610aa79061124e565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610b20576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b17906111ae565b60405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92583604051610bfe91906112ae565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610c7b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c729061122e565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610ceb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ce29061118e565b60405180910390fd5b610cf6838383610e8c565b60008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015610d7c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d73906111ce565b60405180910390fd5b8181036000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610e0f9190611300565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610e7391906112ae565b60405180910390a3610e86848484610e91565b50505050565b505050565b505050565b600081359050610ea5816116fa565b92915050565b600081359050610eba81611711565b92915050565b600060208284031215610ed257600080fd5b6000610ee084828501610e96565b91505092915050565b60008060408385031215610efc57600080fd5b6000610f0a85828601610e96565b9250506020610f1b85828601610e96565b9150509250929050565b600080600060608486031215610f3a57600080fd5b6000610f4886828701610e96565b9350506020610f5986828701610e96565b9250506040610f6a86828701610eab565b9150509250925092565b60008060408385031215610f8757600080fd5b6000610f9585828601610e96565b9250506020610fa685828601610eab565b9150509250929050565b610fb981611368565b82525050565b6000610fca826112e4565b610fd481856112ef565b9350610fe48185602086016113ab565b610fed8161146e565b840191505092915050565b60006110056023836112ef565b91506110108261147f565b604082019050919050565b60006110286022836112ef565b9150611033826114ce565b604082019050919050565b600061104b6026836112ef565b91506110568261151d565b604082019050919050565b600061106e6010836112ef565b91506110798261156c565b602082019050919050565b60006110916028836112ef565b915061109c82611595565b604082019050919050565b60006110b46025836112ef565b91506110bf826115e4565b604082019050919050565b60006110d76024836112ef565b91506110e282611633565b604082019050919050565b60006110fa6025836112ef565b915061110582611682565b604082019050919050565b600061111d601f836112ef565b9150611128826116d1565b602082019050919050565b61113c81611394565b82525050565b61114b8161139e565b82525050565b60006020820190506111666000830184610fb0565b92915050565b600060208201905081810360008301526111868184610fbf565b905092915050565b600060208201905081810360008301526111a781610ff8565b9050919050565b600060208201905081810360008301526111c78161101b565b9050919050565b600060208201905081810360008301526111e78161103e565b9050919050565b6000602082019050818103600083015261120781611061565b9050919050565b6000602082019050818103600083015261122781611084565b9050919050565b60006020820190508181036000830152611247816110a7565b9050919050565b60006020820190508181036000830152611267816110ca565b9050919050565b60006020820190508181036000830152611287816110ed565b9050919050565b600060208201905081810360008301526112a781611110565b9050919050565b60006020820190506112c36000830184611133565b92915050565b60006020820190506112de6000830184611142565b92915050565b600081519050919050565b600082825260208201905092915050565b600061130b82611394565b915061131683611394565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561134b5761134a611410565b5b828201905092915050565b600061136182611374565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60005b838110156113c95780820151818401526020810190506113ae565b838111156113d8576000848401525b50505050565b600060028204905060018216806113f657607f821691505b6020821081141561140a5761140961143f565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000601f19601f8301169050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206260008201527f616c616e63650000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a204e6f74206f776e657200000000000000000000000000000000600082015250565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206160008201527f6c6c6f77616e6365000000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760008201527f207a65726f000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a206d696e7420746f20746865207a65726f206164647265737300600082015250565b61170381611356565b811461170e57600080fd5b50565b61171a81611394565b811461172557600080fd5b5056fea2646970667358221220b6ac3a3baa1a92f9f5628a993657177a7d65adf57696ee461d89686f85a28d6164736f6c63430008040033")! - + let web3 = try await Web3.new(LocalTestCase.url) let allAddresses = try await web3.eth.ownedAccounts() 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 = [ "web3swift", @@ -35,19 +35,19 @@ class TestHelpers { deployTx.transaction.gasLimitPolicy = .manual(3000000) let result = try await deployTx.writeToChain(password: "web3swift") let txHash = Data.fromHex(result.hash.stripHexPrefix())! - + Thread.sleep(forTimeInterval: 1.0) - + let receipt = try await web3.eth.transactionReceipt(txHash) print(receipt) - + switch receipt.status { case .notYetProcessed: throw Web3Error.processingError(desc: "Transaction is unprocessed") default: break } - + return (web3, result, receipt, abiString) } } diff --git a/Tests/web3swiftTests/localTests/TransactionsTests.swift b/Tests/web3swiftTests/localTests/TransactionsTests.swift index a5c3e82e0..79d39f111 100755 --- a/Tests/web3swiftTests/localTests/TransactionsTests.swift +++ b/Tests/web3swiftTests/localTests/TransactionsTests.swift @@ -625,7 +625,7 @@ class TransactionsTests: XCTestCase { XCTFail() } } - + func testEthSendExampleAndGetTransactionReceiptAndDetails() async { do { let web3 = try await Web3.new(LocalTestCase.url) diff --git a/Tests/web3swiftTests/localTests/UncategorizedTests.swift b/Tests/web3swiftTests/localTests/UncategorizedTests.swift index 87a6211fd..8979c580d 100755 --- a/Tests/web3swiftTests/localTests/UncategorizedTests.swift +++ b/Tests/web3swiftTests/localTests/UncategorizedTests.swift @@ -3,7 +3,6 @@ // Copyright © 2018 Alex Vlasov. All rights reserved. // - import XCTest import CryptoSwift import BigInt @@ -14,12 +13,12 @@ import BigInt class UncategorizedTests: XCTestCase { func testBitFunctions () throws { let data = Data([0xf0, 0x02, 0x03]) - let firstBit = data.bitsInRange(0,1) + let firstBit = data.bitsInRange(0, 1) XCTAssert(firstBit == 1) - let first4bits = data.bitsInRange(0,4) + let first4bits = data.bitsInRange(0, 4) XCTAssert(first4bits == 0x0f) } - + func testCombiningPublicKeys() throws { let priv1 = Data(repeating: 0x01, count: 32) let pub1 = Utilities.privateToPublic(priv1, compressed: true)! @@ -30,38 +29,38 @@ class UncategorizedTests: XCTestCase { let compinedPub = Utilities.privateToPublic(compinedPriv, compressed: true) XCTAssert(compinedPub == combined) } - + func testChecksumAddress() throws { let input = "0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359" - let output = EthereumAddress.toChecksumAddress(input); + let output = EthereumAddress.toChecksumAddress(input) XCTAssert(output == "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359", "Failed to checksum address") } - + func testChecksumAddressParsing() throws { let input = "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359" - let addr = EthereumAddress(input); - XCTAssert(addr != nil); + let addr = EthereumAddress(input) + XCTAssert(addr != nil) let invalidInput = "0xfb6916095ca1df60bB79Ce92cE3Ea74c37c5d359" - let invalidAddr = EthereumAddress(invalidInput); - XCTAssert(invalidAddr == nil); + let invalidAddr = EthereumAddress(invalidInput) + XCTAssert(invalidAddr == nil) } - + func testBigUIntFromHex() throws { let hexRepresentation = "0x1c31de57e49fc00".stripHexPrefix() let biguint = BigUInt(hexRepresentation, radix: 16)! XCTAssert(biguint == BigUInt("126978086000000000")) } - + func testBloom() throws { let positive = [ "testtest", "test", "hallo", - "other", + "other" ] let negative = [ "tes", - "lo", + "lo" ] var bloom = EthereumBloomFilter() for str in positive { @@ -69,7 +68,7 @@ class UncategorizedTests: XCTestCase { let oldBytes = bloom.bytes bloom.add(BigUInt(data)) let newBytes = bloom.bytes - if (newBytes != oldBytes) { + if newBytes != oldBytes { print("Added new bits") } } @@ -87,7 +86,7 @@ class UncategorizedTests: XCTestCase { let privKey = SECP256K1.generatePrivateKey() XCTAssert(privKey != nil, "Failed to create new private key") } - + func testIBANcreation() throws { let iban = "XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS" let native = Web3.Utils.Iban(iban) @@ -95,20 +94,20 @@ class UncategorizedTests: XCTestCase { let expectedAddress = "0x00c5496aEe77C1bA1f0854206A26DdA82a81D6D8" let createdAddress = native?.toEthereumAddress()?.address XCTAssert(createdAddress == expectedAddress) - + let address = EthereumAddress("0x03c5496aee77c1ba1f0854206a26dda82a81d6d8")! let fromAddress = Web3.Utils.Iban(address) let ibn = fromAddress?.iban XCTAssert(ibn == "XE83FUTTUNPK7WZJSGGCWVEBARQWQ8YML4") } - + // func testGenericRPCresponse() throws { // let hex = "0x1" // let rpcResponse = JSONRPCresponse(id: 1, jsonrpc: "2.0", result: hex, error: nil) // let value: BigUInt? = rpcResponse.getValue() // XCTAssert(value == 1) // } - + func testPublicMappingsAccess() async throws { let jsonString = "[{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"users\",\"outputs\":[{\"name\":\"name\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"userDeviceCount\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalUsers\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]" let web3 = try await Web3.new(LocalTestCase.url) @@ -138,9 +137,8 @@ class UncategorizedTests: XCTestCase { } measure { for bytes in uuids { - let _ = EthereumBloomFilter.bloom9(bytes) + _ = EthereumBloomFilter.bloom9(bytes) } } } } - diff --git a/Tests/web3swiftTests/localTests/UserCases.swift b/Tests/web3swiftTests/localTests/UserCases.swift index 814b6178b..2b41b3308 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] as [AnyObject])! readTransaction.transaction.from = account let response = try await readTransaction.callContractMethod() let balance = response["0"] as? BigUInt diff --git a/Tests/web3swiftTests/remoteTests/ENSTests.swift b/Tests/web3swiftTests/remoteTests/ENSTests.swift index 3496110e0..598948504 100755 --- a/Tests/web3swiftTests/remoteTests/ENSTests.swift +++ b/Tests/web3swiftTests/remoteTests/ENSTests.swift @@ -10,18 +10,18 @@ import Core // MARK: Works only with network connection class ENSTests: XCTestCase { - + func testDomainNormalization() throws { let normalizedString = NameHash.normalizeDomainName("example.ens") print(normalizedString!) } - + func testNameHash() throws { XCTAssertEqual(NameHash.nameHash(""), Data.fromHex("0x0000000000000000000000000000000000000000000000000000000000000000")) XCTAssertEqual(NameHash.nameHash("eth"), Data.fromHex("0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae")) XCTAssertEqual(NameHash.nameHash("foo.eth"), Data.fromHex("0xde9b09fd7c5f901e23a3f19fecc54828e9c848539801e86591bd9801b019f84f")) } - + func testResolverAddress() async throws { let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let ens = ENS(web3: web3) diff --git a/Tests/web3swiftTests/remoteTests/GasOracleTests.swift b/Tests/web3swiftTests/remoteTests/GasOracleTests.swift index d3c357e30..75b1f7ae0 100644 --- a/Tests/web3swiftTests/remoteTests/GasOracleTests.swift +++ b/Tests/web3swiftTests/remoteTests/GasOracleTests.swift @@ -93,7 +93,6 @@ class GasOracleTests: XCTestCase { // XCTAssert(nullTransactions.isEmpty, "This amount transaction fails to decode: \(nullTransactions.count)") // } - // FIXME: Move it to external test suit. // func testBlockNumber() async throws { // let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) diff --git a/Tests/web3swiftTests/remoteTests/InfuraTests.swift b/Tests/web3swiftTests/remoteTests/InfuraTests.swift index 68570091c..c013d99be 100755 --- a/Tests/web3swiftTests/remoteTests/InfuraTests.swift +++ b/Tests/web3swiftTests/remoteTests/InfuraTests.swift @@ -10,7 +10,7 @@ import Core // MARK: Works only with network connection class InfuraTests: XCTestCase { - + func testGetBalance() async throws { let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let address = EthereumAddress("0xd61b5ca425F8C8775882d4defefC68A6979DBbce")! @@ -18,7 +18,7 @@ class InfuraTests: XCTestCase { let balString = Utilities.formatToPrecision(balance, numberDecimals: Utilities.Units.eth.decimals, formattingDecimals: 3) XCTAssertNotNil(balString) } - + func testGetBlockByHash() async throws { let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let result = try await web3.eth.block(by: "0x6d05ba24da6b7a1af22dc6cc2a1fe42f58b2a5ea4c406b19c8cf672ed8ec0695", fullTransactions: false) @@ -31,33 +31,33 @@ class InfuraTests: XCTestCase { let result = try await web3.eth.block(by: blockHash, fullTransactions: false) XCTAssertEqual(result.number, 5184323) } - + func testGetBlockByNumber1() async throws { let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - let _ = try await web3.eth.block(by: .latest, fullTransactions: false) + _ = try await web3.eth.block(by: .latest, fullTransactions: false) } - + func testGetBlockByNumber2() async throws { let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - let _ = try await web3.eth.block(by: .exact(5184323), fullTransactions: true) + _ = try await web3.eth.block(by: .exact(5184323), fullTransactions: true) } - + func testGetBlockByNumber3() async { let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) do { - let _ = try await web3.eth.block(by: .exact(10000000000000), fullTransactions: true) + _ = try await web3.eth.block(by: .exact(10000000000000), fullTransactions: true) XCTFail("The expression above must throw DecodingError.") } catch { // DecodingError is thrown as a block for the given block number does not exist XCTAssert(error is DecodingError) } } - + func testGasPrice() async throws { let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - let _ = try await web3.eth.gasPrice() + _ = try await web3.eth.gasPrice() } - + // func testGetIndexedEventsPromise() async throws { // let jsonString = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_extraData\",\"type\":\"bytes\"}],\"name\":\"approveAndCall\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"remaining\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"_initialAmount\",\"type\":\"uint256\"},{\"name\":\"_tokenName\",\"type\":\"string\"},{\"name\":\"_decimalUnits\",\"type\":\"uint8\"},{\"name\":\"_tokenSymbol\",\"type\":\"string\"}],\"type\":\"constructor\"},{\"payable\":false,\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},]" // let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) @@ -74,7 +74,7 @@ class InfuraTests: XCTestCase { // XCTAssert(eventParserResult.first?.transactionReceipt != nil) // XCTAssert(eventParserResult.first?.eventLog != nil) // } - + // func testEventParsingBlockByNumberPromise() throws { // let jsonString = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_extraData\",\"type\":\"bytes\"}],\"name\":\"approveAndCall\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"remaining\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"_initialAmount\",\"type\":\"uint256\"},{\"name\":\"_tokenName\",\"type\":\"string\"},{\"name\":\"_decimalUnits\",\"type\":\"uint8\"},{\"name\":\"_tokenSymbol\",\"type\":\"string\"}],\"type\":\"constructor\"},{\"payable\":false,\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},]" // let web3 = Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) diff --git a/Tests/web3swiftTests/remoteTests/RemoteParsingTests.swift b/Tests/web3swiftTests/remoteTests/RemoteParsingTests.swift index 9fa02ccc3..f1ec5d46f 100755 --- a/Tests/web3swiftTests/remoteTests/RemoteParsingTests.swift +++ b/Tests/web3swiftTests/remoteTests/RemoteParsingTests.swift @@ -12,7 +12,7 @@ import Core // MARK: Works only with network connection class RemoteParsingTests: XCTestCase { - + // func testEventParsing1usingABIv2() throws { // print(1) // let jsonString = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_extraData\",\"type\":\"bytes\"}],\"name\":\"approveAndCall\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"remaining\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"_initialAmount\",\"type\":\"uint256\"},{\"name\":\"_tokenName\",\"type\":\"string\"},{\"name\":\"_decimalUnits\",\"type\":\"uint8\"},{\"name\":\"_tokenSymbol\",\"type\":\"string\"}],\"type\":\"constructor\"},{\"payable\":false,\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},]" @@ -38,7 +38,7 @@ class RemoteParsingTests: XCTestCase { // XCTAssert(pres[0].contractAddress == EthereumAddress("0x45245bc59219eeaaf6cd3f382e078a461ff9de7b")!) // XCTAssert(pres[0].transactionReceipt!.transactionHash.toHexString().addHexPrefix() == "0xcb235e8c6ecda032bc82c1084d2159ab82e7e4de35be703da6e80034bc577673") // } - + // func testEventParsing2usingABIv2() throws { // let jsonString = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_extraData\",\"type\":\"bytes\"}],\"name\":\"approveAndCall\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"remaining\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"_initialAmount\",\"type\":\"uint256\"},{\"name\":\"_tokenName\",\"type\":\"string\"},{\"name\":\"_decimalUnits\",\"type\":\"uint8\"},{\"name\":\"_tokenSymbol\",\"type\":\"string\"}],\"type\":\"constructor\"},{\"payable\":false,\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},]" // let web3 = Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) @@ -47,7 +47,7 @@ class RemoteParsingTests: XCTestCase { // let pres = try eventParser.parseBlockByNumber(UInt64(5200120)) // XCTAssert(pres.count == 81) // } - + // func testEventParsing3usingABIv2() throws { // let jsonString = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_extraData\",\"type\":\"bytes\"}],\"name\":\"approveAndCall\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"remaining\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"_initialAmount\",\"type\":\"uint256\"},{\"name\":\"_tokenName\",\"type\":\"string\"},{\"name\":\"_decimalUnits\",\"type\":\"uint8\"},{\"name\":\"_tokenSymbol\",\"type\":\"string\"}],\"type\":\"constructor\"},{\"payable\":false,\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},]" // let web3 = Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) @@ -88,7 +88,7 @@ class RemoteParsingTests: XCTestCase { //// 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])] // } - + // func testEventParsing5usingABIv2() async throws { // let jsonString = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_extraData\",\"type\":\"bytes\"}],\"name\":\"approveAndCall\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"remaining\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"_initialAmount\",\"type\":\"uint256\"},{\"name\":\"_tokenName\",\"type\":\"string\"},{\"name\":\"_decimalUnits\",\"type\":\"uint8\"},{\"name\":\"_tokenSymbol\",\"type\":\"string\"}],\"type\":\"constructor\"},{\"payable\":false,\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},]" // let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) @@ -101,7 +101,7 @@ class RemoteParsingTests: XCTestCase { // guard let result = try await contract?.getIndexedEvents(eventName: "Transfer", filter: filter) else {return XCTFail()} // XCTAssert(result.count == 1) // } - + // func testEventParsing6usingABIv2() async throws { // let jsonString = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_extraData\",\"type\":\"bytes\"}],\"name\":\"approveAndCall\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"remaining\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"_initialAmount\",\"type\":\"uint256\"},{\"name\":\"_tokenName\",\"type\":\"string\"},{\"name\":\"_decimalUnits\",\"type\":\"uint8\"},{\"name\":\"_tokenSymbol\",\"type\":\"string\"}],\"type\":\"constructor\"},{\"payable\":false,\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},]" // let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) diff --git a/Tests/web3swiftTests/remoteTests/ST20AndSecurityTokenTests.swift b/Tests/web3swiftTests/remoteTests/ST20AndSecurityTokenTests.swift index 418c408ab..be8d5b234 100644 --- a/Tests/web3swiftTests/remoteTests/ST20AndSecurityTokenTests.swift +++ b/Tests/web3swiftTests/remoteTests/ST20AndSecurityTokenTests.swift @@ -14,7 +14,7 @@ import Core // MARK: Works only with network connection class ST20AndSecurityTokenTests: XCTestCase { - + // FIXME: Enable me back again // Test fails because there's no such wallet on goerli chain as well as token. // func testERC20TokenCreation() async throws {