rpc: misc rpc fixes.

This commit is contained in:
Christopher Jeffrey 2017-03-13 22:26:08 -07:00
parent f4106a615e
commit 6eb6800fc8
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -244,7 +244,7 @@ RPC.prototype.addNode = co(function* addNode(args, help) {
break;
case 'onetry':
if (!this.pool.peers.get(addr.hostname)) {
peer = this.pool.createPeer(addr);
peer = this.pool.createOutbound(addr);
this.pool.peers.add(peer);
}
break;
@ -442,7 +442,7 @@ RPC.prototype.getBlockchainInfo = co(function* getBlockchainInfo(args, help) {
throw new RPCError('getblockchaininfo');
return {
chain: 'main',
chain: this.network.type,
blocks: this.chain.height,
headers: this.chain.height,
bestblockhash: this.chain.tip.rhash(),
@ -1030,29 +1030,13 @@ RPC.prototype.getWork = co(function* getWork(args, help) {
RPC.prototype.submitBlock = co(function* submitBlock(args, help) {
var valid = new Validator([args]);
var data = valid.buf(0);
var block, tx;
var block;
if (help || args.length < 1 || args.length > 2)
throw new RPCError('submitblock "hexdata" ( "jsonparametersobject" )');
block = Block.fromRaw(data);
// Fix eloipool bug (witness nonce is not present).
if (this.chain.state.hasWitness() && block.getCommitmentHash()) {
tx = block.txs[0];
if (!tx.hasWitness()) {
this.logger.warning('Submitted block had no witness nonce.');
this.logger.debug(tx);
// Recreate witness nonce (all zeroes).
tx.inputs[0].witness.set(0, encoding.ZERO_HASH);
tx.inputs[0].witness.compile();
tx.refresh();
block.refresh();
}
}
return yield this._submitBlock(block);
});
@ -1066,10 +1050,33 @@ RPC.prototype._submitBlock = co(function* _submitBlock(block) {
});
RPC.prototype.__submitBlock = co(function* __submitBlock(block) {
var entry;
var entry, prev, state;
this.logger.info('Handling submitted block: %s.', block.rhash());
prev = yield this.chain.db.getEntry(block.prevBlock);
if (!prev)
return 'rejected: bad-prevblk';
state = yield this.chain.getDeployments(block.ts, prev);
// Fix eloipool bug (witness nonce is not present).
if (state.hasWitness() && block.getCommitmentHash()) {
tx = block.txs[0];
if (!tx.hasWitness()) {
this.logger.warning('Submitted block had no witness nonce.');
this.logger.debug(tx);
// Recreate witness nonce (all zeroes).
tx.inputs[0].witness.set(0, encoding.ZERO_HASH);
tx.inputs[0].witness.compile();
tx.refresh();
block.refresh();
}
}
try {
entry = yield this.chain.add(block);
} catch (err) {
@ -1302,14 +1309,8 @@ RPC.prototype._createTemplate = co(function* _createTemplate(version, coinbase,
};
}
if (attempt.witness) {
tx = attempt.toCoinbase();
output = tx.outputs[tx.outputs.length - 1];
assert(output.script.isCommitment());
json.default_witness_commitment = output.script.toJSON();
} else if (rules && rules.indexOf('segwit') !== -1) {
if (rules && rules.indexOf('segwit') !== -1)
json.default_witness_commitment = attempt.getWitnessScript().toJSON();
}
return json;
});
@ -1350,8 +1351,8 @@ RPC.prototype.getNetworkHashPS = co(function* getNetworkHashPS(args, help) {
RPC.prototype.prioritiseTransaction = co(function* prioritiseTransaction(args, help) {
var valid = new Validator([args]);
var hash = valid.hash(0);
var pri = valid.u64(1);
var fee = valid.btc(2);
var pri = valid.num(1);
var fee = valid.num(2);
var entry;
if (help || args.length !== 3) {
@ -1373,14 +1374,8 @@ RPC.prototype.prioritiseTransaction = co(function* prioritiseTransaction(args, h
if (!entry)
throw new RPCError('Transaction not in mempool.');
entry.priority += pri;
entry.fee += fee;
if (entry.priority < 0)
entry.priority = 0;
if (entry.fee < 0)
entry.fee = 0;
entry.priDelta += pri;
entry.feeDelta += fee;
return true;
});
@ -1507,10 +1502,10 @@ RPC.prototype.createRawTransaction = co(function* createRawTransaction(args, hel
if (!inputs || !sendTo)
throw new RPCError('Invalid parameters (inputs and sendTo).');
tx = new TX();
tx = new MTX();
if (locktime != null)
tx.setLocktime(locktime);
tx.locktime = locktime;
for (i = 0; i < inputs.length; i++) {
input = inputs[i];