@helium/http
Version:
HTTP library for interacting with the Helium blockchain API
124 lines • 5.4 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccountStats = void 0;
/* eslint-disable max-classes-per-file */
const currency_1 = require("@helium/currency");
const address_1 = __importStar(require("@helium/address"));
const Transactions_1 = __importDefault(require("../resources/Transactions"));
const Roles_1 = __importDefault(require("../resources/Roles"));
const PendingTransactions_1 = __importDefault(require("../resources/PendingTransactions"));
const Hotspots_1 = __importDefault(require("../resources/Hotspots"));
const Challenges_1 = __importDefault(require("../resources/Challenges"));
const DataModel_1 = __importDefault(require("./DataModel"));
const Rewards_1 = __importDefault(require("../resources/Rewards"));
const Validators_1 = __importDefault(require("../resources/Validators"));
function toBalance(value, type) {
if (value === undefined)
return undefined;
return new currency_1.Balance(value, type);
}
class AccountStats {
constructor(data) {
this.lastWeek = data.last_week.map((s) => ({
timestamp: s.timestamp,
balance: toBalance(s.balance, currency_1.CurrencyType.default),
}));
this.lastMonth = data.last_month.map((s) => ({
timestamp: s.timestamp,
balance: toBalance(s.balance, currency_1.CurrencyType.default),
}));
this.lastDay = data.last_day.map((s) => ({
timestamp: s.timestamp,
balance: toBalance(s.balance, currency_1.CurrencyType.default),
}));
}
}
exports.AccountStats = AccountStats;
class Account extends DataModel_1.default {
constructor(client, account) {
super();
this.client = client;
this.netType = address_1.default.fromB58(account.address).netType;
const currencyType = this.netType === address_1.NetTypes.TESTNET ? currency_1.CurrencyType.testNetworkToken : currency_1.CurrencyType.default;
this.speculativeNonce = account.speculative_nonce;
this.stakedBalance = toBalance(account.staked_balance, currencyType);
this.secNonce = account.sec_nonce;
this.secBalance = toBalance(account.sec_balance, currency_1.CurrencyType.security);
this.nonce = account.nonce;
this.dcNonce = account.dc_nonce;
this.dcBalance = toBalance(account.dc_balance, currency_1.CurrencyType.dataCredit);
this.block = account.block;
this.balance = toBalance(account.balance, currencyType);
this.mobileBalance = toBalance(account.mobile_balance, currency_1.CurrencyType.mobile);
this.iotBalance = toBalance(account.iot_balance, currency_1.CurrencyType.iot);
this.address = account.address;
this.hotspotCount = account.hotspot_count;
this.validatorCount = account.validator_count;
}
get activity() {
return new Transactions_1.default(this.client, this);
}
get roles() {
return new Roles_1.default(this.client, this);
}
get hotspots() {
return new Hotspots_1.default(this.client, this);
}
get validators() {
return new Validators_1.default(this.client, this);
}
get challenges() {
return new Challenges_1.default(this.client, this);
}
get pendingTransactions() {
return new PendingTransactions_1.default(this.client, this);
}
get rewards() {
return new Rewards_1.default(this.client, this);
}
get data() {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _a = this, { client } = _a, rest = __rest(_a, ["client"]);
// @ts-ignore
return Object.assign({}, rest);
}
}
exports.default = Account;
//# sourceMappingURL=Account.js.map