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, `hash` varchar(64) NOT NULL,
`prefix_hash` varchar(64) NOT NULL DEFAULT '', `prefix_hash` varchar(64) NOT NULL DEFAULT '',
`account_id` bigint(20) UNSIGNED NOT NULL, `account_id` bigint(20) UNSIGNED NOT NULL,
`blockchain_tx_id` bigint(20) UNSIGNED NOT NULL,
`total_received` bigint(20) UNSIGNED NOT NULL, `total_received` bigint(20) UNSIGNED NOT NULL,
`total_sent` bigint(20) UNSIGNED NOT NULL, `total_sent` bigint(20) UNSIGNED NOT NULL,
`unlock_time` bigint(20) UNSIGNED NOT NULL DEFAULT '0', `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); 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 bool
CurrentBlockchainStatus::tx_exist(const string& tx_hash_str) CurrentBlockchainStatus::tx_exist(const string& tx_hash_str)
{ {

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

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

@ -169,6 +169,17 @@ TxSearch::search()
bool is_spendable = CurrentBlockchainStatus::is_tx_unlocked( bool is_spendable = CurrentBlockchainStatus::is_tx_unlocked(
tx.unlock_time, searched_blk_no); 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. // FIRSt step.
oi_identification.identify_outputs(); oi_identification.identify_outputs();
@ -176,6 +187,7 @@ TxSearch::search()
uint64_t tx_mysql_id {0}; uint64_t tx_mysql_id {0};
// if we identified some outputs as ours, // if we identified some outputs as ours,
// save them into mysql. // save them into mysql.
if (!oi_identification.identified_outputs.empty()) if (!oi_identification.identified_outputs.empty())
@ -198,6 +210,7 @@ TxSearch::search()
tx_data.hash = oi_identification.tx_hash_str; tx_data.hash = oi_identification.tx_hash_str;
tx_data.prefix_hash = oi_identification.tx_prefix_hash_str; tx_data.prefix_hash = oi_identification.tx_prefix_hash_str;
tx_data.account_id = acc->id; 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_received = oi_identification.total_received;
tx_data.total_sent = 0; // at this stage we don't have any tx_data.total_sent = 0; // at this stage we don't have any
// info about spendings // info about spendings
@ -346,6 +359,7 @@ TxSearch::search()
tx_data.hash = oi_identification.tx_hash_str; tx_data.hash = oi_identification.tx_hash_str;
tx_data.prefix_hash = oi_identification.tx_prefix_hash_str; tx_data.prefix_hash = oi_identification.tx_prefix_hash_str;
tx_data.account_id = acc->id; 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_received = 0; // because this is spending, total_recieved is 0
tx_data.total_sent = total_sent; tx_data.total_sent = total_sent;
tx_data.unlock_time = tx.unlock_time; tx_data.unlock_time = tx.unlock_time;

@ -190,7 +190,7 @@ YourMoneroRequests::get_address_txs(const shared_ptr< Session > session, const B
for (XmrTransaction tx: txs) for (XmrTransaction tx: txs)
{ {
json j_tx { json j_tx {
{"id" , tx.id}, // strangely, frontend sorts txs by id in database. {"id" , tx.blockchain_tx_id},
{"coinbase" , bool {tx.coinbase}}, {"coinbase" , bool {tx.coinbase}},
{"hash" , tx.hash}, {"hash" , tx.hash},
{"height" , tx.height}, {"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_bigint_unsigned, id,
sql_varchar , hash, sql_varchar , hash,
sql_varchar , prefix_hash, sql_varchar , prefix_hash,
sql_bigint_unsigned, account_id, sql_bigint_unsigned, account_id,
sql_bigint_unsigned, blockchain_tx_id,
sql_bigint_unsigned, total_received, sql_bigint_unsigned, total_received,
sql_bigint_unsigned, total_sent, sql_bigint_unsigned, total_sent,
sql_bigint_unsigned, unlock_time, sql_bigint_unsigned, unlock_time,
@ -107,16 +108,16 @@ struct XmrTransaction : public Transactions, Table
)"; )";
static constexpr const char* INSERT_STMT = R"( 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`, `total_received`, `total_sent`, `unlock_time`,
`height`, `coinbase`, `is_rct`, `rct_type`, `height`, `coinbase`, `is_rct`, `rct_type`,
`spendable`, `spendable`,
`payment_id`, `mixin`, `timestamp`) `payment_id`, `mixin`, `timestamp`)
VALUES (%0q, %1q, %2q, VALUES (%0q, %1q, %2q, %3q,
%3q, %4q, %5q, %4q, %5q, %6q,
%6q, %7q, %8q, %9q, %7q, %8q, %9q, %10q,
%10q, %11q,
%11q, %12q, %13q); %12q, %13q, %14q);
)"; )";
static constexpr const char* MARK_AS_SPENDABLE_STMT = R"( static constexpr const char* MARK_AS_SPENDABLE_STMT = R"(

Loading…
Cancel
Save