multipool-staking-sdk
Version:
This is an sdk for solmask staking pool program
63 lines • 3.29 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransactionPayload = void 0;
const anchor_1 = require("@project-serum/anchor");
const utils_1 = require("./utils");
class TransactionPayload {
constructor(_connection, _signTransaction, _errors, transaction, signers) {
this._connection = _connection;
this._signTransaction = _signTransaction;
this._errors = _errors;
this.transaction = transaction;
this.signers = signers;
}
execute(options) {
return __awaiter(this, void 0, void 0, function* () {
(0, utils_1.assert)(this.transaction.recentBlockhash, "Blockhash is missing in transaction!");
(0, utils_1.assert)(this.transaction.lastValidBlockHeight, "LastValidBlockHeight is missing in transaction!");
const blockhash = this.transaction.recentBlockhash;
const lastValidBlockHeight = this.transaction.lastValidBlockHeight;
if (this.signers.length > 0) {
this.transaction.partialSign(...this.signers);
}
const signed = yield this._signTransaction(this.transaction);
try {
const signature = yield this._connection.sendRawTransaction(signed.serialize(), options);
console.debug("signatue: %s", signature);
const response = yield this._connection.confirmTransaction({
signature,
blockhash,
lastValidBlockHeight,
}, options === null || options === void 0 ? void 0 : options.confirmCommitment);
if (response.value.err) {
throw new Error("Failed to confirm transaction: " + response.value.err.toString());
}
return signature;
}
catch (err) {
const translatedError = (0, anchor_1.translateError)(err, this._errors);
if (translatedError) {
// assert(translatedError instanceof Error, "Translated error is not instanceof Error.");
if (!(translatedError instanceof Error)) {
console.log("translated error:", translatedError);
throw new Error("Some thing went wrong. Please try again");
}
throw translatedError;
}
console.log("Throwing error as it is.");
throw err;
}
});
}
}
exports.TransactionPayload = TransactionPayload;
//# sourceMappingURL=payload.js.map