From 3792e764961f046dcaa444fdbc35d1dd28c00b11 Mon Sep 17 00:00:00 2001 From: polax7 Date: Wed, 11 Jan 2023 15:04:04 +0800 Subject: [PATCH 1/2] add: platform parameter --- Sources/Core/Methods/RequestAccountMethod.swift | 2 +- Sources/Core/Models/QueryName.swift | 2 ++ Sources/Core/Utilities/URLEncoding.swift | 6 +++++- Sources/EVMBase/Methods/SendEVMBasedTransactionMethod.swift | 2 +- Sources/EVMBase/Methods/SignEVMBaseMessageMethod.swift | 2 +- Sources/Flow/Methods/AuthenticateMethod.swift | 2 +- Sources/Flow/Methods/SendFlowTransactionMethod.swift | 2 +- Sources/Flow/Methods/SignFlowMessageMethod.swift | 2 +- .../Solana/Methods/SignAndSendSolanaTransactionMethod.swift | 2 +- 9 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Sources/Core/Methods/RequestAccountMethod.swift b/Sources/Core/Methods/RequestAccountMethod.swift index 1f88e43..d610030 100644 --- a/Sources/Core/Methods/RequestAccountMethod.swift +++ b/Sources/Core/Methods/RequestAccountMethod.swift @@ -39,7 +39,7 @@ public struct RequestAccountMethod: CallbackMethod { var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else { return nil } - var queryItems = URLEncoding.queryItems( + var queryItems = URLEncoding.queryGeneralItems( appId: appId, requestId: id.uuidString, blockchain: blockchain diff --git a/Sources/Core/Models/QueryName.swift b/Sources/Core/Models/QueryName.swift index b2d601c..84044e4 100644 --- a/Sources/Core/Models/QueryName.swift +++ b/Sources/Core/Models/QueryName.swift @@ -40,4 +40,6 @@ public enum QueryName: String { // error case error + + case platform } diff --git a/Sources/Core/Utilities/URLEncoding.swift b/Sources/Core/Utilities/URLEncoding.swift index 10bb9e2..5f03723 100644 --- a/Sources/Core/Utilities/URLEncoding.swift +++ b/Sources/Core/Utilities/URLEncoding.swift @@ -9,15 +9,19 @@ import Foundation public enum URLEncoding { - static func queryItems( + static func queryGeneralItems( appId: String, requestId: String, blockchain: Blockchain ) -> [QueryItem] { + + let platform: String = "sdk_ios" + let queryItems = [ QueryItem(name: .appId, value: appId), QueryItem(name: .requestId, value: requestId), QueryItem(name: .blockchain, value: blockchain.rawValue), + QueryItem(name: .platform, value: platform) ] return queryItems } diff --git a/Sources/EVMBase/Methods/SendEVMBasedTransactionMethod.swift b/Sources/EVMBase/Methods/SendEVMBasedTransactionMethod.swift index 5242620..1574a9e 100644 --- a/Sources/EVMBase/Methods/SendEVMBasedTransactionMethod.swift +++ b/Sources/EVMBase/Methods/SendEVMBasedTransactionMethod.swift @@ -40,7 +40,7 @@ public struct SendEVMBasedTransactionMethod: CallbackMethod { var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else { return nil } - var queryItems = URLEncoding.queryItems( + var queryItems = URLEncoding.queryGeneralItems( appId: appId, requestId: id.uuidString, blockchain: blockchain diff --git a/Sources/EVMBase/Methods/SignEVMBaseMessageMethod.swift b/Sources/EVMBase/Methods/SignEVMBaseMessageMethod.swift index b2ca575..104b5f9 100644 --- a/Sources/EVMBase/Methods/SignEVMBaseMessageMethod.swift +++ b/Sources/EVMBase/Methods/SignEVMBaseMessageMethod.swift @@ -49,7 +49,7 @@ public struct SignEVMBaseMessageMethod: CallbackMethod { var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else { return nil } - var queryItems = URLEncoding.queryItems( + var queryItems = URLEncoding.queryGeneralItems( appId: appId, requestId: id.uuidString, blockchain: blockchain diff --git a/Sources/Flow/Methods/AuthenticateMethod.swift b/Sources/Flow/Methods/AuthenticateMethod.swift index f30358d..5e9468c 100644 --- a/Sources/Flow/Methods/AuthenticateMethod.swift +++ b/Sources/Flow/Methods/AuthenticateMethod.swift @@ -36,7 +36,7 @@ public struct AuthenticateMethod: CallbackMethod { var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else { return nil } - var queryItems = URLEncoding.queryItems( + var queryItems = URLEncoding.queryGeneralItems( appId: appId, requestId: id.uuidString, blockchain: blockchain diff --git a/Sources/Flow/Methods/SendFlowTransactionMethod.swift b/Sources/Flow/Methods/SendFlowTransactionMethod.swift index 60adf1a..614ed7e 100644 --- a/Sources/Flow/Methods/SendFlowTransactionMethod.swift +++ b/Sources/Flow/Methods/SendFlowTransactionMethod.swift @@ -43,7 +43,7 @@ public struct SendFlowTransactionMethod: CallbackMethod { var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false) else { return nil } - var queryItems: [QueryItem] = URLEncoding.queryItems( + var queryItems: [QueryItem] = URLEncoding.queryGeneralItems( appId: appId, requestId: id.uuidString, blockchain: blockchain diff --git a/Sources/Flow/Methods/SignFlowMessageMethod.swift b/Sources/Flow/Methods/SignFlowMessageMethod.swift index 19d9883..57e4d46 100644 --- a/Sources/Flow/Methods/SignFlowMessageMethod.swift +++ b/Sources/Flow/Methods/SignFlowMessageMethod.swift @@ -44,7 +44,7 @@ public struct SignFlowMessageMethod: CallbackMethod { var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else { return nil } - var queryItems = URLEncoding.queryItems( + var queryItems = URLEncoding.queryGeneralItems( appId: appId, requestId: id.uuidString, blockchain: blockchain diff --git a/Sources/Solana/Methods/SignAndSendSolanaTransactionMethod.swift b/Sources/Solana/Methods/SignAndSendSolanaTransactionMethod.swift index e922747..54a0aa4 100644 --- a/Sources/Solana/Methods/SignAndSendSolanaTransactionMethod.swift +++ b/Sources/Solana/Methods/SignAndSendSolanaTransactionMethod.swift @@ -45,7 +45,7 @@ public struct SignAndSendSolanaTransactionMethod: CallbackMethod { var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else { return nil } - var queryItems: [QueryItem] = URLEncoding.queryItems( + var queryItems: [QueryItem] = URLEncoding.queryGeneralItems( appId: appId, requestId: id.uuidString, blockchain: blockchain From 2370883b0bac2340334a2d58981e484a13f6fc4b Mon Sep 17 00:00:00 2001 From: polax7 Date: Wed, 11 Jan 2023 15:26:40 +0800 Subject: [PATCH 2/2] fix: unit test --- .../Tests/Methods/SendTransactionTests.swift | 6 +++-- .../EVMBaseMethodURLEncodeTests.swift | 22 +++++++++++++------ .../URLEncode/FlowMethodURLEncodeTests.swift | 8 ++++++- .../SolanaMethodURLEncodeTests.swift | 10 ++++++--- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Example/Tests/Methods/SendTransactionTests.swift b/Example/Tests/Methods/SendTransactionTests.swift index 84ec4d1..572931f 100644 --- a/Example/Tests/Methods/SendTransactionTests.swift +++ b/Example/Tests/Methods/SendTransactionTests.swift @@ -11,7 +11,8 @@ import XCTest import BigInt class SendTransactionTests: XCTestCase { - + + let platform = "sdk_ios" var mockUIApplication: MockUIApplication! override func setUp() { @@ -52,7 +53,8 @@ class SendTransactionTests: XCTestCase { URLQueryItem(name: .from, value: from), URLQueryItem(name: .to, value: to), URLQueryItem(name: .value, value: "0x7b"), - URLQueryItem(name: .data, value: "0x" + dataString) + URLQueryItem(name: .data, value: "0x" + dataString), + URLQueryItem(name: .platform, value: platform) ] // When: diff --git a/Example/Tests/URLEncode/EVMBaseMethodURLEncodeTests.swift b/Example/Tests/URLEncode/EVMBaseMethodURLEncodeTests.swift index 3976227..dc8b016 100644 --- a/Example/Tests/URLEncode/EVMBaseMethodURLEncodeTests.swift +++ b/Example/Tests/URLEncode/EVMBaseMethodURLEncodeTests.swift @@ -13,6 +13,7 @@ import BigInt // swiftlint:disable type_body_length class EVMBaseMethodURLEncodeTests: XCTestCase { + let platform = "sdk_ios" func testURLComponent() throws { // Given: let item = URLQueryItem(name: .accountProof, value: "123 456 % 1") @@ -38,7 +39,8 @@ class EVMBaseMethodURLEncodeTests: XCTestCase { URLQueryItem(name: .appId, value: appId), URLQueryItem(name: .requestId, value: requestId.uuidString), URLQueryItem(name: .blockchain, value: Blockchain.ethereum.rawValue), - URLQueryItem(name: .method, value: MethodName.requestAccount.rawValue) + URLQueryItem(name: .method, value: MethodName.requestAccount.rawValue), + URLQueryItem(name: .platform, value: platform) ] // When: @@ -74,7 +76,8 @@ class EVMBaseMethodURLEncodeTests: XCTestCase { URLQueryItem(name: .method, value: EVMBaseMethodType.signMessage.rawValue), URLQueryItem(name: .signType, value: EVMBaseSignType.sign.rawValue), URLQueryItem(name: .from, value: ethereumAddress), - URLQueryItem(name: .message, value: message) + URLQueryItem(name: .message, value: message), + URLQueryItem(name: .platform, value: platform) ] // When: @@ -110,7 +113,8 @@ class EVMBaseMethodURLEncodeTests: XCTestCase { URLQueryItem(name: .method, value: EVMBaseMethodType.signMessage.rawValue), URLQueryItem(name: .signType, value: EVMBaseSignType.personalSign.rawValue), URLQueryItem(name: .from, value: ethereumAddress), - URLQueryItem(name: .message, value: message) + URLQueryItem(name: .message, value: message), + URLQueryItem(name: .platform, value: platform) ] // When: @@ -211,7 +215,8 @@ class EVMBaseMethodURLEncodeTests: XCTestCase { URLQueryItem(name: .method, value: EVMBaseMethodType.signMessage.rawValue), URLQueryItem(name: .signType, value: EVMBaseSignType.typedSignV3.rawValue), URLQueryItem(name: .from, value: ethereumAddress), - URLQueryItem(name: .message, value: message) + URLQueryItem(name: .message, value: message), + URLQueryItem(name: .platform, value: platform) ] // When: @@ -331,7 +336,8 @@ class EVMBaseMethodURLEncodeTests: XCTestCase { URLQueryItem(name: .method, value: EVMBaseMethodType.signMessage.rawValue), URLQueryItem(name: .signType, value: EVMBaseSignType.typedSignV4.rawValue), URLQueryItem(name: .from, value: ethereumAddress), - URLQueryItem(name: .message, value: message) + URLQueryItem(name: .message, value: message), + URLQueryItem(name: .platform, value: platform) ] // When: @@ -370,7 +376,8 @@ class EVMBaseMethodURLEncodeTests: XCTestCase { URLQueryItem(name: .from, value: ethereumAddress), URLQueryItem(name: .to, value: to), URLQueryItem(name: .value, value: "0x0"), - URLQueryItem(name: .data, value: "0x" + dataString) + URLQueryItem(name: .data, value: "0x" + dataString), + URLQueryItem(name: .platform, value: platform) ] // When: @@ -409,7 +416,8 @@ class EVMBaseMethodURLEncodeTests: XCTestCase { URLQueryItem(name: .from, value: ethereumAddress), URLQueryItem(name: .to, value: to), URLQueryItem(name: .value, value: "0x100"), - URLQueryItem(name: .data, value: "0x" + dataString) + URLQueryItem(name: .data, value: "0x" + dataString), + URLQueryItem(name: .platform, value: platform) ] // When: diff --git a/Example/Tests/URLEncode/FlowMethodURLEncodeTests.swift b/Example/Tests/URLEncode/FlowMethodURLEncodeTests.swift index 19afb87..094863d 100644 --- a/Example/Tests/URLEncode/FlowMethodURLEncodeTests.swift +++ b/Example/Tests/URLEncode/FlowMethodURLEncodeTests.swift @@ -12,7 +12,8 @@ import FlowSDK @testable import BloctoSDK final class FlowMethodURLEncodeTests: XCTestCase { - + + let platform = "sdk_ios" func testFlowRequestAccount() throws { // Given: let requestId = UUID() @@ -27,6 +28,7 @@ final class FlowMethodURLEncodeTests: XCTestCase { URLQueryItem(name: .requestId, value: requestId.uuidString), URLQueryItem(name: .blockchain, value: Blockchain.flow.rawValue), URLQueryItem(name: .method, value: MethodName.requestAccount.rawValue), + URLQueryItem(name: .platform, value: platform) ] // When: @@ -53,6 +55,7 @@ final class FlowMethodURLEncodeTests: XCTestCase { URLQueryItem(name: .requestId, value: requestId.uuidString), URLQueryItem(name: .blockchain, value: Blockchain.flow.rawValue), URLQueryItem(name: .method, value: FlowMethodType.authenticate.rawValue), + URLQueryItem(name: .platform, value: platform) ] // When: @@ -84,6 +87,7 @@ final class FlowMethodURLEncodeTests: XCTestCase { URLQueryItem(name: .method, value: FlowMethodType.authenticate.rawValue), URLQueryItem(name: .flowAppId, value: appId), URLQueryItem(name: .flowNonce, value: nonce), + URLQueryItem(name: .platform, value: platform) ] // When: @@ -120,6 +124,7 @@ final class FlowMethodURLEncodeTests: XCTestCase { URLQueryItem(name: .method, value: FlowMethodType.userSignature.rawValue), URLQueryItem(name: .from, value: address), URLQueryItem(name: .message, value: message), + URLQueryItem(name: .platform, value: platform) ] // When: @@ -173,6 +178,7 @@ final class FlowMethodURLEncodeTests: XCTestCase { URLQueryItem(name: .method, value: FlowMethodType.sendTransaction.rawValue), URLQueryItem(name: .from, value: addressString), URLQueryItem(name: .flowTransaction, value: transactionDataHex), + URLQueryItem(name: .platform, value: platform) ] // When: diff --git a/Example/Tests/URLEncode/SolanaMethodURLEncodeTests.swift b/Example/Tests/URLEncode/SolanaMethodURLEncodeTests.swift index 16448f6..e66b30e 100644 --- a/Example/Tests/URLEncode/SolanaMethodURLEncodeTests.swift +++ b/Example/Tests/URLEncode/SolanaMethodURLEncodeTests.swift @@ -11,6 +11,7 @@ import XCTest class SolanaMethodURLEncodeTests: XCTestCase { + let platform = "sdk_ios" func testSolanaRequestAccount() throws { // Given: let requestId = UUID() @@ -23,7 +24,8 @@ class SolanaMethodURLEncodeTests: XCTestCase { URLQueryItem(name: .appId, value: appId), URLQueryItem(name: .requestId, value: requestId.uuidString), URLQueryItem(name: .blockchain, value: Blockchain.solana.rawValue), - URLQueryItem(name: .method, value: MethodName.requestAccount.rawValue) + URLQueryItem(name: .method, value: MethodName.requestAccount.rawValue), + URLQueryItem(name: .platform, value: platform) ] // When: @@ -61,7 +63,8 @@ class SolanaMethodURLEncodeTests: XCTestCase { URLQueryItem(name: .method, value: SolanaMethodType.signAndSendTransaction.rawValue), URLQueryItem(name: .from, value: solanaAddress), URLQueryItem(name: .isInvokeWrapped, value: "true"), - URLQueryItem(name: .message, value: messageHex) + URLQueryItem(name: .message, value: messageHex), + URLQueryItem(name: .platform, value: platform) ] // When: @@ -117,7 +120,8 @@ class SolanaMethodURLEncodeTests: XCTestCase { URLQueryItem(name: .message, value: messageHex), URLQueryItem(name: "\(QueryName.appendTx.rawValue)[\(appendTxKey1)]", value: appendTxValue1), URLQueryItem(name: "\(QueryName.appendTx.rawValue)[\(appendTxKey2)]", value: appendTxValue2), - URLQueryItem(name: "\(QueryName.publicKeySignaturePairs.rawValue)[\(publicKey)]", value: signature) + URLQueryItem(name: "\(QueryName.publicKeySignaturePairs.rawValue)[\(publicKey)]", value: signature), + URLQueryItem(name: .platform, value: platform) ] // When: