diff --git a/docs/node/CATEGORIES/11-masternode.md b/docs/node/CATEGORIES/11-masternode.md index 309c104dda..feda9551a0 100644 --- a/docs/node/CATEGORIES/11-masternode.md +++ b/docs/node/CATEGORIES/11-masternode.md @@ -269,3 +269,12 @@ interface MasternodeResult { [id: string]: T } ``` + +## clearMempool +Clears the memory pool and returns a list of the removed transaction ids. + +```ts title="client.masternode.clearMempool" +interface masternode { + clearMempool (): Promise +} +``` diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/clearMempool.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/clearMempool.test.ts new file mode 100644 index 0000000000..56de251a69 --- /dev/null +++ b/packages/jellyfish-api-core/__tests__/category/masternode/clearMempool.test.ts @@ -0,0 +1,30 @@ +import { MasterNodeRegTestContainer } from '@defichain/testcontainers' +import { Testing } from '@defichain/jellyfish-testing' + +describe('clear mempool', () => { + const container = new MasterNodeRegTestContainer() + const testing = Testing.create(container) + + beforeAll(async () => { + await testing.container.start() + await testing.container.waitForWalletCoinbaseMaturity() + }) + + afterAll(async () => { + await testing.container.stop() + }) + + it('should clear mempool and return the removed transaction ids', async () => { + const createdTxId = await testing.rpc.wallet.sendToAddress('mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU', 0.003) + + const txIdsInMempoolBefore = await testing.rpc.blockchain.getRawMempool(false) + expect(txIdsInMempoolBefore.length).toStrictEqual(1) + + const removedTxIds = await testing.rpc.masternode.clearMempool() + + expect(removedTxIds).toContain(createdTxId) + + const txIdsInMempoolAfter = await testing.rpc.blockchain.getRawMempool(false) + expect(txIdsInMempoolAfter.length).toStrictEqual(0) + }) +}) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index 449a650cf5..b9bdd9d615 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -240,6 +240,14 @@ export class Masternode { async listAnchors (): Promise> { return await this.client.call('listanchors', [], 'number') } + + /** + * Clears the memory pool and returns a list of the removed transaction ids. + * @return {Promise} Array of removed transaction ids + */ + async clearMempool (): Promise { + return await this.client.call('clearmempool', [], 'number') + } } export interface UTXO {