From 3061734993a1c2f535f1661d489e8d32be116762 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Wed, 30 Aug 2017 18:14:21 +0200 Subject: [PATCH] Move SEQUENCE_LOCKTIME_* flags from Transaction to TransactionInput. --- .../main/java/org/bitcoinj/core/Transaction.java | 14 -------------- .../java/org/bitcoinj/core/TransactionInput.java | 15 +++++++++++++++ .../src/main/java/org/bitcoinj/script/Script.java | 10 +++++----- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/Transaction.java b/core/src/main/java/org/bitcoinj/core/Transaction.java index 908cd5f65..7bd96c12c 100644 --- a/core/src/main/java/org/bitcoinj/core/Transaction.java +++ b/core/src/main/java/org/bitcoinj/core/Transaction.java @@ -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; diff --git a/core/src/main/java/org/bitcoinj/core/TransactionInput.java b/core/src/main/java/org/bitcoinj/core/TransactionInput.java index 24c8cbd56..1143c0404 100644 --- a/core/src/main/java/org/bitcoinj/core/TransactionInput.java +++ b/core/src/main/java/org/bitcoinj/core/TransactionInput.java @@ -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; diff --git a/core/src/main/java/org/bitcoinj/script/Script.java b/core/src/main/java/org/bitcoinj/script/Script.java index 6f1268900..7a088ed2b 100644 --- a/core/src/main/java/org/bitcoinj/script/Script.java +++ b/core/src/main/java/org/bitcoinj/script/Script.java @@ -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; }