mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-13 11:36:15 +01:00
Block: getTransactions() should not throw if the block represents a header, but rather return null.
This commit is contained in:
parent
b2c1aba4d6
commit
fcd4b8b68a
1 changed files with 9 additions and 5 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Reference in a new issue