UNPKG

@coral-xyz/barter-sdk

Version:
104 lines 5.38 kB
"use strict"; /* * Copyright (C) 2023 Blue Coral, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ 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()); }); }; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _Barter_program, _Barter_provider; Object.defineProperty(exports, "__esModule", { value: true }); exports.Barter = void 0; const anchor_1 = require("@coral-xyz/anchor"); const barter_1 = require("./barter"); const instructions_1 = require("./instructions"); const idlErrors = (0, anchor_1.parseIdlErrors)(barter_1.IDL); class Barter { constructor(provider) { _Barter_program.set(this, void 0); _Barter_provider.set(this, void 0); if (!provider.publicKey) { throw new Error("no public key found on the argued provider"); } else if (!provider.sendAndConfirm) { throw new Error("no sendAndConfirm function found on the argued provider"); } __classPrivateFieldSet(this, _Barter_program, new anchor_1.Program(barter_1.IDL, instructions_1.PROGRAM_ID, provider), "f"); __classPrivateFieldSet(this, _Barter_provider, provider, "f"); } static fromKeypair(keypair, connection) { return new Barter(new anchor_1.AnchorProvider(connection, new anchor_1.Wallet(keypair), {})); } get program() { return __classPrivateFieldGet(this, _Barter_program, "f"); } get provider() { return __classPrivateFieldGet(this, _Barter_provider, "f"); } cancel(opts) { return __awaiter(this, void 0, void 0, function* () { const tx = yield (0, instructions_1.createCancelTransaction)(__classPrivateFieldGet(this, _Barter_program, "f"), opts); return this._withParsedTransactionError(tx); }); } create(opts) { return __awaiter(this, void 0, void 0, function* () { const tx = yield (0, instructions_1.createCreateTransaction)(__classPrivateFieldGet(this, _Barter_program, "f"), opts); return this._withParsedTransactionError(tx); }); } finalize(opts) { return __awaiter(this, void 0, void 0, function* () { const tx = yield (0, instructions_1.createFinalizeTransaction)(__classPrivateFieldGet(this, _Barter_program, "f"), opts); return this._withParsedTransactionError(tx); }); } settle(opts) { return __awaiter(this, void 0, void 0, function* () { const tx = yield (0, instructions_1.createSettleTransaction)(__classPrivateFieldGet(this, _Barter_program, "f"), opts); return this._withParsedTransactionError(tx); }); } _withParsedTransactionError(tx) { return __awaiter(this, void 0, void 0, function* () { try { return yield __classPrivateFieldGet(this, _Barter_provider, "f").sendAndConfirm(tx); } catch (err) { throw (0, anchor_1.translateError)(err, idlErrors); } }); } } exports.Barter = Barter; _Barter_program = new WeakMap(), _Barter_provider = new WeakMap(); //# sourceMappingURL=client.js.map