Skip to content

Commit 5148f98

Browse files
authored
Merge pull request #1609 from evoskuil/master
Add relative locktime helpers.
2 parents 4724ac8 + 65aae3f commit 5148f98

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

include/bitcoin/system/chain/input.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class BC_API input
4343

4444
typedef std::shared_ptr<const input> cptr;
4545

46+
static bool is_relative_locktime_applied(uint32_t sequence) NOEXCEPT;
4647
static bool is_locked(uint32_t sequence, size_t height,
4748
uint32_t median_time_past, size_t prevout_height,
4849
uint32_t prevout_median_time_past) NOEXCEPT;

include/bitcoin/system/chain/transaction.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class BC_API transaction
4545
typedef std::shared_ptr<const transaction> cptr;
4646
typedef input_cptrs::const_iterator input_iterator;
4747

48+
// BIP68: if bit 31 is set then no consensus meaning is applied.
49+
static bool is_relative_locktime_applied(bool coinbase, uint32_t version,
50+
uint32_t sequence) NOEXCEPT;
51+
4852
/// Not genesis and at least 100 blocks deep.
4953
static bool is_coinbase_mature(size_t coinbase_height,
5054
size_t height) NOEXCEPT;

src/chain/input.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,19 @@ bool input::is_roller() const NOEXCEPT
388388
return script_->is_roller() || (prevout && prevout->script().is_roller());
389389
}
390390

391+
// static
392+
bool input::is_relative_locktime_applied(uint32_t sequence) NOEXCEPT
393+
{
394+
// BIP68: if bit 31 is set then no consensus meaning is applied.
395+
return !get_right(sequence, relative_locktime_disabled_bit);
396+
}
397+
391398
// static
392399
bool input::is_locked(uint32_t sequence, size_t height,
393400
uint32_t median_time_past, size_t prevout_height,
394401
uint32_t prevout_median_time_past) NOEXCEPT
395402
{
396-
// BIP68: if bit 31 is set then no consensus meaning is applied.
397-
if (get_right(sequence, relative_locktime_disabled_bit))
403+
if (!is_relative_locktime_applied(sequence))
398404
return false;
399405

400406
// BIP68: the low 16 bits of the sequence apply to relative lock-time.

src/chain/transaction.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@ constexpr bool is_non_coinbase_mature(size_t tx_height, size_t height) NOEXCEPT
11151115
return tx_height <= height;
11161116
}
11171117

1118+
// static
11181119
//*****************************************************************************
11191120
// CONSENSUS: Coinbase output matures at 100 blocks depth.
11201121
// CONSENSUS: Genesis coinbase is forever immature (exception).
@@ -1141,6 +1142,17 @@ bool transaction::is_immature(size_t height) const NOEXCEPT
11411142
return !std::all_of(inputs_->begin(), inputs_->end(), mature);
11421143
}
11431144

1145+
// static
1146+
bool transaction::is_relative_locktime_applied(bool coinbase, uint32_t version,
1147+
uint32_t sequence) NOEXCEPT
1148+
{
1149+
// BIP68: not applied to the sequence of the input of a coinbase.
1150+
// BIP68: if bit 31 is set then no consensus meaning is applied.
1151+
// BIP68: applied to txs with a version greater than or equal to two.
1152+
return !coinbase && input::is_relative_locktime_applied(sequence) &&
1153+
(version >= relative_locktime_min_version);
1154+
}
1155+
11441156
bool transaction::is_internal_lock(const input& in) const NOEXCEPT
11451157
{
11461158
// BIP68: not applied to the sequence of the input of a coinbase.

0 commit comments

Comments
 (0)