From 4958fe0caea7056a581842c8c77ffd65aaeac6c9 Mon Sep 17 00:00:00 2001 From: Jason Spafford Date: Mon, 13 Jun 2022 16:27:06 -0400 Subject: [PATCH] Rename all RPC adapter classes (#1622) This renames them to be inline with the RPC system, and makes clients names consistent with adapter names. Co-authored-by: Jason Spafford --- ironfish-cli/src/commands/deposit.ts | 4 +- ironfish-cli/src/commands/service/faucet.ts | 6 +-- ironfish/src/mining/pool.ts | 8 ++-- ironfish/src/mining/poolShares.ts | 8 ++-- ironfish/src/mining/soloMiner.ts | 6 +-- ironfish/src/rpc/adapters/adapter.ts | 2 +- ironfish/src/rpc/adapters/ipcAdapter.test.ts | 10 ++-- ironfish/src/rpc/adapters/ipcAdapter.ts | 4 +- ironfish/src/rpc/adapters/memoryAdapter.ts | 2 +- .../adapters/socketAdapter/socketAdapter.ts | 4 +- ironfish/src/rpc/adapters/tcpAdapter.ts | 4 +- ironfish/src/rpc/adapters/tlsAdapter.ts | 4 +- ironfish/src/rpc/clients/client.ts | 2 +- ironfish/src/rpc/clients/index.ts | 2 +- ironfish/src/rpc/clients/ipcClient.ts | 4 +- ironfish/src/rpc/clients/memoryClient.ts | 8 ++-- .../clients/{rpcClient.ts => socketClient.ts} | 4 +- ironfish/src/rpc/clients/tcpClient.test.ts | 4 +- ironfish/src/rpc/clients/tcpClient.ts | 4 +- .../{secureTcpClient.ts => tlsClient.ts} | 4 +- ironfish/src/rpc/server.ts | 6 +-- ironfish/src/sdk.test.ts | 8 ++-- ironfish/src/sdk.ts | 46 ++++++++----------- ironfish/src/testUtilities/routeTest.ts | 12 ++--- 24 files changed, 79 insertions(+), 87 deletions(-) rename ironfish/src/rpc/clients/{rpcClient.ts => socketClient.ts} (97%) rename ironfish/src/rpc/clients/{secureTcpClient.ts => tlsClient.ts} (91%) diff --git a/ironfish-cli/src/commands/deposit.ts b/ironfish-cli/src/commands/deposit.ts index 26f323c37e..ebdc6b7628 100644 --- a/ironfish-cli/src/commands/deposit.ts +++ b/ironfish-cli/src/commands/deposit.ts @@ -5,11 +5,11 @@ import { Assert, displayIronAmountWithCurrency, - IronfishClient, ironToOre, isValidAmount, MINIMUM_IRON_AMOUNT, oreToIron, + RpcClient, WebApi, } from '@ironfish/sdk' import { CliUx, Flags } from '@oclif/core' @@ -23,7 +23,7 @@ const IRON_TO_SEND = 0.1 export default class Bank extends IronfishCommand { static description = 'Deposit $IRON for testnet points' - client: IronfishClient | null = null + client: RpcClient | null = null api: WebApi | null = new WebApi() static flags = { diff --git a/ironfish-cli/src/commands/service/faucet.ts b/ironfish-cli/src/commands/service/faucet.ts index 1ed4e3429f..04f72d7189 100644 --- a/ironfish-cli/src/commands/service/faucet.ts +++ b/ironfish-cli/src/commands/service/faucet.ts @@ -1,7 +1,7 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -import { ConnectionError, IronfishRpcClient, Meter, PromiseUtils, WebApi } from '@ironfish/sdk' +import { ConnectionError, Meter, PromiseUtils, RpcSocketClient, WebApi } from '@ironfish/sdk' import { Flags } from '@oclif/core' import { IronfishCommand } from '../../command' import { RemoteFlags } from '../../flags' @@ -77,7 +77,7 @@ export default class Faucet extends IronfishCommand { } } - async startSyncing(client: IronfishRpcClient, api: WebApi, speed: Meter): Promise { + async startSyncing(client: RpcSocketClient, api: WebApi, speed: Meter): Promise { const connected = await client.tryConnect() if (!connected) { @@ -106,7 +106,7 @@ export default class Faucet extends IronfishCommand { } async processNextTransaction( - client: IronfishRpcClient, + client: RpcSocketClient, account: string, speed: Meter, api: WebApi, diff --git a/ironfish/src/mining/pool.ts b/ironfish/src/mining/pool.ts index db755b39a2..4c6e2e4f61 100644 --- a/ironfish/src/mining/pool.ts +++ b/ironfish/src/mining/pool.ts @@ -7,7 +7,7 @@ import { Assert } from '../assert' import { Config } from '../fileStores/config' import { Logger } from '../logger' import { Target } from '../primitives/target' -import { IronfishRpcClient } from '../rpc/clients' +import { RpcSocketClient } from '../rpc/clients' import { SerializedBlockTemplate } from '../serde/BlockTemplateSerde' import { BigIntUtils } from '../utils/bigint' import { ErrorUtils } from '../utils/error' @@ -23,7 +23,7 @@ const RECALCULATE_TARGET_TIMEOUT = 10000 export class MiningPool { readonly stratum: StratumServer - readonly rpc: IronfishRpcClient + readonly rpc: RpcSocketClient readonly logger: Logger readonly shares: MiningPoolShares readonly config: Config @@ -52,7 +52,7 @@ export class MiningPool { recalculateTargetInterval: SetTimeoutToken | null private constructor(options: { - rpc: IronfishRpcClient + rpc: RpcSocketClient shares: MiningPoolShares config: Config logger: Logger @@ -94,7 +94,7 @@ export class MiningPool { } static async init(options: { - rpc: IronfishRpcClient + rpc: RpcSocketClient config: Config logger: Logger discord?: Discord diff --git a/ironfish/src/mining/poolShares.ts b/ironfish/src/mining/poolShares.ts index e4cb1930c1..d83ea033e0 100644 --- a/ironfish/src/mining/poolShares.ts +++ b/ironfish/src/mining/poolShares.ts @@ -3,7 +3,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { Config } from '../fileStores/config' import { Logger } from '../logger' -import { IronfishRpcClient } from '../rpc/clients/rpcClient' +import { RpcSocketClient } from '../rpc/clients/socketClient' import { ErrorUtils } from '../utils' import { BigIntUtils } from '../utils/bigint' import { MapUtils } from '../utils/map' @@ -13,7 +13,7 @@ import { Lark } from './lark' import { DatabaseShare, PoolDatabase } from './poolDatabase' export class MiningPoolShares { - readonly rpc: IronfishRpcClient + readonly rpc: RpcSocketClient readonly config: Config readonly logger: Logger readonly discord: Discord | null @@ -32,7 +32,7 @@ export class MiningPoolShares { private constructor(options: { db: PoolDatabase - rpc: IronfishRpcClient + rpc: RpcSocketClient config: Config logger: Logger discord?: Discord @@ -59,7 +59,7 @@ export class MiningPoolShares { } static async init(options: { - rpc: IronfishRpcClient + rpc: RpcSocketClient config: Config logger: Logger discord?: Discord diff --git a/ironfish/src/mining/soloMiner.ts b/ironfish/src/mining/soloMiner.ts index ff11fe3501..12cbe5d1ed 100644 --- a/ironfish/src/mining/soloMiner.ts +++ b/ironfish/src/mining/soloMiner.ts @@ -7,7 +7,7 @@ import { Assert } from '../assert' import { Logger } from '../logger' import { Meter } from '../metrics/meter' import { Target } from '../primitives/target' -import { IronfishRpcClient } from '../rpc/clients/rpcClient' +import { RpcSocketClient } from '../rpc/clients/socketClient' import { SerializedBlockTemplate } from '../serde/BlockTemplateSerde' import { BigIntUtils } from '../utils/bigint' import { ErrorUtils } from '../utils/error' @@ -22,7 +22,7 @@ export class MiningSoloMiner { readonly hashRate: Meter readonly threadPool: ThreadPoolHandler readonly logger: Logger - readonly rpc: IronfishRpcClient + readonly rpc: RpcSocketClient private started: boolean private stopPromise: Promise | null @@ -48,7 +48,7 @@ export class MiningSoloMiner { batchSize: number logger: Logger graffiti: Buffer - rpc: IronfishRpcClient + rpc: RpcSocketClient }) { this.rpc = options.rpc this.logger = options.logger diff --git a/ironfish/src/rpc/adapters/adapter.ts b/ironfish/src/rpc/adapters/adapter.ts index 212e5715ae..c2e91dad11 100644 --- a/ironfish/src/rpc/adapters/adapter.ts +++ b/ironfish/src/rpc/adapters/adapter.ts @@ -8,7 +8,7 @@ import { RpcServer } from '../server' * An adapter represents a network transport that accepts incoming requests * and routes them into the router. */ -export interface IAdapter { +export interface IRpcAdapter { /** * Called when the adapter has been added to an RpcServer. * This lets you get access to both the RpcServer, and the diff --git a/ironfish/src/rpc/adapters/ipcAdapter.test.ts b/ironfish/src/rpc/adapters/ipcAdapter.test.ts index bbe88ca9ce..bd541c1402 100644 --- a/ironfish/src/rpc/adapters/ipcAdapter.test.ts +++ b/ironfish/src/rpc/adapters/ipcAdapter.test.ts @@ -6,15 +6,15 @@ import os from 'os' import * as yup from 'yup' import { IronfishSdk } from '../../sdk' -import { IronfishRpcClient, RequestError } from '../clients' +import { RequestError, RpcSocketClient } from '../clients' import { ALL_API_NAMESPACES } from '../routes' import { ERROR_CODES, ValidationError } from './errors' -import { IpcAdapter } from './ipcAdapter' +import { RpcIpcAdapter } from './ipcAdapter' describe('IpcAdapter', () => { - let ipc: IpcAdapter + let ipc: RpcIpcAdapter let sdk: IronfishSdk - let client: IronfishRpcClient + let client: RpcSocketClient beforeEach(async () => { const dataDir = os.tmpdir() @@ -24,7 +24,7 @@ describe('IpcAdapter', () => { sdk.config.setOverride('enableRpcIpc', false) const node = await sdk.node() - ipc = new IpcAdapter(ALL_API_NAMESPACES, { + ipc = new RpcIpcAdapter(ALL_API_NAMESPACES, { mode: 'ipc', socketPath: sdk.config.get('ipcPath'), }) diff --git a/ironfish/src/rpc/adapters/ipcAdapter.ts b/ironfish/src/rpc/adapters/ipcAdapter.ts index e126197f04..9091bf4929 100644 --- a/ironfish/src/rpc/adapters/ipcAdapter.ts +++ b/ironfish/src/rpc/adapters/ipcAdapter.ts @@ -11,7 +11,7 @@ import { YupUtils } from '../../utils/yup' import { Request } from '../request' import { ApiNamespace, Router } from '../routes' import { RpcServer } from '../server' -import { IAdapter } from './adapter' +import { IRpcAdapter } from './adapter' import { ERROR_CODES, ResponseError } from './errors' export type IpcRequest = { @@ -79,7 +79,7 @@ export type IpcAdapterConnectionInfo = port: number } -export class IpcAdapter implements IAdapter { +export class RpcIpcAdapter implements IRpcAdapter { router: Router | null = null ipc: IPC | null = null server: IpcServer | null = null diff --git a/ironfish/src/rpc/adapters/memoryAdapter.ts b/ironfish/src/rpc/adapters/memoryAdapter.ts index 39a0b8fd96..f731b6c5c6 100644 --- a/ironfish/src/rpc/adapters/memoryAdapter.ts +++ b/ironfish/src/rpc/adapters/memoryAdapter.ts @@ -16,7 +16,7 @@ import { ResponseError } from './errors' * * This is useful any time you want to make requests without hitting an IO layer. */ -export class MemoryAdapter { +export class RpcMemoryAdapter { /** * Makes a request against the routing layer with a given route, and data and returns * a response for you to accumulate the streaming results, or wait for a response diff --git a/ironfish/src/rpc/adapters/socketAdapter/socketAdapter.ts b/ironfish/src/rpc/adapters/socketAdapter/socketAdapter.ts index 1434a1a0e5..bf820f4385 100644 --- a/ironfish/src/rpc/adapters/socketAdapter/socketAdapter.ts +++ b/ironfish/src/rpc/adapters/socketAdapter/socketAdapter.ts @@ -11,7 +11,7 @@ import { MessageBuffer } from '../../messageBuffer' import { Request } from '../../request' import { ApiNamespace, Router } from '../../routes' import { RpcServer } from '../../server' -import { IAdapter } from '../adapter' +import { IRpcAdapter } from '../adapter' import { ERROR_CODES, ResponseError } from '../errors' import { ClientSocketRpcSchema, @@ -27,7 +27,7 @@ type SocketClient = { messageBuffer: MessageBuffer } -export abstract class SocketAdapter implements IAdapter { +export abstract class RpcSocketAdapter implements IRpcAdapter { logger: Logger host: string port: number diff --git a/ironfish/src/rpc/adapters/tcpAdapter.ts b/ironfish/src/rpc/adapters/tcpAdapter.ts index 726a3d991f..e9962995c0 100644 --- a/ironfish/src/rpc/adapters/tcpAdapter.ts +++ b/ironfish/src/rpc/adapters/tcpAdapter.ts @@ -4,9 +4,9 @@ import net from 'net' import { createRootLogger, Logger } from '../../logger' import { ApiNamespace } from '../routes' -import { SocketAdapter } from './socketAdapter/socketAdapter' +import { RpcSocketAdapter } from './socketAdapter/socketAdapter' -export class TcpAdapter extends SocketAdapter { +export class RpcTcpAdapter extends RpcSocketAdapter { constructor( host: string, port: number, diff --git a/ironfish/src/rpc/adapters/tlsAdapter.ts b/ironfish/src/rpc/adapters/tlsAdapter.ts index 37e65bb3d9..0aeae4a186 100644 --- a/ironfish/src/rpc/adapters/tlsAdapter.ts +++ b/ironfish/src/rpc/adapters/tlsAdapter.ts @@ -7,9 +7,9 @@ import tls from 'tls' import { FileSystem } from '../../fileSystems' import { createRootLogger, Logger } from '../../logger' import { ApiNamespace } from '../routes' -import { SocketAdapter } from './socketAdapter/socketAdapter' +import { RpcSocketAdapter } from './socketAdapter/socketAdapter' -export class TlsAdapter extends SocketAdapter { +export class RpcTlsAdapter extends RpcSocketAdapter { readonly fileSystem: FileSystem readonly nodeKeyPath: string readonly nodeCertPath: string diff --git a/ironfish/src/rpc/clients/client.ts b/ironfish/src/rpc/clients/client.ts index 401756f5b1..e1f447520b 100644 --- a/ironfish/src/rpc/clients/client.ts +++ b/ironfish/src/rpc/clients/client.ts @@ -73,7 +73,7 @@ import { GetPeerMessagesResponse, } from '../routes/peers/getPeerMessages' -export abstract class IronfishClient { +export abstract class RpcClient { readonly logger: Logger constructor(logger: Logger) { diff --git a/ironfish/src/rpc/clients/index.ts b/ironfish/src/rpc/clients/index.ts index 2b3b7d35b2..259eec9fa6 100644 --- a/ironfish/src/rpc/clients/index.ts +++ b/ironfish/src/rpc/clients/index.ts @@ -4,4 +4,4 @@ export * from './errors' export * from './client' export * from './memoryClient' -export * from './rpcClient' +export * from './socketClient' diff --git a/ironfish/src/rpc/clients/ipcClient.ts b/ironfish/src/rpc/clients/ipcClient.ts index add5a7ff89..99a82a8016 100644 --- a/ironfish/src/rpc/clients/ipcClient.ts +++ b/ironfish/src/rpc/clients/ipcClient.ts @@ -8,11 +8,11 @@ import { createRootLogger, Logger } from '../../logger' import { ErrorUtils } from '../../utils' import { IpcRequest } from '../adapters' import { ConnectionLostError, ConnectionRefusedError } from './errors' -import { IronfishRpcClient, RpcClientConnectionInfo } from './rpcClient' +import { RpcClientConnectionInfo, RpcSocketClient } from './socketClient' const CONNECT_RETRY_MS = 2000 -export class IronfishIpcClient extends IronfishRpcClient { +export class RpcIpcClient extends RpcSocketClient { ipc: IPC | null = null ipcPath: string | null = null client: IpcClient | null = null diff --git a/ironfish/src/rpc/clients/memoryClient.ts b/ironfish/src/rpc/clients/memoryClient.ts index 4a2edddfdb..15dc70d770 100644 --- a/ironfish/src/rpc/clients/memoryClient.ts +++ b/ironfish/src/rpc/clients/memoryClient.ts @@ -3,11 +3,11 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { Logger } from '../../logger' import { IronfishNode } from '../../node' -import { MemoryAdapter, MemoryResponse } from '../adapters' +import { MemoryResponse, RpcMemoryAdapter } from '../adapters' import { ALL_API_NAMESPACES, Router } from '../routes' -import { IronfishClient } from './client' +import { RpcClient } from './client' -export class IronfishMemoryClient extends IronfishClient { +export class RpcMemoryClient extends RpcClient { node: IronfishNode router: Router @@ -29,6 +29,6 @@ export class IronfishMemoryClient extends IronfishClient { throw new Error(`MemoryAdapter does not support timeoutMs`) } - return MemoryAdapter.requestStream(this.router, route, data) + return RpcMemoryAdapter.requestStream(this.router, route, data) } } diff --git a/ironfish/src/rpc/clients/rpcClient.ts b/ironfish/src/rpc/clients/socketClient.ts similarity index 97% rename from ironfish/src/rpc/clients/rpcClient.ts rename to ironfish/src/rpc/clients/socketClient.ts index 28db1b3d1d..53c7cfb360 100644 --- a/ironfish/src/rpc/clients/rpcClient.ts +++ b/ironfish/src/rpc/clients/socketClient.ts @@ -9,7 +9,7 @@ import { PromiseUtils, SetTimeoutToken, YupUtils } from '../../utils' import { IpcErrorSchema, IpcResponseSchema, IpcStreamSchema } from '../adapters' import { isResponseError, Response } from '../response' import { Stream } from '../stream' -import { IronfishClient } from './client' +import { RpcClient } from './client' import { ConnectionError, RequestError, RequestTimeoutError } from './errors' const REQUEST_TIMEOUT_MS = null @@ -25,7 +25,7 @@ export type RpcClientConnectionInfo = port: number } -export abstract class IronfishRpcClient extends IronfishClient { +export abstract class RpcSocketClient extends RpcClient { abstract client: IpcClient | net.Socket | null abstract isConnected: boolean abstract connection: Partial diff --git a/ironfish/src/rpc/clients/tcpClient.test.ts b/ironfish/src/rpc/clients/tcpClient.test.ts index 608f8a3db9..59afdd453b 100644 --- a/ironfish/src/rpc/clients/tcpClient.test.ts +++ b/ironfish/src/rpc/clients/tcpClient.test.ts @@ -4,14 +4,14 @@ import net from 'net' import { YupUtils } from '../../utils' import { ClientSocketRpcSchema, MESSAGE_DELIMITER } from '../adapters/socketAdapter/protocol' -import { IronfishTcpClient } from './tcpClient' +import { RpcTcpClient } from './tcpClient' jest.mock('net') describe('IronfishTcpClient', () => { const testHost = 'testhost' const testPort = 1234 - const client: IronfishTcpClient = new IronfishTcpClient(testHost, testPort) + const client: RpcTcpClient = new RpcTcpClient(testHost, testPort) it('should send messages in the node-ipc encoding', async () => { const messageId = 1 diff --git a/ironfish/src/rpc/clients/tcpClient.ts b/ironfish/src/rpc/clients/tcpClient.ts index 62c36eefab..fcbd4ed467 100644 --- a/ironfish/src/rpc/clients/tcpClient.ts +++ b/ironfish/src/rpc/clients/tcpClient.ts @@ -12,9 +12,9 @@ import { } from '../adapters/socketAdapter/protocol' import { MessageBuffer } from '../messageBuffer' import { ConnectionLostError, ConnectionRefusedError } from './errors' -import { IronfishRpcClient, RpcClientConnectionInfo } from './rpcClient' +import { RpcClientConnectionInfo, RpcSocketClient } from './socketClient' -export class IronfishTcpClient extends IronfishRpcClient { +export class RpcTcpClient extends RpcSocketClient { client: net.Socket | null = null protected readonly host: string protected readonly port: number diff --git a/ironfish/src/rpc/clients/secureTcpClient.ts b/ironfish/src/rpc/clients/tlsClient.ts similarity index 91% rename from ironfish/src/rpc/clients/secureTcpClient.ts rename to ironfish/src/rpc/clients/tlsClient.ts index 0ccbe555c8..89c98bde74 100644 --- a/ironfish/src/rpc/clients/secureTcpClient.ts +++ b/ironfish/src/rpc/clients/tlsClient.ts @@ -4,9 +4,9 @@ import tls from 'tls' import { ErrorUtils } from '../../utils' import { ConnectionRefusedError } from './errors' -import { IronfishTcpClient } from './tcpClient' +import { RpcTcpClient } from './tcpClient' -export class IronfishSecureTcpClient extends IronfishTcpClient { +export class RpcTlsClient extends RpcTcpClient { async connect(): Promise { return new Promise((resolve, reject): void => { const onSecureConnect = () => { diff --git a/ironfish/src/rpc/server.ts b/ironfish/src/rpc/server.ts index eea0c1aa24..64b6ff8ddf 100644 --- a/ironfish/src/rpc/server.ts +++ b/ironfish/src/rpc/server.ts @@ -3,13 +3,13 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { IronfishNode } from '../node' -import { IAdapter } from './adapters' +import { IRpcAdapter } from './adapters' import { ApiNamespace, Router, router } from './routes' export class RpcServer { readonly node: IronfishNode - private readonly adapters: IAdapter[] = [] + private readonly adapters: IRpcAdapter[] = [] private readonly router: Router private _isRunning = false private _startPromise: Promise | null = null @@ -57,7 +57,7 @@ export class RpcServer { } /** Adds an adapter to the RPC server and starts it if the server has already been started */ - async mount(adapter: IAdapter): Promise { + async mount(adapter: IRpcAdapter): Promise { this.adapters.push(adapter) await adapter.attach(this) diff --git a/ironfish/src/sdk.test.ts b/ironfish/src/sdk.test.ts index cab6cc1d60..5ee7130c3f 100644 --- a/ironfish/src/sdk.test.ts +++ b/ironfish/src/sdk.test.ts @@ -7,7 +7,7 @@ import { Config, DEFAULT_DATA_DIR } from './fileStores' import { NodeFileProvider } from './fileSystems' import { IronfishNode } from './node' import { Platform } from './platform' -import { IronfishMemoryClient, IronfishRpcClient } from './rpc' +import { RpcClient, RpcMemoryClient } from './rpc' import { IronfishSdk } from './sdk' describe('IronfishSdk', () => { @@ -25,7 +25,7 @@ describe('IronfishSdk', () => { }) expect(sdk.config).toBeInstanceOf(Config) - expect(sdk.client).toBeInstanceOf(IronfishRpcClient) + expect(sdk.client).toBeInstanceOf(RpcClient) expect(sdk.fileSystem).toBe(fileSystem) expect(sdk.config.storage.dataDir).toBe(dataDir) @@ -88,8 +88,8 @@ describe('IronfishSdk', () => { const client = await sdk.connectRpc(true) expect(openDb).toHaveBeenCalledTimes(1) - expect(client).toBeInstanceOf(IronfishMemoryClient) - expect((client as IronfishMemoryClient).node).toBe(node) + expect(client).toBeInstanceOf(RpcMemoryClient) + expect((client as RpcMemoryClient).node).toBe(node) }) }) diff --git a/ironfish/src/sdk.ts b/ironfish/src/sdk.ts index 37231f1d32..6df567d57c 100644 --- a/ironfish/src/sdk.ts +++ b/ironfish/src/sdk.ts @@ -19,21 +19,21 @@ import { IsomorphicWebSocketConstructor } from './network/types' import { IronfishNode } from './node' import { IronfishPKG, Package } from './package' import { Platform } from './platform' -import { IronfishRpcClient, TlsAdapter } from './rpc' -import { IpcAdapter } from './rpc/adapters/ipcAdapter' -import { TcpAdapter } from './rpc/adapters/tcpAdapter' -import { IronfishClient } from './rpc/clients/client' -import { IronfishIpcClient } from './rpc/clients/ipcClient' -import { IronfishMemoryClient } from './rpc/clients/memoryClient' -import { IronfishSecureTcpClient } from './rpc/clients/secureTcpClient' -import { IronfishTcpClient } from './rpc/clients/tcpClient' +import { RpcSocketClient, RpcTlsAdapter } from './rpc' +import { RpcIpcAdapter } from './rpc/adapters/ipcAdapter' +import { RpcTcpAdapter } from './rpc/adapters/tcpAdapter' +import { RpcClient } from './rpc/clients/client' +import { RpcIpcClient } from './rpc/clients/ipcClient' +import { RpcMemoryClient } from './rpc/clients/memoryClient' +import { RpcTcpClient } from './rpc/clients/tcpClient' +import { RpcTlsClient } from './rpc/clients/tlsClient' import { ApiNamespace } from './rpc/routes/router' import { Strategy } from './strategy' import { NodeUtils } from './utils' export class IronfishSdk { pkg: Package - client: IronfishRpcClient + client: RpcSocketClient config: Config fileSystem: FileSystem logger: Logger @@ -45,7 +45,7 @@ export class IronfishSdk { private constructor( pkg: Package, - client: IronfishRpcClient, + client: RpcSocketClient, config: Config, internal: InternalStore, fileSystem: FileSystem, @@ -134,23 +134,15 @@ export class IronfishSdk { metrics = metrics || new MetricsMonitor({ logger }) } - let client: IronfishRpcClient + let client: RpcSocketClient if (config.get('enableRpcTcp')) { if (config.get('enableRpcTls')) { - client = new IronfishSecureTcpClient( - config.get('rpcTcpHost'), - config.get('rpcTcpPort'), - logger, - ) + client = new RpcTlsClient(config.get('rpcTcpHost'), config.get('rpcTcpPort'), logger) } else { - client = new IronfishTcpClient( - config.get('rpcTcpHost'), - config.get('rpcTcpPort'), - logger, - ) + client = new RpcTcpClient(config.get('rpcTcpHost'), config.get('rpcTcpPort'), logger) } } else { - client = new IronfishIpcClient( + client = new RpcIpcClient( { mode: 'ipc', socketPath: config.get('ipcPath'), @@ -214,7 +206,7 @@ export class IronfishSdk { ] await node.rpc.mount( - new IpcAdapter( + new RpcIpcAdapter( namespaces, { mode: 'ipc', @@ -244,7 +236,7 @@ export class IronfishSdk { if (this.config.get('enableRpcTls')) { await node.rpc.mount( - new TlsAdapter( + new RpcTlsAdapter( this.config.get('rpcTcpHost'), this.config.get('rpcTcpPort'), this.fileSystem, @@ -256,7 +248,7 @@ export class IronfishSdk { ) } else { await node.rpc.mount( - new TcpAdapter( + new RpcTcpAdapter( this.config.get('rpcTcpHost'), this.config.get('rpcTcpPort'), this.logger, @@ -269,7 +261,7 @@ export class IronfishSdk { return node } - async connectRpc(forceLocal = false, forceRemote = false): Promise { + async connectRpc(forceLocal = false, forceRemote = false): Promise { forceRemote = forceRemote || this.config.get('enableRpcTcp') if (!forceLocal) { @@ -285,7 +277,7 @@ export class IronfishSdk { } const node = await this.node() - const clientMemory = new IronfishMemoryClient(this.logger, node) + const clientMemory = new RpcMemoryClient(this.logger, node) await NodeUtils.waitForOpen(node) return clientMemory } diff --git a/ironfish/src/testUtilities/routeTest.ts b/ironfish/src/testUtilities/routeTest.ts index f211ad0ed9..88c88cf9ea 100644 --- a/ironfish/src/testUtilities/routeTest.ts +++ b/ironfish/src/testUtilities/routeTest.ts @@ -7,8 +7,8 @@ import { Verifier } from '../consensus' import { createRootLogger } from '../logger' import { PeerNetwork } from '../network/peerNetwork' import { IronfishNode } from '../node' -import { MemoryAdapter } from '../rpc/adapters' -import { IronfishMemoryClient } from '../rpc/clients' +import { RpcMemoryAdapter } from '../rpc/adapters' +import { RpcMemoryClient } from '../rpc/clients' import { IronfishSdk } from '../sdk' import { Syncer } from '../syncer' import { WorkerPool } from '../workerPool' @@ -21,8 +21,8 @@ import { TestStrategy } from './strategy' * the RouteTest */ export class RouteTest extends NodeTest { - adapter!: MemoryAdapter - client!: IronfishMemoryClient + adapter!: RpcMemoryAdapter + client!: RpcMemoryClient async createSetup(): Promise<{ sdk: IronfishSdk @@ -34,12 +34,12 @@ export class RouteTest extends NodeTest { peerNetwork: PeerNetwork syncer: Syncer workerPool: WorkerPool - client: IronfishMemoryClient + client: RpcMemoryClient }> { const setup = await super.createSetup() const logger = createRootLogger().withTag('memoryclient') - const client = new IronfishMemoryClient(logger, setup.node) + const client = new RpcMemoryClient(logger, setup.node) return { ...setup, client } }