UNPKG

@muirglacier/jellyfish-block

Version:

A collection of TypeScript + JavaScript tools and libraries for DeFi Blockchain developers to build decentralized finance for Bitcoin

39 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CBlock = void 0; const blockHeader_1 = require("./blockHeader"); const jellyfish_buffer_1 = require("@muirglacier/jellyfish-buffer"); const jellyfish_transaction_1 = require("@muirglacier/jellyfish-transaction"); const smart_buffer_1 = require("smart-buffer"); /** * Composable Block, C stands for Composable. * Immutable by design, bi-directional fromBuffer, toBuffer deep composer. */ class CBlock extends jellyfish_buffer_1.ComposableBuffer { composers(block) { return [ jellyfish_buffer_1.ComposableBuffer.single(() => block.blockHeader, v => block.blockHeader = v, v => new blockHeader_1.CBlockHeader(v)), jellyfish_buffer_1.ComposableBuffer.varUIntArray(() => block.transactions, v => block.transactions = v, v => { /** * Has to read the marker from buffer in order to determine wether it is a Transaction or TransactionSegWit. */ if (v instanceof smart_buffer_1.SmartBuffer) { const readOffset = v.readOffset; // Keep current offset in order to reset to this point once marker is read. v.readUInt32LE(); // Read 4 bytes from version and discard it. const marker = v.readUInt8(); v.readOffset = readOffset; if (marker > 0x00) { return new jellyfish_transaction_1.CTransaction(v); } return new jellyfish_transaction_1.CTransactionSegWit(v); } if (v.marker === 0x00) { return new jellyfish_transaction_1.CTransactionSegWit(v); } return new jellyfish_transaction_1.CTransaction(v); }) ]; } } exports.CBlock = CBlock; //# sourceMappingURL=block.js.map