Search in sources :

Example 11 with JsonRpcClient

use of com.github.arteam.simplejsonrpc.client.JsonRpcClient in project sparrow by sparrowwallet.

the class SimpleElectrumServerRpc method getFeeRateHistogram.

@Override
public Map<Long, Long> getFeeRateHistogram(Transport transport) {
    try {
        JsonRpcClient client = new JsonRpcClient(transport);
        BigInteger[][] feesArray = new RetryLogic<BigInteger[][]>(MAX_RETRIES, RETRY_DELAY, IllegalStateException.class).getResult(() -> client.createRequest().returnAs(BigInteger[][].class).method("mempool.get_fee_histogram").id(idCounter.incrementAndGet()).execute());
        Map<Long, Long> feeRateHistogram = new TreeMap<>();
        for (BigInteger[] feePair : feesArray) {
            if (feePair[0].longValue() > 0) {
                feeRateHistogram.put(feePair[0].longValue(), feePair[1].longValue());
            }
        }
        return feeRateHistogram;
    } catch (Exception e) {
        throw new ElectrumServerRpcException("Error getting fee rate histogram", e);
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) BigInteger(java.math.BigInteger) JsonRpcClient(com.github.arteam.simplejsonrpc.client.JsonRpcClient) JsonRpcException(com.github.arteam.simplejsonrpc.client.exception.JsonRpcException)

Aggregations

JsonRpcClient (com.github.arteam.simplejsonrpc.client.JsonRpcClient)11 JsonRpcException (com.github.arteam.simplejsonrpc.client.exception.JsonRpcException)11 WalletHistoryStatusEvent (com.sparrowwallet.sparrow.event.WalletHistoryStatusEvent)5 BigInteger (java.math.BigInteger)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 JsonRpcBatchException (com.github.arteam.simplejsonrpc.client.exception.JsonRpcBatchException)2 Transaction (com.sparrowwallet.drongo.protocol.Transaction)2 Transport (com.github.arteam.simplejsonrpc.client.Transport)1 Utils (com.sparrowwallet.drongo.Utils)1 Sha256Hash (com.sparrowwallet.drongo.protocol.Sha256Hash)1 Wallet (com.sparrowwallet.drongo.wallet.Wallet)1 AppServices (com.sparrowwallet.sparrow.AppServices)1 EventManager (com.sparrowwallet.sparrow.EventManager)1 java.util (java.util)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1