diff --git a/docs/node/CATEGORIES/01-blockchain.md b/docs/node/CATEGORIES/01-blockchain.md index 61b8f00f5d..ab8fa92efc 100644 --- a/docs/node/CATEGORIES/01-blockchain.md +++ b/docs/node/CATEGORIES/01-blockchain.md @@ -226,6 +226,28 @@ interface ScriptPubKey { } ``` +## getTxOutSetInfo + +Returns statistics about the unspent transaction output set. +Note this call may take some time. + +```ts title="client.blockchain.getTxOutSetInfo()" +interface blockchain { + getTxOutSetInfo (): Promise +} + +interface TxOutSetInfo { + height: number + bestblock: string + transactions: Number + txouts: Number + bogosize: Number + hash_serialized_2: string + disk_size: Number + total_amount: BigNumber +} +``` + ## getRawMempool Get all transaction ids in memory pool as string[] if verbose is false else as json object diff --git a/packages/jellyfish-api-core/__tests__/category/blockchain/getTxOutSetInfo.test.ts b/packages/jellyfish-api-core/__tests__/category/blockchain/getTxOutSetInfo.test.ts new file mode 100644 index 0000000000..bb11947b14 --- /dev/null +++ b/packages/jellyfish-api-core/__tests__/category/blockchain/getTxOutSetInfo.test.ts @@ -0,0 +1,32 @@ +import { MasterNodeRegTestContainer } from '@defichain/testcontainers' +import { ContainerAdapterClient } from '../../container_adapter_client' +import BigNumber from 'bignumber.js' + +describe('TxOutSetInfo', () => { + const container = new MasterNodeRegTestContainer() + const client = new ContainerAdapterClient(container) + + beforeAll(async () => { + await container.start() + await container.waitForBlockHeight(1) + }) + + afterAll(async () => { + await container.stop() + }) + + it('should getTxOutSetInfo', async () => { + const txOutSetInfo = await client.blockchain.getTxOutSetInfo() + + expect(txOutSetInfo).toStrictEqual({ + height: 2, + bestblock: expect.any(String), + transactions: expect.any(Number), + txouts: expect.any(Number), + bogosize: expect.any(Number), + hash_serialized_2: expect.any(String), + disk_size: expect.any(Number), + total_amount: expect.any(BigNumber) + }) + }) +}) diff --git a/packages/jellyfish-api-core/src/category/blockchain.ts b/packages/jellyfish-api-core/src/category/blockchain.ts index 7895e3c6cc..c2867bde75 100644 --- a/packages/jellyfish-api-core/src/category/blockchain.ts +++ b/packages/jellyfish-api-core/src/category/blockchain.ts @@ -137,6 +137,18 @@ export class Blockchain { }) } + /** + * Returns statistics about the unspent transaction output set. + * Note this call may take some time. + * + * @return {Promise} + */ + async getTxOutSetInfo (): Promise { + return await this.client.call('gettxoutsetinfo', [], { + total_amount: 'bignumber' + }) + } + /** * Get all transaction ids in memory pool as string * @@ -343,6 +355,17 @@ export interface UTXODetails { coinbase: boolean } +export interface TxOutSetInfo { + height: number + bestblock: string + transactions: Number + txouts: Number + bogosize: Number + hash_serialized_2: string + disk_size: Number + total_amount: BigNumber +} + export interface ScriptPubKey { asm: string hex: string