UNPKG

@helium/http

Version:

HTTP library for interacting with the Helium blockchain API

51 lines 1.85 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const camelcase_keys_1 = __importDefault(require("camelcase-keys")); class Vars { constructor(client) { /** * The chain vars needed for transaction configuration. * @private */ this.TXN_VARS = [ 'txn_fee_multiplier', 'dc_payload_size', 'staking_fee_txn_assert_location_v1', 'staking_fee_txn_add_gateway_v1', ]; this.baseUrl = '/vars'; this.client = client; } /** * Fetches the chain vars required to configure helium-js for blockchain transactions. */ async getTransactionVars() { const { data: { data: vars } } = await this.client.get(this.baseUrl, { keys: this.TXN_VARS.join(',') }); return (0, camelcase_keys_1.default)(vars); } /** * Fetches the specific chain vars passed in keys. If called without keys it will fetch the * transaction vars returned by {@link getTransactionVars}. * @param keys array of chain vars to fetch eg 'poc_v4_prob_no_rssi' */ async get(keys = []) { if (keys.length === 0) { return this.getTransactionVars(); } const { data: { data: vars } } = await this.client.get(this.baseUrl, { keys: keys.join(',') }); return (0, camelcase_keys_1.default)(vars); } /** * WARNING: This will be return over 10 MB of data. * Fetches all chain vars. */ async getAll() { const { data: { data: vars } } = await this.client.get(this.baseUrl); return (0, camelcase_keys_1.default)(vars); } } exports.default = Vars; //# sourceMappingURL=Vars.js.map