make some Wallet functions virtual

pull/254/head
larteyoh 2 months ago
parent d4f35e149a
commit b594f1d3d9

@ -22,7 +22,7 @@ int neroshop::MoneroWallet::create_random(const std::string& password, const std
monero::monero_wallet_config wallet_config_obj;
wallet_config_obj.m_path = path;
wallet_config_obj.m_password = password;
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(this->network_type);
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(Wallet::network_type);
monero_wallet_obj = std::unique_ptr<monero_wallet_full>(monero_wallet_full::create_wallet (wallet_config_obj, nullptr));
if(monero_wallet_obj.get()) std::cout << "\033[1;35m" << "created wallet \"" << path << ".keys\"" << "\033[0m" << std::endl;
@ -46,7 +46,7 @@ int neroshop::MoneroWallet::create_from_seed(const std::string& seed, const std:
monero::monero_wallet_config wallet_config_obj;
wallet_config_obj.m_path = path;
wallet_config_obj.m_password = password;
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(this->network_type);
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(Wallet::network_type);
wallet_config_obj.m_seed = seed;
monero_wallet_obj = std::unique_ptr<monero_wallet_full>(monero_wallet_full::create_wallet (wallet_config_obj, nullptr));
@ -72,7 +72,7 @@ int neroshop::MoneroWallet::create_from_keys(const std::string& primary_address,
monero::monero_wallet_config wallet_config_obj;
wallet_config_obj.m_path = path;
wallet_config_obj.m_password = password;
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(this->network_type);
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(Wallet::network_type);
wallet_config_obj.m_primary_address = primary_address;
wallet_config_obj.m_private_view_key = view_key;
wallet_config_obj.m_private_spend_key = spend_key; // To restore a view-only wallet, leave the spend key blank
@ -92,7 +92,7 @@ int neroshop::MoneroWallet::restore_from_seed(const std::string& seed, uint64_t
monero::monero_wallet_config wallet_config_obj;
wallet_config_obj.m_path = ""; // set path to "" for an in-memory wallet
wallet_config_obj.m_password = "";
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(this->network_type);
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(Wallet::network_type);
wallet_config_obj.m_seed = seed;
wallet_config_obj.m_restore_height = restore_height;
@ -116,7 +116,7 @@ int neroshop::MoneroWallet::restore_from_seed(const std::string& seed, uint64_t
int neroshop::MoneroWallet::restore_from_keys(const std::string& primary_address, const std::string& view_key, const std::string& spend_key)
{
// Check validity of primary address
if(!monero_utils::is_valid_address(primary_address, static_cast<monero::monero_network_type>(this->network_type))) {
if(!monero_utils::is_valid_address(primary_address, static_cast<monero::monero_network_type>(Wallet::network_type))) {
std::cerr << "\033[1;91mInvalid Monero address\033[0m\n";
return static_cast<int>(WalletError::InvalidAddress);
}
@ -124,7 +124,7 @@ int neroshop::MoneroWallet::restore_from_keys(const std::string& primary_address
monero::monero_wallet_config wallet_config_obj;
wallet_config_obj.m_path = ""; // set path to "" for an in-memory wallet
wallet_config_obj.m_password = "";
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(this->network_type);
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(Wallet::network_type);
wallet_config_obj.m_primary_address = primary_address;
wallet_config_obj.m_private_view_key = view_key;
wallet_config_obj.m_private_spend_key = spend_key;
@ -145,7 +145,7 @@ int neroshop::MoneroWallet::open(const std::string& path, const std::string& pas
}
try {
monero_wallet_obj = std::unique_ptr<monero_wallet_full>(monero::monero_wallet_full::open_wallet(path, password, static_cast<monero::monero_network_type>(this->network_type)));
monero_wallet_obj = std::unique_ptr<monero_wallet_full>(monero::monero_wallet_full::open_wallet(path, password, static_cast<monero::monero_network_type>(Wallet::network_type)));
} catch (const std::exception& e) {
std::string error_msg = e.what();
std::cerr << "\033[1;91m" << error_msg << "\033[0m\n";//tools::error::invalid_password
@ -280,6 +280,29 @@ void neroshop::MoneroWallet::transfer(const std::vector<std::pair<std::string, d
//-------------------------------------------------------
//-------------------------------------------------------
//-------------------------------------------------------
void neroshop::MoneroWallet::set_network_type(WalletNetworkType network_type) {
auto current_network_type = get_wallet_network_type();
if(current_network_type == network_type) {
return;
}
auto network_type_str = get_wallet_network_type_as_string();
if(monero_wallet_obj.get()) throw std::runtime_error("cannot change " + network_type_str + " wallet network type");
Wallet::network_type = network_type;
}
//-------------------------------------------------------
//-------------------------------------------------------
//-------------------------------------------------------
WalletNetworkType neroshop::MoneroWallet::get_wallet_network_type() const {
if(!monero_wallet_obj.get()) return Wallet::network_type;
return static_cast<WalletNetworkType>(monero_wallet_obj->get_network_type());
}
//-------------------------------------------------------
std::string neroshop::MoneroWallet::get_network_port() const {
auto wallet_network_type = get_wallet_network_type();
return WalletNetworkPortMap[wallet_network_type][0];
}
//-------------------------------------------------------
//-------------------------------------------------------
std::string neroshop::MoneroWallet::get_primary_address() const {
if(!monero_wallet_obj.get()) throw std::runtime_error("monero_wallet_full is not opened");
return monero_wallet_obj->get_primary_address(); // same as: monero_wallet_obj->get_account(0, true).m_primary_address.get();
@ -413,6 +436,11 @@ unsigned int neroshop::MoneroWallet::get_height_by_date(int year, int month, int
}
//-------------------------------------------------------
//-------------------------------------------------------
void * neroshop::MoneroWallet::get_handle() const {
return monero_wallet_obj.get();
}
//-------------------------------------------------------
//-------------------------------------------------------
//-------------------------------------------------------
bool neroshop::MoneroWallet::is_opened() const {
return (monero_wallet_obj != nullptr);
@ -442,8 +470,8 @@ bool neroshop::MoneroWallet::file_exists(const std::string& filename) const {
}
//-------------------------------------------------------
bool neroshop::MoneroWallet::is_valid_address(const std::string& address) const {
auto network_type = get_wallet_network_type();
return monero_utils::is_valid_address(address, static_cast<monero::monero_network_type>(network_type));
auto wallet_network_type = get_wallet_network_type();
return monero_utils::is_valid_address(address, static_cast<monero::monero_network_type>(wallet_network_type));
}
//-------------------------------------------------------
//-------------------------------------------------------

@ -28,6 +28,11 @@ public:
void transfer(const std::string& address, double amount) override;
void transfer(const std::vector<std::pair<std::string, double>>& payment_addresses) override;
void set_network_type(WalletNetworkType network_type) override;
WalletNetworkType get_wallet_network_type() const override;
std::string get_network_port() const override;
std::string get_primary_address() const override;
std::string get_address(unsigned int index) const override;
@ -61,6 +66,8 @@ public:
unsigned int get_height() const override;
unsigned int get_height_by_date(int year, int month, int day) const override;
void * get_handle() const override;
bool is_opened() const override;
bool is_connected_to_daemon() const override;
bool is_synced() const override;

@ -54,7 +54,7 @@ int neroshop::Wallet::create_random(const std::string& password, const std::stri
monero::monero_wallet_config wallet_config_obj;
wallet_config_obj.m_path = path;
wallet_config_obj.m_password = password;
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(this->network_type);
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(Wallet::network_type);
monero_wallet_obj = std::unique_ptr<monero_wallet_full>(monero_wallet_full::create_wallet (wallet_config_obj, nullptr));
if(monero_wallet_obj.get()) std::cout << "\033[1;35;49m" << "created wallet \"" << path << ".keys\"" << "\033[0m" << std::endl;
@ -79,7 +79,7 @@ int neroshop::Wallet::create_from_seed(const std::string& seed, const std::strin
monero::monero_wallet_config wallet_config_obj;
wallet_config_obj.m_path = path;
wallet_config_obj.m_password = password;
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(this->network_type);
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(Wallet::network_type);
wallet_config_obj.m_seed = seed;
monero_wallet_obj = std::unique_ptr<monero_wallet_full>(monero_wallet_full::create_wallet (wallet_config_obj, nullptr));
@ -107,7 +107,7 @@ int neroshop::Wallet::create_from_keys(const std::string& primary_address, const
monero::monero_wallet_config wallet_config_obj;
wallet_config_obj.m_path = path;
wallet_config_obj.m_password = password;
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(this->network_type);
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(Wallet::network_type);
wallet_config_obj.m_primary_address = primary_address;
wallet_config_obj.m_private_view_key = view_key;
wallet_config_obj.m_private_spend_key = spend_key;
@ -127,7 +127,7 @@ int neroshop::Wallet::restore_from_seed(const std::string& seed, uint64_t restor
monero::monero_wallet_config wallet_config_obj;
wallet_config_obj.m_path = ""; // set path to "" for an in-memory wallet
wallet_config_obj.m_password = "";
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(this->network_type);
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(Wallet::network_type);
wallet_config_obj.m_seed = seed;
wallet_config_obj.m_restore_height = (restore_height == 0) ? 1570000 : restore_height;//1570000 (stagenet);3120000 (mainnet)
@ -151,7 +151,7 @@ int neroshop::Wallet::restore_from_seed(const std::string& seed, uint64_t restor
int neroshop::Wallet::restore_from_keys(const std::string& primary_address, const std::string& view_key, const std::string& spend_key)
{
// Check validity of primary address
if(!monero_utils::is_valid_address(primary_address, static_cast<monero::monero_network_type>(this->network_type))) {
if(!monero_utils::is_valid_address(primary_address, static_cast<monero::monero_network_type>(Wallet::network_type))) {
std::cerr << "\033[1;91mInvalid Monero address\033[0m\n";
return static_cast<int>(WalletError::InvalidAddress);
}
@ -159,7 +159,7 @@ int neroshop::Wallet::restore_from_keys(const std::string& primary_address, cons
monero::monero_wallet_config wallet_config_obj;
wallet_config_obj.m_path = ""; // set path to "" for an in-memory wallet
wallet_config_obj.m_password = "";
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(this->network_type);
wallet_config_obj.m_network_type = static_cast<monero::monero_network_type>(Wallet::network_type);
wallet_config_obj.m_primary_address = primary_address;
wallet_config_obj.m_private_view_key = view_key;
wallet_config_obj.m_private_spend_key = spend_key;
@ -179,7 +179,7 @@ int neroshop::Wallet::open(const std::string& path, const std::string& password)
}
try {
monero_wallet_obj = std::unique_ptr<monero_wallet_full>(monero::monero_wallet_full::open_wallet(path, password, static_cast<monero::monero_network_type>(this->network_type)));
monero_wallet_obj = std::unique_ptr<monero_wallet_full>(monero::monero_wallet_full::open_wallet(path, password, static_cast<monero::monero_network_type>(Wallet::network_type)));
} catch (const std::exception& e) {
std::string error_msg = e.what();
std::cerr << "\033[1;91m" << error_msg << "\033[0m\n";//tools::error::invalid_password
@ -393,7 +393,7 @@ void neroshop::Wallet::set_network_type(WalletNetworkType network_type) {
default:
break;
}
this->network_type = network_type;
Wallet::network_type = network_type;
}
//-------------------------------------------------------
void neroshop::Wallet::set_network_type_by_string(const std::string& network_type) {

@ -113,18 +113,18 @@ public:
// setters
void set_wallet_type(WalletType wallet_type);
void set_network_type(WalletNetworkType network_type);
virtual void set_network_type(WalletNetworkType network_type);
void set_network_type_by_string(const std::string& network_type);
void set_tx_note(const std::string& txid, const std::string& tx_note); // "set_tx_note <txid> [free note text here]" - useful for filling address information
// getters
WalletType get_wallet_type() const;
WalletNetworkType get_wallet_network_type() const;
virtual WalletNetworkType get_wallet_network_type() const;
static WalletNetworkType get_network_type();
std::string get_wallet_network_type_as_string() const;
static std::string get_network_type_as_string();
std::string get_network_port() const;
virtual std::string get_network_port() const;
double get_sync_percentage() const;
unsigned long long get_sync_height() const;
@ -174,7 +174,7 @@ public:
std::string get_status() const; // "status" - Check current status of wallet.
std::string get_version() const; // "version" - Check software version.
// get wallet handles (monero, wownero, etc.)
void * get_handle() const;
virtual void * get_handle() const;
monero_wallet_full * get_monero_wallet() const;
//wownero_wallet_full * get_wownero_wallet() const;
std::vector<std::string> recent_address_list; // recently used addresses

Loading…
Cancel
Save