Skip to content

Commit d350c09

Browse files
author
Mark Tyneway
committed
rpc: update node rpc validateaddress
This PR updates the node rpc validateaddress to better seperate the wallet and the node. The rpc was returning ismine and iswatch only. These values were moved to the wallet rpc method getaddressinfo. This corresponds to a change in bitcoind and bcoin. The updated validateaddress rpc returns the values: - isvalid - address - ismine - iswatchonly - isscript - isspendable - witness_version - witness_program See PR in bcoin: bcoin-org/bcoin#731 See PR in bitcoind: bitcoin/bitcoin#10583
1 parent 76e674d commit d350c09

File tree

3 files changed

+65
-7
lines changed

3 files changed

+65
-7
lines changed

lib/node/rpc.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2093,8 +2093,10 @@ class RPC extends RPCBase {
20932093
return {
20942094
isvalid: true,
20952095
address: addr.toString(this.network),
2096-
ismine: false,
2097-
iswatchonly: false
2096+
isscript: addr.isScripthash(),
2097+
isspendable: !addr.isUnspendable(),
2098+
witness_version: addr.version,
2099+
witness_program: addr.hash.toString('hex')
20982100
};
20992101
}
21002102

test/http-test.js

+56-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const consensus = require('../lib/protocol/consensus');
88
const Address = require('../lib/primitives/address');
99
const Outpoint = require('../lib/primitives/outpoint');
1010
const MTX = require('../lib/primitives/mtx');
11+
const Script = require('../lib/script/script');
1112
const FullNode = require('../lib/node/fullnode');
1213
const pkg = require('../lib/pkg');
1314
const Network = require('../lib/protocol/network');
@@ -250,9 +251,62 @@ describe('HTTP', function() {
250251
]);
251252
assert.deepStrictEqual(json, {
252253
isvalid: true,
254+
isscript: false,
255+
isspendable: true,
253256
address: addr.toString(node.network),
254-
ismine: false,
255-
iswatchonly: false
257+
witness_program: addr.hash.toString('hex'),
258+
witness_version: addr.version
259+
});
260+
});
261+
262+
it('should not validate invalid address', async () => {
263+
const json = await nclient.execute('validateaddress', [
264+
addr.toString('main')
265+
]);
266+
assert.deepStrictEqual(json, {
267+
isvalid: false
268+
});
269+
});
270+
271+
it('should validate a p2wsh address', async () => {
272+
const pubkeys = [];
273+
for (let i = 0; i < 2; i++) {
274+
const result = await wallet.createAddress('default');
275+
pubkeys.push(Buffer.from(result.publicKey, 'hex'));
276+
}
277+
278+
const script = Script.fromMultisig(2, 2, pubkeys);
279+
const address = Address.fromScript(script);
280+
281+
const json = await nclient.execute('validateaddress', [
282+
address.toString(node.network)
283+
]);
284+
285+
assert.deepStrictEqual(json, {
286+
address: address.toString(node.network),
287+
isscript: true,
288+
isspendable: true,
289+
isvalid: true,
290+
witness_version: address.version,
291+
witness_program: address.hash.toString('hex')
292+
});
293+
});
294+
295+
it('should validate a null address', async () => {
296+
const data = Buffer.from('foobar', 'ascii');
297+
const nullAddr = Address.fromNulldata(data);
298+
299+
const json = await nclient.execute('validateaddress', [
300+
nullAddr.toString(node.network)
301+
]);
302+
303+
assert.deepStrictEqual(json, {
304+
address: nullAddr.toString(node.network),
305+
isscript: false,
306+
isspendable: false,
307+
isvalid: true,
308+
witness_version: nullAddr.version,
309+
witness_program: nullAddr.hash.toString('hex')
256310
});
257311
});
258312

test/node-test.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,12 @@ describe('Node', function() {
511511
}, {});
512512

513513
assert.deepStrictEqual(json.result, {
514-
isvalid: true,
515514
address: addr.toString(node.network),
516-
ismine: false,
517-
iswatchonly: false
515+
isvalid: true,
516+
isscript: false,
517+
isspendable: true,
518+
witness_version: addr.version,
519+
witness_program: addr.hash.toString('hex')
518520
});
519521
});
520522

0 commit comments

Comments
 (0)