@btc-vision/transaction
Version:
OPNet transaction library allows you to create and sign transactions for the OPNet network.
29 lines (28 loc) • 1.01 kB
JavaScript
import bitcoin from '@btc-vision/bitcoin';
import { MineableReward } from '../../generators/builders/MineableReward.js';
export class ChallengeGenerator {
static generateMineableReward(preimage1, network) {
const mineableReward = new MineableReward(Buffer.alloc(0), network);
const redeemScript = mineableReward.compile(preimage1);
const p2sh = bitcoin.payments.p2sh({
redeem: { output: redeemScript },
network,
});
const outputRedeem = p2sh.redeem?.output;
if (!outputRedeem) {
throw new Error('Output redeem is required');
}
if (!p2sh.address) {
throw new Error('P2SH address is required');
}
const p2shOutputScript = p2sh?.redeem?.output;
if (!p2shOutputScript) {
throw new Error('No redeem output');
}
return {
address: p2sh.address,
p2shOutputScript,
redeemScript: redeemScript,
};
}
}