UNPKG

hive-keychain-commons

Version:

Platform-agnostic functions used in Hive Keychain mobile and extensions

45 lines (44 loc) 2.19 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.TransactionUtils = void 0; const hive_tx_1 = require("hive-tx"); const index_1 = require("../index"); const getData = (method, params, timeout = 3000) => __awaiter(void 0, void 0, void 0, function* () { const response = yield (0, hive_tx_1.call)(method, params, timeout); if (response === null || response === void 0 ? void 0 : response.result) { return response.result; } throw new Error(`Error while retrieving data from ${method} : ${JSON.stringify(response.error)}`); }); const getTransactions = (account, start, limit, operationFilterLow, operationFilterHigh) => __awaiter(void 0, void 0, void 0, function* () { return getData('condenser_api.get_account_history', [ account, start, limit, operationFilterLow, operationFilterHigh, ]); }); const getLastTransaction = (accountName) => __awaiter(void 0, void 0, void 0, function* () { const op = index_1.HistoryFiltersUtils.operationOrders; const allOp = Object.values(op); const allOperationsBitmask = index_1.HistoryFiltersUtils.makeBitMaskFilter(allOp); const transactionsFromBlockchain = yield getTransactions(accountName, -1, 1, allOperationsBitmask[0], allOperationsBitmask[1]); return transactionsFromBlockchain.length > 0 ? transactionsFromBlockchain[0][0] : -1; }); exports.TransactionUtils = { getData, getTransactions, getLastTransaction, };