mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 10:37:37 -07:00
Merge pull request #6752
85899230d
simplewallet: allow setting tx keys when sending to a subaddress (moneromooo-monero)e916201f1
wallet2: fix setting tx keys when another is already set (moneromooo-monero)
This commit is contained in:
commit
a06c83db73
@ -208,7 +208,7 @@ namespace
|
|||||||
const char* USAGE_ADDRESS_BOOK("address_book [(add (<address>|<integrated address>) [<description possibly with whitespaces>])|(delete <index>)]");
|
const char* USAGE_ADDRESS_BOOK("address_book [(add (<address>|<integrated address>) [<description possibly with whitespaces>])|(delete <index>)]");
|
||||||
const char* USAGE_SET_VARIABLE("set <option> [<value>]");
|
const char* USAGE_SET_VARIABLE("set <option> [<value>]");
|
||||||
const char* USAGE_GET_TX_KEY("get_tx_key <txid>");
|
const char* USAGE_GET_TX_KEY("get_tx_key <txid>");
|
||||||
const char* USAGE_SET_TX_KEY("set_tx_key <txid> <tx_key>");
|
const char* USAGE_SET_TX_KEY("set_tx_key <txid> <tx_key> [<subaddress>]");
|
||||||
const char* USAGE_CHECK_TX_KEY("check_tx_key <txid> <txkey> <address>");
|
const char* USAGE_CHECK_TX_KEY("check_tx_key <txid> <txkey> <address>");
|
||||||
const char* USAGE_GET_TX_PROOF("get_tx_proof <txid> <address> [<message>]");
|
const char* USAGE_GET_TX_PROOF("get_tx_proof <txid> <address> [<message>]");
|
||||||
const char* USAGE_CHECK_TX_PROOF("check_tx_proof <txid> <address> <signature_file> [<message>]");
|
const char* USAGE_CHECK_TX_PROOF("check_tx_proof <txid> <address> <signature_file> [<message>]");
|
||||||
@ -7963,11 +7963,27 @@ bool simple_wallet::set_tx_key(const std::vector<std::string> &args_)
|
|||||||
{
|
{
|
||||||
std::vector<std::string> local_args = args_;
|
std::vector<std::string> local_args = args_;
|
||||||
|
|
||||||
if(local_args.size() != 2) {
|
if(local_args.size() != 2 && local_args.size() != 3) {
|
||||||
PRINT_USAGE(USAGE_SET_TX_KEY);
|
PRINT_USAGE(USAGE_SET_TX_KEY);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::optional<cryptonote::account_public_address> single_destination_subaddress;
|
||||||
|
if (local_args.size() > 1)
|
||||||
|
{
|
||||||
|
cryptonote::address_parse_info info;
|
||||||
|
if (cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), local_args.back(), oa_prompter))
|
||||||
|
{
|
||||||
|
if (!info.is_subaddress)
|
||||||
|
{
|
||||||
|
fail_msg_writer() << tr("Last argument is an address, but not a subaddress");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
single_destination_subaddress = info.address;
|
||||||
|
local_args.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
crypto::hash txid;
|
crypto::hash txid;
|
||||||
if (!epee::string_tools::hex_to_pod(local_args[0], txid))
|
if (!epee::string_tools::hex_to_pod(local_args[0], txid))
|
||||||
{
|
{
|
||||||
@ -8007,12 +8023,14 @@ bool simple_wallet::set_tx_key(const std::vector<std::string> &args_)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_wallet->set_tx_key(txid, tx_key, additional_tx_keys);
|
m_wallet->set_tx_key(txid, tx_key, additional_tx_keys, single_destination_subaddress);
|
||||||
success_msg_writer() << tr("Tx key successfully stored.");
|
success_msg_writer() << tr("Tx key successfully stored.");
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
fail_msg_writer() << tr("Failed to store tx key: ") << e.what();
|
fail_msg_writer() << tr("Failed to store tx key: ") << e.what();
|
||||||
|
if (!single_destination_subaddress)
|
||||||
|
fail_msg_writer() << tr("It could be because the transfer was to a subaddress. If this is the case, pass the subaddress last");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -6524,8 +6524,8 @@ void wallet2::commit_tx(pending_tx& ptx)
|
|||||||
add_unconfirmed_tx(ptx.tx, amount_in, dests, payment_id, ptx.change_dts.amount, ptx.construction_data.subaddr_account, ptx.construction_data.subaddr_indices);
|
add_unconfirmed_tx(ptx.tx, amount_in, dests, payment_id, ptx.change_dts.amount, ptx.construction_data.subaddr_account, ptx.construction_data.subaddr_indices);
|
||||||
if (store_tx_info() && ptx.tx_key != crypto::null_skey)
|
if (store_tx_info() && ptx.tx_key != crypto::null_skey)
|
||||||
{
|
{
|
||||||
m_tx_keys.insert(std::make_pair(txid, ptx.tx_key));
|
m_tx_keys[txid] = ptx.tx_key;
|
||||||
m_additional_tx_keys.insert(std::make_pair(txid, ptx.additional_tx_keys));
|
m_additional_tx_keys[txid] = ptx.additional_tx_keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_PRINT_L2("transaction " << txid << " generated ok and sent to daemon, key_images: [" << ptx.key_images << "]");
|
LOG_PRINT_L2("transaction " << txid << " generated ok and sent to daemon, key_images: [" << ptx.key_images << "]");
|
||||||
@ -6745,8 +6745,8 @@ bool wallet2::sign_tx(unsigned_tx_set &exported_txs, std::vector<wallet2::pendin
|
|||||||
if (store_tx_info() && tx_key != crypto::null_skey)
|
if (store_tx_info() && tx_key != crypto::null_skey)
|
||||||
{
|
{
|
||||||
const crypto::hash txid = get_transaction_hash(ptx.tx);
|
const crypto::hash txid = get_transaction_hash(ptx.tx);
|
||||||
m_tx_keys.insert(std::make_pair(txid, tx_key));
|
m_tx_keys[txid] = tx_key;
|
||||||
m_additional_tx_keys.insert(std::make_pair(txid, additional_tx_keys));
|
m_additional_tx_keys[txid] = additional_tx_keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string key_images;
|
std::string key_images;
|
||||||
@ -7194,8 +7194,8 @@ bool wallet2::load_multisig_tx(cryptonote::blobdata s, multisig_tx_set &exported
|
|||||||
const crypto::hash txid = get_transaction_hash(ptx.tx);
|
const crypto::hash txid = get_transaction_hash(ptx.tx);
|
||||||
if (store_tx_info())
|
if (store_tx_info())
|
||||||
{
|
{
|
||||||
m_tx_keys.insert(std::make_pair(txid, ptx.tx_key));
|
m_tx_keys[txid] = ptx.tx_key;
|
||||||
m_additional_tx_keys.insert(std::make_pair(txid, ptx.additional_tx_keys));
|
m_additional_tx_keys[txid] = ptx.additional_tx_keys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7315,8 +7315,8 @@ bool wallet2::sign_multisig_tx(multisig_tx_set &exported_txs, std::vector<crypto
|
|||||||
const crypto::hash txid = get_transaction_hash(ptx.tx);
|
const crypto::hash txid = get_transaction_hash(ptx.tx);
|
||||||
if (store_tx_info())
|
if (store_tx_info())
|
||||||
{
|
{
|
||||||
m_tx_keys.insert(std::make_pair(txid, ptx.tx_key));
|
m_tx_keys[txid] = ptx.tx_key;
|
||||||
m_additional_tx_keys.insert(std::make_pair(txid, ptx.additional_tx_keys));
|
m_additional_tx_keys[txid] = ptx.additional_tx_keys;
|
||||||
}
|
}
|
||||||
txids.push_back(txid);
|
txids.push_back(txid);
|
||||||
}
|
}
|
||||||
@ -11006,7 +11006,7 @@ bool wallet2::get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key, s
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
void wallet2::set_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys)
|
void wallet2::set_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, const boost::optional<cryptonote::account_public_address> &single_destination_subaddress)
|
||||||
{
|
{
|
||||||
// fetch tx from daemon and check if secret keys agree with corresponding public keys
|
// fetch tx from daemon and check if secret keys agree with corresponding public keys
|
||||||
COMMAND_RPC_GET_TRANSACTIONS::request req = AUTO_VAL_INIT(req);
|
COMMAND_RPC_GET_TRANSACTIONS::request req = AUTO_VAL_INIT(req);
|
||||||
@ -11047,13 +11047,23 @@ void wallet2::set_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_
|
|||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// when sent to a single subaddress, the derivation is different
|
||||||
|
if (single_destination_subaddress)
|
||||||
|
{
|
||||||
|
calculated_pub_key = rct::rct2pk(rct::scalarmultKey(rct::pk2rct(single_destination_subaddress->m_spend_public_key), rct::sk2rct(tx_key)));
|
||||||
|
if (calculated_pub_key == pub_key_field.pub_key)
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
THROW_WALLET_EXCEPTION_IF(!found, error::wallet_internal_error, "Given tx secret key doesn't agree with the tx public key in the blockchain");
|
THROW_WALLET_EXCEPTION_IF(!found, error::wallet_internal_error, "Given tx secret key doesn't agree with the tx public key in the blockchain");
|
||||||
tx_extra_additional_pub_keys additional_tx_pub_keys;
|
tx_extra_additional_pub_keys additional_tx_pub_keys;
|
||||||
find_tx_extra_field_by_type(tx_extra_fields, additional_tx_pub_keys);
|
find_tx_extra_field_by_type(tx_extra_fields, additional_tx_pub_keys);
|
||||||
THROW_WALLET_EXCEPTION_IF(additional_tx_keys.size() != additional_tx_pub_keys.data.size(), error::wallet_internal_error, "The number of additional tx secret keys doesn't agree with the number of additional tx public keys in the blockchain" );
|
THROW_WALLET_EXCEPTION_IF(additional_tx_keys.size() != additional_tx_pub_keys.data.size(), error::wallet_internal_error, "The number of additional tx secret keys doesn't agree with the number of additional tx public keys in the blockchain" );
|
||||||
m_tx_keys.insert(std::make_pair(txid, tx_key));
|
m_tx_keys[txid] = tx_key;
|
||||||
m_additional_tx_keys.insert(std::make_pair(txid, additional_tx_keys));
|
m_additional_tx_keys[txid] = additional_tx_keys;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
std::string wallet2::get_spend_proof(const crypto::hash &txid, const std::string &message)
|
std::string wallet2::get_spend_proof(const crypto::hash &txid, const std::string &message)
|
||||||
|
@ -1243,7 +1243,7 @@ private:
|
|||||||
void credits_target(uint64_t threshold) { m_credits_target = threshold; }
|
void credits_target(uint64_t threshold) { m_credits_target = threshold; }
|
||||||
|
|
||||||
bool get_tx_key_cached(const crypto::hash &txid, crypto::secret_key &tx_key, std::vector<crypto::secret_key> &additional_tx_keys) const;
|
bool get_tx_key_cached(const crypto::hash &txid, crypto::secret_key &tx_key, std::vector<crypto::secret_key> &additional_tx_keys) const;
|
||||||
void set_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys);
|
void set_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, const boost::optional<cryptonote::account_public_address> &single_destination_subaddress = boost::none);
|
||||||
bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key, std::vector<crypto::secret_key> &additional_tx_keys);
|
bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key, std::vector<crypto::secret_key> &additional_tx_keys);
|
||||||
void check_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations);
|
void check_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations);
|
||||||
void check_tx_key_helper(const crypto::hash &txid, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations);
|
void check_tx_key_helper(const crypto::hash &txid, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations);
|
||||||
|
Loading…
Reference in New Issue
Block a user