Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added wallet.getUnconfirmedBalance RPC #354

Merged
merged 10 commits into from
Jun 21, 2021
Original file line number Diff line number Diff line change
@@ -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)
})
})
9 changes: 9 additions & 0 deletions packages/jellyfish-api-core/src/category/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BigNumber>
*/
async getUnconfirmedBalance (): Promise<BigNumber> {
return await this.client.call('getunconfirmedbalance', [false], 'bignumber')
}

/**
* Get list of UTXOs in wallet.
*
Expand Down
10 changes: 10 additions & 0 deletions website/docs/jellyfish/api/wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ interface wallet {
}
```

## getUnconfirmedBalance

Identical to getBalance to get untrusted pending balance.

```ts title="client.wallet.getUnconfirmedBalance()"
interface wallet {
getUnconfirmedBalance (): Promise<BigNumber>
}
```

## listUnspent

Get list of UTXOs in wallet.
Expand Down