mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 23:32:16 +00:00
Introduce Transaction.hasLockTime() and use it where appropriate.
This commit is contained in:
parent
2bd9531da6
commit
f7c09d74ea
@ -553,7 +553,7 @@ public class Transaction extends ChildMessage implements Serializable {
|
|||||||
// Basic info about the tx.
|
// Basic info about the tx.
|
||||||
StringBuffer s = new StringBuffer();
|
StringBuffer s = new StringBuffer();
|
||||||
s.append(String.format(" %s: %s%n", getHashAsString(), getConfidence()));
|
s.append(String.format(" %s: %s%n", getHashAsString(), getConfidence()));
|
||||||
if (lockTime > 0) {
|
if (isTimeLocked()) {
|
||||||
String time;
|
String time;
|
||||||
if (lockTime < LOCKTIME_THRESHOLD) {
|
if (lockTime < LOCKTIME_THRESHOLD) {
|
||||||
time = "block " + lockTime;
|
time = "block " + lockTime;
|
||||||
@ -1067,6 +1067,21 @@ public class Transaction extends ChildMessage implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>A transaction is time locked if at least one of its inputs is non-final and it has a lock time</p>
|
||||||
|
*
|
||||||
|
* <p>To check if this transaction is final at a given height and time, see {@link Transaction#isFinal(int, long)}
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public boolean isTimeLocked() {
|
||||||
|
if (getLockTime() == 0)
|
||||||
|
return false;
|
||||||
|
for (TransactionInput input : getInputs())
|
||||||
|
if (input.hasSequence())
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Returns true if this transaction is considered finalized and can be placed in a block. Non-finalized
|
* <p>Returns true if this transaction is considered finalized and can be placed in a block. Non-finalized
|
||||||
* transactions won't be included by miners and can be replaced with newer versions using sequence numbers.
|
* transactions won't be included by miners and can be replaced with newer versions using sequence numbers.
|
||||||
@ -1077,16 +1092,12 @@ public class Transaction extends ChildMessage implements Serializable {
|
|||||||
* re-activated before this functionality is useful.</p>
|
* re-activated before this functionality is useful.</p>
|
||||||
*/
|
*/
|
||||||
public boolean isFinal(int height, long blockTimeSeconds) {
|
public boolean isFinal(int height, long blockTimeSeconds) {
|
||||||
// Time based nLockTime implemented in 0.1.6
|
|
||||||
long time = getLockTime();
|
long time = getLockTime();
|
||||||
if (time == 0)
|
|
||||||
return true;
|
|
||||||
if (time < (time < LOCKTIME_THRESHOLD ? height : blockTimeSeconds))
|
if (time < (time < LOCKTIME_THRESHOLD ? height : blockTimeSeconds))
|
||||||
return true;
|
return true;
|
||||||
for (TransactionInput in : inputs)
|
if (!isTimeLocked())
|
||||||
if (in.hasSequence())
|
|
||||||
return false;
|
|
||||||
return true;
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -370,6 +370,9 @@ public class TransactionInput extends ChildMessage implements Serializable {
|
|||||||
out.defaultWriteObject();
|
out.defaultWriteObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns true if this transaction's sequence number is set (ie it may be a part of a time-locked transaction)
|
||||||
|
*/
|
||||||
public boolean hasSequence() {
|
public boolean hasSequence() {
|
||||||
return sequence != NO_SEQUENCE;
|
return sequence != NO_SEQUENCE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user