Use chrono literals

new_rpc
moneroexamples 6 years ago
parent 25a2884f59
commit a42327b1fb

@ -169,7 +169,7 @@ catch(std::exception const& e)
xmreg::MysqlPing mysql_ping {
mysql_accounts->get_connection(),
bc_setup.mysql_ping_every_seconds};
bc_setup.mysql_ping_every};
xmreg::ThreadRAII mysql_ping_thread(
std::thread(std::ref(mysql_ping)),

@ -158,18 +158,18 @@ BlockchainSetup::read_config(string config_json_path)
void
BlockchainSetup::_init()
{
refresh_block_status_every_seconds
= config_json["refresh_block_status_every_seconds"];
refresh_block_status_every
= seconds {config_json["refresh_block_status_every_seconds"]};
blocks_search_lookahead
= config_json["blocks_search_lookahead"];
max_number_of_blocks_to_import
= config_json["max_number_of_blocks_to_import"];
search_thread_life_in_seconds
= config_json["search_thread_life_in_seconds"];
search_thread_life
= seconds {config_json["search_thread_life_in_seconds"]};
import_fee
= config_json["wallet_import"]["fee"];
mysql_ping_every_seconds
= config_json["mysql_ping_every_seconds"];
mysql_ping_every
= seconds {config_json["mysql_ping_every_seconds"]};
get_blockchain_path();

@ -17,6 +17,8 @@ using namespace crypto;
using namespace cryptonote;
using namespace std;
using chrono::seconds;
class BlockchainSetup
{
public:
@ -37,25 +39,23 @@ public:
network_type net_type;
bool do_not_relay;
uint64_t refresh_block_status_every_seconds;
uint64_t blocks_search_lookahead;
bool do_not_relay {false};
uint64_t max_number_of_blocks_to_import;
seconds refresh_block_status_every {10};
seconds search_thread_life {120};
seconds mysql_ping_every {300};
uint64_t search_thread_life_in_seconds;
uint64_t blocks_search_lookahead {200};
uint64_t mysql_ping_every_seconds;
uint64_t max_number_of_blocks_to_import {132000};
string import_payment_address_str;
string import_payment_viewkey_str;
uint64_t import_fee;
uint64_t import_fee {0};
uint64_t spendable_age;
uint64_t spendable_age_coinbase;
uint64_t spendable_age {10};
uint64_t spendable_age_coinbase {60};
address_parse_info import_payment_address;
secret_key import_payment_viewkey;

@ -26,7 +26,7 @@ void
CurrentBlockchainStatus::monitor_blockchain()
{
TxSearch::set_search_thread_life(
bc_setup.search_thread_life_in_seconds);
bc_setup.search_thread_life);
stop_blockchain_monitor_loop = false;
@ -49,8 +49,7 @@ CurrentBlockchainStatus::monitor_blockchain()
clean_search_thread_map();
std::this_thread::sleep_for(
std::chrono::seconds(
bc_setup.refresh_block_status_every_seconds));
bc_setup.refresh_block_status_every);
}
is_running = false;
@ -440,6 +439,7 @@ CurrentBlockchainStatus::get_mempool_txs()
return mempool_txs;
}
//@todo search_if_payment_made is way too long!
bool
CurrentBlockchainStatus::search_if_payment_made(
const string& payment_id_str,
@ -516,7 +516,8 @@ CurrentBlockchainStatus::search_if_payment_made(
if (!hex_to_pod(tx_payment_id_str, encrypted_payment_id8))
{
OMERROR << "Failed parsing hex to pod for encrypted_payment_id8";
OMERROR << "Failed parsing hex to pod for "
"encrypted_payment_id8";
continue;
}
@ -773,7 +774,8 @@ CurrentBlockchainStatus::get_known_outputs_keys(
}
known_outputs_keys = get_search_thread(address).get_known_outputs_keys();
known_outputs_keys = get_search_thread(address)
.get_known_outputs_keys();
return true;
}
@ -802,8 +804,10 @@ CurrentBlockchainStatus::get_xmr_address_viewkey(
return false;
}
address = get_search_thread(address_str).get_xmr_address_viewkey().first;
viewkey = get_search_thread(address_str).get_xmr_address_viewkey().second;
address = get_search_thread(address_str)
.get_xmr_address_viewkey().first;
viewkey = get_search_thread(address_str)
.get_xmr_address_viewkey().second;
return true;
}
@ -961,7 +965,8 @@ CurrentBlockchainStatus::get_search_thread(string const& acc_address)
if (it == searching_threads.end())
{
OMERROR << "Search thread does not exisit for addr: " << acc_address;
OMERROR << "Search thread does not exisit for addr: "
<< acc_address;
throw std::runtime_error("Trying to accesses "
"non-existing search thread");
}

@ -13,7 +13,7 @@ namespace xmreg
MysqlPing::MysqlPing(
std::shared_ptr<MySqlConnector> _conn,
uint64_t _ping_time)
seconds _ping_time)
: conn {_conn}, ping_time {_ping_time}
{}

@ -14,13 +14,17 @@
namespace xmreg
{
using chrono::seconds;
using namespace literals::chrono_literals;
class MysqlPing
{
public:
enum class StopReason {NotYetStopped, PingFailed, PointerExpired};
MysqlPing(std::shared_ptr<MySqlConnector> _conn, uint64_t _ping_time = 300);
MysqlPing(std::shared_ptr<MySqlConnector> _conn,
seconds _ping_time = 300s);
void operator()();
void stop() {keep_looping = false;}
@ -33,7 +37,7 @@ public:
private:
std::weak_ptr<MySqlConnector> conn;
uint64_t ping_time; // in seconds
seconds ping_time; // in seconds
atomic<bool> keep_looping {true};
atomic<uint64_t> counter {0};
atomic<StopReason> why_stoped {StopReason::NotYetStopped};

@ -46,7 +46,7 @@ TxSearch::TxSearch(XmrAccount& _acc,
// this accont
searched_blk_no = acc->scanned_block_height;
last_ping_timestamp = 0;
last_ping_timestamp = 0s;
ping();
}
@ -55,7 +55,7 @@ void
TxSearch::operator()()
{
uint64_t current_timestamp = get_current_timestamp();
seconds current_timestamp = get_current_timestamp();
last_ping_timestamp = current_timestamp;
@ -71,7 +71,7 @@ TxSearch::operator()()
{
while(continue_search)
{
uint64_t loop_timestamp {current_timestamp};
seconds loop_timestamp {current_timestamp};
uint64_t last_block_height = current_bc_status->current_height;
@ -88,7 +88,7 @@ TxSearch::operator()()
std::this_thread::sleep_for(
std::chrono::seconds(
current_bc_status->get_bc_setup()
.refresh_block_status_every_seconds)
.refresh_block_status_every)
);
loop_timestamp = get_current_timestamp();
@ -600,20 +600,21 @@ TxSearch::get_searched_blk_no() const
return searched_blk_no;
}
inline uint64_t
inline seconds
TxSearch::get_current_timestamp() const
{
return chrono::duration_cast<chrono::seconds>(
chrono::system_clock::now().time_since_epoch()).count();
return chrono::duration_cast<seconds>(
chrono::system_clock::now().time_since_epoch());
}
void
TxSearch::ping()
{
OMINFO << "New last_ping_timestamp: " << last_ping_timestamp;
OMINFO << "New last_ping_timestamp: "
<< last_ping_timestamp.count();
last_ping_timestamp = chrono::duration_cast<chrono::seconds>(
chrono::system_clock::now().time_since_epoch()).count();
last_ping_timestamp = chrono::duration_cast<seconds>(
chrono::system_clock::now().time_since_epoch());
}
bool
@ -836,7 +837,7 @@ TxSearch::get_xmr_address_viewkey() const
void
TxSearch::set_search_thread_life(uint64_t life_seconds)
TxSearch::set_search_thread_life(seconds life_seconds)
{
thread_search_life = life_seconds;
}
@ -866,6 +867,6 @@ TxSearch::delete_existing_tx_if_exists(string const& tx_hash)
// default value of static veriables
uint64_t TxSearch::thread_search_life {600};
seconds TxSearch::thread_search_life {600};
}

@ -14,6 +14,9 @@ namespace xmreg
using namespace std;
using chrono::seconds;
using namespace literals::chrono_literals;
class XmrAccount;
class MySqlAccounts;
@ -40,7 +43,7 @@ private:
// how long should the search thread be live after no request
// are coming from the frontend. For example, when a user finishes
// using the service.
static uint64_t thread_search_life; // in seconds
static seconds thread_search_life;
bool continue_search {true};
@ -51,7 +54,7 @@ private:
mutex getting_eptr;
mutex getting_known_outputs_keys;
uint64_t last_ping_timestamp;
seconds last_ping_timestamp;
atomic<uint64_t> searched_blk_no;
@ -98,7 +101,7 @@ public:
virtual uint64_t
get_searched_blk_no() const;
virtual uint64_t
virtual seconds
get_current_timestamp() const;
virtual void
@ -160,7 +163,7 @@ public:
get_xmr_address_viewkey() const;
static void
set_search_thread_life(uint64_t life_seconds);
set_search_thread_life(seconds life_seconds);
virtual bool
delete_existing_tx_if_exists(string const& tx_hash);

@ -14,8 +14,6 @@ namespace
class BCSTATUS_TEST : public ::testing::TestWithParam<network_type>
{
public:
@ -1496,7 +1494,7 @@ TEST_P(BCSTATUS_TEST, MonitorBlockchain)
// set refresh rate to 1 second as we dont wont to wait long
xmreg::BlockchainSetup bs = bcs->get_bc_setup();
bs.refresh_block_status_every_seconds = 1;
bs.refresh_block_status_every = 1s;
bcs->set_bc_setup(bs);
bcs->is_running = false;

@ -159,7 +159,7 @@ public:
db_config = readin_config();
if (db_config.empty())
FAIL() << "Cant readin_config()";
FAIL() << "Cant read in_config()";
xmreg::MySqlConnector::url = db_config["url"];
xmreg::MySqlConnector::port = db_config["port"];
@ -1502,7 +1502,7 @@ TEST_F(MYSQL_TEST, MysqlPingThreadStopsOnPingFailure)
auto conn = xmr_accounts->get_connection();
// create ping functor that will be pinging mysql every 1 second
xmreg::MysqlPing mysql_ping {conn, 1};
xmreg::MysqlPing mysql_ping {conn, 1s};
{
// create ping thread and start pinging
@ -1543,7 +1543,7 @@ TEST_F(MYSQL_TEST, MysqlPingThreadStopsOnPointerExpiry)
ASSERT_TRUE(new_conn->get_connection().connected());
// create ping functor that will be pinging mysql every 1 second
xmreg::MysqlPing mysql_ping {new_conn, 1};
xmreg::MysqlPing mysql_ping {new_conn, 1s};
{
// create ping thread and start pinging

Loading…
Cancel
Save