aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/stack_trace.cpp19
-rw-r--r--src/cryptonote_core/cryptonote_basic_impl.cpp2
-rw-r--r--src/cryptonote_core/cryptonote_format_utils.cpp2
-rw-r--r--src/daemon/rpc_command_executor.cpp4
-rw-r--r--src/simplewallet/simplewallet.cpp49
-rw-r--r--src/simplewallet/simplewallet.h1
-rw-r--r--src/wallet/api/wallet.cpp32
-rw-r--r--src/wallet/api/wallet.h4
-rw-r--r--src/wallet/wallet2.cpp8
-rw-r--r--src/wallet/wallet2.h7
-rw-r--r--src/wallet/wallet2_api.h18
-rw-r--r--src/wallet/wallet_rpc_server.cpp98
-rw-r--r--src/wallet/wallet_rpc_server.h6
-rw-r--r--src/wallet/wallet_rpc_server_commands_defs.h79
-rw-r--r--src/wallet/wallet_rpc_server_error_codes.h1
15 files changed, 281 insertions, 49 deletions
diff --git a/src/common/stack_trace.cpp b/src/common/stack_trace.cpp
index 99e4bda2c..67065aae7 100644
--- a/src/common/stack_trace.cpp
+++ b/src/common/stack_trace.cpp
@@ -26,11 +26,17 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#if !defined __GNUC__ || defined __MINGW32__ || defined __MINGW64__
+#define USE_UNWIND
+#endif
+
#include "common/stack_trace.h"
#include "misc_log_ex.h"
+#ifdef USE_UNWIND
#define UNW_LOCAL_ONLY
#include <libunwind.h>
#include <cxxabi.h>
+#endif
#ifndef STATICLIB
#include <dlfcn.h>
#endif
@@ -99,6 +105,7 @@ void set_stack_trace_log(const std::string &log)
void log_stack_trace(const char *msg)
{
+#ifdef USE_UNWIND
unw_context_t ctx;
unw_cursor_t cur;
unw_word_t ip, off;
@@ -106,10 +113,13 @@ void log_stack_trace(const char *msg)
char sym[512], *dsym;
int status;
const char *log = stack_trace_log.empty() ? NULL : stack_trace_log.c_str();
+#endif
if (msg)
ST_LOG(msg);
ST_LOG("Unwound call stack:");
+
+#ifdef USE_UNWIND
if (unw_getcontext(&ctx) < 0) {
ST_LOG("Failed to create unwind context");
return;
@@ -138,6 +148,15 @@ void log_stack_trace(const char *msg)
ST_LOG(" " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip << " " << (!status && dsym ? dsym : sym) << " + " << "0x" << off);
free(dsym);
}
+#else
+ std::stringstream ss;
+ ss << el::base::debug::StackTrace();
+ std::vector<std::string> lines;
+ std::string s = ss.str();
+ boost::split(lines, s, boost::is_any_of("\n"));
+ for (const auto &line: lines)
+ ST_LOG(line);
+#endif
}
} // namespace tools
diff --git a/src/cryptonote_core/cryptonote_basic_impl.cpp b/src/cryptonote_core/cryptonote_basic_impl.cpp
index 51c9269a5..338210f01 100644
--- a/src/cryptonote_core/cryptonote_basic_impl.cpp
+++ b/src/cryptonote_core/cryptonote_basic_impl.cpp
@@ -317,7 +317,7 @@ namespace cryptonote {
{
bool has_payment_id;
crypto::hash8 payment_id;
- return get_account_address_from_str_or_url(address, testnet, str_or_url);
+ return get_account_address_from_str_or_url(address, has_payment_id, payment_id, testnet, str_or_url);
}
//--------------------------------------------------------------------------------
bool operator ==(const cryptonote::transaction& a, const cryptonote::transaction& b) {
diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp
index 70ba7ee18..2e6917878 100644
--- a/src/cryptonote_core/cryptonote_format_utils.cpp
+++ b/src/cryptonote_core/cryptonote_format_utils.cpp
@@ -443,6 +443,8 @@ namespace cryptonote
{
if (!memcmp(&destinations[n].addr, &sender_keys.m_account_address, sizeof(destinations[0].addr)))
continue;
+ if (destinations[n].amount == 0)
+ continue;
if (memcmp(&destinations[n].addr, &destinations[0].addr, sizeof(destinations[0].addr)))
return null_pkey;
}
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index 2bcfd7a95..f7d85b5ef 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -381,8 +381,8 @@ bool t_rpc_command_executor::show_status() {
% (unsigned)ires.outgoing_connections_count
% (unsigned)ires.incoming_connections_count
% (unsigned int)floor(uptime / 60.0 / 60.0 / 24.0)
- % (unsigned int)floor(fmod((uptime / 60.0 / 60.0), 24.0)
- % (unsigned int)floor(fmod((uptime / 60.0), 60.0)
+ % (unsigned int)floor(fmod((uptime / 60.0 / 60.0), 24.0))
+ % (unsigned int)floor(fmod((uptime / 60.0), 60.0))
% (unsigned int)fmod(uptime, 60.0)
;
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index f5e20be48..a8f1d177f 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -286,6 +286,7 @@ std::string simple_wallet::get_commands_str()
bool simple_wallet::viewkey(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
+ if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
// don't log
std::cout << "secret: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key) << std::endl;
std::cout << "public: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_account_address.m_view_public_key) << std::endl;
@@ -295,6 +296,12 @@ bool simple_wallet::viewkey(const std::vector<std::string> &args/* = std::vector
bool simple_wallet::spendkey(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
+ if (m_wallet->watch_only())
+ {
+ fail_msg_writer() << tr("wallet is watch-only and has no spend key");
+ return true;
+ }
+ if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
// don't log
std::cout << "secret: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_spend_secret_key) << std::endl;
std::cout << "public: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_account_address.m_spend_public_key) << std::endl;
@@ -312,6 +319,7 @@ bool simple_wallet::seed(const std::vector<std::string> &args/* = std::vector<st
fail_msg_writer() << tr("wallet is watch-only and has no seed");
return true;
}
+ if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
if (m_wallet->is_deterministic())
{
if (m_wallet->get_seed_language().empty())
@@ -380,7 +388,7 @@ bool simple_wallet::change_password(const std::vector<std::string> &args)
m_wallet->rewrite(m_wallet_file, pwd_container->password());
m_wallet->store();
}
- catch (const wallet_logic_error& e)
+ catch (const tools::error::wallet_logic_error& e)
{
fail_msg_writer() << tr("Error with wallet rewrite: ") << e.what();
return false;
@@ -571,6 +579,17 @@ bool simple_wallet::set_confirm_missing_payment_id(const std::vector<std::string
return true;
}
+bool simple_wallet::set_ask_password(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
+{
+ const auto pwd_container = get_and_verify_password();
+ if (pwd_container)
+ {
+ m_wallet->ask_password(is_it_true(args[1]));
+ m_wallet->rewrite(m_wallet_file, pwd_container->password());
+ }
+ return true;
+}
+
bool simple_wallet::help(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
success_msg_writer() << get_commands_str();
@@ -643,6 +662,7 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
success_msg_writer() << "refresh-type = " << get_refresh_type_name(m_wallet->get_refresh_type());
success_msg_writer() << "priority = " << m_wallet->get_default_priority();
success_msg_writer() << "confirm-missing-payment-id = " << m_wallet->confirm_missing_payment_id();
+ success_msg_writer() << "ask-password = " << m_wallet->ask_password();
return true;
}
else
@@ -765,6 +785,19 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
return true;
}
}
+ else if (args[0] == "ask-password")
+ {
+ if (args.size() <= 1)
+ {
+ fail_msg_writer() << tr("set ask-password: needs an argument (0 or 1)");
+ return true;
+ }
+ else
+ {
+ set_ask_password(args);
+ return true;
+ }
+ }
}
fail_msg_writer() << tr("set: unrecognized argument(s)");
return true;
@@ -890,10 +923,6 @@ void simple_wallet::print_seed(std::string seed)
std::cout << seed << std::endl;
}
//----------------------------------------------------------------------------------------------------
-static bool is_local_daemon(const std::string &address)
-{
-}
-//----------------------------------------------------------------------------------------------------
bool simple_wallet::init(const boost::program_options::variables_map& vm)
{
if (!handle_command_line(vm))
@@ -2054,6 +2083,7 @@ bool simple_wallet::print_ring_members(const std::vector<tools::wallet2::pending
//----------------------------------------------------------------------------------------------------
bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::string> &args_)
{
+ if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
if (!try_connect_to_daemon())
return true;
@@ -2412,6 +2442,7 @@ bool simple_wallet::locked_transfer(const std::vector<std::string> &args_)
bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
{
+ if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
if (!try_connect_to_daemon())
return true;
@@ -2574,6 +2605,7 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::sweep_all(const std::vector<std::string> &args_)
{
+ if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
if (!try_connect_to_daemon())
return true;
@@ -2835,6 +2867,7 @@ bool simple_wallet::sweep_all(const std::vector<std::string> &args_)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::donate(const std::vector<std::string> &args_)
{
+ if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
std::vector<std::string> local_args = args_;
if(local_args.empty() || local_args.size() > 3)
{
@@ -2975,6 +3008,7 @@ bool simple_wallet::sign_transfer(const std::vector<std::string> &args_)
fail_msg_writer() << tr("This is a watch only wallet");
return true;
}
+ if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
std::vector<tools::wallet2::pending_tx> ptx;
try
@@ -3123,6 +3157,7 @@ bool simple_wallet::get_tx_key(const std::vector<std::string> &args_)
fail_msg_writer() << tr("usage: get_tx_key <txid>");
return true;
}
+ if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
cryptonote::blobdata txid_data;
if(!epee::string_tools::parse_hexstr_to_binbuff(local_args.front(), txid_data))
@@ -3891,6 +3926,7 @@ bool simple_wallet::sign(const std::vector<std::string> &args)
fail_msg_writer() << tr("wallet is watch-only and cannot sign");
return true;
}
+ if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
std::string filename = args[0];
std::string data;
bool r = epee::file_io_utils::load_file_to_string(filename, data);
@@ -3956,6 +3992,7 @@ bool simple_wallet::export_key_images(const std::vector<std::string> &args)
fail_msg_writer() << tr("wallet is watch-only and cannot export key images");
return true;
}
+ if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
std::string filename = args[0];
try
@@ -4014,6 +4051,7 @@ bool simple_wallet::export_outputs(const std::vector<std::string> &args)
fail_msg_writer() << tr("usage: export_outputs <filename>");
return true;
}
+ if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
std::string filename = args[0];
try
@@ -4302,7 +4340,6 @@ int main(int argc, char* argv[])
const bool r = w.init(*vm);
CHECK_AND_ASSERT_MES(r, 1, sw::tr("Failed to initialize wallet"));
-try{ throw 1; } catch(...){}
std::vector<std::string> command = command_line::get_arg(*vm, arg_command);
if (!command.empty())
{
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index 9918300df..ce0a24be7 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -115,6 +115,7 @@ namespace cryptonote
bool set_auto_refresh(const std::vector<std::string> &args = std::vector<std::string>());
bool set_refresh_type(const std::vector<std::string> &args = std::vector<std::string>());
bool set_confirm_missing_payment_id(const std::vector<std::string> &args = std::vector<std::string>());
+ bool set_ask_password(const std::vector<std::string> &args = std::vector<std::string>());
bool help(const std::vector<std::string> &args = std::vector<std::string>());
bool start_mining(const std::vector<std::string> &args);
bool stop_mining(const std::vector<std::string> &args);
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 9e40d2e02..830f98909 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -85,11 +85,14 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
virtual void on_new_block(uint64_t height, const cryptonote::block& block)
{
- //LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height);
-
- if (m_listener) {
- m_listener->newBlock(height);
- // m_listener->updated();
+ // Don't flood the GUI with signals. On fast refresh - send signal every 1000th block
+ // get_refresh_from_block_height() returns the blockheight from when the wallet was
+ // created or the restore height specified when wallet was recovered
+ if(height >= m_wallet->m_wallet->get_refresh_from_block_height() || height % 1000 == 0) {
+ // LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height);
+ if (m_listener) {
+ m_listener->newBlock(height);
+ }
}
}
@@ -515,7 +518,6 @@ bool WalletImpl::recover(const std::string &path, const std::string &seed)
try {
m_wallet->set_seed_language(old_language);
m_wallet->generate(path, "", recovery_key, true, false);
- // TODO: wallet->init(daemon_address);
} catch (const std::exception &e) {
m_status = Status_Critical;
@@ -535,7 +537,7 @@ bool WalletImpl::close()
if (status() != Status_Critical)
m_wallet->store();
else
- LOG_PRINT_L3("Status_Critical - not storing wallet");
+ LOG_ERROR("Status_Critical - not storing wallet");
LOG_PRINT_L1("wallet::store done");
LOG_PRINT_L1("Calling wallet::stop...");
m_wallet->stop();
@@ -646,19 +648,7 @@ string WalletImpl::keysFilename() const
bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit)
{
clearStatus();
- if (!doInit(daemon_address, upper_transaction_size_limit))
- return false;
- bool result = this->refresh();
- // enabling background refresh thread
- startRefresh();
- return result;
-}
-
-void WalletImpl::initAsync(const string &daemon_address, uint64_t upper_transaction_size_limit)
-{
- clearStatus();
- doInit(daemon_address, upper_transaction_size_limit);
- startRefresh();
+ return doInit(daemon_address, upper_transaction_size_limit);
}
void WalletImpl::setRefreshFromBlockHeight(uint64_t refresh_from_block_height)
@@ -1323,8 +1313,8 @@ void WalletImpl::doRefresh()
void WalletImpl::startRefresh()
{
- LOG_PRINT_L2(__FUNCTION__ << ": refresh started/resumed...");
if (!m_refreshEnabled) {
+ LOG_PRINT_L2(__FUNCTION__ << ": refresh started/resumed...");
m_refreshEnabled = true;
m_refreshCV.notify_one();
}
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index 7daf63e43..3994afaa3 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -78,8 +78,7 @@ public:
bool store(const std::string &path);
std::string filename() const;
std::string keysFilename() const;
- bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit);
- void initAsync(const std::string &daemon_address, uint64_t upper_transaction_size_limit);
+ bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0);
bool connectToDaemon();
ConnectionStatus connected() const;
void setTrustedDaemon(bool arg);
@@ -135,7 +134,6 @@ private:
bool isNewWallet() const;
bool doInit(const std::string &daemon_address, uint64_t upper_transaction_size_limit);
-
private:
friend class PendingTransactionImpl;
friend class UnsignedTransactionImpl;
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 148fb9d52..c52281a2b 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -487,6 +487,8 @@ std::pair<std::unique_ptr<wallet2>, password_container> wallet2::make_new(const
//----------------------------------------------------------------------------------------------------
bool wallet2::init(std::string daemon_address, uint64_t upper_transaction_size_limit)
{
+ if(m_http_client.is_connected())
+ m_http_client.disconnect();
m_upper_transaction_size_limit = upper_transaction_size_limit;
m_daemon_address = std::move(daemon_address);
return m_http_client.set_server(get_daemon_address());
@@ -1860,6 +1862,9 @@ bool wallet2::store_keys(const std::string& keys_file_name, const std::string& p
value2.SetInt(m_confirm_missing_payment_id ? 1 :0);
json.AddMember("confirm_missing_payment_id", value2, json.GetAllocator());
+ value2.SetInt(m_ask_password ? 1 :0);
+ json.AddMember("ask_password", value2, json.GetAllocator());
+
// Serialize the JSON object
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
@@ -1927,6 +1932,7 @@ bool wallet2::load_keys(const std::string& keys_file_name, const std::string& pa
m_auto_refresh = true;
m_refresh_type = RefreshType::RefreshDefault;
m_confirm_missing_payment_id = true;
+ m_ask_password = true;
}
else
{
@@ -1987,6 +1993,8 @@ bool wallet2::load_keys(const std::string& keys_file_name, const std::string& pa
m_refresh_from_block_height = field_refresh_height;
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, confirm_missing_payment_id, int, Int, false, true);
m_confirm_missing_payment_id = field_confirm_missing_payment_id;
+ GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, ask_password, int, Int, false, true);
+ m_ask_password = field_ask_password;
}
const cryptonote::account_keys& keys = m_account.get_keys();
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 91d4db47e..567292d30 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -104,7 +104,7 @@ namespace tools
};
private:
- wallet2(const wallet2&) : m_run(true), m_callback(0), m_testnet(false), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true), m_node_rpc_proxy(m_http_client, m_daemon_rpc_mutex) {}
+ wallet2(const wallet2&) : m_run(true), m_callback(0), m_testnet(false), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true), m_ask_password(true), m_node_rpc_proxy(m_http_client, m_daemon_rpc_mutex) {}
public:
static const char* tr(const char* str);
@@ -125,7 +125,7 @@ namespace tools
//! Uses stdin and stdout. Returns a wallet2 and password for wallet with no file if no errors.
static std::pair<std::unique_ptr<wallet2>, password_container> make_new(const boost::program_options::variables_map& vm);
- wallet2(bool testnet = false, bool restricted = false) : m_run(true), m_callback(0), m_testnet(testnet), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true), m_restricted(restricted), is_old_file_format(false), m_node_rpc_proxy(m_http_client, m_daemon_rpc_mutex) {}
+ wallet2(bool testnet = false, bool restricted = false) : m_run(true), m_callback(0), m_testnet(testnet), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true), m_ask_password(true), m_restricted(restricted), is_old_file_format(false), m_node_rpc_proxy(m_http_client, m_daemon_rpc_mutex) {}
struct transfer_details
{
uint64_t m_block_height;
@@ -506,6 +506,8 @@ namespace tools
void auto_refresh(bool r) { m_auto_refresh = r; }
bool confirm_missing_payment_id() const { return m_confirm_missing_payment_id; }
void confirm_missing_payment_id(bool always) { m_confirm_missing_payment_id = always; }
+ bool ask_password() const { return m_ask_password; }
+ void ask_password(bool always) { m_ask_password = always; }
bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key) const;
@@ -656,6 +658,7 @@ namespace tools
bool m_auto_refresh;
uint64_t m_refresh_from_block_height;
bool m_confirm_missing_payment_id;
+ bool m_ask_password;
NodeRPCProxy m_node_rpc_proxy;
};
}
diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h
index 563f16eaa..883da7da2 100644
--- a/src/wallet/wallet2_api.h
+++ b/src/wallet/wallet2_api.h
@@ -332,26 +332,16 @@ struct Wallet
*/
virtual std::string keysFilename() const = 0;
/*!
- * \brief init - initializes wallet with daemon connection params. implicitly connects to the daemon
- * and refreshes the wallet. "refreshed" callback will be invoked. if daemon_address is
- * local address, "trusted daemon" will be set to true forcibly
+ * \brief init - initializes wallet with daemon connection params.
+ * if daemon_address is local address, "trusted daemon" will be set to true forcibly
+ * startRefresh() should be called when wallet is initialized.
*
* \param daemon_address - daemon address in "hostname:port" format
* \param upper_transaction_size_limit
- * \return - true if initialized and refreshed successfully
+ * \return - true on success
*/
virtual bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit) = 0;
- /*!
- * \brief init - initalizes wallet asynchronously. logic is the same as "init" but returns immediately.
- * "refreshed" callback will be invoked.
- *
- * \param daemon_address - daemon address in "hostname:port" format
- * \param upper_transaction_size_limit
- * \return - true if initialized and refreshed successfully
- */
- virtual void initAsync(const std::string &daemon_address, uint64_t upper_transaction_size_limit) = 0;
-
/*!
* \brief createWatchOnly - Creates a watch only wallet
* \param path - where to store the wallet
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index dcf8f8e6d..22f5f8bb6 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -1302,6 +1302,104 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_get_address_book(const wallet_rpc::COMMAND_RPC_GET_ADDRESS_BOOK_ENTRY::request& req, wallet_rpc::COMMAND_RPC_GET_ADDRESS_BOOK_ENTRY::response& res, epee::json_rpc::error& er)
+ {
+ const auto ab = m_wallet.get_address_book();
+ if (req.entries.empty())
+ {
+ uint64_t idx = 0;
+ for (const auto &entry: ab)
+ res.entries.push_back(wallet_rpc::COMMAND_RPC_GET_ADDRESS_BOOK_ENTRY::entry{idx++, get_account_address_as_str(m_wallet.testnet(), entry.m_address), epee::string_tools::pod_to_hex(entry.m_payment_id), entry.m_description});
+ }
+ else
+ {
+ for (uint64_t idx: req.entries)
+ {
+ if (idx >= ab.size())
+ {
+ er.code = WALLET_RPC_ERROR_CODE_WRONG_INDEX;
+ er.message = "Index out of range: " + std::to_string(idx);
+ return false;
+ }
+ const auto &entry = ab[idx];
+ res.entries.push_back(wallet_rpc::COMMAND_RPC_GET_ADDRESS_BOOK_ENTRY::entry{idx, get_account_address_as_str(m_wallet.testnet(), entry.m_address), epee::string_tools::pod_to_hex(entry.m_payment_id), entry.m_description});
+ }
+ }
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_add_address_book(const wallet_rpc::COMMAND_RPC_ADD_ADDRESS_BOOK_ENTRY::request& req, wallet_rpc::COMMAND_RPC_ADD_ADDRESS_BOOK_ENTRY::response& res, epee::json_rpc::error& er)
+ {
+ cryptonote::account_public_address address;
+ bool has_payment_id;
+ crypto::hash8 payment_id8;
+ crypto::hash payment_id = cryptonote::null_hash;
+ if(!get_account_integrated_address_from_str(address, has_payment_id, payment_id8, m_wallet.testnet(), req.address))
+ {
+ er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS;
+ er.message = std::string("WALLET_RPC_ERROR_CODE_WRONG_ADDRESS: ") + req.address;
+ return false;
+ }
+ if (has_payment_id)
+ {
+ memcpy(payment_id.data, payment_id8.data, 8);
+ memset(payment_id.data + 8, 0, 24);
+ }
+ if (!req.payment_id.empty())
+ {
+ if (has_payment_id)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
+ er.message = "Separate payment ID given with integrated address";
+ return false;
+ }
+
+ crypto::hash long_payment_id;
+ crypto::hash8 short_payment_id;
+
+ if (!wallet2::parse_long_payment_id(req.payment_id, payment_id))
+ {
+ if (!wallet2::parse_short_payment_id(req.payment_id, payment_id8))
+ {
+ er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
+ er.message = "Payment id has invalid format: \"" + req.payment_id + "\", expected 16 or 64 character string";
+ return false;
+ }
+ else
+ {
+ memcpy(payment_id.data, payment_id8.data, 8);
+ memset(payment_id.data + 8, 0, 24);
+ }
+ }
+ }
+ if (!m_wallet.add_address_book_row(address, payment_id, req.description))
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "Failed to add address book entry";
+ return false;
+ }
+ res.index = m_wallet.get_address_book().size();
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_delete_address_book(const wallet_rpc::COMMAND_RPC_DELETE_ADDRESS_BOOK_ENTRY::request& req, wallet_rpc::COMMAND_RPC_DELETE_ADDRESS_BOOK_ENTRY::response& res, epee::json_rpc::error& er)
+ {
+ const auto ab = m_wallet.get_address_book();
+ if (req.index >= ab.size())
+ {
+ er.code = WALLET_RPC_ERROR_CODE_WRONG_INDEX;
+ er.message = "Index out of range: " + std::to_string(req.index);
+ return false;
+ }
+ if (!m_wallet.delete_address_book_row(req.index))
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "Failed to delete address book entry";
+ return false;
+ }
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
}
int main(int argc, char** argv) {
diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h
index 7d5db1bcb..98e6e72ed 100644
--- a/src/wallet/wallet_rpc_server.h
+++ b/src/wallet/wallet_rpc_server.h
@@ -89,6 +89,9 @@ namespace tools
MAP_JON_RPC_WE("import_key_images", on_import_key_images, wallet_rpc::COMMAND_RPC_IMPORT_KEY_IMAGES)
MAP_JON_RPC_WE("make_uri", on_make_uri, wallet_rpc::COMMAND_RPC_MAKE_URI)
MAP_JON_RPC_WE("parse_uri", on_parse_uri, wallet_rpc::COMMAND_RPC_PARSE_URI)
+ MAP_JON_RPC_WE("get_address_book", on_get_address_book, wallet_rpc::COMMAND_RPC_GET_ADDRESS_BOOK_ENTRY)
+ MAP_JON_RPC_WE("add_address_book", on_add_address_book, wallet_rpc::COMMAND_RPC_ADD_ADDRESS_BOOK_ENTRY)
+ MAP_JON_RPC_WE("delete_address_book",on_delete_address_book,wallet_rpc::COMMAND_RPC_DELETE_ADDRESS_BOOK_ENTRY)
END_JSON_RPC_MAP()
END_URI_MAP2()
@@ -119,6 +122,9 @@ namespace tools
bool on_import_key_images(const wallet_rpc::COMMAND_RPC_IMPORT_KEY_IMAGES::request& req, wallet_rpc::COMMAND_RPC_IMPORT_KEY_IMAGES::response& res, epee::json_rpc::error& er);
bool on_make_uri(const wallet_rpc::COMMAND_RPC_MAKE_URI::request& req, wallet_rpc::COMMAND_RPC_MAKE_URI::response& res, epee::json_rpc::error& er);
bool on_parse_uri(const wallet_rpc::COMMAND_RPC_PARSE_URI::request& req, wallet_rpc::COMMAND_RPC_PARSE_URI::response& res, epee::json_rpc::error& er);
+ bool on_get_address_book(const wallet_rpc::COMMAND_RPC_GET_ADDRESS_BOOK_ENTRY::request& req, wallet_rpc::COMMAND_RPC_GET_ADDRESS_BOOK_ENTRY::response& res, epee::json_rpc::error& er);
+ bool on_add_address_book(const wallet_rpc::COMMAND_RPC_ADD_ADDRESS_BOOK_ENTRY::request& req, wallet_rpc::COMMAND_RPC_ADD_ADDRESS_BOOK_ENTRY::response& res, epee::json_rpc::error& er);
+ bool on_delete_address_book(const wallet_rpc::COMMAND_RPC_DELETE_ADDRESS_BOOK_ENTRY::request& req, wallet_rpc::COMMAND_RPC_DELETE_ADDRESS_BOOK_ENTRY::response& res, epee::json_rpc::error& er);
//json rpc v2
bool on_query_key(const wallet_rpc::COMMAND_RPC_QUERY_KEY::request& req, wallet_rpc::COMMAND_RPC_QUERY_KEY::response& res, epee::json_rpc::error& er);
diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h
index 4d643637f..e132b4e2b 100644
--- a/src/wallet/wallet_rpc_server_commands_defs.h
+++ b/src/wallet/wallet_rpc_server_commands_defs.h
@@ -786,5 +786,84 @@ namespace wallet_rpc
};
};
+ struct COMMAND_RPC_ADD_ADDRESS_BOOK_ENTRY
+ {
+ struct request
+ {
+ std::string address;
+ std::string payment_id;
+ std::string description;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(address)
+ KV_SERIALIZE(payment_id)
+ KV_SERIALIZE(description)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ uint64_t index;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(index);
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+
+ struct COMMAND_RPC_GET_ADDRESS_BOOK_ENTRY
+ {
+ struct request
+ {
+ std::list<uint64_t> entries;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(entries)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct entry
+ {
+ uint64_t index;
+ std::string address;
+ std::string payment_id;
+ std::string description;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(index)
+ KV_SERIALIZE(address)
+ KV_SERIALIZE(payment_id)
+ KV_SERIALIZE(description)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::vector<entry> entries;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(entries)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+
+ struct COMMAND_RPC_DELETE_ADDRESS_BOOK_ENTRY
+ {
+ struct request
+ {
+ uint64_t index;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(index);
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ BEGIN_KV_SERIALIZE_MAP()
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+
}
}
diff --git a/src/wallet/wallet_rpc_server_error_codes.h b/src/wallet/wallet_rpc_server_error_codes.h
index 38fbffcc2..7b541c8f6 100644
--- a/src/wallet/wallet_rpc_server_error_codes.h
+++ b/src/wallet/wallet_rpc_server_error_codes.h
@@ -42,3 +42,4 @@
#define WALLET_RPC_ERROR_CODE_WRONG_SIGNATURE -9
#define WALLET_RPC_ERROR_CODE_WRONG_KEY_IMAGE -10
#define WALLET_RPC_ERROR_CODE_WRONG_URI -11
+#define WALLET_RPC_ERROR_CODE_WRONG_INDEX -12