MCPcopy Create free account
hub / github.com/ElementsProject/elements / EquivalentResult

Function EquivalentResult

src/wallet/test/coinselector_tests.cpp:116–131  ·  view source on GitHub ↗

Check if SelectionResult a is equivalent to SelectionResult b. * Equivalent means same input values, but maybe different inputs (i.e. same value, different prevout) */

Source from the content-addressed store, hash-verified

114/** Check if SelectionResult a is equivalent to SelectionResult b.
115 * Equivalent means same input values, but maybe different inputs (i.e. same value, different prevout) */
116static bool EquivalentResult(const SelectionResult& a, const SelectionResult& b)
117{
118 std::vector<CAmount> a_amts;
119 std::vector<CAmount> b_amts;
120 for (const auto& coin : a.GetInputSet()) {
121 a_amts.push_back(coin.txout.nValue.GetAmount());
122 }
123 for (const auto& coin : b.GetInputSet()) {
124 b_amts.push_back(coin.txout.nValue.GetAmount());
125 }
126 std::sort(a_amts.begin(), a_amts.end());
127 std::sort(b_amts.begin(), b_amts.end());
128
129 std::pair<std::vector<CAmount>::iterator, std::vector<CAmount>::iterator> ret = std::mismatch(a_amts.begin(), a_amts.end(), b_amts.begin());
130 return ret.first == a_amts.end() && ret.second == b_amts.end();
131}
132
133/** Check if this selection is equal to another one. Equal means same inputs (i.e same value and prevout) */
134static bool EqualResult(const SelectionResult& a, const SelectionResult& b)

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 4

GetAmountMethod · 0.80
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected