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) {
|
||||
var data;
|
||||
|
||||
assert(this.subtype === 'block');
|
||||
|
||||
data = this.render();
|
||||
|
||||
if (enc === 'hex')
|
||||
@ -553,17 +551,28 @@ Block.prototype.toRaw = function toRaw(enc) {
|
||||
return data;
|
||||
};
|
||||
|
||||
Block._fromRaw = function _fromRaw(data, enc) {
|
||||
Block._fromRaw = function _fromRaw(data, enc, subtype) {
|
||||
var parser = new bcoin.protocol.parser();
|
||||
|
||||
if (!subtype)
|
||||
subtype = 'block';
|
||||
|
||||
if (enc === 'hex')
|
||||
data = new Buffer(data, 'hex');
|
||||
|
||||
if (subtype === 'headers')
|
||||
return parser.parseHeaders(data);
|
||||
|
||||
if (subtype === 'merkleblock')
|
||||
return parser.parseMerkleBlock(data);
|
||||
|
||||
return parser.parseBlock(data);
|
||||
};
|
||||
|
||||
Block.fromRaw = function fromRaw(data, enc) {
|
||||
return new Block(Block._fromRaw(data, enc), 'block');
|
||||
Block.fromRaw = function fromRaw(data, enc, subtype) {
|
||||
if (!subtype)
|
||||
subtype = 'block';
|
||||
return new Block(Block._fromRaw(data, enc, subtype), subtype);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user