rpc: getblocktemplate - abide by bip145.
This commit is contained in:
parent
1af3ac63de
commit
9561b3ee74
@ -1640,7 +1640,7 @@ RPC.prototype._tmpl = function _tmpl(version, coinbase, rules, callback) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
var txs = [];
|
var txs = [];
|
||||||
var txIndex = {};
|
var txIndex = {};
|
||||||
var i, j, tx, deps, input, dep, block;
|
var i, j, tx, deps, input, dep, block, output, raw, rwhash;
|
||||||
var keys, vbavailable, vbrules, mutable, template;
|
var keys, vbavailable, vbrules, mutable, template;
|
||||||
|
|
||||||
callback = this.locker.lock(_tmpl, [version, coinbase, rules, callback]);
|
callback = this.locker.lock(_tmpl, [version, coinbase, rules, callback]);
|
||||||
@ -1729,10 +1729,6 @@ RPC.prototype._tmpl = function _tmpl(version, coinbase, rules, callback) {
|
|||||||
vbrequired: 0,
|
vbrequired: 0,
|
||||||
previousblockhash: utils.revHex(block.prevBlock),
|
previousblockhash: utils.revHex(block.prevBlock),
|
||||||
transactions: txs,
|
transactions: txs,
|
||||||
coinbaseaux: {
|
|
||||||
flags: attempt.coinbaseFlags.toString('hex')
|
|
||||||
},
|
|
||||||
coinbasevalue: attempt.coinbase.outputs[0].value,
|
|
||||||
longpollid: self.chain.tip.rhash + utils.pad32(self._totalTX()),
|
longpollid: self.chain.tip.rhash + utils.pad32(self._totalTX()),
|
||||||
target: utils.revHex(attempt.target.toString('hex')),
|
target: utils.revHex(attempt.target.toString('hex')),
|
||||||
submitold: false,
|
submitold: false,
|
||||||
@ -1747,25 +1743,46 @@ RPC.prototype._tmpl = function _tmpl(version, coinbase, rules, callback) {
|
|||||||
weightlimit: constants.block.MAX_WEIGHT,
|
weightlimit: constants.block.MAX_WEIGHT,
|
||||||
curtime: block.ts,
|
curtime: block.ts,
|
||||||
bits: utils.hex32(block.bits),
|
bits: utils.hex32(block.bits),
|
||||||
height: attempt.height,
|
height: attempt.height
|
||||||
default_witness_commitment: attempt.witness
|
|
||||||
? attempt.coinbase.outputs[1].script.toJSON()
|
|
||||||
: undefined
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (coinbase) {
|
if (coinbase) {
|
||||||
template.coinbaseaux = undefined;
|
tx = attempt.coinbase;
|
||||||
template.coinbasevalue = undefined;
|
|
||||||
tx = block.txs[0];
|
// We don't include the commitment
|
||||||
|
// output (see bip145).
|
||||||
|
if (attempt.witness) {
|
||||||
|
output = tx.outputs.pop();
|
||||||
|
assert(output.script.isCommitment());
|
||||||
|
raw = tx.toRaw();
|
||||||
|
rwhash = tx.rwhash;
|
||||||
|
tx.outputs.push(output);
|
||||||
|
} else {
|
||||||
|
raw = tx.toRaw();
|
||||||
|
rwhash = tx.rwhash;
|
||||||
|
}
|
||||||
|
|
||||||
template.coinbasetxn = {
|
template.coinbasetxn = {
|
||||||
data: tx.toRaw().toString('hex'),
|
data: raw.toString('hex'),
|
||||||
txid: tx.rhash,
|
txid: tx.rhash,
|
||||||
hash: tx.rwhash,
|
hash: rwhash,
|
||||||
depends: [],
|
depends: [],
|
||||||
fee: 0,
|
fee: 0,
|
||||||
sigops: tx.getSigops(),
|
sigops: tx.getSigops(),
|
||||||
weight: tx.getWeight()
|
weight: tx.getWeight()
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
template.coinbaseaux = {
|
||||||
|
flags: attempt.coinbaseFlags.toString('hex')
|
||||||
|
};
|
||||||
|
template.coinbasevalue = attempt.coinbase.getOutputValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attempt.witness) {
|
||||||
|
tx = attempt.coinbase;
|
||||||
|
output = tx.outputs[tx.outputs.length - 1];
|
||||||
|
assert(output.script.isCommitment());
|
||||||
|
template.default_witness_commitment = output.script.toJSON();
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null, template);
|
callback(null, template);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user