generated_locally added to mysql

pull/155/head
moneroexamples 5 years ago
parent 5a7950073f
commit a24b64d794

@ -115,7 +115,7 @@ thinwalletServices
logged_in = true; logged_in = true;
// console.log("logged_in = true;"); // console.log("logged_in = true;");
ApiCalls.login(public_address, view_key) ApiCalls.login(public_address, view_key, generated_account)
.then(function(response) { .then(function(response) {
// set account_imported to true if we are not logging in with a newly generated account, and a new account was created on the server // set account_imported to true if we are not logging in with a newly generated account, and a new account was created on the server

@ -12,12 +12,13 @@ thinwalletServices
return $http.post(config.apiUrl + 'get_version'); return $http.post(config.apiUrl + 'get_version');
}; };
api.login = function(public_address, view_key) { api.login = function(public_address, view_key, gen_locally) {
return $http.post(config.apiUrl + "login", { return $http.post(config.apiUrl + "login", {
withCredentials: true, withCredentials: true,
address: public_address, address: public_address,
view_key: view_key, view_key: view_key,
create_account: true create_account: true,
generated_locally: gen_locally
}); });
}; };
@ -84,4 +85,4 @@ thinwalletServices
}; };
return api; return api;
}); });

@ -40,6 +40,7 @@ CREATE TABLE IF NOT EXISTS `Accounts` (
`scanned_block_height` int(10) UNSIGNED NOT NULL DEFAULT '0', `scanned_block_height` int(10) UNSIGNED NOT NULL DEFAULT '0',
`scanned_block_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `scanned_block_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`start_height` int(10) UNSIGNED NOT NULL DEFAULT '0', `start_height` int(10) UNSIGNED NOT NULL DEFAULT '0',
`generated_locally` tinyint(1) NOT NULL DEFAULT '1',
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
@ -55,13 +56,13 @@ TRUNCATE TABLE `Accounts`;
-- Dumping data for table `Accounts` -- Dumping data for table `Accounts`
-- --
INSERT INTO `Accounts` (`id`, `address`, `viewkey_hash`, `scanned_block_height`, `scanned_block_timestamp`, `start_height`, `created`, `modified`) VALUES INSERT INTO `Accounts` (`id`, `address`, `viewkey_hash`, `scanned_block_height`, `scanned_block_timestamp`, `start_height`,`generated_locally`, `created`, `modified`) VALUES
(129, '57Hx8QpLUSMjhgoCNkvJ2Ch91mVyxcffESCprnRPrtbphMCv8iGUEfCUJxrpUWUeWrS9vPWnFrnMmTwnFpSKJrSKNuaXc5q', '1acf92d12101afe2ce7392169a38d2d547bd042373148eaaab323a3b5185a9ba', 101610, '2018-06-21 03:00:30', 96783, '2018-06-14 05:20:09', '2018-06-14 05:20:09'), (129, '57Hx8QpLUSMjhgoCNkvJ2Ch91mVyxcffESCprnRPrtbphMCv8iGUEfCUJxrpUWUeWrS9vPWnFrnMmTwnFpSKJrSKNuaXc5q', '1acf92d12101afe2ce7392169a38d2d547bd042373148eaaab323a3b5185a9ba', 101610,1, '2018-06-21 03:00:30', 96783, '2018-06-14 05:20:09', '2018-06-14 05:20:09'),
(130, '59imctBu85zZ9fJDTndqQRikvkeGnnUF6EuLERmdpE5fW2EEJbvbAc92uLfao947dpYpV4JaWg7FfUAenFQ6DMyfNQG8v1C', '1af8e9e4b194d2bf6fc771718d97cd65bec142796445df74855e5502205aa41d', 100871, '2018-06-20 01:37:28', 100480, '2018-06-19 04:39:16', '2018-06-19 04:39:16'), (130, '59imctBu85zZ9fJDTndqQRikvkeGnnUF6EuLERmdpE5fW2EEJbvbAc92uLfao947dpYpV4JaWg7FfUAenFQ6DMyfNQG8v1C', '1af8e9e4b194d2bf6fc771718d97cd65bec142796445df74855e5502205aa41d', 100871,1, '2018-06-20 01:37:28', 100480, '2018-06-19 04:39:16', '2018-06-19 04:39:16'),
(131, '55ZbQdMnZHPFS8pmrhHN5jMpgJwnnTXpTDmmM5wkrBBx4xD6aEnpZq7dPkeDeWs67TV9HunDQtT3qF2UGYWzGGxq3zYWCBE', 'c8e858047caf1615dc77759a4b134befc40955ab945bc381de71cf4502047059', 105232, '2018-06-26 04:22:22', 100480, '2018-06-19 04:39:27', '2018-06-19 04:39:27'), (131, '55ZbQdMnZHPFS8pmrhHN5jMpgJwnnTXpTDmmM5wkrBBx4xD6aEnpZq7dPkeDeWs67TV9HunDQtT3qF2UGYWzGGxq3zYWCBE', 'c8e858047caf1615dc77759a4b134befc40955ab945bc381de71cf4502047059', 105232,1, '2018-06-26 04:22:22', 100480, '2018-06-19 04:39:27', '2018-06-19 04:39:27'),
(132, '53mqDDKtVkib8inMa41HuNJG4tj9CcaNKGr6EVSbvhWGJdpDQCiNNYBUNF1oDb8BczU5aD68d3HNKXaEsPq8cvbQE2FBkTS', '4fbcd8e59f156553713e0b624930856a7798e98930cb9ae446712b53c44cde9d', 33399, '2018-03-15 00:47:44', 100870, '2018-06-20 01:36:25', '2018-06-20 01:36:25'), (132, '53mqDDKtVkib8inMa41HuNJG4tj9CcaNKGr6EVSbvhWGJdpDQCiNNYBUNF1oDb8BczU5aD68d3HNKXaEsPq8cvbQE2FBkTS', '4fbcd8e59f156553713e0b624930856a7798e98930cb9ae446712b53c44cde9d', 33399,1, '2018-03-15 00:47:44', 100870, '2018-06-20 01:36:25', '2018-06-20 01:36:25'),
(133, '57hGLsqr6eLjUDoqWwP3Ko9nCJ4GFN5AyezdxNXwpa1PMt6M4AbsBgcHH21hVe2MJrLGSM9C7UTqcEmyBepdhvFE4eyW3Kd', '69b1d4a9f618724fabb85ef1e6631d384a0b8ea75cda94ecc999a8680af2d439', 100871, '2018-06-20 01:37:28', 100871, '2018-06-20 01:38:28', '2018-06-20 01:38:28'), (133, '57hGLsqr6eLjUDoqWwP3Ko9nCJ4GFN5AyezdxNXwpa1PMt6M4AbsBgcHH21hVe2MJrLGSM9C7UTqcEmyBepdhvFE4eyW3Kd', '69b1d4a9f618724fabb85ef1e6631d384a0b8ea75cda94ecc999a8680af2d439', 100871,1, '2018-06-20 01:37:28', 100871, '2018-06-20 01:38:28', '2018-06-20 01:38:28'),
(134, '5AjfkEY7RFgNGDYvoRQkncfwHXT6Fh7oJBisqFUX5u96i3ZepxDPocQK29tmAwBDuvKRpskZnfA6N8Ra58qFzA4bSA3QZFp', '46efade82358c19fc2f42b86cb10297e524fbe6c39f807fb064a445c5d8b6367', 101610, '2018-06-21 03:00:30', 100937, '2018-06-20 03:49:53', '2018-06-20 03:49:53'); (134, '5AjfkEY7RFgNGDYvoRQkncfwHXT6Fh7oJBisqFUX5u96i3ZepxDPocQK29tmAwBDuvKRpskZnfA6N8Ra58qFzA4bSA3QZFp', '46efade82358c19fc2f42b86cb10297e524fbe6c39f807fb064a445c5d8b6367', 101610,1, '2018-06-21 03:00:30', 100937, '2018-06-20 03:49:53', '2018-06-20 03:49:53');
-- -------------------------------------------------------- -- --------------------------------------------------------

@ -91,14 +91,6 @@ OpenMoneroRequests::login(const shared_ptr<Session> session, const Bytes & body)
} }
// return same as what we recieved to client
j_response["generated_locally"] = generated_locally;
//j_response["generated_locally"] = true;
// optinoal field, but we set it to current height
j_response["start_height"] = current_bc_status
->get_current_blockchain_height();
// a placeholder for exciting or new account data // a placeholder for exciting or new account data
uint64_t acc_id {0}; uint64_t acc_id {0};
@ -114,7 +106,8 @@ OpenMoneroRequests::login(const shared_ptr<Session> session, const Bytes & body)
{ {
// account does not exist, so create new one // account does not exist, so create new one
// for this address // for this address
if (!(acc = create_account(xmr_address, view_key))) if (!(acc = create_account(xmr_address, view_key,
generated_locally)))
{ {
// if creating account failed // if creating account failed
j_response = json {{"status", "error"}, j_response = json {{"status", "error"},
@ -123,6 +116,10 @@ OpenMoneroRequests::login(const shared_ptr<Session> session, const Bytes & body)
session_close(session, j_response); session_close(session, j_response);
return; return;
} }
j_response["generated_locally"] = bool {acc->generated_locally};
j_response["start_height"] = acc->start_height;
// set this flag to indicate that we have just created a // set this flag to indicate that we have just created a
// new account in mysql. this information is sent to front-end // new account in mysql. this information is sent to front-end
@ -2016,7 +2013,8 @@ OpenMoneroRequests::parse_request(
boost::optional<XmrAccount> boost::optional<XmrAccount>
OpenMoneroRequests::create_account( OpenMoneroRequests::create_account(
string const& xmr_address, string const& xmr_address,
string const& view_key) const string const& view_key,
bool generated_locally) const
{ {
boost::optional<XmrAccount> acc = XmrAccount{}; boost::optional<XmrAccount> acc = XmrAccount{};
@ -2048,14 +2046,27 @@ OpenMoneroRequests::create_account(
= XmrTransaction::timestamp_to_DateTime( = XmrTransaction::timestamp_to_DateTime(
current_blockchain_timestamp); current_blockchain_timestamp);
// accounts generated locally (using create account button)
// will have start height equal to current blockchain height.
// existing accounts, i.e., those imported ones or extenal ones
// will have start_height of 0 to indicated that they could
// have been created years ago
uint64_t start_height = generated_locally
? current_blockchain_height
: 0;
uint64_t scanned_block_height = start_height;
// create new account // create new account
acc = XmrAccount( acc = XmrAccount(
mysqlpp::null, mysqlpp::null,
xmr_address, xmr_address,
make_hash(view_key), make_hash(view_key),
current_blockchain_height, /* for scanned_block_height */ scanned_block_height,
blk_timestamp_mysql_format, blk_timestamp_mysql_format,
current_blockchain_height); start_height,
generated_locally);
uint64_t acc_id {0}; uint64_t acc_id {0};

@ -151,7 +151,8 @@ private:
boost::optional<XmrAccount> boost::optional<XmrAccount>
create_account(string const& xmr_address, create_account(string const& xmr_address,
string const& view_key) const; string const& view_key,
bool generated_locally = true) const;
bool bool
make_search_thread(XmrAccount& acc) const; make_search_thread(XmrAccount& acc) const;

@ -30,13 +30,14 @@ public:
friend std::ostream& operator<< (std::ostream& stream, const Table& data); friend std::ostream& operator<< (std::ostream& stream, const Table& data);
}; };
sql_create_8(Accounts, 1, 6, sql_create_9(Accounts, 1, 7,
sql_bigint_unsigned_null, id, sql_bigint_unsigned_null, id,
sql_varchar , address, sql_varchar , address,
sql_char , viewkey_hash, sql_char , viewkey_hash,
sql_bigint_unsigned, scanned_block_height, sql_bigint_unsigned, scanned_block_height,
sql_timestamp , scanned_block_timestamp, sql_timestamp , scanned_block_timestamp,
sql_bigint_unsigned, start_height, sql_bigint_unsigned, start_height,
sql_boolean , generated_locally,
sql_timestamp , created, sql_timestamp , created,
sql_timestamp , modified); sql_timestamp , modified);
@ -61,9 +62,10 @@ struct XmrAccount : public Accounts, Table
static constexpr const char* INSERT_STMT = R"( static constexpr const char* INSERT_STMT = R"(
INSERT INTO `Accounts` (`address`, `viewkey_hash`, INSERT INTO `Accounts` (`address`, `viewkey_hash`,
`scanned_block_height`, `scanned_block_height`,
`scanned_block_timestamp`, `start_height`) `scanned_block_timestamp`, `start_height`,
`generated_locally`)
VALUES VALUES
(%0q, %1q, %2q, %3q, %4q); (%0q, %1q, %2q, %3q, %4q, %5q);
)"; )";
using Accounts::Accounts; using Accounts::Accounts;

Loading…
Cancel
Save