grab block height from the coinbase script.
This commit is contained in:
parent
07a1322749
commit
618177b6a6
@ -14,6 +14,7 @@ var constants = bcoin.protocol.constants;
|
||||
|
||||
function Block(data, subtype) {
|
||||
var self = this;
|
||||
var tx;
|
||||
|
||||
if (!(this instanceof Block))
|
||||
return new Block(data, subtype);
|
||||
@ -57,6 +58,13 @@ function Block(data, subtype) {
|
||||
tx.ts = tx.ts || self.ts;
|
||||
return tx;
|
||||
});
|
||||
|
||||
if (this.version >= 2) {
|
||||
tx = this.txs[0];
|
||||
if (tx && tx.inputs[0] && +tx.inputs[0].out.hash === 0)
|
||||
this._height = bcoin.script.coinbase(tx.inputs[0].script);
|
||||
}
|
||||
|
||||
this.invalid = !this._checkBlock();
|
||||
}
|
||||
|
||||
|
||||
@ -1138,6 +1138,20 @@ script.isScripthashInput = function isScripthashInput(s, redeem) {
|
||||
return keys;
|
||||
};
|
||||
|
||||
script.coinbase = function coinbase(s) {
|
||||
var base = s._raw || script.encode(s);
|
||||
var len = Math.min(base[0], base.length);
|
||||
var height = 0;
|
||||
var i, b;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
b = base[i + 1] & 0xff;
|
||||
height |= b << (8 * i);
|
||||
}
|
||||
|
||||
return height;
|
||||
};
|
||||
|
||||
// https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki
|
||||
/**
|
||||
* A canonical signature exists of: <30> <total len> <02> <len R> <R> <02> <len S> <S> <hashtype>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user