Formatting and small fixes here and there.

pull/85/head
moneroexamples 6 years ago
parent a1a44af6ae
commit 774cc71ab0

@ -282,7 +282,7 @@ MySqlAccounts::insert(const T& data_to_insert)
}
catch (std::exception const& e)
{
;
MYSQL_EXCEPTION_MSG(e);;
}
return 0;
@ -320,7 +320,6 @@ MySqlAccounts::insert(const vector<T>& data_to_insert)
catch (std::exception const& e)
{
MYSQL_EXCEPTION_MSG(e);
//throw e;
}
return 0;
@ -352,7 +351,6 @@ MySqlAccounts::select(uint64_t account_id, vector<T>& selected_data)
catch (std::exception const& e)
{
MYSQL_EXCEPTION_MSG(e);
//throw e;
}
return false;
@ -399,7 +397,6 @@ MySqlAccounts::update(T const& orginal_row, T const& new_row)
catch (std::exception const& e)
{
MYSQL_EXCEPTION_MSG(e);
//throw e;
}
return false;
@ -636,4 +633,4 @@ MySqlAccounts::_init()
mysql_payment = make_shared<MysqlPayments>(conn);
}
}
}

@ -15,7 +15,7 @@ OutputInputIdentification::OutputInputIdentification(
crypto::hash const& _tx_hash,
bool is_coinbase,
std::shared_ptr<CurrentBlockchainStatus> _current_bc_status)
: total_received {0}, mixin_no {0}, current_bc_status {_current_bc_status}
: current_bc_status {_current_bc_status}
{
address_info = _a;
viewkey = _v;
@ -36,13 +36,13 @@ OutputInputIdentification::OutputInputIdentification(
if (!generate_key_derivation(tx_pub_key, *viewkey, derivation))
{
cerr << "Cant get derived key for: " << "\n"
OMERROR << "Cant get derived key for: " << "\n"
<< "pub_tx_key: " << get_tx_pub_key_str() << " and "
<< "prv_view_key" << viewkey << endl;
<< "prv_view_key" << viewkey;;
throw OutputInputIdentificationException("Cant get derived key for a tx");
throw OutputInputIdentificationException(
"Cant get derived key for a tx");
}
}
uint64_t
@ -58,7 +58,8 @@ void
OutputInputIdentification::identify_outputs()
{
// <public_key , amount , out idx>
vector<tuple<txout_to_key, uint64_t, uint64_t>> outputs = get_ouputs_tuple(*tx);
vector<tuple<txout_to_key, uint64_t, uint64_t>> outputs
= get_ouputs_tuple(*tx);
for (auto& out: outputs)
{
@ -99,17 +100,24 @@ OutputInputIdentification::identify_outputs()
{
bool r;
// for ringct non-coinbase txs, these values are provided with txs.
// for ringct non-coinbase txs, these values are given
// with txs.
// coinbase ringctx dont have this information. we will provide
// them only when needed, in get_unspent_outputs. So go there
// to see how we deal with ringct coinbase txs when we spent them
// to see how we deal with ringct coinbase txs when we spent
// them
// go to CurrentBlockchainStatus::construct_output_rct_field
// to see how we deal with coinbase ringct that are used as mixins
rtc_outpk = pod_to_hex(tx->rct_signatures.outPk[output_idx_in_tx].mask);
rtc_mask = pod_to_hex(tx->rct_signatures.ecdhInfo[output_idx_in_tx].mask);
rtc_amount = pod_to_hex(tx->rct_signatures.ecdhInfo[output_idx_in_tx].amount);
rct::key mask = tx->rct_signatures.ecdhInfo[output_idx_in_tx].mask;
// to see how we deal with coinbase ringct that are used
// as mixins
rtc_outpk = pod_to_hex(tx->rct_signatures
.outPk[output_idx_in_tx].mask);
rtc_mask = pod_to_hex(tx->rct_signatures
.ecdhInfo[output_idx_in_tx].mask);
rtc_amount = pod_to_hex(tx->rct_signatures
.ecdhInfo[output_idx_in_tx].amount);
rct::key mask = tx->rct_signatures
.ecdhInfo[output_idx_in_tx].mask;
r = decode_ringct(tx->rct_signatures,
tx_pub_key,
@ -120,8 +128,9 @@ OutputInputIdentification::identify_outputs()
if (!r)
{
cerr << "Cant decode ringCT!" << endl;
throw OutputInputIdentificationException("Cant decode ringCT!");
OMERROR << "Cant decode ringCT!";
throw OutputInputIdentificationException(
"Cant decode ringCT!");
}
amount = rct_amount_val;
@ -163,30 +172,30 @@ OutputInputIdentification::identify_inputs(
= cryptonote::relative_output_offsets_to_absolute(
in_key.key_offsets);
// get public keys of outputs used in the mixins that match to the offests
// get public keys of outputs used in the mixins that
// match to the offests
std::vector<cryptonote::output_data_t> mixin_outputs;
if (!current_bc_status->get_output_keys(in_key.amount,
absolute_offsets,
mixin_outputs))
{
cerr << "Mixins key images not found" << endl;
OMERROR << "Mixins key images not found";
continue;
}
// mixin counter
size_t count = 0;
// indicates whether we found any matching mixin in the current input
bool found_a_match {false};
// for each found output public key check if its ours or not
for (const uint64_t& abs_offset: absolute_offsets)
for (size_t count = 0; count < absolute_offsets.size(); ++count)
{
// get basic information about mixn's output
cryptonote::output_data_t output_data = mixin_outputs[count];
cryptonote::output_data_t const& output_data
= mixin_outputs[count];
//cout << " - output_public_key_str: " << output_public_key_str << endl;
//cout << " - output_public_key_str: "
// << output_public_key_str;
// before going to the mysql, check our known outputs cash
// if the key exists. Its much faster than going to mysql
@ -208,8 +217,6 @@ OutputInputIdentification::identify_inputs(
}
++count;
} // for (const cryptonote::output_data_t& output_data: outputs)
if (found_a_match == false)
@ -228,7 +235,7 @@ OutputInputIdentification::identify_inputs(
break;
}
} // for (const txin_to_key& in_key: input_key_imgs)
} // for (count = 0; count < absolute_offsets.size(); ++count)
}

@ -2,8 +2,7 @@
// Created by mwo on 13/02/17.
//
#ifndef RESTBED_XMR_OUTPUTINPUTIDENTIFICATION_H
#define RESTBED_XMR_OUTPUTINPUTIDENTIFICATION_H
#pragma once
#include "CurrentBlockchainStatus.h"
#include "tools.h"
@ -40,7 +39,8 @@ class OutputInputIdentificationException: public std::runtime_error
* because we dont have spendkey. But what we can do is, we can look for
* candidate key images. And this can be achieved by checking if any mixin
* in associated with the given key image, is our output. If it is our output,
* then we assume its our key image (i.e. we spend this output). Off course this is only
* then we assume its our key image (i.e. we spend this output). Off course
* this is only
* assumption as our outputs can be used in key images of others for their
* mixin purposes. Thus, we sent to the frontend the list of key images
* that we think are yours, and the frontend, because it has spendkey,
@ -85,7 +85,9 @@ public:
bool is_rct;
uint8_t rct_type;
uint64_t mixin_no {};
uint64_t total_received {0};
uint64_t mixin_no {0};
// for each output, in a tx, check if it belongs
// to the given account of specific address and viewkey
@ -95,8 +97,6 @@ public:
key_derivation derivation;
uint64_t total_received;
vector<output_info> identified_outputs;
vector<input_info> identified_inputs;
@ -107,7 +107,8 @@ public:
const transaction* _tx,
crypto::hash const& _tx_hash,
bool is_coinbase,
std::shared_ptr<CurrentBlockchainStatus> _current_bc_status);
std::shared_ptr<CurrentBlockchainStatus>
_current_bc_status);
/**
* FIRST step. search for the incoming xmr using address, viewkey and
@ -135,7 +136,8 @@ public:
*
*/
void
identify_inputs(unordered_map<public_key, uint64_t> const& known_outputs_keys);
identify_inputs(unordered_map<public_key, uint64_t> const&
known_outputs_keys);
string const&
get_tx_hash_str();
@ -157,9 +159,6 @@ private:
// transaction that is beeing search
const transaction* tx;
};
}
#endif //RESTBED_XMR_OUTPUTINPUTIDENTIFICATION_H

@ -289,6 +289,7 @@ TxSearch::operator()()
if (tx_mysql_id == 0)
{
OMERROR << "tx_mysql_id is zero!" << tx_data;
throw TxSearchException("tx_mysql_id is zero!");
}
@ -322,7 +323,7 @@ TxSearch::operator()()
std::lock_guard<std::mutex> lck (
getting_known_outputs_keys);
known_outputs_keys.insert(
{out_info.pub_key, out_info.amount});
{out_info.pub_key, out_info.amount});
}
} // for (auto& out_info: oi_identification.identified_outputs)
@ -333,8 +334,7 @@ TxSearch::operator()()
= xmr_accounts->insert(outputs_found);
if (no_rows_inserted == 0)
{
OMERROR << "out_mysql_id is zero!";
{
throw TxSearchException("no_rows_inserted is zero!");
}
@ -378,9 +378,11 @@ TxSearch::operator()()
// above. So there is no risk of deleting same tx twice
if (!delete_existing_tx_if_exists(
oi_identification.get_tx_hash_str()))
{
throw TxSearchException(
"Cant delete tx "
+ oi_identification.tx_hash_str);
}
}
if (blockchain_tx_id == 0)
@ -491,6 +493,8 @@ TxSearch::operator()()
if (tx_mysql_id == 0)
{
OMERROR << "tx_mysql_id is zero!" << tx_data;
//cerr << "tx_mysql_id is zero!" << endl;
throw TxSearchException("tx_mysql_id is zero!");
// it did not insert this tx, because maybe

@ -207,15 +207,17 @@ YourMoneroRequests::get_address_txs(
// for this to continue, search thread must have already been
// created and still exisits.
if (current_bc_status->search_thread_exist(xmr_address))
{
// if (current_bc_status->search_thread_exist(xmr_address))
// {
if (login_and_start_search_thread(xmr_address, view_key, acc, j_response))
{
// populate acc and check view_key
if (!login_and_start_search_thread(xmr_address, view_key, acc, j_response))
{
// some error with loggin in or search thread start
session_close(session, j_response.dump());
return;
}
// if (!login_and_start_search_thread(xmr_address, view_key, acc, j_response))
// {
// // some error with loggin in or search thread start
// session_close(session, j_response.dump());
// return;
// }
// before fetching txs, check if provided view key
// is correct. this is simply to ensure that
@ -427,16 +429,8 @@ YourMoneroRequests::get_address_info(
// for this to continue, search thread must have already been
// created and still exisits.
if (current_bc_status->search_thread_exist(xmr_address))
if (login_and_start_search_thread(xmr_address, view_key, acc, j_response))
{
// populate acc and check view_key
if (!login_and_start_search_thread(xmr_address, view_key, acc, j_response))
{
// some error with loggin in or search thread start
session_close(session, j_response.dump());
return;
}
uint64_t total_received {0};
// ping the search thread that we still need it.

Loading…
Cancel
Save