aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorZachary Michaels <mikezackles@gmail.com>2014-07-16 13:30:15 -0400
committerRiccardo Spagni <ric@spagni.net>2014-09-15 15:53:01 +0200
commit07470fd400ee30b84f6227edffb24094d03781cb (patch)
tree6399848a2020528971884f5f625d0a2403f92327 /src/wallet
parentincrease ABSTRACT_SERVER_SEND_QUE_MAX_COUNT to a more sane value (diff)
downloadmonero-07470fd400ee30b84f6227edffb24094d03781cb.tar.xz
Add testnet flag
Source: cryptonotefoundation
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet2.cpp37
-rw-r--r--src/wallet/wallet2.h7
2 files changed, 35 insertions, 9 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 48aa164ab..be857c78a 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -420,9 +420,6 @@ bool wallet2::clear()
{
m_blockchain.clear();
m_transfers.clear();
- cryptonote::block b;
- cryptonote::generate_genesis_block(b);
- m_blockchain.push_back(get_block_hash(b));
m_local_bc_height = 1;
return true;
}
@@ -501,6 +498,10 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const std::stri
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str());
if(!r) LOG_PRINT_RED_L0("String with address text not saved");
+ cryptonote::block b;
+ generate_genesis(b);
+ m_blockchain.push_back(get_block_hash(b));
+
store();
return retval;
}
@@ -573,15 +574,28 @@ void wallet2::load(const std::string& wallet_, const std::string& password)
m_account_public_address.m_view_public_key != m_account.get_keys().m_account_address.m_view_public_key,
error::wallet_files_doesnt_correspond, m_keys_file, m_wallet_file);
- if(m_blockchain.empty())
+ cryptonote::block genesis;
+ generate_genesis(genesis);
+ crypto::hash genesis_hash = get_block_hash(genesis);
+
+ if (m_blockchain.empty())
{
- cryptonote::block b;
- cryptonote::generate_genesis_block(b);
- m_blockchain.push_back(get_block_hash(b));
+ m_blockchain.push_back(genesis_hash);
+ }
+ else
+ {
+ check_genesis(genesis_hash);
}
+
m_local_bc_height = m_blockchain.size();
}
//----------------------------------------------------------------------------------------------------
+void wallet2::check_genesis(const crypto::hash& genesis_hash) {
+ std::string what("Genesis block missmatch. You probably use wallet without testnet flag with blockchain from test network or vice versa");
+
+ THROW_WALLET_EXCEPTION_IF(genesis_hash != m_blockchain[0], error::wallet_internal_error, what);
+}
+//----------------------------------------------------------------------------------------------------
void wallet2::store()
{
bool r = tools::serialize_obj_to_file(*this, m_wallet_file);
@@ -918,4 +932,13 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions(std::vector<crypto
}
}
}
+
+//----------------------------------------------------------------------------------------------------
+void wallet2::generate_genesis(cryptonote::block& b) {
+ if (m_testnet) {
+ cryptonote::generate_testnet_genesis_block(b);
+ } else {
+ cryptonote::generate_genesis_block(b);
+ }
+}
}
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index a6f4c5c17..28788f693 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -80,9 +80,9 @@ namespace tools
class wallet2
{
- wallet2(const wallet2&) : m_run(true), m_callback(0) {};
+ wallet2(const wallet2&) : m_run(true), m_callback(0), m_testnet(false) {};
public:
- wallet2() : m_run(true), m_callback(0) {};
+ wallet2(bool testnet = false) : m_run(true), m_callback(0), m_testnet(testnet) {};
struct transfer_details
{
uint64_t m_block_height;
@@ -209,6 +209,8 @@ namespace tools
bool prepare_file_names(const std::string& file_path);
void process_unconfirmed(const cryptonote::transaction& tx);
void add_unconfirmed_tx(const cryptonote::transaction& tx, uint64_t change_amount);
+ void generate_genesis(cryptonote::block& b);
+ void check_genesis(const crypto::hash& genesis_hash); //throws
cryptonote::account_base m_account;
std::string m_daemon_address;
@@ -228,6 +230,7 @@ namespace tools
std::atomic<bool> m_run;
i_wallet2_callback* m_callback;
+ bool m_testnet;
};
}
BOOST_CLASS_VERSION(tools::wallet2, 7)