UNPKG

@btc-vision/transaction

Version:

OPNet transaction library allows you to create and sign transactions for the OPNet network.

49 lines (48 loc) 1.53 kB
import { networks, opcodes, script } from '@btc-vision/bitcoin'; import { Generator } from '../Generator.js'; export class MineableReward extends Generator { constructor(senderPubKey, network = networks.bitcoin) { super(senderPubKey, Buffer.alloc(0), network); } compile(preimage1) { let compiledData; if (this.isTestnet()) { compiledData = [ preimage1, opcodes.OP_SHA1, opcodes.OP_SHA1, opcodes.OP_SWAP, opcodes.OP_SHA1, opcodes.OP_SHA1, opcodes.OP_EQUAL, ]; } else { compiledData = [ preimage1, opcodes.OP_SWAP, opcodes.OP_2DUP, opcodes.OP_EQUAL, opcodes.OP_NOT, opcodes.OP_VERIFY, opcodes.OP_SHA1, opcodes.OP_SHA1, opcodes.OP_SWAP, opcodes.OP_SHA1, opcodes.OP_SHA1, opcodes.OP_EQUAL, ]; } const asm = compiledData.flat(); const compiled = script.compile(asm); const decompiled = script.decompile(compiled); if (!decompiled) { throw new Error('Failed to decompile script??'); } return compiled; } isTestnet() { return (this.network.bech32 === networks.testnet.bech32 || this.network.bech32 === networks.regtest.bech32); } }