Skip to content

Commit ee7c6a3

Browse files
Merge branch 'develop' into master
2 parents b657241 + fd78f00 commit ee7c6a3

File tree

108 files changed

+610
-622
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+610
-622
lines changed

Sources/Core/Contract/ContractProtocol.swift

+5-7
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import BigInt
6969
public protocol ContractProtocol {
7070
/// Address of the referenced smart contract. Can be set later, e.g. if the contract is deploying and address is not yet known.
7171
var address: EthereumAddress? {get set}
72-
72+
7373
/// All ABI elements like: events, functions, constructors and errors.
7474
var abi: [ABI.Element] {get}
7575

@@ -81,13 +81,13 @@ public protocol ContractProtocol {
8181
/// - and 4 bytes signature `0xffffffff` (expected to be lowercased).
8282
/// The mapping by name (e.g. `getData`) is the one most likely expected to return arrays with
8383
/// more than one entry due to the fact that solidity allows method overloading.
84-
var methods: [String:[ABI.Element.Function]] {get}
84+
var methods: [String: [ABI.Element.Function]] {get}
8585

8686
/// All values from ``methods``.
8787
var allMethods: [ABI.Element.Function] {get}
8888

8989
/// Events filtered from ``abi`` and mapped to their unchanged ``ABI/Element/Event/name``.
90-
var events: [String:ABI.Element.Event] {get}
90+
var events: [String: ABI.Element.Event] {get}
9191

9292
/// All values from ``events``.
9393
var allEvents: [ABI.Element.Event] {get}
@@ -225,7 +225,6 @@ extension DefaultContractProtocol {
225225
let parameters = parameters,
226226
!parameters.isEmpty {
227227
guard constructor.inputs.count == parameters.count,
228-
// FIXME: This should be zipped, because Arrays don't guarantee it's elements order
229228
let encodedData = constructor.encodeParameters(parameters) else {
230229
NSLog("Constructor encoding will fail as the number of input arguments doesn't match the number of given arguments.")
231230
return nil
@@ -278,11 +277,10 @@ extension DefaultContractProtocol {
278277

279278
public func parseEvent(_ eventLog: EventLog) -> (eventName: String?, eventData: [String: Any]?) {
280279
for (eName, ev) in self.events {
281-
if (!ev.anonymous) {
280+
if !ev.anonymous {
282281
if eventLog.topics[0] != ev.topic {
283282
continue
284-
}
285-
else {
283+
} else {
286284
let logTopics = eventLog.topics
287285
let logData = eventLog.data
288286
let parsed = ev.decodeReturnedLogs(eventLogTopics: logTopics, eventLogData: logData)

Sources/Core/Contract/EthereumContract.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import BigInt
1010
/// constructor, errors and optional ``EthereumAddress`` that could be set later.
1111
public class EthereumContract: DefaultContractProtocol {
1212

13-
public var address: EthereumAddress? = nil
13+
public var address: EthereumAddress?
1414

1515
public let abi: [ABI.Element]
1616
public let methods: [String: [ABI.Element.Function]]
@@ -40,7 +40,7 @@ public class EthereumContract: DefaultContractProtocol {
4040
public convenience required init(_ abiString: String, at: EthereumAddress? = nil) throws {
4141
let jsonData = abiString.data(using: .utf8)
4242
let abi = try JSONDecoder().decode([ABI.Record].self, from: jsonData!)
43-
let abiNative = try abi.map({ (record) -> ABI.Element in
43+
let abiNative = try abi.map({ record -> ABI.Element in
4444
return try record.parse()
4545
})
4646
try self.init(abi: abiNative, at: at)

Sources/Core/EthereumABI/ABIDecoding.swift

+7-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public struct ABIDecoder { }
1010

1111
extension ABIDecoder {
1212
public static func decode(types: [ABI.Element.InOut], data: Data) -> [AnyObject]? {
13-
let params = types.compactMap { (el) -> ABI.Element.ParameterType in
13+
let params = types.compactMap { el -> ABI.Element.ParameterType in
1414
return el.type
1515
}
1616
return decode(types: params, data: data)
@@ -118,10 +118,9 @@ extension ABIDecoder {
118118
let (v, c) = decodeSingleType(type: subType, data: dataSlice, pointer: subpointer)
119119
guard let valueUnwrapped = v, let consumedUnwrapped = c else {break}
120120
toReturn.append(valueUnwrapped)
121-
if (subType.isStatic) {
121+
if subType.isStatic {
122122
subpointer = subpointer + consumedUnwrapped
123-
}
124-
else {
123+
} else {
125124
subpointer = consumedUnwrapped // need to go by nextElementPointer
126125
}
127126
}
@@ -224,16 +223,16 @@ extension ABIDecoder {
224223
eventContent["name"]=event.name
225224
let logs = eventLogTopics
226225
let dataForProcessing = eventLogData
227-
let indexedInputs = event.inputs.filter { (inp) -> Bool in
226+
let indexedInputs = event.inputs.filter { inp -> Bool in
228227
return inp.indexed
229228
}
230-
if (logs.count == 1 && indexedInputs.count > 0) {
229+
if logs.count == 1 && indexedInputs.count > 0 {
231230
return nil
232231
}
233-
let nonIndexedInputs = event.inputs.filter { (inp) -> Bool in
232+
let nonIndexedInputs = event.inputs.filter { inp -> Bool in
234233
return !inp.indexed
235234
}
236-
let nonIndexedTypes = nonIndexedInputs.compactMap { (inp) -> ABI.Element.ParameterType in
235+
let nonIndexedTypes = nonIndexedInputs.compactMap { inp -> ABI.Element.ParameterType in
237236
return inp.type
238237
}
239238
guard logs.count == indexedInputs.count + 1 else {return nil}

Sources/Core/EthereumABI/ABIElements.swift

+16-16
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ public extension ABI {
156156
public struct EthError {
157157
public let name: String
158158
public let inputs: [Input]
159-
159+
160160
public struct Input {
161161
public let name: String
162162
public let type: ParameterType
163-
163+
164164
public init(name: String, type: ParameterType) {
165165
self.name = name
166166
self.type = type
@@ -177,15 +177,15 @@ extension ABI.Element {
177177
switch self {
178178
case .constructor(let constructor):
179179
return constructor.encodeParameters(parameters)
180-
case .event(_):
180+
case .event:
181181
return nil
182-
case .fallback(_):
182+
case .fallback:
183183
return nil
184184
case .function(let function):
185185
return function.encodeParameters(parameters)
186-
case .receive(_):
186+
case .receive:
187187
return nil
188-
case .error(_):
188+
case .error:
189189
return nil
190190
}
191191
}
@@ -224,17 +224,17 @@ extension ABI.Element.Event {
224224
extension ABI.Element {
225225
public func decodeReturnData(_ data: Data) -> [String: Any]? {
226226
switch self {
227-
case .constructor(_):
227+
case .constructor:
228228
return nil
229-
case .event(_):
229+
case .event:
230230
return nil
231-
case .fallback(_):
231+
case .fallback:
232232
return nil
233233
case .function(let function):
234234
return function.decodeReturnData(data)
235-
case .receive(_):
235+
case .receive:
236236
return nil
237-
case .error(_):
237+
case .error:
238238
return nil
239239
}
240240
}
@@ -245,15 +245,15 @@ extension ABI.Element {
245245
switch self {
246246
case .constructor(let constructor):
247247
return constructor.decodeInputData(data)
248-
case .event(_):
248+
case .event:
249249
return nil
250-
case .fallback(_):
250+
case .fallback:
251251
return nil
252252
case .function(let function):
253253
return function.decodeInputData(data)
254-
case .receive(_):
254+
case .receive:
255255
return nil
256-
case .error(_):
256+
case .error:
257257
return nil
258258
}
259259
}
@@ -347,7 +347,7 @@ extension ABI.Element.Constructor {
347347
/// - inputs: expected input types. Order must be the same as in function declaration.
348348
/// - Returns: decoded dictionary of input arguments mapped to their indices and arguments' names if these are not empty.
349349
/// If decoding of at least one argument fails, `rawData` size is invalid or `methodEncoding` doesn't match - `nil` is returned.
350-
fileprivate func decodeInputData(_ rawData: Data,
350+
private func decodeInputData(_ rawData: Data,
351351
methodEncoding: Data? = nil,
352352
inputs: [ABI.Element.InOut]) -> [String: Any]? {
353353
let data: Data

Sources/Core/EthereumABI/ABIEncoding.swift

+5-10
Original file line numberDiff line numberDiff line change
@@ -130,29 +130,25 @@ extension ABIEncoder {
130130
return nil
131131
}
132132

133-
134133
/// Encode Elements In Out
135134
/// - Parameters:
136135
/// - types: Contract element InOut to encode
137136
/// - values: Contract values of a given element to encode
138137
/// - Returns: Encoded data
139138
public static func encode(types: [ABI.Element.InOut], values: [AnyObject]) -> Data? {
140-
// FIXME: This should be zipped, because Arrays don't guarantee it's elements order
141139
guard types.count == values.count else {return nil}
142-
let params = types.compactMap { (el) -> ABI.Element.ParameterType in
140+
let params = types.compactMap { el -> ABI.Element.ParameterType in
143141
return el.type
144142
}
145143
return encode(types: params, values: values)
146144
}
147145

148-
149146
/// Encode Elements Prarmeter Type
150147
/// - Parameters:
151148
/// - types: Contract parameters type to encode
152149
/// - values: Contract values of a given element to encode
153150
/// - Returns: Encoded data
154151
public static func encode(types: [ABI.Element.ParameterType], values: [AnyObject]) -> Data? {
155-
// FIXME: This should be zipped, because Arrays don't guarantee it's elements order
156152
guard types.count == values.count else {return nil}
157153
var tails = [Data]()
158154
var heads = [Data]()
@@ -192,14 +188,14 @@ extension ABIEncoder {
192188

193189
public static func encodeSingleType(type: ABI.Element.ParameterType, value: AnyObject) -> Data? {
194190
switch type {
195-
case .uint(_):
191+
case .uint:
196192
if let biguint = convertToBigUInt(value) {
197193
return biguint.abiEncode(bits: 256)
198194
}
199195
if let bigint = convertToBigInt(value) {
200196
return bigint.abiEncode(bits: 256)
201197
}
202-
case .int(_):
198+
case .int:
203199
if let biguint = convertToBigUInt(value) {
204200
return biguint.abiEncode(bits: 256)
205201
}
@@ -220,7 +216,7 @@ extension ABIEncoder {
220216
}
221217
case .bool:
222218
if let bool = value as? Bool {
223-
if (bool) {
219+
if bool {
224220
return BigUInt(1).abiEncode(bits: 256)
225221
} else {
226222
return BigUInt(0).abiEncode(bits: 256)
@@ -235,8 +231,7 @@ extension ABIEncoder {
235231
var dataGuess: Data?
236232
if string.hasHexPrefix() {
237233
dataGuess = Data.fromHex(string.lowercased().stripHexPrefix())
238-
}
239-
else {
234+
} else {
240235
dataGuess = string.data(using: .utf8)
241236
}
242237
guard let data = dataGuess else {break}

Sources/Core/EthereumABI/ABIParameterTypes.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ extension ABI.Element {
2828
case .dynamicBytes:
2929
return false
3030
case .array(type: let type, length: let length):
31-
if (length == 0) {
31+
if length == 0 {
3232
return false
3333
}
34-
if (!type.isStatic) {
34+
if !type.isStatic {
3535
return false
3636
}
3737
return true
3838
case .tuple(types: let types):
3939
for t in types {
40-
if (!t.isStatic) {
40+
if !t.isStatic {
4141
return false
4242
}
4343
}
@@ -60,7 +60,7 @@ extension ABI.Element {
6060

6161
var isTuple: Bool {
6262
switch self {
63-
case .tuple(_):
63+
case .tuple:
6464
return true
6565
default:
6666
return false
@@ -129,7 +129,7 @@ extension ABI.Element {
129129
var arraySize: ABI.Element.ArraySize {
130130
switch self {
131131
case .array(type: _, length: let length):
132-
if (length == 0) {
132+
if length == 0 {
133133
return ArraySize.dynamicSize
134134
}
135135
return ArraySize.staticSize(length)
@@ -210,7 +210,7 @@ extension ABI.Element.ParameterType: ABIEncoding {
210210
case .function:
211211
return "function"
212212
case .array(type: let type, length: let length):
213-
if (length == 0) {
213+
if length == 0 {
214214
return "\(type.abiRepresentation)[]"
215215
}
216216
return "\(type.abiRepresentation)[\(length)]"
@@ -235,7 +235,7 @@ extension ABI.Element.ParameterType: ABIValidation {
235235
return type.isValid
236236
case .tuple(types: let types):
237237
for t in types {
238-
if (!t.isValid) {
238+
if !t.isValid {
239239
return false
240240
}
241241
}

0 commit comments

Comments
 (0)