kernel: Add API function for getting a tx input's nSequence
What changed, and why it matters
This commit simply adds a new read-only function to the Bitcoin Core kernel library that lets callers retrieve a transaction input's nSequence value. It is a straightforward API addition with no security implications.
No security action needed; review as normal API addition.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change exposes the existing CTransactionInput::nSequence field through a new kernel API function (btck_transaction_input_get_sequence), its C header declaration, a C++ wrapper helper, and a unit test verifying the value is returned correctly. No logic is modified; only a getter is added.
Changed components
src/kernel/bitcoinkernel.cppsrc/kernel/bitcoinkernel.hsrc/kernel/bitcoinkernel_wrapper.hsrc/test/kernel/test_kernel.cppInspect captured patch +21 / −0
diff --git a/src/kernel/bitcoinkernel.cpp b/src/kernel/bitcoinkernel.cpp
index b0ce1721..4216bf92 100644
--- a/src/kernel/bitcoinkernel.cpp
+++ b/src/kernel/bitcoinkernel.cpp
@@ -697,6 +697,11 @@ const btck_TransactionOutPoint* btck_transaction_input_get_out_point(const btck_
return btck_TransactionOutPoint::ref(&btck_TransactionInput::get(input).prevout);
}
+uint32_t btck_transaction_input_get_sequence(const btck_TransactionInput* input)
+{
+ return btck_TransactionInput::get(input).nSequence;
+}
+
void btck_transaction_input_destroy(btck_TransactionInput* input)
{
delete input;
diff --git a/src/kernel/bitcoinkernel.h b/src/kernel/bitcoinkernel.h
index 1513ae3f..fe5bc3f9 100644
--- a/src/kernel/bitcoinkernel.h
+++ b/src/kernel/bitcoinkernel.h
@@ -1514,6 +1514,15 @@ BITCOINKERNEL_API btck_TransactionInput* BITCOINKERNEL_WARN_UNUSED_RESULT btck_t
BITCOINKERNEL_API const btck_TransactionOutPoint* BITCOINKERNEL_WARN_UNUSED_RESULT btck_transaction_input_get_out_point(
const btck_TransactionInput* transaction_input) BITCOINKERNEL_ARG_NONNULL(1);
+/**
+ * @brief Get a transaction input's nSequence value.
+ *
+ * @param[in] transaction_input Non-null.
+ * @return The nSequence value.
+ */
+BITCOINKERNEL_API uint32_t BITCOINKERNEL_WARN_UNUSED_RESULT btck_transaction_input_get_sequence(
+ const btck_TransactionInput* transaction_input) BITCOINKERNEL_ARG_NONNULL(1);
+
/**
* Destroy the transaction input.
*/
diff --git a/src/kernel/bitcoinkernel_wrapper.h b/src/kernel/bitcoinkernel_wrapper.h
index 83ec5d02..fd234857 100644
--- a/src/kernel/bitcoinkernel_wrapper.h
+++ b/src/kernel/bitcoinkernel_wrapper.h
@@ -551,6 +551,11 @@ public:
{
return OutPointView{btck_transaction_input_get_out_point(impl())};
}
+
+ uint32_t GetSequence() const
+ {
+ return btck_transaction_input_get_sequence(impl());
+ }
};
class TransactionInputView : public View<btck_TransactionInput>, public TransactionInputApi<TransactionInputView>
diff --git a/src/test/kernel/test_kernel.cpp b/src/test/kernel/test_kernel.cpp
index ab5d694f..d4a8647b 100644
--- a/src/test/kernel/test_kernel.cpp
+++ b/src/test/kernel/test_kernel.cpp
@@ -404,6 +404,8 @@ BOOST_AUTO_TEST_CASE(btck_transaction_tests)
BOOST_CHECK_EQUAL(tx.GetLocktime(), 510826);
auto broken_tx_data{std::span<std::byte>{tx_data.begin(), tx_data.begin() + 10}};
BOOST_CHECK_THROW(Transaction{broken_tx_data}, std::runtime_error);
+ auto input{tx.GetInput(0)};
+ BOOST_CHECK_EQUAL(input.GetSequence(), 0xfffffffe);
auto output{tx.GetOutput(tx.CountOutputs() - 1)};
BOOST_CHECK_EQUAL(output.Amount(), 42130042);
auto script_pubkey{output.GetScriptPubkey()};
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.