fix: crash of checkandpush when outputs are not found

This commit is contained in:
moneroexamples 2018-03-21 09:17:08 +08:00
parent 18e222481f
commit 0ce61ea930

View file

@ -267,6 +267,8 @@ namespace xmreg
return ss.str(); return ss.str();
} }
~tx_details() {};
}; };
@ -5661,15 +5663,12 @@ namespace xmreg
vector<vector<uint64_t>> mixin_timestamp_groups; vector<vector<uint64_t>> mixin_timestamp_groups;
// make timescale maps for mixins in input // make timescale maps for mixins in input
for (const txin_to_key &in_key: txd.input_key_imgs) for (const txin_to_key &in_key: txd.input_key_imgs)
{ {
if (show_part_of_inputs && (input_idx > max_no_of_inputs_to_show)) if (show_part_of_inputs && (input_idx > max_no_of_inputs_to_show))
{
break; break;
}
// get absolute offsets of mixins // get absolute offsets of mixins
std::vector<uint64_t> absolute_offsets std::vector<uint64_t> absolute_offsets
@ -5681,11 +5680,45 @@ namespace xmreg
try try
{ {
// before proceeding with geting the outputs based on the amount and absolute offset
// check how many outputs there are for that amount
uint64_t no_outputs = core_storage->get_db().get_num_outputs(in_key.amount);
bool offset_too_large {false};
int offset_idx {-1};
for (auto o: absolute_offsets)
{
offset_idx++;
if (o >= no_outputs)
{
offset_too_large = true;
cerr << "Absolute offset (" << o << ") of an output in a key image "
<< pod_to_hex(in_key.k_image)
<< " (ring member no: " << offset_idx << ") "
<< "for amount " << in_key.amount
<< " is too large. There are only "
<< no_outputs << " such outputs!\n";
continue;
}
offset_too_large = false;
}
// go to next input if a too large offset was found
if (offset_too_large)
continue;
// offsets seems good, so try to get the outputs for the amount and
// offsets given
core_storage->get_db().get_output_key(in_key.amount, core_storage->get_db().get_output_key(in_key.amount,
absolute_offsets, absolute_offsets,
outputs); outputs);
} }
catch (const OUTPUT_DNE &e) catch (const std::exception& e)
{ {
string out_msg = fmt::format( string out_msg = fmt::format(
"Outputs with amount {:d} do not exist and indexes ", "Outputs with amount {:d} do not exist and indexes ",
@ -5695,9 +5728,9 @@ namespace xmreg
for (auto offset: absolute_offsets) for (auto offset: absolute_offsets)
out_msg += ", " + to_string(offset); out_msg += ", " + to_string(offset);
out_msg += " don't exist!"; out_msg += " don't exist! " + string {e.what()};
cerr << out_msg << endl; cerr << out_msg << '\n';
context["has_error"] = true; context["has_error"] = true;
context["error_msg"] = out_msg; context["error_msg"] = out_msg;
@ -5925,8 +5958,8 @@ namespace xmreg
// thus for them, we print N/A // thus for them, we print N/A
if (!out_amount_indices.empty()) if (!out_amount_indices.empty())
{ {
out_amount_index_str = fmt::format("{:d}", out_amount_index_str
out_amount_indices.at(output_idx)); = std::to_string(out_amount_indices.at(output_idx));
} }
outputs_xmr_sum += outp.second; outputs_xmr_sum += outp.second;
@ -5939,7 +5972,8 @@ namespace xmreg
{"unformated_output_idx" , output_idx}, {"unformated_output_idx" , output_idx},
{"output_idx" , fmt::format("{:02d}", output_idx++)} {"output_idx" , fmt::format("{:02d}", output_idx++)}
}); });
}
} // for (pair<txout_to_key, uint64_t>& outp: txd.output_pub_keys)
context["outputs_xmr_sum"] = xmreg::xmr_amount_to_str(outputs_xmr_sum); context["outputs_xmr_sum"] = xmreg::xmr_amount_to_str(outputs_xmr_sum);