Skip to content

Commit

Permalink
Rename all RPC adapter classes (iron-fish#1622)
Browse files Browse the repository at this point in the history
This renames them to be inline with the RPC system, and makes clients
names consistent with adapter names.

Co-authored-by: Jason Spafford <[email protected]>
  • Loading branch information
NullSoldier and Jason Spafford authored Jun 13, 2022
1 parent 59ddce1 commit 4958fe0
Show file tree
Hide file tree
Showing 24 changed files with 79 additions and 87 deletions.
4 changes: 2 additions & 2 deletions ironfish-cli/src/commands/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions ironfish-cli/src/commands/service/faucet.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -77,7 +77,7 @@ export default class Faucet extends IronfishCommand {
}
}

async startSyncing(client: IronfishRpcClient, api: WebApi, speed: Meter): Promise<void> {
async startSyncing(client: RpcSocketClient, api: WebApi, speed: Meter): Promise<void> {
const connected = await client.tryConnect()

if (!connected) {
Expand Down Expand Up @@ -106,7 +106,7 @@ export default class Faucet extends IronfishCommand {
}

async processNextTransaction(
client: IronfishRpcClient,
client: RpcSocketClient,
account: string,
speed: Meter,
api: WebApi,
Expand Down
8 changes: 4 additions & 4 deletions ironfish/src/mining/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -52,7 +52,7 @@ export class MiningPool {
recalculateTargetInterval: SetTimeoutToken | null

private constructor(options: {
rpc: IronfishRpcClient
rpc: RpcSocketClient
shares: MiningPoolShares
config: Config
logger: Logger
Expand Down Expand Up @@ -94,7 +94,7 @@ export class MiningPool {
}

static async init(options: {
rpc: IronfishRpcClient
rpc: RpcSocketClient
config: Config
logger: Logger
discord?: Discord
Expand Down
8 changes: 4 additions & 4 deletions ironfish/src/mining/poolShares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -32,7 +32,7 @@ export class MiningPoolShares {

private constructor(options: {
db: PoolDatabase
rpc: IronfishRpcClient
rpc: RpcSocketClient
config: Config
logger: Logger
discord?: Discord
Expand All @@ -59,7 +59,7 @@ export class MiningPoolShares {
}

static async init(options: {
rpc: IronfishRpcClient
rpc: RpcSocketClient
config: Config
logger: Logger
discord?: Discord
Expand Down
6 changes: 3 additions & 3 deletions ironfish/src/mining/soloMiner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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<void> | null
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/rpc/adapters/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions ironfish/src/rpc/adapters/ipcAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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'),
})
Expand Down
4 changes: 2 additions & 2 deletions ironfish/src/rpc/adapters/ipcAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/rpc/adapters/memoryAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ironfish/src/rpc/adapters/socketAdapter/socketAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ironfish/src/rpc/adapters/tcpAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions ironfish/src/rpc/adapters/tlsAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/rpc/clients/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import {
GetPeerMessagesResponse,
} from '../routes/peers/getPeerMessages'

export abstract class IronfishClient {
export abstract class RpcClient {
readonly logger: Logger

constructor(logger: Logger) {
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/rpc/clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
export * from './errors'
export * from './client'
export * from './memoryClient'
export * from './rpcClient'
export * from './socketClient'
4 changes: 2 additions & 2 deletions ironfish/src/rpc/clients/ipcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions ironfish/src/rpc/clients/memoryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -29,6 +29,6 @@ export class IronfishMemoryClient extends IronfishClient {
throw new Error(`MemoryAdapter does not support timeoutMs`)
}

return MemoryAdapter.requestStream<TEnd, TStream>(this.router, route, data)
return RpcMemoryAdapter.requestStream<TEnd, TStream>(this.router, route, data)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<RpcClientConnectionInfo>
Expand Down
4 changes: 2 additions & 2 deletions ironfish/src/rpc/clients/tcpClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ironfish/src/rpc/clients/tcpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
return new Promise((resolve, reject): void => {
const onSecureConnect = () => {
Expand Down
6 changes: 3 additions & 3 deletions ironfish/src/rpc/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown> | null = null
Expand Down Expand Up @@ -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<void> {
async mount(adapter: IRpcAdapter): Promise<void> {
this.adapters.push(adapter)
await adapter.attach(this)

Expand Down
Loading

0 comments on commit 4958fe0

Please sign in to comment.