mirror of
https://github.com/monero-project/monero.git
synced 2024-12-27 05:49:23 -05:00
wallet: only return tx keys via RPC if requested
To get the tx keys returned via RPC, set the "get_tx_key" or "get_tx_keys" request field to true (defaults to false).
This commit is contained in:
parent
32077d3810
commit
d91eb8c7b4
@ -408,7 +408,7 @@ namespace cryptonote
|
||||
return encrypt_payment_id(payment_id, public_key, secret_key);
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool construct_tx(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, std::vector<uint8_t> extra, transaction& tx, uint64_t unlock_time, crypto::secret_key &tx_key)
|
||||
bool construct_tx_and_get_tx_key(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, std::vector<uint8_t> extra, transaction& tx, uint64_t unlock_time, crypto::secret_key &tx_key)
|
||||
{
|
||||
tx.vin.clear();
|
||||
tx.vout.clear();
|
||||
@ -578,6 +578,12 @@ namespace cryptonote
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool construct_tx(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, std::vector<uint8_t> extra, transaction& tx, uint64_t unlock_time)
|
||||
{
|
||||
crypto::secret_key tx_key;
|
||||
return construct_tx_and_get_tx_key(sender_account_keys, sources, destinations, extra, tx, unlock_time, tx_key);
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool get_inputs_money_amount(const transaction& tx, uint64_t& money)
|
||||
{
|
||||
money = 0;
|
||||
|
@ -69,7 +69,8 @@ namespace cryptonote
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------
|
||||
bool construct_tx(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, std::vector<uint8_t> extra, transaction& tx, uint64_t unlock_time, crypto::secret_key &txkey);
|
||||
bool construct_tx(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, std::vector<uint8_t> extra, transaction& tx, uint64_t unlock_time);
|
||||
bool construct_tx_and_get_tx_key(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, std::vector<uint8_t> extra, transaction& tx, uint64_t unlock_time, crypto::secret_key &txkey);
|
||||
|
||||
template<typename T>
|
||||
bool find_tx_extra_field_by_type(const std::vector<tx_extra_field>& tx_extra_fields, T& field)
|
||||
|
@ -540,6 +540,9 @@ bool wallet2::store_keys(const std::string& keys_file_name, const std::string& p
|
||||
value2.SetInt(m_always_confirm_transfers ? 1 :0);
|
||||
json.AddMember("always_confirm_transfers", value2, json.GetAllocator());
|
||||
|
||||
value2.SetInt(m_store_tx_keys ? 1 :0);
|
||||
json.AddMember("store_tx_keys", value2, json.GetAllocator());
|
||||
|
||||
// Serialize the JSON object
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
@ -620,6 +623,7 @@ void wallet2::load_keys(const std::string& keys_file_name, const std::string& pa
|
||||
m_watch_only = false;
|
||||
}
|
||||
m_always_confirm_transfers = json.HasMember("always_confirm_transfers") && (json["always_confirm_transfers"].GetInt() != 0);
|
||||
m_store_tx_keys = json.HasMember("store_tx_keys") && (json["store_tx_keys"].GetInt() != 0);
|
||||
}
|
||||
|
||||
const cryptonote::account_keys& keys = m_account.get_keys();
|
||||
@ -1325,7 +1329,8 @@ void wallet2::commit_tx(pending_tx& ptx)
|
||||
|
||||
txid = get_transaction_hash(ptx.tx);
|
||||
add_unconfirmed_tx(ptx.tx, ptx.change_dts.amount);
|
||||
m_tx_keys.insert(std::make_pair(txid, ptx.tx_key));
|
||||
if (store_tx_keys())
|
||||
m_tx_keys.insert(std::make_pair(txid, ptx.tx_key));
|
||||
|
||||
LOG_PRINT_L2("transaction " << txid << " generated ok and sent to daemon, key_images: [" << ptx.key_images << "]");
|
||||
|
||||
@ -1578,7 +1583,7 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
|
||||
}
|
||||
|
||||
crypto::secret_key tx_key;
|
||||
bool r = cryptonote::construct_tx(m_account.get_keys(), sources, splitted_dsts, extra, tx, unlock_time, tx_key);
|
||||
bool r = cryptonote::construct_tx_and_get_tx_key(m_account.get_keys(), sources, splitted_dsts, extra, tx, unlock_time, tx_key);
|
||||
THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time, m_testnet);
|
||||
THROW_WALLET_EXCEPTION_IF(m_upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, m_upper_transaction_size_limit);
|
||||
|
||||
@ -1925,7 +1930,7 @@ void wallet2::transfer_dust(size_t num_outputs, uint64_t unlock_time, uint64_t n
|
||||
std::to_string(dust) + ", dust_threshold = " + std::to_string(dust_policy.dust_threshold));
|
||||
|
||||
crypto::secret_key tx_key;
|
||||
bool r = cryptonote::construct_tx(m_account.get_keys(), sources, splitted_dsts, extra, tx, unlock_time, tx_key);
|
||||
bool r = cryptonote::construct_tx_and_get_tx_key(m_account.get_keys(), sources, splitted_dsts, extra, tx, unlock_time, tx_key);
|
||||
THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time, m_testnet);
|
||||
THROW_WALLET_EXCEPTION_IF(m_upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, m_upper_transaction_size_limit);
|
||||
|
||||
|
@ -80,9 +80,9 @@ namespace tools
|
||||
|
||||
class wallet2
|
||||
{
|
||||
wallet2(const wallet2&) : m_run(true), m_callback(0), m_testnet(false), m_always_confirm_transfers (false) {};
|
||||
wallet2(const wallet2&) : m_run(true), m_callback(0), m_testnet(false), m_always_confirm_transfers (false), m_store_tx_keys(false) {};
|
||||
public:
|
||||
wallet2(bool testnet = false, bool restricted = false) : m_run(true), m_callback(0), m_testnet(testnet), m_restricted(restricted), is_old_file_format(false) {};
|
||||
wallet2(bool testnet = false, bool restricted = false) : m_run(true), m_callback(0), m_testnet(testnet), m_restricted(restricted), is_old_file_format(false), m_store_tx_keys(false) {};
|
||||
struct transfer_details
|
||||
{
|
||||
uint64_t m_block_height;
|
||||
@ -292,6 +292,8 @@ namespace tools
|
||||
|
||||
bool always_confirm_transfers() const { return m_always_confirm_transfers; }
|
||||
void always_confirm_transfers(bool always) { m_always_confirm_transfers = always; }
|
||||
bool store_tx_keys() const { return m_store_tx_keys; }
|
||||
void store_tx_keys(bool store) { m_store_tx_keys = store; }
|
||||
|
||||
bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key) const;
|
||||
|
||||
@ -351,6 +353,7 @@ namespace tools
|
||||
bool is_old_file_format; /*!< Whether the wallet file is of an old file format */
|
||||
bool m_watch_only; /*!< no spend key */
|
||||
bool m_always_confirm_transfers;
|
||||
bool m_store_tx_keys; /*!< request txkey to be returned in RPC, and store in the wallet cache file */
|
||||
};
|
||||
}
|
||||
BOOST_CLASS_VERSION(tools::wallet2, 8)
|
||||
@ -585,7 +588,7 @@ namespace tools
|
||||
}
|
||||
|
||||
crypto::secret_key tx_key;
|
||||
bool r = cryptonote::construct_tx(m_account.get_keys(), sources, splitted_dsts, extra, tx, unlock_time, tx_key);
|
||||
bool r = cryptonote::construct_tx_and_get_tx_key(m_account.get_keys(), sources, splitted_dsts, extra, tx, unlock_time, tx_key);
|
||||
THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time, m_testnet);
|
||||
THROW_WALLET_EXCEPTION_IF(m_upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, m_upper_transaction_size_limit);
|
||||
|
||||
|
@ -218,7 +218,8 @@ namespace tools
|
||||
|
||||
// populate response with tx hash
|
||||
res.tx_hash = boost::lexical_cast<std::string>(cryptonote::get_transaction_hash(ptx_vector.back().tx));
|
||||
res.tx_key = boost::lexical_cast<std::string>(ptx_vector.back().tx_key);
|
||||
if (req.get_tx_key)
|
||||
res.tx_key = boost::lexical_cast<std::string>(ptx_vector.back().tx_key);
|
||||
return true;
|
||||
}
|
||||
catch (const tools::error::daemon_busy& e)
|
||||
@ -275,7 +276,8 @@ namespace tools
|
||||
for (auto & ptx : ptx_vector)
|
||||
{
|
||||
res.tx_hash_list.push_back(boost::lexical_cast<std::string>(cryptonote::get_transaction_hash(ptx.tx)));
|
||||
res.tx_key_list.push_back(boost::lexical_cast<std::string>(ptx.tx_key));
|
||||
if (req.get_tx_keys)
|
||||
res.tx_key_list.push_back(boost::lexical_cast<std::string>(ptx.tx_key));
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -320,7 +322,8 @@ namespace tools
|
||||
for (auto & ptx : ptx_vector)
|
||||
{
|
||||
res.tx_hash_list.push_back(boost::lexical_cast<std::string>(cryptonote::get_transaction_hash(ptx.tx)));
|
||||
res.tx_key_list.push_back(boost::lexical_cast<std::string>(ptx.tx_key));
|
||||
if (req.get_tx_keys)
|
||||
res.tx_key_list.push_back(boost::lexical_cast<std::string>(ptx.tx_key));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -97,6 +97,7 @@ namespace wallet_rpc
|
||||
uint64_t mixin;
|
||||
uint64_t unlock_time;
|
||||
std::string payment_id;
|
||||
bool get_tx_key;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(destinations)
|
||||
@ -104,6 +105,7 @@ namespace wallet_rpc
|
||||
KV_SERIALIZE(mixin)
|
||||
KV_SERIALIZE(unlock_time)
|
||||
KV_SERIALIZE(payment_id)
|
||||
KV_SERIALIZE(get_tx_key)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
@ -129,6 +131,7 @@ namespace wallet_rpc
|
||||
uint64_t unlock_time;
|
||||
std::string payment_id;
|
||||
bool new_algorithm;
|
||||
bool get_tx_keys;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(destinations)
|
||||
@ -137,6 +140,7 @@ namespace wallet_rpc
|
||||
KV_SERIALIZE(unlock_time)
|
||||
KV_SERIALIZE(payment_id)
|
||||
KV_SERIALIZE(new_algorithm)
|
||||
KV_SERIALIZE(get_tx_keys)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
@ -156,7 +160,10 @@ namespace wallet_rpc
|
||||
{
|
||||
struct request
|
||||
{
|
||||
bool get_tx_keys;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(get_tx_keys)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user