global_index added to Outputs table

pull/1/head
moneroexamples 7 years ago
parent 3c685a06e1
commit bf29ebdd8a

@ -3,7 +3,7 @@
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Dec 27, 2016 at 06:13 AM
-- Generation Time: Dec 28, 2016 at 08:00 AM
-- Server version: 10.1.19-MariaDB
-- PHP Version: 7.0.9
@ -28,7 +28,6 @@ USE `openmonero`;
-- Table structure for table `Accounts`
--
DROP TABLE IF EXISTS `Accounts`;
CREATE TABLE `Accounts` (
`id` bigint(10) UNSIGNED NOT NULL,
`address` varchar(95) NOT NULL,
@ -45,7 +44,6 @@ CREATE TABLE `Accounts` (
-- Table structure for table `Inputs`
--
DROP TABLE IF EXISTS `Inputs`;
CREATE TABLE `Inputs` (
`id` bigint(20) UNSIGNED NOT NULL,
`account_id` bigint(20) UNSIGNED NOT NULL,
@ -62,7 +60,6 @@ CREATE TABLE `Inputs` (
-- Table structure for table `Outputs`
--
DROP TABLE IF EXISTS `Outputs`;
CREATE TABLE `Outputs` (
`id` bigint(20) UNSIGNED NOT NULL,
`account_id` bigint(20) UNSIGNED NOT NULL,
@ -70,6 +67,7 @@ CREATE TABLE `Outputs` (
`out_pub_key` varchar(64) NOT NULL,
`tx_pub_key` varchar(64) NOT NULL DEFAULT '',
`amount` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`global_index` bigint(20) UNSIGNED NOT NULL,
`out_index` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`mixin` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
@ -81,7 +79,6 @@ CREATE TABLE `Outputs` (
-- Table structure for table `Transactions`
--
DROP TABLE IF EXISTS `Transactions`;
CREATE TABLE `Transactions` (
`id` bigint(20) UNSIGNED NOT NULL,
`hash` varchar(64) NOT NULL,
@ -102,13 +99,13 @@ CREATE TABLE `Transactions` (
--
-- Stand-in structure for view `TransactionsWithOutsAndIns`
--
DROP VIEW IF EXISTS `TransactionsWithOutsAndIns`;
CREATE TABLE `TransactionsWithOutsAndIns` (
`tx_id` bigint(20) unsigned
,`account_id` bigint(20) unsigned
,`amount` bigint(20) unsigned zerofill
,`tx_pub_key` varchar(64)
,`out_index` bigint(20) unsigned
,`global_index` bigint(20) unsigned
,`key_image` varchar(64)
,`mixin` bigint(20) unsigned
);
@ -120,7 +117,7 @@ CREATE TABLE `TransactionsWithOutsAndIns` (
--
DROP TABLE IF EXISTS `TransactionsWithOutsAndIns`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `TransactionsWithOutsAndIns` AS select `Inputs`.`tx_id` AS `tx_id`,`Inputs`.`account_id` AS `account_id`,`Inputs`.`amount` AS `amount`,`Outputs`.`tx_pub_key` AS `tx_pub_key`,`Outputs`.`out_index` AS `out_index`,`Inputs`.`key_image` AS `key_image`,`Outputs`.`mixin` AS `mixin` from (`Inputs` join `Outputs` on((`Inputs`.`output_id` = `Outputs`.`id`))) ;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `TransactionsWithOutsAndIns` AS select `Inputs`.`tx_id` AS `tx_id`,`Inputs`.`account_id` AS `account_id`,`Inputs`.`amount` AS `amount`,`Outputs`.`tx_pub_key` AS `tx_pub_key`,`Outputs`.`out_index` AS `out_index`,`Outputs`.`global_index` AS `global_index`,`Inputs`.`key_image` AS `key_image`,`Outputs`.`mixin` AS `mixin` from (`Inputs` join `Outputs` on((`Inputs`.`output_id` = `Outputs`.`id`))) ;
--
-- Indexes for dumped tables
@ -173,17 +170,17 @@ ALTER TABLE `Accounts`
-- AUTO_INCREMENT for table `Inputs`
--
ALTER TABLE `Inputs`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12;
--
-- AUTO_INCREMENT for table `Outputs`
--
ALTER TABLE `Outputs`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=14;
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=37;
--
-- AUTO_INCREMENT for table `Transactions`
--
ALTER TABLE `Transactions`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=25;
--
-- Constraints for dumped tables
--

@ -132,6 +132,30 @@ struct CurrentBlockchainStatus {
return true;
}
static bool
get_amount_specific_indices(const crypto::hash& tx_hash,
vector<uint64_t> out_indices)
{
try
{
// this index is lmdb index of a tx, not tx hash
uint64_t tx_index;
if (core_storage->get_db().tx_exists(tx_hash, tx_index))
{
out_indices = core_storage->get_db()
.get_tx_amount_output_indices(tx_index);
return true;
}
}
catch(const exception& e)
{
cerr << e.what() << endl;
}
return false;
}
};

@ -310,6 +310,7 @@ public:
out_data.out_pub_key,
out_data.tx_pub_key,
out_data.amount,
out_data.global_index,
out_data.out_index,
out_data.mixin,
out_data.timestamp);

@ -176,6 +176,8 @@ public:
crypto::hash tx_hash = get_transaction_hash(tx);
crypto::hash tx_prefix_hash = get_transaction_prefix_hash(tx);
vector<uint64_t> amount_specific_indices;
// cout << pod_to_hex(tx_hash) << endl;
public_key tx_pub_key = xmreg::get_tx_pub_key_from_received_outs(tx);
@ -318,6 +320,15 @@ public:
// insert tx_data into mysql's Transactions table
tx_mysql_id = xmr_accounts->insert_tx(tx_data);
// get amount specific (i.e., global) indices of outputs
if (!CurrentBlockchainStatus::get_amount_specific_indices(tx_hash,
amount_specific_indices))
{
cerr << "cant get_amount_specific_indices!" << endl;
throw TxSearchException("cant get_amount_specific_indices!");
}
if (tx_mysql_id == 0)
{
//cerr << "tx_mysql_id is zero!" << endl;
@ -336,6 +347,7 @@ public:
out_data.tx_pub_key = pod_to_hex(tx_pub_key);
out_data.amount = std::get<1>(out_k_idx);
out_data.out_index = std::get<2>(out_k_idx);
out_data.global_index = amount_specific_indices.at(out_data.out_index);
out_data.mixin = tx_data.mixin;
out_data.timestamp = tx_data.timestamp;

@ -176,13 +176,14 @@ ostream& operator<< (std::ostream& os, const XmrTransaction& acc) {
};
sql_create_9(Outputs, 1, 3,
sql_create_10(Outputs, 1, 3,
sql_bigint_unsigned, id,
sql_bigint_unsigned, account_id,
sql_bigint_unsigned, tx_id,
sql_varchar , out_pub_key,
sql_varchar , tx_pub_key,
sql_bigint_unsigned, amount,
sql_bigint_unsigned, global_index,
sql_bigint_unsigned, out_index,
sql_bigint_unsigned, mixin,
sql_timestamp , timestamp);
@ -201,9 +202,9 @@ struct XmrOutput : public Outputs
static constexpr const char* INSERT_STMT = R"(
INSERT IGNORE INTO `Outputs` (`account_id`, `tx_id`, `out_pub_key`, `tx_pub_key`,
`amount`, `out_index`, `mixin`, `timestamp`)
`amount`, `global_index`, `out_index`, `mixin`, `timestamp`)
VALUES (%0q, %1q, %2q, %3q,
%4q, %5q, %6q, %7q);
%4q, %5q, %6q, %7q, %8q);
)";
@ -218,6 +219,8 @@ struct XmrOutput : public Outputs
{"tx_id" , tx_id},
{"out_pub_key" , out_pub_key},
{"tx_pub_key" , tx_pub_key},
{"amount" , amount},
{"global_index" , global_index},
{"out_index" , out_index},
{"mixin" , mixin},
{"timestamp" , timestamp}
@ -299,12 +302,13 @@ ostream& operator<< (std::ostream& os, const XmrInput& out) {
// this is MySQL VIEW, based on the Transactions,
// Outputs and Inputs tables
sql_create_7(TransactionsWithOutsAndIns, 1, 2,
sql_create_8(TransactionsWithOutsAndIns, 1, 2,
sql_bigint_unsigned, tx_id,
sql_bigint_unsigned, account_id,
sql_bigint_unsigned, amount,
sql_varchar , tx_pub_key,
sql_bigint_unsigned, out_index,
sql_bigint_unsigned, global_index,
sql_varchar_null , key_image,
sql_bigint_unsigned, mixin);
@ -332,6 +336,7 @@ struct XmrTransactionWithOutsAndIns : public TransactionsWithOutsAndIns
{"account_id" , account_id},
{"amount" , amount},
{"tx_pub_key" , tx_pub_key},
{"global_index" , global_index},
{"out_index" , out_index},
{"key_image" , key_image_to_string()},
{"mixin" , mixin}

Loading…
Cancel
Save