|
|
|
@ -72,7 +72,7 @@ TxSearch::search()
|
|
|
|
|
|
|
|
|
|
uint64_t loop_timestamp {current_timestamp};
|
|
|
|
|
|
|
|
|
|
if (loop_idx % 5 == 0)
|
|
|
|
|
if (loop_idx % 10 == 0)
|
|
|
|
|
{
|
|
|
|
|
// get loop time every fith iteration. no need to call it
|
|
|
|
|
// all the time.
|
|
|
|
@ -135,12 +135,14 @@ TxSearch::search()
|
|
|
|
|
{
|
|
|
|
|
// print status every 100th block
|
|
|
|
|
|
|
|
|
|
fmt::print(" - searching block {:d} of hash {:s} \n",
|
|
|
|
|
searched_blk_no, pod_to_hex(get_block_hash(blk)));
|
|
|
|
|
cout << " - searching block " << searched_blk_no
|
|
|
|
|
<< " of hash: "
|
|
|
|
|
<< searched_blk_no << get_block_hash(blk) << '\n';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DateTime blk_timestamp_mysql_format
|
|
|
|
|
= XmrTransaction::timestamp_to_DateTime(blk.timestamp);
|
|
|
|
|
// we will only create mysql DateTime object once, anything is found
|
|
|
|
|
// in a given block;
|
|
|
|
|
unique_ptr<DateTime> blk_timestamp_mysql_format;
|
|
|
|
|
|
|
|
|
|
// searching for our incoming and outgoing xmr has two components.
|
|
|
|
|
//
|
|
|
|
@ -177,7 +179,7 @@ TxSearch::search()
|
|
|
|
|
|
|
|
|
|
if (!CurrentBlockchainStatus::tx_exist(oi_identification.tx_hash, blockchain_tx_id))
|
|
|
|
|
{
|
|
|
|
|
cerr << "Tx " << oi_identification.tx_hash_str
|
|
|
|
|
cerr << "Tx " << oi_identification.get_tx_hash_str()
|
|
|
|
|
<< "not found in blockchain !" << '\n';
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -189,8 +191,9 @@ TxSearch::search()
|
|
|
|
|
|
|
|
|
|
uint64_t tx_mysql_id {0};
|
|
|
|
|
|
|
|
|
|
// start mysql transaction
|
|
|
|
|
mysqlpp::Transaction trans(xmr_accounts->get_connection()->get_connection());
|
|
|
|
|
// create pointer to mysql transaction object
|
|
|
|
|
// that we will initilize if we find something.
|
|
|
|
|
unique_ptr<mysqlpp::Transaction> mysql_transaction;
|
|
|
|
|
|
|
|
|
|
// if we identified some outputs as ours,
|
|
|
|
|
// save them into mysql.
|
|
|
|
@ -230,11 +233,29 @@ TxSearch::search()
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (!blk_timestamp_mysql_format)
|
|
|
|
|
{
|
|
|
|
|
blk_timestamp_mysql_format
|
|
|
|
|
= unique_ptr<DateTime>(
|
|
|
|
|
new DateTime(static_cast<time_t>(blk.timestamp)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mysql_transaction)
|
|
|
|
|
{
|
|
|
|
|
// start mysql transaction here
|
|
|
|
|
mysql_transaction
|
|
|
|
|
= unique_ptr<mysqlpp::Transaction>(
|
|
|
|
|
new mysqlpp::Transaction(
|
|
|
|
|
xmr_accounts->get_connection()
|
|
|
|
|
->get_connection()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XmrTransaction tx_data;
|
|
|
|
|
|
|
|
|
|
tx_data.hash = oi_identification.tx_hash_str;
|
|
|
|
|
tx_data.prefix_hash = oi_identification.tx_prefix_hash_str;
|
|
|
|
|
tx_data.tx_pub_key = oi_identification.tx_pub_key_str;
|
|
|
|
|
tx_data.hash = oi_identification.get_tx_hash_str();
|
|
|
|
|
tx_data.prefix_hash = oi_identification.get_tx_prefix_hash_str();
|
|
|
|
|
tx_data.tx_pub_key = oi_identification.get_tx_pub_key_str();
|
|
|
|
|
tx_data.account_id = acc->id;
|
|
|
|
|
tx_data.blockchain_tx_id = blockchain_tx_id;
|
|
|
|
|
tx_data.total_received = oi_identification.total_received;
|
|
|
|
@ -253,8 +274,8 @@ TxSearch::search()
|
|
|
|
|
tx_data.rct_type = oi_identification.rct_type;
|
|
|
|
|
tx_data.spendable = is_spendable;
|
|
|
|
|
tx_data.payment_id = CurrentBlockchainStatus::get_payment_id_as_string(tx);
|
|
|
|
|
tx_data.mixin = oi_identification.mixin_no;
|
|
|
|
|
tx_data.timestamp = blk_timestamp_mysql_format;
|
|
|
|
|
tx_data.mixin = oi_identification.get_mixin_no();
|
|
|
|
|
tx_data.timestamp = *blk_timestamp_mysql_format;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// insert tx_data into mysql's Transactions table
|
|
|
|
@ -283,7 +304,7 @@ TxSearch::search()
|
|
|
|
|
out_data.account_id = acc->id;
|
|
|
|
|
out_data.tx_id = tx_mysql_id;
|
|
|
|
|
out_data.out_pub_key = out_info.pub_key;
|
|
|
|
|
out_data.tx_pub_key = oi_identification.tx_pub_key_str;
|
|
|
|
|
out_data.tx_pub_key = oi_identification.get_tx_pub_key_str();
|
|
|
|
|
out_data.amount = out_info.amount;
|
|
|
|
|
out_data.out_index = out_info.idx_in_tx;
|
|
|
|
|
out_data.rct_outpk = out_info.rtc_outpk;
|
|
|
|
@ -325,6 +346,26 @@ TxSearch::search()
|
|
|
|
|
// so now, go over those inputs, and check
|
|
|
|
|
// get detail info for each found mixin output from database
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!blk_timestamp_mysql_format)
|
|
|
|
|
{
|
|
|
|
|
blk_timestamp_mysql_format
|
|
|
|
|
= unique_ptr<DateTime>(
|
|
|
|
|
new DateTime(static_cast<time_t>(blk.timestamp)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mysql_transaction)
|
|
|
|
|
{
|
|
|
|
|
// start mysql transaction here if not already present
|
|
|
|
|
mysql_transaction
|
|
|
|
|
= unique_ptr<mysqlpp::Transaction>(
|
|
|
|
|
new mysqlpp::Transaction(
|
|
|
|
|
xmr_accounts->get_connection()
|
|
|
|
|
->get_connection()));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<XmrInput> inputs_found;
|
|
|
|
|
|
|
|
|
|
for (auto& in_info: oi_identification.identified_inputs)
|
|
|
|
@ -348,7 +389,7 @@ TxSearch::search()
|
|
|
|
|
in_data.output_id = out.id;
|
|
|
|
|
in_data.key_image = in_info.key_img;
|
|
|
|
|
in_data.amount = out.amount; // must match corresponding output's amount
|
|
|
|
|
in_data.timestamp = blk_timestamp_mysql_format;
|
|
|
|
|
in_data.timestamp = *blk_timestamp_mysql_format;
|
|
|
|
|
|
|
|
|
|
inputs_found.push_back(in_data);
|
|
|
|
|
|
|
|
|
@ -367,9 +408,7 @@ TxSearch::search()
|
|
|
|
|
uint64_t total_sent {0};
|
|
|
|
|
|
|
|
|
|
for (const XmrInput& in_data: inputs_found)
|
|
|
|
|
{
|
|
|
|
|
total_sent += in_data.amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tx_mysql_id == 0)
|
|
|
|
|
{
|
|
|
|
@ -381,9 +420,9 @@ TxSearch::search()
|
|
|
|
|
|
|
|
|
|
XmrTransaction tx_data;
|
|
|
|
|
|
|
|
|
|
tx_data.hash = oi_identification.tx_hash_str;
|
|
|
|
|
tx_data.prefix_hash = oi_identification.tx_prefix_hash_str;
|
|
|
|
|
tx_data.tx_pub_key = oi_identification.tx_pub_key_str;
|
|
|
|
|
tx_data.hash = oi_identification.get_tx_hash_str();
|
|
|
|
|
tx_data.prefix_hash = oi_identification.get_tx_prefix_hash_str();
|
|
|
|
|
tx_data.tx_pub_key = oi_identification.get_tx_pub_key_str();
|
|
|
|
|
tx_data.account_id = acc->id;
|
|
|
|
|
tx_data.blockchain_tx_id = blockchain_tx_id;
|
|
|
|
|
tx_data.total_received = 0; // because this is spending, total_recieved is 0
|
|
|
|
@ -395,8 +434,8 @@ TxSearch::search()
|
|
|
|
|
tx_data.rct_type = oi_identification.rct_type;
|
|
|
|
|
tx_data.spendable = is_spendable;
|
|
|
|
|
tx_data.payment_id = CurrentBlockchainStatus::get_payment_id_as_string(tx);
|
|
|
|
|
tx_data.mixin = get_mixin_no(tx) - 1;
|
|
|
|
|
tx_data.timestamp = blk_timestamp_mysql_format;
|
|
|
|
|
tx_data.mixin = oi_identification.get_mixin_no();
|
|
|
|
|
tx_data.timestamp = *blk_timestamp_mysql_format;
|
|
|
|
|
|
|
|
|
|
// insert tx_data into mysql's Transactions table
|
|
|
|
|
tx_mysql_id = xmr_accounts->insert_tx(tx_data);
|
|
|
|
@ -431,7 +470,8 @@ TxSearch::search()
|
|
|
|
|
// to be written, i.e., Transactions, Outputs and Inputs. If so, write
|
|
|
|
|
// all this into database.
|
|
|
|
|
|
|
|
|
|
trans.commit();
|
|
|
|
|
if (mysql_transaction)
|
|
|
|
|
mysql_transaction->commit();
|
|
|
|
|
|
|
|
|
|
} // for (const transaction& tx: blk_txs)
|
|
|
|
|
|
|
|
|
@ -444,8 +484,15 @@ TxSearch::search()
|
|
|
|
|
|
|
|
|
|
XmrAccount updated_acc = *acc;
|
|
|
|
|
|
|
|
|
|
if (!blk_timestamp_mysql_format)
|
|
|
|
|
{
|
|
|
|
|
blk_timestamp_mysql_format
|
|
|
|
|
= unique_ptr<DateTime>(
|
|
|
|
|
new DateTime(static_cast<time_t>(blk.timestamp)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updated_acc.scanned_block_height = searched_blk_no;
|
|
|
|
|
updated_acc.scanned_block_timestamp = blk_timestamp_mysql_format;
|
|
|
|
|
updated_acc.scanned_block_timestamp = *blk_timestamp_mysql_format;
|
|
|
|
|
|
|
|
|
|
if (xmr_accounts->update(*acc, updated_acc))
|
|
|
|
|
{
|
|
|
|
@ -585,8 +632,8 @@ TxSearch::find_txs_in_mempool(
|
|
|
|
|
j_tx["id"] = 0; // dont have any database id for tx in mempool
|
|
|
|
|
// this id is used for sorting txs in the frontend.
|
|
|
|
|
|
|
|
|
|
j_tx["hash"] = oi_identification.tx_hash_str;
|
|
|
|
|
j_tx["tx_pub_key"] = oi_identification.tx_pub_key_str;
|
|
|
|
|
j_tx["hash"] = oi_identification.get_tx_hash_str();
|
|
|
|
|
j_tx["tx_pub_key"] = oi_identification.get_tx_pub_key_str();
|
|
|
|
|
j_tx["timestamp"] = recieve_time; // when it got into mempool
|
|
|
|
|
j_tx["total_received"] = oi_identification.total_received;
|
|
|
|
|
j_tx["total_sent"] = 0; // to be set later when looking for key images
|
|
|
|
@ -600,7 +647,7 @@ TxSearch::find_txs_in_mempool(
|
|
|
|
|
j_tx["coinbase"] = false; // mempool tx are not coinbase, so always false
|
|
|
|
|
j_tx["is_rct"] = oi_identification.is_rct;
|
|
|
|
|
j_tx["rct_type"] = oi_identification.rct_type;
|
|
|
|
|
j_tx["mixin"] = get_mixin_no(tx);
|
|
|
|
|
j_tx["mixin"] = oi_identification.get_mixin_no();
|
|
|
|
|
j_tx["mempool"] = true;
|
|
|
|
|
|
|
|
|
|
j_transactions.push_back(j_tx);
|
|
|
|
@ -673,8 +720,8 @@ TxSearch::find_txs_in_mempool(
|
|
|
|
|
j_tx["id"] = 0; // dont have any database id for tx in mempool
|
|
|
|
|
// this id is used for sorting txs in the frontend.
|
|
|
|
|
|
|
|
|
|
j_tx["hash"] = oi_identification.tx_hash_str;
|
|
|
|
|
j_tx["tx_pub_key"] = oi_identification.tx_pub_key_str;
|
|
|
|
|
j_tx["hash"] = oi_identification.get_tx_hash_str();
|
|
|
|
|
j_tx["tx_pub_key"] = oi_identification.get_tx_pub_key_str();
|
|
|
|
|
j_tx["timestamp"] = recieve_time; // when it got into mempool
|
|
|
|
|
j_tx["total_received"] = 0; // we did not recive any outputs/xmr
|
|
|
|
|
j_tx["total_sent"] = total_sent; // to be set later when looking for key images
|
|
|
|
|