@@ -25,7 +25,7 @@ extension Web3 {
25
25
public var parameters : [ ( ABI . Element . ParameterType , Any ) ]
26
26
27
27
public func toString( ) -> String ? {
28
- let encoding = method + " ( " + parameters. map ( { el -> String in
28
+ let encoding = method + " ( " + parameters. map { el -> String in
29
29
if let string = el. 1 as? String {
30
30
return el. 0 . abiRepresentation + " " + string
31
31
} else if let number = el. 1 as? BigUInt {
@@ -36,7 +36,7 @@ extension Web3 {
36
36
return el. 0 . abiRepresentation + " " + data. toHexString ( ) . addHexPrefix ( )
37
37
}
38
38
return " "
39
- } ) . joined ( separator: " , " ) + " ) "
39
+ } . joined ( separator: " , " ) + " ) "
40
40
return encoding
41
41
}
42
42
}
@@ -104,33 +104,34 @@ extension Web3 {
104
104
public static func parse( _ string: String ) -> EIP67Code ? {
105
105
guard string. hasPrefix ( " ethereum: " ) else { return nil }
106
106
let striped = string. components ( separatedBy: " ethereum: " )
107
- guard striped. count == 2 else { return nil }
108
- guard let encoding = striped [ 1 ] . removingPercentEncoding else { return nil }
109
- guard let url = URL . init ( string: encoding) else { return nil }
110
- guard let address = EthereumAddress ( url. lastPathComponent) else { return nil }
107
+ guard striped. count == 2 ,
108
+ let encoding = striped [ 1 ] . removingPercentEncoding,
109
+ let url = URL . init ( string: encoding) ,
110
+ let address = EthereumAddress ( url. lastPathComponent) else { return nil }
111
111
var code = EIP67Code ( address: address)
112
- guard let components = URLComponents ( string: encoding) ? . queryItems else { return code}
112
+ parseEncodingComponents ( & code, encoding)
113
+ return code
114
+ }
115
+
116
+ private static func parseEncodingComponents( _ code: inout EIP67Code , _ encoding: ) {
117
+ guard let components = URLComponents ( string: encoding) ? . queryItems else { return code }
113
118
for comp in components {
114
119
switch comp. name {
115
120
case " value " :
116
- guard let value = comp. value else { return nil }
117
- guard let val = BigUInt ( value, radix: 10 ) else { return nil }
121
+ guard let value = comp. value, let val = BigUInt ( value, radix: 10 ) else { return nil }
118
122
code. amount = val
119
123
case " gas " :
120
- guard let value = comp. value else { return nil }
121
- guard let val = BigUInt ( value, radix: 10 ) else { return nil }
124
+ guard let value = comp. value, let val = BigUInt ( value, radix: 10 ) else { return nil }
122
125
code. gasLimit = val
123
126
case " data " :
124
- guard let value = comp. value else { return nil }
125
- guard let data = Data . fromHex ( value) else { return nil }
127
+ guard let value = comp. value, let data = Data . fromHex ( value) else { return nil }
126
128
code. data = EIP67Code . DataType. data ( data)
127
129
case " function " :
128
130
continue
129
131
default :
130
132
continue
131
133
}
132
134
}
133
- return code
134
135
}
135
136
}
136
137
}
0 commit comments