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