001package org.consensusj.bitcoin.rx.jsonrpc; 002 003import io.reactivex.rxjava3.core.Flowable; 004import org.consensusj.bitcoin.rx.ChainTipService; 005import org.consensusj.jsonrpc.AsyncSupport; 006import org.consensusj.rx.jsonrpc.RxJsonRpcClient; 007import org.reactivestreams.Publisher; 008 009import java.util.concurrent.CompletionStage; 010import java.util.function.Supplier; 011 012/** 013 * A JSON-RPC client interface that provides ChainTipService 014 */ 015@Deprecated 016public interface RxJsonChainTipClient extends ChainTipService, RxJsonRpcClient { 017 018 /** 019 * Repeatedly once-per-new-block poll a method 020 * 021 * @param method A supplier (should be an RPC Method) that can throw {@link Exception}. 022 * @param <RSLT> The type of the expected result 023 * @return An Observable for the expected result type, so we can expect one call to {@code onNext} per block. 024 */ 025 @Deprecated 026 default <RSLT> Publisher<RSLT> pollOnNewBlock(AsyncSupport.ThrowingSupplier<RSLT> method) { 027 return Flowable.fromPublisher(chainTipPublisher()).flatMapMaybe(tip -> pollOnce(method)); 028 } 029 030 /** 031 * Repeatedly once-per-new-block poll an async method 032 * 033 * @param supplier A supplier (should be an RPC Method) of a CompletionStage 034 * @param <RSLT> The type of the expected result 035 * @return An Observable for the expected result type, so we can expect one call to {@code onNext} per block. 036 */ 037 default <RSLT> Publisher<RSLT> pollOnNewBlockAsync(Supplier<CompletionStage<RSLT>> supplier) { 038 return Flowable.fromPublisher(chainTipPublisher()).flatMapMaybe(tip -> pollOnceAsync(supplier)); 039 } 040}