Accounts table simplified

pull/1/head
moneroexamples 7 years ago
parent 09d51cf843
commit 37f46076a7

@ -598,7 +598,7 @@ public:
}
uint64_t
insert(const string& address, const uint64_t& scanned_block_height = 0)
insert(const string& address, const uint64_t& current_blkchain_height = 0)
{
// static shared_ptr<Query> query;
@ -618,7 +618,13 @@ public:
try
{
SimpleResult sr = query.execute(address, scanned_block_height);
// scanned_block_height and start_height are
// set to current blockchain height
// when account is created.
SimpleResult sr = query.execute(address,
current_blkchain_height,
current_blkchain_height);
if (sr.rows() == 1)
return sr.insert_id();

@ -190,13 +190,12 @@ public:
// initializa json response
json j_response {
{ "total_received", "0"},
{ "total_sent", "0"},
{ "scanned_height", 0},
{ "scanned_block_height", 0},
{ "start_height", 0},
{ "transaction_height", 0},
{ "blockchain_height", 0}
{ "total_received", "0"}, // taken from Accounts table
{ "scanned_height", 0}, // not used. it is here to match mymonero
{ "scanned_block_height", 0}, // taken from Accounts table
{ "start_height", 0}, // not used. it is here to match mymonero
{ "transaction_height", 0}, // not used. it is here to match mymonero
{ "blockchain_height", 0} // current blockchain height
};
@ -212,13 +211,13 @@ public:
vector<XmrTransaction> txs;
// retrive txs from mysql associated with the given address
// retrieve txs from mysql associated with the given address
if (xmr_accounts->select_txs(acc.id, txs))
{
// we found some txs.
if (!txs.empty())
{
// we found some txs.
json j_txs = json::array();
for (XmrTransaction tx: txs)
@ -232,7 +231,6 @@ public:
if (xmr_accounts->select_inputs_for_tx(tx.id, inputs))
{
json j_spent_outputs = json::array();
uint64_t total_spent {0};
@ -244,6 +242,7 @@ public:
}
j_tx["total_sent"] = total_spent;
j_tx["spent_outputs"] = j_spent_outputs;
}
@ -251,9 +250,12 @@ public:
}
j_response["transactions"] = j_txs;
}
}
}
} // if (!txs.empty())
} // if (xmr_accounts->select_txs(acc.id, txs))
} // if (xmr_accounts->select(xmr_address, acc))
string response_body = j_response.dump();
@ -296,7 +298,6 @@ public:
j_response["scanned_block_height"] = acc.scanned_block_height;
j_response["blockchain_height"] = CurrentBlockchainStatus::get_current_blockchain_height();
uint64_t total_sent {0};
vector<XmrTransactionWithOutsAndIns> txs;

@ -22,16 +22,12 @@ using namespace nlohmann;
// to see what it does can run preprecoess on this file
// g++ -I/usr/include/mysql -E ~/restbed-xmr/src/MySqlConnector.h > /tmp/out.h
sql_create_11(Accounts, 1, 2,
sql_create_7(Accounts, 1, 2,
sql_bigint_unsigned, id,
sql_varchar , address,
sql_bigint_unsigned, total_received,
sql_bigint_unsigned, scanned_height,
sql_bigint_unsigned, scanned_block_height,
sql_bigint_unsigned, start_height,
sql_bigint_unsigned, transaction_height,
sql_bigint_unsigned, blockchain_height,
sql_bigint_unsigned, total_sent,
sql_timestamp , created,
sql_timestamp , modified);
@ -48,7 +44,7 @@ struct XmrAccount : public Accounts
)";
static constexpr const char* INSERT_STMT = R"(
INSERT INTO `Accounts` (`address`, `scanned_block_height`) VALUES (%0q, %1q);
INSERT INTO `Accounts` (`address`, `start_height`, `scanned_block_height`) VALUES (%0q, %1q , %2q);
)";
@ -57,12 +53,9 @@ struct XmrAccount : public Accounts
XmrAccount():Accounts()
{
address = "";
scanned_height = 0;
total_received = 0;
scanned_block_height = 0;
start_height = 0;
transaction_height = 0;
blockchain_height = 0;
total_sent = 0;
}
// viewkey is not stored in mysql db or anywhere
@ -76,9 +69,8 @@ struct XmrAccount : public Accounts
{"address" , address},
{"viewkey" , viewkey},
{"total_received" , total_received},
{"total_sent" , total_sent},
{"scanned_block_height", scanned_block_height},
{"blockchain_height" , blockchain_height}
{"start_height" , start_height}
};
return j;

Loading…
Cancel
Save