rpc: getblocktemplate - abide by bip145.

This commit is contained in:
Christopher Jeffrey 2016-09-18 12:57:50 -07:00
parent 1af3ac63de
commit 9561b3ee74
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -1640,7 +1640,7 @@ RPC.prototype._tmpl = function _tmpl(version, coinbase, rules, callback) {
var self = this;
var txs = [];
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;
callback = this.locker.lock(_tmpl, [version, coinbase, rules, callback]);
@ -1729,10 +1729,6 @@ RPC.prototype._tmpl = function _tmpl(version, coinbase, rules, callback) {
vbrequired: 0,
previousblockhash: utils.revHex(block.prevBlock),
transactions: txs,
coinbaseaux: {
flags: attempt.coinbaseFlags.toString('hex')
},
coinbasevalue: attempt.coinbase.outputs[0].value,
longpollid: self.chain.tip.rhash + utils.pad32(self._totalTX()),
target: utils.revHex(attempt.target.toString('hex')),
submitold: false,
@ -1747,25 +1743,46 @@ RPC.prototype._tmpl = function _tmpl(version, coinbase, rules, callback) {
weightlimit: constants.block.MAX_WEIGHT,
curtime: block.ts,
bits: utils.hex32(block.bits),
height: attempt.height,
default_witness_commitment: attempt.witness
? attempt.coinbase.outputs[1].script.toJSON()
: undefined
height: attempt.height
};
if (coinbase) {
template.coinbaseaux = undefined;
template.coinbasevalue = undefined;
tx = block.txs[0];
tx = attempt.coinbase;
// 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 = {
data: tx.toRaw().toString('hex'),
data: raw.toString('hex'),
txid: tx.rhash,
hash: tx.rwhash,
hash: rwhash,
depends: [],
fee: 0,
sigops: tx.getSigops(),
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);