From c03402d5250b86c7ab887fd2c5f674a23a33a7ee Mon Sep 17 00:00:00 2001 From: Some Random Crypto Guy Date: Wed, 1 Oct 2025 14:40:47 +0100 Subject: [PATCH] updated API methods for 3rd-party wallets --- README.md | 2 +- src/cryptonote_core/tx_pool.cpp | 10 ++++++++++ src/wallet/api/wallet.cpp | 14 ++++++++------ src/wallet/api/wallet.h | 4 ++-- src/wallet/api/wallet2_api.h | 6 +++--- src/wallet/wallet2.cpp | 11 +++++++++-- src/wallet/wallet2.h | 2 +- src/wallet/wallet_rpc_server.cpp | 12 +++++++++--- 8 files changed, 43 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index f4722f555..b84d4f911 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ As with many development projects, the repository on GitHub is considered to be ## Supporting the project -Salvium is a 100% community-sponsored endeavor. If you want to join our efforts, the easiest thing you can do is support the project financially. Go to [https://salvium.io/donate/](https://salvium.io/donate/) for more information. +Salvium is a 100% community-sponsored endeavor. If you want to join our efforts, the easiest thing you can do is support the project financially. Go to [https://salvium.io/donate](https://salvium.io/donate) for more information. ## License diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 46b6edcd7..3dfdf6a35 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -1749,6 +1749,16 @@ namespace cryptonote LOG_PRINT_L2(" key images already seen"); continue; } + if (version < HF_VERSION_CARROT && tx.version >= TRANSACTION_VERSION_CARROT) + { + LOG_PRINT_L2(" is a Carrot transaction - cannot be mined"); + continue; + } + if (version >= HF_VERSION_CARROT && tx.version < TRANSACTION_VERSION_CARROT) + { + LOG_PRINT_L2(" is not a Carrot transaction - cannot be mined"); + continue; + } bl.tx_hashes.push_back(sorted_it->second); total_weight += meta.weight; diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index bf163fa1d..977241402 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -877,18 +877,18 @@ bool WalletImpl::setDevicePassphrase(const std::string &passphrase) return status() == Status_Ok; } -std::string WalletImpl::address(uint32_t accountIndex, uint32_t addressIndex) const +std::string WalletImpl::address(uint32_t accountIndex, uint32_t addressIndex, bool carrot) const { - return m_wallet->get_subaddress_as_str({accountIndex, addressIndex}); + return m_wallet->get_subaddress_as_str({{accountIndex, addressIndex}, carrot ? carrot::AddressDeriveType::Carrot : carrot::AddressDeriveType::PreCarrot}); } -std::string WalletImpl::integratedAddress(const std::string &payment_id) const +std::string WalletImpl::integratedAddress(const std::string &payment_id, bool carrot) const { crypto::hash8 pid; if (!tools::wallet2::parse_short_payment_id(payment_id, pid)) { return ""; } - return m_wallet->get_integrated_address_as_str(pid); + return m_wallet->get_integrated_address_as_str(pid, carrot); } std::string WalletImpl::secretViewKey() const @@ -1588,7 +1588,8 @@ PendingTransaction* WalletImpl::restoreMultisigTransaction(const string& signDat PendingTransaction *WalletImpl::createStakeTransaction(uint64_t amount, uint32_t mixin_count, PendingTransaction::Priority priority, uint32_t subaddr_account, std::set subaddr_indices) { // Need to populate {dst_entr, payment_id, asset_type, is_return} - const string dst_addr = m_wallet->get_subaddress_as_str({subaddr_account, 0});//MY LOCAL (SUB)ADDRESS + const bool is_carrot = m_wallet->get_current_hard_fork() >= HF_VERSION_CARROT; + const string dst_addr = m_wallet->get_subaddress_as_str({{subaddr_account, 0}, is_carrot ? carrot::AddressDeriveType::Carrot : carrot::AddressDeriveType::PreCarrot});//MY LOCAL (SUB)ADDRESS const string payment_id = ""; const string asset_type = "SAL1"; const bool is_return = false; @@ -1605,7 +1606,8 @@ PendingTransaction *WalletImpl::createAuditTransaction( std::set subaddr_indices ) { // Need to populate {dst_entr, payment_id, asset_type, is_return} - const string dst_addr = m_wallet->get_subaddress_as_str({subaddr_account, 0});//MY LOCAL (SUB)ADDRESS + const bool is_carrot = m_wallet->get_current_hard_fork() >= HF_VERSION_CARROT; + const string dst_addr = m_wallet->get_subaddress_as_str({{subaddr_account, 0}, is_carrot ? carrot::AddressDeriveType::Carrot : carrot::AddressDeriveType::PreCarrot});//MY LOCAL (SUB)ADDRESS const string payment_id = ""; const string asset_type = "SAL"; const bool is_return = false; diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index 9cc3f87a9..f4289ec62 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -93,8 +93,8 @@ public: const std::string& getPassword() const override; bool setDevicePin(const std::string &password) override; bool setDevicePassphrase(const std::string &password) override; - std::string address(uint32_t accountIndex = 0, uint32_t addressIndex = 0) const override; - std::string integratedAddress(const std::string &payment_id) const override; + std::string address(uint32_t accountIndex = 0, uint32_t addressIndex = 0, bool carrot = true) const override; + std::string integratedAddress(const std::string &payment_id, bool carrot = true) const override; std::string secretViewKey() const override; std::string publicViewKey() const override; std::string secretSpendKey() const override; diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h index 1510893df..1a6cab849 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -513,8 +513,8 @@ struct Wallet virtual const std::string& getPassword() const = 0; virtual bool setDevicePin(const std::string &pin) { (void)pin; return false; }; virtual bool setDevicePassphrase(const std::string &passphrase) { (void)passphrase; return false; }; - virtual std::string address(uint32_t accountIndex = 0, uint32_t addressIndex = 0) const = 0; - std::string mainAddress() const { return address(0, 0); } + virtual std::string address(uint32_t accountIndex = 0, uint32_t addressIndex = 0, bool carrot = true) const = 0; + std::string mainAddress(bool carrot = true) const { return address(0, 0, carrot); } virtual std::string path() const = 0; virtual NetworkType nettype() const = 0; bool mainnet() const { return nettype() == MAINNET; } @@ -533,7 +533,7 @@ struct Wallet * generated * \return - 106 characters string representing integrated address */ - virtual std::string integratedAddress(const std::string &payment_id) const = 0; + virtual std::string integratedAddress(const std::string &payment_id, bool carrot = true) const = 0; /*! * \brief secretViewKey - returns secret view key diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index dc71317eb..544bde49b 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1596,9 +1596,16 @@ std::string wallet2::get_subaddress_as_str(const carrot::subaddress_index_extend return cryptonote::get_account_address_as_str(m_nettype, address.is_subaddress, addr, addr.m_is_carrot); } //---------------------------------------------------------------------------------------------------- -std::string wallet2::get_integrated_address_as_str(const crypto::hash8& payment_id) const +std::string wallet2::get_integrated_address_as_str(const crypto::hash8& payment_id, bool carrot) const { - return cryptonote::get_account_integrated_address_as_str(m_nettype, get_address(), payment_id); + carrot::subaddress_index_extended subaddr{{0, 0}, carrot ? carrot::AddressDeriveType::Carrot : carrot::AddressDeriveType::PreCarrot}; + carrot::CarrotDestinationV1 address = m_account.subaddress(subaddr); + + // Build the cryptonote::account_public_address + account_public_address addr{address.address_spend_pubkey, address.address_view_pubkey}; + addr.m_is_carrot = carrot; + + return cryptonote::get_account_integrated_address_as_str(m_nettype, addr, payment_id, carrot); } //---------------------------------------------------------------------------------------------------- void wallet2::add_subaddress_account(const std::string& label) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 646cfb355..0158ec7d2 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1198,7 +1198,7 @@ private: //std::string get_subaddress_as_str(const cryptonote::subaddress_index& index) const; std::string get_subaddress_as_str(const carrot::subaddress_index_extended& index) const; std::string get_address_as_str() const { return get_subaddress_as_str({0, 0}); } - std::string get_integrated_address_as_str(const crypto::hash8& payment_id) const; + std::string get_integrated_address_as_str(const crypto::hash8& payment_id, bool carrot = true) const; void add_subaddress_account(const std::string& label); size_t get_num_subaddress_accounts() const { return m_subaddress_labels.size(); } size_t get_num_subaddresses(uint32_t index_major) const { return index_major < m_subaddress_labels.size() ? m_subaddress_labels[index_major].size() : 0; } diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 77f3f555e..94f0e91ae 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -657,7 +657,8 @@ namespace tools info.address_index = index.minor; info.used = std::find_if(transfers.begin(), transfers.end(), [&](const tools::wallet2::transfer_details& td) { return td.m_subaddr_index == index; }) != transfers.end(); } - res.address = m_wallet->get_subaddress_as_str({req.account_index, 0}); + //res.address = m_wallet->get_subaddress_as_str({req.account_index, 0}); + res.address = m_wallet->get_subaddress_as_str({{req.account_index, 0}, is_carrot ? carrot::AddressDeriveType::Carrot : carrot::AddressDeriveType::PreCarrot}); } catch (const std::exception& e) { @@ -700,6 +701,8 @@ namespace tools return false; } + bool is_carrot = m_wallet->get_current_hard_fork() >= HF_VERSION_CARROT; + std::vector addresses; std::vector address_indices; @@ -710,7 +713,8 @@ namespace tools m_wallet->add_subaddress(req.account_index, req.label); uint32_t new_address_index = m_wallet->get_num_subaddresses(req.account_index) - 1; address_indices.push_back(new_address_index); - addresses.push_back(m_wallet->get_subaddress_as_str({req.account_index, new_address_index})); + //addresses.push_back(m_wallet->get_subaddress_as_str({req.account_index, new_address_index})); + addresses.push_back(m_wallet->get_subaddress_as_str({{req.account_index, new_address_index}, is_carrot ? carrot::AddressDeriveType::Carrot : carrot::AddressDeriveType::PreCarrot})); } res.address = addresses[0]; @@ -806,7 +810,9 @@ namespace tools { m_wallet->add_subaddress_account(req.label); res.account_index = m_wallet->get_num_subaddress_accounts() - 1; - res.address = m_wallet->get_subaddress_as_str({res.account_index, 0}); + //res.address = m_wallet->get_subaddress_as_str({res.account_index, 0}); + bool is_carrot = m_wallet->get_current_hard_fork() >= HF_VERSION_CARROT; + res.address = m_wallet->get_subaddress_as_str({{res.account_index, 0}, is_carrot ? carrot::AddressDeriveType::Carrot : carrot::AddressDeriveType::PreCarrot}); } catch (const std::exception& e) {