From e3bcb49c4c7b590e9f00d4f762b31bbcc58dc357 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Mon, 30 Sep 2013 14:11:12 +0200 Subject: [PATCH] Better use of annotations in Block --- .../java/com/google/bitcoin/core/Block.java | 43 +++++++------------ 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/core/Block.java b/core/src/main/java/com/google/bitcoin/core/Block.java index aa9c3a0f..ca4101a6 100644 --- a/core/src/main/java/com/google/bitcoin/core/Block.java +++ b/core/src/main/java/com/google/bitcoin/core/Block.java @@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; @@ -984,7 +985,8 @@ public class Block extends Message { * Returns a solved block that builds on top of this one. This exists for unit tests. * In this variant you can specify a public key (pubkey) for use in generating coinbase blocks. */ - Block createNextBlock(Address to, TransactionOutPoint prevOut, long time, byte[] pubKey, BigInteger coinbaseValue) { + Block createNextBlock(@Nullable Address to, @Nullable TransactionOutPoint prevOut, long time, + byte[] pubKey, BigInteger coinbaseValue) { Block b = new Block(params); b.setDifficultyTarget(difficultyTarget); b.addCoinbaseTransaction(pubKey, coinbaseValue); @@ -1025,21 +1027,22 @@ public class Block extends Message { return b; } - // Visible for testing. - public Block createNextBlock(Address to, TransactionOutPoint prevOut) { + @VisibleForTesting + public Block createNextBlock(@Nullable Address to, TransactionOutPoint prevOut) { return createNextBlock(to, prevOut, Utils.now().getTime() / 1000, EMPTY_BYTES, Utils.toNanoCoins(50, 0)); } - // Visible for testing. - public Block createNextBlock(Address to, BigInteger value) { + @VisibleForTesting + public Block createNextBlock(@Nullable Address to, BigInteger value) { return createNextBlock(to, null, Utils.now().getTime() / 1000, EMPTY_BYTES, value); } - public Block createNextBlock(Address to) { + @VisibleForTesting + public Block createNextBlock(@Nullable Address to) { return createNextBlock(to, Utils.toNanoCoins(50, 0)); } - // Visible for testing. + @VisibleForTesting public Block createNextBlockWithCoinbase(byte[] pubKey, BigInteger coinbaseValue) { return createNextBlock(null, null, Utils.now().getTime() / 1000, pubKey, coinbaseValue); } @@ -1048,44 +1051,28 @@ public class Block extends Message { * Create a block sending 50BTC as a coinbase transaction to the public key specified. * This method is intended for test use only. */ + @VisibleForTesting Block createNextBlockWithCoinbase(byte[] pubKey) { return createNextBlock(null, null, Utils.now().getTime() / 1000, pubKey, Utils.toNanoCoins(50, 0)); } - /** - * Used for unit test - * - * @return the headerParsed - */ + @VisibleForTesting boolean isParsedHeader() { return headerParsed; } - /** - * Used for unit test - * - * @return the transactionsParsed - */ + @VisibleForTesting boolean isParsedTransactions() { return transactionsParsed; } - /** - * Used for unit test - * - * @return the headerBytesValid - */ + @VisibleForTesting boolean isHeaderBytesValid() { return headerBytesValid; } - /** - * Used for unit test - * - * @return the transactionBytesValid - */ + @VisibleForTesting boolean isTransactionBytesValid() { return transactionBytesValid; } - }