Add weight and ability to get strippedsize

This commit is contained in:
junderw 2019-11-29 15:30:23 +09:00
parent 29e319525f
commit 48bf08c0d3
No known key found for this signature in database
GPG key ID: B256185D3A971908
5 changed files with 28 additions and 6 deletions
ts_src

View file

@ -148,13 +148,20 @@ export class Block {
return anyTxHasWitness(this.transactions!);
}
byteLength(headersOnly?: boolean): number {
weight(): number {
const base = this.byteLength(false, false);
const total = this.byteLength(false, true);
return base * 3 + total;
}
byteLength(headersOnly?: boolean, allowWitness: boolean = true): number {
if (headersOnly || !this.transactions) return 80;
return (
80 +
varuint.encodingLength(this.transactions.length) +
this.transactions.reduce((a, x) => a + x.byteLength(), 0)
// @ts-ignore using the __byteLength private method on Transaction
this.transactions.reduce((a, x) => a + x.__byteLength(allowWitness), 0)
);
}