rpc: misc rpc fixes.
This commit is contained in:
parent
f4106a615e
commit
6eb6800fc8
@ -244,7 +244,7 @@ RPC.prototype.addNode = co(function* addNode(args, help) {
|
|||||||
break;
|
break;
|
||||||
case 'onetry':
|
case 'onetry':
|
||||||
if (!this.pool.peers.get(addr.hostname)) {
|
if (!this.pool.peers.get(addr.hostname)) {
|
||||||
peer = this.pool.createPeer(addr);
|
peer = this.pool.createOutbound(addr);
|
||||||
this.pool.peers.add(peer);
|
this.pool.peers.add(peer);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -442,7 +442,7 @@ RPC.prototype.getBlockchainInfo = co(function* getBlockchainInfo(args, help) {
|
|||||||
throw new RPCError('getblockchaininfo');
|
throw new RPCError('getblockchaininfo');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
chain: 'main',
|
chain: this.network.type,
|
||||||
blocks: this.chain.height,
|
blocks: this.chain.height,
|
||||||
headers: this.chain.height,
|
headers: this.chain.height,
|
||||||
bestblockhash: this.chain.tip.rhash(),
|
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) {
|
RPC.prototype.submitBlock = co(function* submitBlock(args, help) {
|
||||||
var valid = new Validator([args]);
|
var valid = new Validator([args]);
|
||||||
var data = valid.buf(0);
|
var data = valid.buf(0);
|
||||||
var block, tx;
|
var block;
|
||||||
|
|
||||||
if (help || args.length < 1 || args.length > 2)
|
if (help || args.length < 1 || args.length > 2)
|
||||||
throw new RPCError('submitblock "hexdata" ( "jsonparametersobject" )');
|
throw new RPCError('submitblock "hexdata" ( "jsonparametersobject" )');
|
||||||
|
|
||||||
block = Block.fromRaw(data);
|
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);
|
return yield this._submitBlock(block);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1066,10 +1050,33 @@ RPC.prototype._submitBlock = co(function* _submitBlock(block) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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());
|
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 {
|
try {
|
||||||
entry = yield this.chain.add(block);
|
entry = yield this.chain.add(block);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -1302,14 +1309,8 @@ RPC.prototype._createTemplate = co(function* _createTemplate(version, coinbase,
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attempt.witness) {
|
if (rules && rules.indexOf('segwit') !== -1)
|
||||||
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) {
|
|
||||||
json.default_witness_commitment = attempt.getWitnessScript().toJSON();
|
json.default_witness_commitment = attempt.getWitnessScript().toJSON();
|
||||||
}
|
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
});
|
});
|
||||||
@ -1350,8 +1351,8 @@ RPC.prototype.getNetworkHashPS = co(function* getNetworkHashPS(args, help) {
|
|||||||
RPC.prototype.prioritiseTransaction = co(function* prioritiseTransaction(args, help) {
|
RPC.prototype.prioritiseTransaction = co(function* prioritiseTransaction(args, help) {
|
||||||
var valid = new Validator([args]);
|
var valid = new Validator([args]);
|
||||||
var hash = valid.hash(0);
|
var hash = valid.hash(0);
|
||||||
var pri = valid.u64(1);
|
var pri = valid.num(1);
|
||||||
var fee = valid.btc(2);
|
var fee = valid.num(2);
|
||||||
var entry;
|
var entry;
|
||||||
|
|
||||||
if (help || args.length !== 3) {
|
if (help || args.length !== 3) {
|
||||||
@ -1373,14 +1374,8 @@ RPC.prototype.prioritiseTransaction = co(function* prioritiseTransaction(args, h
|
|||||||
if (!entry)
|
if (!entry)
|
||||||
throw new RPCError('Transaction not in mempool.');
|
throw new RPCError('Transaction not in mempool.');
|
||||||
|
|
||||||
entry.priority += pri;
|
entry.priDelta += pri;
|
||||||
entry.fee += fee;
|
entry.feeDelta += fee;
|
||||||
|
|
||||||
if (entry.priority < 0)
|
|
||||||
entry.priority = 0;
|
|
||||||
|
|
||||||
if (entry.fee < 0)
|
|
||||||
entry.fee = 0;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@ -1507,10 +1502,10 @@ RPC.prototype.createRawTransaction = co(function* createRawTransaction(args, hel
|
|||||||
if (!inputs || !sendTo)
|
if (!inputs || !sendTo)
|
||||||
throw new RPCError('Invalid parameters (inputs and sendTo).');
|
throw new RPCError('Invalid parameters (inputs and sendTo).');
|
||||||
|
|
||||||
tx = new TX();
|
tx = new MTX();
|
||||||
|
|
||||||
if (locktime != null)
|
if (locktime != null)
|
||||||
tx.setLocktime(locktime);
|
tx.locktime = locktime;
|
||||||
|
|
||||||
for (i = 0; i < inputs.length; i++) {
|
for (i = 0; i < inputs.length; i++) {
|
||||||
input = inputs[i];
|
input = inputs[i];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user