blockchain_tx_id added to Transaction table

pull/12/head
moneroexamples 7 years ago
parent de2881ef5f
commit 16b8c429bf

@ -110,6 +110,7 @@ CREATE TABLE `Transactions` (
`hash` varchar(64) NOT NULL,
`prefix_hash` varchar(64) NOT NULL DEFAULT '',
`account_id` bigint(20) UNSIGNED NOT NULL,
`blockchain_tx_id` bigint(20) UNSIGNED NOT NULL,
`total_received` bigint(20) UNSIGNED NOT NULL,
`total_sent` bigint(20) UNSIGNED NOT NULL,
`unlock_time` bigint(20) UNSIGNED NOT NULL DEFAULT '0',

@ -224,6 +224,18 @@ CurrentBlockchainStatus::tx_exist(const crypto::hash& tx_hash)
return core_storage->have_tx(tx_hash);
}
bool
CurrentBlockchainStatus::tx_exist(const crypto::hash& tx_hash, uint64_t& tx_index)
{
if (!core_storage->get_db().tx_exists(tx_hash, tx_index))
{
return false;
}
return true;
}
bool
CurrentBlockchainStatus::tx_exist(const string& tx_hash_str)
{

@ -103,6 +103,9 @@ struct CurrentBlockchainStatus
static bool
tx_exist(const crypto::hash& tx_hash);
static bool
tx_exist(const crypto::hash& tx_hash, uint64_t& tx_index);
static bool
tx_exist(const string& tx_hash_str);

@ -398,6 +398,7 @@ MysqlTransactions::insert(const XmrTransaction& tx_data)
SimpleResult sr = query.execute(tx_data.hash,
tx_data.prefix_hash,
tx_data.account_id,
tx_data.blockchain_tx_id,
tx_data.total_received,
tx_data.total_sent,
tx_data.unlock_time,

@ -20,7 +20,7 @@ OutputInputIdentification::OutputInputIdentification(
tx_hash = get_transaction_hash(*tx);
tx_prefix_hash = get_transaction_prefix_hash(*tx);
tx_pub_key = xmreg::get_tx_pub_key_from_received_outs(*tx);
tx_pub_key = xmreg::get_tx_pub_key_from_received_outs(*tx);
tx_hash_str = pod_to_hex(tx_hash);
tx_prefix_hash_str = pod_to_hex(tx_prefix_hash);

@ -169,6 +169,17 @@ TxSearch::search()
bool is_spendable = CurrentBlockchainStatus::is_tx_unlocked(
tx.unlock_time, searched_blk_no);
// this is id of txs in lmdb blockchain table.
// it will be used mostly to sort txs in the frontend.
uint64_t blockchain_tx_id {0};
if (!CurrentBlockchainStatus::tx_exist(oi_identification.tx_hash, blockchain_tx_id))
{
cerr << "Tx " << oi_identification.tx_hash_str << "not found in blockchain !" << endl;
continue;
}
// FIRSt step.
oi_identification.identify_outputs();
@ -176,6 +187,7 @@ TxSearch::search()
uint64_t tx_mysql_id {0};
// if we identified some outputs as ours,
// save them into mysql.
if (!oi_identification.identified_outputs.empty())
@ -195,27 +207,28 @@ TxSearch::search()
<< endl;
}
tx_data.hash = oi_identification.tx_hash_str;
tx_data.prefix_hash = oi_identification.tx_prefix_hash_str;
tx_data.account_id = acc->id;
tx_data.total_received = oi_identification.total_received;
tx_data.total_sent = 0; // at this stage we don't have any
// info about spendings
// this is current block + unlock time
// for regular tx, the unlock time is
// default of 10 blocks.
// for coinbase tx it is 60 blocks
tx_data.unlock_time = tx.unlock_time;
tx_data.height = searched_blk_no;
tx_data.coinbase = oi_identification.tx_is_coinbase;
tx_data.is_rct = oi_identification.is_rct;
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.hash = oi_identification.tx_hash_str;
tx_data.prefix_hash = oi_identification.tx_prefix_hash_str;
tx_data.account_id = acc->id;
tx_data.blockchain_tx_id = blockchain_tx_id;
tx_data.total_received = oi_identification.total_received;
tx_data.total_sent = 0; // at this stage we don't have any
// info about spendings
// this is current block + unlock time
// for regular tx, the unlock time is
// default of 10 blocks.
// for coinbase tx it is 60 blocks
tx_data.unlock_time = tx.unlock_time;
tx_data.height = searched_blk_no;
tx_data.coinbase = oi_identification.tx_is_coinbase;
tx_data.is_rct = oi_identification.is_rct;
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;
// insert tx_data into mysql's Transactions table
@ -343,20 +356,21 @@ 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.account_id = acc->id;
tx_data.total_received = 0; // because this is spending, total_recieved is 0
tx_data.total_sent = total_sent;
tx_data.unlock_time = tx.unlock_time;
tx_data.height = searched_blk_no;
tx_data.coinbase = oi_identification.tx_is_coinbase;
tx_data.is_rct = oi_identification.is_rct;
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.hash = oi_identification.tx_hash_str;
tx_data.prefix_hash = oi_identification.tx_prefix_hash_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
tx_data.total_sent = total_sent;
tx_data.unlock_time = tx.unlock_time;
tx_data.height = searched_blk_no;
tx_data.coinbase = oi_identification.tx_is_coinbase;
tx_data.is_rct = oi_identification.is_rct;
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;
// insert tx_data into mysql's Transactions table
tx_mysql_id = xmr_accounts->insert_tx(tx_data);

@ -190,7 +190,7 @@ YourMoneroRequests::get_address_txs(const shared_ptr< Session > session, const B
for (XmrTransaction tx: txs)
{
json j_tx {
{"id" , tx.id}, // strangely, frontend sorts txs by id in database.
{"id" , tx.blockchain_tx_id},
{"coinbase" , bool {tx.coinbase}},
{"hash" , tx.hash},
{"height" , tx.height},

@ -69,11 +69,12 @@ struct XmrAccount : public Accounts, Table
};
sql_create_15(Transactions, 1, 2,
sql_create_16(Transactions, 1, 2,
sql_bigint_unsigned, id,
sql_varchar , hash,
sql_varchar , prefix_hash,
sql_bigint_unsigned, account_id,
sql_bigint_unsigned, blockchain_tx_id,
sql_bigint_unsigned, total_received,
sql_bigint_unsigned, total_sent,
sql_bigint_unsigned, unlock_time,
@ -107,16 +108,16 @@ struct XmrTransaction : public Transactions, Table
)";
static constexpr const char* INSERT_STMT = R"(
INSERT IGNORE INTO `Transactions` (`hash`, `prefix_hash`, `account_id`,
INSERT IGNORE INTO `Transactions` (`hash`, `prefix_hash`, `account_id`, `blockchain_tx_id`,
`total_received`, `total_sent`, `unlock_time`,
`height`, `coinbase`, `is_rct`, `rct_type`,
`spendable`,
`payment_id`, `mixin`, `timestamp`)
VALUES (%0q, %1q, %2q,
%3q, %4q, %5q,
%6q, %7q, %8q, %9q,
%10q,
%11q, %12q, %13q);
VALUES (%0q, %1q, %2q, %3q,
%4q, %5q, %6q,
%7q, %8q, %9q, %10q,
%11q,
%12q, %13q, %14q);
)";
static constexpr const char* MARK_AS_SPENDABLE_STMT = R"(

Loading…
Cancel
Save