@pokt-network/pocket-js
Version:
Pocket-js core package with the main functionalities to interact with the Pocket Network.
924 lines (923 loc) • 62.5 kB
JavaScript
"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());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.QueryNamespace = void 0;
var __1 = require("../..");
var __2 = require("..");
var challenge_response_1 = require("../models/output/challenge-response");
var query_account_txs_response_1 = require("../models/output/query-account-txs-response");
var jailed_status_1 = require("../models/jailed-status");
var models_1 = require("../models");
var query_block_txs_response_1 = require("../models/output/query-block-txs-response");
var query_node_claim_response_1 = require("../models/output/query-node-claim-response");
var query_node_claims_response_1 = require("../models/output/query-node-claims-response");
var QueryNamespace = /** @class */ (function () {
/**
* @description Query namespace class
* @param {IRPCProvider} rpcProvider - RPC Provider interface object.
*/
function QueryNamespace(rpcProvider) {
this.rpcProvider = rpcProvider;
}
/**
*
* Query a Block information
* @param {BigInt} blockHeight - Block's number.
* @param {number} timeout - Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getBlock = function (blockHeight, timeout, rejectSelfSignedCertificates) {
if (blockHeight === void 0) { blockHeight = BigInt(0); }
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, queryBlockResponse, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (Number(blockHeight.toString()) < 0) {
return [2 /*return*/, new __2.RpcError("101", "block height can't be lower than 0")];
}
payload = JSON.stringify({ height: Number(blockHeight.toString()) });
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryBlock.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryBlockResponse = __2.QueryBlockResponse.fromJSON(response);
return [2 /*return*/, queryBlockResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the block information: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_1 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_1)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Query a Block transaction list
* @param {BigInt} blockHeight - Block's number.
* @param {boolean} prove - True or false to include the tx proof.
* @param {number} page - Page number, default 1.
* @param {number} perPage - Records count per page, default 30.
* @param {number} timeout - Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getBlockTxs = function (blockHeight, prove, page, perPage, timeout, rejectSelfSignedCertificates) {
if (blockHeight === void 0) { blockHeight = BigInt(0); }
if (prove === void 0) { prove = false; }
if (page === void 0) { page = 1; }
if (perPage === void 0) { perPage = 30; }
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, queryBlockTxsResponse, err_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (Number(blockHeight.toString()) < 0) {
return [2 /*return*/, new __2.RpcError("101", "block height can't be lower than 0")];
}
payload = JSON.stringify({
height: Number(blockHeight.toString()),
prove: prove,
page: page,
per_page: perPage
});
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryBlockTxs.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryBlockTxsResponse = query_block_txs_response_1.QueryBlockTxsResponse.fromJSON(response);
return [2 /*return*/, queryBlockTxsResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the block information: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_2 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_2)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Retrieves a transaction information
* @param {string} txHash - Transaction hash.
* @param {number} timeout - Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getTX = function (txHash, timeout, rejectSelfSignedCertificates) {
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, queryTXResponse, err_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (!__1.Hex.isHex(txHash) && __1.Hex.byteLength(txHash) !== 20) {
return [2 /*return*/, new __2.RpcError("0", "Invalid Address Hex")];
}
payload = JSON.stringify({ hash: txHash });
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryTX.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryTXResponse = __2.QueryTXResponse.fromJSON(response);
return [2 /*return*/, queryTXResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the block information: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_3 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_3)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Get the current network block height
* @param {number} timeout - Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getHeight = function (timeout, rejectSelfSignedCertificates) {
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var response, queryHeightResponse, err_4;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryHeight.toString(), "", timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryHeightResponse = __2.QueryHeightResponse.fromJSON(response);
return [2 /*return*/, queryHeightResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the network block height: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_4 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_4)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Retrieves an account balance
* @param {string} address - Account's address.
* @param {BigInt} blockHeight - Block's number.
* @param {number} timeout - Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getBalance = function (address, blockHeight, timeout, rejectSelfSignedCertificates) {
if (blockHeight === void 0) { blockHeight = BigInt(0); }
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, queryBalanceResponse, err_5;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (Number(blockHeight.toString()) < 0) {
return [2 /*return*/, new __2.RpcError("101", "block height can't be lower than 0")];
}
if (!__1.Hex.isHex(address) && __1.Hex.byteLength(address) !== 20) {
return [2 /*return*/, new __2.RpcError("0", "Invalid Address Hex")];
}
payload = JSON.stringify({ "address": address, "height": Number(blockHeight.toString()) });
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryBalance.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryBalanceResponse = __2.QueryBalanceResponse.fromJSON(response);
return [2 /*return*/, queryBalanceResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve current balance: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_5 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_5)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Retrieves a list of validator nodes
* @param {StakingStatus} stakingStatus - Staking status.
* @param {JailedStatus} jailedStatus - Jailed status.
* @param {BigInt} blockHeight - Block's number.
* @param {string} blockchain - (optional) Blockchain Identifier.
* @param {number} page - (optional) Page number, default 1.
* @param {number} perPage - (optional) Records count per page, default 30.
* @param {number} timeout - (optional) Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getNodes = function (stakingStatus, jailedStatus, blockHeight, blockchain, page, perPage, timeout, rejectSelfSignedCertificates) {
if (stakingStatus === void 0) { stakingStatus = __2.StakingStatus.NA; }
if (jailedStatus === void 0) { jailedStatus = jailed_status_1.JailedStatus.NA; }
if (blockHeight === void 0) { blockHeight = BigInt(0); }
if (blockchain === void 0) { blockchain = ""; }
if (page === void 0) { page = 1; }
if (perPage === void 0) { perPage = 30; }
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, queryNodesResponse, err_6;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (Number(blockHeight.toString()) < 0) {
return [2 /*return*/, new __2.RpcError("101", "block height can't be lower than 0")];
}
payload = JSON.stringify({
height: Number(blockHeight.toString()),
opts: {
staking_status: stakingStatus === "" ? null : stakingStatus,
jailed_status: jailedStatus === "" ? null : jailedStatus,
blockchain: blockchain,
page: page,
per_page: perPage
}
});
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryNodes.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryNodesResponse = models_1.QueryNodesResponse.fromJSON(response);
return [2 /*return*/, queryNodesResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve a list of validator nodes: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_6 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_6)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Query a Node information
* @param {string} address - Node address.
* @param {BigInt} blockHeight - Block's number.
* @param {number} timeout - Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getNode = function (address, blockHeight, timeout, rejectSelfSignedCertificates) {
if (blockHeight === void 0) { blockHeight = BigInt(0); }
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, queryNodeResponse, err_7;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (Number(blockHeight.toString()) < 0) {
return [2 /*return*/, new __2.RpcError("101", "block height can't be lower than 0")];
}
if (!__1.Hex.isHex(address) && __1.Hex.byteLength(address) !== 20) {
return [2 /*return*/, new __2.RpcError("0", "Invalid Address Hex")];
}
payload = JSON.stringify({
address: address,
height: Number(blockHeight.toString())
});
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryNode.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryNodeResponse = __2.QueryNodeResponse.fromJSON(response);
return [2 /*return*/, queryNodeResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the node information: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_7 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_7)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Retrieves the node params
* @param {BigInt} blockHeight - Block's number.
* @param {number} timeout - Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getNodeParams = function (blockHeight, timeout, rejectSelfSignedCertificates) {
if (blockHeight === void 0) { blockHeight = BigInt(0); }
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, queryNodeParamsResponse, err_8;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (Number(blockHeight.toString()) < 0) {
return [2 /*return*/, new __2.RpcError("101", "block height can't be lower than 0")];
}
payload = JSON.stringify({ height: Number(blockHeight.toString()) });
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryNodeParams.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryNodeParamsResponse = __2.QueryNodeParamsResponse.fromJSON(response);
return [2 /*return*/, queryNodeParamsResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the node params information: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_8 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_8)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Retrieves the node receipts information
* @param {string} address - Node's address.
* @param {BigInt} blockHeight - Block's number.
* @param {number} timeout - Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getNodeReceipts = function (address, blockHeight, page, perPage, timeout, rejectSelfSignedCertificates) {
if (blockHeight === void 0) { blockHeight = BigInt(0); }
if (page === void 0) { page = 1; }
if (perPage === void 0) { perPage = 30; }
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, queryNodeReceiptsResponse, err_9;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (Number(blockHeight.toString()) < 0) {
return [2 /*return*/, new __2.RpcError("101", "block height can't be lower than 0")];
}
if (!__1.Hex.validateAddress(address)) {
return [2 /*return*/, new __2.RpcError("0", "Invalid Address Hex")];
}
payload = JSON.stringify({
address: address,
height: Number(blockHeight.toString()),
page: page,
per_page: perPage
});
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryNodeReceipts.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryNodeReceiptsResponse = __2.QueryNodeReceiptsResponse.fromJSON(response);
return [2 /*return*/, queryNodeReceiptsResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the node receipts: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_9 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_9)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Retrieves the node receipt information
* @param {string} address - Node's address.
* @param {string} appPubKey - Node's address.
* @param {string} blockchain - Node's address.
* @param {BigInt} height - Node's address.
* @param {BigInt} sessionBlockHeight - Node's address.
* @param {string} receiptType - Node's address.
* @param {number} timeout - Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getNodeReceipt = function (address, appPubKey, blockchain, height, sessionBlockHeight, receiptType, timeout, rejectSelfSignedCertificates) {
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var nodeReceipt, payload, response, queryNodeReceiptResponse, err_10;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
nodeReceipt = new __2.NodeReceipt(address, blockchain, appPubKey, sessionBlockHeight, height, receiptType);
if (!nodeReceipt.isValid()) {
return [2 /*return*/, new __2.RpcError("0", "Invalid Node Receipt information")];
}
payload = nodeReceipt.toJSON();
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryNodeReceipt.toString(), JSON.stringify(payload), timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryNodeReceiptResponse = __2.QueryNodeReceiptResponse.fromJSON(response);
return [2 /*return*/, queryNodeReceiptResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the node receipt: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_10 = _a.sent();
return [2 /*return*/, err_10];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Retrieves a list of apps
* @param {StakingStatus} stakingStatus - Staking status.
* @param {BigInt} blockHeight - Block's number.
* @param {string} blockchain - (optional) Blockchain identifier.
* @param {BigInt} page - (optional) Block's number.
* @param {BigInt} perPage - (optional) Block's number.
* @param {number} timeout - (optional) Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getApps = function (stakingStatus, blockHeight, blockchain, page, perPage, timeout, rejectSelfSignedCertificates) {
if (stakingStatus === void 0) { stakingStatus = __2.StakingStatus.NA; }
if (blockHeight === void 0) { blockHeight = BigInt(0); }
if (blockchain === void 0) { blockchain = ""; }
if (page === void 0) { page = 1; }
if (perPage === void 0) { perPage = 30; }
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, queryAppsResponse, err_11;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (Number(blockHeight.toString()) < 0) {
return [2 /*return*/, new __2.RpcError("101", "block height can't be lower than 0")];
}
payload = JSON.stringify({
height: Number(blockHeight.toString()),
opts: {
staking_status: stakingStatus === "" ? null : stakingStatus,
blockchain: blockchain,
page: page,
per_page: perPage
}
});
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryApps.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryAppsResponse = __2.QueryAppsResponse.fromJSON(response);
return [2 /*return*/, queryAppsResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the list of apps: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_11 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_11)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Retrieves an app information
* @param {string} address - Address of the app.
* @param {BigInt} blockHeight - Block's number.
* @param {number} timeout - Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getApp = function (address, blockHeight, timeout, rejectSelfSignedCertificates) {
if (blockHeight === void 0) { blockHeight = BigInt(0); }
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, queryAppResponse, err_12;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (!__1.Hex.isHex(address) && __1.Hex.byteLength(address) !== 20) {
return [2 /*return*/, new __2.RpcError("0", "Invalid Address Hex")];
}
if (Number(blockHeight.toString()) < 0) {
return [2 /*return*/, new __2.RpcError("101", "block height can't be lower than 0")];
}
payload = JSON.stringify({
address: address,
height: Number(blockHeight.toString())
});
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryApp.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryAppResponse = __2.QueryAppResponse.fromJSON(response);
return [2 /*return*/, queryAppResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the app infromation: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_12 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_12)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Retrieves app params.
* @param {BigInt} blockHeight - Block's number.
* @param {number} timeout - Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getAppParams = function (blockHeight, timeout, rejectSelfSignedCertificates) {
if (blockHeight === void 0) { blockHeight = BigInt(0); }
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, queryAppParamsResponse, err_13;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (Number(blockHeight.toString()) < 0) {
return [2 /*return*/, new __2.RpcError("101", "block height can't be lower than 0")];
}
payload = JSON.stringify({ height: Number(blockHeight.toString()) });
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryAppParams.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryAppParamsResponse = __2.QueryAppParamsResponse.fromJSON(response);
return [2 /*return*/, queryAppParamsResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the app params: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_13 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_13)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Retrieves the pocket params.
* @param {BigInt} blockHeight - Block's number.
* @param {number} timeout - Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getPocketParams = function (blockHeight, timeout, rejectSelfSignedCertificates) {
if (blockHeight === void 0) { blockHeight = BigInt(0); }
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, queryPocketParamsResponse, err_14;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (Number(blockHeight.toString()) < 0) {
return [2 /*return*/, new __2.RpcError("101", "block height can't be lower than 0")];
}
payload = JSON.stringify({ height: Number(blockHeight.toString()) });
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryPocketParams.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryPocketParamsResponse = __2.QueryPocketParamsResponse.fromJSON(response);
return [2 /*return*/, queryPocketParamsResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the pocket params: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_14 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_14)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Retrieves supported chains
* @param {BigInt} blockHeight - Block's number.
* @param {number} timeout - Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getSupportedChains = function (blockHeight, timeout, rejectSelfSignedCertificates) {
if (blockHeight === void 0) { blockHeight = BigInt(0); }
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, querySupportedChainsResponse, err_15;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (Number(blockHeight.toString()) < 0) {
return [2 /*return*/, new __2.RpcError("101", "block height can't be lower than 0")];
}
payload = JSON.stringify({ height: Number(blockHeight.toString()) });
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QuerySupportedChains.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
querySupportedChainsResponse = __2.QuerySupportedChainsResponse.fromJSON(response);
return [2 /*return*/, querySupportedChainsResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the supported chains list: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_15 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_15)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Retrieves current supply information
* @param {BigInt} blockHeight - Block's number.
* @param {number} timeout - Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getSupply = function (blockHeight, timeout, rejectSelfSignedCertificates) {
if (blockHeight === void 0) { blockHeight = BigInt(0); }
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, querySupplyResponse, err_16;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (Number(blockHeight.toString()) < 0) {
return [2 /*return*/, new __2.RpcError("101", "block height can't be lower than 0")];
}
payload = JSON.stringify({
height: Number(blockHeight.toString())
});
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QuerySupply.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
querySupplyResponse = __2.QuerySupplyResponse.fromJSON(response);
return [2 /*return*/, querySupplyResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the supply information: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_16 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_16)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Retrieves current Account information
* @param {string} address - Account's address.
* @param {number} timeout - Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getAccount = function (address, timeout, rejectSelfSignedCertificates) {
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, queryAccountResponse, err_17;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (!__1.Hex.isHex(address) && __1.Hex.byteLength(address) !== 20) {
return [2 /*return*/, new __2.RpcError("0", "Invalid Address Hex")];
}
payload = JSON.stringify({ address: address });
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryAccount.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryAccountResponse = __2.QueryAccountResponse.fromJSON(response);
return [2 /*return*/, queryAccountResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the account information: " + response.message)];
}
return [3 /*break*/, 3];
case 2:
err_17 = _a.sent();
return [2 /*return*/, new __2.RpcError("0", err_17)];
case 3: return [2 /*return*/];
}
});
});
};
/**
*
* Retrieves an account transaction list
* @param {string} address - Account's address.
* @param {boolean} received - Filters for received or sent txs.
* @param {boolean} prove - True or false to include the tx proof.
* @param {number} page - (optional) Page number, default 1.
* @param {number} perPage - (optional) Records count per page, default 30.
* @param {number} timeout - (optional) Request timeout.
* @param {boolean} rejectSelfSignedCertificates - force certificates to come from CAs
* @memberof QueryNamespace
*/
QueryNamespace.prototype.getAccountTxs = function (address, received, prove, page, perPage, timeout, rejectSelfSignedCertificates) {
if (page === void 0) { page = 1; }
if (perPage === void 0) { perPage = 30; }
if (timeout === void 0) { timeout = 60000; }
if (rejectSelfSignedCertificates === void 0) { rejectSelfSignedCertificates = true; }
return __awaiter(this, void 0, void 0, function () {
var payload, response, queryAccountTxsResponse, err_18;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
if (!__1.Hex.isHex(address) && __1.Hex.byteLength(address) !== 20) {
return [2 /*return*/, new __2.RpcError("0", "Invalid Address Hex")];
}
payload = JSON.stringify({
address: address,
prove: prove,
received: received,
page: page,
per_page: perPage
});
return [4 /*yield*/, this.rpcProvider.send(__2.V1RPCRoutes.QueryAccountTxs.toString(), payload, timeout, rejectSelfSignedCertificates)
// Check if response is an error
];
case 1:
response = _a.sent();
// Check if response is an error
if (!__1.typeGuard(response, __2.RpcError)) {
queryAccountTxsResponse = query_account_txs_response_1.QueryAccountTxsResponse.fromJSON(response);
return [2 /*return*/, queryAccountTxsResponse];
}
else {
return [2 /*return*/, new __2.RpcError(response.code, "Failed to retrieve the supply information: " + response.message)];