UNPKG

@muirglacier/jellyfish-transaction-builder

Version:

A collection of TypeScript + JavaScript tools and libraries for DeFi Blockchain developers to build decentralized finance for Bitcoin

87 lines 4.66 kB
"use strict"; 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.TxnBuilderOracles = void 0; const jellyfish_transaction_1 = require("@muirglacier/jellyfish-transaction"); const txn_builder_1 = require("./txn_builder"); const txn_builder_error_1 = require("./txn_builder_error"); class TxnBuilderOracles extends txn_builder_1.P2WPKHTxnBuilder { /** * Appoints an oracle. Currently requires Foundation Authorization. * * @param {AppointOracle} appointOracle txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @throws {TxnBuilderError} if 'appointOracle.weightage' is below `1` or over `100` * @returns {Promise<TransactionSegWit>} */ appointOracle(appointOracle, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { if (appointOracle.weightage < 1 || appointOracle.weightage > 100) { throw new txn_builder_error_1.TxnBuilderError(txn_builder_error_1.TxnBuilderErrorType.INVALID_APPOINT_ORACLE_INPUT, 'Conversion input `appointOracle.weightage` must be above `0` and below `101`'); } return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_APPOINT_ORACLE(appointOracle), changeScript); }); } /** * Removes an oracle. Currently requires Foundation Authorization. * * @param {RemoveOracle} removeOracle txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ removeOracle(removeOracle, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_REMOVE_ORACLE(removeOracle), changeScript); }); } /** * Updates an oracle. Currently requires Foundation Authorization. * * @param {UpdateOracle} updateOracle txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @throws {TxnBuilderError} if 'updateOracle.weightage' is below `1` or over `100` * @returns {Promise<TransactionSegWit>} */ updateOracle(updateOracle, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { if (updateOracle.weightage < 1 || updateOracle.weightage > 100) { throw new txn_builder_error_1.TxnBuilderError(txn_builder_error_1.TxnBuilderErrorType.INVALID_UPDATE_ORACLE_INPUT, 'Conversion input `updateOracle.weightage` must be above `0` and below `101`'); } return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_UPDATE_ORACLE(updateOracle), changeScript); }); } /** * Sets data on an oracle. Currently requires Foundation Authorization. * * @param {SetOracleData} setOracleData txn to create * @param {Script} changeScript to send unspent to after deducting the (converted + fees) * @returns {Promise<TransactionSegWit>} */ setOracleData(setOracleData, changeScript) { const _super = Object.create(null, { createDeFiTx: { get: () => super.createDeFiTx } }); return __awaiter(this, void 0, void 0, function* () { return yield _super.createDeFiTx.call(this, jellyfish_transaction_1.OP_CODES.OP_DEFI_TX_SET_ORACLE_DATA(setOracleData), changeScript); }); } } exports.TxnBuilderOracles = TxnBuilderOracles; //# sourceMappingURL=txn_builder_oracles.js.map