Skip to content

Commit

Permalink
add RPCRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Aug 2, 2022
1 parent 4de254a commit 7a00520
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Sources/Auth/Services/App/AuthRequestService.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import WalletConnectUtils
import WalletConnectKMS
import JSONRPC

actor AuthRequestService {
private let networkingInteractor: NetworkInteracting
Expand All @@ -22,7 +23,7 @@ actor AuthRequestService {
let issueAt = ISO8601DateFormatter().string(from: Date())
let payload = AuthPayload(requestParams: params, iat: issueAt)
let params = AuthRequestParams(requester: requester, payloadParams: payload)
let request = JSONRPCRequest<AuthRequestParams>(method: "wc_authRequest", params: params)
let request = RPCRequest(method: "wc_authRequest", params: params)
try await networkingInteractor.request(request, topic: topic)
try await networkingInteractor.subscribe(topic: responseTopic)
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/Auth/Services/Common/NetworkingInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import Foundation
import WalletConnectRelay
import WalletConnectUtils
import WalletConnectKMS
import JSONRPC

protocol NetworkInteracting {
func subscribe(topic: String) async throws
func request(_ request: JSONRPCRequest<AuthRequestParams>, topic: String, envelopeType: Envelope.EnvelopeType) async throws
func request(_ request: RPCRequest, topic: String, envelopeType: Envelope.EnvelopeType) async throws
}

extension NetworkInteracting {
func request(_ request: JSONRPCRequest<AuthRequestParams>, topic: String, envelopeType: Envelope.EnvelopeType = .type0) async throws {
func request(_ request: RPCRequest, topic: String, envelopeType: Envelope.EnvelopeType = .type0) async throws {
try await self.request(request, topic: topic, envelopeType: envelopeType)
}
}
Expand All @@ -32,7 +33,7 @@ class NetworkingInteractor: NetworkInteracting {
try await relayClient.subscribe(topic: topic)
}

func request(_ request: JSONRPCRequest<AuthRequestParams>, topic: String, envelopeType: Envelope.EnvelopeType) async throws {
func request(_ request: RPCRequest, topic: String, envelopeType: Envelope.EnvelopeType) async throws {
try jsonRpcHistory.set(topic: topic, request: request)
let message = try! serializer.serialize(topic: topic, encodable: request, envelopeType: envelopeType)
try await relayClient.publish(topic: topic, payload: message, tag: AuthRequestParams.tag)
Expand Down

0 comments on commit 7a00520

Please sign in to comment.