Skip to content

Commit

Permalink
Merge 3dfa9b2 into e270b8c
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Feb 5, 2021
2 parents e270b8c + 3dfa9b2 commit d2d3aa5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ The reveal will have to be broadcasted at a later time, during the REVEAL phase.
The lockup must include a blind big enough to ensure the BID will be the only input of the REVEAL
transaction.

- `rpc getbids` accepts a third parameter `unrevealed` _(bool)_ which filters the response by checking
the wallet's unspent coins database for each bid. If an unspent coin is found, the output address
of that coin is added to the JSON response. This is useful for wallet recovery scenarios
when users need to call `rpc importnonce` to repair unknown blinds. The complete usage is now
`rpc getbids name (own) (unrevealed)` so for example a wallet-recovering user would execute
`rpc getbids null true true`.

### Node & Wallet API changes

- The `stats` field included in `namestate.toJSON()` includes extra data if the name
Expand Down
34 changes: 30 additions & 4 deletions lib/wallet/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1742,26 +1742,52 @@ class RPC extends RPCBase {
}

async getBids(args, help) {
if (help || args.length > 2)
throw new RPCError(errs.MISC_ERROR, 'getbids "name" ( own )');
if (help || args.length > 3)
throw new RPCError(
errs.MISC_ERROR,
'getbids "name" ( own ) ( unrevealed )'
);

const wallet = this.wallet;
const valid = new Validator(args);
const name = valid.str(0);
let own = valid.bool(1, false);
const unrevealed = valid.bool(2, false);

if (name && !rules.verifyName(name))
throw new RPCError(errs.TYPE_ERROR, 'Invalid name.');

if (unrevealed && !own) {
throw new RPCError(
errs.MISC_ERROR,
'"own" must be true if "unrevealed" is set.'
);
}

if (!name)
own = true;

const bids = await wallet.getBidsByName(name);
const items = [];

for (const bid of bids) {
if (!own || bid.own)
items.push(bid.toJSON());
if (!own || bid.own) {
const json = bid.toJSON();

if (unrevealed) {
const coin = await wallet.getCoin(
bid.prevout.hash,
bid.prevout.index
);
if (!coin) {
continue;
} else {
json.address = coin.address.toString(this.network);
}
}

items.push(json);
}
}

return items;
Expand Down

0 comments on commit d2d3aa5

Please sign in to comment.