From 94088f795cd7ac13e1966819381bd0a9228f9713 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Fri, 21 May 2021 08:44:55 +0200 Subject: [PATCH] handle invalid values from mempool.get_fee_histogram --- .../sparrow/net/BatchedElectrumServerRpc.java | 11 +++++++---- .../sparrow/net/SimpleElectrumServerRpc.java | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/net/BatchedElectrumServerRpc.java b/src/main/java/com/sparrowwallet/sparrow/net/BatchedElectrumServerRpc.java index 388444df..f33bfc25 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/BatchedElectrumServerRpc.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/BatchedElectrumServerRpc.java @@ -14,6 +14,7 @@ import com.sparrowwallet.sparrow.event.WalletHistoryStatusEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.math.BigInteger; import java.util.*; import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; @@ -236,12 +237,14 @@ public class BatchedElectrumServerRpc implements ElectrumServerRpc { public Map getFeeRateHistogram(Transport transport) { try { JsonRpcClient client = new JsonRpcClient(transport); - Long[][] feesArray = new RetryLogic(MAX_RETRIES, RETRY_DELAY, IllegalStateException.class).getResult(() -> - client.createRequest().returnAs(Long[][].class).method("mempool.get_fee_histogram").id(idCounter.incrementAndGet()).execute()); + BigInteger[][] feesArray = new RetryLogic(MAX_RETRIES, RETRY_DELAY, IllegalStateException.class).getResult(() -> + client.createRequest().returnAs(BigInteger[][].class).method("mempool.get_fee_histogram").id(idCounter.incrementAndGet()).execute()); Map feeRateHistogram = new TreeMap<>(); - for(Long[] feePair : feesArray) { - feeRateHistogram.put(feePair[0], feePair[1]); + for(BigInteger[] feePair : feesArray) { + if(feePair[0].longValue() > 0) { + feeRateHistogram.put(feePair[0].longValue(), feePair[1].longValue()); + } } return feeRateHistogram; diff --git a/src/main/java/com/sparrowwallet/sparrow/net/SimpleElectrumServerRpc.java b/src/main/java/com/sparrowwallet/sparrow/net/SimpleElectrumServerRpc.java index 643fcaf0..122fd202 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/SimpleElectrumServerRpc.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/SimpleElectrumServerRpc.java @@ -13,6 +13,7 @@ import com.sparrowwallet.sparrow.event.WalletHistoryStatusEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.math.BigInteger; import java.util.*; import java.util.concurrent.atomic.AtomicLong; @@ -257,12 +258,14 @@ public class SimpleElectrumServerRpc implements ElectrumServerRpc { public Map getFeeRateHistogram(Transport transport) { try { JsonRpcClient client = new JsonRpcClient(transport); - Long[][] feesArray = new RetryLogic(MAX_RETRIES, RETRY_DELAY, IllegalStateException.class).getResult(() -> - client.createRequest().returnAs(Long[][].class).method("mempool.get_fee_histogram").id(idCounter.incrementAndGet()).execute()); + BigInteger[][] feesArray = new RetryLogic(MAX_RETRIES, RETRY_DELAY, IllegalStateException.class).getResult(() -> + client.createRequest().returnAs(BigInteger[][].class).method("mempool.get_fee_histogram").id(idCounter.incrementAndGet()).execute()); Map feeRateHistogram = new TreeMap<>(); - for(Long[] feePair : feesArray) { - feeRateHistogram.put(feePair[0], feePair[1]); + for(BigInteger[] feePair : feesArray) { + if(feePair[0].longValue() > 0) { + feeRateHistogram.put(feePair[0].longValue(), feePair[1].longValue()); + } } return feeRateHistogram;