@ -127,6 +127,7 @@ namespace
const command_line : : arg_descriptor < bool > arg_restore_multisig_wallet = { " restore-multisig-wallet " , sw : : tr ( " Recover multisig wallet using Electrum-style mnemonic seed " ) , false } ;
const command_line : : arg_descriptor < bool > arg_non_deterministic = { " non-deterministic " , sw : : tr ( " Generate non-deterministic view and spend keys " ) , false } ;
const command_line : : arg_descriptor < bool > arg_trusted_daemon = { " trusted-daemon " , sw : : tr ( " Enable commands which rely on a trusted daemon " ) , false } ;
const command_line : : arg_descriptor < bool > arg_untrusted_daemon = { " untrusted-daemon " , sw : : tr ( " Disable commands which rely on a trusted daemon " ) , false } ;
const command_line : : arg_descriptor < bool > arg_allow_mismatched_daemon_version = { " allow-mismatched-daemon-version " , sw : : tr ( " Allow communicating with a daemon that uses a different RPC version " ) , false } ;
const command_line : : arg_descriptor < uint64_t > arg_restore_height = { " restore-height " , sw : : tr ( " Restore from specific blockchain height " ) , 0 } ;
const command_line : : arg_descriptor < bool > arg_do_not_relay = { " do-not-relay " , sw : : tr ( " The newly created transaction will not be relayed to the wownero network " ) , false } ;
@ -376,21 +377,10 @@ namespace
boost : : optional < std : : pair < uint32_t , uint32_t > > parse_subaddress_lookahead ( const std : : string & str )
{
auto pos = str . find ( " : " ) ;
bool r = pos ! = std : : string : : npos ;
uint32_t major ;
r = r & & epee : : string_tools : : get_xtype_from_string ( major , str . substr ( 0 , pos ) ) ;
uint32_t minor ;
r = r & & epee : : string_tools : : get_xtype_from_string ( minor , str . substr ( pos + 1 ) ) ;
if ( r )
{
return std : : make_pair ( major , minor ) ;
}
else
{
auto r = tools : : parse_subaddress_lookahead ( str ) ;
if ( ! r )
fail_msg_writer ( ) < < tr ( " invalid format for subaddress lookahead; must be <major>:<minor> " ) ;
return { } ;
}
return r ;
}
void handle_transfer_exception ( const std : : exception_ptr & e , bool trusted_daemon )
@ -1060,7 +1050,7 @@ bool simple_wallet::import_multisig(const std::vector<std::string> &args)
fail_msg_writer ( ) < < tr ( " Failed to import multisig info: " ) < < e . what ( ) ;
return true ;
}
if ( m_trusted_daemon )
if ( is_daemon_trusted( ) )
{
try
{
@ -1212,7 +1202,7 @@ bool simple_wallet::submit_multisig(const std::vector<std::string> &args)
}
catch ( const std : : exception & e )
{
handle_transfer_exception ( std : : current_exception ( ) , m_trusted_daemon ) ;
handle_transfer_exception ( std : : current_exception ( ) , is_daemon_trusted( ) ) ;
}
catch ( . . . )
{
@ -1989,7 +1979,7 @@ simple_wallet::simple_wallet()
tr ( " Stop mining in the daemon. " ) ) ;
m_cmd_binder . set_handler ( " set_daemon " ,
boost : : bind ( & simple_wallet : : set_daemon , this , _1 ) ,
tr ( " set_daemon <host>[:<port>] " ) ,
tr ( " set_daemon <host>[:<port>] [trusted|untrusted] " ) ,
tr ( " Set another daemon to connect to. " ) ) ;
m_cmd_binder . set_handler ( " save_bc " ,
boost : : bind ( & simple_wallet : : save_bc , this , _1 ) ,
@ -3078,18 +3068,22 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
return false ;
}
// set --trusted-daemon if local
try
// set --trusted-daemon if local and not overridden
if ( ! m_trusted_daemon )
{
if ( tools : : is_local_address ( m_wallet - > get_daemon_address ( ) ) )
try
{
MINFO ( tr ( " Daemon is local, assuming trusted " ) ) ;
m_trusted_daemon = true ;
m_trusted_daemon = false ;
if ( tools : : is_local_address ( m_wallet - > get_daemon_address ( ) ) )
{
MINFO ( tr ( " Daemon is local, assuming trusted " ) ) ;
m_trusted_daemon = true ;
}
}
catch ( const std : : exception & e ) { }
}
catch ( const std : : exception & e ) { }
if ( ! m_trusted_daemon )
if ( ! is_daemon_trusted( ) )
message_writer ( ) < < ( boost : : format ( tr ( " Warning: using an untrusted daemon at %s, privacy will be lessened " ) ) % m_wallet - > get_daemon_address ( ) ) . str ( ) ;
if ( m_wallet - > get_ring_database ( ) . empty ( ) )
@ -3123,7 +3117,10 @@ bool simple_wallet::handle_command_line(const boost::program_options::variables_
m_restore_deterministic_wallet = command_line : : get_arg ( vm , arg_restore_deterministic_wallet ) ;
m_restore_multisig_wallet = command_line : : get_arg ( vm , arg_restore_multisig_wallet ) ;
m_non_deterministic = command_line : : get_arg ( vm , arg_non_deterministic ) ;
m_trusted_daemon = command_line : : get_arg ( vm , arg_trusted_daemon ) ;
if ( ! command_line : : is_arg_defaulted ( vm , arg_trusted_daemon ) | | ! command_line : : is_arg_defaulted ( vm , arg_untrusted_daemon ) )
m_trusted_daemon = command_line : : get_arg ( vm , arg_trusted_daemon ) & & ! command_line : : get_arg ( vm , arg_untrusted_daemon ) ;
if ( ! command_line : : is_arg_defaulted ( vm , arg_trusted_daemon ) & & ! command_line : : is_arg_defaulted ( vm , arg_untrusted_daemon ) )
message_writer ( ) < < tr ( " --trusted-daemon and --untrusted-daemon are both seen, assuming untrusted " ) ;
m_allow_mismatched_daemon_version = command_line : : get_arg ( vm , arg_allow_mismatched_daemon_version ) ;
m_restore_height = command_line : : get_arg ( vm , arg_restore_height ) ;
m_do_not_relay = command_line : : get_arg ( vm , arg_do_not_relay ) ;
@ -3612,7 +3609,7 @@ bool simple_wallet::save_watch_only(const std::vector<std::string> &args/* = std
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : start_mining ( const std : : vector < std : : string > & args )
{
if ( ! m_trusted_daemon )
if ( ! is_daemon_trusted( ) )
{
fail_msg_writer ( ) < < tr ( " this command requires a trusted daemon. Enable with --trusted-daemon " ) ;
return true ;
@ -3723,6 +3720,33 @@ bool simple_wallet::set_daemon(const std::vector<std::string>& args)
}
LOCK_IDLE_SCOPE ( ) ;
m_wallet - > init ( daemon_url ) ;
if ( args . size ( ) = = 2 )
{
if ( args [ 1 ] = = " trusted " )
m_trusted_daemon = true ;
else if ( args [ 1 ] = = " untrusted " )
m_trusted_daemon = false ;
else
{
fail_msg_writer ( ) < < tr ( " Expected trusted or untrusted, got " ) < < args [ 1 ] < < " : assuming untrusted " ;
m_trusted_daemon = false ;
}
}
else
{
m_trusted_daemon = false ;
try
{
if ( tools : : is_local_address ( m_wallet - > get_daemon_address ( ) ) )
{
MINFO ( tr ( " Daemon is local, assuming trusted " ) ) ;
m_trusted_daemon = true ;
}
}
catch ( const std : : exception & e ) { }
}
success_msg_writer ( ) < < boost : : format ( " Daemon set to %s, %s " ) % daemon_url % ( * m_trusted_daemon ? tr ( " trusted " ) : tr ( " untrusted " ) ) ;
} else {
fail_msg_writer ( ) < < tr ( " This does not seem to be a valid daemon URL. " ) ;
}
@ -4108,7 +4132,7 @@ bool simple_wallet::show_blockchain_height(const std::vector<std::string>& args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet : : rescan_spent ( const std : : vector < std : : string > & args )
{
if ( ! m_trusted_daemon )
if ( ! is_daemon_trusted( ) )
{
fail_msg_writer ( ) < < tr ( " this command requires a trusted daemon. Enable with --trusted-daemon " ) ;
return true ;
@ -4439,16 +4463,16 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
return true ;
}
unlock_block = bc_height + locked_blocks ;
ptx_vector = m_wallet - > create_transactions_2 ( dsts , fake_outs_count , unlock_block /* unlock_time */ , priority , extra , m_current_subaddress_account , subaddr_indices , m_trusted_daemon ) ;
ptx_vector = m_wallet - > create_transactions_2 ( dsts , fake_outs_count , unlock_block /* unlock_time */ , priority , extra , m_current_subaddress_account , subaddr_indices , is_daemon_trusted( ) ) ;
break ;
case TransferNew :
ptx_vector = m_wallet - > create_transactions_2 ( dsts , fake_outs_count , 0 /* unlock_time */ , priority , extra , m_current_subaddress_account , subaddr_indices , m_trusted_daemon ) ;
ptx_vector = m_wallet - > create_transactions_2 ( dsts , fake_outs_count , 0 /* unlock_time */ , priority , extra , m_current_subaddress_account , subaddr_indices , is_daemon_trusted( ) ) ;
break ;
default :
LOG_ERROR ( " Unknown transfer method, using original " ) ;
/* FALLTHRU */
case TransferOriginal :
ptx_vector = m_wallet - > create_transactions ( dsts , fake_outs_count , 0 /* unlock_time */ , priority , extra , m_trusted_daemon ) ;
ptx_vector = m_wallet - > create_transactions ( dsts , fake_outs_count , 0 /* unlock_time */ , priority , extra , is_daemon_trusted( ) ) ;
break ;
}
@ -4607,7 +4631,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
}
catch ( const std : : exception & e )
{
handle_transfer_exception ( std : : current_exception ( ) , m_trusted_daemon ) ;
handle_transfer_exception ( std : : current_exception ( ) , is_daemon_trusted( ) ) ;
}
catch ( . . . )
{
@ -4644,7 +4668,7 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
try
{
// figure out what tx will be necessary
auto ptx_vector = m_wallet - > create_unmixable_sweep_transactions ( m_trusted_daemon ) ;
auto ptx_vector = m_wallet - > create_unmixable_sweep_transactions ( is_daemon_trusted( ) ) ;
if ( ptx_vector . empty ( ) )
{
@ -4713,9 +4737,23 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
commit_or_save ( ptx_vector , m_do_not_relay ) ;
}
}
catch ( const tools : : error : : not_enough_unlocked_money & e )
{
fail_msg_writer ( ) < < tr ( " Not enough money in unlocked balance " ) ;
std : : string accepted = input_line ( ( boost : : format ( tr ( " Discarding %s of unmixable outputs that cannot be spent, which can be undone by \" rescan_spent \" . Is this okay? (Y/Yes/N/No): " ) ) % print_money ( e . available ( ) ) ) . str ( ) ) ;
if ( std : : cin . eof ( ) )
return true ;
if ( command_line : : is_yes ( accepted ) )
{
try
{
m_wallet - > discard_unmixable_outputs ( is_daemon_trusted ( ) ) ;
} catch ( . . . ) { }
}
}
catch ( const std : : exception & e )
{
handle_transfer_exception ( std : : current_exception ( ) , m_trusted_daemon ) ;
handle_transfer_exception ( std : : current_exception ( ) , is_daemon_trusted( ) ) ;
}
catch ( . . . )
{
@ -4846,7 +4884,7 @@ bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &a
try
{
// figure out what tx will be necessary
auto ptx_vector = m_wallet - > create_transactions_all ( below , info . address , info . is_subaddress , fake_outs_count , 0 /* unlock_time */ , priority , extra , m_current_subaddress_account , subaddr_indices , m_trusted_daemon ) ;
auto ptx_vector = m_wallet - > create_transactions_all ( below , info . address , info . is_subaddress , fake_outs_count , 0 /* unlock_time */ , priority , extra , m_current_subaddress_account , subaddr_indices , is_daemon_trusted( ) ) ;
if ( ptx_vector . empty ( ) )
{
@ -4930,7 +4968,7 @@ bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &a
}
catch ( const std : : exception & e )
{
handle_transfer_exception ( std : : current_exception ( ) , m_trusted_daemon ) ;
handle_transfer_exception ( std : : current_exception ( ) , is_daemon_trusted( ) ) ;
}
catch ( . . . )
{
@ -5045,7 +5083,7 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
try
{
// figure out what tx will be necessary
auto ptx_vector = m_wallet - > create_transactions_single ( ki , info . address , info . is_subaddress , fake_outs_count , 0 /* unlock_time */ , priority , extra , m_trusted_daemon ) ;
auto ptx_vector = m_wallet - > create_transactions_single ( ki , info . address , info . is_subaddress , fake_outs_count , 0 /* unlock_time */ , priority , extra , is_daemon_trusted( ) ) ;
if ( ptx_vector . empty ( ) )
{
@ -5115,7 +5153,7 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
}
catch ( const std : : exception & e )
{
handle_transfer_exception ( std : : current_exception ( ) , m_trusted_daemon ) ;
handle_transfer_exception ( std : : current_exception ( ) , is_daemon_trusted( ) ) ;
}
catch ( . . . )
{
@ -5420,7 +5458,7 @@ bool simple_wallet::submit_transfer(const std::vector<std::string> &args_)
}
catch ( const std : : exception & e )
{
handle_transfer_exception ( std : : current_exception ( ) , m_trusted_daemon ) ;
handle_transfer_exception ( std : : current_exception ( ) , is_daemon_trusted( ) ) ;
}
catch ( . . . )
{
@ -7008,7 +7046,7 @@ bool simple_wallet::import_key_images(const std::vector<std::string> &args)
fail_msg_writer ( ) < < tr ( " command not supported by HW wallet " ) ;
return true ;
}
if ( ! m_trusted_daemon )
if ( ! is_daemon_trusted( ) )
{
fail_msg_writer ( ) < < tr ( " this command requires a trusted daemon. Enable with --trusted-daemon " ) ;
return true ;
@ -7394,6 +7432,7 @@ int main(int argc, char* argv[])
command_line : : add_arg ( desc_params , arg_non_deterministic ) ;
command_line : : add_arg ( desc_params , arg_electrum_seed ) ;
command_line : : add_arg ( desc_params , arg_trusted_daemon ) ;
command_line : : add_arg ( desc_params , arg_untrusted_daemon ) ;
command_line : : add_arg ( desc_params , arg_allow_mismatched_daemon_version ) ;
command_line : : add_arg ( desc_params , arg_restore_height ) ;
command_line : : add_arg ( desc_params , arg_do_not_relay ) ;