Skip to content

Commit

Permalink
wallet-client: add options to the getNames.
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Dec 18, 2023
1 parent db07477 commit d037103
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -61,11 +61,13 @@ process and allows parallel rescans.
- `open()` no longer calls scan, instead only rollbacks and waits for
sync to do the rescan.
- emits events for: `open`, `close`, `connect`, `disconnect`, `sync done`.
- HTTP Changes:

### Wallet HTTP Client
- All transaction creating endpoints now accept `hardFee` for specifying the
exact fee.
- All transaction sending endpoints now fundlock/queue tx creation. (no more
conflicting transactions)
- Add options to `getNames` for passing `own`.

## v6.0.0

Expand Down
27 changes: 23 additions & 4 deletions lib/client/wallet.js
Expand Up @@ -118,6 +118,9 @@ class WalletClient extends Client {

/**
* Create a wallet object.
* @param {String} id
* @param {String} [token]
* @returns {Wallet}
*/

wallet(id, token) {
Expand Down Expand Up @@ -339,11 +342,13 @@ class WalletClient extends Client {
* that the wallet is managing.
* {@see hsd.NameState}
* @param {String} id
* @param {Object} options
* @param {Boolean} [optoins.own=false]
* @returns {Promise}
*/

getNames(id) {
return this.get(`/wallet/${id}/name`);
getNames(id, options) {
return this.get(`/wallet/${id}/name`, options);
}

/**
Expand Down Expand Up @@ -893,6 +898,18 @@ class WalletClient extends Client {
*/

class Wallet extends EventEmitter {
/** @type {WalletClient} */
client;

/** @type {WalletClient} */
parent;

/** @type {String} */
id;

/** @type {String} */
token;

/**
* Create a wallet client.
* @param {Object?} options
Expand Down Expand Up @@ -1051,11 +1068,13 @@ class Wallet extends EventEmitter {
* Get name state for all names
* that the wallet is managing.
* {@see hsd.NameState}
* @param {Object} options
* @param {Boolean} [optoins.own=false]
* @returns {Promise}
*/

getNames() {
return this.client.getNames(this.id);
getNames(options) {
return this.client.getNames(this.id, options);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions test/util/node-context.js
Expand Up @@ -11,6 +11,15 @@ const {NodeClient, WalletClient} = require('../../lib/client');
const Logger = require('blgr');

class NodeContext {
/** @type {FullNode|SPVNode} */
node;

/** @type {WalletClient} */
wclient;

/** @type {NodeClient} */
nclient;

constructor(options = {}) {
this.name = 'node-test';
this.options = {};
Expand Down
4 changes: 1 addition & 3 deletions test/wallet-http-test.js
Expand Up @@ -1787,9 +1787,7 @@ describe('Wallet HTTP', function() {
});

it('should only get wallet-owned names', async () => {
// TODO: convert to using hs-client method
// when wallet.getNames() allows `options`
const names = await wallet.client.get(`/wallet/${wallet.id}/name`, {own: true});
const names = await wallet.getNames({ own: true });

assert.equal(names.length, ownedNames.length);

Expand Down

0 comments on commit d037103

Please sign in to comment.