Add weight and ability to get strippedsize
This commit is contained in:
parent
29e319525f
commit
48bf08c0d3
5 changed files with 28 additions and 6 deletions
ts_src
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue