Implement Zcash modifications to block header
This commit is contained in:
parent
bc8e5f4121
commit
8740d9e964
|
@ -27,10 +27,12 @@ var BlockHeader = function BlockHeader(arg) {
|
||||||
this.version = info.version;
|
this.version = info.version;
|
||||||
this.prevHash = info.prevHash;
|
this.prevHash = info.prevHash;
|
||||||
this.merkleRoot = info.merkleRoot;
|
this.merkleRoot = info.merkleRoot;
|
||||||
|
this.reserved = info.reserved;
|
||||||
this.time = info.time;
|
this.time = info.time;
|
||||||
this.timestamp = info.time;
|
this.timestamp = info.time;
|
||||||
this.bits = info.bits;
|
this.bits = info.bits;
|
||||||
this.nonce = info.nonce;
|
this.nonce = info.nonce;
|
||||||
|
this.solution = info.solution;
|
||||||
|
|
||||||
if (info.hash) {
|
if (info.hash) {
|
||||||
$.checkState(
|
$.checkState(
|
||||||
|
@ -69,21 +71,35 @@ BlockHeader._fromObject = function _fromObject(data) {
|
||||||
$.checkArgument(data, 'data is required');
|
$.checkArgument(data, 'data is required');
|
||||||
var prevHash = data.prevHash;
|
var prevHash = data.prevHash;
|
||||||
var merkleRoot = data.merkleRoot;
|
var merkleRoot = data.merkleRoot;
|
||||||
|
var reserved = data.reserved;
|
||||||
|
var nonce = data.nonce;
|
||||||
|
var solution = data.solution;
|
||||||
if (_.isString(data.prevHash)) {
|
if (_.isString(data.prevHash)) {
|
||||||
prevHash = BufferUtil.reverse(new Buffer(data.prevHash, 'hex'));
|
prevHash = BufferUtil.reverse(new Buffer(data.prevHash, 'hex'));
|
||||||
}
|
}
|
||||||
if (_.isString(data.merkleRoot)) {
|
if (_.isString(data.merkleRoot)) {
|
||||||
merkleRoot = BufferUtil.reverse(new Buffer(data.merkleRoot, 'hex'));
|
merkleRoot = BufferUtil.reverse(new Buffer(data.merkleRoot, 'hex'));
|
||||||
}
|
}
|
||||||
|
if (_.isString(data.reserved)) {
|
||||||
|
reserved = BufferUtil.reverse(new Buffer(data.reserved, 'hex'));
|
||||||
|
}
|
||||||
|
if (_.isString(data.nonce)) {
|
||||||
|
nonce = BufferUtil.reverse(new Buffer(data.nonce, 'hex'));
|
||||||
|
}
|
||||||
|
if (_.isString(data.solution)) {
|
||||||
|
solution = new Buffer(data.solution, 'hex');
|
||||||
|
}
|
||||||
var info = {
|
var info = {
|
||||||
hash: data.hash,
|
hash: data.hash,
|
||||||
version: data.version,
|
version: data.version,
|
||||||
prevHash: prevHash,
|
prevHash: prevHash,
|
||||||
merkleRoot: merkleRoot,
|
merkleRoot: merkleRoot,
|
||||||
|
reserved: reserved,
|
||||||
time: data.time,
|
time: data.time,
|
||||||
timestamp: data.time,
|
timestamp: data.time,
|
||||||
bits: data.bits,
|
bits: data.bits,
|
||||||
nonce: data.nonce
|
nonce: nonce,
|
||||||
|
solution: solution
|
||||||
};
|
};
|
||||||
return info;
|
return info;
|
||||||
};
|
};
|
||||||
|
@ -139,9 +155,12 @@ BlockHeader._fromBufferReader = function _fromBufferReader(br) {
|
||||||
info.version = br.readUInt32LE();
|
info.version = br.readUInt32LE();
|
||||||
info.prevHash = br.read(32);
|
info.prevHash = br.read(32);
|
||||||
info.merkleRoot = br.read(32);
|
info.merkleRoot = br.read(32);
|
||||||
|
info.reserved = br.read(32);
|
||||||
info.time = br.readUInt32LE();
|
info.time = br.readUInt32LE();
|
||||||
info.bits = br.readUInt32LE();
|
info.bits = br.readUInt32LE();
|
||||||
info.nonce = br.readUInt32LE();
|
info.nonce = br.read(32);
|
||||||
|
var lenSolution = br.readVarintNum();
|
||||||
|
info.solution = br.read(lenSolution);
|
||||||
return info;
|
return info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -163,9 +182,11 @@ BlockHeader.prototype.toObject = BlockHeader.prototype.toJSON = function toObjec
|
||||||
version: this.version,
|
version: this.version,
|
||||||
prevHash: BufferUtil.reverse(this.prevHash).toString('hex'),
|
prevHash: BufferUtil.reverse(this.prevHash).toString('hex'),
|
||||||
merkleRoot: BufferUtil.reverse(this.merkleRoot).toString('hex'),
|
merkleRoot: BufferUtil.reverse(this.merkleRoot).toString('hex'),
|
||||||
|
reserved: BufferUtil.reverse(this.reserved).toString('hex'),
|
||||||
time: this.time,
|
time: this.time,
|
||||||
bits: this.bits,
|
bits: this.bits,
|
||||||
nonce: this.nonce
|
nonce: BufferUtil.reverse(this.nonce).toString('hex'),
|
||||||
|
solution: this.solution.toString('hex')
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -194,9 +215,12 @@ BlockHeader.prototype.toBufferWriter = function toBufferWriter(bw) {
|
||||||
bw.writeUInt32LE(this.version);
|
bw.writeUInt32LE(this.version);
|
||||||
bw.write(this.prevHash);
|
bw.write(this.prevHash);
|
||||||
bw.write(this.merkleRoot);
|
bw.write(this.merkleRoot);
|
||||||
|
bw.write(this.reserved);
|
||||||
bw.writeUInt32LE(this.time);
|
bw.writeUInt32LE(this.time);
|
||||||
bw.writeUInt32LE(this.bits);
|
bw.writeUInt32LE(this.bits);
|
||||||
bw.writeUInt32LE(this.nonce);
|
bw.write(this.nonce);
|
||||||
|
bw.writeVarintNum(this.solution.length);
|
||||||
|
bw.write(this.solution);
|
||||||
return bw;
|
return bw;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue