3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-31 23:32:16 +00:00

Better use of annotations in Block

This commit is contained in:
Mike Hearn 2013-09-30 14:11:12 +02:00
parent e4a5c6bbc9
commit e3bcb49c4c

View File

@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableList;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; 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. * 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. * 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); Block b = new Block(params);
b.setDifficultyTarget(difficultyTarget); b.setDifficultyTarget(difficultyTarget);
b.addCoinbaseTransaction(pubKey, coinbaseValue); b.addCoinbaseTransaction(pubKey, coinbaseValue);
@ -1025,21 +1027,22 @@ public class Block extends Message {
return b; return b;
} }
// Visible for testing. @VisibleForTesting
public Block createNextBlock(Address to, TransactionOutPoint prevOut) { public Block createNextBlock(@Nullable Address to, TransactionOutPoint prevOut) {
return createNextBlock(to, prevOut, Utils.now().getTime() / 1000, EMPTY_BYTES, Utils.toNanoCoins(50, 0)); return createNextBlock(to, prevOut, Utils.now().getTime() / 1000, EMPTY_BYTES, Utils.toNanoCoins(50, 0));
} }
// Visible for testing. @VisibleForTesting
public Block createNextBlock(Address to, BigInteger value) { public Block createNextBlock(@Nullable Address to, BigInteger value) {
return createNextBlock(to, null, Utils.now().getTime() / 1000, EMPTY_BYTES, 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)); return createNextBlock(to, Utils.toNanoCoins(50, 0));
} }
// Visible for testing. @VisibleForTesting
public Block createNextBlockWithCoinbase(byte[] pubKey, BigInteger coinbaseValue) { public Block createNextBlockWithCoinbase(byte[] pubKey, BigInteger coinbaseValue) {
return createNextBlock(null, null, Utils.now().getTime() / 1000, pubKey, 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. * Create a block sending 50BTC as a coinbase transaction to the public key specified.
* This method is intended for test use only. * This method is intended for test use only.
*/ */
@VisibleForTesting
Block createNextBlockWithCoinbase(byte[] pubKey) { Block createNextBlockWithCoinbase(byte[] pubKey) {
return createNextBlock(null, null, Utils.now().getTime() / 1000, pubKey, Utils.toNanoCoins(50, 0)); return createNextBlock(null, null, Utils.now().getTime() / 1000, pubKey, Utils.toNanoCoins(50, 0));
} }
/** @VisibleForTesting
* Used for unit test
*
* @return the headerParsed
*/
boolean isParsedHeader() { boolean isParsedHeader() {
return headerParsed; return headerParsed;
} }
/** @VisibleForTesting
* Used for unit test
*
* @return the transactionsParsed
*/
boolean isParsedTransactions() { boolean isParsedTransactions() {
return transactionsParsed; return transactionsParsed;
} }
/** @VisibleForTesting
* Used for unit test
*
* @return the headerBytesValid
*/
boolean isHeaderBytesValid() { boolean isHeaderBytesValid() {
return headerBytesValid; return headerBytesValid;
} }
/** @VisibleForTesting
* Used for unit test
*
* @return the transactionBytesValid
*/
boolean isTransactionBytesValid() { boolean isTransactionBytesValid() {
return transactionBytesValid; return transactionBytesValid;
} }
} }