sql code updated

pull/1/head
moneroexamples 8 years ago
parent 355727ba3c
commit 5e0bf5a43c

@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Dec 14, 2016 at 10:03 AM
-- Generation Time: Dec 16, 2016 at 12:57 PM
-- Server version: 5.7.16-0ubuntu0.16.10.1
-- PHP Version: 7.0.8-3ubuntu3
@ -44,6 +44,23 @@ CREATE TABLE `Accounts` (
-- --------------------------------------------------------
--
-- Table structure for table `Outputs`
--
CREATE TABLE `Outputs` (
`id` bigint(20) UNSIGNED NOT NULL,
`account_id` bigint(20) UNSIGNED NOT NULL,
`tx_id` bigint(20) UNSIGNED NOT NULL,
`out_pub_key` char(64) NOT NULL,
`tx_pub_key` varchar(64) NOT NULL DEFAULT '',
`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
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `Transactions`
--
@ -57,6 +74,7 @@ CREATE TABLE `Transactions` (
`unlock_time` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`height` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`coinbase` tinyint(1) NOT NULL DEFAULT '0',
`payment_id` varchar(64) NOT NULL DEFAULT '',
`mixin` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@ -72,6 +90,15 @@ ALTER TABLE `Accounts`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `address` (`address`);
--
-- Indexes for table `Outputs`
--
ALTER TABLE `Outputs`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `out_pub_key` (`out_pub_key`),
ADD KEY `account_id` (`account_id`),
ADD KEY `tx_id` (`tx_id`);
--
-- Indexes for table `Transactions`
--
@ -89,11 +116,28 @@ ALTER TABLE `Transactions`
-- AUTO_INCREMENT for table `Accounts`
--
ALTER TABLE `Accounts`
MODIFY `id` bigint(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=54;
MODIFY `id` bigint(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
--
-- AUTO_INCREMENT for table `Outputs`
--
ALTER TABLE `Outputs`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
--
-- AUTO_INCREMENT for table `Transactions`
--
ALTER TABLE `Transactions`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
--
-- Constraints for dumped tables
--
--
-- Constraints for table `Outputs`
--
ALTER TABLE `Outputs`
ADD CONSTRAINT `account_id3_FK` FOREIGN KEY (`account_id`) REFERENCES `Accounts` (`id`) ON DELETE CASCADE,
ADD CONSTRAINT `transaction_id_FK` FOREIGN KEY (`tx_id`) REFERENCES `Transactions` (`id`) ON DELETE CASCADE;
--
-- Constraints for table `Transactions`
--

@ -205,6 +205,9 @@ public:
uint64_t total_received {0};
// FIRST component: Checking for our outputs.
// <out_pub_key, index in tx>
vector<pair<string, uint64_t>> found_mine_outputs;
@ -323,6 +326,12 @@ public:
// insert tx_data into mysql's Transactions table
uint64_t tx_mysql_id = xmr_accounts->insert_tx(tx_data);
if (tx_mysql_id == 0)
{
cerr << "tx_mysql_id is zero!" << endl;
throw TxSearchException("tx_mysql_id is zero!");
}
// now add the found outputs into Outputs tables
for (auto &out_k_idx: found_mine_outputs)
@ -339,9 +348,21 @@ public:
// insert output into mysql's outputs table
uint64_t out_mysql_id = xmr_accounts->insert_output(out_data);
if (out_mysql_id == 0)
{
cerr << "out_mysql_id is zero!" << endl;
throw TxSearchException("out_mysql_id is zero!");
}
}
// SECOND component: Checking for our key images, i.e., inputs.
// once tx and outputs were added, update Accounts table
XmrAccount updated_acc = acc;

Loading…
Cancel
Save