1
0
Fork 0
forked from lthn/blockchain

Merge branch 'develop' into libmdbx

This commit is contained in:
cryptozoidberg 2019-10-23 15:01:30 +02:00
commit f75be80a3f
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
103 changed files with 3125 additions and 1513 deletions

View file

@ -45,6 +45,7 @@
#include <boost/cstdint.hpp>
#include <boost/thread.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/algorithm/string.hpp>
#endif
#if defined(WIN32)

View file

@ -133,12 +133,12 @@ class connection
volatile uint32_t& m_ref_sockets_count;
i_connection_filter*& m_pfilter;
volatile bool m_is_multithreaded;
//this should be the last one, because it could be wait on destructor, while other activities possible on other threads
t_protocol_handler m_protocol_handler;
//typename t_protocol_handler::config_type m_dummy_config;
std::list<boost::shared_ptr<connection<t_protocol_handler>>> m_self_refs; // add_ref/release support
critical_section m_self_refs_lock;
t_protocol_handler m_protocol_handler;
//this should be the last line with m_protocol_handler, because it could be wait on destructor, while other activities possible on other threads
//DON'T ADD ANYTHING HERE!!!
};
/************************************************************************/

View file

@ -220,6 +220,11 @@ public:
bool add_invoke_response_handler(const callback_t& cb, uint64_t timeout, async_protocol_handler& con, int command)
{
CRITICAL_REGION_LOCAL(m_invoke_response_handlers_lock);
if (m_protocol_released)
{
LOG_PRINT_L0("ERROR: Adding response handler to a released object");
return false;
}
boost::shared_ptr<invoke_response_handler_base> handler(boost::make_shared<invoke_handler<callback_t>>(cb, timeout, con, command));
m_invoke_response_handlers.push_back(handler);
LOG_PRINT_L4("[LEVIN_PROTOCOL" << this << "] INVOKE_HANDLER_QUE: PUSH_BACK RESPONSE HANDLER");

View file

@ -29,4 +29,5 @@ namespace command_line
const arg_descriptor<bool> arg_disable_stop_if_time_out_of_sync = { "disable-stop-if-time-out-of-sync", "Do not stop the daemon if serious time synchronization problem is detected", false, true };
const arg_descriptor<bool> arg_disable_stop_on_low_free_space = { "disable-stop-on-low-free-space", "Do not stop the daemon if free space at data dir is critically low", false, true };
const arg_descriptor<bool> arg_enable_offers_service = { "enable-offers-service", "Enables marketplace feature", false, false};
}

View file

@ -187,4 +187,5 @@ namespace command_line
extern const arg_descriptor<bool> arg_disable_upnp;
extern const arg_descriptor<bool> arg_disable_stop_if_time_out_of_sync;
extern const arg_descriptor<bool> arg_disable_stop_on_low_free_space;
extern const arg_descriptor<bool> arg_enable_offers_service;
}

View file

@ -658,4 +658,41 @@ std::string get_nix_version_display_string()
return static_cast<uint64_t>(in.tellg());
}
bool check_remote_client_version(const std::string& client_ver)
{
std::string v = client_ver.substr(0, client_ver.find('[')); // remove commit id
v = v.substr(0, v.rfind('.')); // remove build number
int v_major = 0, v_minor = 0, v_revision = 0;
size_t dot_pos = v.find('.');
if (dot_pos == std::string::npos || !epee::string_tools::string_to_num_fast(v.substr(0, dot_pos), v_major))
return false;
v = v.substr(dot_pos + 1);
dot_pos = v.find('.');
if (!epee::string_tools::string_to_num_fast(v.substr(0, dot_pos), v_minor))
return false;
if (dot_pos != std::string::npos)
{
// revision
v = v.substr(dot_pos + 1);
if (!epee::string_tools::string_to_num_fast(v, v_revision))
return false;
}
// got v_major, v_minor, v_revision
// allow 1.1.x and greater
if (v_major < 1)
return false;
if (v_major == 1 && v_minor < 1)
return false;
return true;
}
} // namespace tools

View file

@ -30,6 +30,8 @@ namespace tools
std::string get_default_user_dir();
std::string get_current_username();
std::string get_os_version_string();
bool check_remote_client_version(const std::string& client_ver);
bool create_directories_if_necessary(const std::string& path);
std::error_code replace_file(const std::string& replacement_name, const std::string& replaced_name);

View file

@ -362,13 +362,16 @@ bool blockchain_storage::init(const std::string& config_folder, const boost::pro
//------------------------------------------------------------------
bool blockchain_storage::set_lost_tx_unmixable_for_height(uint64_t height)
{
#ifndef TESTNET
if (height == 75738)
return set_lost_tx_unmixable();
#endif
return true;
}
//------------------------------------------------------------------
bool blockchain_storage::set_lost_tx_unmixable()
{
#ifndef TESTNET
if (m_db_blocks.size() > 75738)
{
crypto::hash tx_id_1 = epee::string_tools::parse_tpod_from_hex_string<crypto::hash>("c2a2229d614e7c026433efbcfdbd0be1f68d9b419220336df3e2c209f5d57314");
@ -392,11 +395,13 @@ bool blockchain_storage::set_lost_tx_unmixable()
}
m_db_transactions.set(tx_id_2, tx2_local_entry);
}
#endif
return true;
}
//------------------------------------------------------------------
void blockchain_storage::patch_out_if_needed(txout_to_key& out, const crypto::hash& tx_id, uint64_t n) const
{
#ifndef TESTNET
static crypto::hash tx_id_1 = epee::string_tools::parse_tpod_from_hex_string<crypto::hash>("c2a2229d614e7c026433efbcfdbd0be1f68d9b419220336df3e2c209f5d57314");
static crypto::hash tx_id_2 = epee::string_tools::parse_tpod_from_hex_string<crypto::hash>("647f936c6ffbd136f5c95d9a90ad554bdb4c01541c6eb5755ad40b984d80da67");
@ -407,6 +412,7 @@ void blockchain_storage::patch_out_if_needed(txout_to_key& out, const crypto::h
{
out.mix_attr = CURRENCY_TO_KEY_OUT_FORCED_NO_MIX;
}
#endif
}
//------------------------------------------------------------------
void blockchain_storage::store_db_solo_options_values()

View file

@ -1550,8 +1550,8 @@ namespace currency
bool check_tx_derivation_hint(const transaction& tx, const crypto::key_derivation& derivation)
{
bool found_der_xor = false;
uint16_t my_derive_xor = get_derivation_hint(derivation);
tx_derivation_hint dh = make_tx_derivation_hint_from_uint16(my_derive_xor);
uint16_t hint = get_derivation_hint(derivation);
tx_derivation_hint dh = make_tx_derivation_hint_from_uint16(hint);
for (auto& e : tx.extra)
{
if (e.type() == typeid(tx_derivation_hint))
@ -1737,7 +1737,13 @@ namespace currency
}
return true;
}
//------------------------------------------------------------------
bool validate_password(const std::string& password)
{
static const std::string allowed_password_symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~!?@#$%^&*_+|{}[]()<>:;\"'-=\\/.,";
size_t n = password.find_first_not_of(allowed_password_symbols, 0);
return n == std::string::npos;
}
//------------------------------------------------------------------
#define ANTI_OVERFLOW_AMOUNT 1000000

View file

@ -21,7 +21,6 @@
#include "crypto/crypto.h"
#include "crypto/hash.h"
#include "difficulty.h"
//#include "offers_services_helpers.h"
#include "rpc/core_rpc_server_commands_defs.h"
#include "bc_payments_id_service.h"
#include "bc_attachments_helpers_basic.h"
@ -29,6 +28,7 @@
#include "currency_format_utils_blocks.h"
#include "currency_format_utils_transactions.h"
// ------ get_tx_type_definition -------------
#define GUI_TX_TYPE_NORMAL 0
#define GUI_TX_TYPE_PUSH_OFFER 1
@ -163,6 +163,7 @@ namespace currency
uint64_t get_string_uint64_hash(const std::string& str);
bool construct_tx_out(const tx_destination_entry& de, const crypto::secret_key& tx_sec_key, size_t output_index, transaction& tx, std::set<uint16_t>& deriv_cache, uint8_t tx_outs_attr = CURRENCY_TO_KEY_OUT_RELAXED);
bool validate_alias_name(const std::string& al);
bool validate_password(const std::string& password);
void get_attachment_extra_info_details(const std::vector<attachment_v>& attachment, extra_attachment_info& eai);
bool construct_tx(const account_keys& sender_account_keys,
const std::vector<tx_source_entry>& sources,

View file

@ -19,7 +19,7 @@ namespace bc_services
{
//fields filled in UI
uint8_t offer_type; // OFFER_TYPE_PRIMARY_TO_TARGET - 0, OFFER_TYPE_TARGET_TO_PRIMARY - 1 etc.
uint8_t offer_type; // OFFER_TYPE_PRIMARY_TO_TARGET(SELL ORDER) - 0, OFFER_TYPE_TARGET_TO_PRIMARY(BUY ORDER) - 1 etc.
uint64_t amount_primary; // amount of the currency
uint64_t amount_target; // amount of other currency or goods
std::string bonus; //
@ -125,4 +125,69 @@ namespace bc_services
typedef boost::variant<offer_details, update_offer, cancel_offer> offers_attachment_t;
inline std::string transform_double_to_string(const double& a)
{
return std::to_string(a);
}
inline double transform_string_to_double(const std::string& d)
{
double n = 0;
epee::string_tools::get_xtype_from_string(n, d);
return n;
}
struct core_offers_filter
{
uint64_t order_by;
bool reverse;
uint64_t offset;
uint64_t limit;
//filter entry
uint64_t timestamp_start;
uint64_t timestamp_stop;
uint64_t offer_type_mask;
uint64_t amount_low_limit;
uint64_t amount_up_limit;
double rate_low_limit;
double rate_up_limit;
std::list<std::string> payment_types;
std::string location_country;
std::string location_city;
std::string target;
std::string primary;
bool bonus;
std::string category;
std::string keyword;
bool fake;
uint64_t current_time;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(order_by)
KV_SERIALIZE(reverse)
KV_SERIALIZE(offset)
KV_SERIALIZE(limit)
KV_SERIALIZE(timestamp_start)
KV_SERIALIZE(timestamp_stop)
KV_SERIALIZE(offer_type_mask)
KV_SERIALIZE(amount_low_limit)
KV_SERIALIZE(amount_up_limit)
KV_SERIALIZE_CUSTOM(rate_low_limit, std::string, bc_services::transform_double_to_string, bc_services::transform_string_to_double)
KV_SERIALIZE_CUSTOM(rate_up_limit, std::string, bc_services::transform_double_to_string, bc_services::transform_string_to_double)
KV_SERIALIZE(payment_types)
KV_SERIALIZE(location_country)
KV_SERIALIZE(location_city)
KV_SERIALIZE(target)
KV_SERIALIZE(primary)
KV_SERIALIZE(bonus)
KV_SERIALIZE(category)
KV_SERIALIZE(keyword)
KV_SERIALIZE(fake)
END_KV_SERIALIZE_MAP()
};
}

View file

@ -17,17 +17,7 @@
namespace bc_services
{
std::string transform_double_to_string(const double& a)
{
return std::to_string(a);
}
double transform_string_to_double(const std::string& d)
{
double n = 0;
epee::string_tools::get_xtype_from_string(n, d);
return n;
}
bool order_offers_by_timestamp(const offer_details_ex* a, const offer_details_ex* b)
{

View file

@ -18,60 +18,6 @@
namespace bc_services
{
std::string transform_double_to_string(const double& a);
double transform_string_to_double(const std::string& d);
struct core_offers_filter
{
uint64_t order_by;
bool reverse;
uint64_t offset;
uint64_t limit;
//filter entry
uint64_t timestamp_start;
uint64_t timestamp_stop;
uint64_t offer_type_mask;
uint64_t amount_low_limit;
uint64_t amount_up_limit;
double rate_low_limit;
double rate_up_limit;
std::list<std::string> payment_types;
std::string location_country;
std::string location_city;
std::string target;
std::string primary;
bool bonus;
std::string category;
std::string keyword;
bool fake;
uint64_t current_time;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(order_by)
KV_SERIALIZE(reverse)
KV_SERIALIZE(offset)
KV_SERIALIZE(limit)
KV_SERIALIZE(timestamp_start)
KV_SERIALIZE(timestamp_stop)
KV_SERIALIZE(offer_type_mask)
KV_SERIALIZE(amount_low_limit)
KV_SERIALIZE(amount_up_limit)
KV_SERIALIZE_CUSTOM(rate_low_limit, std::string, bc_services::transform_double_to_string, bc_services::transform_string_to_double)
KV_SERIALIZE_CUSTOM(rate_up_limit, std::string, bc_services::transform_double_to_string, bc_services::transform_string_to_double)
KV_SERIALIZE(payment_types)
KV_SERIALIZE(location_country)
KV_SERIALIZE(location_city)
KV_SERIALIZE(target)
KV_SERIALIZE(primary)
KV_SERIALIZE(bonus)
KV_SERIALIZE(category)
KV_SERIALIZE(keyword)
KV_SERIALIZE(fake)
END_KV_SERIALIZE_MAP()
};
struct offer_id
{

View file

@ -174,7 +174,8 @@ namespace currency
"That means that current software is outdated, please updated it." <<
"Current heigh lay under checkpoints on remote host, so it is not possible validate this transactions on local host, disconnecting.", LOG_LEVEL_0);
return false;
}else if (m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() < hshd.last_checkpoint_height)
}
else if (m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() < hshd.last_checkpoint_height)
{
LOG_PRINT_MAGENTA("Remote node have longer checkpoints zone( " << hshd.last_checkpoint_height << ") " <<
"that local (" << m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() << ")" <<
@ -788,7 +789,7 @@ namespace currency
std::vector<int64_t> time_deltas_copy(m_time_deltas.begin(), m_time_deltas.end());
m_last_median2local_time_difference = epee::misc_utils::median(time_deltas_copy);
LOG_PRINT_MAGENTA("TIME: network time difference is " << m_last_median2local_time_difference << " (max is " << TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE << ")", LOG_LEVEL_2);
LOG_PRINT_MAGENTA("TIME: network time difference is " << m_last_median2local_time_difference << " (max is " << TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE << ")", m_last_median2local_time_difference >= 3 ? LOG_LEVEL_2 : LOG_LEVEL_3);
if (std::abs(m_last_median2local_time_difference) > TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE)
{
int64_t ntp_time = tools::get_ntp_time();

View file

@ -75,10 +75,16 @@ struct core_critical_error_handler_t : public currency::i_critical_error_handler
LOG_ERROR(ENDL << ENDL << "Free space at data directory is critically low (" << available / (1024 * 1024) << " MB, while " << required / (1024 * 1024) << " MB is required), daemon will stop immediately" << ENDL << ENDL);
/*
temporary disable daemon stop due to issue #133
*/
return false;
/*
// stop handling
dch.stop_handling();
p2psrv.send_stop_signal();
return true; // the caller must stop processing
*/
}
daemon_commands_handler& dch;
@ -106,7 +112,7 @@ int main(int argc, char* argv[])
//_CrtSetAllocHook(alloc_hook);
#endif
log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2);
log_space::get_set_log_detalisation_level(true, LOG_LEVEL_0);
log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL);
log_space::log_singletone::enable_channels("core,currency_protocol,tx_pool,wallet");
LOG_PRINT_L0("Starting...");
@ -140,6 +146,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_cmd_sett, command_line::arg_show_rpc_autodoc);
command_line::add_arg(desc_cmd_sett, command_line::arg_disable_stop_if_time_out_of_sync);
command_line::add_arg(desc_cmd_sett, command_line::arg_disable_stop_on_low_free_space);
command_line::add_arg(desc_cmd_sett, command_line::arg_enable_offers_service);
arg_market_disable.default_value = true;
@ -219,7 +226,7 @@ int main(int argc, char* argv[])
//create objects and link them
bc_services::bc_offers_service offers_service(nullptr);
offers_service.set_disabled(true);
offers_service.set_disabled(true); //disable by default
currency::core ccore(NULL);
currency::t_currency_protocol_handler<currency::core> cprotocol(ccore, NULL );
p2psrv_t p2psrv(cprotocol);
@ -233,8 +240,16 @@ int main(int argc, char* argv[])
command_line::get_arg(vm, command_line::arg_disable_stop_on_low_free_space));
ccore.set_critical_error_handler(&cceh);
//ccore.get_blockchain_storage().get_attachment_services_manager().add_service(&offers_service);
std::shared_ptr<currency::stratum_server> stratum_server_ptr;
if (command_line::get_arg(vm, command_line::arg_enable_offers_service))
{
offers_service.set_disabled(false);
ccore.get_blockchain_storage().get_attachment_services_manager().add_service(&offers_service);
}
std::shared_ptr<currency::stratum_server> stratum_server_ptr;
if (stratum_enabled)
stratum_server_ptr = std::make_shared<currency::stratum_server>(&ccore);
@ -263,9 +278,10 @@ int main(int argc, char* argv[])
CHECK_AND_ASSERT_MES(res, 1, "Failed to initialize p2p server.");
LOG_PRINT_L0("P2p server initialized OK on port: " << p2psrv.get_this_peer_port());
tools::miniupnp_helper upnp_helper;
if (!command_line::get_arg(vm, command_line::arg_disable_upnp))
{
tools::miniupnp_helper upnp_helper;
LOG_PRINT_L0("Starting UPnP");
upnp_helper.start_regular_mapping(p2psrv.get_this_peer_port(), p2psrv.get_this_peer_port(), 20*60*1000);
}

View file

@ -40,7 +40,8 @@ daemon_backend::daemon_backend():m_pview(&m_view_stub),
m_offers_service(nullptr),
m_ui_opt(AUTO_VAL_INIT(m_ui_opt)),
m_remote_node_mode(false),
m_is_pos_allowed(false)
m_is_pos_allowed(false),
m_qt_logs_enbaled(false)
{
m_offers_service.set_disabled(true);
//m_ccore.get_blockchain_storage().get_attachment_services_manager().add_service(&m_offers_service);
@ -52,6 +53,7 @@ const command_line::arg_descriptor<std::string> arg_xcode_stub = {"-NSDocumentRe
const command_line::arg_descriptor<bool> arg_enable_gui_debug_mode = { "gui-debug-mode", "Enable debug options in GUI", false, true };
const command_line::arg_descriptor<uint32_t> arg_qt_remote_debugging_port = { "remote-debugging-port", "Specify port for Qt remote debugging", 30333, true };
const command_line::arg_descriptor<std::string> arg_remote_node = { "remote-node", "Switch GUI to work with remote node instead of local daemon", "", true };
const command_line::arg_descriptor<bool> arg_enable_qt_logs = { "enable-qt-logs", "Forward Qt log messages into main log", false, true };
void wallet_lock_time_watching_policy::watch_lock_time(uint64_t lock_time)
{
@ -124,9 +126,7 @@ bool daemon_backend::init(int argc, char* argv[], view::i_view* pview_handler)
command_line::add_arg(desc_cmd_sett, arg_enable_gui_debug_mode);
command_line::add_arg(desc_cmd_sett, arg_qt_remote_debugging_port);
command_line::add_arg(desc_cmd_sett, arg_remote_node);
command_line::add_arg(desc_cmd_sett, arg_enable_qt_logs);
currency::core::init_options(desc_cmd_sett);
@ -220,6 +220,8 @@ bool daemon_backend::init(int argc, char* argv[], view::i_view* pview_handler)
// configure for remote node
}
m_qt_logs_enbaled = command_line::get_arg(m_vm, arg_enable_qt_logs);
m_pview->init(path_to_html);
if (!coomand_line_parsed)
@ -1129,7 +1131,7 @@ std::string daemon_backend::get_wallet_info(size_t wallet_id, view::wallet_info&
GET_WALLET_OPT_BY_ID(wallet_id, w);
return get_wallet_info(w, wi);
}
std::string daemon_backend::get_contracts(size_t wallet_id, std::vector<tools::wallet_rpc::escrow_contract_details>& contracts)
std::string daemon_backend::get_contracts(size_t wallet_id, std::vector<tools::wallet_public::escrow_contract_details>& contracts)
{
tools::wallet2::escrow_contracts_container cc;
GET_WALLET_OPT_BY_ID(wallet_id, w);
@ -1146,49 +1148,45 @@ std::string daemon_backend::get_contracts(size_t wallet_id, std::vector<tools::w
size_t i = 0;
for (auto& c: cc)
{
static_cast<tools::wallet_rpc::escrow_contract_details_basic&>(contracts[i]) = c.second;
static_cast<tools::wallet_public::escrow_contract_details_basic&>(contracts[i]) = c.second;
contracts[i].contract_id = c.first;
i++;
}
return API_RETURN_CODE_OK;
}
std::string daemon_backend::create_proposal(size_t wallet_id,
const bc_services::contract_private_details& escrow_details,
const std::string& payment_id,
uint64_t expiration_period,
uint64_t fee,
uint64_t b_fee)
std::string daemon_backend::create_proposal(const view::create_proposal_param_gui& cpp)
{
tools::wallet2::escrow_contracts_container cc;
GET_WALLET_OPT_BY_ID(wallet_id, w);
//tools::wallet2::escrow_contracts_container cc;
GET_WALLET_OPT_BY_ID(cpp.wallet_id, w);
try
{
currency::transaction tx = AUTO_VAL_INIT(tx);
currency::transaction template_tx = AUTO_VAL_INIT(template_tx);
w.w->get()->send_escrow_proposal(escrow_details, 0, 0, expiration_period, fee, b_fee, payment_id, tx, template_tx);
w.w->get()->send_escrow_proposal(cpp, tx, template_tx);
//TODO: add some
return API_RETURN_CODE_OK;
}
catch (const tools::error::not_enough_money& e)
{
LOG_ERROR(get_wallet_log_prefix(wallet_id) + "send_escrow_proposal error: API_RETURN_CODE_NOT_ENOUGH_MONEY: " << e.what());
LOG_ERROR(get_wallet_log_prefix(cpp.wallet_id) + "send_escrow_proposal error: API_RETURN_CODE_NOT_ENOUGH_MONEY: " << e.what());
std::string err_code = API_RETURN_CODE_NOT_ENOUGH_MONEY;
return err_code;
}
catch (const std::exception& e)
{
LOG_ERROR(get_wallet_log_prefix(wallet_id) + "send_escrow_proposal error: " << e.what());
LOG_ERROR(get_wallet_log_prefix(cpp.wallet_id) + "send_escrow_proposal error: " << e.what());
std::string err_code = API_RETURN_CODE_INTERNAL_ERROR;
err_code += std::string(":") + e.what();
return err_code;
}
catch (...)
{
LOG_ERROR(get_wallet_log_prefix(wallet_id) + "send_escrow_proposal error: unknown error");
LOG_ERROR(get_wallet_log_prefix(cpp.wallet_id) + "send_escrow_proposal error: unknown error");
return API_RETURN_CODE_INTERNAL_ERROR;
}
}
std::string daemon_backend::accept_proposal(size_t wallet_id, const crypto::hash& contract_id)
{
GET_WALLET_OPT_BY_ID(wallet_id, w);
@ -1298,7 +1296,7 @@ std::string daemon_backend::start_pos_mining(uint64_t wallet_id)
wo.need_to_update_wallet_info = true;
return API_RETURN_CODE_OK;
}
std::string daemon_backend::get_mining_history(uint64_t wallet_id, tools::wallet_rpc::mining_history& mh)
std::string daemon_backend::get_mining_history(uint64_t wallet_id, tools::wallet_public::mining_history& mh)
{
GET_WALLET_OPT_BY_ID(wallet_id, wo);
@ -1421,10 +1419,10 @@ std::string daemon_backend::push_update_offer(const bc_services::update_offer_de
}
}
// std::string daemon_backend::get_all_offers(currency::COMMAND_RPC_GET_ALL_OFFERS::response& od)
// std::string daemon_backend::get_all_offers(currency::COMMAND_RPC_GET_OFFERS_EX::response& od)
// {
// currency::COMMAND_RPC_GET_ALL_OFFERS::request rq = AUTO_VAL_INIT(rq);
// m_rpc_proxy->call_COMMAND_RPC_GET_ALL_OFFERS(rq, od);
// currency::COMMAND_RPC_GET_OFFERS_EX::request rq = AUTO_VAL_INIT(rq);
// m_rpc_proxy->call_COMMAND_RPC_GET_OFFERS_EX(rq, od);
// return API_RETURN_CODE_OK;
// }
@ -1454,7 +1452,7 @@ void daemon_backend::on_new_block(size_t wallet_id, uint64_t /*height*/, const c
}
void daemon_backend::on_transfer2(size_t wallet_id, const tools::wallet_rpc::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined)
void daemon_backend::on_transfer2(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined)
{
view::transfer_event_info tei = AUTO_VAL_INIT(tei);
tei.ti = wti;
@ -1477,7 +1475,7 @@ void daemon_backend::on_sync_progress(size_t wallet_id, const uint64_t& percents
wspp.wallet_id = wallet_id;
m_pview->wallet_sync_progress(wspp);
}
void daemon_backend::on_transfer_canceled(size_t wallet_id, const tools::wallet_rpc::wallet_transfer_info& wti)
void daemon_backend::on_transfer_canceled(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti)
{
view::transfer_event_info tei = AUTO_VAL_INIT(tei);
tei.ti = wti;
@ -1537,7 +1535,7 @@ void daemon_backend::wallet_vs_options::worker_func()
auto w_ptr = *w; // get locked exclusive access to the wallet first (it's more likely that wallet is locked for a long time than 'offers')
auto offers_list_proxy = *offers; // than get locked exclusive access to offers
offers_list_proxy->clear();
(*w_ptr)->get_actual_offers(*offers_list_proxy, false);
(*w_ptr)->get_actual_offers(*offers_list_proxy);
}
wallet_state = wsi.wallet_state = view::wallet_status_info::wallet_state_ready;

View file

@ -90,23 +90,19 @@ public:
std::string run_wallet(uint64_t wallet_id);
std::string get_recent_transfers(size_t wallet_id, uint64_t offset, uint64_t count, view::transfers_array& tr_hist);
std::string get_wallet_info(size_t wallet_id, view::wallet_info& wi);
std::string get_contracts(size_t wallet_id, std::vector<tools::wallet_rpc::escrow_contract_details>& contracts);
std::string create_proposal(size_t wallet_id, const bc_services::contract_private_details& escrow, const std::string& payment_id,
uint64_t expiration_period,
uint64_t fee,
uint64_t b_fee);
std::string get_contracts(size_t wallet_id, std::vector<tools::wallet_public::escrow_contract_details>& contracts);
std::string create_proposal(const view::create_proposal_param_gui& cpp);
std::string accept_proposal(size_t wallet_id, const crypto::hash& contract_id);
std::string release_contract(size_t wallet_id, const crypto::hash& contract_id, const std::string& contract_over_type);
std::string request_cancel_contract(size_t wallet_id, const crypto::hash& contract_id, uint64_t fee, uint64_t expiration_period);
std::string accept_cancel_contract(size_t wallet_id, const crypto::hash& contract_id);
std::string get_wallet_info(wallet_vs_options& w, view::wallet_info& wi);
std::string close_wallet(size_t wallet_id);
std::string push_offer(size_t wallet_id, const bc_services::offer_details_ex& od, currency::transaction& res_tx);
std::string cancel_offer(const view::cancel_offer_param& co, currency::transaction& res_tx);
std::string push_update_offer(const bc_services::update_offer_details& uo, currency::transaction& res_tx);
//std::string get_all_offers(currency::COMMAND_RPC_GET_ALL_OFFERS::response& od);
//std::string get_all_offers(currency::COMMAND_RPC_GET_OFFERS_EX::response& od);
std::string get_offers_ex(const bc_services::core_offers_filter& cof, std::list<bc_services::offer_details_ex>& offers, uint64_t& total_count);
std::string get_aliases(view::alias_set& al_set);
std::string get_alias_info_by_address(const std::string& addr, currency::alias_rpc_details& res_details);
@ -119,7 +115,7 @@ public:
std::string start_pos_mining(uint64_t wallet_id);
std::string stop_pos_mining(uint64_t wallet_id);
std::string check_available_sources(uint64_t wallet_id, std::list<uint64_t>& amounts);
std::string get_mining_history(uint64_t wallet_id, tools::wallet_rpc::mining_history& wrpc);
std::string get_mining_history(uint64_t wallet_id, tools::wallet_public::mining_history& wrpc);
std::string get_wallet_restore_info(uint64_t wallet_id, std::string& restore_key);
std::string backup_wallet(uint64_t wallet_id, const std::wstring& path);
std::string reset_wallet_password(uint64_t wallet_id, const std::string& pass);
@ -142,6 +138,7 @@ public:
void unsubscribe_to_core_events();
void get_gui_options(view::gui_options& opt);
std::string get_wallet_log_prefix(size_t wallet_id) const;
bool is_qt_logs_enabled() const { return m_qt_logs_enbaled; }
private:
void main_worker(const po::variables_map& vm);
@ -157,10 +154,10 @@ private:
static void prepare_wallet_status_info(wallet_vs_options& wo, view::wallet_status_info& wsi);
//----- i_backend_wallet_callback ------
virtual void on_new_block(size_t wallet_id, uint64_t height, const currency::block& block);
virtual void on_transfer2(size_t wallet_id, const tools::wallet_rpc::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined);
virtual void on_transfer2(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined);
virtual void on_pos_block_found(size_t wallet_id, const currency::block& /*block*/);
virtual void on_sync_progress(size_t wallet_id, const uint64_t& /*percents*/);
virtual void on_transfer_canceled(size_t wallet_id, const tools::wallet_rpc::wallet_transfer_info& wti);
virtual void on_transfer_canceled(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti);
std::thread m_main_worker_thread;
std::atomic<bool> m_stop_singal_sent;
@ -187,6 +184,7 @@ private:
currency::core_rpc_server m_rpc_server;
bool m_remote_node_mode;
bool m_qt_logs_enbaled;
std::atomic<bool> m_is_pos_allowed;

View file

@ -609,10 +609,45 @@ bool MainWindow::show_msg_box(const std::string& message)
return true;
CATCH_ENTRY2(false);
}
void qt_log_message_handler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QByteArray local_msg = msg.toLocal8Bit();
const char* msg_type = "";
switch (type)
{
case QtDebugMsg: msg_type = "DEBG "; break;
case QtInfoMsg: msg_type = "INFO "; break;
case QtWarningMsg: msg_type = "WARN "; break;
case QtCriticalMsg: msg_type = "CRIT "; break;
case QtFatalMsg: msg_type = "FATAL "; break;
}
if (context.file == nullptr && context.function == nullptr)
{
// no debug info
LOG_PRINT("[QT] " << msg_type << local_msg.constData(), LOG_LEVEL_0);
}
else
{
// some debug info
LOG_PRINT("[QT] " << msg_type << local_msg.constData() << " @ " << (context.file ? context.file : "") << ":" << context.line << ", " << (context.function ? context.function : ""), LOG_LEVEL_0);
}
}
bool MainWindow::init_backend(int argc, char* argv[])
{
TRY_ENTRY();
return m_backend.init(argc, argv, this);
if (!m_backend.init(argc, argv, this))
return false;
if (m_backend.is_qt_logs_enabled())
{
qInstallMessageHandler(qt_log_message_handler);
QLoggingCategory::setFilterRules("*=true"); // enable all logs
}
return true;
CATCH_ENTRY2(false);
}
@ -999,6 +1034,7 @@ void MainWindow::on_complete_events()
}
CATCH_ENTRY2(void());
}
void MainWindow::on_clear_events()
{
TRY_ENTRY();
@ -1020,9 +1056,13 @@ QString MainWindow::get_secure_app_data(const QString& param)
}
std::string app_data_buff;
bool r = file_io_utils::load_file_to_string(m_backend.get_config_folder() + "/" + GUI_SECURE_CONFIG_FILENAME, app_data_buff);
std::string filename = m_backend.get_config_folder() + "/" + GUI_SECURE_CONFIG_FILENAME;
bool r = file_io_utils::load_file_to_string(filename, app_data_buff);
if (!r)
{
LOG_PRINT_L1("config file was not loaded: " << m_backend.get_config_folder() + "/" + GUI_SECURE_CONFIG_FILENAME);
return "";
}
if (app_data_buff.size() < sizeof(app_data_file_binary_header))
{
@ -1045,23 +1085,38 @@ QString MainWindow::get_secure_app_data(const QString& param)
m_master_password = pwd.pass;
crypto::hash master_password_pre_hash = crypto::cn_fast_hash(m_master_password.c_str(), m_master_password.length());
crypto::hash master_password_hash = crypto::cn_fast_hash(&master_password_pre_hash, sizeof master_password_pre_hash);
LOG_PRINT_L0("get_secure_app_data, pass hash: " << master_password_hash);
return app_data_buff.substr(sizeof(app_data_file_binary_header)).c_str();
CATCH_ENTRY2(API_RETURN_CODE_INTERNAL_ERROR);
}
QString MainWindow::set_master_password(const QString& param)
{
view::api_response ar;
view::password_data pwd = AUTO_VAL_INIT(pwd);
if (!epee::serialization::load_t_from_json(pwd, param.toStdString()))
{
view::api_response ar;
ar.error_code = API_RETURN_CODE_BAD_ARG;
return MAKE_RESPONSE(ar);
}
if (!currency::validate_password(pwd.pass))
{
ar.error_code = API_RETURN_CODE_BAD_ARG;
return MAKE_RESPONSE(ar);
}
m_master_password = pwd.pass;
view::api_response ar;
crypto::hash master_password_pre_hash = crypto::cn_fast_hash(m_master_password.c_str(), m_master_password.length());
crypto::hash master_password_hash = crypto::cn_fast_hash(&master_password_pre_hash, sizeof master_password_pre_hash);
LOG_PRINT_L0("set_master_password, pass hash: " << master_password_hash);
ar.error_code = API_RETURN_CODE_OK;
return MAKE_RESPONSE(ar);
}
@ -1076,11 +1131,18 @@ QString MainWindow::check_master_password(const QString& param)
ar.error_code = API_RETURN_CODE_BAD_ARG;
return MAKE_RESPONSE(ar);
}
crypto::hash master_password_pre_hash = crypto::cn_fast_hash(m_master_password.c_str(), m_master_password.length());
crypto::hash master_password_hash = crypto::cn_fast_hash(&master_password_pre_hash, sizeof master_password_pre_hash);
crypto::hash pwd_pre_hash = crypto::cn_fast_hash(pwd.pass.c_str(), pwd.pass.length());
crypto::hash pwd_hash = crypto::cn_fast_hash(&pwd_pre_hash, sizeof pwd_pre_hash);
if (m_master_password != pwd.pass)
{
ar.error_code = API_RETURN_CODE_WRONG_PASSWORD;
}else
LOG_PRINT_L0("check_master_password: pwd hash: " << pwd_hash << ", expected: " << master_password_hash);
}
else
{
ar.error_code = API_RETURN_CODE_OK;
}
@ -1099,18 +1161,27 @@ QString MainWindow::store_app_data(const QString& param)
return MAKE_RESPONSE(ar);
}
//bool r = file_io_utils::save_string_to_file(m_backend.get_config_folder() + "/" + GUI_CONFIG_FILENAME, param.toStdString());
bool r = file_io_utils::save_string_to_file(m_backend.get_config_folder() + "/" + GUI_CONFIG_FILENAME, param.toStdString());
//view::api_response ar;
if (r)
ar.error_code = API_RETURN_CODE_OK;
else
ar.error_code = API_RETURN_CODE_FAIL;
crypto::hash master_password_pre_hash = crypto::cn_fast_hash(m_master_password.c_str(), m_master_password.length());
crypto::hash master_password_hash = crypto::cn_fast_hash(&master_password_pre_hash, sizeof master_password_pre_hash);
LOG_PRINT_L0("store_app_data, pass hash: " << master_password_hash);
std::string filename = m_backend.get_config_folder() + "/" + GUI_CONFIG_FILENAME;
bool r = file_io_utils::save_string_to_file(filename, param.toStdString());
if (r)
{
ar.error_code = API_RETURN_CODE_OK;
LOG_PRINT_L1("config saved: " << filename);
}
else
{
ar.error_code = API_RETURN_CODE_FAIL;
LOG_PRINT_L1("config save failed: " << filename);
}
//ar.error_code = store_to_file((m_backend.get_config_folder() + "/" + GUI_CONFIG_FILENAME).c_str(), param).toStdString();
return MAKE_RESPONSE(ar);
CATCH_ENTRY_FAIL_API_RESPONCE();
}
QString MainWindow::is_file_exist(const QString& path)
{
TRY_ENTRY();
@ -1123,7 +1194,7 @@ QString MainWindow::is_file_exist(const QString& path)
}
catch (const std::exception& ex)
{
LOG_ERROR("FILED TO STORE TO FILE: " << path.toStdString() << " ERROR:" << ex.what());
LOG_ERROR("failed to check file existance: " << path.toStdString() << " ERROR:" << ex.what());
return QString(API_RETURN_CODE_ALREADY_EXISTS) + ": " + ex.what();
}
@ -1133,6 +1204,7 @@ QString MainWindow::is_file_exist(const QString& path)
}
CATCH_ENTRY2(API_RETURN_CODE_INTERNAL_ERROR);
}
QString MainWindow::store_to_file(const QString& path, const QString& buff)
{
TRY_ENTRY();
@ -1221,6 +1293,10 @@ QString MainWindow::store_secure_app_data(const QString& param)
else
ar.error_code = API_RETURN_CODE_FAIL;
crypto::hash master_password_pre_hash = crypto::cn_fast_hash(m_master_password.c_str(), m_master_password.length());
crypto::hash master_password_hash = crypto::cn_fast_hash(&master_password_pre_hash, sizeof master_password_pre_hash);
LOG_PRINT_L0("store_secure_app_data, r = " << r << ", pass hash: " << master_password_hash);
return MAKE_RESPONSE(ar);
CATCH_ENTRY_FAIL_API_RESPONCE();
}
@ -1335,7 +1411,7 @@ QString MainWindow::get_log_level(const QString& param)
// return MAKE_RESPONSE(ar);
// }
//
// currency::COMMAND_RPC_GET_ALL_OFFERS::response rp = AUTO_VAL_INIT(rp);
// currency::COMMAND_RPC_GET_OFFERS_EX::response rp = AUTO_VAL_INIT(rp);
// ar.error_code = m_backend.get_all_offers(rp);
//
// std::string buff = epee::serialization::store_t_to_json(rp);
@ -1424,7 +1500,7 @@ QString MainWindow::get_contracts(const QString& param)
TRY_ENTRY();
LOG_API_TIMING();
PREPARE_ARG_FROM_JSON(view::wallet_id_obj, owd);
PREPARE_RESPONSE(view::contracts_array, ar);
PREPARE_RESPONSE(tools::wallet_public::contracts_array, ar);
ar.error_code = m_backend.get_contracts(owd.wallet_id, ar.response_data.contracts);
return MAKE_RESPONSE(ar);
@ -1435,16 +1511,14 @@ QString MainWindow::create_proposal(const QString& param)
{
TRY_ENTRY();
LOG_API_TIMING();
PREPARE_ARG_FROM_JSON(view::create_proposal_param, cpp);
PREPARE_RESPONSE(view::contracts_array, ar);
ar.error_code = m_backend.create_proposal(cpp.wallet_id, cpp.details, cpp.payment_id, cpp.expiration_period, cpp.fee, cpp.b_fee);
PREPARE_ARG_FROM_JSON(view::create_proposal_param_gui, cpp);
PREPARE_RESPONSE(tools::wallet_public::contracts_array, ar);
ar.error_code = m_backend.create_proposal(cpp);
return MAKE_RESPONSE(ar);
CATCH_ENTRY_FAIL_API_RESPONCE();
}
QString MainWindow::accept_proposal(const QString& param)
{
TRY_ENTRY();
@ -1461,7 +1535,7 @@ QString MainWindow::release_contract(const QString& param)
{
TRY_ENTRY();
LOG_API_TIMING();
PREPARE_ARG_FROM_JSON(view::accept_proposal_param, rcp);
PREPARE_ARG_FROM_JSON(view::release_contract_param, rcp);
PREPARE_RESPONSE(view::api_void, ar);
ar.error_code = m_backend.release_contract(rcp.wallet_id, rcp.contract_id, rcp.release_type);
@ -1538,7 +1612,7 @@ QString MainWindow::get_my_offers(const QString& param)
LOG_API_TIMING();
//return que_call2<view::open_wallet_request>("open_wallet", param, [this](const view::open_wallet_request& owd, view::api_response& ar){
PREPARE_ARG_FROM_JSON(bc_services::core_offers_filter, f);
PREPARE_RESPONSE(currency::COMMAND_RPC_GET_ALL_OFFERS::response, ar);
PREPARE_RESPONSE(currency::COMMAND_RPC_GET_OFFERS_EX::response, ar);
ar.error_code = m_backend.get_my_offers(f, ar.response_data.offers);
return MAKE_RESPONSE(ar);
CATCH_ENTRY_FAIL_API_RESPONCE();
@ -1548,7 +1622,7 @@ QString MainWindow::get_fav_offers(const QString& param)
TRY_ENTRY();
LOG_API_TIMING();
PREPARE_ARG_FROM_JSON(view::get_fav_offers_request, f);
PREPARE_RESPONSE(currency::COMMAND_RPC_GET_ALL_OFFERS::response, ar);
PREPARE_RESPONSE(currency::COMMAND_RPC_GET_OFFERS_EX::response, ar);
ar.error_code = m_backend.get_fav_offers(f.ids, f.filter, ar.response_data.offers);
return MAKE_RESPONSE(ar);
CATCH_ENTRY_FAIL_API_RESPONCE();
@ -1591,7 +1665,7 @@ QString MainWindow::get_offers_ex(const QString& param)
LOG_API_TIMING();
//return que_call2<bc_services::core_offers_filter>("get_offers_ex", param, [this](const bc_services::core_offers_filter& f, view::api_response& ar){
PREPARE_ARG_FROM_JSON(bc_services::core_offers_filter, f);
PREPARE_RESPONSE(currency::COMMAND_RPC_GET_ALL_OFFERS::response, ar);
PREPARE_RESPONSE(currency::COMMAND_RPC_GET_OFFERS_EX::response, ar);
ar.error_code = m_backend.get_offers_ex(f, ar.response_data.offers, ar.response_data.total_offers);
return MAKE_RESPONSE(ar);
CATCH_ENTRY_FAIL_API_RESPONCE();
@ -1606,7 +1680,6 @@ QString MainWindow::push_offer(const QString& param)
PREPARE_ARG_FROM_JSON(view::push_offer_param, a);
PREPARE_RESPONSE(view::transfer_response, ar);
currency::transaction res_tx = AUTO_VAL_INIT(res_tx);
ar.error_code = m_backend.push_offer(a.wallet_id, a.od, res_tx);
@ -1685,7 +1758,7 @@ QString MainWindow::get_mining_history(const QString& param)
LOG_API_TIMING();
//return prepare_call<view::wallet_id_obj, tools::wallet_rpc::mining_history>("get_mining_history", param, [this](const view::wallet_id_obj& a, view::api_response& ar) {
PREPARE_ARG_FROM_JSON(view::wallet_id_obj, a);
PREPARE_RESPONSE(tools::wallet_rpc::mining_history, ar);
PREPARE_RESPONSE(tools::wallet_public::mining_history, ar);
ar.error_code = m_backend.get_mining_history(a.wallet_id, ar.response_data);
if (ar.error_code != API_RETURN_CODE_OK)

View file

@ -17,7 +17,7 @@ DISABLE_VS_WARNINGS(4503)
#include "serialization/keyvalue_serialization.h"
#include "storages/portable_storage_template_helper.h"
#include "rpc/core_rpc_server_commands_defs.h"
#include "wallet/wallet_rpc_server_commans_defs.h"
#include "wallet/wallet_public_structs_defs.h"
#include "currency_core/offers_services_helpers.h"
#include "currency_core/basic_api_response_codes.h"
POP_VS_WARNINGS
@ -340,7 +340,7 @@ public:
struct transfer_event_info
{
tools::wallet_rpc::wallet_transfer_info ti;
tools::wallet_public::wallet_transfer_info ti;
uint64_t unlocked_balance;
uint64_t balance;
uint64_t total_mined;
@ -357,8 +357,8 @@ public:
struct transfers_array
{
std::vector<tools::wallet_rpc::wallet_transfer_info> unconfirmed;
std::vector<tools::wallet_rpc::wallet_transfer_info> history;
std::vector<tools::wallet_public::wallet_transfer_info> unconfirmed;
std::vector<tools::wallet_public::wallet_transfer_info> history;
uint64_t total_history_items;
BEGIN_KV_SERIALIZE_MAP()
@ -439,16 +439,6 @@ public:
};
struct contracts_array
{
std::vector<tools::wallet_rpc::escrow_contract_details> contracts;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(contracts)
END_KV_SERIALIZE_MAP()
};
struct header_entry
{
std::string field;
@ -583,24 +573,6 @@ public:
};
struct create_proposal_param
{
uint64_t wallet_id;
bc_services::contract_private_details details;
std::string payment_id;
uint64_t expiration_period;
uint64_t fee;
uint64_t b_fee;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(wallet_id)
KV_SERIALIZE(details)
KV_SERIALIZE(payment_id)
KV_SERIALIZE(expiration_period)
KV_SERIALIZE(fee)
KV_SERIALIZE(b_fee)
END_KV_SERIALIZE_MAP()
};
struct wallet_and_contract_id_param
{
@ -614,7 +586,7 @@ public:
END_KV_SERIALIZE_MAP()
};
struct accept_proposal_param : public wallet_and_contract_id_param
struct release_contract_param : public wallet_and_contract_id_param
{
std::string release_type;
@ -644,7 +616,16 @@ public:
KV_SERIALIZE(expiration_period)
KV_CHAIN_BASE(contract_and_fee_param)
END_KV_SERIALIZE_MAP()
};
struct create_proposal_param_gui : public tools::wallet_public::create_proposal_param
{
uint64_t wallet_id;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(wallet_id)
KV_CHAIN_BASE(tools::wallet_public::create_proposal_param)
END_KV_SERIALIZE_MAP()
};
struct address_validation_response

View file

@ -12,10 +12,10 @@ class i_backend_wallet_callback
{
public:
virtual void on_new_block(size_t wallet_id, uint64_t /*height*/, const currency::block& /*block*/) {}
virtual void on_transfer2(size_t wallet_id, const tools::wallet_rpc::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) {}
virtual void on_transfer2(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) {}
virtual void on_pos_block_found(size_t wallet_id, const currency::block& /*block*/) {}
virtual void on_sync_progress(size_t wallet_id, const uint64_t& /*percents*/) {}
virtual void on_transfer_canceled(size_t wallet_id, const tools::wallet_rpc::wallet_transfer_info& wti) {}
virtual void on_transfer_canceled(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti) {}
};
struct i_wallet_to_i_backend_adapter: public tools::i_wallet2_callback
@ -27,7 +27,7 @@ struct i_wallet_to_i_backend_adapter: public tools::i_wallet2_callback
virtual void on_new_block(uint64_t height, const currency::block& block) {
m_pbackend->on_new_block(m_wallet_id, height, block);
}
virtual void on_transfer2(const tools::wallet_rpc::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) {
virtual void on_transfer2(const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) {
m_pbackend->on_transfer2(m_wallet_id, wti, balance, unlocked_balance, total_mined);
}
virtual void on_pos_block_found(const currency::block& wti) {
@ -36,7 +36,7 @@ struct i_wallet_to_i_backend_adapter: public tools::i_wallet2_callback
virtual void on_sync_progress(const uint64_t& progress) {
m_pbackend->on_sync_progress(m_wallet_id, progress);
}
virtual void on_transfer_canceled(const tools::wallet_rpc::wallet_transfer_info& wti) {
virtual void on_transfer_canceled(const tools::wallet_public::wallet_transfer_info& wti) {
m_pbackend->on_transfer_canceled(m_wallet_id, wti);
}
private:

View file

@ -46,7 +46,7 @@
"ONLINE": "Online",
"ERROR": "Systemfehler",
"COMPLETE": "Abschluss",
"SYNCING": "Synchronisiere Blockchain",
"SYNCING": "Syncing block",
"LOADING": "Lade Blockchain-Daten"
},
"UPDATE": {

View file

@ -150,16 +150,30 @@
"TIME3": "1 hour",
"TIME4": "Never"
},
"SCALE": {
"75": "75% scale",
"100": "100% scale",
"125": "125% scale",
"150": "150% scale"
},
"LANGUAGE": {
"TITLE": "Language",
"EN": "English",
"FR": "French",
"DE": "Deutsch",
"IT": "Italian",
"PT": "Portuguese"
},
"MASTER_PASSWORD": {
"TITLE": "Update master password",
"OLD": "Old password",
"OLD": "Current password",
"NEW": "New password",
"CONFIRM": "New password confirmation",
"BUTTON": "Save"
},
"FORM_ERRORS": {
"PASS_REQUIRED": "Password is required",
"PASS_NOT_MATCH": "Old password not match",
"PASS_NOT_MATCH": "Incorrect password",
"CONFIRM_NOT_MATCH": "Confirm password not match"
},
"LAST_BUILD": "Current build: {{value}}",
@ -172,6 +186,10 @@
"AVAILABLE_BALANCE": "Available <b>{{available}} {{currency}}<b/>",
"LOCKED_BALANCE": "Locked <b>{{locked}} {{currency}}<b/>",
"LOCKED_BALANCE_LINK": "What does that mean?",
"CONFIRM": {
"TITLE": "Remove wallet from the list?",
"MESSAGE": "To access it youll have to add it again"
},
"TABS": {
"SEND": "Send",
"RECEIVE": "Receive",
@ -179,6 +197,12 @@
"CONTRACTS": "Contracts",
"MESSAGES": "Messages",
"STAKING": "Staking"
},
"TOOLTIPS": {
"EDIT_ALIAS": "Edit alias",
"TRANSFER_ALIAS": "Transfer alias",
"SETTINGS": "Settings",
"CLOSE": "Close wallet"
}
},
"WALLET_DETAILS": {
@ -453,7 +477,8 @@
"ERROR": "Error",
"SUCCESS": "Success",
"INFO": "Information",
"OK": "OK"
"OK": "OK",
"CANCEL": "Cancel"
},
"CONFIRM": {
"BUTTON_CONFIRM": "Send",

View file

@ -46,7 +46,7 @@
"ONLINE": "En ligne",
"ERROR": "Erreur de système",
"COMPLETE": "Fermeture",
"SYNCING": "Synchronisation de la blockchain",
"SYNCING": "Syncing block",
"LOADING": "Chargement des données de la blockchain"
},
"UPDATE": {

View file

@ -46,7 +46,7 @@
"ONLINE": "Online",
"ERROR": "Errore di sistema",
"COMPLETE": "Completata",
"SYNCING": "Sincronizzazione blockchain",
"SYNCING": "Syncing block",
"LOADING": "Caricamento dati blockchain"
},
"UPDATE": {

File diff suppressed because it is too large Load diff

View file

@ -789,6 +789,16 @@ input[type='checkbox'].style-checkbox {
&.custom-select {
width: 100%;
&.ng-select-single {
.ng-select-container {
.ng-value-container {
.ng-value {
line-height: 1.8rem;
}
}
}
}
.ng-select-container {
border: none;
border-radius: 0;
@ -873,7 +883,7 @@ input[type='checkbox'].style-checkbox {
}
}
app-modal-container {
app-modal-container, app-confirm-modal {
.modal {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -649,7 +649,7 @@ module.exports = function (NAME, wrapper, methods, common, IS_MAP, IS_WEAK) {
/*! no static exports found */
/***/ (function(module, exports) {
var core = module.exports = { version: '2.6.9' };
var core = module.exports = { version: '2.6.10' };
if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef
@ -5800,8 +5800,8 @@ __webpack_require__.r(__webpack_exports__);
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(/*! D:\Projects\Projects now\work\zano\src\gui\qt-daemon\html_source\src\polyfills.ts */"./src/polyfills.ts");
module.exports = __webpack_require__(/*! D:\Projects\Projects now\work\zano\src\gui\qt-daemon\html_source\node_modules\@angular-devkit\build-angular\src\angular-cli-files\models\jit-polyfills.js */"./node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/jit-polyfills.js");
__webpack_require__(/*! C:\Users\Admin\Desktop\zano\src\gui\qt-daemon\html_source\src\polyfills.ts */"./src/polyfills.ts");
module.exports = __webpack_require__(/*! C:\Users\Admin\Desktop\zano\src\gui\qt-daemon\html_source\node_modules\@angular-devkit\build-angular\src\angular-cli-files\models\jit-polyfills.js */"./node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/jit-polyfills.js");
/***/ })

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,16 @@
<div class="modal">
<div class="content">
<i class="icon info"></i>
<div class="message-container">
<span class="title">{{title}}</span>
<span class="message">{{message}}</span>
<div class="wrap-btn">
<button type="button" class="action-button" (click)="onSubmit()" #btn>{{ 'MODALS.OK' | translate }}</button>
<button type="button" class="action-button" (click)="onClose()">{{ 'MODALS.CANCEL' | translate }}</button>
</div>
</div>
</div>
<button type="button" class="close-button" (click)="onClose()"><i class="icon close"></i></button>
</div>

View file

@ -0,0 +1,87 @@
:host {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
align-items: center;
justify-content: center;
background: rgba(255, 255, 255, 0.25);
}
.modal {
position: relative;
display: flex;
flex-direction: column;
background-position: center;
background-size: 200%;
padding: 3rem;
min-width: 34rem;
max-width: 60rem;
.content {
display: flex;
.icon {
flex: 0 0 auto;
width: 4.4rem;
height: 4.4rem;
&.info {
mask: url(~src/assets/icons/modal-info.svg) no-repeat center;
}
}
.message-container {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
margin-left: 2rem;
.title {
font-size: 1.8rem;
font-weight: 600;
line-height: 2.2rem;
}
.message {
font-size: 1.3rem;
line-height: 1.8rem;
margin-top: 0.4rem;
}
}
}
.wrap-btn {
display: flex;
justify-content: space-between;
width: 100%;
margin-top: 3.5rem;
}
.action-button {
width: 10rem;
height: 2.4rem;
}
.close-button {
position: absolute;
top: 0;
right: 0;
display: flex;
align-items: center;
justify-content: center;
background: transparent;
margin: 0;
padding: 0;
width: 2.4rem;
height: 2.4rem;
.icon {
mask: url(~src/assets/icons/close.svg) no-repeat center;
width: 2.4rem;
height: 2.4rem;
}
}
}

View file

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ConfirmModalComponent } from './confirm-modal.component';
describe('ConfirmModalComponent', () => {
let component: ConfirmModalComponent;
let fixture: ComponentFixture<ConfirmModalComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ConfirmModalComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ConfirmModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View file

@ -0,0 +1,28 @@
import { Component, OnInit, Input, Output, EventEmitter, ViewChild, ElementRef } from '@angular/core';
@Component({
selector: 'app-confirm-modal',
templateUrl: './confirm-modal.component.html',
styleUrls: ['./confirm-modal.component.scss']
})
export class ConfirmModalComponent implements OnInit {
@Input() title: string;
@Input() message: string;
@Output() confirmed: EventEmitter<boolean> = new EventEmitter<boolean>();
@ViewChild('btn') button: ElementRef;
constructor() { }
ngOnInit() {
this.button.nativeElement.focus();
}
onSubmit() {
this.confirmed.emit(true);
}
onClose() {
this.confirmed.emit(false);
}
}

View file

@ -13,6 +13,7 @@ export class TooltipDirective implements OnDestroy {
@Input() placement: string;
@Input() tooltipClass: string;
@Input() timeout = 0;
@Input() timeDelay = 0;
@Input() delay = 0;
@Input() showWhenNoOverflow = true;
@Output() onHide = new EventEmitter<boolean>();
@ -23,6 +24,8 @@ export class TooltipDirective implements OnDestroy {
removeTooltipTimeout;
removeTooltipTimeoutInner;
removeTooltipTimeDelay;
constructor(private el: ElementRef, private renderer: Renderer2, private route: ActivatedRoute) {
}
@ -30,7 +33,13 @@ export class TooltipDirective implements OnDestroy {
if (this.showWhenNoOverflow || (!this.showWhenNoOverflow && this.el.nativeElement.offsetWidth < this.el.nativeElement.scrollWidth)) {
this.cursor = 'pointer';
if (!this.tooltip) {
this.show();
if (this.timeDelay !== 0) {
this.removeTooltipTimeDelay = setTimeout(() => {
this.show();
}, this.timeDelay);
} else {
this.show();
}
} else {
this.cancelHide();
}
@ -38,6 +47,7 @@ export class TooltipDirective implements OnDestroy {
}
@HostListener('mouseleave') onMouseLeave() {
clearTimeout(this.removeTooltipTimeDelay);
if (this.tooltip) {
this.hide();
}
@ -222,6 +232,7 @@ export class TooltipDirective implements OnDestroy {
ngOnDestroy() {
clearTimeout(this.removeTooltipTimeout);
clearTimeout(this.removeTooltipTimeoutInner);
clearTimeout(this.removeTooltipTimeDelay);
if (this.tooltip) {
this.renderer.removeChild(document.body, this.tooltip);
this.tooltip = null;

View file

@ -58,6 +58,8 @@ export class VariablesService {
public contacts: Array<Contact> = [];
public newContact: Contact = {name: null, address: null, notes: null};
public pattern = '^[a-zA-Z0-9_.\\\]\*\|\~\!\?\@\#\$\%\^\&\+\{\}\(\)\<\>\:\;\"\'\-\=\/\,\[\\\\]*$';
getExpMedTsEvent = new BehaviorSubject(null);
getHeightAppEvent = new BehaviorSubject(null);
getHeightMaxEvent = new BehaviorSubject(null);

View file

@ -15,7 +15,8 @@ import {ModalService} from './_helpers/services/modal.service';
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit, OnDestroy {
intervalUpdatePriceState;
intervalUpdateContractsState;
expMedTsEvent;
onQuitRequest = false;
@ -38,7 +39,7 @@ export class AppComponent implements OnInit, OnDestroy {
private intToMoneyPipe: IntToMoneyPipe,
private modalService: ModalService
) {
translate.addLangs(['en', 'fr']);
translate.addLangs(['en', 'fr', 'de', 'it', 'pt']);
translate.setDefaultLang('en');
// const browserLang = translate.getBrowserLang();
// translate.use(browserLang.match(/en|fr/) ? browserLang : 'en');
@ -62,7 +63,7 @@ export class AppComponent implements OnInit, OnDestroy {
this.translate.instant('BACKEND_LOCALIZATION.TRAY_MENU_SHOW'),
this.translate.instant('BACKEND_LOCALIZATION.TRAY_MENU_MINIMIZE')
];
this.backend.setBackendLocalization(stringsArray, 'en');
this.backend.setBackendLocalization(stringsArray, this.variablesService.settings.language);
} else {
console.warn('wait translate use');
setTimeout(() => {
@ -173,7 +174,7 @@ export class AppComponent implements OnInit, OnDestroy {
this.variablesService.last_build_displaymode = data.last_build_displaymode;
this.variablesService.setHeightApp(data.height);
this.variablesService.setHeightMax(data.max_net_seen_height);
this.backend.getContactAlias();
this.ngZone.run(() => {
this.variablesService.daemon_state = data['daemon_network_state'];
if (data['daemon_network_state'] === 1) {
@ -516,7 +517,7 @@ export class AppComponent implements OnInit, OnDestroy {
this.variablesService.settings.theme = this.variablesService.defaultTheme;
this.renderer.addClass(document.body, 'theme-' + this.variablesService.settings.theme);
}
this.translate.use(this.variablesService.settings.language);
this.setBackendLocalization();
this.backend.setLogLevel(this.variablesService.settings.appLog);
@ -547,6 +548,10 @@ export class AppComponent implements OnInit, OnDestroy {
console.log(error);
});
this.getMoneyEquivalent();
this.intervalUpdatePriceState = setInterval(() => {
this.getMoneyEquivalent();
}, 30000);
}
getMoneyEquivalent() {
@ -565,7 +570,7 @@ export class AppComponent implements OnInit, OnDestroy {
console.warn('api.coingecko.com error: ', error);
setTimeout(() => {
this.getMoneyEquivalent();
}, 60000);
}, 30000);
}
)
}
@ -673,6 +678,9 @@ export class AppComponent implements OnInit, OnDestroy {
if (this.intervalUpdateContractsState) {
clearInterval(this.intervalUpdateContractsState);
}
if (this.intervalUpdatePriceState) {
clearInterval(this.intervalUpdatePriceState);
}
this.expMedTsEvent.unsubscribe();
}

View file

@ -57,12 +57,14 @@ import { ContactsComponent } from './contacts/contacts.component';
import { AddContactsComponent } from './add-contacts/add-contacts.component';
import { ContactSendComponent } from './contact-send/contact-send.component';
import { ExportImportComponent } from './export-import/export-import.component';
import { ConfirmModalComponent } from './_helpers/directives/confirm-modal/confirm-modal.component';
export function HttpLoaderFactory(httpClient: HttpClient) {
return new TranslateHttpLoader(httpClient, './assets/i18n/', '.json');
}
import { PapaParseModule } from 'ngx-papaparse';
// import * as more from 'highcharts/highcharts-more.src';
// import * as exporting from 'highcharts/modules/exporting.src';
// import * as highstock from 'highcharts/modules/stock.src';
@ -120,7 +122,8 @@ export function highchartsFactory() {
AddContactsComponent,
ContactSendComponent,
ExportImportComponent,
SafeHTMLPipe
SafeHTMLPipe,
ConfirmModalComponent
],
imports: [
BrowserModule,
@ -150,7 +153,8 @@ export function highchartsFactory() {
],
entryComponents: [
ModalContainerComponent,
SendModalComponent
SendModalComponent,
ConfirmModalComponent
],
bootstrap: [AppComponent]
})

View file

@ -32,6 +32,11 @@
<div class="input-block">
<label for="wallet-password">{{ 'CREATE_WALLET.PASS' | translate }}</label>
<input type="password" id="wallet-password" formControlName="password" [attr.readonly]="walletSaved ? '' : null" (contextmenu)="variablesService.onContextMenuPasteSelect($event)">
<div class="error-block" *ngIf="createForm.controls['password'].dirty && createForm.controls['password'].errors">
<div *ngIf="createForm.controls['password'].errors.pattern">
{{ 'ERRORS.WRONG_PASSWORD' | translate }}
</div>
</div>
</div>
<div class="input-block">

View file

@ -23,7 +23,7 @@ export class CreateWalletComponent implements OnInit {
}
return null;
}]),
password: new FormControl(''),
password: new FormControl('', Validators.pattern(this.variablesService.pattern)),
confirm: new FormControl('')
}, function (g: FormGroup) {
return g.get('password').value === g.get('confirm').value ? null : {'confirm_mismatch': true};

View file

@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, NgZone } from '@angular/core';
import { Location } from '@angular/common';
import { BackendService } from '../_helpers/services/backend.service';
import { VariablesService } from '../_helpers/services/variables.service';
@ -6,6 +6,7 @@ import { Contact } from '../_helpers/models/contact.model';
import { ModalService } from '../_helpers/services/modal.service';
import { Papa } from 'ngx-papaparse';
import { TranslateService } from '@ngx-translate/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-export-import',
@ -21,7 +22,9 @@ export class ExportImportComponent implements OnInit {
private backend: BackendService,
private modalService: ModalService,
private papa: Papa,
private translate: TranslateService
private translate: TranslateService,
private router: Router,
private ngZone: NgZone
) {}
ngOnInit() {}
@ -78,10 +81,9 @@ export class ExportImportComponent implements OnInit {
});
}
this.backend.getContactAlias();
this.modalService.prepareModal(
'success',
'CONTACTS.SUCCESS_IMPORT'
);
this.ngZone.run(() => {
this.router.navigate(['/contacts']);
});
}
if (elements.errors.length) {
this.modalService.prepareModal(
@ -106,7 +108,7 @@ export class ExportImportComponent implements OnInit {
delete contact.alias;
contacts.push(contact);
});
this.backend.saveFileDialog(
'',
'*',
@ -118,10 +120,6 @@ export class ExportImportComponent implements OnInit {
const path = this.isValid(file_data.path) ? file_data.path : `${file_data.path}.csv`;
if (file_status && this.isValid(path) && this.variablesService.contacts.length) {
this.backend.storeFile(path, this.papa.unparse(contacts));
this.modalService.prepareModal(
'success',
'CONTACTS.SUCCESS_EXPORT'
);
}
if (!(file_data.error_code === 'CANCELED') && !this.isValid(path)) {
this.modalService.prepareModal('error', 'CONTACTS.ERROR_EXPORT');

View file

@ -9,6 +9,11 @@
<div class="input-block">
<label for="master-pass">{{ 'LOGIN.SETUP_MASTER_PASS' | translate }}</label>
<input type="password" id="master-pass" formControlName="password" (contextmenu)="variablesService.onContextMenuPasteSelect($event)">
<div class="error-block" *ngIf="regForm.controls['password'].dirty && regForm.controls['password'].errors">
<div *ngIf="regForm.controls['password'].errors.pattern">
{{ 'ERRORS.WRONG_PASSWORD' | translate }}
</div>
</div>
</div>
<div class="input-block">
@ -22,7 +27,7 @@
</div>
<div class="wrap-button">
<button type="submit" class="blue-button" [disabled]="!regForm.controls['password'].value.length || !regForm.controls['confirmation'].value.length || (regForm.errors && regForm.errors['mismatch'])">{{ 'LOGIN.BUTTON_NEXT' | translate }}</button>
<button type="submit" class="blue-button" [disabled]="!regForm.controls['password'].value.length || !regForm.controls['confirmation'].value.length || (regForm.errors && regForm.errors['mismatch']) || regForm.controls['password'].errors">{{ 'LOGIN.BUTTON_NEXT' | translate }}</button>
<button type="button" class="blue-button" (click)="onSkipCreatePass()" [disabled]="regForm.controls['password'].value.length || regForm.controls['confirmation'].value.length">{{ 'LOGIN.BUTTON_SKIP' | translate }}</button>
</div>

View file

@ -18,7 +18,7 @@
justify-content: center;
&::ng-deep svg {
width: 14rem;
width: 15rem;
}
}

View file

@ -1,5 +1,5 @@
import {Component, NgZone, OnInit, OnDestroy} from '@angular/core';
import {FormGroup, FormControl} from '@angular/forms';
import {FormGroup, FormControl, Validators} from '@angular/forms';
import {ActivatedRoute, Router} from '@angular/router';
import {BackendService} from '../_helpers/services/backend.service';
import {VariablesService} from '../_helpers/services/variables.service';
@ -18,11 +18,13 @@ export class LoginComponent implements OnInit, OnDestroy {
queryRouting;
regForm = new FormGroup({
password: new FormControl(''),
password: new FormControl('',
Validators.pattern(this.variablesService.pattern)),
confirmation: new FormControl('')
}, function (g: FormGroup) {
}, [function (g: FormGroup) {
return g.get('password').value === g.get('confirmation').value ? null : {'mismatch': true};
});
}
]);
authForm = new FormGroup({
password: new FormControl('')

View file

@ -35,13 +35,13 @@
display: flex;
cursor: pointer;
font-size: 1.3rem;
line-height: 1.4rem;
line-height: 1.5rem;
.icon {
mask: url(../../assets/icons/howto.svg) no-repeat center;
margin-right: 0.8rem;
width: 1.4rem;
height: 1.4rem;
width: 1.5rem;
height: 1.5rem;
}
}
}

View file

@ -32,6 +32,11 @@
<div class="input-block half-block">
<label for="wallet-password">{{ 'RESTORE_WALLET.PASS' | translate }}</label>
<input type="password" id="wallet-password" formControlName="password" [attr.readonly]="walletSaved ? '' : null" (contextmenu)="variablesService.onContextMenuPasteSelect($event)">
<div class="error-block" *ngIf="restoreForm.controls['password'].dirty && restoreForm.controls['password'].errors">
<div *ngIf="restoreForm.controls['password'].errors.pattern">
{{ 'ERRORS.WRONG_PASSWORD' | translate }}
</div>
</div>
</div>
<div class="input-block half-block">

View file

@ -24,7 +24,7 @@ export class RestoreWalletComponent implements OnInit {
return null;
}]),
key: new FormControl('', Validators.required),
password: new FormControl(''),
password: new FormControl('', Validators.pattern(this.variablesService.pattern)),
confirm: new FormControl('')
}, function (g: FormGroup) {
return g.get('password').value === g.get('confirm').value ? null : {'confirm_mismatch': true};

View file

@ -27,10 +27,29 @@
<div class="scale-selection">
<button type="button" class="button-block" [class.active]="item.id === variablesService.settings.scale" *ngFor="let item of appScaleOptions" (click)="setScale(item.id)">
<span class="label">{{item.name}}</span>
<span class="label">{{item.name | translate}}</span>
</button>
</div>
<div class="lock-selection">
<label class="lock-selection-title">{{ 'SETTINGS.LANGUAGE.TITLE' | translate }}</label>
<ng-select class="custom-select"
[items]="languagesOptions"
bindValue="name"
bindLabel="language"
[(ngModel)]="variablesService.settings.language"
[clearable]="false"
[searchable]="false"
(change)="onLanguageChange()">
<ng-template ng-label-tmp let-item="item">
{{item.language | translate}}
</ng-template>
<ng-template ng-option-tmp let-item="item" let-index="index">
{{item.language | translate}}
</ng-template>
</ng-select>
</div>
<div class="lock-selection">
<label class="lock-selection-title">{{ 'SETTINGS.APP_LOCK.TITLE' | translate }}</label>
<ng-select class="custom-select"
@ -78,6 +97,11 @@
<div class="input-block">
<label for="new-password">{{ 'SETTINGS.MASTER_PASSWORD.NEW' | translate }}</label>
<input type="password" id="new-password" formControlName="new_password" (contextmenu)="variablesService.onContextMenuPasteSelect($event)"/>
<div class="error-block" *ngIf="changeForm.controls['new_password'].dirty && changeForm.controls['new_password'].errors">
<div *ngIf="changeForm.controls['new_password'].errors.pattern">
{{ 'ERRORS.WRONG_PASSWORD' | translate }}
</div>
</div>
</div>
<div class="input-block">

View file

@ -1,8 +1,9 @@
import {Component, NgZone, OnInit, Renderer2} from '@angular/core';
import {VariablesService} from '../_helpers/services/variables.service';
import {BackendService} from '../_helpers/services/backend.service';
import {FormControl, FormGroup} from '@angular/forms';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {Location} from '@angular/common';
import { TranslateService } from '@ngx-translate/core';
@Component({
selector: 'app-settings',
@ -14,6 +15,28 @@ export class SettingsComponent implements OnInit {
theme: string;
scale: number;
changeForm: any;
languagesOptions = [
{
name: 'en',
language: 'SETTINGS.LANGUAGE.EN'
},
{
name: 'fr',
language: 'SETTINGS.LANGUAGE.FR'
},
{
name: 'de',
language: 'SETTINGS.LANGUAGE.DE'
},
{
name: 'it',
language: 'SETTINGS.LANGUAGE.IT'
},
{
name: 'pt',
language: 'SETTINGS.LANGUAGE.PT'
}
];
appLockOptions = [
{
id: 5,
@ -35,19 +58,19 @@ export class SettingsComponent implements OnInit {
appScaleOptions = [
{
id: 7.5,
name: '75% scale'
name: 'SETTINGS.SCALE.75'
},
{
id: 10,
name: '100% scale'
name: 'SETTINGS.SCALE.100'
},
{
id: 12.5,
name: '125% scale'
name: 'SETTINGS.SCALE.125'
},
{
id: 15,
name: '150% scale'
name: 'SETTINGS.SCALE.150'
}
];
appLogOptions = [
@ -79,13 +102,14 @@ export class SettingsComponent implements OnInit {
public variablesService: VariablesService,
private backend: BackendService,
private location: Location,
public translate: TranslateService,
private ngZone: NgZone
) {
this.theme = this.variablesService.settings.theme;
this.scale = this.variablesService.settings.scale;
this.changeForm = new FormGroup({
password: new FormControl(''),
new_password: new FormControl(''),
new_password: new FormControl('', Validators.pattern(this.variablesService.pattern)),
new_confirmation: new FormControl('')
}, [(g: FormGroup) => {
return g.get('new_password').value === g.get('new_confirmation').value ? null : {'confirm_mismatch': true};
@ -133,15 +157,14 @@ export class SettingsComponent implements OnInit {
} else {
console.log(data['error_code']);
}
})
});
} else {
this.backend.dropSecureAppData();
}
this.changeForm.reset();
}
}
onLockChange() {
if (this.variablesService.appLogin) {
this.variablesService.restartCountdown();
@ -154,6 +177,11 @@ export class SettingsComponent implements OnInit {
this.backend.storeAppData();
}
onLanguageChange() {
this.translate.use(this.variablesService.settings.language);
this.backend.storeAppData();
}
back() {
this.location.back();
}

View file

@ -38,7 +38,7 @@
</div>
</div>
<div class="sidebar-settings">
<div class="wrap-button" routerLinkActive="active" *ngIf="variablesService.appPass === ''; else contactsShow" tooltip="{{ 'SIDEBAR.CONTACTS_TOOLTIP' | translate }}" placement="top" tooltipClass="table-tooltip account-tooltip" [delay]="500">
<div class="wrap-button" routerLinkActive="active" *ngIf="variablesService.appPass === ''; else contactsShow" tooltip="{{ 'SIDEBAR.CONTACTS_TOOLTIP' | translate }}" placement="top" tooltipClass="table-tooltip account-tooltip" [delay]="500" [timeDelay]="500">
<button (click)="contactsRoute()" [class.disabled]="variablesService.daemon_state !== 2 || variablesService.appPass === ''"
[disabled]="variablesService.daemon_state !== 2 || variablesService.appPass === ''">
<i class="icon contacts"></i>
@ -47,7 +47,7 @@
</div>
<ng-template #contactsShow>
<div class="wrap-button" routerLinkActive="active">
<button (click)="contactsRoute()"
<button (click)="contactsRoute()" [class.disabled]="variablesService.daemon_state !== 2" [disabled]="variablesService.daemon_state !== 2"
(mouseover)="menuItem = true"
(mouseleave)="menuItem = false"
>
@ -71,7 +71,7 @@
<span>{{ 'SIDEBAR.SETTINGS' | translate }}</span>
</button>
</div>
<div class="wrap-button" *ngIf="variablesService.appPass === ''; else masterPass" tooltip="{{ 'SIDEBAR.LOG_OUT_TOOLTIP' | translate }}" placement="bottom" tooltipClass="table-tooltip account-tooltip" [delay]="500">
<div class="wrap-button" *ngIf="variablesService.appPass === ''; else masterPass" tooltip="{{ 'SIDEBAR.LOG_OUT_TOOLTIP' | translate }}" placement="bottom" tooltipClass="table-tooltip account-tooltip" [delay]="500" [timeDelay]="500">
<button (click)="logOut()" [class.disabled]="variablesService.appPass === ''" [disabled]="variablesService.appPass === ''">
<i class="icon logout"></i>
<span>{{ 'SIDEBAR.LOG_OUT' | translate }}</span>

View file

@ -8,16 +8,16 @@
<div class="alias" *ngIf="variablesService.currentWallet.alias.hasOwnProperty('name') && variablesService.currentWallet.loaded && variablesService.daemon_state === 2">
<span>{{variablesService.currentWallet.alias['name']}}</span>
<ng-container *ngIf="variablesService.currentWallet.alias_available">
<i class="icon edit" [routerLink]="['/edit-alias']"></i>
<i class="icon transfer" [routerLink]="['/transfer-alias']"></i>
<i class="icon edit" [routerLink]="['/edit-alias']" tooltip="{{ 'WALLET.TOOLTIPS.EDIT_ALIAS' | translate }}" placement="bottom-right" tooltipClass="table-tooltip account-tooltip" [delay]="500" [timeDelay]="500"></i>
<i class="icon transfer" [routerLink]="['/transfer-alias']" tooltip="{{ 'WALLET.TOOLTIPS.TRANSFER_ALIAS' | translate }}" placement="right" tooltipClass="table-tooltip account-tooltip" [delay]="500" [timeDelay]="500"></i>
</ng-container>
</div>
</div>
<div>
<button [routerLink]="['/details']" routerLinkActive="active">
<button [routerLink]="['/details']" routerLinkActive="active" tooltip="{{ 'WALLET.TOOLTIPS.SETTINGS' | translate }}" placement="left" tooltipClass="table-tooltip account-tooltip" [delay]="500" [timeDelay]="500">
<i class="icon details"></i>
</button>
<button type="button" (click)="closeWallet()">
<button type="button" (click)="showDialog()" tooltip="{{ 'WALLET.TOOLTIPS.CLOSE' | translate }}" placement="bottom-right" tooltipClass="table-tooltip account-tooltip" [delay]="500" [timeDelay]="500">
<i class="icon close-wallet"></i>
</button>
</div>
@ -48,3 +48,4 @@
</div>
</div>
<app-confirm-modal *ngIf="isModalDialogVisible" [title]=" 'WALLET.CONFIRM.TITLE' | translate " [message]=" 'WALLET.CONFIRM.MESSAGE' | translate " (confirmed)="confirmed($event)"></app-confirm-modal>

View file

@ -50,6 +50,7 @@
height: 1.7rem;
&.account {
height: 1.6rem;
mask: url(../../assets/icons/account.svg) no-repeat center;
}
@ -60,6 +61,7 @@
&.details {
mask: url(../../assets/icons/details-settings.svg) no-repeat center;
margin-right: 0;
height: 1.8rem;
}
&.close-wallet {
@ -105,6 +107,7 @@
height: 1.7rem;
&.copy {
width: 1.8rem;
mask: url(../../assets/icons/copy.svg) no-repeat center;
&:hover {

View file

@ -21,6 +21,7 @@ export class WalletComponent implements OnInit, OnDestroy {
copyAnimation = false;
copyAnimationTimeout;
balanceTooltip;
isModalDialogVisible = false;
@ViewChild('scrolledContent') private scrolledContent: ElementRef;
@ -182,6 +183,17 @@ export class WalletComponent implements OnInit, OnDestroy {
this.backend.openUrlInBrowser(link);
}
showDialog() {
this.isModalDialogVisible = true;
}
confirmed(confirmed: boolean) {
if (confirmed) {
this.closeWallet();
}
this.isModalDialogVisible = false;
}
closeWallet() {
this.backend.closeWallet(this.variablesService.currentWallet.wallet_id, () => {
for (let i = this.variablesService.wallets.length - 1; i >= 0; i--) {

View file

@ -46,7 +46,7 @@
"ONLINE": "Online",
"ERROR": "Systemfehler",
"COMPLETE": "Abschluss",
"SYNCING": "Synchronisiere Blockchain",
"SYNCING": "Syncing block",
"LOADING": "Lade Blockchain-Daten"
},
"UPDATE": {

View file

@ -150,16 +150,30 @@
"TIME3": "1 hour",
"TIME4": "Never"
},
"SCALE": {
"75": "75% scale",
"100": "100% scale",
"125": "125% scale",
"150": "150% scale"
},
"LANGUAGE": {
"TITLE": "Language",
"EN": "English",
"FR": "French",
"DE": "Deutsch",
"IT": "Italian",
"PT": "Portuguese"
},
"MASTER_PASSWORD": {
"TITLE": "Update master password",
"OLD": "Old password",
"OLD": "Current password",
"NEW": "New password",
"CONFIRM": "New password confirmation",
"BUTTON": "Save"
},
"FORM_ERRORS": {
"PASS_REQUIRED": "Password is required",
"PASS_NOT_MATCH": "Old password not match",
"PASS_NOT_MATCH": "Incorrect password",
"CONFIRM_NOT_MATCH": "Confirm password not match"
},
"LAST_BUILD": "Current build: {{value}}",
@ -172,6 +186,10 @@
"AVAILABLE_BALANCE": "Available <b>{{available}} {{currency}}<b/>",
"LOCKED_BALANCE": "Locked <b>{{locked}} {{currency}}<b/>",
"LOCKED_BALANCE_LINK": "What does that mean?",
"CONFIRM": {
"TITLE": "Remove wallet from the list?",
"MESSAGE": "To access it youll have to add it again"
},
"TABS": {
"SEND": "Send",
"RECEIVE": "Receive",
@ -179,6 +197,12 @@
"CONTRACTS": "Contracts",
"MESSAGES": "Messages",
"STAKING": "Staking"
},
"TOOLTIPS": {
"EDIT_ALIAS": "Edit alias",
"TRANSFER_ALIAS": "Transfer alias",
"SETTINGS": "Settings",
"CLOSE": "Close wallet"
}
},
"WALLET_DETAILS": {
@ -453,7 +477,8 @@
"ERROR": "Error",
"SUCCESS": "Success",
"INFO": "Information",
"OK": "OK"
"OK": "OK",
"CANCEL": "Cancel"
},
"CONFIRM": {
"BUTTON_CONFIRM": "Send",

View file

@ -46,7 +46,7 @@
"ONLINE": "En ligne",
"ERROR": "Erreur de système",
"COMPLETE": "Fermeture",
"SYNCING": "Synchronisation de la blockchain",
"SYNCING": "Syncing block",
"LOADING": "Chargement des données de la blockchain"
},
"UPDATE": {

View file

@ -46,7 +46,7 @@
"ONLINE": "Online",
"ERROR": "Errore di sistema",
"COMPLETE": "Completata",
"SYNCING": "Sincronizzazione blockchain",
"SYNCING": "Syncing block",
"LOADING": "Caricamento dati blockchain"
},
"UPDATE": {

File diff suppressed because it is too large Load diff

View file

@ -789,6 +789,16 @@ input[type='checkbox'].style-checkbox {
&.custom-select {
width: 100%;
&.ng-select-single {
.ng-select-container {
.ng-value-container {
.ng-value {
line-height: 1.8rem;
}
}
}
}
.ng-select-container {
border: none;
border-radius: 0;
@ -873,7 +883,7 @@ input[type='checkbox'].style-checkbox {
}
}
app-modal-container {
app-modal-container, app-confirm-modal {
.modal {

View file

@ -483,6 +483,12 @@ namespace nodetool
return;
}
if (!tools::check_remote_client_version(rsp.payload_data.client_version))
{
LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE Failed, wrong client version: " << rsp.payload_data.client_version << ", closing connection.");
return;
}
if(!handle_maintainers_entry(rsp.maintrs_entry))
{
LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE Failed, wrong maintainers entry!, closing connection.");
@ -1304,6 +1310,14 @@ namespace nodetool
return 1;
}
if (!tools::check_remote_client_version(arg.payload_data.client_version))
{
LOG_PRINT_CCONTEXT_L2("COMMAND_HANDSHAKE: wrong client version: " << arg.payload_data.client_version << ", closing connection.");
drop_connection(context);
add_ip_fail(context.m_remote_ip);
return 1;
}
if(!handle_maintainers_entry(arg.maintrs_entry))
{
LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE Failed, wrong maintainers entry!, closing connection.");

View file

@ -450,12 +450,12 @@ namespace currency
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
// bool core_rpc_server::on_rpc_get_all_offers(const COMMAND_RPC_GET_ALL_OFFERS::request& req, COMMAND_RPC_GET_ALL_OFFERS::response& res, connection_context& cntx)
// {
// m_core.get_blockchain_storage().get_all_offers(res.offers);
// res.status = CORE_RPC_STATUS_OK;
// return true;
// }
bool core_rpc_server::on_get_offers_ex(const COMMAND_RPC_GET_OFFERS_EX::request& req, COMMAND_RPC_GET_OFFERS_EX::response& res, epee::json_rpc::error& error_resp, connection_context& cntx)
{
m_of.get_offers_ex(req.filter, res.offers, res.total_offers, m_core.get_blockchain_storage().get_core_runtime_config().get_core_time());
res.status = CORE_RPC_STATUS_OK;
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_pos_mining_details(const COMMAND_RPC_GET_POS_MINING_DETAILS::request& req, COMMAND_RPC_GET_POS_MINING_DETAILS::response& res, connection_context& cntx)
{

View file

@ -55,7 +55,7 @@ namespace currency
bool on_scan_pos(const COMMAND_RPC_SCAN_POS::request& req, COMMAND_RPC_SCAN_POS::response& res, connection_context& cntx);
bool on_rpc_get_blocks_details(const COMMAND_RPC_GET_BLOCKS_DETAILS::request& req, COMMAND_RPC_GET_BLOCKS_DETAILS::response& res, connection_context& cntx);
bool on_force_relaey_raw_txs(const COMMAND_RPC_FORCE_RELAY_RAW_TXS::request& req, COMMAND_RPC_FORCE_RELAY_RAW_TXS::response& res, connection_context& cntx);
//bool on_rpc_get_all_offers(const COMMAND_RPC_GET_ALL_OFFERS::request& req, COMMAND_RPC_GET_ALL_OFFERS::response& res, connection_context& cntx);
bool on_get_offers_ex(const COMMAND_RPC_GET_OFFERS_EX::request& req, COMMAND_RPC_GET_OFFERS_EX::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
//json_rpc
@ -151,6 +151,9 @@ namespace currency
//
MAP_JON_RPC ("reset_transaction_pool", on_reset_transaction_pool, COMMAND_RPC_RESET_TX_POOL)
MAP_JON_RPC ("get_current_core_tx_expiration_median", on_get_current_core_tx_expiration_median, COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN)
//
MAP_JON_RPC_WE("marketplace_global_get_offers_ex", on_get_offers_ex, COMMAND_RPC_GET_OFFERS_EX)
//remote miner rpc
MAP_JON_RPC_N(on_login, mining::COMMAND_RPC_LOGIN)
MAP_JON_RPC_N(on_getjob, mining::COMMAND_RPC_GETJOB)

View file

@ -14,7 +14,6 @@
#include "storages/portable_storage_base.h"
#include "currency_core/offers_service_basics.h"
#include "currency_core/basic_api_response_codes.h"
namespace currency
{
//-----------------------------------------------
@ -1505,12 +1504,13 @@ namespace currency
};
struct COMMAND_RPC_GET_ALL_OFFERS
struct COMMAND_RPC_GET_OFFERS_EX
{
struct request
{
bc_services::core_offers_filter filter;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(filter)
END_KV_SERIALIZE_MAP()
};

View file

@ -678,7 +678,7 @@ bool simple_wallet::show_balance(const std::vector<std::string>& args/* = std::v
return true;
}
//----------------------------------------------------------------------------------------------------
bool print_wti(const tools::wallet_rpc::wallet_transfer_info& wti)
bool print_wti(const tools::wallet_public::wallet_transfer_info& wti)
{
epee::log_space::console_colors cl;
if (wti.is_income)
@ -713,8 +713,8 @@ bool print_wti(const tools::wallet_rpc::wallet_transfer_info& wti)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::list_recent_transfers(const std::vector<std::string>& args)
{
std::vector<tools::wallet_rpc::wallet_transfer_info> unconfirmed;
std::vector<tools::wallet_rpc::wallet_transfer_info> recent;
std::vector<tools::wallet_public::wallet_transfer_info> unconfirmed;
std::vector<tools::wallet_public::wallet_transfer_info> recent;
m_wallet->get_recent_transfers_history(recent, 0, 0);
m_wallet->get_unconfirmed_transfers(unconfirmed);
//workaround for missed fee
@ -738,8 +738,8 @@ bool simple_wallet::list_recent_transfers(const std::vector<std::string>& args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::list_recent_transfers_ex(const std::vector<std::string>& args)
{
std::vector<tools::wallet_rpc::wallet_transfer_info> unconfirmed;
std::vector<tools::wallet_rpc::wallet_transfer_info> recent;
std::vector<tools::wallet_public::wallet_transfer_info> unconfirmed;
std::vector<tools::wallet_public::wallet_transfer_info> recent;
m_wallet->get_recent_transfers_history(recent, 0, 0);
m_wallet->get_unconfirmed_transfers(unconfirmed);
//workaround for missed fee

View file

@ -1,12 +1,13 @@
#pragma once
#include "misc_language.h"
#define BUILD_COMMIT_ID "@VERSION@"
#define PROJECT_MAJOR_VERSION "1"
#define PROJECT_MINOR_VERSION "1"
#define PROJECT_REVISION "0"
#define PROJECT_REVISION "2"
#define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION
#define PROJECT_VERSION_BUILD_NO 62
#define PROJECT_VERSION_BUILD_NO 67
#define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO)
#define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]"

View file

@ -38,7 +38,7 @@ namespace tools
virtual bool call_COMMAND_RPC_SUBMITBLOCK(const currency::COMMAND_RPC_SUBMITBLOCK::request& req, currency::COMMAND_RPC_SUBMITBLOCK::response& rsp){ return false; }
virtual bool call_COMMAND_RPC_GET_POS_MINING_DETAILS(const currency::COMMAND_RPC_GET_POS_MINING_DETAILS::request& req, currency::COMMAND_RPC_GET_POS_MINING_DETAILS::response& rsp){ return false; }
virtual bool call_COMMAND_RPC_GET_BLOCKS_DETAILS(const currency::COMMAND_RPC_GET_BLOCKS_DETAILS::request& req, currency::COMMAND_RPC_GET_BLOCKS_DETAILS::response& res){ return false; }
virtual bool call_COMMAND_RPC_GET_ALL_OFFERS(const currency::COMMAND_RPC_GET_ALL_OFFERS::request& req, currency::COMMAND_RPC_GET_ALL_OFFERS::response& res){ return false; }
virtual bool call_COMMAND_RPC_GET_OFFERS_EX(const currency::COMMAND_RPC_GET_OFFERS_EX::request& req, currency::COMMAND_RPC_GET_OFFERS_EX::response& res){ return false; }
virtual bool call_COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN(const currency::COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN::request& req, currency::COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN::response& res){ return false; }
virtual bool call_COMMAND_RPC_GET_POOL_INFO(const currency::COMMAND_RPC_GET_POOL_INFO::request& req, currency::COMMAND_RPC_GET_POOL_INFO::response& res) { return false; }

View file

@ -28,6 +28,8 @@ using namespace epee;
#include "version.h"
using namespace currency;
#define MINIMUM_REQUIRED_WALLET_FREE_SPACE_BYTES (100*1024*1024) // 100 MB
#undef LOG_DEFAULT_CHANNEL
#define LOG_DEFAULT_CHANNEL "wallet"
ENABLE_CHANNEL_BY_DEFAULT("wallet")
@ -63,7 +65,7 @@ namespace tools
return max_unlock_time;
}
//----------------------------------------------------------------------------------------------------
void wallet2::fill_transfer_details(const currency::transaction& tx, const tools::money_transfer2_details& td, tools::wallet_rpc::wallet_transfer_info_details& res_td) const
void wallet2::fill_transfer_details(const currency::transaction& tx, const tools::money_transfer2_details& td, tools::wallet_public::wallet_transfer_info_details& res_td) const
{
PROFILE_FUNC("wallet2::fill_transfer_details");
for (auto si : td.spent_indices)
@ -459,7 +461,7 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t
}
}
//----------------------------------------------------------------------------------------------------
void wallet2::prepare_wti_decrypted_attachments(wallet_rpc::wallet_transfer_info& wti, const std::vector<currency::payload_items_v>& decrypted_att)
void wallet2::prepare_wti_decrypted_attachments(wallet_public::wallet_transfer_info& wti, const std::vector<currency::payload_items_v>& decrypted_att)
{
PROFILE_FUNC("wallet2::prepare_wti_decrypted_attachments");
tx_payer tp = AUTO_VAL_INIT(tp);
@ -511,7 +513,7 @@ void wallet2::accept_proposal(const crypto::hash& contract_id, uint64_t b_accept
THROW_IF_FALSE_WALLET_INT_ERR_EX(contr_it != m_contracts.end(), "Unknow contract id: " << contract_id);
THROW_IF_FALSE_WALLET_INT_ERR_EX(!contr_it->second.is_a, "contr_it->second.is_a supposed to be false, but it is " << contr_it->second.is_a);
THROW_IF_FALSE_WALLET_INT_ERR_EX(contr_it->second.state == tools::wallet_rpc::escrow_contract_details_basic::proposal_sent, "contr_it->second.state supposed to be proposal_sent(" << tools::wallet_rpc::escrow_contract_details_basic::proposal_sent << ") but it is: " << tools::wallet_rpc::get_escrow_contract_state_name(contr_it->second.state));
THROW_IF_FALSE_WALLET_INT_ERR_EX(contr_it->second.state == tools::wallet_public::escrow_contract_details_basic::proposal_sent, "contr_it->second.state supposed to be proposal_sent(" << tools::wallet_public::escrow_contract_details_basic::proposal_sent << ") but it is: " << tools::wallet_public::get_escrow_contract_state_name(contr_it->second.state));
construct_tx_param construct_param = AUTO_VAL_INIT(construct_param);
construct_param.fee = b_acceptance_fee;
@ -585,10 +587,10 @@ void wallet2::finish_contract(const crypto::hash& contract_id, const std::string
THROW_IF_FALSE_WALLET_INT_ERR_EX(contr_it != m_contracts.end(), "Unknow contract id: " << contract_id);
THROW_IF_FALSE_WALLET_INT_ERR_EX(contr_it->second.is_a, "contr_it->second.is_a is supposed to be true, but it is " << contr_it->second.is_a);
THROW_IF_FALSE_WALLET_INT_ERR_EX(contr_it->second.state == tools::wallet_rpc::escrow_contract_details_basic::contract_accepted
|| contr_it->second.state == tools::wallet_rpc::escrow_contract_details_basic::contract_cancel_proposal_sent,
"incorrect contract state at finish_contract(): (" << contr_it->second.state << "), expected states: contract_accepted (" << tools::wallet_rpc::escrow_contract_details_basic::contract_accepted << "), " <<
"contract_cancel_proposal_sent (" << tools::wallet_rpc::escrow_contract_details_basic::contract_cancel_proposal_sent << ")");
THROW_IF_FALSE_WALLET_INT_ERR_EX(contr_it->second.state == tools::wallet_public::escrow_contract_details_basic::contract_accepted
|| contr_it->second.state == tools::wallet_public::escrow_contract_details_basic::contract_cancel_proposal_sent,
"incorrect contract state at finish_contract(): (" << contr_it->second.state << "), expected states: contract_accepted (" << tools::wallet_public::escrow_contract_details_basic::contract_accepted << "), " <<
"contract_cancel_proposal_sent (" << tools::wallet_public::escrow_contract_details_basic::contract_cancel_proposal_sent << ")");
auto multisig_it = m_multisig_transfers.find(contract_id);
THROW_IF_FALSE_WALLET_INT_ERR_EX(multisig_it != m_multisig_transfers.end(), "Unknow multisig id: " << contract_id);
@ -627,8 +629,8 @@ void wallet2::accept_cancel_contract(const crypto::hash& contract_id, currency::
TIME_MEASURE_FINISH_MS(timing1);
THROW_IF_FALSE_WALLET_INT_ERR_EX(!contr_it->second.is_a, "contr_it->second.is_a is supposed to be false, but it is " << contr_it->second.is_a);
THROW_IF_FALSE_WALLET_INT_ERR_EX(contr_it->second.state == tools::wallet_rpc::escrow_contract_details_basic::contract_cancel_proposal_sent,
"incorrect contract state: (" << contr_it->second.state << "), expected state: contract_cancel_proposal_sent (" << tools::wallet_rpc::escrow_contract_details_basic::contract_cancel_proposal_sent << ")");
THROW_IF_FALSE_WALLET_INT_ERR_EX(contr_it->second.state == tools::wallet_public::escrow_contract_details_basic::contract_cancel_proposal_sent,
"incorrect contract state: (" << contr_it->second.state << "), expected state: contract_cancel_proposal_sent (" << tools::wallet_public::escrow_contract_details_basic::contract_cancel_proposal_sent << ")");
TIME_MEASURE_START_MS(timing2);
auto multisig_it = m_multisig_transfers.find(contract_id);
@ -659,10 +661,10 @@ void wallet2::request_cancel_contract(const crypto::hash& contract_id, uint64_t
THROW_IF_FALSE_WALLET_INT_ERR_EX(contr_it != m_contracts.end(), "Unknow contract id: " << contract_id);
THROW_IF_FALSE_WALLET_INT_ERR_EX(contr_it->second.is_a, "contr_it->second.is_a supposed to be true at request_cancel_contract");
THROW_IF_FALSE_WALLET_INT_ERR_EX(contr_it->second.state == tools::wallet_rpc::escrow_contract_details_basic::contract_accepted
|| contr_it->second.state == tools::wallet_rpc::escrow_contract_details_basic::contract_cancel_proposal_sent,
"incorrect contract state at request_cancel_contract(): " << tools::wallet_rpc::get_escrow_contract_state_name(contr_it->second.state) << ", expected states: contract_accepted (" << tools::wallet_rpc::escrow_contract_details_basic::contract_accepted << "), " <<
"contract_cancel_proposal_sent (" << tools::wallet_rpc::escrow_contract_details_basic::contract_cancel_proposal_sent << ")");
THROW_IF_FALSE_WALLET_INT_ERR_EX(contr_it->second.state == tools::wallet_public::escrow_contract_details_basic::contract_accepted
|| contr_it->second.state == tools::wallet_public::escrow_contract_details_basic::contract_cancel_proposal_sent,
"incorrect contract state at request_cancel_contract(): " << tools::wallet_public::get_escrow_contract_state_name(contr_it->second.state) << ", expected states: contract_accepted (" << tools::wallet_public::escrow_contract_details_basic::contract_accepted << "), " <<
"contract_cancel_proposal_sent (" << tools::wallet_public::escrow_contract_details_basic::contract_cancel_proposal_sent << ")");
auto multisig_it = m_multisig_transfers.find(contract_id);
THROW_IF_FALSE_WALLET_INT_ERR_EX(multisig_it != m_multisig_transfers.end(), "Unknow multisig id: " << contract_id);
@ -716,24 +718,24 @@ void wallet2::scan_tx_to_key_inputs(std::vector<uint64_t>& found_transfers, cons
}
}
//-----------------------------------------------------------------------------------------------------
void wallet2::change_contract_state(wallet_rpc::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const wallet_rpc::wallet_transfer_info& wti) const
void wallet2::change_contract_state(wallet_public::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const wallet_public::wallet_transfer_info& wti) const
{
WLT_LOG_YELLOW("escrow contract STATE CHANGE (" << (contract.is_a ? "A," : "B,") << contract_id << " via tx " << get_transaction_hash(wti.tx) << ", height: " << wti.height << ") : "
<< wallet_rpc::get_escrow_contract_state_name(contract.state) << " -> " << wallet_rpc::get_escrow_contract_state_name(new_state), LOG_LEVEL_1);
<< wallet_public::get_escrow_contract_state_name(contract.state) << " -> " << wallet_public::get_escrow_contract_state_name(new_state), LOG_LEVEL_1);
contract.state = new_state;
contract.height = wti.height; // update height of last state change
}
//-----------------------------------------------------------------------------------------------------
void wallet2::change_contract_state(wallet_rpc::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const std::string& reason /*= "internal intention"*/) const
void wallet2::change_contract_state(wallet_public::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const std::string& reason /*= "internal intention"*/) const
{
WLT_LOG_YELLOW("escrow contract STATE CHANGE (" << (contract.is_a ? "A," : "B,") << contract_id << " " << reason << ") : "
<< wallet_rpc::get_escrow_contract_state_name(contract.state) << " -> " << wallet_rpc::get_escrow_contract_state_name(new_state), LOG_LEVEL_1);
<< wallet_public::get_escrow_contract_state_name(contract.state) << " -> " << wallet_public::get_escrow_contract_state_name(new_state), LOG_LEVEL_1);
contract.state = new_state;
}
//-----------------------------------------------------------------------------------------------------
bool wallet2::handle_proposal(wallet_rpc::wallet_transfer_info& wti, const bc_services::proposal_body& prop)
bool wallet2::handle_proposal(wallet_public::wallet_transfer_info& wti, const bc_services::proposal_body& prop)
{
PROFILE_FUNC("wallet2::handle_proposal");
crypto::hash ms_id = AUTO_VAL_INIT(ms_id);
@ -742,17 +744,17 @@ bool wallet2::handle_proposal(wallet_rpc::wallet_transfer_info& wti, const bc_se
if (!validate_escrow_proposal(wti, prop, decrypted_items, ms_id, cpd))
return false;
wallet_rpc::escrow_contract_details_basic& ed = epee::misc_utils::get_or_insert_value_initialized(m_contracts, ms_id);
wallet_public::escrow_contract_details_basic& ed = epee::misc_utils::get_or_insert_value_initialized(m_contracts, ms_id);
ed.expiration_time = currency::get_tx_expiration_time(prop.tx_template);
ed.timestamp = wti.timestamp;
ed.is_a = cpd.a_addr.m_spend_public_key == m_account.get_keys().m_account_address.m_spend_public_key;
change_contract_state(ed, wallet_rpc::escrow_contract_details_basic::proposal_sent, ms_id, wti);
change_contract_state(ed, wallet_public::escrow_contract_details_basic::proposal_sent, ms_id, wti);
ed.private_detailes = cpd;
currency::get_payment_id_from_tx(decrypted_items, ed.payment_id);
ed.proposal = prop;
ed.height = wti.height;
wti.contract.resize(1);
static_cast<wallet_rpc::escrow_contract_details_basic&>(wti.contract.back()) = ed;
static_cast<wallet_public::escrow_contract_details_basic&>(wti.contract.back()) = ed;
wti.contract.back().contract_id = ms_id;
//correct fee in case if it "B", cz fee is paid by "A"
@ -778,7 +780,7 @@ bool wallet2::handle_proposal(wallet_rpc::wallet_transfer_info& wti, const bc_se
return true;
}
//-----------------------------------------------------------------------------------------------------
bool wallet2::handle_release_contract(wallet_rpc::wallet_transfer_info& wti, const std::string& release_instruction)
bool wallet2::handle_release_contract(wallet_public::wallet_transfer_info& wti, const std::string& release_instruction)
{
PROFILE_FUNC("wallet2::handle_release_contract");
size_t n = get_multisig_in_index(wti.tx.vin);
@ -789,12 +791,12 @@ bool wallet2::handle_release_contract(wallet_rpc::wallet_transfer_info& wti, con
WLT_CHECK_AND_ASSERT_MES(it != m_contracts.end(), false, "Multisig out not found in tx template in proposal");
if (release_instruction == BC_ESCROW_SERVICE_INSTRUCTION_RELEASE_NORMAL)
change_contract_state(it->second, wallet_rpc::escrow_contract_details_basic::contract_released_normal, ms_id, wti);
change_contract_state(it->second, wallet_public::escrow_contract_details_basic::contract_released_normal, ms_id, wti);
else if (release_instruction == BC_ESCROW_SERVICE_INSTRUCTION_RELEASE_CANCEL)
change_contract_state(it->second, wallet_rpc::escrow_contract_details_basic::contract_released_cancelled, ms_id, wti);
change_contract_state(it->second, wallet_public::escrow_contract_details_basic::contract_released_cancelled, ms_id, wti);
else if (release_instruction == BC_ESCROW_SERVICE_INSTRUCTION_RELEASE_BURN)
{
change_contract_state(it->second, wallet_rpc::escrow_contract_details_basic::contract_released_burned, ms_id, wti);
change_contract_state(it->second, wallet_public::escrow_contract_details_basic::contract_released_burned, ms_id, wti);
wti.amount = it->second.private_detailes.amount_to_pay + it->second.private_detailes.amount_a_pledge + it->second.private_detailes.amount_b_pledge;
if (!it->second.is_a)
{
@ -812,7 +814,7 @@ bool wallet2::handle_release_contract(wallet_rpc::wallet_transfer_info& wti, con
}
wti.contract.resize(1);
static_cast<wallet_rpc::escrow_contract_details_basic&>(wti.contract.back()) = it->second;
static_cast<wallet_public::escrow_contract_details_basic&>(wti.contract.back()) = it->second;
wti.contract.back().contract_id = ms_id;
//if it's A(buyer) then fee paid by B(seller)
@ -824,7 +826,7 @@ bool wallet2::handle_release_contract(wallet_rpc::wallet_transfer_info& wti, con
}
//-----------------------------------------------------------------------------------------------------
bool wallet2::handle_contract(wallet_rpc::wallet_transfer_info& wti, const bc_services::contract_private_details& cntr, const std::vector<currency::payload_items_v>& decrypted_attach)
bool wallet2::handle_contract(wallet_public::wallet_transfer_info& wti, const bc_services::contract_private_details& cntr, const std::vector<currency::payload_items_v>& decrypted_attach)
{
PROFILE_FUNC("wallet2::handle_contract");
bool is_a = cntr.a_addr == m_account.get_public_address();
@ -833,19 +835,19 @@ bool wallet2::handle_contract(wallet_rpc::wallet_transfer_info& wti, const bc_se
if (!validate_escrow_contract(wti, cntr, is_a, decrypted_attach, ms_id, rel))
return false;
wallet_rpc::escrow_contract_details_basic& ed = epee::misc_utils::get_or_insert_value_initialized(m_contracts, ms_id);
wallet_public::escrow_contract_details_basic& ed = epee::misc_utils::get_or_insert_value_initialized(m_contracts, ms_id);
ed.is_a = is_a;
ed.expiration_time = currency::get_tx_expiration_time(wti.tx);
if (wti.timestamp)
ed.timestamp = wti.timestamp;
ed.height = wti.height;
ed.payment_id = wti.payment_id;
change_contract_state(ed, wallet_rpc::escrow_contract_details_basic::contract_accepted, ms_id, wti);
change_contract_state(ed, wallet_public::escrow_contract_details_basic::contract_accepted, ms_id, wti);
ed.private_detailes = cntr;
ed.release_body = rel;
wti.contract.resize(1);
static_cast<wallet_rpc::escrow_contract_details_basic&>(wti.contract.back()) = ed;
static_cast<wallet_public::escrow_contract_details_basic&>(wti.contract.back()) = ed;
wti.contract.back().contract_id = ms_id;
//fee workaround: in consolidating transactions impossible no figure out which part of participants paid fee for tx, so we correct it
@ -860,7 +862,7 @@ bool wallet2::handle_contract(wallet_rpc::wallet_transfer_info& wti, const bc_se
return true;
}
//-----------------------------------------------------------------------------------------------------
bool wallet2::handle_cancel_proposal(wallet_rpc::wallet_transfer_info& wti, const bc_services::escrow_cancel_templates_body& ectb, const std::vector<currency::payload_items_v>& decrypted_attach)
bool wallet2::handle_cancel_proposal(wallet_public::wallet_transfer_info& wti, const bc_services::escrow_cancel_templates_body& ectb, const std::vector<currency::payload_items_v>& decrypted_attach)
{
PROFILE_FUNC("wallet2::handle_cancel_proposal");
//validate cancel proposal
@ -875,26 +877,26 @@ bool wallet2::handle_cancel_proposal(wallet_rpc::wallet_transfer_info& wti, cons
uint32_t contract_state = it->second.state;
switch (contract_state)
{
case wallet_rpc::escrow_contract_details::contract_accepted:
change_contract_state(it->second, wallet_rpc::escrow_contract_details_basic::contract_cancel_proposal_sent, contract_id, wti); BOOST_FALLTHROUGH;
case wallet_public::escrow_contract_details::contract_accepted:
change_contract_state(it->second, wallet_public::escrow_contract_details_basic::contract_cancel_proposal_sent, contract_id, wti); BOOST_FALLTHROUGH;
// pass through
case wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent: // update contract info even if already in that state
case wallet_public::escrow_contract_details::contract_cancel_proposal_sent: // update contract info even if already in that state
it->second.cancel_body.tx_cancel_template = ectb.tx_cancel_template;
it->second.cancel_expiration_time = currency::get_tx_expiration_time(ectb.tx_cancel_template);
//update wti info to let GUI know
wti.contract.resize(1);
static_cast<wallet_rpc::escrow_contract_details_basic&>(wti.contract.back()) = it->second;
static_cast<wallet_public::escrow_contract_details_basic&>(wti.contract.back()) = it->second;
wti.contract.back().contract_id = contract_id;
return true;
default:
WLT_LOG_RED("handle_cancel_proposal for contract (" << (it->second.is_a ? "A," : "B,") << contract_id << " via tx " << get_transaction_hash(wti.tx) << ", height: " << wti.height << ") : " << ENDL <<
"incorrect state " << wallet_rpc::get_escrow_contract_state_name(it->second.state) << ", while 'contract_accepted' or 'contract_cancel_proposal_sent' was expected -- decline cancel proposal", LOG_LEVEL_1);
"incorrect state " << wallet_public::get_escrow_contract_state_name(it->second.state) << ", while 'contract_accepted' or 'contract_cancel_proposal_sent' was expected -- decline cancel proposal", LOG_LEVEL_1);
}
return false;
}
//-----------------------------------------------------------------------------------------------------
bool wallet2::process_contract_info(wallet_rpc::wallet_transfer_info& wti, const std::vector<currency::payload_items_v>& decrypted_attach)
bool wallet2::process_contract_info(wallet_public::wallet_transfer_info& wti, const std::vector<currency::payload_items_v>& decrypted_attach)
{
PROFILE_FUNC("wallet2::process_contract_info");
for (const auto& v : decrypted_attach)
@ -953,7 +955,7 @@ bool wallet2::process_contract_info(wallet_rpc::wallet_transfer_info& wti, const
return true;
}
//-----------------------------------------------------------------------------------------------------
void wallet2::prepare_wti(wallet_rpc::wallet_transfer_info& wti, uint64_t height, uint64_t timestamp, const currency::transaction& tx, uint64_t amount, const money_transfer2_details& td)
void wallet2::prepare_wti(wallet_public::wallet_transfer_info& wti, uint64_t height, uint64_t timestamp, const currency::transaction& tx, uint64_t amount, const money_transfer2_details& td)
{
PROFILE_FUNC("wallet2::prepare_wti");
wti.tx = tx;
@ -991,15 +993,15 @@ void wallet2::prepare_wti(wallet_rpc::wallet_transfer_info& wti, uint64_t height
void wallet2::handle_money_received2(const currency::block& b, const currency::transaction& tx, uint64_t amount, const money_transfer2_details& td)
{
//decrypt attachments
m_transfer_history.push_back(AUTO_VAL_INIT(wallet_rpc::wallet_transfer_info()));
wallet_rpc::wallet_transfer_info& wti = m_transfer_history.back();
m_transfer_history.push_back(AUTO_VAL_INIT(wallet_public::wallet_transfer_info()));
wallet_public::wallet_transfer_info& wti = m_transfer_history.back();
wti.is_income = true;
prepare_wti(wti, get_block_height(b), get_actual_timestamp(b), tx, amount, td);
rise_on_transfer2(wti);
}
//----------------------------------------------------------------------------------------------------
void wallet2::rise_on_transfer2(const wallet_rpc::wallet_transfer_info& wti)
void wallet2::rise_on_transfer2(const wallet_public::wallet_transfer_info& wti)
{
PROFILE_FUNC("wallet2::rise_on_transfer2");
if (!m_do_rise_transfer)
@ -1018,8 +1020,8 @@ void wallet2::handle_money_spent2(const currency::block& b,
const std::vector<std::string>& recipients,
const std::vector<std::string>& recipients_aliases)
{
m_transfer_history.push_back(AUTO_VAL_INIT(wallet_rpc::wallet_transfer_info()));
wallet_rpc::wallet_transfer_info& wti = m_transfer_history.back();
m_transfer_history.push_back(AUTO_VAL_INIT(wallet_public::wallet_transfer_info()));
wallet_public::wallet_transfer_info& wti = m_transfer_history.back();
wti.is_income = false;
wti.remote_addresses = recipients;
@ -1033,7 +1035,7 @@ void wallet2::process_unconfirmed(const currency::transaction& tx, std::vector<s
auto unconf_it = m_unconfirmed_txs.find(get_transaction_hash(tx));
if (unconf_it != m_unconfirmed_txs.end())
{
wallet_rpc::wallet_transfer_info& wti = unconf_it->second;
wallet_public::wallet_transfer_info& wti = unconf_it->second;
recipients = wti.remote_addresses;
recipients_aliases = wti.recipients_aliases;
@ -1406,7 +1408,7 @@ void wallet2::scan_tx_pool(bool& has_related_alias_in_unconfirmed)
continue;
//prepare notification about pending transaction
wallet_rpc::wallet_transfer_info& unconfirmed_wti = misc_utils::get_or_insert_value_initialized(m_unconfirmed_txs, tx_hash);
wallet_public::wallet_transfer_info& unconfirmed_wti = misc_utils::get_or_insert_value_initialized(m_unconfirmed_txs, tx_hash);
unconfirmed_wti.is_income = true;
prepare_wti(unconfirmed_wti, 0, m_core_runtime_config.get_core_time(), tx, tx_money_got_in_outs, td);
@ -1434,7 +1436,7 @@ void wallet2::scan_tx_pool(bool& has_related_alias_in_unconfirmed)
}
//prepare notification about pending transaction
wallet_rpc::wallet_transfer_info& unconfirmed_wti = misc_utils::get_or_insert_value_initialized(m_unconfirmed_txs, tx_hash);
wallet_public::wallet_transfer_info& unconfirmed_wti = misc_utils::get_or_insert_value_initialized(m_unconfirmed_txs, tx_hash);
unconfirmed_wti.is_income = false;
prepare_wti(unconfirmed_wti, 0, m_core_runtime_config.get_core_time(), tx, amount, td);
@ -1661,13 +1663,13 @@ void wallet2::handle_contract_expirations(uint64_t tx_expiration_ts_median)
{
switch (contract.second.state)
{
case tools::wallet_rpc::escrow_contract_details_basic::contract_cancel_proposal_sent:
case tools::wallet_public::escrow_contract_details_basic::contract_cancel_proposal_sent:
if (is_tx_expired(contract.second.cancel_body.tx_cancel_template, tx_expiration_ts_median))
change_contract_state(contract.second, tools::wallet_rpc::escrow_contract_details_basic::contract_accepted, contract.first, "cancel proposal expiration");
change_contract_state(contract.second, tools::wallet_public::escrow_contract_details_basic::contract_accepted, contract.first, "cancel proposal expiration");
break;
case tools::wallet_rpc::escrow_contract_details_basic::contract_released_cancelled:
case tools::wallet_public::escrow_contract_details_basic::contract_released_cancelled:
if (contract.second.height == 0 && is_tx_expired(contract.second.cancel_body.tx_cancel_template, tx_expiration_ts_median))
change_contract_state(contract.second, tools::wallet_rpc::escrow_contract_details_basic::contract_accepted, contract.first, "cancel acceptance expiration");
change_contract_state(contract.second, tools::wallet_public::escrow_contract_details_basic::contract_accepted, contract.first, "cancel acceptance expiration");
break;
}
}
@ -1962,8 +1964,12 @@ void wallet2::assign_account(const currency::account_base& acc)
//----------------------------------------------------------------------------------------------------
void wallet2::generate(const std::wstring& path, const std::string& pass)
{
WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(validate_password(pass), "new wallet generation failed: password contains forbidden characters")
clear();
prepare_file_names(path);
check_for_free_space_and_throw_if_it_lacks(m_wallet_file);
m_password = pass;
m_account.generate();
init_log_prefix();
@ -1999,6 +2005,9 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password)
{
clear();
prepare_file_names(wallet_);
check_for_free_space_and_throw_if_it_lacks(m_wallet_file);
m_password = password;
std::string keys_buff;
@ -2057,35 +2066,55 @@ void wallet2::store(const std::wstring& path_to_save, const std::string& passwor
{
LOG_PRINT_L0("(before storing: pending_key_images: " << m_pending_key_images.size() << ", pki file elements: " << m_pending_key_images_file_container.size() << ", tx_keys: " << m_tx_keys.size() << ")");
check_for_free_space_and_throw_if_it_lacks(path_to_save);
std::string ascii_path_to_save = epee::string_encoding::convert_to_ansii(path_to_save);
//prepare data
std::string keys_buff;
bool r = store_keys(keys_buff, password);
CHECK_AND_ASSERT_THROW_MES(r, "failed to store_keys for wallet " << epee::string_encoding::convert_to_ansii(m_wallet_file));
wallet_file_binary_header wbh = AUTO_VAL_INIT(wbh);
WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(r, "failed to store_keys for wallet " << ascii_path_to_save);
//store data
wallet_file_binary_header wbh = AUTO_VAL_INIT(wbh);
wbh.m_signature = WALLET_FILE_SIGNATURE;
wbh.m_cb_keys = keys_buff.size();
//@#@ change it to proper
wbh.m_cb_body = 1000;
std::string header_buff((const char*)&wbh, sizeof(wbh));
uint64_t ts = m_core_runtime_config.get_core_time();
// save to tmp file, then rename
boost::filesystem::path tmp_file_path = boost::filesystem::path(path_to_save);
tmp_file_path += L".newtmp_" + std::to_wstring(ts);
//std::ofstream data_file;
boost::filesystem::ofstream data_file;
data_file.open(path_to_save, std::ios_base::binary | std::ios_base::out | std::ios::trunc);
CHECK_AND_ASSERT_THROW_MES(!data_file.fail(), "failed to open binary wallet file for saving: " << epee::string_encoding::convert_to_ansii(m_wallet_file));
data_file.open(tmp_file_path, std::ios_base::binary | std::ios_base::out | std::ios::trunc);
WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(!data_file.fail(), "failed to open binary wallet file for saving: " << tmp_file_path.string());
data_file << header_buff << keys_buff;
WLT_LOG_L0("Storing to file...");
WLT_LOG_L0("Storing to " << tmp_file_path.string() << " ...");
r = tools::portble_serialize_obj_to_stream(*this, data_file);
CHECK_AND_ASSERT_THROW_MES(r, "failed to portble_serialize_obj_to_stream for wallet " << epee::string_encoding::convert_to_ansii(m_wallet_file));
if (!r)
{
boost::filesystem::remove(tmp_file_path); // remove tmp file if smth went wrong
WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(false, "portble_serialize_obj_to_stream failed for wallet " << tmp_file_path.string());
}
data_file.flush();
data_file.close();
// for the sake of safety perform a double-renaming: wallet file -> old tmp, new tmp -> wallet file, remove old tmp
boost::filesystem::path tmp_old_file_path = boost::filesystem::path(path_to_save);
tmp_old_file_path += L".oldtmp_" + std::to_wstring(ts);
if (boost::filesystem::is_regular_file(path_to_save))
boost::filesystem::rename(path_to_save, tmp_old_file_path);
boost::filesystem::rename(tmp_file_path, path_to_save);
boost::filesystem::remove(tmp_old_file_path);
}
//----------------------------------------------------------------------------------------------------
void wallet2::store_watch_only(const std::wstring& path_to_save, const std::string& password) const
@ -2133,6 +2162,49 @@ void wallet2::store_watch_only(const std::wstring& path_to_save, const std::stri
wo.store(path_to_save, password);
}
//----------------------------------------------------------------------------------------------------
void wallet2::check_for_free_space_and_throw_if_it_lacks(const std::wstring& wallet_filename, uint64_t exact_size_needed_if_known /* = UINT64_MAX */)
{
namespace fs = boost::filesystem;
try
{
fs::path wallet_file_path(wallet_filename);
fs::path base_path = wallet_file_path.parent_path();
if (base_path.empty())
base_path = fs::path(".");
WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(fs::is_directory(base_path), "directory does not exist: " << base_path.string());
uint64_t min_free_size = exact_size_needed_if_known;
if (min_free_size == UINT64_MAX)
{
// if exact size needed is unknown -- determine it as
// twice the original wallet file size or MINIMUM_REQUIRED_WALLET_FREE_SPACE_BYTES, which one is bigger
min_free_size = MINIMUM_REQUIRED_WALLET_FREE_SPACE_BYTES;
if (fs::is_regular_file(wallet_file_path))
min_free_size = std::max(min_free_size, 2 * fs::file_size(wallet_file_path));
}
else
{
min_free_size += 1024 * 1024 * 10; // add a little for FS overhead and so
}
fs::space_info si = fs::space(base_path);
WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(si.available > min_free_size, "free space at " << base_path.string() << " is too low: " << si.available << ", required minimum is: " << min_free_size);
}
catch (tools::error::wallet_common_error&)
{
throw;
}
catch (std::exception& e)
{
WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(false, "failed to determine free space: " << e.what());
}
catch (...)
{
WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(false, "failed to determine free space: unknown exception");
}
}
//----------------------------------------------------------------------------------------------------
uint64_t wallet2::unlocked_balance() const
{
uint64_t stub = 0;
@ -2422,7 +2494,7 @@ uint64_t wallet2::get_recent_transfers_total_count()
return m_transfer_history.size();
}
//----------------------------------------------------------------------------------------------------
void wallet2::get_recent_transfers_history(std::vector<wallet_rpc::wallet_transfer_info>& trs, size_t offset, size_t count)
void wallet2::get_recent_transfers_history(std::vector<wallet_public::wallet_transfer_info>& trs, size_t offset, size_t count)
{
if (offset >= m_transfer_history.size())
return;
@ -2459,13 +2531,13 @@ bool wallet2::is_transfer_okay_for_pos(const transfer_details& tr, uint64_t& sta
return true;
}
//----------------------------------------------------------------------------------------------------
void wallet2::get_mining_history(wallet_rpc::mining_history& hist)
void wallet2::get_mining_history(wallet_public::mining_history& hist)
{
for (auto& tr : m_transfer_history)
{
if (currency::is_coinbase(tr.tx) && tr.tx.vin.size() == 2)
{
tools::wallet_rpc::mining_history_entry mhe = AUTO_VAL_INIT(mhe);
tools::wallet_public::mining_history_entry mhe = AUTO_VAL_INIT(mhe);
mhe.a = tr.amount;
mhe.t = tr.timestamp;
mhe.h = tr.height;
@ -2730,7 +2802,7 @@ bool wallet2::build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request&
return true;
}
//----------------------------------------------------------------------------------------------------
void wallet2::get_unconfirmed_transfers(std::vector<wallet_rpc::wallet_transfer_info>& trs)
void wallet2::get_unconfirmed_transfers(std::vector<wallet_public::wallet_transfer_info>& trs)
{
for (auto& u : m_unconfirmed_txs)
trs.push_back(u.second);
@ -3256,6 +3328,13 @@ void wallet2::remove_transfer_from_expiration_list(uint64_t transfer_index)
// (don't change m_spent flag, because transfer status is unclear - the caller should take care of it)
}
//----------------------------------------------------------------------------------------------------
void wallet2::send_escrow_proposal(const wallet_public::create_proposal_param& wp,
currency::transaction &proposal_tx,
currency::transaction &escrow_template_tx)
{
return send_escrow_proposal(wp.details, wp.fake_outputs_count, wp.unlock_time, wp.expiration_period, wp.fee, wp.b_fee, wp.payment_id, proposal_tx, escrow_template_tx);
}
//----------------------------------------------------------------------------------------------------
void wallet2::send_escrow_proposal(const bc_services::contract_private_details& ecrow_details,
size_t fake_outputs_count,
uint64_t unlock_time,
@ -3654,10 +3733,9 @@ bool wallet2::select_my_offers(std::list<bc_services::offer_details_ex>& offers)
return true;
}
//----------------------------------------------------------------------------------------------------
bool wallet2::get_actual_offers(std::list<bc_services::offer_details_ex>& offers, bool fake)
bool wallet2::get_actual_offers(std::list<bc_services::offer_details_ex>& offers)
{
select_my_offers(offers);
return true;
}
//----------------------------------------------------------------------------------------------------
@ -3749,7 +3827,7 @@ uint64_t wallet2::select_transfers(uint64_t needed_money, size_t fake_outputs_co
}
//----------------------------------------------------------------------------------------------------
bool wallet2::read_money_transfer2_details_from_tx(const transaction& tx, const std::vector<currency::tx_destination_entry>& splitted_dsts,
wallet_rpc::wallet_transfer_info_details& wtd)
wallet_public::wallet_transfer_info_details& wtd)
{
PROFILE_FUNC("wallet2::read_money_transfer2_details_from_tx");
for (auto& d : splitted_dsts)
@ -3780,7 +3858,7 @@ void wallet2::add_sent_unconfirmed_tx(const currency::transaction& tx,
const std::vector<currency::tx_destination_entry>& splitted_dsts)
{
PROFILE_FUNC("wallet2::add_sent_unconfirmed_tx");
wallet_rpc::wallet_transfer_info& unconfirmed_wti = misc_utils::get_or_insert_value_initialized(m_unconfirmed_txs, currency::get_transaction_hash(tx));
wallet_public::wallet_transfer_info& unconfirmed_wti = misc_utils::get_or_insert_value_initialized(m_unconfirmed_txs, currency::get_transaction_hash(tx));
//unconfirmed_wti.tx = tx;
unconfirmed_wti.remote_addresses = recipients;

View file

@ -23,7 +23,7 @@
#include "currency_core/account_boost_serialization.h"
#include "currency_core/currency_format_utils.h"
#include "wallet_rpc_server_commans_defs.h"
#include "wallet_public_structs_defs.h"
#include "currency_core/currency_format_utils.h"
#include "common/unordered_containers_boost_serialization.h"
#include "storages/portable_storage_template_helper.h"
@ -34,7 +34,6 @@
#include "wallet_errors.h"
#include "eos/portable_archive.hpp"
#include "currency_core/core_runtime_config.h"
#include "currency_core/offers_services_helpers.h"
#include "currency_core/bc_offers_serialization.h"
#include "currency_core/bc_escrow_service.h"
#include "common/pod_array_file_container.h"
@ -48,21 +47,22 @@
ENABLE_CHANNEL_BY_DEFAULT("wallet");
// wallet-specific logging functions
#define WLT_LOG_L0(msg) LOG_PRINT_L0("[W:" << m_log_prefix << "]" << msg)
#define WLT_LOG_L1(msg) LOG_PRINT_L1("[W:" << m_log_prefix << "]" << msg)
#define WLT_LOG_L2(msg) LOG_PRINT_L2("[W:" << m_log_prefix << "]" << msg)
#define WLT_LOG_L3(msg) LOG_PRINT_L3("[W:" << m_log_prefix << "]" << msg)
#define WLT_LOG_L4(msg) LOG_PRINT_L4("[W:" << m_log_prefix << "]" << msg)
#define WLT_LOG_ERROR(msg) LOG_ERROR("[W:" << m_log_prefix << "]" << msg)
#define WLT_LOG_BLUE(msg, log_level) LOG_PRINT_BLUE("[W:" << m_log_prefix << "]" << msg, log_level)
#define WLT_LOG_CYAN(msg, log_level) LOG_PRINT_CYAN("[W:" << m_log_prefix << "]" << msg, log_level)
#define WLT_LOG_GREEN(msg, log_level) LOG_PRINT_GREEN("[W:" << m_log_prefix << "]" << msg, log_level)
#define WLT_LOG_MAGENTA(msg, log_level) LOG_PRINT_MAGENTA("[W:" << m_log_prefix << "]" << msg, log_level)
#define WLT_LOG_RED(msg, log_level) LOG_PRINT_RED("[W:" << m_log_prefix << "]" << msg, log_level)
#define WLT_LOG_YELLOW(msg, log_level) LOG_PRINT_YELLOW("[W:" << m_log_prefix << "]" << msg, log_level)
#define WLT_CHECK_AND_ASSERT_MES(expr, ret, msg) CHECK_AND_ASSERT_MES(expr, ret, "[W:" << m_log_prefix << "]" << msg)
#define WLT_CHECK_AND_ASSERT_MES_NO_RET(expr, msg) CHECK_AND_ASSERT_MES_NO_RET(expr, "[W:" << m_log_prefix << "]" << msg)
#define WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(cond, msg) THROW_IF_FALSE_WALLET_INT_ERR_EX(cond, "[W:" << m_log_prefix << "]" << msg)
#define WLT_LOG_L0(msg) LOG_PRINT_L0("[W:" << m_log_prefix << "] " << msg)
#define WLT_LOG_L1(msg) LOG_PRINT_L1("[W:" << m_log_prefix << "] " << msg)
#define WLT_LOG_L2(msg) LOG_PRINT_L2("[W:" << m_log_prefix << "] " << msg)
#define WLT_LOG_L3(msg) LOG_PRINT_L3("[W:" << m_log_prefix << "] " << msg)
#define WLT_LOG_L4(msg) LOG_PRINT_L4("[W:" << m_log_prefix << "] " << msg)
#define WLT_LOG_ERROR(msg) LOG_ERROR("[W:" << m_log_prefix << "] " << msg)
#define WLT_LOG_BLUE(msg, log_level) LOG_PRINT_BLUE("[W:" << m_log_prefix << "] " << msg, log_level)
#define WLT_LOG_CYAN(msg, log_level) LOG_PRINT_CYAN("[W:" << m_log_prefix << "] " << msg, log_level)
#define WLT_LOG_GREEN(msg, log_level) LOG_PRINT_GREEN("[W:" << m_log_prefix << "] " << msg, log_level)
#define WLT_LOG_MAGENTA(msg, log_level) LOG_PRINT_MAGENTA("[W:" << m_log_prefix << "] " << msg, log_level)
#define WLT_LOG_RED(msg, log_level) LOG_PRINT_RED("[W:" << m_log_prefix << "] " << msg, log_level)
#define WLT_LOG_YELLOW(msg, log_level) LOG_PRINT_YELLOW("[W:" << m_log_prefix << "] " << msg, log_level)
#define WLT_CHECK_AND_ASSERT_MES(expr, ret, msg) CHECK_AND_ASSERT_MES(expr, ret, "[W:" << m_log_prefix << "] " << msg)
#define WLT_CHECK_AND_ASSERT_MES_NO_RET(expr, msg) CHECK_AND_ASSERT_MES_NO_RET(expr, "[W:" << m_log_prefix << "] " << msg)
#define WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(cond, msg) THROW_IF_FALSE_WALLET_INT_ERR_EX(cond, "[W:" << m_log_prefix << "] " << msg)
#define WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(cond, msg) THROW_IF_FALSE_WALLET_CMN_ERR_EX(cond, "[W:" << m_log_prefix << "] " << msg)
class test_generator;
@ -91,10 +91,10 @@ namespace tools
virtual ~i_wallet2_callback() = default;
virtual void on_new_block(uint64_t /*height*/, const currency::block& /*block*/) {}
virtual void on_transfer2(const wallet_rpc::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) {}
virtual void on_transfer2(const wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) {}
virtual void on_pos_block_found(const currency::block& /*block*/) {}
virtual void on_sync_progress(const uint64_t& /*percents*/) {}
virtual void on_transfer_canceled(const wallet_rpc::wallet_transfer_info& wti) {}
virtual void on_transfer_canceled(const wallet_public::wallet_transfer_info& wti) {}
};
struct tx_dust_policy
@ -432,7 +432,7 @@ namespace tools
typedef std::deque<transfer_details> transfer_container;
typedef std::unordered_map<crypto::hash, transfer_details_base> multisig_transfer_container;
typedef std::unordered_map<crypto::hash, tools::wallet_rpc::escrow_contract_details_basic> escrow_contracts_container;
typedef std::unordered_map<crypto::hash, tools::wallet_public::escrow_contract_details_basic> escrow_contracts_container;
typedef std::map<uint64_t, std::set<size_t> > free_amounts_cache_type;
@ -459,9 +459,9 @@ namespace tools
currency::account_base& get_account() { return m_account; }
const currency::account_base& get_account() const { return m_account; }
void get_recent_transfers_history(std::vector<wallet_rpc::wallet_transfer_info>& trs, size_t offset, size_t count);
void get_recent_transfers_history(std::vector<wallet_public::wallet_transfer_info>& trs, size_t offset, size_t count);
uint64_t get_recent_transfers_total_count();
void get_unconfirmed_transfers(std::vector<wallet_rpc::wallet_transfer_info>& trs);
void get_unconfirmed_transfers(std::vector<wallet_public::wallet_transfer_info>& trs);
void init(const std::string& daemon_address = "http://localhost:8080");
bool deinit();
@ -580,6 +580,11 @@ namespace tools
std::vector<uint64_t>& selected_transfers,
crypto::secret_key& one_time_key);
void send_escrow_proposal(const wallet_public::create_proposal_param& wp,
currency::transaction &proposal_tx,
currency::transaction &escrow_template_tx);
void send_escrow_proposal(const bc_services::contract_private_details& ecrow_detaild,
size_t fake_outputs_count,
uint64_t unlock_time,
@ -686,16 +691,16 @@ namespace tools
bool reset_history();
bool is_transfer_unlocked(const transfer_details& td) const;
bool is_transfer_unlocked(const transfer_details& td, bool for_pos_mining, uint64_t& stake_lock_time) const;
void get_mining_history(wallet_rpc::mining_history& hist);
void get_mining_history(wallet_public::mining_history& hist);
void set_core_runtime_config(const currency::core_runtime_config& pc);
currency::core_runtime_config& get_core_runtime_config();
bool backup_keys(const std::string& path);
bool reset_password(const std::string& pass);
bool is_password_valid(const std::string& pass);
bool get_actual_offers(std::list<bc_services::offer_details_ex>& offers, bool fake = false);
bool get_actual_offers(std::list<bc_services::offer_details_ex>& offers);
bool get_fake_offers(std::list<bc_services::offer_details_ex>& offers, uint64_t amount);
bool process_contract_info(wallet_rpc::wallet_transfer_info& wti, const std::vector<currency::payload_items_v>& decrypted_attach);
bool handle_proposal(wallet_rpc::wallet_transfer_info& wti, const bc_services::proposal_body& prop);
bool process_contract_info(wallet_public::wallet_transfer_info& wti, const std::vector<currency::payload_items_v>& decrypted_attach);
bool handle_proposal(wallet_public::wallet_transfer_info& wti, const bc_services::proposal_body& prop);
void accept_proposal(const crypto::hash& contract_id, uint64_t b_acceptance_fee, currency::transaction* p_acceptance_tx = nullptr);
void finish_contract(const crypto::hash& contract_id, const std::string& release_type, currency::transaction* p_release_tx = nullptr);
void request_cancel_contract(const crypto::hash& contract_id, uint64_t fee, uint64_t expiration_period, currency::transaction* p_cancellation_proposal_tx = nullptr);
@ -724,6 +729,7 @@ namespace tools
std::string get_log_prefix() const { return m_log_prefix; }
static uint64_t get_max_unlock_time_from_receive_indices(const currency::transaction& tx, const money_transfer2_details& td);
private:
void add_transfers_to_expiration_list(const std::vector<uint64_t>& selected_transfers, uint64_t expiration, uint64_t change_amount, const crypto::hash& related_tx_id);
void remove_transfer_from_expiration_list(uint64_t transfer_index);
@ -751,11 +757,11 @@ private:
const std::vector<currency::tx_destination_entry>& splitted_dsts);
bool read_money_transfer2_details_from_tx(const currency::transaction& tx,
const std::vector<currency::tx_destination_entry>& splitted_dsts,
wallet_rpc::wallet_transfer_info_details& wtd);
wallet_public::wallet_transfer_info_details& wtd);
void update_current_tx_limit();
void prepare_wti(wallet_rpc::wallet_transfer_info& wti, uint64_t height, uint64_t timestamp, const currency::transaction& tx, uint64_t amount, const money_transfer2_details& td);
void prepare_wti_decrypted_attachments(wallet_rpc::wallet_transfer_info& wti, const std::vector<currency::payload_items_v>& decrypted_att);
void prepare_wti(wallet_public::wallet_transfer_info& wti, uint64_t height, uint64_t timestamp, const currency::transaction& tx, uint64_t amount, const money_transfer2_details& td);
void prepare_wti_decrypted_attachments(wallet_public::wallet_transfer_info& wti, const std::vector<currency::payload_items_v>& decrypted_att);
void handle_money_received2(const currency::block& b,
const currency::transaction& tx,
uint64_t amount,
@ -774,7 +780,7 @@ private:
bool is_transfer_okay_for_pos(const transfer_details& tr, uint64_t& stake_unlock_time);
bool scan_unconfirmed_outdate_tx();
const currency::transaction& get_transaction_by_id(const crypto::hash& tx_hash);
void rise_on_transfer2(const wallet_rpc::wallet_transfer_info& wti);
void rise_on_transfer2(const wallet_public::wallet_transfer_info& wti);
void process_genesis_if_needed(const currency::block& genesis);
bool build_escrow_proposal(bc_services::contract_private_details& ecrow_details, uint64_t fee, uint64_t unlock_time, currency::tx_service_attachment& att, std::vector<uint64_t>& selected_indicies);
bool prepare_tx_sources(uint64_t needed_money, size_t fake_outputs_count, uint64_t dust_threshold, std::vector<currency::tx_source_entry>& sources, std::vector<uint64_t>& selected_indicies, uint64_t& found_money);
@ -786,14 +792,14 @@ private:
const tx_dust_policy& dust_policy,
const std::vector<currency::tx_destination_entry>& dsts,
std::vector<currency::tx_destination_entry>& final_detinations);
bool handle_contract(wallet_rpc::wallet_transfer_info& wti, const bc_services::contract_private_details& cntr, const std::vector<currency::payload_items_v>& decrypted_attach);
bool handle_release_contract(wallet_rpc::wallet_transfer_info& wti, const std::string& release_instruction);
bool handle_cancel_proposal(wallet_rpc::wallet_transfer_info& wti, const bc_services::escrow_cancel_templates_body& ectb, const std::vector<currency::payload_items_v>& decrypted_attach);
bool handle_contract(wallet_public::wallet_transfer_info& wti, const bc_services::contract_private_details& cntr, const std::vector<currency::payload_items_v>& decrypted_attach);
bool handle_release_contract(wallet_public::wallet_transfer_info& wti, const std::string& release_instruction);
bool handle_cancel_proposal(wallet_public::wallet_transfer_info& wti, const bc_services::escrow_cancel_templates_body& ectb, const std::vector<currency::payload_items_v>& decrypted_attach);
bool handle_expiration_list(uint64_t tx_expiration_ts_median);
void handle_contract_expirations(uint64_t tx_expiration_ts_median);
void change_contract_state(wallet_rpc::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const wallet_rpc::wallet_transfer_info& wti) const;
void change_contract_state(wallet_rpc::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const std::string& reason = "internal intention") const;
void change_contract_state(wallet_public::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const wallet_public::wallet_transfer_info& wti) const;
void change_contract_state(wallet_public::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const std::string& reason = "internal intention") const;
uint64_t get_tx_expiration_median() const;
@ -801,25 +807,25 @@ private:
void print_tx_sent_message(const currency::transaction& tx, const std::string& description, uint64_t fee = UINT64_MAX);
// Validates escrow template tx in assumption it's related to wallet's account (wallet's account is either A or B party in escrow process)
bool validate_escrow_proposal(const wallet_rpc::wallet_transfer_info& wti, const bc_services::proposal_body& prop,
bool validate_escrow_proposal(const wallet_public::wallet_transfer_info& wti, const bc_services::proposal_body& prop,
std::vector<currency::payload_items_v>& decrypted_items, crypto::hash& ms_id, bc_services::contract_private_details& cpd);
bool validate_escrow_release(const currency::transaction& tx, bool release_type_normal, const bc_services::contract_private_details& cpd,
const currency::txout_multisig& source_ms_out, const crypto::hash& ms_id, size_t source_ms_out_index, const currency::transaction& source_tx, const currency::account_keys& a_keys) const;
bool validate_escrow_contract(const wallet_rpc::wallet_transfer_info& wti, const bc_services::contract_private_details& cpd, bool is_a,
bool validate_escrow_contract(const wallet_public::wallet_transfer_info& wti, const bc_services::contract_private_details& cpd, bool is_a,
const std::vector<currency::payload_items_v>& decrypted_items, crypto::hash& ms_id, bc_services::escrow_relese_templates_body& rtb);
bool validate_escrow_cancel_release(const currency::transaction& tx, const wallet_rpc::wallet_transfer_info& wti, const bc_services::escrow_cancel_templates_body& ectb,
bool validate_escrow_cancel_release(const currency::transaction& tx, const wallet_public::wallet_transfer_info& wti, const bc_services::escrow_cancel_templates_body& ectb,
const std::vector<currency::payload_items_v>& decrypted_items, crypto::hash& ms_id, bc_services::contract_private_details& cpd, const currency::transaction& source_tx,
size_t source_ms_out_index, const currency::account_keys& b_keys, uint64_t minimum_release_fee) const;
bool validate_escrow_cancel_proposal(const wallet_rpc::wallet_transfer_info& wti, const bc_services::escrow_cancel_templates_body& ectb,
bool validate_escrow_cancel_proposal(const wallet_public::wallet_transfer_info& wti, const bc_services::escrow_cancel_templates_body& ectb,
const std::vector<currency::payload_items_v>& decrypted_items, crypto::hash& ms_id, bc_services::contract_private_details& cpd,
const currency::transaction& proposal_template_tx);
void fill_transfer_details(const currency::transaction& tx, const tools::money_transfer2_details& td, tools::wallet_rpc::wallet_transfer_info_details& res_td) const;
void fill_transfer_details(const currency::transaction& tx, const tools::money_transfer2_details& td, tools::wallet_public::wallet_transfer_info_details& res_td) const;
void print_source_entry(const currency::tx_source_entry& src) const;
void init_log_prefix();
@ -835,7 +841,7 @@ private:
void exception_handler();
void exception_handler() const;
uint64_t get_minimum_allowed_fee_for_contract(const crypto::hash& ms_id);
void check_for_free_space_and_throw_if_it_lacks(const std::wstring& path, uint64_t exact_size_needed_if_known = UINT64_MAX);
@ -859,9 +865,9 @@ private:
uint64_t m_upper_transaction_size_limit; //TODO: auto-calc this value or request from daemon, now use some fixed value
std::atomic<bool> m_stop;
std::vector<wallet_rpc::wallet_transfer_info> m_transfer_history;
std::vector<wallet_public::wallet_transfer_info> m_transfer_history;
std::unordered_map<crypto::hash, currency::transaction> m_unconfirmed_in_transfers;
std::unordered_map<crypto::hash, tools::wallet_rpc::wallet_transfer_info> m_unconfirmed_txs;
std::unordered_map<crypto::hash, tools::wallet_public::wallet_transfer_info> m_unconfirmed_txs;
std::unordered_set<crypto::hash> m_unconfirmed_multisig_transfers;
std::unordered_map<crypto::hash, crypto::secret_key> m_tx_keys;
@ -887,7 +893,7 @@ private:
} // namespace tools
BOOST_CLASS_VERSION(tools::wallet2, WALLET_FILE_SERIALIZATION_VERSION)
BOOST_CLASS_VERSION(tools::wallet_rpc::wallet_transfer_info, 9)
BOOST_CLASS_VERSION(tools::wallet_public::wallet_transfer_info, 9)
BOOST_CLASS_VERSION(tools::wallet2::transfer_details, 2)
@ -932,14 +938,14 @@ namespace boost
}
template <class Archive>
inline void serialize(Archive& a, tools::wallet_rpc::wallet_transfer_info_details& x, const boost::serialization::version_type ver)
inline void serialize(Archive& a, tools::wallet_public::wallet_transfer_info_details& x, const boost::serialization::version_type ver)
{
a & x.rcv;
a & x.spn;
}
template <class Archive>
inline void serialize(Archive& a, tools::wallet_rpc::wallet_transfer_info& x, const boost::serialization::version_type ver)
inline void serialize(Archive& a, tools::wallet_public::wallet_transfer_info& x, const boost::serialization::version_type ver)
{
a & x.amount;
@ -975,7 +981,7 @@ namespace boost
}
template <class Archive>
inline void serialize(Archive& a, tools::wallet_rpc::escrow_contract_details_basic& x, const boost::serialization::version_type ver)
inline void serialize(Archive& a, tools::wallet_public::escrow_contract_details_basic& x, const boost::serialization::version_type ver)
{
a & x.state;
a & x.is_a;
@ -992,9 +998,9 @@ namespace boost
}
template <class Archive>
inline void serialize(Archive& a, tools::wallet_rpc::escrow_contract_details& x, const boost::serialization::version_type ver)
inline void serialize(Archive& a, tools::wallet_public::escrow_contract_details& x, const boost::serialization::version_type ver)
{
a & static_cast<tools::wallet_rpc::escrow_contract_details_basic&>(x);
a & static_cast<tools::wallet_public::escrow_contract_details_basic&>(x);
a & x.contract_id;
}

View file

@ -16,7 +16,7 @@ using namespace currency;
namespace tools
{
//-----------------------------------------------------------------------------------------------------
bool wallet2::validate_escrow_proposal(const wallet_rpc::wallet_transfer_info& wti, const bc_services::proposal_body& prop,
bool wallet2::validate_escrow_proposal(const wallet_public::wallet_transfer_info& wti, const bc_services::proposal_body& prop,
std::vector<payload_items_v>& decrypted_items, /* OUT */
crypto::hash& ms_id, /* OUT */
bc_services::contract_private_details& cpd /* OUT */
@ -244,7 +244,7 @@ bool wallet2::validate_escrow_release(const transaction& tx, bool release_type_n
#undef LOC_CHK
}
//----------------------------------------------------------------------------------------------------
bool wallet2::validate_escrow_contract(const wallet_rpc::wallet_transfer_info& wti, const bc_services::contract_private_details& cpd, bool is_a,
bool wallet2::validate_escrow_contract(const wallet_public::wallet_transfer_info& wti, const bc_services::contract_private_details& cpd, bool is_a,
const std::vector<currency::payload_items_v>& decrypted_items,
crypto::hash& ms_id, /* OUT */
bc_services::escrow_relese_templates_body& rtb /* OUT */)
@ -307,7 +307,7 @@ uint64_t wallet2::get_minimum_allowed_fee_for_contract(const crypto::hash& ms_id
// TODO move here:
// bool wallet2::handle_contract()
//----------------------------------------------------------------------------------------------------
bool wallet2::validate_escrow_cancel_release(const currency::transaction& tx, const wallet_rpc::wallet_transfer_info& wti, const bc_services::escrow_cancel_templates_body& ectb,
bool wallet2::validate_escrow_cancel_release(const currency::transaction& tx, const wallet_public::wallet_transfer_info& wti, const bc_services::escrow_cancel_templates_body& ectb,
const std::vector<currency::payload_items_v>& decrypted_items, crypto::hash& ms_id, bc_services::contract_private_details& cpd, const currency::transaction& source_tx,
size_t source_ms_out_index, const currency::account_keys& b_keys, uint64_t minimum_release_fee) const
{
@ -402,7 +402,7 @@ bool wallet2::validate_escrow_cancel_release(const currency::transaction& tx, co
#undef LOC_CHK
}
//----------------------------------------------------------------------------------------------------
bool wallet2::validate_escrow_cancel_proposal(const wallet_rpc::wallet_transfer_info& wti, const bc_services::escrow_cancel_templates_body& ectb,
bool wallet2::validate_escrow_cancel_proposal(const wallet_public::wallet_transfer_info& wti, const bc_services::escrow_cancel_templates_body& ectb,
const std::vector<currency::payload_items_v>& decrypted_items, crypto::hash& ms_id, bc_services::contract_private_details& cpd, const currency::transaction& proposal_template_tx)
{
#define LOC_CHK(cond, mes) WLT_CHECK_AND_ASSERT_MES(cond, false, "Invalid escrow cancellation request: " << mes << ". ms id: " << ms_id << ", tx: " << get_transaction_hash(wti.tx));

View file

@ -11,9 +11,11 @@
#include "wallet_rpc_server_error_codes.h"
#include "currency_core/offers_service_basics.h"
#include "currency_core/bc_escrow_service.h"
#include "rpc/core_rpc_server_commands_defs.h"
namespace tools
{
namespace wallet_rpc
namespace wallet_public
{
#define WALLET_RPC_STATUS_OK "OK"
#define WALLET_RPC_STATUS_BUSY "BUSY"
@ -132,7 +134,14 @@ namespace wallet_rpc
END_KV_SERIALIZE_MAP()
};
struct contracts_array
{
std::vector<escrow_contract_details> contracts;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(contracts)
END_KV_SERIALIZE_MAP()
};
@ -509,6 +518,225 @@ namespace wallet_rpc
};
};
struct create_proposal_param
{
// uint64_t wallet_id;
bc_services::contract_private_details details;
std::string payment_id;
uint64_t expiration_period;
uint64_t fee;
uint64_t b_fee;
uint64_t fake_outputs_count;
uint64_t unlock_time;
BEGIN_KV_SERIALIZE_MAP()
// KV_SERIALIZE(wallet_id)
KV_SERIALIZE(details)
KV_SERIALIZE(payment_id)
KV_SERIALIZE(expiration_period)
KV_SERIALIZE(fee)
KV_SERIALIZE(b_fee)
KV_SERIALIZE(fake_outputs_count)
KV_SERIALIZE(unlock_time)
END_KV_SERIALIZE_MAP()
};
struct COMMAND_CONTRACTS_SEND_PROPOSAL
{
typedef create_proposal_param request;
struct response
{
std::string status; //"OK", "UNCONFIRMED", "BAD", "SPENT", "INTERNAL_ERROR", "BAD_ADDRESS"
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
};
struct COMMAND_CONTRACTS_ACCEPT_PROPOSAL
{
struct request
{
crypto::hash contract_id;
uint64_t acceptance_fee;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(acceptance_fee)
KV_SERIALIZE_POD_AS_HEX_STRING(contract_id)
END_KV_SERIALIZE_MAP()
};
struct response
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
};
struct COMMAND_CONTRACTS_GET_ALL
{
struct request
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
typedef contracts_array response;
};
struct COMMAND_CONTRACTS_RELEASE
{
struct request
{
crypto::hash contract_id;
std::string release_type;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(release_type)
KV_SERIALIZE_POD_AS_HEX_STRING(contract_id)
END_KV_SERIALIZE_MAP()
};
struct response
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
};
struct COMMAND_CONTRACTS_REQUEST_CANCEL
{
struct request
{
crypto::hash contract_id;
uint64_t expiration_period;
uint64_t fee;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(expiration_period)
KV_SERIALIZE(fee)
KV_SERIALIZE_POD_AS_HEX_STRING(contract_id)
END_KV_SERIALIZE_MAP()
};
struct response
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
};
struct COMMAND_CONTRACTS_ACCEPT_CANCEL
{
struct request
{
crypto::hash contract_id;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_POD_AS_HEX_STRING(contract_id)
END_KV_SERIALIZE_MAP()
};
struct response
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
};
//--------------------
typedef currency::COMMAND_RPC_GET_OFFERS_EX COMMAND_MARKETPLACE_GET_MY_OFFERS;
struct COMMAND_MARKETPLACE_PUSH_OFFER
{
struct request
{
bc_services::offer_details_ex od;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(od)
END_KV_SERIALIZE_MAP()
};
struct response
{
std::string tx_hash;
uint64_t tx_blob_size;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(tx_hash)
KV_SERIALIZE(tx_blob_size)
END_KV_SERIALIZE_MAP()
};
};
struct COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER
{
struct request
{
crypto::hash tx_id;
uint64_t no;
bc_services::offer_details_ex od;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_POD_AS_HEX_STRING(tx_id)
KV_SERIALIZE(no)
KV_SERIALIZE(od)
END_KV_SERIALIZE_MAP()
};
struct response
{
std::string tx_hash;
uint64_t tx_blob_size;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(tx_hash)
KV_SERIALIZE(tx_blob_size)
END_KV_SERIALIZE_MAP()
};
};
struct COMMAND_MARKETPLACE_CANCEL_OFFER
{
struct request
{
crypto::hash tx_id;
uint64_t no;
uint64_t fee;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_POD_AS_HEX_STRING(tx_id)
KV_SERIALIZE(no)
KV_SERIALIZE(fee)
END_KV_SERIALIZE_MAP()
};
struct response
{
std::string tx_hash;
uint64_t tx_blob_size;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(tx_hash)
KV_SERIALIZE(tx_blob_size)
END_KV_SERIALIZE_MAP()
};
};
inline std::string get_escrow_contract_state_name(uint32_t state)
{
switch (state)

View file

@ -16,6 +16,22 @@ using namespace epee;
#include "crypto/hash.h"
#include "wallet_rpc_server_error_codes.h"
#define WALLET_RPC_BEGIN_TRY_ENTRY() try {
#define WALLET_RPC_CATCH_TRY_ENTRY() } \
catch (const std::exception& e) \
{ \
er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR; \
er.message = e.what(); \
return false; \
} \
catch (...) \
{ \
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; \
er.message = "WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR"; \
return false; \
}
namespace tools
{
//-----------------------------------------------------------------------------------
@ -125,7 +141,7 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_getbalance(const wallet_rpc::COMMAND_RPC_GET_BALANCE::request& req, wallet_rpc::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er, connection_context& cntx)
bool wallet_rpc_server::on_getbalance(const wallet_public::COMMAND_RPC_GET_BALANCE::request& req, wallet_public::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
try
{
@ -141,7 +157,7 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_getaddress(const wallet_rpc::COMMAND_RPC_GET_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_GET_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx)
bool wallet_rpc_server::on_getaddress(const wallet_public::COMMAND_RPC_GET_ADDRESS::request& req, wallet_public::COMMAND_RPC_GET_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
try
{
@ -156,7 +172,7 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_transfer(const wallet_rpc::COMMAND_RPC_TRANSFER::request& req, wallet_rpc::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx)
bool wallet_rpc_server::on_transfer(const wallet_public::COMMAND_RPC_TRANSFER::request& req, wallet_public::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
std::string payment_id;
if (!epee::string_tools::parse_hexstr_to_binbuff(req.payment_id, payment_id))
@ -244,22 +260,15 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_store(const wallet_rpc::COMMAND_RPC_STORE::request& req, wallet_rpc::COMMAND_RPC_STORE::response& res, epee::json_rpc::error& er, connection_context& cntx)
bool wallet_rpc_server::on_store(const wallet_public::COMMAND_RPC_STORE::request& req, wallet_public::COMMAND_RPC_STORE::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
try
{
m_wallet.store();
}
catch (std::exception& e)
{
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
er.message = e.what();
return false;
}
WALLET_RPC_BEGIN_TRY_ENTRY();
m_wallet.store();
WALLET_RPC_CATCH_TRY_ENTRY();
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_get_payments(const wallet_rpc::COMMAND_RPC_GET_PAYMENTS::request& req, wallet_rpc::COMMAND_RPC_GET_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx)
bool wallet_rpc_server::on_get_payments(const wallet_public::COMMAND_RPC_GET_PAYMENTS::request& req, wallet_public::COMMAND_RPC_GET_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
std::string payment_id;
if (!currency::parse_payment_id_from_hex_str(req.payment_id, payment_id))
@ -281,7 +290,7 @@ namespace tools
if (payment.m_unlock_time > payment.m_block_height + WALLET_DEFAULT_TX_SPENDABLE_AGE)
continue;
}
wallet_rpc::payment_details rpc_payment;
wallet_public::payment_details rpc_payment;
rpc_payment.payment_id = req.payment_id;
rpc_payment.tx_hash = epee::string_tools::pod_to_hex(payment.m_tx_hash);
rpc_payment.amount = payment.m_amount;
@ -293,7 +302,7 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_get_bulk_payments(const wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS::request& req, wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx)
bool wallet_rpc_server::on_get_bulk_payments(const wallet_public::COMMAND_RPC_GET_BULK_PAYMENTS::request& req, wallet_public::COMMAND_RPC_GET_BULK_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
res.payments.clear();
@ -320,7 +329,7 @@ namespace tools
continue;
}
wallet_rpc::payment_details rpc_payment;
wallet_public::payment_details rpc_payment;
rpc_payment.payment_id = payment_id_str;
rpc_payment.tx_hash = epee::string_tools::pod_to_hex(payment.m_tx_hash);
rpc_payment.amount = payment.m_amount;
@ -333,7 +342,7 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_make_integrated_address(const wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx)
bool wallet_rpc_server::on_make_integrated_address(const wallet_public::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::request& req, wallet_public::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
std::string payment_id;
if (!epee::string_tools::parse_hexstr_to_binbuff(req.payment_id, payment_id))
@ -362,7 +371,7 @@ namespace tools
return !res.integrated_address.empty();
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_split_integrated_address(const wallet_rpc::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx)
bool wallet_rpc_server::on_split_integrated_address(const wallet_public::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::request& req, wallet_public::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
currency::account_public_address addr;
std::string payment_id;
@ -378,40 +387,27 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_sign_transfer(const wallet_rpc::COMMAND_SIGN_TRANSFER::request& req, wallet_rpc::COMMAND_SIGN_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx)
bool wallet_rpc_server::on_sign_transfer(const wallet_public::COMMAND_SIGN_TRANSFER::request& req, wallet_public::COMMAND_SIGN_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
try
WALLET_RPC_BEGIN_TRY_ENTRY();
currency::transaction tx = AUTO_VAL_INIT(tx);
std::string tx_unsigned_blob;
if (!string_tools::parse_hexstr_to_binbuff(req.tx_unsigned_hex, tx_unsigned_blob))
{
currency::transaction tx = AUTO_VAL_INIT(tx);
std::string tx_unsigned_blob;
if (!string_tools::parse_hexstr_to_binbuff(req.tx_unsigned_hex, tx_unsigned_blob))
{
er.code = WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT;
er.message = "tx_unsigned_hex is invalid";
return false;
}
std::string tx_signed_blob;
m_wallet.sign_transfer(tx_unsigned_blob, tx_signed_blob, tx);
er.code = WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT;
er.message = "tx_unsigned_hex is invalid";
return false;
}
std::string tx_signed_blob;
m_wallet.sign_transfer(tx_unsigned_blob, tx_signed_blob, tx);
res.tx_signed_hex = epee::string_tools::buff_to_hex_nodelimer(tx_signed_blob);
res.tx_hash = epee::string_tools::pod_to_hex(currency::get_transaction_hash(tx));
}
catch (const std::exception& e)
{
er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR;
er.message = e.what();
return false;
}
catch (...)
{
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
er.message = "WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR";
return false;
}
res.tx_signed_hex = epee::string_tools::buff_to_hex_nodelimer(tx_signed_blob);
res.tx_hash = epee::string_tools::pod_to_hex(currency::get_transaction_hash(tx));
WALLET_RPC_CATCH_TRY_ENTRY();
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_submit_transfer(const wallet_rpc::COMMAND_SUBMIT_TRANSFER::request& req, wallet_rpc::COMMAND_SUBMIT_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx)
bool wallet_rpc_server::on_submit_transfer(const wallet_public::COMMAND_SUBMIT_TRANSFER::request& req, wallet_public::COMMAND_SUBMIT_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
std::string tx_signed_blob;
if (!string_tools::parse_hexstr_to_binbuff(req.tx_signed_hex, tx_signed_blob))
@ -421,27 +417,122 @@ namespace tools
return false;
}
try
{
currency::transaction tx = AUTO_VAL_INIT(tx);
m_wallet.submit_transfer(tx_signed_blob, tx);
res.tx_hash = epee::string_tools::pod_to_hex(currency::get_transaction_hash(tx));
}
catch (const std::exception& e)
{
er.code = WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR;
er.message = e.what();
return false;
}
catch (...)
{
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
er.message = "WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR";
return false;
}
WALLET_RPC_BEGIN_TRY_ENTRY();
currency::transaction tx = AUTO_VAL_INIT(tx);
m_wallet.submit_transfer(tx_signed_blob, tx);
res.tx_hash = epee::string_tools::pod_to_hex(currency::get_transaction_hash(tx));
WALLET_RPC_CATCH_TRY_ENTRY();
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_contracts_send_proposal(const wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
WALLET_RPC_BEGIN_TRY_ENTRY();
currency::transaction tx = AUTO_VAL_INIT(tx);
currency::transaction template_tx = AUTO_VAL_INIT(template_tx);
m_wallet.send_escrow_proposal(req, tx, template_tx);
return true;
WALLET_RPC_CATCH_TRY_ENTRY();
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_contracts_accept_proposal(const wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
WALLET_RPC_BEGIN_TRY_ENTRY();
m_wallet.accept_proposal(req.contract_id, req.acceptance_fee);
return true;
WALLET_RPC_CATCH_TRY_ENTRY();
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_contracts_get_all(const wallet_public::COMMAND_CONTRACTS_GET_ALL::request& req, wallet_public::COMMAND_CONTRACTS_GET_ALL::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
WALLET_RPC_BEGIN_TRY_ENTRY();
tools::wallet2::escrow_contracts_container ecc;
m_wallet.get_contracts(ecc);
res.contracts.resize(ecc.size());
size_t i = 0;
for (auto& c : ecc)
{
static_cast<tools::wallet_public::escrow_contract_details_basic&>(res.contracts[i]) = c.second;
res.contracts[i].contract_id = c.first;
i++;
}
return true;
WALLET_RPC_CATCH_TRY_ENTRY();
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_contracts_release(const wallet_public::COMMAND_CONTRACTS_RELEASE::request& req, wallet_public::COMMAND_CONTRACTS_RELEASE::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
WALLET_RPC_BEGIN_TRY_ENTRY();
m_wallet.finish_contract(req.contract_id, req.release_type);
return true;
WALLET_RPC_CATCH_TRY_ENTRY();
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_contracts_request_cancel(const wallet_public::COMMAND_CONTRACTS_REQUEST_CANCEL::request& req, wallet_public::COMMAND_CONTRACTS_REQUEST_CANCEL::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
WALLET_RPC_BEGIN_TRY_ENTRY();
m_wallet.request_cancel_contract(req.contract_id, req.fee, req.expiration_period);
return true;
WALLET_RPC_CATCH_TRY_ENTRY();
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_contracts_accept_cancel(const wallet_public::COMMAND_CONTRACTS_ACCEPT_CANCEL::request& req, wallet_public::COMMAND_CONTRACTS_ACCEPT_CANCEL::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
WALLET_RPC_BEGIN_TRY_ENTRY();
m_wallet.accept_cancel_contract(req.contract_id);
return true;
WALLET_RPC_CATCH_TRY_ENTRY();
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_marketplace_get_my_offers(const wallet_public::COMMAND_MARKETPLACE_GET_MY_OFFERS::request& req, wallet_public::COMMAND_MARKETPLACE_GET_MY_OFFERS::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
WALLET_RPC_BEGIN_TRY_ENTRY();
m_wallet.get_actual_offers(res.offers);
size_t offers_count_before_filtering = res.offers.size();
bc_services::filter_offers_list(res.offers, req.filter, m_wallet.get_core_runtime_config().get_core_time());
LOG_PRINT("get_my_offers(): " << res.offers.size() << " offers returned (" << offers_count_before_filtering << " was before filter)", LOG_LEVEL_1);
return true;
WALLET_RPC_CATCH_TRY_ENTRY();
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_marketplace_push_offer(const wallet_public::COMMAND_MARKETPLACE_PUSH_OFFER::request& req, wallet_public::COMMAND_MARKETPLACE_PUSH_OFFER::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
WALLET_RPC_BEGIN_TRY_ENTRY();
currency::transaction res_tx = AUTO_VAL_INIT(res_tx);
m_wallet.push_offer(req.od, res_tx);
res.tx_hash = string_tools::pod_to_hex(currency::get_transaction_hash(res_tx));
res.tx_blob_size = currency::get_object_blobsize(res_tx);
return true;
WALLET_RPC_CATCH_TRY_ENTRY();
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_marketplace_push_update_offer(const wallet_public::COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER::request& req, wallet_public::COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
WALLET_RPC_BEGIN_TRY_ENTRY();
currency::transaction res_tx = AUTO_VAL_INIT(res_tx);
m_wallet.update_offer_by_id(req.tx_id, req.no, req.od, res_tx);
res.tx_hash = string_tools::pod_to_hex(currency::get_transaction_hash(res_tx));
res.tx_blob_size = currency::get_object_blobsize(res_tx);
return true;
WALLET_RPC_CATCH_TRY_ENTRY();
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_marketplace_cancel_offer(const wallet_public::COMMAND_MARKETPLACE_CANCEL_OFFER::request& req, wallet_public::COMMAND_MARKETPLACE_CANCEL_OFFER::response& res, epee::json_rpc::error& er, connection_context& cntx)
{
WALLET_RPC_BEGIN_TRY_ENTRY();
currency::transaction res_tx = AUTO_VAL_INIT(res_tx);
m_wallet.cancel_offer_by_id(req.tx_id, req.no, req.fee, res_tx);
res.tx_hash = string_tools::pod_to_hex(currency::get_transaction_hash(res_tx));
res.tx_blob_size = currency::get_object_blobsize(res_tx);
return true;
WALLET_RPC_CATCH_TRY_ENTRY();
}
} // namespace tools

View file

@ -9,7 +9,7 @@
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
#include "net/http_server_impl_base.h"
#include "wallet_rpc_server_commans_defs.h"
#include "wallet_public_structs_defs.h"
#include "wallet2.h"
#include "common/command_line.h"
namespace tools
@ -39,30 +39,55 @@ namespace tools
BEGIN_URI_MAP2()
BEGIN_JSON_RPC_MAP("/json_rpc")
MAP_JON_RPC_WE("getbalance", on_getbalance, wallet_rpc::COMMAND_RPC_GET_BALANCE)
MAP_JON_RPC_WE("getaddress", on_getaddress, wallet_rpc::COMMAND_RPC_GET_ADDRESS)
MAP_JON_RPC_WE("transfer", on_transfer, wallet_rpc::COMMAND_RPC_TRANSFER)
MAP_JON_RPC_WE("store", on_store, wallet_rpc::COMMAND_RPC_STORE)
MAP_JON_RPC_WE("get_payments", on_get_payments, wallet_rpc::COMMAND_RPC_GET_PAYMENTS)
MAP_JON_RPC_WE("get_bulk_payments", on_get_bulk_payments, wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS)
MAP_JON_RPC_WE("make_integrated_address", on_make_integrated_address, wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS)
MAP_JON_RPC_WE("split_integrated_address", on_split_integrated_address, wallet_rpc::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS)
MAP_JON_RPC_WE("sign_transfer", on_sign_transfer, wallet_rpc::COMMAND_SIGN_TRANSFER)
MAP_JON_RPC_WE("submit_transfer", on_submit_transfer, wallet_rpc::COMMAND_SUBMIT_TRANSFER)
MAP_JON_RPC_WE("getbalance", on_getbalance, wallet_public::COMMAND_RPC_GET_BALANCE)
MAP_JON_RPC_WE("getaddress", on_getaddress, wallet_public::COMMAND_RPC_GET_ADDRESS)
MAP_JON_RPC_WE("transfer", on_transfer, wallet_public::COMMAND_RPC_TRANSFER)
MAP_JON_RPC_WE("store", on_store, wallet_public::COMMAND_RPC_STORE)
MAP_JON_RPC_WE("get_payments", on_get_payments, wallet_public::COMMAND_RPC_GET_PAYMENTS)
MAP_JON_RPC_WE("get_bulk_payments", on_get_bulk_payments, wallet_public::COMMAND_RPC_GET_BULK_PAYMENTS)
MAP_JON_RPC_WE("make_integrated_address", on_make_integrated_address, wallet_public::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS)
MAP_JON_RPC_WE("split_integrated_address", on_split_integrated_address, wallet_public::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS)
MAP_JON_RPC_WE("sign_transfer", on_sign_transfer, wallet_public::COMMAND_SIGN_TRANSFER)
MAP_JON_RPC_WE("submit_transfer", on_submit_transfer, wallet_public::COMMAND_SUBMIT_TRANSFER)
//contracts API
MAP_JON_RPC_WE("contracts_send_proposal", on_contracts_send_proposal, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL)
MAP_JON_RPC_WE("contracts_accept_proposal", on_contracts_accept_proposal, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL)
MAP_JON_RPC_WE("contracts_get_all", on_contracts_get_all, wallet_public::COMMAND_CONTRACTS_GET_ALL)
MAP_JON_RPC_WE("contracts_release", on_contracts_release, wallet_public::COMMAND_CONTRACTS_RELEASE)
MAP_JON_RPC_WE("contracts_request_cancel", on_contracts_request_cancel, wallet_public::COMMAND_CONTRACTS_REQUEST_CANCEL)
MAP_JON_RPC_WE("contracts_accept_cancel", on_contracts_accept_cancel, wallet_public::COMMAND_CONTRACTS_ACCEPT_CANCEL)
//marketplace API
MAP_JON_RPC_WE("marketplace_get_offers_ex", on_marketplace_get_my_offers, wallet_public::COMMAND_MARKETPLACE_GET_MY_OFFERS)
MAP_JON_RPC_WE("marketplace_push_offer", on_marketplace_push_offer, wallet_public::COMMAND_MARKETPLACE_PUSH_OFFER)
MAP_JON_RPC_WE("marketplace_push_update_offer", on_marketplace_push_update_offer, wallet_public::COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER)
MAP_JON_RPC_WE("marketplace_cancel_offer", on_marketplace_cancel_offer, wallet_public::COMMAND_MARKETPLACE_CANCEL_OFFER)
END_JSON_RPC_MAP()
END_URI_MAP2()
//json_rpc
bool on_getbalance(const wallet_rpc::COMMAND_RPC_GET_BALANCE::request& req, wallet_rpc::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_getaddress(const wallet_rpc::COMMAND_RPC_GET_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_GET_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_transfer(const wallet_rpc::COMMAND_RPC_TRANSFER::request& req, wallet_rpc::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_store(const wallet_rpc::COMMAND_RPC_STORE::request& req, wallet_rpc::COMMAND_RPC_STORE::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_get_payments(const wallet_rpc::COMMAND_RPC_GET_PAYMENTS::request& req, wallet_rpc::COMMAND_RPC_GET_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_get_bulk_payments(const wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS::request& req, wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_make_integrated_address(const wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_split_integrated_address(const wallet_rpc::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_sign_transfer(const wallet_rpc::COMMAND_SIGN_TRANSFER::request& req, wallet_rpc::COMMAND_SIGN_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_submit_transfer(const wallet_rpc::COMMAND_SUBMIT_TRANSFER::request& req, wallet_rpc::COMMAND_SUBMIT_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_getbalance(const wallet_public::COMMAND_RPC_GET_BALANCE::request& req, wallet_public::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_getaddress(const wallet_public::COMMAND_RPC_GET_ADDRESS::request& req, wallet_public::COMMAND_RPC_GET_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_transfer(const wallet_public::COMMAND_RPC_TRANSFER::request& req, wallet_public::COMMAND_RPC_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_store(const wallet_public::COMMAND_RPC_STORE::request& req, wallet_public::COMMAND_RPC_STORE::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_get_payments(const wallet_public::COMMAND_RPC_GET_PAYMENTS::request& req, wallet_public::COMMAND_RPC_GET_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_get_bulk_payments(const wallet_public::COMMAND_RPC_GET_BULK_PAYMENTS::request& req, wallet_public::COMMAND_RPC_GET_BULK_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_make_integrated_address(const wallet_public::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::request& req, wallet_public::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_split_integrated_address(const wallet_public::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::request& req, wallet_public::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_sign_transfer(const wallet_public::COMMAND_SIGN_TRANSFER::request& req, wallet_public::COMMAND_SIGN_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_submit_transfer(const wallet_public::COMMAND_SUBMIT_TRANSFER::request& req, wallet_public::COMMAND_SUBMIT_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_contracts_send_proposal(const wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_contracts_accept_proposal(const wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_contracts_get_all(const wallet_public::COMMAND_CONTRACTS_GET_ALL::request& req, wallet_public::COMMAND_CONTRACTS_GET_ALL::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_contracts_release(const wallet_public::COMMAND_CONTRACTS_RELEASE::request& req, wallet_public::COMMAND_CONTRACTS_RELEASE::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_contracts_request_cancel(const wallet_public::COMMAND_CONTRACTS_REQUEST_CANCEL::request& req, wallet_public::COMMAND_CONTRACTS_REQUEST_CANCEL::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_contracts_accept_cancel(const wallet_public::COMMAND_CONTRACTS_ACCEPT_CANCEL::request& req, wallet_public::COMMAND_CONTRACTS_ACCEPT_CANCEL::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_marketplace_get_my_offers(const wallet_public::COMMAND_MARKETPLACE_GET_MY_OFFERS::request& req, wallet_public::COMMAND_MARKETPLACE_GET_MY_OFFERS::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_marketplace_push_offer(const wallet_public::COMMAND_MARKETPLACE_PUSH_OFFER::request& req, wallet_public::COMMAND_MARKETPLACE_PUSH_OFFER::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_marketplace_push_update_offer(const wallet_public::COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER::request& req, wallet_public::COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_marketplace_cancel_offer(const wallet_public::COMMAND_MARKETPLACE_CANCEL_OFFER::request& req, wallet_public::COMMAND_MARKETPLACE_CANCEL_OFFER::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool handle_command_line(const boost::program_options::variables_map& vm);

View file

@ -2057,6 +2057,7 @@ test_chain_unit_enchanced::test_chain_unit_enchanced()
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, check_tx_pool_empty);
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, check_tx_pool_count);
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, print_tx_pool);
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, remove_stuck_txs);
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, check_offers_count);
}
@ -2122,6 +2123,16 @@ bool test_chain_unit_enchanced::print_tx_pool(currency::core& c, size_t ev_index
return true;
}
bool test_chain_unit_enchanced::remove_stuck_txs(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
{
size_t tx_count_before = c.get_pool_transactions_count();
bool r = c.get_tx_pool().remove_stuck_transactions();
CHECK_AND_ASSERT_MES(r, false, "remove_stuck_transactions() failed");
LOG_PRINT_L0("stuck txs removed from the pool, pool tx count: " << tx_count_before << " -> " << c.get_pool_transactions_count());
return true;
}
std::string print_market(bc_services::bc_offers_service* offers_service)
{
std::stringstream ss;

View file

@ -297,6 +297,7 @@ public:
bool check_tx_pool_empty(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
bool check_tx_pool_count(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
bool print_tx_pool(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
bool remove_stuck_txs(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
bool check_offers_count(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
protected:

View file

@ -919,6 +919,7 @@ int main(int argc, char* argv[])
GENERATE_AND_PLAY(tx_expiration_time);
GENERATE_AND_PLAY(tx_expiration_time_and_block_template);
GENERATE_AND_PLAY(tx_expiration_time_and_chain_switching);
GENERATE_AND_PLAY(tx_key_image_pool_conflict);
// Double spend
GENERATE_AND_PLAY(gen_double_spend_in_tx<false>);

View file

@ -328,7 +328,7 @@ bool escrow_altchain_meta_impl::c1(currency::core& c, size_t ev_index, const std
{
contracts.clear();
alice_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(check_contract_state(contracts, m_etd.cpd, static_cast<tools::wallet_rpc::escrow_contract_details_basic::contract_state>(se.a_state), "Alice"), false, "");
CHECK_AND_ASSERT_MES(check_contract_state(contracts, m_etd.cpd, static_cast<tools::wallet_public::escrow_contract_details_basic::contract_state>(se.a_state), "Alice"), false, "");
}
LOG_PRINT_GREEN("Bob's wallet is refreshing...", LOG_LEVEL_1);
@ -346,7 +346,7 @@ bool escrow_altchain_meta_impl::c1(currency::core& c, size_t ev_index, const std
{
contracts.clear();
bob_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(check_contract_state(contracts, m_etd.cpd, static_cast<tools::wallet_rpc::escrow_contract_details_basic::contract_state>(se.b_state), "Bob"), false, "");
CHECK_AND_ASSERT_MES(check_contract_state(contracts, m_etd.cpd, static_cast<tools::wallet_public::escrow_contract_details_basic::contract_state>(se.b_state), "Bob"), false, "");
}
mine_empty_block = true;

View file

@ -14,7 +14,7 @@ enum { eam_contract_state_initial = 0, eam_contract_state_none = (uint32_t)(-1)
enum { eam_tx_unknown = 0, eam_tx_make, eam_tx_confirm, eam_tx_make_and_confirm }; // make = construct tx and send it to the pool; confirm = put tx into a block
using contract_states = tools::wallet_rpc::escrow_contract_details_basic;
using contract_states = tools::wallet_public::escrow_contract_details_basic;
struct eam_event_noop
{

View file

@ -70,8 +70,8 @@ inline bool refresh_wallet_and_check_1_contract_state(const char* wallet_name, s
tools::wallet2::escrow_contracts_container contracts;
r = wallet->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r && contracts.size() == 1, false, "get_contracts() for " << wallet_name << " failed or returned wrong contracts count: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == expected_contract_state, false, wallet_name << " has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state)
<< ", expected: " << tools::wallet_rpc::get_escrow_contract_state_name(expected_contract_state));
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == expected_contract_state, false, wallet_name << " has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state)
<< ", expected: " << tools::wallet_public::get_escrow_contract_state_name(expected_contract_state));
return true;
}
@ -92,8 +92,8 @@ inline bool refresh_wallet_and_check_contract_state(const char* wallet_name, std
{
if (c.first == contract_id)
{
CHECK_AND_ASSERT_MES(c.second.state == expected_contract_state, false, wallet_name << " has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(c.second.state)
<< ", expected: " << tools::wallet_rpc::get_escrow_contract_state_name(expected_contract_state));
CHECK_AND_ASSERT_MES(c.second.state == expected_contract_state, false, wallet_name << " has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(c.second.state)
<< ", expected: " << tools::wallet_public::get_escrow_contract_state_name(expected_contract_state));
return true;
}
}
@ -606,11 +606,11 @@ inline bool operator==(const bc_services::contract_private_details& lhs, const b
lhs.title == rhs.title;
}
inline bool check_contract_state(const tools::wallet2::escrow_contracts_container& contracts, const bc_services::contract_private_details& cpd, tools::wallet_rpc::escrow_contract_details::contract_state state, const char* party)
inline bool check_contract_state(const tools::wallet2::escrow_contracts_container& contracts, const bc_services::contract_private_details& cpd, tools::wallet_public::escrow_contract_details::contract_state state, const char* party)
{
CHECK_AND_ASSERT_MES(contracts.size() == 1, false, party << " has incorrect number of contracts: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.private_detailes == cpd, false, party << " has invalid contract's private details");
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == state, false, party << " has invalid contract state: " <<
tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state) << ", expected state: " << tools::wallet_rpc::get_escrow_contract_state_name(state));
tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state) << ", expected state: " << tools::wallet_public::get_escrow_contract_state_name(state));
return true;
}

View file

@ -17,12 +17,12 @@ using namespace currency;
struct wallet_tests_callback_handler : public tools::i_wallet2_callback
{
virtual void on_transfer2(const tools::wallet_rpc::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined)
virtual void on_transfer2(const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined)
{
all_wtis.push_back(wti);
}
std::vector<tools::wallet_rpc::wallet_transfer_info> all_wtis;
std::vector<tools::wallet_public::wallet_transfer_info> all_wtis;
};
escrow_wallet_test::escrow_wallet_test()
@ -136,8 +136,8 @@ bool escrow_wallet_test::prepare_proposal_accepted_test(currency::core& c, const
CHECK_AND_FORCE_ASSERT_MES(contracts_buyer.begin()->second.is_a == true, false, "Incorrect contracts_buyer state");
CHECK_AND_FORCE_ASSERT_MES(contracts_seller.begin()->second.is_a == false, false, "Incorrect contracts_seller state");
CHECK_AND_FORCE_ASSERT_MES(contracts_buyer.begin()->second.state == tools::wallet_rpc::escrow_contract_details_basic::proposal_sent, false, "Incorrect contracts_buyer state");
CHECK_AND_FORCE_ASSERT_MES(contracts_seller.begin()->second.state == tools::wallet_rpc::escrow_contract_details_basic::proposal_sent, false, "Incorrect contracts_seller state");
CHECK_AND_FORCE_ASSERT_MES(contracts_buyer.begin()->second.state == tools::wallet_public::escrow_contract_details_basic::proposal_sent, false, "Incorrect contracts_buyer state");
CHECK_AND_FORCE_ASSERT_MES(contracts_seller.begin()->second.state == tools::wallet_public::escrow_contract_details_basic::proposal_sent, false, "Incorrect contracts_seller state");
CHECK_AND_FORCE_ASSERT_MES(contracts_buyer.begin()->first == multisig_id, false, "Incorrect contracts_buyer state");
CHECK_AND_FORCE_ASSERT_MES(contracts_seller.begin()->first == multisig_id, false, "Incorrect contracts_seller state");
@ -160,8 +160,8 @@ bool escrow_wallet_test::prepare_proposal_accepted_test(currency::core& c, const
CHECK_AND_FORCE_ASSERT_MES(contracts_buyer.begin()->second.is_a == true, false, "Incorrect contracts_buyer state");
CHECK_AND_FORCE_ASSERT_MES(contracts_seller.begin()->second.is_a == false, false, "Incorrect contracts_seller state");
CHECK_AND_FORCE_ASSERT_MES(contracts_buyer.begin()->second.state == tools::wallet_rpc::escrow_contract_details_basic::contract_accepted, false, "Incorrect contracts_buyer state");
CHECK_AND_FORCE_ASSERT_MES(contracts_seller.begin()->second.state == tools::wallet_rpc::escrow_contract_details_basic::contract_accepted, false, "Incorrect contracts_seller state");
CHECK_AND_FORCE_ASSERT_MES(contracts_buyer.begin()->second.state == tools::wallet_public::escrow_contract_details_basic::contract_accepted, false, "Incorrect contracts_buyer state");
CHECK_AND_FORCE_ASSERT_MES(contracts_seller.begin()->second.state == tools::wallet_public::escrow_contract_details_basic::contract_accepted, false, "Incorrect contracts_seller state");
tools::wallet2::multisig_transfer_container ms_buyer, ms_seller;
wallet_buyer->get_multisig_transfers(ms_buyer);
@ -183,16 +183,16 @@ bool escrow_wallet_test::exec_test_with_specific_release_type(currency::core& c,
// release contract
//----------------------
std::string release_instruction;
tools::wallet_rpc::escrow_contract_details_basic::contract_state expected_state = AUTO_VAL_INIT(expected_state);
tools::wallet_public::escrow_contract_details_basic::contract_state expected_state = AUTO_VAL_INIT(expected_state);
if (release_normal)
{
release_instruction = BC_ESCROW_SERVICE_INSTRUCTION_RELEASE_NORMAL;
expected_state = tools::wallet_rpc::escrow_contract_details_basic::contract_released_normal;
expected_state = tools::wallet_public::escrow_contract_details_basic::contract_released_normal;
}
else
{
release_instruction = BC_ESCROW_SERVICE_INSTRUCTION_RELEASE_BURN;
expected_state = tools::wallet_rpc::escrow_contract_details_basic::contract_released_burned;
expected_state = tools::wallet_public::escrow_contract_details_basic::contract_released_burned;
}
tools::wallet2::escrow_contracts_container contracts_buyer, contracts_seller;
@ -246,8 +246,8 @@ bool escrow_wallet_test::exec_test_with_cancel_release_type(currency::core& c, c
CHECK_AND_FORCE_ASSERT_MES(contracts_buyer.begin()->second.is_a == true, false, "Incorrect contracts_buyer state");
CHECK_AND_FORCE_ASSERT_MES(contracts_seller.begin()->second.is_a == false, false, "Incorrect contracts_seller state");
CHECK_AND_FORCE_ASSERT_MES(contracts_buyer.begin()->second.state == tools::wallet_rpc::escrow_contract_details_basic::contract_cancel_proposal_sent, false, "Incorrect contracts_buyer state");
CHECK_AND_FORCE_ASSERT_MES(contracts_seller.begin()->second.state == tools::wallet_rpc::escrow_contract_details_basic::contract_cancel_proposal_sent, false, "Incorrect contracts_seller state");
CHECK_AND_FORCE_ASSERT_MES(contracts_buyer.begin()->second.state == tools::wallet_public::escrow_contract_details_basic::contract_cancel_proposal_sent, false, "Incorrect contracts_buyer state");
CHECK_AND_FORCE_ASSERT_MES(contracts_seller.begin()->second.state == tools::wallet_public::escrow_contract_details_basic::contract_cancel_proposal_sent, false, "Incorrect contracts_seller state");
//cancel contract
wallet_seller->accept_cancel_contract(multisig_id);
@ -264,8 +264,8 @@ bool escrow_wallet_test::exec_test_with_cancel_release_type(currency::core& c, c
CHECK_AND_FORCE_ASSERT_MES(contracts_buyer.begin()->second.is_a == true, false, "Incorrect contracts_buyer state");
CHECK_AND_FORCE_ASSERT_MES(contracts_seller.begin()->second.is_a == false, false, "Incorrect contracts_seller state");
CHECK_AND_FORCE_ASSERT_MES(contracts_buyer.begin()->second.state == tools::wallet_rpc::escrow_contract_details_basic::contract_released_cancelled, false, "Incorrect contracts_buyer state");
CHECK_AND_FORCE_ASSERT_MES(contracts_seller.begin()->second.state == tools::wallet_rpc::escrow_contract_details_basic::contract_released_cancelled, false, "Incorrect contracts_seller state");
CHECK_AND_FORCE_ASSERT_MES(contracts_buyer.begin()->second.state == tools::wallet_public::escrow_contract_details_basic::contract_released_cancelled, false, "Incorrect contracts_buyer state");
CHECK_AND_FORCE_ASSERT_MES(contracts_seller.begin()->second.state == tools::wallet_public::escrow_contract_details_basic::contract_released_cancelled, false, "Incorrect contracts_seller state");
return true;
}
@ -642,7 +642,7 @@ bool escrow_incorrect_proposal::check_normal_proposal(currency::core& c, size_t
alice_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Alice didn't receive escrow proposal");
CHECK_AND_ASSERT_MES(contracts.begin()->second.is_a == false, false, "proposal has wrong is_a");
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::proposal_sent, false, "proposal has invalid state");
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::proposal_sent, false, "proposal has invalid state");
crypto::hash contract_id = contracts.begin()->first;
bc_services::contract_private_details cpd = contracts.begin()->second.private_detailes;
@ -794,7 +794,7 @@ bool escrow_proposal_expiration::c1(currency::core& c, size_t ev_index, const st
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool");
// make sure Bob has received correct escrow proposal
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent, ms_id, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::proposal_sent, ms_id, 1), false, "");
// mine few block to shift the timestamp median far enough
r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW);
@ -807,7 +807,7 @@ bool escrow_proposal_expiration::c1(currency::core& c, size_t ev_index, const st
CHECK_AND_ASSERT_MES(alice_balance == alice_expected_balance, false, "Alice has incorrect balance after her proposal is expired: " << alice_balance << ", expected: " << alice_expected_balance);
// check Bob's contracts
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent, ms_id, TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::proposal_sent, ms_id, TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW), false, "");
// try to accept expired proposal -- an exception should be thrown
r = false;
@ -860,8 +860,8 @@ bool escrow_proposal_expiration::c2(currency::core& c, size_t ev_index, const st
CHECK_AND_ASSERT_MES(ms_id != null_hash, false, "Can't obtain multisig id from escrow template tx");
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count());
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent, ms_id, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent, ms_id, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::proposal_sent, ms_id, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::proposal_sent, ms_id, 0), false, "");
// mine a few blocks with no txs
for (size_t i = 0; i < TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW + 1; ++i)
@ -880,8 +880,8 @@ bool escrow_proposal_expiration::c2(currency::core& c, size_t ev_index, const st
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count());
// check contract status, should remain the same
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent, ms_id, TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW + 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent, ms_id, TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW + 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::proposal_sent, ms_id, TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW + 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::proposal_sent, ms_id, TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW + 1), false, "");
// try to accept expired proposal -- an exception should be thrown
r = false;
@ -903,8 +903,8 @@ bool escrow_proposal_expiration::c2(currency::core& c, size_t ev_index, const st
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count());
// check contract status, should remain the same
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent, ms_id, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent, ms_id, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::proposal_sent, ms_id, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::proposal_sent, ms_id, 1), false, "");
// try to accept expired proposal -- an exception should be thrown
r = false;
@ -997,8 +997,8 @@ bool escrow_proposal_and_accept_expiration::c1(currency::core& c, size_t ev_inde
CHECK_AND_ASSERT_MES(ms_id != null_hash, false, "Can't obtain multisig id from escrow template tx");
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count());
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent, ms_id, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent, ms_id, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::proposal_sent, ms_id, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::proposal_sent, ms_id, 0), false, "");
// accept unconfirmed proposal
try
@ -1012,8 +1012,8 @@ bool escrow_proposal_and_accept_expiration::c1(currency::core& c, size_t ev_inde
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 2, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count());
LOG_PRINT("Tx pool:" << ENDL << c.get_tx_pool().print_pool(true), LOG_LEVEL_0);
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, ms_id, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, ms_id, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::contract_accepted, ms_id, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::contract_accepted, ms_id, 0), false, "");
LOG_PRINT_CYAN("%%%%% Escrow proposal accepted (unconfirmed), Alice's transfers: " << ENDL << alice_wlt->dump_trunsfers(), LOG_LEVEL_0);
LOG_PRINT_CYAN("%%%%% Escrow proposal accepted (unconfirmed), Bob's transfers: " << ENDL << bob_wlt->dump_trunsfers(), LOG_LEVEL_0);
@ -1038,8 +1038,8 @@ bool escrow_proposal_and_accept_expiration::c1(currency::core& c, size_t ev_inde
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count());
// check contract status, should remain the same
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, ms_id, TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW + 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, ms_id, TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW + 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::contract_accepted, ms_id, TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW + 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::contract_accepted, ms_id, TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW + 1), false, "");
LOG_PRINT_CYAN("%%%%% Escrow acceptance tx expired and removed from tx pool, Alice's transfers: " << ENDL << alice_wlt->dump_trunsfers(), LOG_LEVEL_0);
LOG_PRINT_CYAN("%%%%% Escrow acceptance tx expired and removed from tx pool, Bob's transfers: " << ENDL << bob_wlt->dump_trunsfers(), LOG_LEVEL_0);
@ -1064,8 +1064,8 @@ bool escrow_proposal_and_accept_expiration::c1(currency::core& c, size_t ev_inde
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count());
//
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent, ms_id, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent, ms_id, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::proposal_sent, ms_id, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::proposal_sent, ms_id, 1), false, "");
// try to accept expired proposal -- an exception should be thrown
r = false;
@ -1328,7 +1328,7 @@ bool escrow_incorrect_proposal_acceptance::check_normal_acceptance(currency::cor
CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Alice has incorrect number of contracts: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.private_detailes == m_cpd, false, "Alice has invalid contract's private details");
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_accepted, false, "Alice has invalid contract state: " << contracts.begin()->second.state);
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::contract_accepted, false, "Alice has invalid contract state: " << contracts.begin()->second.state);
crypto::hash ms_id = contracts.begin()->first;
@ -1348,7 +1348,7 @@ bool escrow_incorrect_proposal_acceptance::check_normal_acceptance(currency::cor
CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Bob has incorrect number of contracts: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.private_detailes == m_cpd, false, "Bob has invalid contract's private details");
uint8_t contract_expected_state = release_normal ? tools::wallet_rpc::escrow_contract_details::contract_released_normal : tools::wallet_rpc::escrow_contract_details::contract_released_burned;
uint8_t contract_expected_state = release_normal ? tools::wallet_public::escrow_contract_details::contract_released_normal : tools::wallet_public::escrow_contract_details::contract_released_burned;
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == contract_expected_state, false, "Bob has invalid contract state: " << contracts.begin()->second.state << " expected: " << contract_expected_state);
uint64_t bob_balance_end = bob_wlt->balance();
@ -1410,7 +1410,7 @@ bool escrow_incorrect_proposal_acceptance::check_incorrect_acceptance(currency::
}
// check it here in order to let more bugs show off with finish_contract()
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::proposal_sent, false, "Alice has invalid contract state: " << contracts.begin()->second.state);
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::proposal_sent, false, "Alice has invalid contract state: " << contracts.begin()->second.state);
CHECK_AND_ASSERT_MES(exception_on_finish_contract, false, "Alice was able to finish contract: " << param);
return true;
@ -1717,7 +1717,7 @@ bool escrow_custom_test::do_custom_test(currency::core& c, size_t ev_index, cons
tools::wallet2::escrow_contracts_container contracts;
r = bob_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Bob failed");
CHECK_AND_ASSERT_MES(check_contract_state(contracts, cd.cpd, tools::wallet_rpc::escrow_contract_details::proposal_sent, "Bob"), false, "wrong contract");
CHECK_AND_ASSERT_MES(check_contract_state(contracts, cd.cpd, tools::wallet_public::escrow_contract_details::proposal_sent, "Bob"), false, "wrong contract");
CHECK_AND_ASSERT_MES(contracts.begin()->second.payment_id == cd.payment_id, false, "incorrect payment_id was found in Bob's contract: " << contracts.begin()->second.payment_id << ", expected: " << cd.payment_id);
crypto::hash ms_id = contracts.begin()->first;
@ -1756,7 +1756,7 @@ bool escrow_custom_test::do_custom_test(currency::core& c, size_t ev_index, cons
r = alice_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed");
CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "incorrect contracts size for Alice: " << contracts.size());
CHECK_AND_ASSERT_MES(check_contract_state(contracts, cd.cpd, tools::wallet_rpc::escrow_contract_details::contract_accepted, "Alice"), false, "wrong contract");
CHECK_AND_ASSERT_MES(check_contract_state(contracts, cd.cpd, tools::wallet_public::escrow_contract_details::contract_accepted, "Alice"), false, "wrong contract");
CHECK_AND_ASSERT_MES(contracts.begin()->second.payment_id == cd.payment_id, false, "incorrect payment_id was found in Alice's contract: " << contracts.begin()->second.payment_id << ", expected: " << cd.payment_id);
// request cancellation if needed (normal/burn release should be still possible after that)
@ -1789,7 +1789,7 @@ bool escrow_custom_test::do_custom_test(currency::core& c, size_t ev_index, cons
contracts.clear();
r = alice_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed");
CHECK_AND_ASSERT_MES(check_contract_state(contracts, cd.cpd, tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, "Alice"), false, "wrong contract state");
CHECK_AND_ASSERT_MES(check_contract_state(contracts, cd.cpd, tools::wallet_public::escrow_contract_details::contract_cancel_proposal_sent, "Alice"), false, "wrong contract state");
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt.get(), "Alice", alice_expected_balance, 0, INVALID_BALANCE_VAL, 0, 0), false, "");
@ -1797,7 +1797,7 @@ bool escrow_custom_test::do_custom_test(currency::core& c, size_t ev_index, cons
contracts.clear();
r = bob_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Bob failed");
CHECK_AND_ASSERT_MES(check_contract_state(contracts, cd.cpd, tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, "Bob"), false, "wrong contract state");
CHECK_AND_ASSERT_MES(check_contract_state(contracts, cd.cpd, tools::wallet_public::escrow_contract_details::contract_cancel_proposal_sent, "Bob"), false, "wrong contract state");
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*bob_wlt.get(), "Bob", bob_expected_balance, 0, INVALID_BALANCE_VAL, 0, 0), false, "");
}
@ -1833,7 +1833,7 @@ bool escrow_custom_test::do_custom_test(currency::core& c, size_t ev_index, cons
contracts.clear();
r = alice_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed");
tools::wallet_rpc::escrow_contract_details::contract_state expected_state = cd.is_release_normal() ? tools::wallet_rpc::escrow_contract_details::contract_released_normal : tools::wallet_rpc::escrow_contract_details::contract_released_burned;
tools::wallet_public::escrow_contract_details::contract_state expected_state = cd.is_release_normal() ? tools::wallet_public::escrow_contract_details::contract_released_normal : tools::wallet_public::escrow_contract_details::contract_released_burned;
CHECK_AND_ASSERT_MES(check_contract_state(contracts, cd.cpd, expected_state, "Alice"), false, "wrong contract");
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt.get(), "Alice", alice_expected_balance, 0, INVALID_BALANCE_VAL, 0, 0), false, "");
@ -1843,7 +1843,7 @@ bool escrow_custom_test::do_custom_test(currency::core& c, size_t ev_index, cons
contracts.clear();
r = bob_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Bob failed");
expected_state = cd.is_release_normal() ? tools::wallet_rpc::escrow_contract_details::contract_released_normal : tools::wallet_rpc::escrow_contract_details::contract_released_burned;
expected_state = cd.is_release_normal() ? tools::wallet_public::escrow_contract_details::contract_released_normal : tools::wallet_public::escrow_contract_details::contract_released_burned;
CHECK_AND_ASSERT_MES(check_contract_state(contracts, cd.cpd, expected_state, "Bob"), false, "wrong contract");
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*bob_wlt.get(), "Bob", bob_expected_balance, 0, INVALID_BALANCE_VAL, 0, 0), false, "");
@ -1880,7 +1880,7 @@ bool escrow_custom_test::do_custom_test(currency::core& c, size_t ev_index, cons
contracts.clear();
r = alice_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed");
CHECK_AND_ASSERT_MES(check_contract_state(contracts, cd.cpd, tools::wallet_rpc::escrow_contract_details::contract_released_cancelled, "Alice"), false, "wrong contract state");
CHECK_AND_ASSERT_MES(check_contract_state(contracts, cd.cpd, tools::wallet_public::escrow_contract_details::contract_released_cancelled, "Alice"), false, "wrong contract state");
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt.get(), "Alice", alice_expected_balance, 0, INVALID_BALANCE_VAL, 0, 0), false, "");
@ -1888,7 +1888,7 @@ bool escrow_custom_test::do_custom_test(currency::core& c, size_t ev_index, cons
contracts.clear();
r = bob_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Bob failed");
CHECK_AND_ASSERT_MES(check_contract_state(contracts, cd.cpd, tools::wallet_rpc::escrow_contract_details::contract_released_cancelled, "Bob"), false, "wrong contract state");
CHECK_AND_ASSERT_MES(check_contract_state(contracts, cd.cpd, tools::wallet_public::escrow_contract_details::contract_released_cancelled, "Bob"), false, "wrong contract state");
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*bob_wlt.get(), "Bob", bob_expected_balance, 0, INVALID_BALANCE_VAL, 0, 0), false, "");
}
@ -2113,14 +2113,14 @@ bool escrow_incorrect_cancel_proposal::check_normal_cancel_proposal(currency::co
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed");
CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Alice has incorrect number of contracts: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.private_detailes == m_cpd, false, "Alice has invalid contract's private details");
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, false, "Alice has invalid contract state: " << contracts.begin()->second.state);
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::contract_cancel_proposal_sent, false, "Alice has invalid contract state: " << contracts.begin()->second.state);
contracts.clear();
r = bob_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Bob failed");
CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Bob has incorrect number of contracts: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.private_detailes == m_cpd, false, "Bob has invalid contract's private details");
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, false, "Bob has invalid contract state: " << contracts.begin()->second.state);
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::contract_cancel_proposal_sent, false, "Bob has invalid contract state: " << contracts.begin()->second.state);
crypto::hash ms_id = contracts.begin()->first;
bob_wlt->accept_cancel_contract(ms_id);
@ -2136,7 +2136,7 @@ bool escrow_incorrect_cancel_proposal::check_normal_cancel_proposal(currency::co
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed");
CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Alice has incorrect number of contracts: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.private_detailes == m_cpd, false, "Alice has invalid contract's private details");
uint8_t contract_expected_state = tools::wallet_rpc::escrow_contract_details::contract_released_cancelled;
uint8_t contract_expected_state = tools::wallet_public::escrow_contract_details::contract_released_cancelled;
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == contract_expected_state, false, "Alice has invalid contract state: " << contracts.begin()->second.state << " expected: " << contract_expected_state);
uint64_t alice_balance_end = alice_wlt->balance();
@ -2223,8 +2223,8 @@ bool escrow_incorrect_cancel_proposal::check_incorrect_cancel_proposal_internal(
}
// check it here in order to let more bugs show off with finish_contract()
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_accepted ||
contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, false, "Bob has invalid contract state: " << contracts.begin()->second.state); // It's ok for Bob to be mistaken about state, for ex: in case of too late cancellation acceptance
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::contract_accepted ||
contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::contract_cancel_proposal_sent, false, "Bob has invalid contract state: " << contracts.begin()->second.state); // It's ok for Bob to be mistaken about state, for ex: in case of too late cancellation acceptance
CHECK_AND_ASSERT_MES(exception_on_cancel_contract, false, "Bob was able to cancel escrow contract, requested with invalid cancellation request.");
return true;
@ -2384,7 +2384,7 @@ bool escrow_cancellation_and_tx_order::c1(currency::core& c, size_t ev_index, co
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed");
CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Alice has incorrect number of contracts: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.private_detailes == cpd, false, "Alice has invalid contract's private details");
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::proposal_sent, false, "Alice has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state));
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::proposal_sent, false, "Alice has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state));
crypto::hash contract_id = contracts.begin()->first;
// mine a block, containing escrow proposal tx
@ -2399,7 +2399,7 @@ bool escrow_cancellation_and_tx_order::c1(currency::core& c, size_t ev_index, co
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Bob failed");
CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Bob has incorrect number of contracts: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.private_detailes == cpd, false, "Bob has invalid contract's private details");
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::proposal_sent, false, "Bob has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state));
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::proposal_sent, false, "Bob has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state));
// Bob accepts the proposal
LOG_PRINT_GREEN("\n" "bob_wlt->accept_proposal()", LOG_LEVEL_0);
@ -2417,7 +2417,7 @@ bool escrow_cancellation_and_tx_order::c1(currency::core& c, size_t ev_index, co
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed");
CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Alice has incorrect number of contracts: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.private_detailes == cpd, false, "Alice has invalid contract's private details");
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_accepted, false, "Alice has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state));
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::contract_accepted, false, "Alice has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state));
// Alice requests cancellation
LOG_PRINT_GREEN("\n" "alice_wlt->request_cancel_contract()", LOG_LEVEL_0);
@ -2435,14 +2435,14 @@ bool escrow_cancellation_and_tx_order::c1(currency::core& c, size_t ev_index, co
contracts.clear();
r = alice_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r && contracts.size() == 1, false, "get_contracts() for Alice failed or returned wrong contracts count: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, false, "Alice has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state));
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::contract_cancel_proposal_sent, false, "Alice has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state));
bob_wlt->refresh();
bob_wlt->scan_tx_pool(stub_bool);
contracts.clear();
r = bob_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r && contracts.size() == 1, false, "get_contracts() for Bob failed or returned wrong contracts count: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, false, "Bob has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state));
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::contract_cancel_proposal_sent, false, "Bob has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state));
// don't mine block, try to accept cancellation on-the-fly
LOG_PRINT_GREEN("\n" "bob_wlt->accept_cancel_contract()", LOG_LEVEL_0);
@ -2458,13 +2458,13 @@ bool escrow_cancellation_and_tx_order::c1(currency::core& c, size_t ev_index, co
contracts.clear();
r = alice_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r && contracts.size() == 1, false, "get_contracts() for Alice failed or returned wrong contracts count: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_released_cancelled, false, "Alice has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state));
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::contract_released_cancelled, false, "Alice has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state));
bob_wlt->scan_tx_pool(stub_bool);
contracts.clear();
r = bob_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r && contracts.size() == 1, false, "get_contracts() for Bob failed or returned wrong contracts count: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_released_cancelled, false, "Bob has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state));
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::contract_released_cancelled, false, "Bob has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state));
// mine a block containing only cancel_request_acceptance_tx (this should trigger contracts' states swtiching into contract_released_cancelled)
LOG_PRINT_GREEN("\n" "mine_next_pow_block_in_playtime_with_given_txs(cancel_request_acceptance_tx)", LOG_LEVEL_0);
@ -2477,14 +2477,14 @@ bool escrow_cancellation_and_tx_order::c1(currency::core& c, size_t ev_index, co
contracts.clear();
r = alice_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r && contracts.size() == 1, false, "get_contracts() for Alice failed or returned wrong contracts count: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_released_cancelled, false, "Alice has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state));
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::contract_released_cancelled, false, "Alice has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state));
bob_wlt->refresh();
bob_wlt->scan_tx_pool(stub_bool);
contracts.clear();
r = bob_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r && contracts.size() == 1, false, "get_contracts() for Bob failed or returned wrong contracts count: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_released_cancelled, false, "Bob has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state));
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::contract_released_cancelled, false, "Bob has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state));
// mine a block containing only cancel_request_tx (this SHOULD NOT trigger contracts' states swtiching into contract_cancel_proposal_sent or anything)
@ -2498,14 +2498,14 @@ bool escrow_cancellation_and_tx_order::c1(currency::core& c, size_t ev_index, co
contracts.clear();
r = alice_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r && contracts.size() == 1, false, "get_contracts() for Alice failed or returned wrong contracts count: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_released_cancelled, false, "Alice has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state));
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::contract_released_cancelled, false, "Alice has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state));
bob_wlt->refresh();
bob_wlt->scan_tx_pool(stub_bool);
contracts.clear();
r = bob_wlt->get_contracts(contracts);
CHECK_AND_ASSERT_MES(r && contracts.size() == 1, false, "get_contracts() for Bob failed or returned wrong contracts count: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_released_cancelled, false, "Bob has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state));
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::contract_released_cancelled, false, "Bob has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state));
return true;
}
@ -2585,7 +2585,7 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed");
CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Alice has incorrect number of contracts: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.private_detailes == cpd, false, "Alice has invalid contract's private details");
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::proposal_sent, false, "Alice has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state));
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::proposal_sent, false, "Alice has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state));
crypto::hash contract_id = contracts.begin()->first;
uint64_t alice_blocked_transfers_sum = 0;
@ -2603,7 +2603,7 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Bob failed");
CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Bob has incorrect number of contracts: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.private_detailes == cpd, false, "Bob has invalid contract's private details");
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::proposal_sent, false, "Bob has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state));
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::proposal_sent, false, "Bob has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state));
// Bob accepts the proposal
LOG_PRINT_GREEN("\n" "bob_wlt->accept_proposal()", LOG_LEVEL_0);
@ -2624,7 +2624,7 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in
CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed");
CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Alice has incorrect number of contracts: " << contracts.size());
CHECK_AND_ASSERT_MES(contracts.begin()->second.private_detailes == cpd, false, "Alice has invalid contract's private details");
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_accepted, false, "Alice has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state));
CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_public::escrow_contract_details::contract_accepted, false, "Alice has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state));
// ===== (1/2) =====
// Alice requests cancellation for the first time -- this request will not be included into a block and will expire in tx pool
@ -2645,8 +2645,8 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in
CHECK_AND_ASSERT_MES(extract_cancellation_template_tx_from_request_tx(cancel_request_tx, m_accounts[BOB_ACC_IDX].get_keys(), tx_cancel_template), false, "extract_calcellation_template_tx_from_request_tx failed");
// contract state in wallets should be cancel_proposal_sent for both parties
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::contract_cancel_proposal_sent, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::contract_cancel_proposal_sent, 1), false, "");
// mine a few blocks with no txs to shift expiration median
for(size_t i = 0; i < 7; ++i)
@ -2675,8 +2675,8 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in
CHECK_AND_ASSERT_MES(r, false, "accept_cancel_contract succeeded, but it was excepted to fail");
// as cancellation request is expired, contract state should be contract_accepted for both
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, 7), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, 7), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::contract_accepted, 7), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::contract_accepted, 7), false, "");
// mine a block containing cancel_request_tx (already expired) -- should be okay
LOG_PRINT_GREEN("\n\n\n" "mine_next_pow_block_in_playtime() -- including expires contract cancellation request" "\n\n", LOG_LEVEL_0);
@ -2685,8 +2685,8 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count());
// expired cancellation request--even included into a block--should be ignored, contract state remains the same
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::contract_accepted, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::contract_accepted, 1), false, "");
// check balances
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt.get(), "Alice", alice_start_balance - TESTS_DEFAULT_FEE - cpd.amount_a_pledge - cpd.amount_to_pay - TESTS_DEFAULT_FEE), false, "");
@ -2710,8 +2710,8 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in
CHECK_AND_ASSERT_MES(extract_cancellation_template_tx_from_request_tx(cancel_request_tx, m_accounts[BOB_ACC_IDX].get_keys(), tx_cancel_template), false, "extract_calcellation_template_tx_from_request_tx failed");
// contract state in wallets should be cancel_proposal_sent for both parties, as new cancellation request was handled
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::contract_cancel_proposal_sent, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::contract_cancel_proposal_sent, 0), false, "");
// mine a block containing cancel_request_tx
LOG_PRINT_GREEN("\n" "mine_next_pow_block_in_playtime()", LOG_LEVEL_0);
@ -2720,8 +2720,8 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count());
// contracts' states should not change after receiving a block
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::contract_cancel_proposal_sent, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::contract_cancel_proposal_sent, 1), false, "");
// mine one more block (it's necessary for triggering expiration checks in wallets and shifting an expiration ts median)
LOG_PRINT_GREEN("\n" "mine_next_pow_block_in_playtime()", LOG_LEVEL_0);
@ -2747,8 +2747,8 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in
CHECK_AND_ASSERT_MES(r, false, "accept_cancel_contract succeeded, but it was excepted to fail");
// check contracts again - their state should change back to contract_accepted
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, 7), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, 7), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::contract_accepted, 7), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::contract_accepted, 7), false, "");
// check balances
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt.get(), "Alice", alice_start_balance - TESTS_DEFAULT_FEE - cpd.amount_a_pledge - cpd.amount_to_pay - TESTS_DEFAULT_FEE - TESTS_DEFAULT_FEE), false, "");
@ -2827,8 +2827,8 @@ bool escrow_cancellation_acceptance_expiration::c1(currency::core& c, size_t ev_
LOG_PRINT_GREEN("\n" "alice_wlt->send_escrow_proposal()", LOG_LEVEL_0);
alice_wlt->send_escrow_proposal(cpd, 0, 0, expiration_time, TX_DEFAULT_FEE, b_release_fee, "", proposal_tx, escrow_template_tx);
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::proposal_sent), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::proposal_sent), false, "");
tools::wallet2::escrow_contracts_container contracts;
r = alice_wlt->get_contracts(contracts);
@ -2844,7 +2844,7 @@ bool escrow_cancellation_acceptance_expiration::c1(currency::core& c, size_t ev_
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed");
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count());
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::proposal_sent), false, "");
// Bob accepts the proposal
LOG_PRINT_GREEN("\n" "bob_wlt->accept_proposal()", LOG_LEVEL_0);
@ -2859,7 +2859,7 @@ bool escrow_cancellation_acceptance_expiration::c1(currency::core& c, size_t ev_
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed");
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count());
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, 2), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::contract_accepted, 2), false, "");
// Alice requests cancellation
uint64_t cancel_request_expiration_period = DIFFICULTY_TOTAL_TARGET;
@ -2872,8 +2872,8 @@ bool escrow_cancellation_acceptance_expiration::c1(currency::core& c, size_t ev_
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count());
// contract state in wallets should be cancel_proposal_sent for both parties
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, 2), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::contract_cancel_proposal_sent, 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::contract_cancel_proposal_sent, 2), false, "");
LOG_PRINT_GREEN("%%%%% Bob : accept_cancel_contract()", LOG_LEVEL_0);
bob_wlt->accept_cancel_contract(contract_id);
@ -2886,8 +2886,8 @@ bool escrow_cancellation_acceptance_expiration::c1(currency::core& c, size_t ev_
transaction cancel_accept_tx = txs.front();
// contract state in wallets should be cancel_proposal_sent for both parties
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::contract_released_cancelled, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::contract_released_cancelled, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::contract_released_cancelled, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::contract_released_cancelled, 0), false, "");
// mine a few blocks with no txs to shift expiration median, cancellation acceptance is still in the pool
for(size_t i = 0; i < 7; ++i)
@ -2901,8 +2901,8 @@ bool escrow_cancellation_acceptance_expiration::c1(currency::core& c, size_t ev_
CHECK_AND_ASSERT_MES(is_tx_expired(cancel_accept_tx, c.get_blockchain_storage().get_tx_expiration_median()), false, "cancel_accept_tx did not expire");
// as cancellation acceptance is expired, contract state should be contract_accepted for both
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, 7), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, 7), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::contract_accepted, 7), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::contract_accepted, 7), false, "");
// check final balances
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt.get(), "Alice", alice_start_balance - TESTS_DEFAULT_FEE - cpd.amount_a_pledge - cpd.amount_to_pay - TESTS_DEFAULT_FEE), false, "");
@ -2920,8 +2920,8 @@ bool escrow_cancellation_acceptance_expiration::c1(currency::core& c, size_t ev_
CHECK_AND_ASSERT_MES(!r, false, "mine_next_pow_block_in_playtime_with_given_txs should have been failed as block contains expired tx");
// no changes with contract state expected
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::contract_accepted, 0), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::contract_accepted, 0), false, "");
// no changes with balances expected
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt.get(), "Alice", alice_start_balance - TESTS_DEFAULT_FEE - cpd.amount_a_pledge - cpd.amount_to_pay - TESTS_DEFAULT_FEE), false, "");

View file

@ -2533,7 +2533,7 @@ bool multisig_unconfirmed_transfer_and_multiple_scan_pool_calls::c1(currency::co
bool stub;
std::deque<tools::wallet2::transfer_details> transfers;
std::vector<tools::wallet_rpc::wallet_transfer_info> unconfirmed_transfers;
std::vector<tools::wallet_public::wallet_transfer_info> unconfirmed_transfers;
alice_wlt->scan_tx_pool(stub);
alice_wlt->get_transfers(transfers);

View file

@ -1450,3 +1450,128 @@ bool tx_expiration_time_and_chain_switching::generate(std::vector<test_event_ent
return true;
}
//------------------------------------------------------------------
tx_key_image_pool_conflict::tx_key_image_pool_conflict()
{
REGISTER_CALLBACK_METHOD(tx_key_image_pool_conflict, c1);
REGISTER_CALLBACK_METHOD(tx_key_image_pool_conflict, c2);
}
bool tx_key_image_pool_conflict::generate(std::vector<test_event_entry>& events) const
{
bool r = false;
m_miner_acc.generate();
GENERATE_ACCOUNT(bob_acc);
MAKE_GENESIS_BLOCK(events, blk_0, m_miner_acc, test_core_time::get_time());
REWIND_BLOCKS_N(events, blk_0r, blk_0, m_miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3);
// make tx_0 : miner -> bob
std::vector<tx_source_entry> sources;
std::vector<tx_destination_entry> destinations;
r = fill_tx_sources_and_destinations(events, blk_0r, m_miner_acc.get_keys(), bob_acc.get_public_address(), MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations);
CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed");
transaction tx_0 = AUTO_VAL_INIT(tx_0);
r = construct_tx(m_miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, 0);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
LOG_PRINT_YELLOW("tx_0 = " << get_transaction_hash(tx_0), LOG_LEVEL_0);
// do not push tx_0 into events yet
// tx_1 spends the same key image as tx_0
transaction tx_1 = tx_0;
keypair kp = keypair::generate();
// change tx pub key to end up with different tx hash
update_or_add_field_to_extra(tx_1.extra, kp.pub);
r = resign_tx(m_miner_acc.get_keys(), sources, tx_1);
CHECK_AND_ASSERT_MES(r, false, "resign_tx failed");
LOG_PRINT_YELLOW("tx_1 = " << get_transaction_hash(tx_1), LOG_LEVEL_0);
// tx_2 spends the same key image as tx_0
transaction tx_2 = tx_0;
kp = keypair::generate();
// change tx pub key to end up with different tx hash
update_or_add_field_to_extra(tx_2.extra, kp.pub);
r = resign_tx(m_miner_acc.get_keys(), sources, tx_2);
CHECK_AND_ASSERT_MES(r, false, "resign_tx failed");
LOG_PRINT_YELLOW("tx_2 = " << get_transaction_hash(tx_2), LOG_LEVEL_0);
events.push_back(tx_1);
DO_CALLBACK_PARAMS(events, "check_tx_pool_count", static_cast<size_t>(1));
// as long as tx_0 is using the same key image as tx_1, tx_0 and tx_2 can't be added to the pool atm
// make sure that it's true
DO_CALLBACK(events, "mark_invalid_tx");
events.push_back(tx_0);
DO_CALLBACK(events, "mark_invalid_tx");
events.push_back(tx_2);
// however, tx_0 and tx_2 can be added with kept_by_block flag (to simulate it's going with blk_1)
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true));
events.push_back(tx_0);
events.push_back(tx_2);
events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false));
DO_CALLBACK_PARAMS(events, "check_tx_pool_count", static_cast<size_t>(3));
// make a block with tx_0 and put tx_0 to the blockchain
MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, m_miner_acc, tx_0);
DO_CALLBACK_PARAMS(events, "check_tx_pool_count", static_cast<size_t>(2));
// tx_1 and tx_2 is still in the pool
// it can never be added to any block as long as blk_1 is in the blockchain due to key image conflict
DO_CALLBACK(events, "mark_invalid_block");
MAKE_NEXT_BLOCK_TX1(events, blk_2_bad, blk_1, m_miner_acc, tx_1);
// add tx_1 to alt block, it should go well
MAKE_NEXT_BLOCK_TX1(events, blk_1a, blk_0r, m_miner_acc, tx_1);
// however, it does not remove tx from the pool
DO_CALLBACK_PARAMS(events, "check_tx_pool_count", static_cast<size_t>(2));
MAKE_NEXT_BLOCK(events, blk_2, blk_1, m_miner_acc);
DO_CALLBACK(events, "remove_stuck_txs");
// remove_stuck_txs should not remove anything, tx_1 and tx_2 should be in the pool
DO_CALLBACK_PARAMS(events, "check_tx_pool_count", static_cast<size_t>(2));
// shift time by CURRENCY_MEMPOOL_TX_LIVETIME
events.push_back(event_core_time(CURRENCY_MEMPOOL_TX_LIVETIME + 1, true));
// remove_stuck_txs should remove only tx_2 and left tx_1
DO_CALLBACK(events, "remove_stuck_txs");
DO_CALLBACK_PARAMS(events, "check_tx_pool_count", static_cast<size_t>(1));
DO_CALLBACK(events, "print_tx_pool");
return true;
}
bool tx_key_image_pool_conflict::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
{
bool r = false;
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "incorrect tx pool count = " << c.get_pool_transactions_count());
// try to mine a block and make sure tx_1 is still in the pool (was not added to the blocktemplate)
block b;
r = mine_next_pow_block_in_playtime(m_miner_acc.get_public_address(), c, &b);
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed");
// make sure tx_1 is still here
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "incorrect tx pool count = " << c.get_pool_transactions_count());
return true;
}
bool tx_key_image_pool_conflict::c2(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
{
return true;
}

View file

@ -147,3 +147,13 @@ struct tx_expiration_time_and_chain_switching : public test_chain_unit_enchanced
{
bool generate(std::vector<test_event_entry>& events) const;
};
struct tx_key_image_pool_conflict : public test_chain_unit_enchanced
{
tx_key_image_pool_conflict();
bool generate(std::vector<test_event_entry>& events) const;
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
bool c2(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
mutable currency::account_base m_miner_acc;
};

View file

@ -32,10 +32,10 @@ bool wallet_rpc_integrated_address::generate(std::vector<test_event_entry>& even
epee::json_rpc::error je;
tools::wallet_rpc_server::connection_context ctx;
tools::wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::request mia_req = AUTO_VAL_INIT(mia_req);
tools::wallet_rpc::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::response mia_res = AUTO_VAL_INIT(mia_res);
tools::wallet_rpc::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::request sia_req = AUTO_VAL_INIT(sia_req);
tools::wallet_rpc::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::response sia_res = AUTO_VAL_INIT(sia_res);
tools::wallet_public::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::request mia_req = AUTO_VAL_INIT(mia_req);
tools::wallet_public::COMMAND_RPC_MAKE_INTEGRATED_ADDRESS::response mia_res = AUTO_VAL_INIT(mia_res);
tools::wallet_public::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::request sia_req = AUTO_VAL_INIT(sia_req);
tools::wallet_public::COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS::response sia_res = AUTO_VAL_INIT(sia_res);
// 1. make_integrated_address with empty payment id (should use a random payment id instead) + on_split_integrated_address
mia_req.payment_id = "";
@ -114,15 +114,15 @@ bool wallet_rpc_integrated_address_transfer::c1(currency::core& c, size_t ev_ind
epee::json_rpc::error je;
tools::wallet_rpc_server::connection_context ctx;
tools::wallet_rpc::COMMAND_RPC_TRANSFER::request req = AUTO_VAL_INIT(req);
tools::wallet_public::COMMAND_RPC_TRANSFER::request req = AUTO_VAL_INIT(req);
req.fee = TESTS_DEFAULT_FEE;
req.mixin = 0;
tools::wallet_rpc::trnsfer_destination tds = AUTO_VAL_INIT(tds);
tools::wallet_public::trnsfer_destination tds = AUTO_VAL_INIT(tds);
tds.address = alice_integrated_address;
tds.amount = MK_TEST_COINS(3);
req.destinations.push_back(tds);
tools::wallet_rpc::COMMAND_RPC_TRANSFER::response res = AUTO_VAL_INIT(res);
tools::wallet_public::COMMAND_RPC_TRANSFER::response res = AUTO_VAL_INIT(res);
// 1. integrated address + external payment id => the following should fail
req.payment_id = "90210";
@ -152,7 +152,7 @@ bool wallet_rpc_integrated_address_transfer::c1(currency::core& c, size_t ev_ind
// 3. standard address + invalid external payment id => fail
req.destinations.clear();
tools::wallet_rpc::trnsfer_destination tds2 = AUTO_VAL_INIT(tds2);
tools::wallet_public::trnsfer_destination tds2 = AUTO_VAL_INIT(tds2);
tds2.address = m_accounts[ALICE_ACC_IDX].get_public_address_str();
tds2.amount = MK_TEST_COINS(7);
req.destinations.push_back(tds2);

View file

@ -6,7 +6,7 @@
#include "chaingen.h"
#include "wallet_tests.h"
#include "wallet_test_core_proxy.h"
#include "../../src/wallet/wallet_rpc_server_commans_defs.h"
#include "../../src/wallet/wallet_public_structs_defs.h"
#include "offers_helper.h"
#include "string_coding.h"
#include "random_helper.h"
@ -24,9 +24,9 @@ const currency::account_base null_account = AUTO_VAL_INIT(null_account);
struct wlt_lambda_on_transfer2_wrapper : public tools::i_wallet2_callback
{
typedef std::function<bool(const tools::wallet_rpc::wallet_transfer_info&, uint64_t, uint64_t, uint64_t)> Func;
typedef std::function<bool(const tools::wallet_public::wallet_transfer_info&, uint64_t, uint64_t, uint64_t)> Func;
wlt_lambda_on_transfer2_wrapper(Func callback) : m_result(false), m_callback(callback) {}
virtual void on_transfer2(const tools::wallet_rpc::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) override
virtual void on_transfer2(const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) override
{
m_result = m_callback(wti, balance, unlocked_balance, total_mined);
}
@ -669,7 +669,7 @@ bool gen_wallet_unconfirmed_outdated_tx::c1(currency::core& c, size_t ev_index,
if (!check_balance_via_wallet(*alice_wlt.get(), "alice_wlt", MK_TEST_COINS(200), 0, 0, MK_TEST_COINS(200), 0))
return false;
std::vector<tools::wallet_rpc::wallet_transfer_info> trs;
std::vector<tools::wallet_public::wallet_transfer_info> trs;
alice_wlt->get_unconfirmed_transfers(trs);
CHECK_AND_ASSERT_MES(trs.size() == 1, false, "Incorrect num of unconfirmed tx");
@ -697,7 +697,7 @@ bool gen_wallet_unconfirmed_outdated_tx::c2(currency::core& c, size_t ev_index,
if (!check_balance_via_wallet(*alice_wlt.get(), "alice_wlt", MK_TEST_COINS(700), 0, 0, MK_TEST_COINS(700), 0))
return false;
std::vector<tools::wallet_rpc::wallet_transfer_info> trs;
std::vector<tools::wallet_public::wallet_transfer_info> trs;
alice_wlt->get_unconfirmed_transfers(trs);
CHECK_AND_ASSERT_MES(trs.size() == 2, false, "Incorrect num of unconfirmed tx");
CHECK_AND_ASSERT_MES(trs[0].timestamp != trs[1].timestamp, false, "wallet set the same timestamp for unconfirmed txs which came not simultaneously");
@ -726,7 +726,7 @@ bool gen_wallet_unconfirmed_outdated_tx::c3(currency::core& c, size_t ev_index,
if (!check_balance_via_wallet(*alice_wlt.get(), "alice_wlt", MK_TEST_COINS(500), 0, 0, MK_TEST_COINS(500), 0))
return false;
std::vector<tools::wallet_rpc::wallet_transfer_info> trs;
std::vector<tools::wallet_public::wallet_transfer_info> trs;
alice_wlt->get_unconfirmed_transfers(trs);
CHECK_AND_ASSERT_MES(trs.size() == 1, false, "Incorrect num of unconfirmed tx");
@ -1551,7 +1551,7 @@ bool gen_wallet_decrypted_attachments::generate(std::vector<test_event_entry>& e
return true;
}
void gen_wallet_decrypted_attachments::on_transfer2(const tools::wallet_rpc::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined)
void gen_wallet_decrypted_attachments::on_transfer2(const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined)
{
m_on_transfer2_called = true;
//try {
@ -1777,7 +1777,7 @@ bool gen_wallet_alias_via_special_wallet_funcs::c1(currency::core& c, size_t ev_
uint64_t biggest_alias_reward = get_alias_coast_from_fee("a", TESTS_DEFAULT_FEE);
std::shared_ptr<wlt_lambda_on_transfer2_wrapper> l(new wlt_lambda_on_transfer2_wrapper(
[biggest_alias_reward](const tools::wallet_rpc::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) -> bool {
[biggest_alias_reward](const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) -> bool {
return std::count(wti.recipients_aliases.begin(), wti.recipients_aliases.end(), "minerminer") == 1 &&
wti.amount == biggest_alias_reward;
}
@ -3259,7 +3259,7 @@ bool wallet_unconfimed_tx_balance::c1(currency::core& c, size_t ev_index, const
bool callback_is_ok = false;
// this callback will ba called from within wallet2::transfer() below
std::shared_ptr<wlt_lambda_on_transfer2_wrapper> l(new wlt_lambda_on_transfer2_wrapper(
[&callback_is_ok](const tools::wallet_rpc::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) -> bool
[&callback_is_ok](const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) -> bool
{
CHECK_AND_ASSERT_MES(balance == MK_TEST_COINS(70), false, "invalid balance: " << print_money_brief(balance));
CHECK_AND_ASSERT_MES(unlocked_balance == MK_TEST_COINS(50), false, "invalid unlocked_balance: " << print_money_brief(unlocked_balance));

View file

@ -111,7 +111,7 @@ struct gen_wallet_decrypted_attachments : public wallet_test, virtual public too
bool generate(std::vector<test_event_entry>& events) const;
// intrface tools::i_wallet2_callback
virtual void on_transfer2(const tools::wallet_rpc::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) override;
virtual void on_transfer2(const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) override;
private:
mutable bool m_on_transfer2_called;

View file

@ -6,7 +6,7 @@
#include "chaingen.h"
#include "wallet_tests.h"
#include "wallet_test_core_proxy.h"
#include "../../src/wallet/wallet_rpc_server_commans_defs.h"
#include "../../src/wallet/wallet_public_structs_defs.h"
#include "offers_helper.h"
#include "string_coding.h"

View file

@ -0,0 +1,87 @@
#pragma once
#include <cstdio>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>
#include <array>
#include <boost/filesystem.hpp>
#include "misc_log_ex.h"
std::string exec(const char* cmd)
{
std::array<char, 1024> buffer;
#if defined(WIN32)
std::unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(cmd, "r"), _pclose);
#else
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
#endif
if (!pipe)
throw std::runtime_error("popen() failed!");
std::string result;
while (fgets(buffer.data(), static_cast<int>(buffer.size()), pipe.get()) != nullptr)
result += buffer.data();
return result;
}
void free_space_check()
{
namespace fs = boost::filesystem;
std::string output;
#ifdef WIN32
output = exec("dir");
#else
output = exec("df -h");
#endif
LOG_PRINT_L0("test command output:" << std::endl << output);
boost::filesystem::path current_path(".");
size_t counter = 0;
while (true)
{
std::this_thread::sleep_for(std::chrono::milliseconds( 900 ));
try
{
fs::space_info si = fs::space(current_path);
if (si.available > 1024)
{
// free space is ok
counter = (counter + 1) % 4;
std::cout << '\b';
std::cout << ( counter == 0 ? '*' : counter == 1 ? '\\' : counter == 2 ? '|' : '/' );
continue;
}
// free space is not ok!
LOG_PRINT_YELLOW("free space available: " << si.available, LOG_LEVEL_0);
#ifdef WIN32
output = exec("dir");
#else
output = exec("df -h");
#endif
LOG_PRINT_YELLOW(output, LOG_LEVEL_0);
}
catch (std::exception& e)
{
LOG_ERROR("failed to determine free space: " << e.what());
}
catch (...)
{
LOG_ERROR("failed to determine free space: unknown exception");
}
}
}

View file

@ -19,6 +19,8 @@
#include "serialization_performance_test.h"
#include "keccak_test.h"
#include "blake2_test.h"
#include "print_struct_to_json.h"
#include "free_space_check.h"
int main(int argc, char** argv)
{
@ -33,7 +35,11 @@ int main(int argc, char** argv)
set_process_affinity(1);
set_thread_high_priority();
test_blake2();
//test_blake2();
free_space_check();
//print_struct_to_json();
//performance_timer timer;
//timer.start();

View file

@ -0,0 +1,26 @@
// Copyright (c) 2012-2013 The Boolberry developers
// Copyright (c) 2012-2013 The Zano developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
#include "currency_core/currency_basic.h"
#include "rpc/core_rpc_server_commands_defs.h"
#include "wallet/wallet_public_structs_defs.h"
inline bool print_struct_to_json()
{
tools::wallet_public::COMMAND_MARKETPLACE_PUSH_OFFER::request of = AUTO_VAL_INIT(of);
tools::wallet_public::COMMAND_MARKETPLACE_PUSH_UPDATE_OFFER::request uo = AUTO_VAL_INIT(uo);
bc_services::core_offers_filter ft = AUTO_VAL_INIT(ft);
std::string s = epee::serialization::store_t_to_json(of);
s = epee::serialization::store_t_to_json(ft);
s = epee::serialization::store_t_to_json(uo);
return true;
}

View file

@ -17,8 +17,8 @@ bool if_alt_chain_stronger(const currency::wide_difficulty_type& pos, const curr
alt_cumul_diff.pos_diff = pos;
static currency::wide_difficulty_type difficulty_pos_at_split_point = 400000;
static currency::wide_difficulty_type difficulty_pow_at_split_point = 4000;
currency::wide_difficulty_type main = currency::get_a_to_b_relative_cumulative_difficulty(difficulty_pos_at_split_point, difficulty_pow_at_split_point, main_cumul_diff, alt_cumul_diff);
currency::wide_difficulty_type alt = currency::get_a_to_b_relative_cumulative_difficulty(difficulty_pos_at_split_point, difficulty_pow_at_split_point, alt_cumul_diff, main_cumul_diff);
boost::multiprecision::uint1024_t main = currency::get_a_to_b_relative_cumulative_difficulty(difficulty_pos_at_split_point, difficulty_pow_at_split_point, main_cumul_diff, alt_cumul_diff);
boost::multiprecision::uint1024_t alt = currency::get_a_to_b_relative_cumulative_difficulty(difficulty_pos_at_split_point, difficulty_pow_at_split_point, alt_cumul_diff, main_cumul_diff);
if (alt > main)
return true;
return false;

View file

@ -0,0 +1,53 @@
// Copyright (c) 2019 Zano Project
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "gtest/gtest.h"
#include "common/util.h"
TEST(p2p_client_version, test_1)
{
using namespace tools;
// good
ASSERT_TRUE(check_remote_client_version("10.101.999.28391[deadbeef31337-dirty]"));
ASSERT_TRUE(check_remote_client_version("1.1.9.237[aabcd]"));
ASSERT_TRUE(check_remote_client_version("3.0.2.7[aa00bcd]"));
ASSERT_TRUE(check_remote_client_version("1.4.2.7[aabcd]"));
ASSERT_TRUE(check_remote_client_version("1.1.2.67[88f868c]"));
ASSERT_TRUE(check_remote_client_version("1.1.2.67[88f868c]"));
ASSERT_TRUE(check_remote_client_version("1.1.2.67[26c00a8]"));
ASSERT_TRUE(check_remote_client_version("1.1.2.67[26c00a8-dirty]"));
ASSERT_TRUE(check_remote_client_version("1.1.0.65[40ba8cd]"));
ASSERT_TRUE(check_remote_client_version("1.1.0.63[b0f376b]"));
ASSERT_TRUE(check_remote_client_version("1.1.0.58[14bd668]"));
ASSERT_TRUE(check_remote_client_version("1.1.0.58[9920eb7]"));
ASSERT_TRUE(check_remote_client_version("1.1.0.58[e0d4ad8]"));
ASSERT_TRUE(check_remote_client_version("1.1.0.57[b77b915]"));
ASSERT_TRUE(check_remote_client_version("1.1.0.57[7dd61ae]"));
ASSERT_TRUE(check_remote_client_version("1.1.0.57[7dd61ae-dirty]"));
ASSERT_TRUE(check_remote_client_version("1.1.0.57"));
// bad
ASSERT_FALSE(check_remote_client_version(""));
ASSERT_FALSE(check_remote_client_version(" "));
ASSERT_FALSE(check_remote_client_version("1.0.999"));
ASSERT_FALSE(check_remote_client_version("1.0.40[f77f0d7]"));
ASSERT_FALSE(check_remote_client_version("1.0.40[734b726]"));
ASSERT_FALSE(check_remote_client_version("1.0.41[488e369]"));
ASSERT_FALSE(check_remote_client_version("1.0.40[469]"));
ASSERT_FALSE(check_remote_client_version("1.0.39[f77f0d7]"));
ASSERT_FALSE(check_remote_client_version("1.0.38[f77f0d7-dirty]"));
ASSERT_FALSE(check_remote_client_version("1.0.37[7dd61ae-dirty]"));
ASSERT_FALSE(check_remote_client_version("0.0.500[000]"));
}

View file

@ -0,0 +1,10 @@
{
"jsonrpc": "2.0",
"id": 0,
"method": "marketplace_cancel_offer",
"params": {
"no": 0,
"tx_id": "1ca72152db6b962e473a0f838c281c902b7e1ed79c0a762bdb197ccf7f4ab2d5",
"fee": 10000000000
}
}

View file

@ -0,0 +1,8 @@
{
"id": 0,
"jsonrpc": "2.0",
"result": {
"tx_blob_size": 368,
"tx_hash": "d52014dae0b65168e0551acef9e95972041f3f38d92455d18c8b886baece3d90"
}
}

View file

@ -0,0 +1,28 @@
{
"jsonrpc": "2.0",
"id": 0,
"method": "marketplace_get_offers_ex",
"params": {
"filter": {
"amount_low_limit": 0,
"amount_up_limit": 0,
"bonus": false,
"category": "",
"fake": false,
"keyword": "",
"limit": 100,
"location_city": "",
"location_country": "",
"offer_type_mask": 0,
"offset": 0,
"order_by": 0,
"primary": "",
"rate_low_limit": "0.000000",
"rate_up_limit": "0.000000",
"reverse": false,
"target": "",
"timestamp_start": 0,
"timestamp_stop": 0
}
}
}

View file

@ -0,0 +1,51 @@
{
"id": 0,
"jsonrpc": "2.0",
"result": {
"offers": [{
"ap": "20",
"at": "1",
"b": "",
"cat": "CLS:MAN:TSH",
"cnt": "Skype: some_skype, discord: some_user#01012",
"com": "Some nice comments about tshirt",
"do": "Additional conditions",
"et": 10,
"fee": 10000000000,
"index_in_tx": 0,
"lci": "",
"lco": "World Wide",
"ot": 1,
"p": "USD",
"pt": "Credit cards, BTC, ZANO, ETH",
"security": "0000000000000000000000000000000000000000000000000000000000000000",
"t": "T-shirt with Zano logo, made by Crypjunkie",
"timestamp": 1570219600,
"tx_hash": "6ba12c5d2c66d31f770bfdc88ae9dc90d007b9b33f946fc7c1d9750f8655331c",
"tx_original_hash": "0000000000000000000000000000000000000000000000000000000000000000"
},{
"ap": "20",
"at": "1",
"b": "",
"cat": "CLS:MAN:TSH",
"cnt": "Skype: some_skype, discord: some_user#01012",
"com": "Some nice comments about tshirt",
"do": "Additional conditions",
"et": 10,
"fee": 10000000000,
"index_in_tx": 0,
"lci": "",
"lco": "World Wide",
"ot": 1,
"p": "USD",
"pt": "Credit cards, BTC, ZANO, ETH",
"security": "0000000000000000000000000000000000000000000000000000000000000000",
"t": "T-shirt with Zano logo, made by Crypjunkie",
"timestamp": 1570219840,
"tx_hash": "2987b671cc337203628a3a1bb7ac811e41f110864d6162d3c2276d2c79f694d6",
"tx_original_hash": "0000000000000000000000000000000000000000000000000000000000000000"
}],
"status": "",
"total_offers": 0
}
}

View file

@ -0,0 +1,28 @@
{
"jsonrpc": "2.0",
"id": 0,
"method": "marketplace_global_get_offers_ex",
"params": {
"filter": {
"amount_low_limit": 0,
"amount_up_limit": 0,
"bonus": false,
"category": "",
"fake": false,
"keyword": "",
"limit": 100,
"location_city": "",
"location_country": "",
"offer_type_mask": 0,
"offset": 0,
"order_by": 0,
"primary": "",
"rate_low_limit": "0.000000",
"rate_up_limit": "0.000000",
"reverse": false,
"target": "",
"timestamp_start": 0,
"timestamp_stop": 0
}
}
}

View file

@ -0,0 +1,23 @@
{
"jsonrpc": "2.0",
"id": 0,
"method": "marketplace_push_offer",
"params": {
"od": {
"ap": "20",
"at": "1",
"cat": "CLS:MAN:TSH",
"cnt": "Skype: some_skype, discord: some_user#01012",
"com": "Some nice comments about tshirt",
"do": "Additional conditions",
"et": 10,
"fee": 10000000000,
"lci": "",
"lco": "World Wide",
"ot": 1,
"p": "USD",
"pt": "Credit cards, BTC, ZANO, ETH",
"t": "T-shirt with Zano logo, made by Crypjunkie[4]"
}
}
}

View file

@ -0,0 +1,23 @@
{
"jsonrpc": "2.0",
"id": 0,
"method": "marketplace_push_offer",
"params": {
"od": {
"ap": "10000",
"at": "1",
"cat": "HRD:MIN",
"cnt": "Skype: some_skype, discord: some_user#01012",
"com": "Some nice comments about farm",
"do": "Additional conditions",
"et": 10,
"fee": 10000000000,
"lci": "",
"lco": "World Wide",
"ot": 1,
"p": "USD",
"pt": "Credit cards, BTC, ZANO, ETH",
"t": "Mining farm built by Gigabyted[2]"
}
}
}

Some files were not shown because too many files have changed in this diff Show more