opnet
Version:
The perfect library for building Bitcoin-based applications.
74 lines (73 loc) • 2.19 kB
JavaScript
import { Address } from '@btc-vision/transaction';
import { TransactionParser } from '../transactions/TransactionParser.js';
export class Block {
height;
hash;
previousBlockHash;
previousBlockChecksum;
bits;
nonce;
version;
size;
txCount;
weight;
strippedSize;
time;
medianTime;
checksumRoot;
merkleRoot;
storageRoot;
receiptRoot;
ema;
baseGas;
gasUsed;
checksumProofs;
_rawBlock;
_network;
constructor(block, network) {
if (!block)
throw new Error('Invalid block.');
this._rawBlock = block;
this._network = network;
this.height = BigInt(block.height.toString());
this.hash = block.hash;
this.previousBlockHash = block.previousBlockHash;
this.previousBlockChecksum = block.previousBlockChecksum;
this.bits = block.bits;
this.nonce = block.nonce;
this.version = block.version;
this.size = block.size;
this.txCount = block.txCount;
this.ema = BigInt(block.ema);
this.baseGas = BigInt(block.baseGas);
this.gasUsed = BigInt(block.gasUsed);
this.weight = block.weight;
this.strippedSize = block.strippedSize;
this.time = block.time;
this.medianTime = block.medianTime;
this.checksumRoot = block.checksumRoot;
this.merkleRoot = block.merkleRoot;
this.storageRoot = block.storageRoot;
this.receiptRoot = block.receiptRoot;
this.checksumProofs = block.checksumProofs;
}
_transactions;
get transactions() {
if (!this._transactions) {
this._transactions = TransactionParser.parseTransactions(this._rawBlock.transactions, this._network);
}
return this._transactions;
}
_deployments;
get deployments() {
if (!this._deployments) {
this._deployments = this._rawBlock.deployments
? this._rawBlock.deployments.map((address) => Address.fromString(address))
: [];
}
return this._deployments;
}
get rawTransactions() {
return this._rawBlock.transactions;
}
}