UNPKG

@helium/http

Version:

HTTP library for interacting with the Helium blockchain API

48 lines 2.07 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Account_1 = __importDefault(require("../models/Account")); const ResourceList_1 = __importDefault(require("../ResourceList")); const Hotspot_1 = __importDefault(require("../models/Hotspot")); const Validator_1 = __importDefault(require("../models/Validator")); class Roles { constructor(client, context) { this.client = client; this.context = context; } async list(params = {}) { var _a, _b; const { data: { data: roles, cursor }, } = await this.client.get(this.activityUrl, { cursor: params.cursor, filter_types: params.filterTypes ? params.filterTypes.join() : undefined, min_time: params.minTime instanceof Date ? (_a = params.minTime) === null || _a === void 0 ? void 0 : _a.toISOString() : params.minTime, max_time: params.maxTime instanceof Date ? (_b = params.maxTime) === null || _b === void 0 ? void 0 : _b.toISOString() : params.maxTime, limit: params.limit, }); const data = roles.map((d) => d); return new ResourceList_1.default(data, this.list.bind(this), cursor); } get activityUrl() { let url; if (this.context instanceof Account_1.default) { const account = this.context; url = `/accounts/${account.address}/roles`; } else if (this.context instanceof Hotspot_1.default) { const hotspot = this.context; url = `/hotspots/${hotspot.address}/roles`; } else if (this.context instanceof Validator_1.default) { const validator = this.context; url = `/validators/${validator.address}/roles`; } else { throw new Error('Must provide a context to list roles from'); } return url; } } exports.default = Roles; //# sourceMappingURL=Roles.js.map