diff --git a/packages/jellyfish-api-core/__tests__/category/wallet/getUnconfirmedBalance.test.ts b/packages/jellyfish-api-core/__tests__/category/wallet/getUnconfirmedBalance.test.ts new file mode 100644 index 0000000000..87a48c33a4 --- /dev/null +++ b/packages/jellyfish-api-core/__tests__/category/wallet/getUnconfirmedBalance.test.ts @@ -0,0 +1,24 @@ +import { MasterNodeRegTestContainer } from '@defichain/testcontainers' +import { ContainerAdapterClient } from '../../container_adapter_client' +import { BigNumber } from 'bignumber.js' + +// TODO(aikchun): untrusted_pending simulation after multi-node set up +describe('Balance on masternode', () => { + const container = new MasterNodeRegTestContainer() + const client = new ContainerAdapterClient(container) + + beforeAll(async () => { + await container.start() + await container.waitForReady() + await container.waitForWalletCoinbaseMaturity() + }) + + afterAll(async () => { + await container.stop() + }) + + it('should getUnconfirmedBalance', async () => { + const unconfirmedBalance: BigNumber = await client.wallet.getUnconfirmedBalance() + expect(unconfirmedBalance.isEqualTo(new BigNumber('0'))).toStrictEqual(true) + }) +}) diff --git a/packages/jellyfish-api-core/src/category/wallet.ts b/packages/jellyfish-api-core/src/category/wallet.ts index f0cb1dcf96..9d7973dafe 100644 --- a/packages/jellyfish-api-core/src/category/wallet.ts +++ b/packages/jellyfish-api-core/src/category/wallet.ts @@ -62,6 +62,15 @@ export class Wallet { return await this.client.call('getbalance', ['*', minimumConfirmation, includeWatchOnly], 'bignumber') } + /** + * Identical to getBalance to get untrusted pending balance + * + * @return Promise + */ + async getUnconfirmedBalance (): Promise { + return await this.client.call('getunconfirmedbalance', [false], 'bignumber') + } + /** * Get list of UTXOs in wallet. * diff --git a/website/docs/jellyfish/api/wallet.md b/website/docs/jellyfish/api/wallet.md index 824e896600..fa1d8bb4a6 100644 --- a/website/docs/jellyfish/api/wallet.md +++ b/website/docs/jellyfish/api/wallet.md @@ -29,6 +29,16 @@ interface wallet { } ``` +## getUnconfirmedBalance + +Identical to getBalance to get untrusted pending balance. + +```ts title="client.wallet.getUnconfirmedBalance()" +interface wallet { + getUnconfirmedBalance (): Promise +} +``` + ## listUnspent Get list of UTXOs in wallet.