78{
80 sources.clear();
81
83 std::unordered_set<size_t> selected_idx;
84 std::unordered_set<crypto::key_image> selected_kis;
86 size_t roffset = offset >= 0 ? offset : ntrans - offset - 1;
87 size_t iters = 0;
89 size_t cur_utxo = 0;
90 bool abort = false;
91 unsigned brk_cond = 0;
92 unsigned brk_thresh = num_utxo && min_amount ? 2 : (num_utxo || min_amount ? 1 : 0);
93
94#define EVAL_BRK_COND() do { \
95 brk_cond = 0; \
96 if (num_utxo && num_utxo.get() <= cur_utxo) \
97 brk_cond += 1; \
98 if (min_amount && min_amount.get() <= sum) \
99 brk_cond += 1; \
100 } while(0)
101
102 for(ssize_t i = roffset; iters < ntrans && !abort; i += step, ++iters)
103 {
105 if (brk_cond >= brk_thresh)
106 break;
107
108 i = i < 0 ? (i + ntrans) : i % ntrans;
109 auto & td = transfers[i];
110 if (td.m_spent)
111 continue;
113 continue;
114 if (selected_idx.find((size_t)i) != selected_idx.end()){
115 MERROR(
"Should not happen (selected_idx not found): " << i);
116 continue;
117 }
118 if (selected_kis.find(td.m_key_image) != selected_kis.end()){
119 MERROR(
"Should not happen (selected KI): " << i <<
"ki: " <<
dump_keys(td.m_key_image.data));
120 continue;
121 }
122
123 try {
124 cryptonote::tx_source_entry src;
126
127
128 if (fnc_accept){
129 tx_source_info_crate_t c_info{.td=&td, .src=&src, .selected_idx=&selected_idx, .selected_kis=&selected_kis,
130 .ntrans=ntrans, .iters=iters, .sum=sum, .cur_utxo=cur_utxo};
131
132 bool take_it = (fnc_accept.get())(c_info, abort);
133 if (!take_it){
134 continue;
135 }
136 }
137
139 <<
" ki: " <<
dump_keys(td.m_key_image.data)
140 << " amnt: " << td.amount()
141 << " rct: " << td.is_rct()
142 << " glob: " << td.m_global_output_index);
143
144 sum += td.amount();
145 cur_utxo += 1;
146
147 sources.emplace_back(src);
148 selected.push_back((size_t)i);
149 selected_idx.insert((size_t)i);
150 selected_kis.insert(td.m_key_image);
151
152 } catch(const std::exception &e){
154 << ", amnt: " << td.amount() << ", rct: " << td.is_rct()
155 << ", glob: " << td.m_global_output_index << " is not applicable: " << e.what());
156 }
157 }
158
160 return brk_cond >= brk_thresh;
161#undef EVAL_BRK_COND
162}
std::string dump_keys(T *buff32)
static tools::wallet2::transfer_container & get_transfers(tools::wallet2 *wallet)
#define CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
unsigned __int64 uint64_t