UNPKG

@logsn/arweave

Version:
42 lines 1.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const error_1 = __importDefault(require("./lib/error")); require("arconnect"); class Blocks { api; network; static ENDPOINT = "block/hash/"; constructor(api, network) { this.api = api; this.network = network; } /** * Gets a block by its "indep_hash" */ async get(indepHash) { const response = await this.api.get(`${Blocks.ENDPOINT}${indepHash}`); if (response.status === 200) { return response.data; } else { if (response.status === 404) { throw new error_1.default("BLOCK_NOT_FOUND" /* ArweaveErrorType.BLOCK_NOT_FOUND */); } else { throw new Error(`Error while loading block data: ${response}`); } } } /** * Gets current block data (ie. block with indep_hash = Network.getInfo().current) */ async getCurrent() { const { current } = await this.network.getInfo(); return await this.get(current); } } exports.default = Blocks; //# sourceMappingURL=blocks.js.map