Separate testnet address prefix

This commit is contained in:
Zachary Michaels
2014-09-09 10:58:53 -04:00
committed by Riccardo Spagni
parent ee1bacc64f
commit d03308734b
21 changed files with 126 additions and 69 deletions
+2 -2
View File
@@ -496,7 +496,7 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const std::stri
bool r = store_keys(m_keys_file, password);
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str());
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet));
if(!r) LOG_PRINT_RED_L0("String with address text not saved");
cryptonote::block b;
@@ -562,7 +562,7 @@ void wallet2::load(const std::string& wallet_, const std::string& password)
THROW_WALLET_EXCEPTION_IF(e || !exists, error::file_not_found, m_keys_file);
load_keys(m_keys_file, password);
LOG_PRINT_L0("Loaded wallet keys file, with public address: " << m_account.get_public_address_str());
LOG_PRINT_L0("Loaded wallet keys file, with public address: " << m_account.get_public_address_str(m_testnet));
//keys loaded ok!
//try to load wallet file. but even if we failed, it is not big problem
+4 -2
View File
@@ -158,6 +158,8 @@ namespace tools
void refresh(uint64_t start_height, size_t & blocks_fetched, bool& received_money);
bool refresh(size_t & blocks_fetched, bool& received_money, bool& ok);
bool testnet() { return m_testnet; }
uint64_t balance();
uint64_t unlocked_balance();
template<typename T>
@@ -360,7 +362,7 @@ namespace tools
{
THROW_WALLET_EXCEPTION_IF(0 == dt.amount, error::zero_destination);
needed_money += dt.amount;
THROW_WALLET_EXCEPTION_IF(needed_money < dt.amount, error::tx_sum_overflow, dsts, fee);
THROW_WALLET_EXCEPTION_IF(needed_money < dt.amount, error::tx_sum_overflow, dsts, fee, m_testnet);
}
// randomly select inputs for transaction
@@ -465,7 +467,7 @@ namespace tools
}
bool r = cryptonote::construct_tx(m_account.get_keys(), sources, splitted_dsts, extra, tx, unlock_time);
THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time);
THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time, m_testnet);
THROW_WALLET_EXCEPTION_IF(m_upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, m_upper_transaction_size_limit);
std::string key_images;
+26 -11
View File
@@ -376,11 +376,18 @@ namespace tools
typedef std::vector<cryptonote::tx_source_entry> sources_t;
typedef std::vector<cryptonote::tx_destination_entry> destinations_t;
explicit tx_not_constructed(std::string&& loc, const sources_t& sources, const destinations_t& destinations, uint64_t unlock_time)
: transfer_error(std::move(loc), "transaction was not constructed")
, m_sources(sources)
, m_destinations(destinations)
, m_unlock_time(unlock_time)
explicit tx_not_constructed(
std::string && loc
, sources_t const & sources
, destinations_t const & destinations
, uint64_t unlock_time
, bool testnet
)
: transfer_error {std::move(loc), "transaction was not constructed"}
, m_sources {sources}
, m_destinations {destinations}
, m_unlock_time {unlock_time}
, m_testnet {testnet}
{
}
@@ -414,7 +421,7 @@ namespace tools
for (size_t i = 0; i < m_destinations.size(); ++i)
{
const cryptonote::tx_destination_entry& dst = m_destinations[i];
ss << "\n " << i << ": " << cryptonote::get_account_address_as_str(dst.addr) << " " <<
ss << "\n " << i << ": " << cryptonote::get_account_address_as_str(m_testnet, dst.addr) << " " <<
cryptonote::print_money(dst.amount);
}
@@ -427,6 +434,7 @@ namespace tools
sources_t m_sources;
destinations_t m_destinations;
uint64_t m_unlock_time;
bool m_testnet;
};
//----------------------------------------------------------------------------------------------------
struct tx_rejected : public transfer_error
@@ -457,10 +465,16 @@ namespace tools
//----------------------------------------------------------------------------------------------------
struct tx_sum_overflow : public transfer_error
{
explicit tx_sum_overflow(std::string&& loc, const std::vector<cryptonote::tx_destination_entry>& destinations, uint64_t fee)
: transfer_error(std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits<uint64_t>::max()))
, m_destinations(destinations)
, m_fee(fee)
explicit tx_sum_overflow(
std::string && loc
, const std::vector<cryptonote::tx_destination_entry>& destinations
, uint64_t fee
, bool testnet
)
: transfer_error {std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits<uint64_t>::max())}
, m_destinations {destinations}
, m_fee {fee}
, m_testnet {testnet}
{
}
@@ -475,7 +489,7 @@ namespace tools
", destinations:";
for (const auto& dst : m_destinations)
{
ss << '\n' << cryptonote::print_money(dst.amount) << " -> " << cryptonote::get_account_address_as_str(dst.addr);
ss << '\n' << cryptonote::print_money(dst.amount) << " -> " << cryptonote::get_account_address_as_str(m_testnet, dst.addr);
}
return ss.str();
}
@@ -483,6 +497,7 @@ namespace tools
private:
std::vector<cryptonote::tx_destination_entry> m_destinations;
uint64_t m_fee;
bool m_testnet;
};
//----------------------------------------------------------------------------------------------------
struct tx_too_big : public transfer_error
+2 -2
View File
@@ -101,7 +101,7 @@ namespace tools
{
try
{
res.address = m_wallet.get_account().get_public_address_str();
res.address = m_wallet.get_account().get_public_address_str(m_wallet.testnet());
}
catch (std::exception& e)
{
@@ -118,7 +118,7 @@ namespace tools
for (auto it = destinations.begin(); it != destinations.end(); it++)
{
cryptonote::tx_destination_entry de;
if(!get_account_address_from_str(de.addr, it->address))
if(!get_account_address_from_str(de.addr, m_wallet.testnet(), it->address))
{
er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS;
er.message = std::string("WALLET_RPC_ERROR_CODE_WRONG_ADDRESS: ") + it->address;