UNPKG

chaingate

Version:

A complete TypeScript library for connecting to and making transactions on different blockchains

41 lines 1.88 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Utxo = void 0; const decimal_js_1 = __importDefault(require("decimal.js")); const CGDriver_1 = require("../../../../../CGDriver"); const Currency_1 = require("../../Currency"); const CurrencyAmount_1 = require("../../CurrencyAmount"); const errors_1 = require("../../errors"); class Utxo extends Currency_1.Currency { networkParams; constructor(currencyInfo, api, currencyProviders, networkParams) { super(currencyInfo, api, currencyProviders); this.networkParams = networkParams; } async getBalance(address) { const balance = await (0, CGDriver_1.ConsumeFunction)(this.api, this.api.addressBalance, address ?? await this.getAddress()); return { confirmed: new CurrencyAmount_1.CurrencyAmount(this.currencyInfo, new decimal_js_1.default(balance.confirmed)), unconfirmed: new CurrencyAmount_1.CurrencyAmount(this.currencyInfo, new decimal_js_1.default(balance.unconfirmed)) }; } async amount(amountStr, unit) { try { switch (unit) { default: return new CurrencyAmount_1.CurrencyAmount(this.currencyInfo, new decimal_js_1.default(amountStr)); case 'satoshi': return new CurrencyAmount_1.CurrencyAmount(this.currencyInfo, new decimal_js_1.default(amountStr).div(100_000_000)); } } catch (_ex) { throw new errors_1.CannotParseAmount(amountStr); } } async addressHistory(page) { return (await (0, CGDriver_1.ConsumeFunction)(this.api, this.api.addressHistory, this.getAddress(), page)).transactions; } } exports.Utxo = Utxo; //# sourceMappingURL=Utxo.js.map