@@ -25,7 +25,7 @@ extension Web3 {
2525 public var parameters : [ ( ABI . Element . ParameterType , Any ) ]
2626
2727 public func toString( ) -> String ? {
28- let encoding = method + " ( " + parameters. map ( { el -> String in
28+ let encoding = method + " ( " + parameters. map { el -> String in
2929 if let string = el. 1 as? String {
3030 return el. 0 . abiRepresentation + " " + string
3131 } else if let number = el. 1 as? BigUInt {
@@ -36,7 +36,7 @@ extension Web3 {
3636 return el. 0 . abiRepresentation + " " + data. toHexString ( ) . addHexPrefix ( )
3737 }
3838 return " "
39- } ) . joined ( separator: " , " ) + " ) "
39+ } . joined ( separator: " , " ) + " ) "
4040 return encoding
4141 }
4242 }
@@ -104,33 +104,34 @@ extension Web3 {
104104 public static func parse( _ string: String ) -> EIP67Code ? {
105105 guard string. hasPrefix ( " ethereum: " ) else { return nil }
106106 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 }
111111 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 }
113118 for comp in components {
114119 switch comp. name {
115120 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 }
118122 code. amount = val
119123 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 }
122125 code. gasLimit = val
123126 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 }
126128 code. data = EIP67Code . DataType. data ( data)
127129 case " function " :
128130 continue
129131 default :
130132 continue
131133 }
132134 }
133- return code
134135 }
135136 }
136137}
0 commit comments