mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-13 11:36:15 +01:00
Merge 525efae6ff
into e8ec153322
This commit is contained in:
commit
8c34cc7f1a
3 changed files with 76 additions and 118 deletions
|
@ -202,17 +202,17 @@ public class PeerMonitor {
|
|||
|
||||
@Override
|
||||
public String getColumnName(int i) {
|
||||
switch (i) {
|
||||
case IP_ADDRESS: return "Address";
|
||||
case PROTOCOL_VERSION: return "Protocol version";
|
||||
case USER_AGENT: return "User Agent";
|
||||
case CHAIN_HEIGHT: return "Chain height";
|
||||
case FEE_FILTER: return "Fee filter (per kB)";
|
||||
case PING_TIME: return "Average ping";
|
||||
case LAST_PING_TIME: return "Last ping";
|
||||
case ADDRESSES: return "Peer addresses";
|
||||
default: throw new RuntimeException();
|
||||
}
|
||||
return switch (i) {
|
||||
case IP_ADDRESS -> "Address";
|
||||
case PROTOCOL_VERSION -> "Protocol version";
|
||||
case USER_AGENT -> "User Agent";
|
||||
case CHAIN_HEIGHT -> "Chain height";
|
||||
case FEE_FILTER -> "Fee filter (per kB)";
|
||||
case PING_TIME -> "Average ping";
|
||||
case LAST_PING_TIME -> "Last ping";
|
||||
case ADDRESSES -> "Peer addresses";
|
||||
default -> throw new RuntimeException();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -222,16 +222,11 @@ public class PeerMonitor {
|
|||
|
||||
@Override
|
||||
public Class<?> getColumnClass(int column) {
|
||||
switch (column) {
|
||||
case PROTOCOL_VERSION:
|
||||
return Integer.class;
|
||||
case CHAIN_HEIGHT:
|
||||
case PING_TIME:
|
||||
case LAST_PING_TIME:
|
||||
return Long.class;
|
||||
default:
|
||||
return String.class;
|
||||
}
|
||||
return switch (column) {
|
||||
case PROTOCOL_VERSION -> Integer.class;
|
||||
case CHAIN_HEIGHT, PING_TIME, LAST_PING_TIME -> Long.class;
|
||||
default -> String.class;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -239,41 +234,28 @@ public class PeerMonitor {
|
|||
if (row >= connectedPeers.size()) {
|
||||
// Peer that isn't connected yet.
|
||||
Peer peer = pendingPeers.get(row - connectedPeers.size());
|
||||
switch (col) {
|
||||
case IP_ADDRESS:
|
||||
return getAddressForPeer(peer);
|
||||
case PROTOCOL_VERSION:
|
||||
return 0;
|
||||
case CHAIN_HEIGHT:
|
||||
case PING_TIME:
|
||||
case LAST_PING_TIME:
|
||||
return 0L;
|
||||
default:
|
||||
return "(pending)";
|
||||
}
|
||||
return switch (col) {
|
||||
case IP_ADDRESS -> getAddressForPeer(peer);
|
||||
case PROTOCOL_VERSION -> 0;
|
||||
case CHAIN_HEIGHT, PING_TIME, LAST_PING_TIME -> 0L;
|
||||
default -> "(pending)";
|
||||
};
|
||||
}
|
||||
Peer peer = connectedPeers.get(row);
|
||||
switch (col) {
|
||||
case IP_ADDRESS:
|
||||
return getAddressForPeer(peer);
|
||||
case PROTOCOL_VERSION:
|
||||
return Integer.toString(peer.getPeerVersionMessage().clientVersion);
|
||||
case USER_AGENT:
|
||||
return peer.getPeerVersionMessage().subVer;
|
||||
case CHAIN_HEIGHT:
|
||||
return peer.getBestHeight();
|
||||
case FEE_FILTER:
|
||||
return switch (col) {
|
||||
case IP_ADDRESS -> getAddressForPeer(peer);
|
||||
case PROTOCOL_VERSION -> Integer.toString(peer.getPeerVersionMessage().clientVersion);
|
||||
case USER_AGENT -> peer.getPeerVersionMessage().subVer;
|
||||
case CHAIN_HEIGHT -> peer.getBestHeight();
|
||||
case FEE_FILTER -> {
|
||||
Coin feeFilter = peer.getFeeFilter();
|
||||
return feeFilter != null ? feeFilter.toFriendlyString() : "";
|
||||
case PING_TIME:
|
||||
return peer.pingInterval().map(Duration::toMillis).orElse(0L);
|
||||
case LAST_PING_TIME:
|
||||
return peer.lastPingInterval().map(Duration::toMillis).orElse(0L);
|
||||
case ADDRESSES:
|
||||
return getAddressesForPeer(peer);
|
||||
|
||||
default: throw new RuntimeException();
|
||||
yield feeFilter != null ? feeFilter.toFriendlyString() : "";
|
||||
}
|
||||
case PING_TIME -> peer.pingInterval().map(Duration::toMillis).orElse(0L);
|
||||
case LAST_PING_TIME -> peer.lastPingInterval().map(Duration::toMillis).orElse(0L);
|
||||
case ADDRESSES -> getAddressesForPeer(peer);
|
||||
default -> throw new RuntimeException();
|
||||
};
|
||||
}
|
||||
|
||||
private String getAddressForPeer(Peer peer) {
|
||||
|
|
|
@ -85,22 +85,12 @@ public class BuildCheckpoints implements Callable<Integer> {
|
|||
params = NetworkParameters.of(net);
|
||||
Context.propagate(new Context());
|
||||
|
||||
switch (net) {
|
||||
case MAINNET:
|
||||
suffix = "";
|
||||
break;
|
||||
case TESTNET:
|
||||
suffix = "-testnet";
|
||||
break;
|
||||
case SIGNET:
|
||||
suffix = "-signet";
|
||||
break;
|
||||
case REGTEST:
|
||||
suffix = "-regtest";
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unreachable.");
|
||||
}
|
||||
suffix = switch (net) {
|
||||
case MAINNET -> "";
|
||||
case TESTNET -> "-testnet";
|
||||
case SIGNET -> "-signet";
|
||||
case REGTEST -> "-regtest";
|
||||
};
|
||||
|
||||
// Configure bitcoinj to fetch only headers, not save them to disk, connect to a local fully synced/validated
|
||||
// node and to save block headers that are on interval boundaries, as long as they are <1 month old.
|
||||
|
|
|
@ -259,35 +259,22 @@ public class WalletTool implements Callable<Integer> {
|
|||
else if (from.startsWith(">")) type = Type.GT;
|
||||
else throw new RuntimeException("Unknown operator in condition: " + from);
|
||||
|
||||
String s;
|
||||
switch (type) {
|
||||
case LT:
|
||||
case GT:
|
||||
case EQUAL:
|
||||
s = from.substring(1);
|
||||
break;
|
||||
case LTE:
|
||||
case GTE:
|
||||
s = from.substring(2);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unreachable");
|
||||
}
|
||||
value = s;
|
||||
value = switch (type) {
|
||||
case LT, GT, EQUAL -> from.substring(1);
|
||||
case LTE, GTE -> from.substring(2);
|
||||
};
|
||||
}
|
||||
|
||||
public boolean matchBitcoins(Coin comparison) {
|
||||
try {
|
||||
Coin units = parseCoin(value);
|
||||
switch (type) {
|
||||
case LT: return comparison.compareTo(units) < 0;
|
||||
case GT: return comparison.compareTo(units) > 0;
|
||||
case EQUAL: return comparison.compareTo(units) == 0;
|
||||
case LTE: return comparison.compareTo(units) <= 0;
|
||||
case GTE: return comparison.compareTo(units) >= 0;
|
||||
default:
|
||||
throw new RuntimeException("Unreachable");
|
||||
}
|
||||
return switch (type) {
|
||||
case LT -> comparison.compareTo(units) < 0;
|
||||
case GT -> comparison.compareTo(units) > 0;
|
||||
case EQUAL -> comparison.compareTo(units) == 0;
|
||||
case LTE -> comparison.compareTo(units) <= 0;
|
||||
case GTE -> comparison.compareTo(units) >= 0;
|
||||
};
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("Could not parse value from condition string: " + value);
|
||||
System.exit(1);
|
||||
|
@ -400,14 +387,14 @@ public class WalletTool implements Callable<Integer> {
|
|||
|
||||
// What should we do?
|
||||
switch (action) {
|
||||
case DUMP: dumpWallet(); break;
|
||||
case ADD_KEY: addKey(); break;
|
||||
case ADD_ADDR: addAddr(); break;
|
||||
case DELETE_KEY: deleteKey(); break;
|
||||
case CURRENT_RECEIVE_ADDR: currentReceiveAddr(); break;
|
||||
case RESET: reset(); break;
|
||||
case SYNC: syncChain(); break;
|
||||
case SEND:
|
||||
case DUMP -> dumpWallet();
|
||||
case ADD_KEY -> addKey();
|
||||
case ADD_ADDR -> addAddr();
|
||||
case DELETE_KEY -> deleteKey();
|
||||
case CURRENT_RECEIVE_ADDR -> currentReceiveAddr();
|
||||
case RESET -> reset();
|
||||
case SYNC -> syncChain();
|
||||
case SEND -> {
|
||||
if (paymentRequestLocationStr != null && outputsStr != null) {
|
||||
System.err.println("--payment-request and --output cannot be used together.");
|
||||
return 1;
|
||||
|
@ -460,12 +447,12 @@ public class WalletTool implements Callable<Integer> {
|
|||
System.err.println("You must specify a --payment-request or at least one --output=addr:value.");
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case ENCRYPT: encrypt(); break;
|
||||
case DECRYPT: decrypt(); break;
|
||||
case UPGRADE: upgrade(); break;
|
||||
case ROTATE: rotate(); break;
|
||||
case SET_CREATION_TIME: setCreationTime(); break;
|
||||
}
|
||||
case ENCRYPT -> encrypt();
|
||||
case DECRYPT -> decrypt();
|
||||
case UPGRADE -> upgrade();
|
||||
case ROTATE -> rotate();
|
||||
case SET_CREATION_TIME -> setCreationTime();
|
||||
}
|
||||
|
||||
if (!wallet.isConsistent()) {
|
||||
|
@ -906,26 +893,25 @@ public class WalletTool implements Callable<Integer> {
|
|||
*/
|
||||
private CompletableFuture<String> wait(WaitForEnum waitFor, Condition condition) {
|
||||
CompletableFuture<String> future = new CompletableFuture<>();
|
||||
switch (waitFor) {
|
||||
case EVER:
|
||||
break; // Future will never complete
|
||||
|
||||
case WALLET_TX:
|
||||
switch (waitFor) {
|
||||
case EVER -> {
|
||||
// Future will never complete
|
||||
}
|
||||
case WALLET_TX -> {
|
||||
// Future will complete with a transaction ID string
|
||||
Consumer<Transaction> txListener = tx -> future.complete(tx.getTxId().toString());
|
||||
// Both listeners run in a peer thread
|
||||
wallet.addCoinsReceivedEventListener((wallet, tx, prevBalance, newBalance) -> txListener.accept(tx));
|
||||
wallet.addCoinsSentEventListener((wallet, tx, prevBalance, newBalance) -> txListener.accept(tx));
|
||||
break;
|
||||
|
||||
case BLOCK:
|
||||
}
|
||||
case BLOCK -> {
|
||||
// Future will complete with a Block hash string
|
||||
peerGroup.addBlocksDownloadedEventListener((peer, block, filteredBlock, blocksLeft) ->
|
||||
future.complete(block.getHashAsString())
|
||||
);
|
||||
break;
|
||||
|
||||
case BALANCE:
|
||||
}
|
||||
case BALANCE -> {
|
||||
// Future will complete with a balance amount string
|
||||
// Check if the balance already meets the given condition.
|
||||
Coin existingBalance = wallet.getBalance(Wallet.BalanceType.ESTIMATED);
|
||||
|
@ -946,7 +932,7 @@ public class WalletTool implements Callable<Integer> {
|
|||
wallet.addChangeEventListener(w -> onChange.run());
|
||||
wallet.addReorganizeEventListener(w -> onChange.run());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return future;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue