diff --git a/packages/jellyfish-api-core/__tests__/category/server/getRpcInfo.test.ts b/packages/jellyfish-api-core/__tests__/category/server/getRpcInfo.test.ts new file mode 100644 index 0000000000..2cf97c2477 --- /dev/null +++ b/packages/jellyfish-api-core/__tests__/category/server/getRpcInfo.test.ts @@ -0,0 +1,24 @@ +import { MasterNodeRegTestContainer } from '@defichain/testcontainers' +import { ContainerAdapterClient } from '../../container_adapter_client' + +describe('Server on masternode', () => { + const container = new MasterNodeRegTestContainer() + const client = new ContainerAdapterClient(container) + + beforeAll(async () => { + await container.start() + await container.waitForReady() + }) + + afterAll(async () => { + await container.stop() + }) + + it('should getRpcInfo', async () => { + const info = await client.server.getRpcInfo() + expect(info.active_commands[0].method).toStrictEqual('getrpcinfo') + expect(info.active_commands[0].duration).toBeGreaterThanOrEqual(0) + expect(typeof info.logpath).toBe('string') + expect(info.logpath).toContain('regtest/debug.log') + }) +}) diff --git a/packages/jellyfish-api-core/src/category/server.ts b/packages/jellyfish-api-core/src/category/server.ts new file mode 100644 index 0000000000..389a98de32 --- /dev/null +++ b/packages/jellyfish-api-core/src/category/server.ts @@ -0,0 +1,28 @@ +import { ApiClient } from '../.' + +export class Server { + private readonly client: ApiClient + + constructor (client: ApiClient) { + this.client = client + } + + /** + * Returns details of the RPC server + * + * @return {Promise} + */ + async getRpcInfo (): Promise { + return await this.client.call('getrpcinfo', [], 'number') + } +} + +export interface ActiveCommand { + method: string + duration: number +} + +export interface RpcInfo { + active_commands: ActiveCommand[] + logpath: string +} diff --git a/packages/jellyfish-api-core/src/index.ts b/packages/jellyfish-api-core/src/index.ts index 6466339ef6..a250e83a35 100644 --- a/packages/jellyfish-api-core/src/index.ts +++ b/packages/jellyfish-api-core/src/index.ts @@ -7,6 +7,7 @@ import { Wallet } from './category/wallet' import { Account } from './category/account' import { PoolPair } from './category/poolpair' import { Token } from './category/token' +import { Server } from './category/server' export * from '@defichain/jellyfish-json' @@ -18,6 +19,7 @@ export * as wallet from './category/wallet' export * as poolpair from './category/poolpair' export * as token from './category/token' export * as account from './category/account' +export * as server from './category/server' /** * A protocol agnostic DeFiChain node client, RPC calls are separated into their category. @@ -31,6 +33,7 @@ export abstract class ApiClient { public readonly account = new Account(this) public readonly poolpair = new PoolPair(this) public readonly token = new Token(this) + public readonly server = new Server(this) /** * A promise based procedure call handling diff --git a/website/docs/jellyfish/api/server.md b/website/docs/jellyfish/api/server.md new file mode 100644 index 0000000000..7acf075306 --- /dev/null +++ b/website/docs/jellyfish/api/server.md @@ -0,0 +1,36 @@ +--- +id: server +title: Server API +sidebar_label: Server API +slug: /jellyfish/api/server +--- + +```js +import {Client} from '@defichain/jellyfish' +const client = new Client() + +// Using client.server. +const something = await client.server.method() +``` + +## getRpcInfo + +Returns details of the RPC server. +- `active_commands` a list of active commands +- `logpath` the complete path to the debug log + +```ts title="client.server.getRpcInfo()" +interface server { + getRpcInfo (): Promise +} + +interface RpcInfo { + active_commands: ActiveCommand[] + logpath: string +} + +interface ActiveCommand { + method: string + duration: number +} +``` diff --git a/website/sidebars.js b/website/sidebars.js index 04cdc6a6da..d8f9b543f9 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -15,7 +15,8 @@ module.exports = { 'jellyfish/api/wallet', 'jellyfish/api/poolpair', 'jellyfish/api/token', - 'jellyfish/api/account' + 'jellyfish/api/account', + 'jellyfish/api/server' ] } ],