@@ -10,16 +10,16 @@ import Core
10
10
11
11
extension Web3 {
12
12
13
- // request = "ethereum" ":" [ "pay-" ]target_address [ "@" chain_id ] [ "/" function_name ] [ "?" parameters ]
14
- // target_address = ethereum_address
15
- // chain_id = 1*DIGIT
16
- // function_name = STRING
17
- // ethereum_address = ( "0x" 40*40HEXDIG ) / ENS_NAME
18
- // parameters = parameter *( "&" parameter )
19
- // parameter = key "=" value
20
- // key = "value" / "gas" / "gasLimit" / "gasPrice" / TYPE
21
- // value = number / ethereum_address / STRING
22
- // number = [ "-" / "+" ] *DIGIT [ "." 1*DIGIT ] [ ( "e" / "E" ) [ 1*DIGIT ] [ "+" UNIT ]
13
+ // request = "ethereum" ":" [ "pay-" ]target_address [ "@" chain_id ] [ "/" function_name ] [ "?" parameters ]
14
+ // target_address = ethereum_address
15
+ // chain_id = 1*DIGIT
16
+ // function_name = STRING
17
+ // ethereum_address = ( "0x" 40*40HEXDIG ) / ENS_NAME
18
+ // parameters = parameter *( "&" parameter )
19
+ // parameter = key "=" value
20
+ // key = "value" / "gas" / "gasLimit" / "gasPrice" / TYPE
21
+ // value = number / ethereum_address / STRING
22
+ // number = [ "-" / "+" ] *DIGIT [ "." 1*DIGIT ] [ ( "e" / "E" ) [ 1*DIGIT ] [ "+" UNIT ]
23
23
24
24
public struct EIP681Code {
25
25
public struct EIP681Parameter {
@@ -91,7 +91,7 @@ extension Web3 {
91
91
92
92
public struct EIP681CodeEncoder {
93
93
public static func encodeFunctionArgument( _ inputType: ABI . Element . ParameterType ,
94
- _ rawValue: AnyObject ) -> String ? {
94
+ _ rawValue: AnyObject ) -> String ? {
95
95
switch inputType {
96
96
case . address:
97
97
if let ethAddress = rawValue as? EthereumAddress {
@@ -288,10 +288,10 @@ extension Web3 {
288
288
for comp in queryItems {
289
289
if let inputType = try ? ABITypeParser . parseTypeString ( comp. name) {
290
290
guard let rawValue = comp. value,
291
- let functionArgument = parseFunctionArgument ( inputType,
292
- rawValue. trimmingCharacters ( in: . whitespacesAndNewlines) ,
293
- chainID: code. chainID ?? 0 ,
294
- inputNumber: inputNumber)
291
+ let functionArgument = await parseFunctionArgument ( inputType,
292
+ rawValue. trimmingCharacters ( in: . whitespacesAndNewlines) ,
293
+ chainID: code. chainID ?? 0 ,
294
+ inputNumber: inputNumber)
295
295
else { continue }
296
296
297
297
inputs. append ( functionArgument. argType)
@@ -351,59 +351,59 @@ extension Web3 {
351
351
private static func parseFunctionArgument( _ inputType: ABI . Element . ParameterType ,
352
352
_ rawValue: String ,
353
353
chainID: BigUInt ,
354
- inputNumber: Int ) -> FunctionArgument ? {
355
- var parsedValue : AnyObject ? = nil
354
+ inputNumber: Int ) async -> FunctionArgument ? {
355
+ var nativeValue : AnyObject ? = nil
356
356
switch inputType {
357
357
case . address:
358
358
let val = EIP681Code . TargetAddress ( rawValue)
359
359
switch val {
360
360
case . ethereumAddress( let ethereumAddress) :
361
- parsedValue = ethereumAddress as AnyObject
361
+ nativeValue = ethereumAddress as AnyObject
362
362
case . ensAddress( let ens) :
363
363
do {
364
- let web = web3 ( provider: InfuraProvider ( Networks . fromInt ( Int ( chainID) ) ?? Networks . Mainnet) !)
364
+ let web = await web3 ( provider: InfuraProvider ( Networks . fromInt ( UInt ( chainID ?? 1 ) ) ?? Networks . Mainnet) !)
365
365
let ensModel = ENS ( web3: web)
366
- try ensModel? . setENSResolver ( withDomain: ens)
367
- let address = try ensModel? . getAddress ( forNode: ens)
368
- parsedValue = address as AnyObject
366
+ try await ensModel? . setENSResolver ( withDomain: ens)
367
+ let address = try await ensModel? . getAddress ( forNode: ens)
368
+ nativeValue = address as AnyObject
369
369
} catch {
370
370
return nil
371
371
}
372
372
}
373
373
case . uint( bits: _) :
374
374
if let val = BigUInt ( rawValue, radix: 10 ) {
375
- parsedValue = val as AnyObject
375
+ nativeValue = val as AnyObject
376
376
} else if let val = BigUInt ( rawValue. stripHexPrefix ( ) , radix: 16 ) {
377
- parsedValue = val as AnyObject
377
+ nativeValue = val as AnyObject
378
378
}
379
379
case . int( bits: _) :
380
380
if let val = BigInt ( rawValue, radix: 10 ) {
381
- parsedValue = val as AnyObject
381
+ nativeValue = val as AnyObject
382
382
} else if let val = BigInt ( rawValue. stripHexPrefix ( ) , radix: 16 ) {
383
- parsedValue = val as AnyObject
383
+ nativeValue = val as AnyObject
384
384
}
385
385
case . string:
386
- parsedValue = rawValue as AnyObject
386
+ nativeValue = rawValue as AnyObject
387
387
case . dynamicBytes:
388
388
if let val = Data . fromHex ( rawValue) {
389
- parsedValue = val as AnyObject
389
+ nativeValue = val as AnyObject
390
390
} else if let val = rawValue. data ( using: . utf8) {
391
- parsedValue = val as AnyObject
391
+ nativeValue = val as AnyObject
392
392
}
393
393
case . bytes( length: _) :
394
394
if let val = Data . fromHex ( rawValue) {
395
- parsedValue = val as AnyObject
395
+ nativeValue = val as AnyObject
396
396
} else if let val = rawValue. data ( using: . utf8) {
397
- parsedValue = val as AnyObject
397
+ nativeValue = val as AnyObject
398
398
}
399
399
case . bool:
400
400
switch rawValue {
401
401
case " true " , " True " , " TRUE " , " 1 " :
402
- parsedValue = true as AnyObject
402
+ nativeValue = true as AnyObject
403
403
case " false " , " False " , " FALSE " , " 0 " :
404
- parsedValue = false as AnyObject
404
+ nativeValue = false as AnyObject
405
405
default :
406
- parsedValue = true as AnyObject
406
+ nativeValue = true as AnyObject
407
407
}
408
408
case let . array( type, length) :
409
409
var rawValues : [ String ] = [ ]
@@ -422,26 +422,32 @@ extension Web3 {
422
422
rawValues = rawValue. split ( separator: " , " ) . map { String ( $0) }
423
423
}
424
424
425
- parsedValue = rawValues. compactMap {
426
- parseFunctionArgument ( type,
427
- String ( $0) ,
428
- chainID: chainID,
429
- inputNumber: inputNumber) ?
425
+ var nativeValueArray : [ AnyObject ] = [ ]
426
+
427
+ for value in rawValues {
428
+ let intermidiateValue = await parseFunctionArgument ( type,
429
+ value,
430
+ chainID: chainID,
431
+ inputNumber: inputNumber) ?
430
432
. parameter
431
433
. value
432
- } as AnyObject
434
+ if let intermidiateValue = intermidiateValue {
435
+ nativeValueArray. append ( intermidiateValue)
436
+ }
437
+ }
438
+ nativeValue = nativeValueArray as AnyObject
433
439
434
- guard ( parsedValue as? [ AnyObject ] ) ? . count == rawValues. count &&
440
+ guard nativeValueArray . count == rawValues. count &&
435
441
( length == 0 || UInt64 ( rawValues. count) == length) else { return nil }
436
442
case let . tuple( types) :
437
443
// TODO: implement!
438
444
return nil
439
445
default : return nil
440
446
}
441
447
442
- guard let parsedValue = parsedValue else { return nil }
448
+ guard let nativeValue = nativeValue else { return nil }
443
449
return FunctionArgument ( ABI . Element. InOut ( name: String ( inputNumber) , type: inputType) ,
444
- EIP681Code . EIP681Parameter ( type: inputType, value: parsedValue ) )
450
+ EIP681Code . EIP681Parameter ( type: inputType, value: nativeValue ) )
445
451
}
446
452
447
453
// MARK: - Parsing functions for complex data structures
0 commit comments