From 2d39db7aa128a948b6ad11242591ef26a342f5b1 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Wed, 1 Jun 2022 17:39:58 -0400 Subject: 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). --- src/wallet/coincontrol.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'src/wallet/coincontrol.cpp') 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 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 CCoinControl::GetSequence(const COutPoint& outpoint) con return it != m_selected.end() ? it->second.GetSequence() : std::nullopt; } +std::pair, std::optional> 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 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> PreselectedInput::GetScripts() const +{ + return {m_script_sig, m_script_witness}; +} + +void PreselectedInput::SetPosition(unsigned int pos) +{ + m_pos = pos; +} + +std::optional PreselectedInput::GetPosition() const +{ + return m_pos; +} } // namespace wallet -- cgit v1.2.3