UNPKG

chaingate

Version:

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

42 lines 1.97 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, client, api, currencyProviders, networkParams) { super(currencyInfo, client, currencyProviders); this.networkParams = networkParams; this.api = api; } 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), this.client), unconfirmed: new CurrencyAmount_1.CurrencyAmount(this.currencyInfo, new decimal_js_1.default(balance.unconfirmed), this.client), }; } async amount(amountStr, unit) { try { switch (unit) { default: return new CurrencyAmount_1.CurrencyAmount(this.currencyInfo, new decimal_js_1.default(amountStr), this.client); case 'satoshi': return new CurrencyAmount_1.CurrencyAmount(this.currencyInfo, new decimal_js_1.default(amountStr).div(100_000_000), this.client); } } 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