Skip to content

Commit

Permalink
feat(jellyfish-api-core): add wallet listWallets RPC (#953)
Browse files Browse the repository at this point in the history
* add list wallets rpc

* use testing package for container creation

* tweak value assignment as per suggestion

Co-authored-by: Fuxing Loh <[email protected]>

* split wallets generation and expect test

* further update tests based on feedback

Co-authored-by: Fuxing Loh <[email protected]>
  • Loading branch information
kodemon and fuxingloh authored Feb 21, 2022
1 parent f5ba961 commit 1a11e4a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
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)

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

0 comments on commit 1a11e4a

Please sign in to comment.