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:
moneromooo-monero 2015-08-19 20:59:44 +01:00
parent 32077d3810
commit d91eb8c7b4
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
6 changed files with 36 additions and 11 deletions

View File

@ -408,7 +408,7 @@ namespace cryptonote
return encrypt_payment_id(payment_id, public_key, secret_key); 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.vin.clear();
tx.vout.clear(); tx.vout.clear();
@ -578,6 +578,12 @@ namespace cryptonote
return true; 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) bool get_inputs_money_amount(const transaction& tx, uint64_t& money)
{ {
money = 0; money = 0;

View File

@ -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> template<typename T>
bool find_tx_extra_field_by_type(const std::vector<tx_extra_field>& tx_extra_fields, T& field) bool find_tx_extra_field_by_type(const std::vector<tx_extra_field>& tx_extra_fields, T& field)

View File

@ -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); value2.SetInt(m_always_confirm_transfers ? 1 :0);
json.AddMember("always_confirm_transfers", value2, json.GetAllocator()); 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 // Serialize the JSON object
rapidjson::StringBuffer buffer; rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(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_watch_only = false;
} }
m_always_confirm_transfers = json.HasMember("always_confirm_transfers") && (json["always_confirm_transfers"].GetInt() != 0); 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(); const cryptonote::account_keys& keys = m_account.get_keys();
@ -1325,6 +1329,7 @@ void wallet2::commit_tx(pending_tx& ptx)
txid = get_transaction_hash(ptx.tx); txid = get_transaction_hash(ptx.tx);
add_unconfirmed_tx(ptx.tx, ptx.change_dts.amount); add_unconfirmed_tx(ptx.tx, ptx.change_dts.amount);
if (store_tx_keys())
m_tx_keys.insert(std::make_pair(txid, ptx.tx_key)); 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 << "]"); 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; 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(!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); 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)); std::to_string(dust) + ", dust_threshold = " + std::to_string(dust_policy.dust_threshold));
crypto::secret_key tx_key; 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(!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); THROW_WALLET_EXCEPTION_IF(m_upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, m_upper_transaction_size_limit);

View File

@ -80,9 +80,9 @@ namespace tools
class wallet2 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: 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 struct transfer_details
{ {
uint64_t m_block_height; uint64_t m_block_height;
@ -292,6 +292,8 @@ namespace tools
bool always_confirm_transfers() const { return m_always_confirm_transfers; } bool always_confirm_transfers() const { return m_always_confirm_transfers; }
void always_confirm_transfers(bool always) { m_always_confirm_transfers = always; } 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; 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 is_old_file_format; /*!< Whether the wallet file is of an old file format */
bool m_watch_only; /*!< no spend key */ bool m_watch_only; /*!< no spend key */
bool m_always_confirm_transfers; 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) BOOST_CLASS_VERSION(tools::wallet2, 8)
@ -585,7 +588,7 @@ namespace tools
} }
crypto::secret_key tx_key; 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(!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); THROW_WALLET_EXCEPTION_IF(m_upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, m_upper_transaction_size_limit);

View File

@ -218,6 +218,7 @@ namespace tools
// populate response with tx hash // populate response with tx hash
res.tx_hash = boost::lexical_cast<std::string>(cryptonote::get_transaction_hash(ptx_vector.back().tx)); res.tx_hash = boost::lexical_cast<std::string>(cryptonote::get_transaction_hash(ptx_vector.back().tx));
if (req.get_tx_key)
res.tx_key = boost::lexical_cast<std::string>(ptx_vector.back().tx_key); res.tx_key = boost::lexical_cast<std::string>(ptx_vector.back().tx_key);
return true; return true;
} }
@ -275,6 +276,7 @@ namespace tools
for (auto & ptx : ptx_vector) for (auto & ptx : ptx_vector)
{ {
res.tx_hash_list.push_back(boost::lexical_cast<std::string>(cryptonote::get_transaction_hash(ptx.tx))); res.tx_hash_list.push_back(boost::lexical_cast<std::string>(cryptonote::get_transaction_hash(ptx.tx)));
if (req.get_tx_keys)
res.tx_key_list.push_back(boost::lexical_cast<std::string>(ptx.tx_key)); res.tx_key_list.push_back(boost::lexical_cast<std::string>(ptx.tx_key));
} }
@ -320,6 +322,7 @@ namespace tools
for (auto & ptx : ptx_vector) for (auto & ptx : ptx_vector)
{ {
res.tx_hash_list.push_back(boost::lexical_cast<std::string>(cryptonote::get_transaction_hash(ptx.tx))); res.tx_hash_list.push_back(boost::lexical_cast<std::string>(cryptonote::get_transaction_hash(ptx.tx)));
if (req.get_tx_keys)
res.tx_key_list.push_back(boost::lexical_cast<std::string>(ptx.tx_key)); res.tx_key_list.push_back(boost::lexical_cast<std::string>(ptx.tx_key));
} }

View File

@ -97,6 +97,7 @@ namespace wallet_rpc
uint64_t mixin; uint64_t mixin;
uint64_t unlock_time; uint64_t unlock_time;
std::string payment_id; std::string payment_id;
bool get_tx_key;
BEGIN_KV_SERIALIZE_MAP() BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(destinations) KV_SERIALIZE(destinations)
@ -104,6 +105,7 @@ namespace wallet_rpc
KV_SERIALIZE(mixin) KV_SERIALIZE(mixin)
KV_SERIALIZE(unlock_time) KV_SERIALIZE(unlock_time)
KV_SERIALIZE(payment_id) KV_SERIALIZE(payment_id)
KV_SERIALIZE(get_tx_key)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
}; };
@ -129,6 +131,7 @@ namespace wallet_rpc
uint64_t unlock_time; uint64_t unlock_time;
std::string payment_id; std::string payment_id;
bool new_algorithm; bool new_algorithm;
bool get_tx_keys;
BEGIN_KV_SERIALIZE_MAP() BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(destinations) KV_SERIALIZE(destinations)
@ -137,6 +140,7 @@ namespace wallet_rpc
KV_SERIALIZE(unlock_time) KV_SERIALIZE(unlock_time)
KV_SERIALIZE(payment_id) KV_SERIALIZE(payment_id)
KV_SERIALIZE(new_algorithm) KV_SERIALIZE(new_algorithm)
KV_SERIALIZE(get_tx_keys)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
}; };
@ -156,7 +160,10 @@ namespace wallet_rpc
{ {
struct request struct request
{ {
bool get_tx_keys;
BEGIN_KV_SERIALIZE_MAP() BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(get_tx_keys)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
}; };