UNPKG

@berrywallet/core

Version:

Berrywallet main Core for work with common cryptocurrencies like Bitcoin, Ethereum, Dash, Litecoin

73 lines (72 loc) 2.53 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; } Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = require("lodash"); const Tracker = __importStar(require("./tracker")); exports.Tracker = Tracker; class NetworkClient { constructor(coin, options) { this.onBlocksCbs = []; this.onAddrTXCbs = {}; this.coin = coin; this.options = options; } getCoin() { return this.coin; } getApiUrl() { return this.options.url; } getWSUrl() { return this.options.wsUrl; } enabledWS() { return !!this.getWSUrl(); } getOptions() { return this.options; } getTracker() { throw new Error('Tracker Client must be implement!'); } getBulkAddrsTxs(addrs) { return __awaiter(this, void 0, void 0, function* () { const promiseMap = lodash_1.map(addrs, (addr) => { return this.getAddressTxs(addr); }); const txChunks = yield Promise.all(promiseMap); const txList = []; lodash_1.forEach(txChunks, (txs) => { lodash_1.forEach(txs, (tx) => { const indx = lodash_1.findIndex(txList, { txid: tx.txid }); if (indx >= 0) { txList[indx] = Object.assign(txList[indx], tx); } else { txList.push(tx); } }); }); return txList; }); } destruct() { this.onBlocksCbs = []; this.onAddrTXCbs = {}; } } exports.NetworkClient = NetworkClient;