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
1 changed files with 5539 additions and 5505 deletions

View File

@ -117,21 +117,21 @@ namespace xmreg
{
using namespace cryptonote;
using namespace crypto;
using namespace std;
using namespace cryptonote;
using namespace crypto;
using namespace std;
using epee::string_tools::pod_to_hex;
using epee::string_tools::hex_to_pod;
using epee::string_tools::pod_to_hex;
using epee::string_tools::hex_to_pod;
/**
* @brief The tx_details struct
*
* Basic information about tx
*
*/
struct tx_details
{
* @brief The tx_details struct
*
* Basic information about tx
*
*/
struct tx_details
{
crypto::hash hash;
crypto::hash prefix_hash;
crypto::public_key pk;
@ -267,11 +267,13 @@ namespace xmreg
return ss.str();
}
};
~tx_details() {};
};
class page
{
class page
{
static const bool FULL_AGE_FORMAT {true};
@ -338,7 +340,7 @@ namespace xmreg
lru_cache_t<tx_info_cache::key, tx_info_cache> tx_context_cache;
public:
public:
page(MicroCore* _mcore,
Blockchain* _core_storage,
@ -5257,7 +5259,7 @@ namespace xmreg
}
private:
private:
string
@ -5661,15 +5663,12 @@ namespace xmreg
vector<vector<uint64_t>> mixin_timestamp_groups;
// make timescale maps for mixins in input
for (const txin_to_key &in_key: txd.input_key_imgs)
{
if (show_part_of_inputs && (input_idx > max_no_of_inputs_to_show))
{
break;
}
// get absolute offsets of mixins
std::vector<uint64_t> absolute_offsets
@ -5681,11 +5680,45 @@ namespace xmreg
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,
absolute_offsets,
outputs);
}
catch (const OUTPUT_DNE &e)
catch (const std::exception& e)
{
string out_msg = fmt::format(
"Outputs with amount {:d} do not exist and indexes ",
@ -5695,9 +5728,9 @@ namespace xmreg
for (auto offset: absolute_offsets)
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["error_msg"] = out_msg;
@ -5925,8 +5958,8 @@ namespace xmreg
// thus for them, we print N/A
if (!out_amount_indices.empty())
{
out_amount_index_str = fmt::format("{:d}",
out_amount_indices.at(output_idx));
out_amount_index_str
= std::to_string(out_amount_indices.at(output_idx));
}
outputs_xmr_sum += outp.second;
@ -5939,7 +5972,8 @@ namespace xmreg
{"unformated_output_idx" , 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);
@ -6301,7 +6335,7 @@ namespace xmreg
}};
}
};
};
}