block: add block subtype - block or merkleblock.
Signed-off-by: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
parent
2b5f8693bf
commit
e04931026c
@ -1,11 +1,12 @@
|
|||||||
var bcoin = require('../bcoin');
|
var bcoin = require('../bcoin');
|
||||||
var utils = bcoin.utils;
|
var utils = bcoin.utils;
|
||||||
|
|
||||||
function Block(data) {
|
function Block(data, subtype) {
|
||||||
if (!(this instanceof Block))
|
if (!(this instanceof Block))
|
||||||
return new Block(data);
|
return new Block(data, subtype);
|
||||||
|
|
||||||
this.type = 'block';
|
this.type = 'block';
|
||||||
|
this.subtype = subtype;
|
||||||
this.version = data.version;
|
this.version = data.version;
|
||||||
this.prevBlock = utils.toHex(data.prevBlock);
|
this.prevBlock = utils.toHex(data.prevBlock);
|
||||||
this.merkleRoot = utils.toHex(data.merkleRoot);
|
this.merkleRoot = utils.toHex(data.merkleRoot);
|
||||||
|
|||||||
@ -449,7 +449,7 @@ Chain.prototype.fromJSON = function fromJSON(json) {
|
|||||||
this.index.bloom = new bcoin.bloom(28 * 1024 * 1024, 16, 0xdeadbee0);
|
this.index.bloom = new bcoin.bloom(28 * 1024 * 1024, 16, 0xdeadbee0);
|
||||||
|
|
||||||
if (this.index.hashes.length === 0)
|
if (this.index.hashes.length === 0)
|
||||||
this.add(new bcoin.block(constants.genesis));
|
this.add(new bcoin.block(constants.genesis, 'block'));
|
||||||
|
|
||||||
for (var i = 0; i < this.index.hashes.length; i++) {
|
for (var i = 0; i < this.index.hashes.length; i++) {
|
||||||
this.index.bloom.add(this.index.hashes[i], 'hex');
|
this.index.bloom.add(this.index.hashes[i], 'hex');
|
||||||
|
|||||||
@ -278,7 +278,7 @@ Peer.prototype._onPacket = function onPacket(packet) {
|
|||||||
return this._handlePong(payload);
|
return this._handlePong(payload);
|
||||||
|
|
||||||
if (cmd === 'merkleblock' || cmd === 'block') {
|
if (cmd === 'merkleblock' || cmd === 'block') {
|
||||||
payload = bcoin.block(payload);
|
payload = bcoin.block(payload, cmd);
|
||||||
this.lastBlock = payload;
|
this.lastBlock = payload;
|
||||||
} else if (cmd === 'tx') {
|
} else if (cmd === 'tx') {
|
||||||
payload = bcoin.tx(payload, this.lastBlock);
|
payload = bcoin.tx(payload, this.lastBlock);
|
||||||
|
|||||||
@ -25,7 +25,7 @@ describe('Block', function() {
|
|||||||
'1f5e46b9da3a8b1241f4a1501741d3453bafddf6135b600b926e3f4056c6d564',
|
'1f5e46b9da3a8b1241f4a1501741d3453bafddf6135b600b926e3f4056c6d564',
|
||||||
'33825657ba32afe269819f01993bd77baba86379043168c94845d32370e53562' ],
|
'33825657ba32afe269819f01993bd77baba86379043168c94845d32370e53562' ],
|
||||||
flags: [ 245, 90, 0 ]
|
flags: [ 245, 90, 0 ]
|
||||||
});
|
}, 'merkleblock');
|
||||||
|
|
||||||
assert(block.verify());
|
assert(block.verify());
|
||||||
assert.equal(block.tx.length, 2);
|
assert.equal(block.tx.length, 2);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user