@sol-synth-engine/js-client
Version:
JavaScript client for Sol Synth Engine
55 lines (54 loc) • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransactionBuilder = void 0;
const web3_js_1 = require("@solana/web3.js");
class TransactionBuilder {
constructor() {
this.instructions = [];
this.signers = [];
}
addInstructions(...instructions) {
this.instructions.push(...instructions);
return this;
}
addSigners(...signers) {
this.signers.push(...signers);
return this;
}
build(options) {
const transaction = new web3_js_1.Transaction();
transaction.feePayer = options.feePayer;
transaction.recentBlockhash = options.recentBlockhash;
transaction.instructions = this.instructions;
for (const signer of this.signers) {
if (signer.publicKey.equals(options.feePayer)) {
transaction.sign(signer);
}
else {
transaction.partialSign(signer);
}
}
return transaction;
}
buildVersioned(options) {
const message = new web3_js_1.TransactionMessage({
payerKey: options.feePayer,
recentBlockhash: options.recentBlockhash,
instructions: this.instructions,
}).compileToV0Message();
let versionedTransaction = new web3_js_1.VersionedTransaction(message);
versionedTransaction.sign(this.signers);
return versionedTransaction;
}
getInstructions() {
return this.instructions;
}
getSigners() {
return this.signers;
}
clear() {
this.instructions = [];
this.signers = [];
}
}
exports.TransactionBuilder = TransactionBuilder;