Skip to content

Commit

Permalink
sign_txs() returns monero_tx_set instead of string
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Nov 11, 2023
1 parent 5d2652c commit eeb6549
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/wallet/monero_wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -941,16 +941,16 @@ namespace monero {
* Sign unsigned transactions from a view-only wallet.
*
* @param unsigned_tx_hex is unsigned transaction hex from when the transactions were created
* @return the signed transaction hex
* @return the signed transaction set
*/
virtual std::string sign_txs(const std::string& unsigned_tx_hex) {
virtual monero_tx_set sign_txs(const std::string& unsigned_tx_hex) {
throw std::runtime_error("sign_txs() not supported");
}

/**
* Submit signed transactions from a view-only wallet.
*
* @param signed_tx_hex is signed transaction hex from signTxs()
* @param signed_tx_hex is signed transaction hex from sign_txs()
* @return the resulting transaction hashes
*/
virtual std::vector<std::string> submit_txs(const std::string& signed_tx_hex) {
Expand Down
23 changes: 20 additions & 3 deletions src/wallet/monero_wallet_full.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2657,7 +2657,7 @@ namespace monero {
int first_known_non_zero_change_index = -1;
for (int64_t n = 0; n < tx_constructions.size(); ++n)
{
// pre-initialize tx
// init tx
std::shared_ptr<monero_tx_wallet> tx = std::make_shared<monero_tx_wallet>();
tx->m_is_outgoing = true;
tx->m_input_sum = 0;
Expand Down Expand Up @@ -2769,7 +2769,7 @@ namespace monero {
}

// implementation based on monero-project wallet_rpc_server.cpp::on_sign_transfer()
std::string monero_wallet_full::sign_txs(const std::string& unsigned_tx_hex) {
monero_tx_set monero_wallet_full::sign_txs(const std::string& unsigned_tx_hex) {
if (m_w2->key_on_device()) throw std::runtime_error("command not supported by HW wallet");
if (m_w2->watch_only()) throw std::runtime_error("command not supported by view-only wallet");

Expand All @@ -2780,11 +2780,28 @@ namespace monero {
if(!m_w2->parse_unsigned_tx_from_str(blob, exported_txs)) throw std::runtime_error("cannot load unsigned_txset");

std::vector<tools::wallet2::pending_tx> ptxs;
std::vector<std::shared_ptr<monero_tx_wallet>> txs;
try {
tools::wallet2::signed_tx_set signed_txs;
std::string ciphertext = m_w2->sign_tx_dump_to_str(exported_txs, ptxs, signed_txs);
if (ciphertext.empty()) throw std::runtime_error("Failed to sign unsigned tx");
return epee::string_tools::buff_to_hex_nodelimer(ciphertext);

// init tx set
monero_tx_set tx_set;
tx_set.m_signed_tx_hex = epee::string_tools::buff_to_hex_nodelimer(ciphertext);
for (auto &ptx : ptxs) {

// init tx
std::shared_ptr<monero_tx_wallet> tx = std::make_shared<monero_tx_wallet>();
tx->m_is_outgoing = true;
tx->m_hash = epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(ptx.tx));
tx->m_key = epee::string_tools::pod_to_hex(ptx.tx_key);
for (const crypto::secret_key& additional_tx_key : ptx.additional_tx_keys) {
tx->m_key = tx->m_key.get() += epee::string_tools::pod_to_hex(additional_tx_key);
}
tx_set.m_txs.push_back(tx);
}
return tx_set;
} catch (const std::exception &e) {
throw std::runtime_error(std::string("Failed to sign unsigned tx: ") + e.what());
}
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/monero_wallet_full.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ namespace monero {
std::vector<std::shared_ptr<monero_tx_wallet>> sweep_dust(bool relay = false) override;
std::vector<std::string> relay_txs(const std::vector<std::string>& tx_metadatas) override;
monero_tx_set describe_tx_set(const monero_tx_set& tx_set) override;
std::string sign_txs(const std::string& unsigned_tx_hex) override;
monero_tx_set sign_txs(const std::string& unsigned_tx_hex) override;
std::vector<std::string> submit_txs(const std::string& signed_tx_hex) override;
std::string sign_message(const std::string& msg, monero_message_signature_type signature_type, uint32_t account_idx = 0, uint32_t subaddress_idx = 0) const override;
monero_message_signature_result verify_message(const std::string& msg, const std::string& address, const std::string& signature) const override;
Expand Down

0 comments on commit eeb6549

Please sign in to comment.