aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/coincontrol.cpp
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2022-06-01 17:39:58 -0400
committerAndrew Chow <github@achow101.com>2023-12-08 17:12:19 -0500
commit2d39db7aa128a948b6ad11242591ef26a342f5b1 (patch)
treea235dad9cfb243d3a1dffec56971f491e5ad275d /src/wallet/coincontrol.cpp
parent14e50746f683361f4d511d384d6f1dc44ed2bf10 (diff)
downloadbitcoin-2d39db7aa128a948b6ad11242591ef26a342f5b1.tar.xz
wallet: Explicitly preserve scriptSig and scriptWitness in CreateTransaction
When creating a transaction with preset inputs, also preserve the scriptSig and scriptWitness for those preset inputs if they are provided (e.g. in fundrawtransaction).
Diffstat (limited to 'src/wallet/coincontrol.cpp')
-rw-r--r--src/wallet/coincontrol.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/wallet/coincontrol.cpp b/src/wallet/coincontrol.cpp
index f13b7073be..873c5ab383 100644
--- a/src/wallet/coincontrol.cpp
+++ b/src/wallet/coincontrol.cpp
@@ -39,7 +39,10 @@ std::optional<CTxOut> CCoinControl::GetExternalOutput(const COutPoint& outpoint)
PreselectedInput& CCoinControl::Select(const COutPoint& outpoint)
{
- return m_selected[outpoint];
+ auto& input = m_selected[outpoint];
+ input.SetPosition(m_selection_pos);
+ ++m_selection_pos;
+ return input;
}
void CCoinControl::UnSelect(const COutPoint& outpoint)
{
@@ -78,6 +81,12 @@ std::optional<uint32_t> CCoinControl::GetSequence(const COutPoint& outpoint) con
return it != m_selected.end() ? it->second.GetSequence() : std::nullopt;
}
+std::pair<std::optional<CScript>, std::optional<CScriptWitness>> CCoinControl::GetScripts(const COutPoint& outpoint) const
+{
+ const auto it = m_selected.find(outpoint);
+ return it != m_selected.end() ? m_selected.at(outpoint).GetScripts() : std::make_pair(std::nullopt, std::nullopt);
+}
+
void PreselectedInput::SetTxOut(const CTxOut& txout)
{
m_txout = txout;
@@ -113,4 +122,34 @@ std::optional<uint32_t> PreselectedInput::GetSequence() const
{
return m_sequence;
}
+
+void PreselectedInput::SetScriptSig(const CScript& script)
+{
+ m_script_sig = script;
+}
+
+void PreselectedInput::SetScriptWitness(const CScriptWitness& script_wit)
+{
+ m_script_witness = script_wit;
+}
+
+bool PreselectedInput::HasScripts() const
+{
+ return m_script_sig.has_value() || m_script_witness.has_value();
+}
+
+std::pair<std::optional<CScript>, std::optional<CScriptWitness>> PreselectedInput::GetScripts() const
+{
+ return {m_script_sig, m_script_witness};
+}
+
+void PreselectedInput::SetPosition(unsigned int pos)
+{
+ m_pos = pos;
+}
+
+std::optional<unsigned int> PreselectedInput::GetPosition() const
+{
+ return m_pos;
+}
} // namespace wallet