UNPKG

solmash-whitelist-sdk

Version:

A sdk for interacting Solmash Whitelist program

55 lines 2.53 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SolmashWhitelistPayload = void 0; const assert_1 = __importDefault(require("assert")); const anchor_1 = require("@project-serum/anchor"); class SolmashWhitelistPayload { constructor(_connection, _signTransaction, _errors, transaction, signers) { this._connection = _connection; this._signTransaction = _signTransaction; this._errors = _errors; this.transaction = transaction; this.signers = signers; } async execute(options) { (0, assert_1.default)(this.transaction.recentBlockhash, "Blockhash is missing in transaction!"); (0, assert_1.default)(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 = await this._signTransaction(this.transaction); try { const signature = await this._connection.sendRawTransaction(signed.serialize(), options); console.debug("signatue: %s", signature); const response = await this._connection.confirmTransaction({ signature, blockhash, lastValidBlockHeight, }, options?.commitment); 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("translatedError:", translatedError); throw new Error("Unknown error occured. Please try again."); } throw translatedError; } console.debug("Throwing error as it is."); throw err; } } } exports.SolmashWhitelistPayload = SolmashWhitelistPayload; //# sourceMappingURL=payload.js.map