UNPKG

@parity/light.js

Version:

A high-level reactive JS library optimized for light clients

41 lines (40 loc) 1.55 kB
"use strict"; // Copyright 2015-2019 Parity Technologies (UK) Ltd. // This file is part of Parity. // // SPDX-License-Identifier: MIT Object.defineProperty(exports, "__esModule", { value: true }); var operators_1 = require("rxjs/operators"); var memoizee = require("memoizee"); var api_1 = require("../api"); var createPubsubObservable_1 = require("./utils/createPubsubObservable"); var operators_2 = require("../utils/operators"); var health_1 = require("./health"); /** * Pure function version of {@link onEveryBlock$}. * * @ignore */ var onEveryBlockWithApi$ = memoizee(function (api, options) { return createPubsubObservable_1.default('eth_newHeads', 'eth_getBlockByNumber', options).pipe(operators_1.withLatestFrom(health_1.onSyncingChanged$(options).pipe(operators_1.startWith(false))), operators_1.filter(function (_a) { var _ = _a[0], isSyncing = _a[1]; return isSyncing === false; }), operators_1.map(function (_a) { var blockNumber = _a[0]; return blockNumber; }), operators_2.distinctValues()); }, { length: 1 } // Only memoize by api ); /** * Observable that emits on every new block. Note: this FrequencyObservable * won't fire when the light client is syncing. * * @param options - Options to pass to {@link FrequencyObservable}. */ function onEveryBlock$(options) { var api = options && options.provider ? api_1.createApiFromProvider(options.provider) : api_1.getApi(); return onEveryBlockWithApi$(api, options); } exports.onEveryBlock$ = onEveryBlock$;