From eeb6549dced3188f04d27e2945f722706b00d1ae Mon Sep 17 00:00:00 2001 From: woodser Date: Sun, 5 Nov 2023 08:47:42 -0500 Subject: [PATCH] sign_txs() returns monero_tx_set instead of string --- src/wallet/monero_wallet.h | 6 +++--- src/wallet/monero_wallet_full.cpp | 23 ++++++++++++++++++++--- src/wallet/monero_wallet_full.h | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/wallet/monero_wallet.h b/src/wallet/monero_wallet.h index 65cb3460..fa811e6b 100644 --- a/src/wallet/monero_wallet.h +++ b/src/wallet/monero_wallet.h @@ -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 submit_txs(const std::string& signed_tx_hex) { diff --git a/src/wallet/monero_wallet_full.cpp b/src/wallet/monero_wallet_full.cpp index c15fc4ef..6c98503f 100644 --- a/src/wallet/monero_wallet_full.cpp +++ b/src/wallet/monero_wallet_full.cpp @@ -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 tx = std::make_shared(); tx->m_is_outgoing = true; tx->m_input_sum = 0; @@ -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"); @@ -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 ptxs; + std::vector> 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 tx = std::make_shared(); + 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()); } diff --git a/src/wallet/monero_wallet_full.h b/src/wallet/monero_wallet_full.h index 93a7e996..f1012c8e 100644 --- a/src/wallet/monero_wallet_full.h +++ b/src/wallet/monero_wallet_full.h @@ -204,7 +204,7 @@ namespace monero { std::vector> sweep_dust(bool relay = false) override; std::vector relay_txs(const std::vector& 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 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;