diff options
author | Jacob Brydolf <jacob@brydolf.net> | 2016-11-10 15:36:16 +0100 |
---|---|---|
committer | Jacob Brydolf <jacob@brydolf.net> | 2016-11-13 03:36:44 +0100 |
commit | 4fca34ddb4d711ad45f4ecb30d74c7d8ebdcba5b (patch) | |
tree | 9acd7738856770ae641b85179b5aac1652e7a3de /src/wallet/wallet2.cpp | |
parent | Merge pull request #1330 (diff) | |
download | monero-4fca34ddb4d711ad45f4ecb30d74c7d8ebdcba5b.tar.xz |
Wallet2: calculate approximate blockchain height on offline creation
Wallet API: add approximateBlockChainHeight()
Diffstat (limited to 'src/wallet/wallet2.cpp')
-rw-r--r-- | src/wallet/wallet2.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 02346e0eb..091439ce5 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2004,6 +2004,19 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const std::stri m_account_public_address = m_account.get_keys().m_account_address; m_watch_only = false; + if(m_refresh_from_block_height == 0 && !recover){ + // Wallets created offline don't know blockchain height. + // Set blockchain height calculated from current date/time + // -1 month for fluctuations in block time and machine date/time setup. + // avg seconds per block + const int seconds_per_block = DIFFICULTY_TARGET_V2; + // ~num blocks per month + const uint64_t blocks_per_month = 60*60*24*30/seconds_per_block; + uint64_t approx_blockchain_height = get_approximate_blockchain_height(); + if(approx_blockchain_height > 0) { + m_refresh_from_block_height = approx_blockchain_height - blocks_per_month; + } + } bool r = store_keys(m_keys_file, password, false); THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file); @@ -4578,6 +4591,21 @@ uint64_t wallet2::get_daemon_blockchain_target_height(string &err) return resp_t.result.target_height; } +uint64_t wallet2::get_approximate_blockchain_height() const +{ + if (m_testnet) return 0; + // time of v2 fork + const time_t fork_time = 1458748658; + // v2 fork block + const uint64_t fork_block = 1009827; + // avg seconds per block + const int seconds_per_block = DIFFICULTY_TARGET_V2; + // Calculated blockchain height + uint64_t approx_blockchain_height = fork_block + (time(NULL) - fork_time)/seconds_per_block; + LOG_PRINT_L2("Calculated blockchain height: " << approx_blockchain_height); + return approx_blockchain_height; +} + void wallet2::set_tx_note(const crypto::hash &txid, const std::string ¬e) { m_tx_notes[txid] = note; |