Search in sources :

Example 1 with Transport

use of com.github.arteam.simplejsonrpc.client.Transport in project bitcoin-spring-boot-starter by theborakompanioni.

the class ElectrumClientFactoryImpl method create.

@Override
public ElectrumClient create(URI uri, String username, String password) {
    CloseableHttpClient httpClient = httpClient();
    Transport transport = transport(httpClient, uri, username, password);
    ElectrumDaemonRpcService delegate = electrumDaemonRpcService(transport);
    return new ElectrumClientImpl(delegate);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Transport(com.github.arteam.simplejsonrpc.client.Transport)

Example 2 with Transport

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

the class SimpleElectrumServerRpc method getFeeEstimates.

@Override
public Map<Integer, Double> getFeeEstimates(Transport transport, List<Integer> targetBlocks) {
    JsonRpcClient client = new JsonRpcClient(transport);
    Map<Integer, Double> result = new LinkedHashMap<>();
    for (Integer targetBlock : targetBlocks) {
        if (targetBlock <= MAX_TARGET_BLOCKS) {
            try {
                Double targetBlocksFeeRateBtcKb = new RetryLogic<Double>(MAX_RETRIES, RETRY_DELAY, IllegalStateException.class).getResult(() -> client.createRequest().returnAs(Double.class).method("blockchain.estimatefee").id(idCounter.incrementAndGet()).params(targetBlock).execute());
                result.put(targetBlock, targetBlocksFeeRateBtcKb);
            } catch (JsonRpcException e) {
                throw new ElectrumServerRpcException("Failed to retrieve fee rate for target blocks: " + targetBlock, e);
            } catch (Exception e) {
                log.warn("Failed to retrieve fee rate for target blocks: " + targetBlock + " (" + e.getMessage() + ")");
                result.put(targetBlock, result.values().stream().mapToDouble(v -> v).min().orElse(0.0001d));
            }
        } else {
            result.put(targetBlock, result.values().stream().mapToDouble(v -> v).min().orElse(0.0001d));
        }
    }
    return result;
}
Also used : BigInteger(java.math.BigInteger) JsonRpcException(com.github.arteam.simplejsonrpc.client.exception.JsonRpcException) Transaction(com.sparrowwallet.drongo.protocol.Transaction) java.util(java.util) Logger(org.slf4j.Logger) Wallet(com.sparrowwallet.drongo.wallet.Wallet) LoggerFactory(org.slf4j.LoggerFactory) WalletHistoryStatusEvent(com.sparrowwallet.sparrow.event.WalletHistoryStatusEvent) Transport(com.github.arteam.simplejsonrpc.client.Transport) AtomicLong(java.util.concurrent.atomic.AtomicLong) JsonRpcClient(com.github.arteam.simplejsonrpc.client.JsonRpcClient) AppServices(com.sparrowwallet.sparrow.AppServices) Utils(com.sparrowwallet.drongo.Utils) EventManager(com.sparrowwallet.sparrow.EventManager) BigInteger(java.math.BigInteger) Sha256Hash(com.sparrowwallet.drongo.protocol.Sha256Hash) JsonRpcClient(com.github.arteam.simplejsonrpc.client.JsonRpcClient) JsonRpcException(com.github.arteam.simplejsonrpc.client.exception.JsonRpcException) JsonRpcException(com.github.arteam.simplejsonrpc.client.exception.JsonRpcException)

Aggregations

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