@celo/network-utils
Version:
Utilities for fetching static information about the Celo network
39 lines • 2.03 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenesisBlockUtils = exports.GenesisBlocksGoogleStorageBucketName = void 0;
const google_storage_utils_1 = require("./google-storage-utils");
const TAG = 'genesis-block-utils';
exports.GenesisBlocksGoogleStorageBucketName = 'genesis_blocks';
class GenesisBlockUtils {
/**
* Fetches the genesis block (as JSON data) from Google Storage.
* If the network is not working, the method will reject the returned promise
* along with the response data from Google api.
* @param networkName Name of the network to fetch genesis block for
*/
static getGenesisBlockAsync(networkName) {
return __awaiter(this, void 0, void 0, function* () {
console.debug(`${TAG} getGenesisBlockAsync("${networkName}") called`);
return google_storage_utils_1.GoogleStorageUtils.fetchFileFromGoogleStorage(exports.GenesisBlocksGoogleStorageBucketName, networkName);
});
}
static getChainIdFromGenesis(genesis) {
try {
return JSON.parse(genesis).config.chainId;
}
catch (error) {
throw new Error(`Error extract config.chainId field from "${genesis}"`);
}
}
}
exports.GenesisBlockUtils = GenesisBlockUtils;
//# sourceMappingURL=genesis-block-utils.js.map