Skip to content

Commit

Permalink
feat(jellyfish-api-core): add masternode clearMempool RPC (#1801)
Browse files Browse the repository at this point in the history
What this PR does / why we need it:
/kind feature

Which issue(s) does this PR fixes?:
Fixes part of #48

- Implements `clearmempool` type for RPC.
  • Loading branch information
helloscoopa authored Oct 17, 2022
1 parent 02d87fc commit 48dd22b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/node/CATEGORIES/11-masternode.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,12 @@ interface MasternodeResult<T> {
[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<string[]>
}
```
Original file line number Diff line number Diff line change
@@ -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)
})
})
8 changes: 8 additions & 0 deletions packages/jellyfish-api-core/src/category/masternode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ export class Masternode {
async listAnchors (): Promise<MasternodeResult<MasternodeAnchor>> {
return await this.client.call('listanchors', [], 'number')
}

/**
* Clears the memory pool and returns a list of the removed transaction ids.
* @return {Promise<string[]>} Array of removed transaction ids
*/
async clearMempool (): Promise<string[]> {
return await this.client.call('clearmempool', [], 'number')
}
}

export interface UTXO {
Expand Down

0 comments on commit 48dd22b

Please sign in to comment.