Block: getTransactions() should not throw if the block represents a header, but rather return null.

This commit is contained in:
Mike Hearn 2015-02-17 15:16:43 +01:00
parent b2c1aba4d6
commit fcd4b8b68a

View file

@ -83,8 +83,9 @@ public class Block extends Message {
private long difficultyTarget; // "nBits"
private long nonce;
// TODO: Get rid of all the direct accesses to this field. It's a long-since unnecessary holdover from the Dalvik days.
/** If null, it means this object holds only the headers. */
List<Transaction> transactions;
@Nullable List<Transaction> transactions;
/** Stores the hash of the block. If null, getHash() will recalculate it. */
private transient Sha256Hash hash;
@ -949,10 +950,13 @@ public class Block extends Message {
this.hash = null;
}
/** Returns an immutable list of transactions held in this block. */
public List<Transaction> getTransactions() {
maybeParseTransactions();
return ImmutableList.copyOf(transactions);
/** Returns an immutable list of transactions held in this block, or null if this object represents just a header. */
public @Nullable List<Transaction> getTransactions() {
maybeParseTransactions();
if (transactions == null)
return null;
else
return ImmutableList.copyOf(transactions);
}
// ///////////////////////////////////////////////////////////////////////////////////////////////