@helium/http
Version:
HTTP library for interacting with the Helium blockchain API
65 lines • 2.85 kB
JavaScript
;
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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const snakecase_keys_1 = __importDefault(require("snakecase-keys"));
const Account_1 = __importStar(require("../models/Account"));
const ResourceList_1 = __importDefault(require("../ResourceList"));
class Accounts {
constructor(client) {
this.client = client;
}
fromAddress(address) {
return new Account_1.default(this.client, { address });
}
async list(params = {}) {
const url = '/accounts';
const response = await this.client.get(url, { cursor: params.cursor });
const { data: { data: accounts, cursor } } = response;
const data = accounts.map((d) => new Account_1.default(this.client, d));
return new ResourceList_1.default(data, this.list.bind(this), cursor);
}
async listRich() {
const url = '/accounts/rich';
const response = await this.client.get(url);
const { data: { data: accounts }, } = response;
const data = accounts.map((d) => new Account_1.default(this.client, d));
return new ResourceList_1.default(data, this.list.bind(this));
}
async get(address, params) {
const path = `/accounts/${address}`;
const { data: { data: account }, } = await this.client.get(path, (0, snakecase_keys_1.default)(params || {}));
return new Account_1.default(this.client, account);
}
async getStats(address) {
const url = `/accounts/${address}/stats`;
const { data: { data: stats } } = await this.client.get(url);
return new Account_1.AccountStats(stats);
}
}
exports.default = Accounts;
//# sourceMappingURL=Accounts.js.map