UNPKG

avail-js-sdk

Version:

Avail library of functions to interact with blockchain and manipulate transactions

83 lines (82 loc) 3.21 kB
"use strict"; 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.Client = void 0; const metadata_1 = require("./metadata"); const rpc_1 = require("./rpc"); class Client { constructor(api) { this.api = api; } storageAt(at) { return __awaiter(this, void 0, void 0, function* () { if (at == undefined) { return this.api.query; } return (yield this.api.at(at.toString())).query; }); } headerAt(at) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.rpc.chain.getHeader(at.toString()); }); } rpcBlockAt(at) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.rpc.chain.getBlock(at.toString()); }); } finalizedBlockHash() { return __awaiter(this, void 0, void 0, function* () { return new metadata_1.H256(yield this.api.rpc.chain.getFinalizedHead()); }); } bestBlockHash() { return __awaiter(this, void 0, void 0, function* () { return new metadata_1.H256(yield this.api.rpc.chain.getBlockHash()); }); } blockHash(at) { return __awaiter(this, void 0, void 0, function* () { return new metadata_1.H256(yield this.api.rpc.chain.getBlockHash(at)); }); } finalizedBlockNumber() { return __awaiter(this, void 0, void 0, function* () { const header = yield this.headerAt(yield this.finalizedBlockHash()); return header.number.toNumber(); }); } bestBlockNumber() { return __awaiter(this, void 0, void 0, function* () { const header = yield this.headerAt(yield this.bestBlockHash()); return header.number.toNumber(); }); } blockNumber(at) { return __awaiter(this, void 0, void 0, function* () { const header = yield this.headerAt(at); return header.number.toNumber(); }); } rotateKeys() { return __awaiter(this, void 0, void 0, function* () { const keysBytes = yield this.api.rpc.author.rotateKeys(); return metadata_1.SessionKeys.fromHex(keysBytes.toString()); }); } transactionState(txHash, finalized) { return __awaiter(this, void 0, void 0, function* () { return yield (0, rpc_1.transactionState)(this, txHash.toString(), finalized); }); } } exports.Client = Client;