mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2026-08-10 08:37:05 +00:00
cormorant: add block stats rpc call, and prefer for block summaries
This commit is contained in:
@@ -82,6 +82,8 @@ public class ElectrumServer {
|
||||
|
||||
private static Server coreElectrumServer;
|
||||
|
||||
private static ServerCapability serverCapability;
|
||||
|
||||
private static final Pattern RPC_WALLET_LOADING_PATTERN = Pattern.compile(".*\"(Wallet loading failed[:.][^\"]*)\".*");
|
||||
|
||||
private static synchronized CloseableTransport getTransport() throws ServerException {
|
||||
@@ -981,6 +983,21 @@ public class ElectrumServer {
|
||||
}
|
||||
|
||||
public Map<Integer, BlockSummary> getBlockSummaryMap(Integer height, BlockHeader blockHeader) throws ServerException {
|
||||
if(serverCapability.supportsBlockStats()) {
|
||||
if(height == null) {
|
||||
Integer current = AppServices.getCurrentBlockHeight();
|
||||
if(current == null) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Set<Integer> heights = IntStream.range(current - 1, current + 1).boxed().collect(Collectors.toSet());
|
||||
Map<Integer, BlockStats> blockStats = electrumServerRpc.getBlockStats(getTransport(), heights);
|
||||
return blockStats.keySet().stream().collect(Collectors.toMap(java.util.function.Function.identity(), v -> blockStats.get(v).toBlockSummary()));
|
||||
} else {
|
||||
Map<Integer, BlockStats> blockStats = electrumServerRpc.getBlockStats(getTransport(), Set.of(height));
|
||||
return blockStats.keySet().stream().collect(Collectors.toMap(java.util.function.Function.identity(), v -> blockStats.get(v).toBlockSummary()));
|
||||
}
|
||||
}
|
||||
|
||||
FeeRatesSource feeRatesSource = Config.get().getFeeRatesSource();
|
||||
feeRatesSource = (feeRatesSource == null ? FeeRatesSource.MEMPOOL_SPACE : feeRatesSource);
|
||||
|
||||
@@ -1010,7 +1027,7 @@ public class ElectrumServer {
|
||||
if(current == null) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Set<BlockTransactionHash> references = IntStream.range(current - 4, current + 1)
|
||||
Set<BlockTransactionHash> references = IntStream.range(current - 1, current + 1)
|
||||
.mapToObj(i -> new BlockTransaction(null, i, null, null, null)).collect(Collectors.toSet());
|
||||
Map<Integer, BlockHeader> blockHeaders = getBlockHeaders(null, references);
|
||||
return blockHeaders.keySet().stream()
|
||||
@@ -1219,7 +1236,7 @@ public class ElectrumServer {
|
||||
}
|
||||
|
||||
if(server.startsWith("cormorant")) {
|
||||
return new ServerCapability(true);
|
||||
return new ServerCapability(true, false, true);
|
||||
}
|
||||
|
||||
if(server.startsWith("electrs/")) {
|
||||
@@ -1405,7 +1422,7 @@ public class ElectrumServer {
|
||||
firstCall = false;
|
||||
|
||||
//If electrumx is detected, we can upgrade to batched RPC. Electrs/EPS do not support batching.
|
||||
ServerCapability serverCapability = getServerCapability(serverVersion);
|
||||
serverCapability = getServerCapability(serverVersion);
|
||||
if(serverCapability.supportsBatching()) {
|
||||
log.debug("Upgrading to batched JSON-RPC");
|
||||
electrumServerRpc = new BatchedElectrumServerRpc(electrumServerRpc.getIdCounterValue(), serverCapability.getMaxTargetBlocks());
|
||||
|
||||
Reference in New Issue
Block a user