@btc-vision/transaction
Version:
OPNet transaction library allows you to create and sign transactions for the OPNet network.
31 lines (30 loc) • 1.33 kB
JavaScript
import { TransactionType } from '../enums/TransactionType.js';
import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
import { Features } from '../../generators/Features.js';
export class InteractionTransaction extends SharedInteractionTransaction {
constructor(parameters) {
super(parameters);
this.type = TransactionType.INTERACTION;
this.tapLeafScript = null;
if (!parameters.contract) {
throw new Error('parameters.contract is required for interaction transaction.');
}
this.contractSecret = Buffer.from(parameters.contract.replace('0x', ''), 'hex');
if (this.contractSecret.length !== 32) {
throw new Error('Invalid contract secret length. Expected 32 bytes.');
}
this.compiledTargetScript = this.calldataGenerator.compile(this.calldata, this.contractSecret, this.preimage, this.priorityFee, this.generateFeatures(parameters));
this.scriptTree = this.getScriptTree();
this.internalInit();
}
generateFeatures(parameters) {
const features = [];
if (parameters.loadedStorage) {
features.push({
opcode: Features.ACCESS_LIST,
data: parameters.loadedStorage,
});
}
return features;
}
}