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

feat(jellyfish-api-core): add wallet listWallets RPC #953

Merged
merged 5 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/node/CATEGORIES/05-wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,15 @@ interface wallet {
importPrivKey (privkey: string, label: string = "", rescan: boolean = true): Promise<void>
}
```

## listWallets

Returns a list of currently loaded wallets.

For full information on the wallet, use [getWalletInfo](#getwalletinfo)

```ts title="client.wallet.listWallets()"
interface wallet {
listWallets (): Promise<string[]>
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Testing } from '@defichain/jellyfish-testing'
import { MasterNodeRegTestContainer, RegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../../container_adapter_client'

describe('Wallet without masternode', () => {
const container = new RegTestContainer()
const client = new ContainerAdapterClient(container)
kodemon marked this conversation as resolved.
Show resolved Hide resolved
fuxingloh marked this conversation as resolved.
Show resolved Hide resolved

beforeAll(async () => {
await container.start()
await client.wallet.createWallet('test')
})

afterAll(async () => {
await container.stop()
})

it('should listWallets', async () => {
const wallets = await client.wallet.listWallets()
expect(wallets).toStrictEqual(['', 'test'])
})
})

describe('Wallet with masternode', () => {
const master = new MasterNodeRegTestContainer()
const testing = Testing.create(master)

beforeAll(async () => {
await testing.container.start()
await testing.rpc.wallet.createWallet('test')
})

afterAll(async () => {
await testing.container.stop()
})

it('should listWallets', async () => {
const wallets = await testing.rpc.wallet.listWallets()
expect(wallets).toEqual(['', 'test'])
})
})
10 changes: 10 additions & 0 deletions packages/jellyfish-api-core/src/category/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,16 @@ export class Wallet {
async getTransaction (txid: string, includeWatchOnly: boolean = true): Promise<InWalletTransaction> {
return await this.client.call('gettransaction', [txid, includeWatchOnly], { amount: 'bignumber' })
}

/**
* Returns a list of currently loaded wallets.
* For full information on the wallet, use 'getwalletinfo'
*
* @return {Promise<string[]>}
*/
async listWallets (): Promise<string[]> {
return await this.client.call('listwallets', [], 'number')
}
}

export interface UTXO {
Expand Down