coinbase flags.
This commit is contained in:
parent
1bf606a22d
commit
6a482af6d0
@ -120,6 +120,12 @@ function getTX(callback) {
|
||||
client.getTX(hash, function(err, tx) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
if (!tx) {
|
||||
utils.print('TX not found.');
|
||||
return callback();
|
||||
}
|
||||
|
||||
utils.print(tx);
|
||||
callback();
|
||||
});
|
||||
@ -134,7 +140,15 @@ function getBlock(callback) {
|
||||
client.getBlock(hash, function(err, block) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
if (!block) {
|
||||
utils.print('Block not found.');
|
||||
return callback();
|
||||
}
|
||||
|
||||
utils.print(block);
|
||||
utils.print('Coinbase Data:');
|
||||
utils.print(block.txs[0].inputs[0].script.getCoinbaseFlags());
|
||||
callback();
|
||||
});
|
||||
}
|
||||
@ -154,6 +168,12 @@ function getCoin(callback) {
|
||||
client.getCoin(hash, index, function(err, coin) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
if (!coin) {
|
||||
utils.print('Coin not found.');
|
||||
return callback();
|
||||
}
|
||||
|
||||
utils.print(coin);
|
||||
callback();
|
||||
});
|
||||
|
||||
@ -3051,28 +3051,28 @@ Script.getCoinbaseHeight = function getCoinbaseHeight(code) {
|
||||
* `extraNonce`, `flags`, and `text`.
|
||||
*/
|
||||
|
||||
Script.prototype.getCoinbaseData = function getCoinbaseData() {
|
||||
Script.prototype.getCoinbaseFlags = function getCoinbaseFlags() {
|
||||
var coinbase = {};
|
||||
var flags;
|
||||
var index = 0;
|
||||
var nonce;
|
||||
|
||||
coinbase.height = this.getCoinbaseHeight();
|
||||
|
||||
if (Buffer.isBuffer(this.code[1]))
|
||||
coinbase.extraNonce = new bn(this.code[1], 'le');
|
||||
else
|
||||
coinbase.extraNonce = new bn(0);
|
||||
if (coinbase.height !== -1)
|
||||
index++;
|
||||
|
||||
flags = this.code.slice(2).filter(function(chunk) {
|
||||
return Buffer.isBuffer(chunk) && chunk.length !== 0;
|
||||
});
|
||||
if (Buffer.isBuffer(this.code[1]) && this.code[1].length <= 6) {
|
||||
coinbase.extraNonce = new bn(this.code[1], 'le').toNumber();
|
||||
} else {
|
||||
nonce = Script.getSmall(this.code[1]);
|
||||
coinbase.extraNonce = nonce == null ? -1 : nonce;
|
||||
}
|
||||
|
||||
coinbase.flags = flags;
|
||||
coinbase.flags = Script.encode(this.code.slice(index));
|
||||
|
||||
flags = flags.map(function(flag) {
|
||||
return flag.toString('utf8');
|
||||
});
|
||||
|
||||
coinbase.text = flags.join('').replace(/[\u0000-\u0019\u007f-\u00ff]/g, '');
|
||||
coinbase.text = coinbase.flags
|
||||
.toString('utf8')
|
||||
.replace(/[\u0000-\u0019\u007f-\u00ff]/g, '');
|
||||
|
||||
return coinbase;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user