@helium/http
Version:
HTTP library for interacting with the Helium blockchain API
67 lines • 2.88 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 Challenge_1 = __importDefault(require("../models/Challenge"));
const ResourceList_1 = __importDefault(require("../ResourceList"));
const Account_1 = __importDefault(require("../models/Account"));
const Hotspot_1 = __importDefault(require("../models/Hotspot"));
const Sums_1 = __importStar(require("./Sums"));
class Challenges {
constructor(client, context) {
this.client = client;
this.context = context;
}
async list(params = {}) {
let url = '/challenges';
if (this.context instanceof Account_1.default) {
const account = this.context;
url = `/accounts/${account.address}/challenges`;
}
else if (this.context instanceof Hotspot_1.default) {
const hotspot = this.context;
url = `/hotspots/${hotspot.address}/challenges`;
}
const response = await this.client.get(url, { cursor: params.cursor });
const { data: { data: challenges, cursor } } = response;
const data = challenges.map((d) => new Challenge_1.default(d));
return new ResourceList_1.default(data, this.list.bind(this), cursor);
}
async get(hash) {
const url = `/challenges/${hash}`;
const { data: { data: challenge } } = await this.client.get(url);
return new Challenge_1.default(challenge);
}
get sum() {
if (this.context instanceof Hotspot_1.default) {
return new Sums_1.default(this.client, Sums_1.SumsType.challenges, this.context);
}
throw new Error('invalid context');
}
}
exports.default = Challenges;
//# sourceMappingURL=Challenges.js.map