improve block.fromRaw.
This commit is contained in:
parent
727a000b23
commit
d1f05453bb
@ -543,8 +543,6 @@ Block.fromCompact = function fromCompact(json) {
|
|||||||
Block.prototype.toRaw = function toRaw(enc) {
|
Block.prototype.toRaw = function toRaw(enc) {
|
||||||
var data;
|
var data;
|
||||||
|
|
||||||
assert(this.subtype === 'block');
|
|
||||||
|
|
||||||
data = this.render();
|
data = this.render();
|
||||||
|
|
||||||
if (enc === 'hex')
|
if (enc === 'hex')
|
||||||
@ -553,17 +551,28 @@ Block.prototype.toRaw = function toRaw(enc) {
|
|||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
Block._fromRaw = function _fromRaw(data, enc) {
|
Block._fromRaw = function _fromRaw(data, enc, subtype) {
|
||||||
var parser = new bcoin.protocol.parser();
|
var parser = new bcoin.protocol.parser();
|
||||||
|
|
||||||
|
if (!subtype)
|
||||||
|
subtype = 'block';
|
||||||
|
|
||||||
if (enc === 'hex')
|
if (enc === 'hex')
|
||||||
data = new Buffer(data, 'hex');
|
data = new Buffer(data, 'hex');
|
||||||
|
|
||||||
|
if (subtype === 'headers')
|
||||||
|
return parser.parseHeaders(data);
|
||||||
|
|
||||||
|
if (subtype === 'merkleblock')
|
||||||
|
return parser.parseMerkleBlock(data);
|
||||||
|
|
||||||
return parser.parseBlock(data);
|
return parser.parseBlock(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
Block.fromRaw = function fromRaw(data, enc) {
|
Block.fromRaw = function fromRaw(data, enc, subtype) {
|
||||||
return new Block(Block._fromRaw(data, enc), 'block');
|
if (!subtype)
|
||||||
|
subtype = 'block';
|
||||||
|
return new Block(Block._fromRaw(data, enc, subtype), subtype);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user