@helium/http
Version:
HTTP library for interacting with the Helium blockchain API
39 lines • 1.74 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const OraclePrice_1 = __importDefault(require("../models/OraclePrice"));
const OraclePricePrediction_1 = __importDefault(require("../models/OraclePricePrediction"));
const ResourceList_1 = __importDefault(require("../ResourceList"));
class Oracle {
constructor(client) {
this.client = client;
}
async getCurrentPrice() {
const url = '/oracle/prices/current';
const { data: { data }, } = await this.client.get(url);
return new OraclePrice_1.default(this.client, data);
}
async listPrices(params = {}) {
const { data: { data: prices, cursor }, } = await this.client.get('/oracle/prices', { cursor: params.cursor });
const data = prices.map((d) => new OraclePrice_1.default(this.client, d));
return new ResourceList_1.default(data, this.listPrices.bind(this), cursor);
}
async getPriceAtBlock(height) {
const url = `/oracle/prices/${height}`;
const { data: { data }, } = await this.client.get(url);
return new OraclePrice_1.default(this.client, data);
}
async getPredictedPrice() {
const url = '/oracle/predictions';
const response = await this.client.get(url);
if (!response.data.data || !response.data.data.length) {
return [];
}
const { data: { data: predictions }, } = response;
return predictions.map((prediction) => new OraclePricePrediction_1.default(this.client, prediction));
}
}
exports.default = Oracle;
//# sourceMappingURL=Oracle.js.map