diff --git a/tools/src/main/java/org/bitcoinj/tools/BuildCheckpoints.java b/tools/src/main/java/org/bitcoinj/tools/BuildCheckpoints.java index df3d9e6b7d4..9f65bcd9ac4 100644 --- a/tools/src/main/java/org/bitcoinj/tools/BuildCheckpoints.java +++ b/tools/src/main/java/org/bitcoinj/tools/BuildCheckpoints.java @@ -32,6 +32,7 @@ import org.bitcoinj.store.MemoryBlockStore; import org.bitcoinj.utils.BriefLogFormatter; import org.bitcoinj.utils.Threading; +import org.jspecify.annotations.Nullable; import picocli.CommandLine; import java.io.File; @@ -50,6 +51,7 @@ import java.time.temporal.ChronoUnit; import java.util.Base64; import java.util.List; +import java.util.Objects; import java.util.TreeMap; import java.util.concurrent.Callable; import java.util.concurrent.Future; @@ -66,7 +68,7 @@ public class BuildCheckpoints implements Callable { @CommandLine.Option(names = "--net", description = "Which network to connect to. Valid values: ${COMPLETION-CANDIDATES}. Default: ${DEFAULT-VALUE}") private BitcoinNetwork net = BitcoinNetwork.MAINNET; @CommandLine.Option(names = "--peer", description = "IP address/domain name for connection instead of localhost.") - private String peer = null; + @Nullable private String peer = null; @CommandLine.Option(names = "--days", description = "How many days to keep as a safety margin. Checkpointing will be done up to this many days ago.") private int days = 7; @CommandLine.Option(names = "--verbose", description = "Enables logging.") @@ -74,7 +76,7 @@ public class BuildCheckpoints implements Callable { @CommandLine.Option(names = "--help", usageHelp = true, description = "Displays program options.") private boolean help; - private static NetworkParameters params; + private static @Nullable NetworkParameters params; public static void main(String[] args) throws Exception { int exitCode = new CommandLine(new BuildCheckpoints()).execute(args); @@ -90,6 +92,7 @@ public Integer call() throws Exception { final String suffix; params = NetworkParameters.of(net); + Objects.requireNonNull(params); Context.propagate(new Context()); switch (net) { @@ -156,6 +159,7 @@ public Integer call() throws Exception { System.out.println("Checkpointing up to " + TimeUtils.dateTimeFormat(timeAgo)); chain.addNewBestBlockListener(Threading.SAME_THREAD, block -> { + Objects.requireNonNull(params); int height = block.getHeight(); if (height % params.getInterval() == 0 && timeAgo.isAfter(block.getHeader().time())) { System.out.println(String.format("Checkpointing block %s at height %d, time %s", @@ -210,6 +214,7 @@ private static void writeTextualCheckpoints(TreeMap checkp } private static void sanityCheck(File file, int expectedSize) throws IOException { + Objects.requireNonNull(params); FileInputStream fis = new FileInputStream(file); CheckpointManager manager; try { @@ -239,6 +244,7 @@ private static void sanityCheck(File file, int expectedSize) throws IOException } private static void startPeerGroup(PeerGroup peerGroup, InetAddress ipAddress) { + Objects.requireNonNull(params); final PeerAddress peerAddress = PeerAddress.simple(ipAddress, params.getPort()); System.out.println("Connecting to " + peerAddress + "..."); peerGroup.addAddress(peerAddress); diff --git a/tools/src/main/java/org/bitcoinj/tools/TestFeeLevel.java b/tools/src/main/java/org/bitcoinj/tools/TestFeeLevel.java index fa00fce9a09..3302a431f92 100644 --- a/tools/src/main/java/org/bitcoinj/tools/TestFeeLevel.java +++ b/tools/src/main/java/org/bitcoinj/tools/TestFeeLevel.java @@ -26,8 +26,10 @@ import org.bitcoinj.wallet.KeyChainGroupStructure; import org.bitcoinj.wallet.SendRequest; import org.bitcoinj.wallet.Wallet; +import org.jspecify.annotations.Nullable; import java.io.File; +import java.util.Objects; import java.util.concurrent.ExecutionException; /** @@ -36,7 +38,7 @@ public class TestFeeLevel { private static final int NUM_OUTPUTS = 2; - private static WalletAppKit kit; + private static @Nullable WalletAppKit kit; public static void main(String[] args) throws Exception { BriefLogFormatter.initWithSilentBitcoinJ(); @@ -60,6 +62,7 @@ public static void main(String[] args) throws Exception { } private static void go(Coin feeRateToTest, int numOutputs) throws InterruptedException, ExecutionException, InsufficientMoneyException { + Objects.requireNonNull(kit); System.out.println("Wallet has " + kit.wallet().getBalance().toFriendlyString() + "; current receive address is " + kit.wallet().currentReceiveAddress()); diff --git a/tools/src/main/java/org/bitcoinj/tools/package-info.java b/tools/src/main/java/org/bitcoinj/tools/package-info.java new file mode 100644 index 00000000000..2f1ff2d79c1 --- /dev/null +++ b/tools/src/main/java/org/bitcoinj/tools/package-info.java @@ -0,0 +1,23 @@ +/* + * Copyright by the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * bitcoinj tool utility applications. + */ +@NullMarked +package org.bitcoinj.tools; + +import org.jspecify.annotations.NullMarked;