mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-24 14:50:57 +01:00
Move SEQUENCE_LOCKTIME_* flags from Transaction to TransactionInput.
This commit is contained in:
parent
9a3006d03c
commit
3061734993
3 changed files with 20 additions and 19 deletions
|
@ -195,20 +195,6 @@ public class Transaction extends ChildMessage {
|
|||
@Nullable
|
||||
private String memo;
|
||||
|
||||
/* Below flags apply in the context of BIP 68 */
|
||||
/* If this flag set, CTxIn::nSequence is NOT interpreted as a
|
||||
* relative lock-time. */
|
||||
public static final long SEQUENCE_LOCKTIME_DISABLE_FLAG = 1L << 31;
|
||||
|
||||
/* If CTxIn::nSequence encodes a relative lock-time and this flag
|
||||
* is set, the relative lock-time has units of 512 seconds,
|
||||
* otherwise it specifies blocks with a granularity of 1. */
|
||||
public static final long SEQUENCE_LOCKTIME_TYPE_FLAG = 1L << 22;
|
||||
|
||||
/* If CTxIn::nSequence encodes a relative lock-time, this mask is
|
||||
* applied to extract that lock-time from the sequence field. */
|
||||
public static final long SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
|
||||
|
||||
public Transaction(NetworkParameters params) {
|
||||
super(params);
|
||||
version = 1;
|
||||
|
|
|
@ -48,6 +48,21 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
public class TransactionInput extends ChildMessage {
|
||||
/** Magic sequence number that indicates there is no sequence number. */
|
||||
public static final long NO_SEQUENCE = 0xFFFFFFFFL;
|
||||
/**
|
||||
* BIP68: If this flag set, sequence is NOT interpreted as a relative lock-time.
|
||||
*/
|
||||
public static final long SEQUENCE_LOCKTIME_DISABLE_FLAG = 1L << 31;
|
||||
/**
|
||||
* BIP68: If sequence encodes a relative lock-time and this flag is set, the relative lock-time has units of 512
|
||||
* seconds, otherwise it specifies blocks with a granularity of 1.
|
||||
*/
|
||||
public static final long SEQUENCE_LOCKTIME_TYPE_FLAG = 1L << 22;
|
||||
/**
|
||||
* BIP68: If sequence encodes a relative lock-time, this mask is applied to extract that lock-time from the sequence
|
||||
* field.
|
||||
*/
|
||||
public static final long SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
|
||||
|
||||
private static final byte[] EMPTY_ARRAY = new byte[0];
|
||||
// Magic outpoint index that indicates the input is in fact unconnected.
|
||||
private static final long UNCONNECTED = 0xFFFFFFFFL;
|
||||
|
|
|
@ -1453,7 +1453,7 @@ public class Script {
|
|||
// To provide for future soft-fork extensibility, if the
|
||||
// operand has the disabled lock-time flag set,
|
||||
// CHECKSEQUENCEVERIFY behaves as a NOP.
|
||||
if ((nSequence & Transaction.SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0)
|
||||
if ((nSequence & TransactionInput.SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0)
|
||||
return;
|
||||
|
||||
// Compare the specified sequence number with the input.
|
||||
|
@ -1475,12 +1475,12 @@ public class Script {
|
|||
// consensus constrained. Testing that the transaction's sequence
|
||||
// number do not have this bit set prevents using this property
|
||||
// to get around a CHECKSEQUENCEVERIFY check.
|
||||
if ((txToSequence & Transaction.SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0)
|
||||
if ((txToSequence & TransactionInput.SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0)
|
||||
return false;
|
||||
|
||||
// Mask off any bits that do not have consensus-enforced meaning
|
||||
// before doing the integer comparisons
|
||||
long nLockTimeMask = Transaction.SEQUENCE_LOCKTIME_TYPE_FLAG | Transaction.SEQUENCE_LOCKTIME_MASK;
|
||||
long nLockTimeMask = TransactionInput.SEQUENCE_LOCKTIME_TYPE_FLAG | TransactionInput.SEQUENCE_LOCKTIME_MASK;
|
||||
long txToSequenceMasked = txToSequence & nLockTimeMask;
|
||||
long nSequenceMasked = nSequence & nLockTimeMask;
|
||||
|
||||
|
@ -1491,8 +1491,8 @@ public class Script {
|
|||
// We want to compare apples to apples, so fail the script
|
||||
// unless the type of nSequenceMasked being tested is the same as
|
||||
// the nSequenceMasked in the transaction.
|
||||
if (!((txToSequenceMasked < Transaction.SEQUENCE_LOCKTIME_TYPE_FLAG && nSequenceMasked < Transaction.SEQUENCE_LOCKTIME_TYPE_FLAG) ||
|
||||
(txToSequenceMasked >= Transaction.SEQUENCE_LOCKTIME_TYPE_FLAG && nSequenceMasked >= Transaction.SEQUENCE_LOCKTIME_TYPE_FLAG))) {
|
||||
if (!((txToSequenceMasked < TransactionInput.SEQUENCE_LOCKTIME_TYPE_FLAG && nSequenceMasked < TransactionInput.SEQUENCE_LOCKTIME_TYPE_FLAG) ||
|
||||
(txToSequenceMasked >= TransactionInput.SEQUENCE_LOCKTIME_TYPE_FLAG && nSequenceMasked >= TransactionInput.SEQUENCE_LOCKTIME_TYPE_FLAG))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue