|
@@ -30,7 +30,6 @@ const ZERO = new BN(0); |
|
|
* @property {Hash} merkleRoot |
|
|
* @property {Hash} witnessRoot |
|
|
* @property {Hash} treeRoot |
|
|
* @property {Hash} filterRoot |
|
|
* @property {Hash} reservedRoot |
|
|
* @property {Number} time |
|
|
* @property {Number} bits |
|
@@ -55,11 +54,12 @@ class ChainEntry extends bio.Struct { |
|
|
this.merkleRoot = consensus.ZERO_HASH; |
|
|
this.witnessRoot = consensus.ZERO_HASH; |
|
|
this.treeRoot = consensus.ZERO_HASH; |
|
|
this.filterRoot = consensus.ZERO_HASH; |
|
|
this.reservedRoot = consensus.ZERO_HASH; |
|
|
this.time = 0; |
|
|
this.bits = 0; |
|
|
this.nonce = consensus.ZERO_NONCE; |
|
|
this.nonce = 0; |
|
|
this.extraNonce = consensus.ZERO_NONCE; |
|
|
this.mask = consensus.ZERO_HASH; |
|
|
this.height = 0; |
|
|
this.chainwork = ZERO; |
|
|
|
|
@@ -81,11 +81,12 @@ class ChainEntry extends bio.Struct { |
|
|
assert(Buffer.isBuffer(options.merkleRoot)); |
|
|
assert(Buffer.isBuffer(options.witnessRoot)); |
|
|
assert(Buffer.isBuffer(options.treeRoot)); |
|
|
assert(Buffer.isBuffer(options.filterRoot)); |
|
|
assert(Buffer.isBuffer(options.reservedRoot)); |
|
|
assert(util.isU64(options.time)); |
|
|
assert((options.bits >>> 0) === options.bits); |
|
|
assert(Buffer.isBuffer(options.nonce)); |
|
|
assert((options.nonce >>> 0) === options.nonce); |
|
|
assert(Buffer.isBuffer(options.extraNonce)); |
|
|
assert(Buffer.isBuffer(options.mask)); |
|
|
assert((options.height >>> 0) === options.height); |
|
|
assert(!options.chainwork || BN.isBN(options.chainwork)); |
|
|
|
|
@@ -95,11 +96,12 @@ class ChainEntry extends bio.Struct { |
|
|
this.merkleRoot = options.merkleRoot; |
|
|
this.witnessRoot = options.witnessRoot; |
|
|
this.treeRoot = options.treeRoot; |
|
|
this.filterRoot = options.filterRoot; |
|
|
this.reservedRoot = options.reservedRoot; |
|
|
this.time = options.time; |
|
|
this.bits = options.bits; |
|
|
this.nonce = options.nonce; |
|
|
this.extraNonce = options.extraNonce; |
|
|
this.mask = options.mask; |
|
|
|
|
|
this.height = options.height; |
|
|
this.chainwork = options.chainwork || ZERO; |
|
@@ -179,11 +181,12 @@ class ChainEntry extends bio.Struct { |
|
|
this.merkleRoot = block.merkleRoot; |
|
|
this.witnessRoot = block.witnessRoot; |
|
|
this.treeRoot = block.treeRoot; |
|
|
this.filterRoot = block.filterRoot; |
|
|
this.reservedRoot = block.reservedRoot; |
|
|
this.time = block.time; |
|
|
this.bits = block.bits; |
|
|
this.nonce = block.nonce; |
|
|
this.extraNonce = block.extraNonce; |
|
|
this.mask = block.mask; |
|
|
this.height = prev ? prev.height + 1 : 0; |
|
|
this.chainwork = this.getChainwork(prev); |
|
|
return this; |
|
@@ -211,11 +214,12 @@ class ChainEntry extends bio.Struct { |
|
|
bw.writeHash(this.merkleRoot); |
|
|
bw.writeHash(this.witnessRoot); |
|
|
bw.writeHash(this.treeRoot); |
|
|
bw.writeHash(this.filterRoot); |
|
|
bw.writeHash(this.reservedRoot); |
|
|
bw.writeU64(this.time); |
|
|
bw.writeU32(this.bits); |
|
|
bw.writeBytes(this.nonce); |
|
|
bw.writeU32(this.nonce); |
|
|
bw.writeBytes(this.extraNonce); |
|
|
bw.writeBytes(this.mask); |
|
|
bw.writeBytes(this.chainwork.toArrayLike(Buffer, 'be', 32)); |
|
|
return bw; |
|
|
} |
|
@@ -234,11 +238,12 @@ class ChainEntry extends bio.Struct { |
|
|
this.merkleRoot = br.readHash(); |
|
|
this.witnessRoot = br.readHash(); |
|
|
this.treeRoot = br.readHash(); |
|
|
this.filterRoot = br.readHash(); |
|
|
this.reservedRoot = br.readHash(); |
|
|
this.time = br.readU64(); |
|
|
this.bits = br.readU32(); |
|
|
this.nonce = br.readBytes(consensus.NONCE_SIZE); |
|
|
this.nonce = br.readU32(); |
|
|
this.extraNonce = br.readBytes(consensus.NONCE_SIZE); |
|
|
this.mask = br.readBytes(32); |
|
|
this.chainwork = new BN(br.readBytes(32), 'be'); |
|
|
return this; |
|
|
} |
|
@@ -258,11 +263,12 @@ class ChainEntry extends bio.Struct { |
|
|
merkleRoot: this.merkleRoot.toString('hex'), |
|
|
witnessRoot: this.witnessRoot.toString('hex'), |
|
|
treeRoot: this.treeRoot.toString('hex'), |
|
|
filterRoot: this.filterRoot.toString('hex'), |
|
|
reservedRoot: this.reservedRoot.toString('hex'), |
|
|
time: this.time, |
|
|
bits: this.bits, |
|
|
nonce: this.nonce.toString('hex'), |
|
|
nonce: this.nonce, |
|
|
extraNonce: this.extraNonce.toString('hex'), |
|
|
mask: this.mask.toString('hex'), |
|
|
chainwork: this.chainwork.toString('hex', 64) |
|
|
}; |
|
|
} |
|
@@ -279,6 +285,7 @@ class ChainEntry extends bio.Struct { |
|
|
assert((json.version >>> 0) === json.version); |
|
|
assert(util.isU64(json.time)); |
|
|
assert((json.bits >>> 0) === json.bits); |
|
|
assert((json.nonce >>> 0) === json.nonce); |
|
|
|
|
|
const work = util.parseHex(json.chainwork, 32); |
|
|
|
|
@@ -289,11 +296,12 @@ class ChainEntry extends bio.Struct { |
|
|
this.merkleRoot = util.parseHex(json.merkleRoot, 32); |
|
|
this.witnessRoot = util.parseHex(json.witnessRoot, 32); |
|
|
this.treeRoot = util.parseHex(json.treeRoot, 32); |
|
|
this.filterRoot = util.parseHex(json.filterRoot, 32); |
|
|
this.reservedRoot = util.parseHex(json.reservedRoot, 32); |
|
|
this.time = json.time; |
|
|
this.bits = json.bits; |
|
|
this.nonce = util.parseHex(json.nonce, 20); |
|
|
this.nonce = json.nonce; |
|
|
this.extraNonce = util.parseHex(json.extraNonce, consensus.NONCE_SIZE); |
|
|
this.mask = util.parseHex(json.mask, 32); |
|
|
this.chainwork = new BN(work, 'be'); |
|
|
|
|
|
return this; |
|
|
0 comments on commit
5a34dd6