block: rename "abbr" methods to "head".
This commit is contained in:
parent
23397dd753
commit
7ed36ec2ba
@ -1027,7 +1027,7 @@ RPC.prototype._submitWork = async function _submitWork(data) {
|
||||
if (data.length !== 128)
|
||||
throw new RPCError(errs.INVALID_PARAMETER, 'Invalid work size.');
|
||||
|
||||
header = Headers.fromAbbr(data);
|
||||
header = Headers.fromHead(data);
|
||||
|
||||
data = data.slice(0, 80);
|
||||
data = swap32(data);
|
||||
|
||||
@ -257,7 +257,7 @@ CompactBlock.prototype.getSize = function getSize(witness) {
|
||||
*/
|
||||
|
||||
CompactBlock.prototype.writeRaw = function writeRaw(bw, witness) {
|
||||
this.writeAbbr(bw);
|
||||
this.writeHead(bw);
|
||||
|
||||
bw.writeBytes(this.keyNonce);
|
||||
|
||||
@ -397,7 +397,7 @@ CompactBlock.prototype.hasIndex = function hasIndex(index) {
|
||||
*/
|
||||
|
||||
CompactBlock.prototype.getKey = function getKey() {
|
||||
let data = Buffer.concat([this.abbr(), this.keyNonce]);
|
||||
let data = Buffer.concat([this.toHead(), this.keyNonce]);
|
||||
let hash = digest.sha256(data);
|
||||
return hash.slice(0, 16);
|
||||
};
|
||||
|
||||
@ -155,7 +155,7 @@ AbstractBlock.prototype.hash = function _hash(enc) {
|
||||
let hash = this._hash;
|
||||
|
||||
if (!hash) {
|
||||
hash = digest.hash256(this.abbr());
|
||||
hash = digest.hash256(this.toHead());
|
||||
if (!this.mutable)
|
||||
this._hash = hash;
|
||||
}
|
||||
@ -178,8 +178,8 @@ AbstractBlock.prototype.hash = function _hash(enc) {
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
AbstractBlock.prototype.abbr = function abbr() {
|
||||
return this.writeAbbr(new StaticWriter(80)).render();
|
||||
AbstractBlock.prototype.toHead = function toHead() {
|
||||
return this.writeHead(new StaticWriter(80)).render();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -187,7 +187,7 @@ AbstractBlock.prototype.abbr = function abbr() {
|
||||
* @param {BufferWriter} bw
|
||||
*/
|
||||
|
||||
AbstractBlock.prototype.writeAbbr = function writeAbbr(bw) {
|
||||
AbstractBlock.prototype.writeHead = function writeHead(bw) {
|
||||
bw.writeU32(this.version);
|
||||
bw.writeHash(this.prevBlock);
|
||||
bw.writeHash(this.merkleRoot);
|
||||
@ -202,7 +202,7 @@ AbstractBlock.prototype.writeAbbr = function writeAbbr(bw) {
|
||||
* @param {BufferReader} br
|
||||
*/
|
||||
|
||||
AbstractBlock.prototype.parseAbbr = function parseAbbr(br) {
|
||||
AbstractBlock.prototype.parseHead = function parseHead(br) {
|
||||
this.version = br.readU32();
|
||||
this.prevBlock = br.readHash('hex');
|
||||
this.merkleRoot = br.readHash('hex');
|
||||
|
||||
@ -644,7 +644,7 @@ Block.prototype.fromReader = function fromReader(br) {
|
||||
|
||||
br.start();
|
||||
|
||||
this.parseAbbr(br);
|
||||
this.parseHead(br);
|
||||
|
||||
count = br.readVarint();
|
||||
|
||||
@ -718,14 +718,12 @@ Block.prototype.toMerkle = function toMerkle(filter) {
|
||||
*/
|
||||
|
||||
Block.prototype.writeNormal = function writeNormal(bw) {
|
||||
this.writeAbbr(bw);
|
||||
this.writeHead(bw);
|
||||
|
||||
bw.writeVarint(this.txs.length);
|
||||
|
||||
for (let i = 0; i < this.txs.length; i++) {
|
||||
let tx = this.txs[i];
|
||||
for (let tx of this.txs)
|
||||
tx.toNormalWriter(bw);
|
||||
}
|
||||
|
||||
return bw;
|
||||
};
|
||||
@ -739,14 +737,12 @@ Block.prototype.writeNormal = function writeNormal(bw) {
|
||||
*/
|
||||
|
||||
Block.prototype.writeWitness = function writeWitness(bw) {
|
||||
this.writeAbbr(bw);
|
||||
this.writeHead(bw);
|
||||
|
||||
bw.writeVarint(this.txs.length);
|
||||
|
||||
for (let i = 0; i < this.txs.length; i++) {
|
||||
let tx = this.txs[i];
|
||||
for (let tx of this.txs)
|
||||
tx.toWriter(bw);
|
||||
}
|
||||
|
||||
return bw;
|
||||
};
|
||||
@ -802,10 +798,8 @@ Block.prototype.getNormalSizes = function getNormalSizes() {
|
||||
size += 80;
|
||||
size += encoding.sizeVarint(this.txs.length);
|
||||
|
||||
for (let i = 0; i < this.txs.length; i++) {
|
||||
let tx = this.txs[i];
|
||||
for (let tx of this.txs)
|
||||
size += tx.getBaseSize();
|
||||
}
|
||||
|
||||
return new RawBlock(size, 0);
|
||||
};
|
||||
@ -822,8 +816,7 @@ Block.prototype.getWitnessSizes = function getWitnessSizes() {
|
||||
size += 80;
|
||||
size += encoding.sizeVarint(this.txs.length);
|
||||
|
||||
for (let i = 0; i < this.txs.length; i++) {
|
||||
let tx = this.txs[i];
|
||||
for (let tx of this.txs) {
|
||||
let sizes = tx.getSizes();
|
||||
size += sizes.total;
|
||||
witness += sizes.witness;
|
||||
|
||||
@ -58,7 +58,7 @@ Headers.prototype.getSize = function getSize() {
|
||||
*/
|
||||
|
||||
Headers.prototype.toWriter = function toWriter(bw) {
|
||||
this.writeAbbr(bw);
|
||||
this.writeHead(bw);
|
||||
bw.writeVarint(0);
|
||||
return bw;
|
||||
};
|
||||
@ -80,7 +80,7 @@ Headers.prototype.toRaw = function toRaw() {
|
||||
*/
|
||||
|
||||
Headers.prototype.fromReader = function fromReader(br) {
|
||||
this.parseAbbr(br);
|
||||
this.parseHead(br);
|
||||
br.readVarint();
|
||||
return this;
|
||||
};
|
||||
@ -118,34 +118,15 @@ Headers.fromRaw = function fromRaw(data, enc) {
|
||||
return new Headers().fromRaw(data);
|
||||
};
|
||||
|
||||
/**
|
||||
* Inject properties from buffer reader.
|
||||
* @private
|
||||
* @param {BufferReader} br
|
||||
*/
|
||||
|
||||
Headers.prototype.fromAbbrReader = function fromAbbrReader(br) {
|
||||
return this.parseAbbr(br);
|
||||
};
|
||||
|
||||
/**
|
||||
* Inject properties from serialized data.
|
||||
* TODO: MOVE.
|
||||
* @private
|
||||
* @param {Buffer} data
|
||||
*/
|
||||
|
||||
Headers.prototype.fromAbbr = function fromAbbr(data) {
|
||||
return this.fromAbbrReader(new BufferReader(data));
|
||||
};
|
||||
|
||||
/**
|
||||
* Instantiate headers from buffer reader.
|
||||
* @param {BufferReader} br
|
||||
* @returns {Headers}
|
||||
*/
|
||||
|
||||
Headers.fromAbbrReader = function fromAbbrReader(br) {
|
||||
return new Headers().fromAbbrReader(br);
|
||||
Headers.prototype.fromHead = function fromHead(data) {
|
||||
return this.parseHead(new BufferReader(data));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -155,10 +136,10 @@ Headers.fromAbbrReader = function fromAbbrReader(br) {
|
||||
* @returns {Headers}
|
||||
*/
|
||||
|
||||
Headers.fromAbbr = function fromAbbr(data, enc) {
|
||||
Headers.fromHead = function fromHead(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = Buffer.from(data, enc);
|
||||
return new Headers().fromAbbr(data);
|
||||
return new Headers().fromHead(data);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -291,7 +272,7 @@ Headers.prototype.format = function format(view, height) {
|
||||
Headers.isHeaders = function isHeaders(obj) {
|
||||
return obj
|
||||
&& !obj.txs
|
||||
&& typeof obj.abbr === 'function'
|
||||
&& typeof obj.toHead === 'function'
|
||||
&& typeof obj.toBlock !== 'function';
|
||||
};
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ MemBlock.prototype.memory = true;
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
MemBlock.prototype.abbr = function abbr() {
|
||||
MemBlock.prototype.toHead = function toHead() {
|
||||
return this._raw.slice(0, 80);
|
||||
};
|
||||
|
||||
@ -144,7 +144,7 @@ MemBlock.prototype.parseCoinbaseHeight = function parseCoinbaseHeight() {
|
||||
MemBlock.prototype.fromRaw = function fromRaw(data) {
|
||||
let br = new BufferReader(data, true);
|
||||
|
||||
this.parseAbbr(br);
|
||||
this.parseHead(br);
|
||||
|
||||
this._raw = br.data;
|
||||
|
||||
|
||||
@ -346,7 +346,7 @@ MerkleBlock.prototype.getSize = function getSize() {
|
||||
*/
|
||||
|
||||
MerkleBlock.prototype.toWriter = function toWriter(bw) {
|
||||
this.writeAbbr(bw);
|
||||
this.writeHead(bw);
|
||||
|
||||
bw.writeU32(this.totalTX);
|
||||
|
||||
@ -380,7 +380,7 @@ MerkleBlock.prototype.toRaw = function toRaw() {
|
||||
MerkleBlock.prototype.fromReader = function fromReader(br) {
|
||||
let count;
|
||||
|
||||
this.parseAbbr(br);
|
||||
this.parseHead(br);
|
||||
|
||||
this.totalTX = br.readU32();
|
||||
|
||||
|
||||
@ -314,7 +314,7 @@ function parseEntry(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = Buffer.from(data, 'hex');
|
||||
|
||||
block = Headers.fromAbbr(data);
|
||||
block = Headers.fromHead(data);
|
||||
|
||||
br = new BufferReader(data);
|
||||
br.seek(80);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user