rpc: misc fixes.
This commit is contained in:
parent
5e18dddd37
commit
170cf0db28
@ -352,6 +352,9 @@ RPC.prototype.stop = function stop(args, callback) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
RPC.prototype.getnetworkinfo = function getnetworkinfo(args, callback) {
|
RPC.prototype.getnetworkinfo = function getnetworkinfo(args, callback) {
|
||||||
|
if (args.help || args.length !== 0)
|
||||||
|
return callback(new RPCError('getnetworkinfo'));
|
||||||
|
|
||||||
callback(null, {
|
callback(null, {
|
||||||
version: constants.USER_VERSION,
|
version: constants.USER_VERSION,
|
||||||
subversion: constants.USER_AGENT,
|
subversion: constants.USER_AGENT,
|
||||||
@ -359,29 +362,7 @@ RPC.prototype.getnetworkinfo = function getnetworkinfo(args, callback) {
|
|||||||
localservices: this.pool.services,
|
localservices: this.pool.services,
|
||||||
timeoffset: bcoin.time.offset,
|
timeoffset: bcoin.time.offset,
|
||||||
connections: this.pool.peers.all.length,
|
connections: this.pool.peers.all.length,
|
||||||
networks: [
|
networks: [],
|
||||||
{
|
|
||||||
name: 'ipv4',
|
|
||||||
limited: false,
|
|
||||||
reachable: false,
|
|
||||||
proxy: '',
|
|
||||||
proxy_randomize_credentials: false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'ipv6',
|
|
||||||
limited: false,
|
|
||||||
reachable: false,
|
|
||||||
proxy: '',
|
|
||||||
proxy_randomize_credentials: false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'onion',
|
|
||||||
limited: false,
|
|
||||||
reachable: false,
|
|
||||||
proxy: '',
|
|
||||||
proxy_randomize_credentials: false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
relayfee: +utils.btc(this.network.getMinRelay()),
|
relayfee: +utils.btc(this.network.getMinRelay()),
|
||||||
localaddresses: [],
|
localaddresses: [],
|
||||||
warnings: ''
|
warnings: ''
|
||||||
@ -389,29 +370,33 @@ RPC.prototype.getnetworkinfo = function getnetworkinfo(args, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
RPC.prototype.addnode = function addnode(args, callback) {
|
RPC.prototype.addnode = function addnode(args, callback) {
|
||||||
var i, node, cmd, host, seed;
|
var i, node, cmd, host, seed, peer;
|
||||||
|
|
||||||
if (args.help || args.length !== 2)
|
if (args.help || args.length !== 2)
|
||||||
return callback(new RPCError('addnode "node" "add|remove|onetry"'));
|
return callback(new RPCError('addnode "node" "add|remove|onetry"'));
|
||||||
|
|
||||||
node = toString(args[0]);
|
node = toString(args[0]);
|
||||||
cmd = toString(args[1]);
|
cmd = toString(args[1]);
|
||||||
host = NetworkAddress.fromHostname(node, this.network);
|
addr = NetworkAddress.fromHostname(node, this.network);
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case 'add':
|
case 'add':
|
||||||
this.pool.seeds.push(host);
|
this.pool.seeds.push(addr);
|
||||||
break;
|
break;
|
||||||
case 'remove':
|
case 'remove':
|
||||||
for (i = 0; i < this.pool.seeds.length; i++) {
|
for (i = 0; i < this.pool.seeds.length; i++) {
|
||||||
seed = this.pool.seeds[i];
|
seed = this.pool.seeds[i];
|
||||||
if (seed.hostname === host.hostname) {
|
if (seed.hostname === addr.hostname) {
|
||||||
this.pool.seeds.splice(i, 1);
|
this.pool.seeds.splice(i, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'onetry':
|
case 'onetry':
|
||||||
|
if (this.pool.peers.get(addr))
|
||||||
|
break;
|
||||||
|
peer = this.createPeer(addr);
|
||||||
|
this.peers.addPending(peer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,15 +404,15 @@ RPC.prototype.addnode = function addnode(args, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
RPC.prototype.disconnectnode = function disconnectnode(args, callback) {
|
RPC.prototype.disconnectnode = function disconnectnode(args, callback) {
|
||||||
var node, peer;
|
var node, addr, peer;
|
||||||
|
|
||||||
if (args.help || args.length !== 1)
|
if (args.help || args.length !== 1)
|
||||||
return callback(new RPCError('disconnectnode "node"'));
|
return callback(new RPCError('disconnectnode "node"'));
|
||||||
|
|
||||||
node = toString(args[0]);
|
node = toString(args[0]);
|
||||||
node = NetworkAddress.fromHostname(node, this.network);
|
addr = NetworkAddress.fromHostname(node, this.network);
|
||||||
|
|
||||||
peer = this.pool.peers.get(node);
|
peer = this.pool.peers.get(addr);
|
||||||
if (peer)
|
if (peer)
|
||||||
peer.destroy();
|
peer.destroy();
|
||||||
|
|
||||||
@ -436,14 +421,15 @@ RPC.prototype.disconnectnode = function disconnectnode(args, callback) {
|
|||||||
|
|
||||||
RPC.prototype.getaddednodeinfo = function getaddednodeinfo(args, callback) {
|
RPC.prototype.getaddednodeinfo = function getaddednodeinfo(args, callback) {
|
||||||
var out = [];
|
var out = [];
|
||||||
var i, host, peer, peers;
|
var i, host, addr, peer, peers;
|
||||||
|
|
||||||
if (args.help || args.length < 1 || args.length > 2)
|
if (args.help || args.length < 1 || args.length > 2)
|
||||||
return callback(new RPCError('getaddednodeinfo dummy ( "node" )'));
|
return callback(new RPCError('getaddednodeinfo dummy ( "node" )'));
|
||||||
|
|
||||||
if (args.length === 2) {
|
if (args.length === 2) {
|
||||||
host = toString(args[1]);
|
host = toString(args[1]);
|
||||||
peer = this.pool.peers.get(host);
|
addr = NetworkAddress.fromHostname(host, this.network);
|
||||||
|
peer = this.pool.peers.get(addr);
|
||||||
if (!peer)
|
if (!peer)
|
||||||
return callback(new RPCError('Node has not been added.'));
|
return callback(new RPCError('Node has not been added.'));
|
||||||
peers = [peer];
|
peers = [peer];
|
||||||
@ -2576,7 +2562,7 @@ RPC.prototype._scriptForWitness = function scriptForWitness(script) {
|
|||||||
return bcoin.script.fromProgram(0, hash);
|
return bcoin.script.fromProgram(0, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
hash = crypto.sha256(script.toRaw());
|
hash = script.sha256();
|
||||||
return bcoin.script.fromProgram(0, hash);
|
return bcoin.script.fromProgram(0, hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user