Skip to content

Commit

Permalink
Add Transaction.includedInBestChainAt
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarguindzberg committed Jan 24, 2019
1 parent f35520a commit cc774c5
Show file tree
Hide file tree
Showing 4 changed files with 277 additions and 140 deletions.
17 changes: 17 additions & 0 deletions core/src/main/java/org/bitcoinj/core/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public int compare(final Transaction tx1, final Transaction tx2) {
// list of transactions from a wallet, which is helpful for presenting to users.
private Date updatedAt;

// Date of the block that includes this transaction on the best chain
@Nullable
private Date includedInBestChainAt;

// This is an in memory helper only.
private Sha256Hash hash;

Expand Down Expand Up @@ -331,6 +335,9 @@ public void setBlockAppearance(StoredBlock block, boolean bestChain, int relativ
if (bestChain && (updatedAt == null || updatedAt.getTime() == 0 || updatedAt.getTime() > blockTime)) {
updatedAt = new Date(blockTime);
}
if (bestChain) {
includedInBestChainAt = new Date(blockTime);
}

addBlockAppearance(block.getHeader().getHash(), relativityOffset);

Expand Down Expand Up @@ -471,6 +478,14 @@ public void setUpdateTime(Date updatedAt) {
this.updatedAt = updatedAt;
}

public Date getIncludedInBestChainAt() {

This comment has been minimized.

Copy link
@ManfredKarrer

ManfredKarrer Jan 25, 2019

Would add here @nullable as well

This comment has been minimized.

Copy link
@oscarguindzberg

oscarguindzberg Feb 4, 2019

Author Owner

done.

return includedInBestChainAt;
}

public void setIncludedInBestChainAt(Date includedInBestChainAt) {
this.includedInBestChainAt = includedInBestChainAt;
}

/**
* These constants are a part of a scriptSig signature on the inputs. They define the details of how a
* transaction can be redeemed, specifically, they control how the hash of the transaction is calculated.
Expand Down Expand Up @@ -644,6 +659,8 @@ public String toString(@Nullable AbstractBlockChain chain) {
s.append(" ").append(getHashAsString()).append('\n');
if (updatedAt != null)
s.append(" updated: ").append(Utils.dateTimeFormat(updatedAt)).append('\n');
if (includedInBestChainAt != null)
s.append(" included in best chain at: ").append(Utils.dateTimeFormat(includedInBestChainAt)).append('\n');
if (version != 1)
s.append(" version ").append(version).append('\n');
if (isTimeLocked()) {
Expand Down
Loading

0 comments on commit cc774c5

Please sign in to comment.