From 2a38bf29618a8ce163f9d6f83b7ae86924752e32 Mon Sep 17 00:00:00 2001 From: cyan Date: Wed, 4 Dec 2024 10:22:48 -0500 Subject: cleanup patches (and other stuff) (#79) * cleanup patches * fix polyseed patch * Fix iOS builds * fix polyseed dependencies * fix polyseed patch for macOS * update ledger patch * update wownero patches and version * update checksums * wip" * update gitmodules * update boost build script * update build_single.sh * vix verbosey_copy * fix __clear_cache bug on wownero * update randomwow * migrate build system * fix cross compilation issues * some more build issue * update polyseed * cleanup cmakelists * fix toolchain.cmake.in * add ssp * another attempt at building windows on CI * fix package name * migrate mirror to my own hosting * change download mirror priority (fallback first) * link ssp in monero module as well by using CMAKE_{C,CXX}_FLAGS * fix android builds * update polyseed source * 13 -> trixie * fix package name conflicts, update runner to sid * update boost to 1_84_0, disable patch that's no longer needed * switch to ubuntu:24.04 * add POLYSEED_STATIC to toolchain.cmake.in in order to properly link * drop patches * fixes to darwin * link missing wowner-seed library * a litte bit more of experiments * build locale only on windows * update iconv * update definitions * update ci builds * update my progress * ios fix, update depends, ci * multithread build system * fix android, mingw and linux build issues * remove dependency check * update Dockerfile to include pigz * show a message when pigz is missing * fix devcontainer mingw setup (missing ENV) * update android build runner * sailfishos dropped (you better go behave yourself and run actual linux programs) * fiz pigz issues * install llvm-ranlib for android * fix iOS build issues * fix dummy ledger patch * fix macos and darwin * fix macos ci * fix macos build command * install autoconf * add automake * add libtool * macos fixes, wownero fixes, idk what else, please help me * fix wownero iOS build * Cleanup patches * add try-catch into monero code * fix error handling * update checksums --- patches/monero/0009-coin-control.patch | 979 +++++++++++++++++++++++++++++++++ 1 file changed, 979 insertions(+) create mode 100644 patches/monero/0009-coin-control.patch (limited to 'patches/monero/0009-coin-control.patch') diff --git a/patches/monero/0009-coin-control.patch b/patches/monero/0009-coin-control.patch new file mode 100644 index 0000000..1aac12a --- /dev/null +++ b/patches/monero/0009-coin-control.patch @@ -0,0 +1,979 @@ +From 4d897d9ee1d24710500f4d58e9ccd79fb48cf1d2 Mon Sep 17 00:00:00 2001 +From: tobtoht +Date: Tue, 12 Mar 2024 11:07:57 +0100 +Subject: [PATCH 09/14] coin control + +--- + src/simplewallet/simplewallet.cpp | 2 +- + src/wallet/api/CMakeLists.txt | 8 +- + src/wallet/api/coins.cpp | 186 ++++++++++++++++++++++++++++++ + src/wallet/api/coins.h | 40 +++++++ + src/wallet/api/coins_info.cpp | 122 ++++++++++++++++++++ + src/wallet/api/coins_info.h | 71 ++++++++++++ + src/wallet/api/wallet.cpp | 64 +++++++++- + src/wallet/api/wallet.h | 10 +- + src/wallet/api/wallet2_api.h | 52 ++++++++- + src/wallet/wallet2.cpp | 46 +++++++- + src/wallet/wallet2.h | 11 +- + 11 files changed, 593 insertions(+), 19 deletions(-) + create mode 100644 src/wallet/api/coins.cpp + create mode 100644 src/wallet/api/coins.h + create mode 100644 src/wallet/api/coins_info.cpp + create mode 100644 src/wallet/api/coins_info.h + +diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp +index 2c51337..645bd37 100644 +--- a/src/simplewallet/simplewallet.cpp ++++ b/src/simplewallet/simplewallet.cpp +@@ -6930,7 +6930,7 @@ bool simple_wallet::transfer_main(const std::vector &args_, bool ca + { + // figure out what tx will be necessary + auto ptx_vector = m_wallet->create_transactions_2(dsts, fake_outs_count, priority, extra, +- m_current_subaddress_account, subaddr_indices, subtract_fee_from_outputs); ++ m_current_subaddress_account, subaddr_indices, {}, subtract_fee_from_outputs); + + if (ptx_vector.empty()) + { +diff --git a/src/wallet/api/CMakeLists.txt b/src/wallet/api/CMakeLists.txt +index af7948d..bb740e2 100644 +--- a/src/wallet/api/CMakeLists.txt ++++ b/src/wallet/api/CMakeLists.txt +@@ -40,7 +40,9 @@ set(wallet_api_sources + address_book.cpp + subaddress.cpp + subaddress_account.cpp +- unsigned_transaction.cpp) ++ unsigned_transaction.cpp ++ coins.cpp ++ coins_info.cpp) + + set(wallet_api_headers + wallet2_api.h) +@@ -55,7 +57,9 @@ set(wallet_api_private_headers + address_book.h + subaddress.h + subaddress_account.h +- unsigned_transaction.h) ++ unsigned_transaction.h ++ coins.h ++ coins_info.h) + + monero_private_headers(wallet_api + ${wallet_api_private_headers}) +diff --git a/src/wallet/api/coins.cpp b/src/wallet/api/coins.cpp +new file mode 100644 +index 0000000..ef12141 +--- /dev/null ++++ b/src/wallet/api/coins.cpp +@@ -0,0 +1,186 @@ ++#include "coins.h" ++#include "coins_info.h" ++#include "wallet.h" ++#include "crypto/hash.h" ++#include "wallet/wallet2.h" ++#include "common_defines.h" ++ ++#include ++#include ++ ++using namespace epee; ++ ++namespace Monero { ++ ++Coins::~Coins() = default; ++ ++CoinsImpl::CoinsImpl(WalletImpl *wallet) ++ : m_wallet(wallet) {} ++ ++CoinsImpl::~CoinsImpl() ++{ ++ for (auto t : m_rows) ++ delete t; ++} ++ ++int CoinsImpl::count() const ++{ ++ boost::shared_lock lock(m_rowsMutex); ++ int result = m_rows.size(); ++ return result; ++} ++ ++CoinsInfo *CoinsImpl::coin(int index) const ++{ ++ boost::shared_lock lock(m_rowsMutex); ++ // sanity check ++ if (index < 0) ++ return nullptr; ++ auto index_ = static_cast(index); ++ return index_ < m_rows.size() ? m_rows[index_] : nullptr; ++} ++ ++std::vector CoinsImpl::getAll() const ++{ ++ boost::shared_lock lock(m_rowsMutex); ++ return m_rows; ++} ++ ++ ++void CoinsImpl::refresh() ++{ ++ LOG_PRINT_L2("Refreshing coins"); ++ ++ boost::unique_lock lock(m_rowsMutex); ++ boost::shared_lock transfers_lock(m_wallet->m_wallet->m_transfers_mutex); ++ ++ // delete old outputs; ++ for (auto t : m_rows) ++ delete t; ++ m_rows.clear(); ++ ++ for (size_t i = 0; i < m_wallet->m_wallet->get_num_transfer_details(); ++i) ++ { ++ const tools::wallet2::transfer_details &td = m_wallet->m_wallet->get_transfer_details(i); ++ ++ auto ci = new CoinsInfoImpl(); ++ ci->m_blockHeight = td.m_block_height; ++ ci->m_hash = string_tools::pod_to_hex(td.m_txid); ++ ci->m_internalOutputIndex = td.m_internal_output_index; ++ ci->m_globalOutputIndex = td.m_global_output_index; ++ ci->m_spent = td.m_spent; ++ ci->m_frozen = td.m_frozen; ++ ci->m_spentHeight = td.m_spent_height; ++ ci->m_amount = td.m_amount; ++ ci->m_rct = td.m_rct; ++ ci->m_keyImageKnown = td.m_key_image_known; ++ ci->m_pkIndex = td.m_pk_index; ++ ci->m_subaddrIndex = td.m_subaddr_index.minor; ++ ci->m_subaddrAccount = td.m_subaddr_index.major; ++ ci->m_address = m_wallet->m_wallet->get_subaddress_as_str(td.m_subaddr_index); // todo: this is expensive, cache maybe? ++ ci->m_addressLabel = m_wallet->m_wallet->get_subaddress_label(td.m_subaddr_index); ++ ci->m_keyImage = string_tools::pod_to_hex(td.m_key_image); ++ ci->m_unlockTime = td.m_tx.unlock_time; ++ ci->m_unlocked = m_wallet->m_wallet->is_transfer_unlocked(td); ++ ci->m_pubKey = string_tools::pod_to_hex(td.get_public_key()); ++ ci->m_coinbase = td.m_tx.vin.size() == 1 && td.m_tx.vin[0].type() == typeid(cryptonote::txin_gen); ++ ci->m_description = m_wallet->m_wallet->get_tx_note(td.m_txid); ++ ++ m_rows.push_back(ci); ++ } ++} ++ ++void CoinsImpl::setFrozen(std::string public_key) ++{ ++ crypto::public_key pk; ++ if (!epee::string_tools::hex_to_pod(public_key, pk)) ++ { ++ LOG_ERROR("Invalid public key: " << public_key); ++ return; ++ } ++ ++ try ++ { ++ m_wallet->m_wallet->freeze(pk); ++ refresh(); ++ } ++ catch (const std::exception& e) ++ { ++ LOG_ERROR("setFrozen: " << e.what()); ++ } ++} ++ ++void CoinsImpl::setFrozen(int index) ++{ ++ try ++ { ++ LOG_ERROR("Freezing coin: " << index); ++ m_wallet->m_wallet->freeze(index); ++ refresh(); ++ } ++ catch (const std::exception& e) ++ { ++ LOG_ERROR("setLabel: " << e.what()); ++ } ++} ++ ++void CoinsImpl::thaw(std::string public_key) ++{ ++ crypto::public_key pk; ++ if (!epee::string_tools::hex_to_pod(public_key, pk)) ++ { ++ LOG_ERROR("Invalid public key: " << public_key); ++ return; ++ } ++ ++ try ++ { ++ m_wallet->m_wallet->thaw(pk); ++ refresh(); ++ } ++ catch (const std::exception& e) ++ { ++ LOG_ERROR("thaw: " << e.what()); ++ } ++} ++ ++void CoinsImpl::thaw(int index) ++{ ++ try ++ { ++ m_wallet->m_wallet->thaw(index); ++ refresh(); ++ } ++ catch (const std::exception& e) ++ { ++ LOG_ERROR("thaw: " << e.what()); ++ } ++} ++ ++bool CoinsImpl::isTransferUnlocked(uint64_t unlockTime, uint64_t blockHeight) { ++ return m_wallet->m_wallet->is_transfer_unlocked(unlockTime, blockHeight); ++} ++ ++void CoinsImpl::setDescription(const std::string &public_key, const std::string &description) ++{ ++ crypto::public_key pk; ++ if (!epee::string_tools::hex_to_pod(public_key, pk)) ++ { ++ LOG_ERROR("Invalid public key: " << public_key); ++ return; ++ } ++ ++ try ++ { ++ const size_t index = m_wallet->m_wallet->get_transfer_details(pk); ++ const tools::wallet2::transfer_details &td = m_wallet->m_wallet->get_transfer_details(index); ++ m_wallet->m_wallet->set_tx_note(td.m_txid, description); ++ refresh(); ++ } ++ catch (const std::exception& e) ++ { ++ LOG_ERROR("setDescription: " << e.what()); ++ } ++} ++ ++} // namespace +diff --git a/src/wallet/api/coins.h b/src/wallet/api/coins.h +new file mode 100644 +index 0000000..b7a0a86 +--- /dev/null ++++ b/src/wallet/api/coins.h +@@ -0,0 +1,40 @@ ++#ifndef FEATHER_COINS_H ++#define FEATHER_COINS_H ++ ++#include "wallet/api/wallet2_api.h" ++#include "wallet/wallet2.h" ++ ++namespace Monero { ++ ++class WalletImpl; ++ ++class CoinsImpl : public Coins ++{ ++public: ++ explicit CoinsImpl(WalletImpl * wallet); ++ ~CoinsImpl() override; ++ int count() const override; ++ CoinsInfo * coin(int index) const override; ++ std::vector getAll() const override; ++ void refresh() override; ++ ++ void setFrozen(std::string public_key) override; ++ void setFrozen(int index) override; ++ void thaw(std::string public_key) override; ++ void thaw(int index) override; ++ ++ bool isTransferUnlocked(uint64_t unlockTime, uint64_t blockHeight) override; ++ ++ void setDescription(const std::string &public_key, const std::string &description) override; ++ ++private: ++ WalletImpl *m_wallet; ++ std::vector m_rows; ++ mutable boost::shared_mutex m_rowsMutex; ++}; ++ ++} ++ ++namespace Bitmonero = Monero; ++ ++#endif //FEATHER_COINS_H +diff --git a/src/wallet/api/coins_info.cpp b/src/wallet/api/coins_info.cpp +new file mode 100644 +index 0000000..5f2c4e1 +--- /dev/null ++++ b/src/wallet/api/coins_info.cpp +@@ -0,0 +1,122 @@ ++#include "coins_info.h" ++ ++using namespace std; ++ ++namespace Monero { ++ ++CoinsInfo::~CoinsInfo() = default; ++ ++CoinsInfoImpl::CoinsInfoImpl() ++ : m_blockHeight(0) ++ , m_internalOutputIndex(0) ++ , m_globalOutputIndex(0) ++ , m_spent(false) ++ , m_frozen(false) ++ , m_spentHeight(0) ++ , m_amount(0) ++ , m_rct(false) ++ , m_keyImageKnown(false) ++ , m_pkIndex(0) ++ , m_subaddrAccount(0) ++ , m_subaddrIndex(0) ++ , m_unlockTime(0) ++ , m_unlocked(false) ++{ ++ ++} ++ ++CoinsInfoImpl::~CoinsInfoImpl() = default; ++ ++uint64_t CoinsInfoImpl::blockHeight() const ++{ ++ return m_blockHeight; ++} ++ ++string CoinsInfoImpl::hash() const ++{ ++ return m_hash; ++} ++ ++size_t CoinsInfoImpl::internalOutputIndex() const { ++ return m_internalOutputIndex; ++} ++ ++uint64_t CoinsInfoImpl::globalOutputIndex() const ++{ ++ return m_globalOutputIndex; ++} ++ ++bool CoinsInfoImpl::spent() const ++{ ++ return m_spent; ++} ++ ++bool CoinsInfoImpl::frozen() const ++{ ++ return m_frozen; ++} ++ ++uint64_t CoinsInfoImpl::spentHeight() const ++{ ++ return m_spentHeight; ++} ++ ++uint64_t CoinsInfoImpl::amount() const ++{ ++ return m_amount; ++} ++ ++bool CoinsInfoImpl::rct() const { ++ return m_rct; ++} ++ ++bool CoinsInfoImpl::keyImageKnown() const { ++ return m_keyImageKnown; ++} ++ ++size_t CoinsInfoImpl::pkIndex() const { ++ return m_pkIndex; ++} ++ ++uint32_t CoinsInfoImpl::subaddrIndex() const { ++ return m_subaddrIndex; ++} ++ ++uint32_t CoinsInfoImpl::subaddrAccount() const { ++ return m_subaddrAccount; ++} ++ ++string CoinsInfoImpl::address() const { ++ return m_address; ++} ++ ++string CoinsInfoImpl::addressLabel() const { ++ return m_addressLabel; ++} ++ ++string CoinsInfoImpl::keyImage() const { ++ return m_keyImage; ++} ++ ++uint64_t CoinsInfoImpl::unlockTime() const { ++ return m_unlockTime; ++} ++ ++bool CoinsInfoImpl::unlocked() const { ++ return m_unlocked; ++} ++ ++string CoinsInfoImpl::pubKey() const { ++ return m_pubKey; ++} ++ ++bool CoinsInfoImpl::coinbase() const { ++ return m_coinbase; ++} ++ ++string CoinsInfoImpl::description() const { ++ return m_description; ++} ++} // namespace ++ ++namespace Bitmonero = Monero; +diff --git a/src/wallet/api/coins_info.h b/src/wallet/api/coins_info.h +new file mode 100644 +index 0000000..c43e45a +--- /dev/null ++++ b/src/wallet/api/coins_info.h +@@ -0,0 +1,71 @@ ++#ifndef FEATHER_COINS_INFO_H ++#define FEATHER_COINS_INFO_H ++ ++#include "wallet/api/wallet2_api.h" ++#include ++#include ++ ++namespace Monero { ++ ++class CoinsImpl; ++ ++class CoinsInfoImpl : public CoinsInfo ++{ ++public: ++ CoinsInfoImpl(); ++ ~CoinsInfoImpl(); ++ ++ virtual uint64_t blockHeight() const override; ++ virtual std::string hash() const override; ++ virtual size_t internalOutputIndex() const override; ++ virtual uint64_t globalOutputIndex() const override; ++ virtual bool spent() const override; ++ virtual bool frozen() const override; ++ virtual uint64_t spentHeight() const override; ++ virtual uint64_t amount() const override; ++ virtual bool rct() const override; ++ virtual bool keyImageKnown() const override; ++ virtual size_t pkIndex() const override; ++ virtual uint32_t subaddrIndex() const override; ++ virtual uint32_t subaddrAccount() const override; ++ virtual std::string address() const override; ++ virtual std::string addressLabel() const override; ++ virtual std::string keyImage() const override; ++ virtual uint64_t unlockTime() const override; ++ virtual bool unlocked() const override; ++ virtual std::string pubKey() const override; ++ virtual bool coinbase() const override; ++ virtual std::string description() const override; ++ ++private: ++ uint64_t m_blockHeight; ++ std::string m_hash; ++ size_t m_internalOutputIndex; ++ uint64_t m_globalOutputIndex; ++ bool m_spent; ++ bool m_frozen; ++ uint64_t m_spentHeight; ++ uint64_t m_amount; ++ bool m_rct; ++ bool m_keyImageKnown; ++ size_t m_pkIndex; ++ uint32_t m_subaddrIndex; ++ uint32_t m_subaddrAccount; ++ std::string m_address; ++ std::string m_addressLabel; ++ std::string m_keyImage; ++ uint64_t m_unlockTime; ++ bool m_unlocked; ++ std::string m_pubKey; ++ bool m_coinbase; ++ std::string m_description; ++ ++ friend class CoinsImpl; ++ ++}; ++ ++} // namespace ++ ++namespace Bitmonero = Monero; ++ ++#endif //FEATHER_COINS_INFO_H +diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp +index 67ac90a..6bb3a21 100644 +--- a/src/wallet/api/wallet.cpp ++++ b/src/wallet/api/wallet.cpp +@@ -35,6 +35,7 @@ + #include "transaction_history.h" + #include "address_book.h" + #include "subaddress.h" ++#include "coins.h" + #include "subaddress_account.h" + #include "common_defines.h" + #include "common/util.h" +@@ -473,6 +474,7 @@ WalletImpl::WalletImpl(NetworkType nettype, uint64_t kdf_rounds) + m_wallet->set_refresh_enabled(false); + m_addressBook.reset(new AddressBookImpl(this)); + m_subaddress.reset(new SubaddressImpl(this)); ++ m_coins.reset(new CoinsImpl(this)); + m_subaddressAccount.reset(new SubaddressAccountImpl(this)); + + +@@ -2046,7 +2048,7 @@ PendingTransaction* WalletImpl::restoreMultisigTransaction(const string& signDat + // - unconfirmed_transfer_details; + // - confirmed_transfer_details) + +-PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector &dst_addr, const string &payment_id, optional> amount, uint32_t mixin_count, PendingTransaction::Priority priority, uint32_t subaddr_account, std::set subaddr_indices) ++PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector &dst_addr, const string &payment_id, optional> amount, uint32_t mixin_count, PendingTransaction::Priority priority, uint32_t subaddr_account, std::set subaddr_indices, const std::set &preferred_inputs) + + { + clearStatus(); +@@ -2084,6 +2086,7 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vectornettype(), dst_addr[i])) { + // TODO: copy-paste 'if treating as an address fails, try as url' from simplewallet.cpp:1982 +@@ -2105,6 +2108,7 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vectorunlocked_balance(subaddr_account, true); ++ // if (maxAllowedSpend < amountSum) { ++ // error = true; ++ // setStatusError(tr("Amount you are trying to spend is larger than unlocked amount")); ++ // break; ++ // } ++ std::vector preferred_input_list; ++ if (!preferred_inputs.empty()) { ++ LOG_ERROR("empty"); ++ ++ for (const auto &public_key : preferred_inputs) { ++ crypto::key_image keyImage; ++ bool r = epee::string_tools::hex_to_pod(public_key, keyImage); ++ if (!r) { ++ error = true; ++ setStatusError(tr("failed to parse key image")); ++ break; ++ } ++ if (m_wallet->frozen(keyImage)) { ++ error = true; ++ setStatusError(tr("refusing to spend frozen coin")); ++ break; ++ } ++ ++ preferred_input_list.push_back(keyImage); ++ } ++ } else { ++ LOG_ERROR("not empty"); ++ ++ boost::shared_lock transfers_lock(m_wallet->m_transfers_mutex); ++ for (size_t i = 0; i < m_wallet->get_num_transfer_details(); ++i) { ++ const tools::wallet2::transfer_details &td = m_wallet->get_transfer_details(i); ++ LOG_ERROR("COIN: " << i << ": " << td.amount() << "; "<frozen(td)); ++ if (td.m_spent) continue; ++ LOG_ERROR("is frozen"); ++ if (!td.m_frozen) { ++ LOG_ERROR("isn't:"); ++ LOG_ERROR("hash: " << td.m_key_image << "; " << td.amount()); ++ preferred_input_list.push_back(td.m_key_image); ++ } ++ } ++ } ++ for (const auto &de : preferred_input_list) { ++ LOG_ERROR("preferred input: " << de); ++ } + if (error) { + break; + } +@@ -2129,11 +2178,11 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vectorm_pending_tx = m_wallet->create_transactions_2(dsts, fake_outs_count, + adjusted_priority, +- extra, subaddr_account, subaddr_indices); ++ extra, subaddr_account, subaddr_indices, preferred_input_list); + } else { + transaction->m_pending_tx = m_wallet->create_transactions_all(0, info.address, info.is_subaddress, 1, fake_outs_count, + adjusted_priority, +- extra, subaddr_account, subaddr_indices); ++ extra, subaddr_account, subaddr_indices, preferred_input_list); + } + pendingTxPostProcess(transaction); + +@@ -2214,10 +2263,10 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector amount, uint32_t mixin_count, +- PendingTransaction::Priority priority, uint32_t subaddr_account, std::set subaddr_indices) ++ PendingTransaction::Priority priority, uint32_t subaddr_account, std::set subaddr_indices, const std::set &preferred_inputs) + + { +- return createTransactionMultDest(std::vector {dst_addr}, payment_id, amount ? (std::vector {*amount}) : (optional>()), mixin_count, priority, subaddr_account, subaddr_indices); ++ return createTransactionMultDest(std::vector {dst_addr}, payment_id, amount ? (std::vector {*amount}) : (optional>()), mixin_count, priority, subaddr_account, subaddr_indices, preferred_inputs); + } + + PendingTransaction *WalletImpl::createSweepUnmixableTransaction() +@@ -2342,6 +2391,11 @@ AddressBook *WalletImpl::addressBook() + return m_addressBook.get(); + } + ++Coins *WalletImpl::coins() ++{ ++ return m_coins.get(); ++} ++ + Subaddress *WalletImpl::subaddress() + { + return m_subaddress.get(); +diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h +index 32e1228..a82f270 100644 +--- a/src/wallet/api/wallet.h ++++ b/src/wallet/api/wallet.h +@@ -46,6 +46,7 @@ class PendingTransactionImpl; + class UnsignedTransactionImpl; + class AddressBookImpl; + class SubaddressImpl; ++class CoinsImpl; + class SubaddressAccountImpl; + struct Wallet2CallbackImpl; + +@@ -167,12 +168,14 @@ public: + optional> amount, uint32_t mixin_count, + PendingTransaction::Priority priority = PendingTransaction::Priority_Low, + uint32_t subaddr_account = 0, +- std::set subaddr_indices = {}) override; ++ std::set subaddr_indices = {}, ++ const std::set &preferred_inputs = {}) override; + PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id, + optional amount, uint32_t mixin_count, + PendingTransaction::Priority priority = PendingTransaction::Priority_Low, + uint32_t subaddr_account = 0, +- std::set subaddr_indices = {}) override; ++ std::set subaddr_indices = {}, ++ const std::set &preferred_inputs = {}) override; + virtual PendingTransaction * createSweepUnmixableTransaction() override; + bool submitTransaction(const std::string &fileName) override; + bool submitTransactionUR(const std::string &input) override; +@@ -201,6 +204,7 @@ public: + PendingTransaction::Priority priority) const override; + virtual TransactionHistory * history() override; + virtual AddressBook * addressBook() override; ++ virtual Coins * coins() override; + virtual Subaddress * subaddress() override; + virtual SubaddressAccount * subaddressAccount() override; + virtual void setListener(WalletListener * l) override; +@@ -272,6 +276,7 @@ private: + friend class TransactionHistoryImpl; + friend struct Wallet2CallbackImpl; + friend class AddressBookImpl; ++ friend class CoinsImpl; + friend class SubaddressImpl; + friend class SubaddressAccountImpl; + +@@ -288,6 +293,7 @@ private: + std::unique_ptr m_wallet2Callback; + std::unique_ptr m_addressBook; + std::unique_ptr m_subaddress; ++ std::unique_ptr m_coins; + std::unique_ptr m_subaddressAccount; + + // multi-threaded refresh stuff +diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h +index be1c370..013b5bc 100644 +--- a/src/wallet/api/wallet2_api.h ++++ b/src/wallet/api/wallet2_api.h +@@ -263,6 +263,51 @@ struct AddressBook + virtual int lookupPaymentID(const std::string &payment_id) const = 0; + }; + ++/** ++ * @brief The CoinsInfo - interface for displaying coins information ++ */ ++struct CoinsInfo ++{ ++ virtual ~CoinsInfo() = 0; ++ ++ virtual uint64_t blockHeight() const = 0; ++ virtual std::string hash() const = 0; ++ virtual size_t internalOutputIndex() const = 0; ++ virtual uint64_t globalOutputIndex() const = 0; ++ virtual bool spent() const = 0; ++ virtual bool frozen() const = 0; ++ virtual uint64_t spentHeight() const = 0; ++ virtual uint64_t amount() const = 0; ++ virtual bool rct() const = 0; ++ virtual bool keyImageKnown() const = 0; ++ virtual size_t pkIndex() const = 0; ++ virtual uint32_t subaddrIndex() const = 0; ++ virtual uint32_t subaddrAccount() const = 0; ++ virtual std::string address() const = 0; ++ virtual std::string addressLabel() const = 0; ++ virtual std::string keyImage() const = 0; ++ virtual uint64_t unlockTime() const = 0; ++ virtual bool unlocked() const = 0; ++ virtual std::string pubKey() const = 0; ++ virtual bool coinbase() const = 0; ++ virtual std::string description() const = 0; ++}; ++ ++struct Coins ++{ ++ virtual ~Coins() = 0; ++ virtual int count() const = 0; ++ virtual CoinsInfo * coin(int index) const = 0; ++ virtual std::vector getAll() const = 0; ++ virtual void refresh() = 0; ++ virtual void setFrozen(std::string public_key) = 0; ++ virtual void setFrozen(int index) = 0; ++ virtual void thaw(std::string public_key) = 0; ++ virtual void thaw(int index) = 0; ++ virtual bool isTransferUnlocked(uint64_t unlockTime, uint64_t blockHeight) = 0; ++ virtual void setDescription(const std::string &public_key, const std::string &description) = 0; ++}; ++ + struct SubaddressRow { + public: + SubaddressRow(std::size_t _rowId, const std::string &_address, const std::string &_label): +@@ -856,7 +901,8 @@ struct Wallet + optional> amount, uint32_t mixin_count, + PendingTransaction::Priority = PendingTransaction::Priority_Low, + uint32_t subaddr_account = 0, +- std::set subaddr_indices = {}) = 0; ++ std::set subaddr_indices = {}, ++ const std::set &preferred_inputs = {}) = 0; + + /*! + * \brief createTransaction creates transaction. if dst_addr is an integrated address, payment_id is ignored +@@ -875,7 +921,8 @@ struct Wallet + optional amount, uint32_t mixin_count, + PendingTransaction::Priority = PendingTransaction::Priority_Low, + uint32_t subaddr_account = 0, +- std::set subaddr_indices = {}) = 0; ++ std::set subaddr_indices = {}, ++ const std::set &preferred_inputs = {}) = 0; + + /*! + * \brief createSweepUnmixableTransaction creates transaction with unmixable outputs. +@@ -994,6 +1041,7 @@ struct Wallet + + virtual TransactionHistory * history() = 0; + virtual AddressBook * addressBook() = 0; ++ virtual Coins * coins() = 0; + virtual Subaddress * subaddress() = 0; + virtual SubaddressAccount * subaddressAccount() = 0; + virtual void setListener(WalletListener *) = 0; +diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp +index fa346a9..d060bf9 100644 +--- a/src/wallet/wallet2.cpp ++++ b/src/wallet/wallet2.cpp +@@ -2094,12 +2094,21 @@ bool wallet2::frozen(const multisig_tx_set& txs) const + + return false; + } ++void wallet2::freeze(const crypto::public_key &pk) ++{ ++ freeze(get_transfer_details(pk)); ++} + //---------------------------------------------------------------------------------------------------- + void wallet2::freeze(const crypto::key_image &ki) + { + freeze(get_transfer_details(ki)); + } + //---------------------------------------------------------------------------------------------------- ++void wallet2::thaw(const crypto::public_key &pk) ++{ ++ thaw(get_transfer_details(pk)); ++} ++//---------------------------------------------------------------------------------------------------- + void wallet2::thaw(const crypto::key_image &ki) + { + thaw(get_transfer_details(ki)); +@@ -2110,6 +2119,18 @@ bool wallet2::frozen(const crypto::key_image &ki) const + return frozen(get_transfer_details(ki)); + } + //---------------------------------------------------------------------------------------------------- ++size_t wallet2::get_transfer_details(const crypto::public_key &pk) const ++{ ++ for (size_t idx = 0; idx < m_transfers.size(); ++idx) ++ { ++ const transfer_details &td = m_transfers[idx]; ++ if (td.get_public_key() == pk) { ++ return idx; ++ } ++ } ++ CHECK_AND_ASSERT_THROW_MES(false, "Public key not found"); ++} ++//---------------------------------------------------------------------------------------------------- + size_t wallet2::get_transfer_details(const crypto::key_image &ki) const + { + for (size_t idx = 0; idx < m_transfers.size(); ++idx) +@@ -2521,6 +2542,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote + uint64_t amount = tx.vout[o].amount ? tx.vout[o].amount : tx_scan_info[o].amount; + if (!pool) + { ++ boost::unique_lock lock(m_transfers_mutex); + m_transfers.push_back(transfer_details{}); + transfer_details& td = m_transfers.back(); + td.m_block_height = height; +@@ -2624,6 +2646,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote + uint64_t extra_amount = amount - burnt; + if (!pool) + { ++ boost::unique_lock lock(m_transfers_mutex); + transfer_details &td = m_transfers[kit->second]; + td.m_block_height = height; + td.m_internal_output_index = o; +@@ -10500,7 +10523,7 @@ void wallet2::transfer_selected_rct(std::vector wallet2::pick_preferred_rct_inputs(uint64_t needed_money, uint32_t subaddr_account, const std::set &subaddr_indices) ++std::vector wallet2::pick_preferred_rct_inputs(uint64_t needed_money, uint32_t subaddr_account, const std::set &subaddr_indices, const std::vector& preferred_input_list) + { + std::vector picks; + float current_output_relatdness = 1.0f; +@@ -10511,6 +10534,9 @@ std::vector wallet2::pick_preferred_rct_inputs(uint64_t needed_money, ui + for (size_t i = 0; i < m_transfers.size(); ++i) + { + const transfer_details& td = m_transfers[i]; ++ if (!is_preferred_input(preferred_input_list, td.m_key_image)) { ++ continue; ++ } + if (!is_spent(td, false) && !td.m_frozen && td.is_rct() && td.amount() >= needed_money && is_transfer_unlocked(td) && td.m_subaddr_index.major == subaddr_account && subaddr_indices.count(td.m_subaddr_index.minor) == 1) + { + if (td.amount() > m_ignore_outputs_above || td.amount() < m_ignore_outputs_below) +@@ -10531,6 +10557,9 @@ std::vector wallet2::pick_preferred_rct_inputs(uint64_t needed_money, ui + for (size_t i = 0; i < m_transfers.size(); ++i) + { + const transfer_details& td = m_transfers[i]; ++ if (!is_preferred_input(preferred_input_list, td.m_key_image)) { ++ continue; ++ } + if (!is_spent(td, false) && !td.m_frozen && !td.m_key_image_partial && td.is_rct() && is_transfer_unlocked(td) && td.m_subaddr_index.major == subaddr_account && subaddr_indices.count(td.m_subaddr_index.minor) == 1) + { + if (td.amount() > m_ignore_outputs_above || td.amount() < m_ignore_outputs_below) +@@ -10542,6 +10571,9 @@ std::vector wallet2::pick_preferred_rct_inputs(uint64_t needed_money, ui + for (size_t j = i + 1; j < m_transfers.size(); ++j) + { + const transfer_details& td2 = m_transfers[j]; ++ if (!is_preferred_input(preferred_input_list, td2.m_key_image)) { ++ continue; ++ } + if (td2.amount() > m_ignore_outputs_above || td2.amount() < m_ignore_outputs_below) + { + MDEBUG("Ignoring output " << j << " of amount " << print_money(td2.amount()) << " which is outside prescribed range [" << print_money(m_ignore_outputs_below) << ", " << print_money(m_ignore_outputs_above) << "]"); +@@ -11114,7 +11146,7 @@ bool wallet2::light_wallet_key_image_is_ours(const crypto::key_image& key_image, + // This system allows for sending (almost) the entire balance, since it does + // not generate spurious change in all txes, thus decreasing the instantaneous + // usable balance. +-std::vector wallet2::create_transactions_2(std::vector dsts, const size_t fake_outs_count, uint32_t priority, const std::vector& extra, uint32_t subaddr_account, std::set subaddr_indices, const unique_index_container& subtract_fee_from_outputs) ++std::vector wallet2::create_transactions_2(std::vector dsts, const size_t fake_outs_count, uint32_t priority, const std::vector& extra, uint32_t subaddr_account, std::set subaddr_indices, const std::vector& preferred_input_list, const unique_index_container& subtract_fee_from_outputs) + { + //ensure device is let in NONE mode in any case + hw::device &hwdev = m_account.get_device(); +@@ -11322,6 +11354,9 @@ std::vector wallet2::create_transactions_2(std::vector wallet2::create_transactions_2(std::vector &ptx_vector, c + return true; + } + +-std::vector wallet2::create_transactions_all(uint64_t below, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, uint32_t priority, const std::vector& extra, uint32_t subaddr_account, std::set subaddr_indices) ++std::vector wallet2::create_transactions_all(uint64_t below, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, uint32_t priority, const std::vector& extra, uint32_t subaddr_account, std::set subaddr_indices, const std::vector& preferred_input_list) + { + std::vector unused_transfers_indices; + std::vector unused_dust_indices; +@@ -11921,6 +11956,9 @@ std::vector wallet2::create_transactions_all(uint64_t below + for (size_t i = 0; i < m_transfers.size(); ++i) + { + const transfer_details& td = m_transfers[i]; ++ if (!is_preferred_input(preferred_input_list, td.m_key_image)) { ++ continue; ++ } + if (m_ignore_fractional_outputs && td.amount() < fractional_threshold) + { + MDEBUG("Ignoring output " << i << " of amount " << print_money(td.amount()) << " which is below threshold " << print_money(fractional_threshold)); +diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h +index 91cf2a3..bc16d52 100644 +--- a/src/wallet/wallet2.h ++++ b/src/wallet/wallet2.h +@@ -1209,8 +1209,8 @@ private: + bool parse_unsigned_tx_from_str(const std::string &unsigned_tx_st, unsigned_tx_set &exported_txs) const; + bool load_tx(const std::string &signed_filename, std::vector &ptx, std::function accept_func = NULL); + bool parse_tx_from_str(const std::string &signed_tx_st, std::vector &ptx, std::function accept_func); +- std::vector create_transactions_2(std::vector dsts, const size_t fake_outs_count, uint32_t priority, const std::vector& extra, uint32_t subaddr_account, std::set subaddr_indices, const unique_index_container& subtract_fee_from_outputs = {}); // pass subaddr_indices by value on purpose +- std::vector create_transactions_all(uint64_t below, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, uint32_t priority, const std::vector& extra, uint32_t subaddr_account, std::set subaddr_indices); ++ std::vector create_transactions_2(std::vector dsts, const size_t fake_outs_count, uint32_t priority, const std::vector& extra, uint32_t subaddr_account, std::set subaddr_indices, const std::vector& preferred_input_list = {}, const unique_index_container& subtract_fee_from_outputs = {}); // pass subaddr_indices by value on purpose ++ std::vector create_transactions_all(uint64_t below, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, uint32_t priority, const std::vector& extra, uint32_t subaddr_account, std::set subaddr_indices, const std::vector& preferred_input_list = {}); + std::vector create_transactions_single(const crypto::key_image &ki, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, uint32_t priority, const std::vector& extra); + std::vector create_transactions_from(const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, std::vector unused_transfers_indices, std::vector unused_dust_indices, const size_t fake_outs_count, uint32_t priority, const std::vector& extra); + bool sanity_check(const std::vector &ptx_vector, const std::vector& dsts, const unique_index_container& subtract_fee_from_outputs = {}) const; +@@ -1562,6 +1562,7 @@ private: + uint64_t get_num_rct_outputs(); + size_t get_num_transfer_details() const { return m_transfers.size(); } + const transfer_details &get_transfer_details(size_t idx) const; ++ size_t get_transfer_details(const crypto::public_key &pk) const; + + uint8_t get_current_hard_fork(); + void get_hard_fork_info(uint8_t version, uint64_t &earliest_height); +@@ -1793,7 +1794,9 @@ private: + void freeze(size_t idx); + void thaw(size_t idx); + bool frozen(size_t idx) const; ++ void freeze(const crypto::public_key &pk); + void freeze(const crypto::key_image &ki); ++ void thaw(const crypto::public_key &pk); + void thaw(const crypto::key_image &ki); + bool frozen(const crypto::key_image &ki) const; + bool frozen(const transfer_details &td) const; +@@ -1834,6 +1837,8 @@ private: + + static std::string get_default_daemon_address() { CRITICAL_REGION_LOCAL(default_daemon_address_lock); return default_daemon_address; } + ++ boost::shared_mutex m_transfers_mutex; ++ + private: + /*! + * \brief Stores wallet information to wallet file. +@@ -1905,7 +1910,7 @@ private: + std::vector get_unspent_amounts_vector(bool strict); + uint64_t get_dynamic_base_fee_estimate(); + float get_output_relatedness(const transfer_details &td0, const transfer_details &td1) const; +- std::vector pick_preferred_rct_inputs(uint64_t needed_money, uint32_t subaddr_account, const std::set &subaddr_indices); ++ std::vector pick_preferred_rct_inputs(uint64_t needed_money, uint32_t subaddr_account, const std::set &subaddr_indices, const std::vector& preferred_input_list); + void set_spent(size_t idx, uint64_t height); + void set_unspent(size_t idx); + bool is_spent(const transfer_details &td, bool strict = true) const; +-- +2.39.5 (Apple Git-154) + -- cgit v1.2.3 From 58267fe5bd07b0a22f533f0139de013ee9087c2f Mon Sep 17 00:00:00 2001 From: cyan Date: Mon, 30 Dec 2024 13:49:32 +0000 Subject: update coin-control patch --- patches/monero/0009-coin-control.patch | 105 ++++++++++++++++++++++++++------- 1 file changed, 84 insertions(+), 21 deletions(-) (limited to 'patches/monero/0009-coin-control.patch') diff --git a/patches/monero/0009-coin-control.patch b/patches/monero/0009-coin-control.patch index 1aac12a..4c4b842 100644 --- a/patches/monero/0009-coin-control.patch +++ b/patches/monero/0009-coin-control.patch @@ -1,7 +1,7 @@ -From 4d897d9ee1d24710500f4d58e9ccd79fb48cf1d2 Mon Sep 17 00:00:00 2001 +From d15a18cac55cb06d5421ecfef1118e439d0cd572 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Tue, 12 Mar 2024 11:07:57 +0100 -Subject: [PATCH 09/14] coin control +Subject: [PATCH 10/15] coin control --- src/simplewallet/simplewallet.cpp | 2 +- @@ -10,19 +10,19 @@ Subject: [PATCH 09/14] coin control src/wallet/api/coins.h | 40 +++++++ src/wallet/api/coins_info.cpp | 122 ++++++++++++++++++++ src/wallet/api/coins_info.h | 71 ++++++++++++ - src/wallet/api/wallet.cpp | 64 +++++++++- + src/wallet/api/wallet.cpp | 106 ++++++++++++++++- src/wallet/api/wallet.h | 10 +- src/wallet/api/wallet2_api.h | 52 ++++++++- src/wallet/wallet2.cpp | 46 +++++++- src/wallet/wallet2.h | 11 +- - 11 files changed, 593 insertions(+), 19 deletions(-) + 11 files changed, 635 insertions(+), 19 deletions(-) create mode 100644 src/wallet/api/coins.cpp create mode 100644 src/wallet/api/coins.h create mode 100644 src/wallet/api/coins_info.cpp create mode 100644 src/wallet/api/coins_info.h diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp -index 2c51337..645bd37 100644 +index 2c51337ef..645bd37e2 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -6930,7 +6930,7 @@ bool simple_wallet::transfer_main(const std::vector &args_, bool ca @@ -35,7 +35,7 @@ index 2c51337..645bd37 100644 if (ptx_vector.empty()) { diff --git a/src/wallet/api/CMakeLists.txt b/src/wallet/api/CMakeLists.txt -index af7948d..bb740e2 100644 +index af7948d8a..bb740e2ac 100644 --- a/src/wallet/api/CMakeLists.txt +++ b/src/wallet/api/CMakeLists.txt @@ -40,7 +40,9 @@ set(wallet_api_sources @@ -62,7 +62,7 @@ index af7948d..bb740e2 100644 ${wallet_api_private_headers}) diff --git a/src/wallet/api/coins.cpp b/src/wallet/api/coins.cpp new file mode 100644 -index 0000000..ef12141 +index 000000000..ef12141cf --- /dev/null +++ b/src/wallet/api/coins.cpp @@ -0,0 +1,186 @@ @@ -254,7 +254,7 @@ index 0000000..ef12141 +} // namespace diff --git a/src/wallet/api/coins.h b/src/wallet/api/coins.h new file mode 100644 -index 0000000..b7a0a86 +index 000000000..b7a0a8642 --- /dev/null +++ b/src/wallet/api/coins.h @@ -0,0 +1,40 @@ @@ -300,7 +300,7 @@ index 0000000..b7a0a86 +#endif //FEATHER_COINS_H diff --git a/src/wallet/api/coins_info.cpp b/src/wallet/api/coins_info.cpp new file mode 100644 -index 0000000..5f2c4e1 +index 000000000..5f2c4e1e4 --- /dev/null +++ b/src/wallet/api/coins_info.cpp @@ -0,0 +1,122 @@ @@ -428,7 +428,7 @@ index 0000000..5f2c4e1 +namespace Bitmonero = Monero; diff --git a/src/wallet/api/coins_info.h b/src/wallet/api/coins_info.h new file mode 100644 -index 0000000..c43e45a +index 000000000..c43e45abd --- /dev/null +++ b/src/wallet/api/coins_info.h @@ -0,0 +1,71 @@ @@ -504,7 +504,7 @@ index 0000000..c43e45a + +#endif //FEATHER_COINS_INFO_H diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp -index 67ac90a..6bb3a21 100644 +index 67ac90a46..a76d773ba 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -35,6 +35,7 @@ @@ -548,7 +548,7 @@ index 67ac90a..6bb3a21 100644 de.is_subaddress = info.is_subaddress; de.is_integrated = info.has_payment_id; dsts.push_back(de); -@@ -2115,6 +2119,51 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector preferred_input_list; ++ uint64_t max_coin_control_input = 0; ++ uint64_t max_frozen_input = 0; + if (!preferred_inputs.empty()) { -+ LOG_ERROR("empty"); ++ LOG_ERROR("not empty"); + + for (const auto &public_key : preferred_inputs) { + crypto::key_image keyImage; @@ -576,6 +578,16 @@ index 67ac90a..6bb3a21 100644 + break; + } + ++ for (size_t i = 0; i < m_wallet->get_num_transfer_details(); ++i) { ++ const tools::wallet2::transfer_details &td = m_wallet->get_transfer_details(i); ++ if (td.m_key_image == keyImage) { ++ max_coin_control_input += td.amount(); ++ } ++ if (td.m_frozen) { ++ max_frozen_input += td.amount(); ++ } ++ } ++ + preferred_input_list.push_back(keyImage); + } + } else { @@ -600,7 +612,7 @@ index 67ac90a..6bb3a21 100644 if (error) { break; } -@@ -2129,11 +2178,11 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vectorm_pending_tx = m_wallet->create_transactions_2(dsts, fake_outs_count, adjusted_priority, @@ -614,7 +626,58 @@ index 67ac90a..6bb3a21 100644 } pendingTxPostProcess(transaction); -@@ -2214,10 +2263,10 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector amount, uint32_t mixin_count, @@ -627,7 +690,7 @@ index 67ac90a..6bb3a21 100644 } PendingTransaction *WalletImpl::createSweepUnmixableTransaction() -@@ -2342,6 +2391,11 @@ AddressBook *WalletImpl::addressBook() +@@ -2342,6 +2433,11 @@ AddressBook *WalletImpl::addressBook() return m_addressBook.get(); } @@ -640,7 +703,7 @@ index 67ac90a..6bb3a21 100644 { return m_subaddress.get(); diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h -index 32e1228..a82f270 100644 +index 32e12284b..a82f270e4 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -46,6 +46,7 @@ class PendingTransactionImpl; @@ -693,7 +756,7 @@ index 32e1228..a82f270 100644 // multi-threaded refresh stuff diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h -index be1c370..013b5bc 100644 +index be1c3704e..013b5bcba 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -263,6 +263,51 @@ struct AddressBook @@ -777,7 +840,7 @@ index be1c370..013b5bc 100644 virtual SubaddressAccount * subaddressAccount() = 0; virtual void setListener(WalletListener *) = 0; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp -index fa346a9..d060bf9 100644 +index fa346a96e..d060bf95b 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2094,12 +2094,21 @@ bool wallet2::frozen(const multisig_tx_set& txs) const @@ -924,7 +987,7 @@ index fa346a9..d060bf9 100644 { MDEBUG("Ignoring output " << i << " of amount " << print_money(td.amount()) << " which is below threshold " << print_money(fractional_threshold)); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h -index 91cf2a3..bc16d52 100644 +index 91cf2a376..bc16d528c 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1209,8 +1209,8 @@ private: @@ -975,5 +1038,5 @@ index 91cf2a3..bc16d52 100644 void set_unspent(size_t idx); bool is_spent(const transfer_details &td, bool strict = true) const; -- -2.39.5 (Apple Git-154) +2.43.0 -- cgit v1.2.3 From fcc2924f31e6ecc1ad787ab6c704188c393318aa Mon Sep 17 00:00:00 2001 From: cyan Date: Sat, 4 Jan 2025 09:02:44 +0100 Subject: initial zano commit (#83) * initial zano commit * update checksum, fix zano patches on CI * fix monero builds * fix cmake command * fix: devcontainer on x64 ffigen: add zano zano: add missing free dart: implement zano * update boost filenames * unboost the cmakelists * fix zano boost issues * added patch into proper location * fix various build issues * [skip ci] update tor-connect * fix zano builds for ios * fix apply patches and don't fail-fast * uncomment build depends for monero * build_single.sh fix for macos native builds * disable qemu on arm64 builders from buildjet * fix boost, fix missing symbols (maybe) * fix ordering of crypto and ssl libraries * fix wownero mingw * fetch zano releases to release-bulk * build things 'the zano way' * proper cmake config * Zano.. yeah... * Update zano release to 2.0.1.367 * update zano patches * update zano builds * update zano build * fix zano build * move zlibstatic to the top (this shouldn't matter anyway) * fix patch location, update tor-connect * update ci runner * fix zano build on the CI * enable zano for other targets * nvm * don't use darwin in single release file * Increase max password length * build contrib/depends offline * zano support for macos * Update dependencies to work on multithread via rosetta2 * different way of adding .patch-applied * Improve performance of incremental builds * remove unnecessary patches * update coin-control patch * fix test * remove contrib/depends patches in wownero * chore: support fallback names in the download_deps util --------- Co-authored-by: Im-Beast --- .devcontainer/Dockerfile | 5 +- .github/workflows/full_check.yaml | 34 +- .gitmodules | 4 + README.md | 3 +- apply_patches.sh | 27 +- build_single.sh | 21 +- contrib/depends/packages/android_ndk.mk | 2 +- contrib/depends/packages/native_ccache.mk | 4 +- contrib/depends/packages/sodium.mk | 4 +- contrib/depends/toolchain.cmake.in | 1 + generate_checksum.sh | 2 +- impls/monero.dart/ffigen_zano.yaml | 11 + impls/monero.dart/lib/src/checksum_zano.dart | 4 + .../lib/src/generated_bindings_zano.g.dart | 527 ++++++++++++++++ impls/monero.dart/lib/zano.dart | 688 +++++++++++++++++++++ impls/monero.dart/update_bindings.sh | 1 + impls/monero.ts/checksum_zano.ts | 5 + monero_libwallet2_api_c/CMakeLists.txt | 60 +- monero_libwallet2_api_c/src/main/cpp/helpers.hpp | 1 + patches/monero/0009-coin-control.patch | 211 ++++--- patches/zano/0001-add-missing-include.patch | 64 ++ patches/zano/0002-fix-build-issues.patch | 39 ++ patches/zano/0003-fix-mingw-build-issues.patch | 61 ++ patches/zano/0004-update-tor-connect.patch | 33 + patches/zano/0005-fix-ios-builds.patch | 43 ++ ...006-use-boost-filesystem-instead-of-stdfs.patch | 80 +++ ...ade-cmake-version-so-LIB_DEPENDS-shows-up.patch | 22 + patches/zano/0008-increase-max-password.patch | 25 + tests/.DS_Store | Bin 0 -> 6148 bytes tests/download_deps.ts | 171 +++-- tests/integration.test.ts | 2 +- tests/utils.ts | 4 +- zano | 1 + zano_libwallet2_api_c/CMakeLists.txt | 1 + zano_libwallet2_api_c/src/main/cpp/helpers.cpp | 1 + zano_libwallet2_api_c/src/main/cpp/helpers.hpp | 1 + .../src/main/cpp/wallet2_api_c.cpp | 322 ++++++++++ zano_libwallet2_api_c/src/main/cpp/wallet2_api_c.h | 67 ++ zano_libwallet2_api_c/src/main/cpp/zano_checksum.h | 6 + zano_libwallet2_api_c/zano_libwallet2_api_c.exp | 33 + 40 files changed, 2411 insertions(+), 180 deletions(-) create mode 100644 impls/monero.dart/ffigen_zano.yaml create mode 100644 impls/monero.dart/lib/src/checksum_zano.dart create mode 100644 impls/monero.dart/lib/src/generated_bindings_zano.g.dart create mode 100644 impls/monero.dart/lib/zano.dart create mode 100644 impls/monero.ts/checksum_zano.ts create mode 100644 patches/zano/0001-add-missing-include.patch create mode 100644 patches/zano/0002-fix-build-issues.patch create mode 100644 patches/zano/0003-fix-mingw-build-issues.patch create mode 100644 patches/zano/0004-update-tor-connect.patch create mode 100644 patches/zano/0005-fix-ios-builds.patch create mode 100644 patches/zano/0006-use-boost-filesystem-instead-of-stdfs.patch create mode 100644 patches/zano/0007-downgrade-cmake-version-so-LIB_DEPENDS-shows-up.patch create mode 100644 patches/zano/0008-increase-max-password.patch create mode 100644 tests/.DS_Store create mode 160000 zano create mode 120000 zano_libwallet2_api_c/CMakeLists.txt create mode 120000 zano_libwallet2_api_c/src/main/cpp/helpers.cpp create mode 120000 zano_libwallet2_api_c/src/main/cpp/helpers.hpp create mode 100644 zano_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp create mode 100644 zano_libwallet2_api_c/src/main/cpp/wallet2_api_c.h create mode 100644 zano_libwallet2_api_c/src/main/cpp/zano_checksum.h create mode 100644 zano_libwallet2_api_c/zano_libwallet2_api_c.exp (limited to 'patches/monero/0009-coin-control.patch') diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 6dc59c4..ed16f21 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -6,7 +6,10 @@ SHELL ["/bin/bash", "-c"] # lintinfo5 -RUN wget http://mirrors.kernel.org/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb -O libtinfo5.deb \ +SHELL ["/bin/bash", "-c"] + +RUN [[ "$(uname -m)" == "aarch64" || "$(uname -m)" == "arm64" ]] && exit 0 \ + || wget http://mirrors.kernel.org/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb -O libtinfo5.deb \ && apt install ./libtinfo5.deb \ && rm libtinfo5.deb diff --git a/.github/workflows/full_check.yaml b/.github/workflows/full_check.yaml index e083dd6..20dcbc5 100644 --- a/.github/workflows/full_check.yaml +++ b/.github/workflows/full_check.yaml @@ -64,8 +64,8 @@ jobs: strategy: fail-fast: false matrix: - coin: [monero, wownero] - runs-on: ubuntu-24.04 + coin: [monero, wownero, zano] + runs-on: ubuntu-22.04 # container: # image: debian:bookworm steps: @@ -137,7 +137,7 @@ jobs: strategy: fail-fast: false matrix: - coin: [monero, wownero] + coin: [monero, wownero, zano] runs-on: ubuntu-latest container: image: debian:bullseye @@ -195,7 +195,7 @@ jobs: strategy: fail-fast: false matrix: - coin: [monero, wownero] + coin: [monero, wownero, zano] name: macos build runs-on: macos-14 steps: @@ -210,7 +210,7 @@ jobs: xcode-version: '15.4' - name: install dependencies run: | - brew install ccache binutils pigz autoconf automake libtool + brew install ccache binutils pigz autoconf automake libtool pkg-config - name: Patch sources run: | git config --global --add safe.directory '*' @@ -256,9 +256,9 @@ jobs: strategy: fail-fast: false matrix: - coin: [monero, wownero] + coin: [monero, wownero, zano] name: ios build - runs-on: macos-14 + runs-on: macos-15 steps: - name: Checkout monero_c repo uses: actions/checkout@v4 @@ -268,10 +268,10 @@ jobs: submodules: recursive - uses: maxim-lobanov/setup-xcode@v1 with: - xcode-version: '15.4' + xcode-version: '16.1' - name: install dependencies run: | - brew install ccache unbound zmq autoconf automake libtool + brew install ccache cmake autoconf automake libtool - name: Patch sources run: | git config --global --add safe.directory '*' @@ -325,6 +325,10 @@ jobs: with: name: android wownero path: release/wownero + - uses: actions/download-artifact@v4 + with: + name: android zano + path: release/zano - uses: actions/download-artifact@v4 with: name: ios monero @@ -333,6 +337,10 @@ jobs: with: name: ios wownero path: release/wownero + - uses: actions/download-artifact@v4 + with: + name: ios zano + path: release/zano - uses: actions/download-artifact@v4 with: name: linux monero @@ -341,6 +349,10 @@ jobs: with: name: linux wownero path: release/wownero + - uses: actions/download-artifact@v4 + with: + name: linux zano + path: release/zano - uses: actions/download-artifact@v4 with: name: macos monero @@ -349,6 +361,10 @@ jobs: with: name: macos wownero path: release/wownero + - uses: actions/download-artifact@v4 + with: + name: macos zano + path: release/zano - uses: actions/download-artifact@v4 with: name: mingw monero diff --git a/.gitmodules b/.gitmodules index ecf86b2..04af1e1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,6 +7,10 @@ path = wownero url = https://codeberg.org/wownero/wownero shallow = true +[submodule "zano"] + path = zano + url = https://github.com/hyle-team/zano + shallow = true [submodule "wownero_libwallet2_api_c/wownero-seed"] path = wownero_libwallet2_api_c/wownero-seed url = https://github.com/MrCyjaneK/wownero-seed diff --git a/README.md b/README.md index 4036888..5ed7564 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,7 @@ TL;DR: ```bash $ rm -rf monero wownero release $ git submodule update --init --recursive --force -$ for coin in monero wownero; do ./apply_patches.sh $coin; done -$ ./build_single monero $(gcc -dumpmachine) -j$(nproc) +$ for coin in monero wownero zano; do ./apply_patches.sh $coin; done ``` Broken? Not working? Need help? https://moneroc.mrcyjanek.net/ diff --git a/apply_patches.sh b/apply_patches.sh index 22c3bba..8013c9d 100755 --- a/apply_patches.sh +++ b/apply_patches.sh @@ -38,7 +38,30 @@ then git remote set-url origin https://github.com/mrcyjanek/randomwow.git popd fi +if [[ "$repo" == "zano" ]]; +then + pushd contrib/tor-connect + git remote set-url origin https://github.com/mrcyjanek/tor-connect.git + popd +fi git submodule init git submodule update --init --recursive --force -touch .patch-applied -echo "you are good to go!" \ No newline at end of file +git am -3 < +Date: Fri, 20 Dec 2024 09:18:08 +0100 +Subject: [PATCH] add .patch-applied + +--- + .patch-applied | 0 + 1 file changed, 0 insertions(+), 0 deletions(-) + create mode 100644 .patch-applied + +diff --git a/.patch-applied b/.patch-applied +new file mode 100644 +index 000000000..e69de29bb +-- +2.39.5 (Apple Git-154) +EOF + +echo "you are good to go!" diff --git a/build_single.sh b/build_single.sh index f868f98..0309a28 100755 --- a/build_single.sh +++ b/build_single.sh @@ -20,14 +20,14 @@ set -e repo=$1 if [[ "x$repo" == "x" ]]; then - echo "Usage: $0 monero/wownero $(gcc -dumpmachine) -j$proccount" + echo "Usage: $0 monero/wownero/zano $(gcc -dumpmachine) -j$proccount" exit 1 fi -if [[ "x$repo" != "xwownero" && "x$repo" != "xmonero" ]]; +if [[ "x$repo" != "xwownero" && "x$repo" != "xmonero" && "x$repo" != "xzano" ]]; then - echo "Usage: $0 monero/wownero $(gcc -dumpmachine) -j$proccount" - echo "Invalid target given, only monero and wownero are supported targets" + echo "Usage: $0 monero/wownero/zano $(gcc -dumpmachine) -j$proccount" + echo "Invalid target given" exit 1 fi @@ -55,7 +55,12 @@ fi cd $(dirname $0) WDIR=$PWD pushd contrib/depends - env -i PATH="$PATH" CC=gcc CXX=g++ make "$NPROC" HOST="$HOST_ABI" + if [[ -d $HOST_ABI ]]; + then + echo "Not building depends, directory exists" + else + env -i PATH="$PATH" CC=gcc CXX=g++ make "$NPROC" HOST="$HOST_ABI" + fi popd buildType=Debug @@ -63,8 +68,12 @@ buildType=Debug pushd ${repo}_libwallet2_api_c rm -rf build/${HOST_ABI} || true mkdir -p build/${HOST_ABI} -p + if [[ "$repo" == "zano" ]]; + then + EXTRA_CMAKE_FLAGS="-DCAKEWALLET=ON" + fi pushd build/${HOST_ABI} - cmake -DCMAKE_TOOLCHAIN_FILE=$PWD/../../../contrib/depends/${HOST_ABI}/share/toolchain.cmake -DUSE_DEVICE_TREZOR=OFF -DMONERO_FLAVOR=$repo -DCMAKE_BUILD_TYPE=Debug -DHOST_ABI=${HOST_ABI} ../.. + cmake -DCMAKE_TOOLCHAIN_FILE=$PWD/../../../contrib/depends/${HOST_ABI}/share/toolchain.cmake $EXTRA_CMAKE_FLAGS -DUSE_DEVICE_TREZOR=OFF -DMONERO_FLAVOR=$repo -DCMAKE_BUILD_TYPE=Debug -DHOST_ABI=${HOST_ABI} ../.. make $NPROC popd popd diff --git a/contrib/depends/packages/android_ndk.mk b/contrib/depends/packages/android_ndk.mk index 2c2914e..89db323 100644 --- a/contrib/depends/packages/android_ndk.mk +++ b/contrib/depends/packages/android_ndk.mk @@ -15,7 +15,7 @@ endef define $(package)_extract_cmds echo $($(package)_sha256_hash) $($(1)_source_dir)/$($(package)_file_name) | sha256sum -c &&\ - unzip -q $($(1)_source_dir)/$($(package)_file_name) + echo "A" | unzip -q $($(1)_source_dir)/$($(package)_file_name) endef # arm-linux-androideabi-ar - openssl workaround diff --git a/contrib/depends/packages/native_ccache.mk b/contrib/depends/packages/native_ccache.mk index 6821454..1523660 100644 --- a/contrib/depends/packages/native_ccache.mk +++ b/contrib/depends/packages/native_ccache.mk @@ -5,7 +5,7 @@ $(package)_file_name=ccache-$($(package)_version).tar.gz $(package)_sha256_hash=108100960bb7e64573ea925af2ee7611701241abb36ce0aae3354528403a7d87 define $(package)_set_vars -$(package)_config_opts=-DCMAKE_INSTALL_PREFIX="$(host_prefix)/native" +$(package)_config_opts=-DCMAKE_INSTALL_PREFIX="$(host_prefix)/native" -DENABLE_TESTING=OFF endef define $(package)_config_cmds @@ -17,7 +17,7 @@ define $(package)_build_cmds endef define $(package)_stage_cmds - cd build && $(MAKE) DESTDIR=$($(package)_staging_dir) install + cd build && $(MAKE) -j1 DESTDIR=$($(package)_staging_dir) install endef define $(package)_postprocess_cmds diff --git a/contrib/depends/packages/sodium.mk b/contrib/depends/packages/sodium.mk index 8e85a4e..0050bd3 100644 --- a/contrib/depends/packages/sodium.mk +++ b/contrib/depends/packages/sodium.mk @@ -21,11 +21,11 @@ define $(package)_config_cmds endef define $(package)_build_cmds - $(MAKE) -j$(NUM_CORES) + $(MAKE) endef define $(package)_stage_cmds - $(MAKE) DESTDIR=$($(package)_staging_dir) install + $(MAKE) -j1 DESTDIR=$($(package)_staging_dir) install endef define $(package)_postprocess_cmds diff --git a/contrib/depends/toolchain.cmake.in b/contrib/depends/toolchain.cmake.in index 2e0ba52..216741e 100644 --- a/contrib/depends/toolchain.cmake.in +++ b/contrib/depends/toolchain.cmake.in @@ -197,6 +197,7 @@ include_directories(@prefix@/include) include_directories(@prefix@/include/wownero_seed) add_definitions(-DPOLYSEED_STATIC=ON) +add_definitions(-DMOBILE_WALLET_BUILD) #Create a new global cmake flag that indicates building with depends set (DEPENDS true) \ No newline at end of file diff --git a/generate_checksum.sh b/generate_checksum.sh index 4b82e53..ea59961 100755 --- a/generate_checksum.sh +++ b/generate_checksum.sh @@ -6,7 +6,7 @@ then function sha256sum() { shasum -a 256 "$@" ; } && export -f sha256sum fi -for coin in monero wownero; +for coin in monero wownero zano; do submodule_hash=$(git ls-tree HEAD ${coin} | xargs | awk '{ print $3 }') COIN=$(echo "$coin" | tr a-z A-Z) diff --git a/impls/monero.dart/ffigen_zano.yaml b/impls/monero.dart/ffigen_zano.yaml new file mode 100644 index 0000000..2c0f6a0 --- /dev/null +++ b/impls/monero.dart/ffigen_zano.yaml @@ -0,0 +1,11 @@ +name: ZanoC +description: monero_c bindings +output: 'lib/src/generated_bindings_zano.g.dart' +headers: + entry-points: + - '../../zano_libwallet2_api_c/src/main/cpp/wallet2_api_c.h' + +exclude-all-by-default: true +functions: + include: + - "ZANO_.+" \ No newline at end of file diff --git a/impls/monero.dart/lib/src/checksum_zano.dart b/impls/monero.dart/lib/src/checksum_zano.dart new file mode 100644 index 0000000..b8b879a --- /dev/null +++ b/impls/monero.dart/lib/src/checksum_zano.dart @@ -0,0 +1,4 @@ +// ignore_for_file: constant_identifier_names +const String wallet2_api_c_h_sha256 = "8acaa95513b85a984c08e05cc3f2ac7530bb8f32946eeeb45357bd846aef33dd"; +const String wallet2_api_c_cpp_sha256 = "4efacd3812d53dd268b6869cc0a9560e7320574d96e09136cf067f796edfeba6-2817090c8ac7639d6f697d00fc8bcba2b3681d90"; +const String wallet2_api_c_exp_sha256 = "66f3ff655bbfd11ad28c318ab707090b5a93276f436b06f7b1c0f329dba3c9c2"; diff --git a/impls/monero.dart/lib/src/generated_bindings_zano.g.dart b/impls/monero.dart/lib/src/generated_bindings_zano.g.dart new file mode 100644 index 0000000..1ffdc3e --- /dev/null +++ b/impls/monero.dart/lib/src/generated_bindings_zano.g.dart @@ -0,0 +1,527 @@ +// AUTO GENERATED FILE, DO NOT EDIT. +// +// Generated by `package:ffigen`. +// ignore_for_file: type=lint +import 'dart:ffi' as ffi; + +/// monero_c bindings +class ZanoC { + /// Holds the symbol lookup function. + final ffi.Pointer Function(String symbolName) + _lookup; + + /// The symbols are looked up in [dynamicLibrary]. + ZanoC(ffi.DynamicLibrary dynamicLibrary) : _lookup = dynamicLibrary.lookup; + + /// The symbols are looked up with [lookup]. + ZanoC.fromLookup( + ffi.Pointer Function(String symbolName) + lookup) + : _lookup = lookup; + + ffi.Pointer ZANO_PlainWallet_init( + ffi.Pointer address, + ffi.Pointer working_dir, + int log_level, + ) { + return _ZANO_PlainWallet_init( + address, + working_dir, + log_level, + ); + } + + late final _ZANO_PlainWallet_initPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer, ffi.Int)>>('ZANO_PlainWallet_init'); + late final _ZANO_PlainWallet_init = _ZANO_PlainWallet_initPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer, int)>(); + + ffi.Pointer ZANO_PlainWallet_init2( + ffi.Pointer ip, + ffi.Pointer port, + ffi.Pointer working_dir, + int log_level, + ) { + return _ZANO_PlainWallet_init2( + ip, + port, + working_dir, + log_level, + ); + } + + late final _ZANO_PlainWallet_init2Ptr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Int)>>('ZANO_PlainWallet_init2'); + late final _ZANO_PlainWallet_init2 = _ZANO_PlainWallet_init2Ptr.asFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer, ffi.Pointer, int)>(); + + ffi.Pointer ZANO_PlainWallet_reset() { + return _ZANO_PlainWallet_reset(); + } + + late final _ZANO_PlainWallet_resetPtr = + _lookup Function()>>( + 'ZANO_PlainWallet_reset'); + late final _ZANO_PlainWallet_reset = + _ZANO_PlainWallet_resetPtr.asFunction Function()>(); + + ffi.Pointer ZANO_PlainWallet_setLogLevel( + int log_level, + ) { + return _ZANO_PlainWallet_setLogLevel( + log_level, + ); + } + + late final _ZANO_PlainWallet_setLogLevelPtr = + _lookup Function(ffi.Int)>>( + 'ZANO_PlainWallet_setLogLevel'); + late final _ZANO_PlainWallet_setLogLevel = _ZANO_PlainWallet_setLogLevelPtr + .asFunction Function(int)>(); + + ffi.Pointer ZANO_PlainWallet_getVersion() { + return _ZANO_PlainWallet_getVersion(); + } + + late final _ZANO_PlainWallet_getVersionPtr = + _lookup Function()>>( + 'ZANO_PlainWallet_getVersion'); + late final _ZANO_PlainWallet_getVersion = _ZANO_PlainWallet_getVersionPtr + .asFunction Function()>(); + + ffi.Pointer ZANO_PlainWallet_getWalletFiles() { + return _ZANO_PlainWallet_getWalletFiles(); + } + + late final _ZANO_PlainWallet_getWalletFilesPtr = + _lookup Function()>>( + 'ZANO_PlainWallet_getWalletFiles'); + late final _ZANO_PlainWallet_getWalletFiles = + _ZANO_PlainWallet_getWalletFilesPtr.asFunction< + ffi.Pointer Function()>(); + + ffi.Pointer ZANO_PlainWallet_getExportPrivateInfo( + ffi.Pointer target_dir, + ) { + return _ZANO_PlainWallet_getExportPrivateInfo( + target_dir, + ); + } + + late final _ZANO_PlainWallet_getExportPrivateInfoPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('ZANO_PlainWallet_getExportPrivateInfo'); + late final _ZANO_PlainWallet_getExportPrivateInfo = + _ZANO_PlainWallet_getExportPrivateInfoPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + ffi.Pointer ZANO_PlainWallet_deleteWallet( + ffi.Pointer file_name, + ) { + return _ZANO_PlainWallet_deleteWallet( + file_name, + ); + } + + late final _ZANO_PlainWallet_deleteWalletPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('ZANO_PlainWallet_deleteWallet'); + late final _ZANO_PlainWallet_deleteWallet = _ZANO_PlainWallet_deleteWalletPtr + .asFunction Function(ffi.Pointer)>(); + + ffi.Pointer ZANO_PlainWallet_getAddressInfo( + ffi.Pointer addr, + ) { + return _ZANO_PlainWallet_getAddressInfo( + addr, + ); + } + + late final _ZANO_PlainWallet_getAddressInfoPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('ZANO_PlainWallet_getAddressInfo'); + late final _ZANO_PlainWallet_getAddressInfo = + _ZANO_PlainWallet_getAddressInfoPtr.asFunction< + ffi.Pointer Function(ffi.Pointer)>(); + + ffi.Pointer ZANO_PlainWallet_getAppconfig( + ffi.Pointer encryption_key, + ) { + return _ZANO_PlainWallet_getAppconfig( + encryption_key, + ); + } + + late final _ZANO_PlainWallet_getAppconfigPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('ZANO_PlainWallet_getAppconfig'); + late final _ZANO_PlainWallet_getAppconfig = _ZANO_PlainWallet_getAppconfigPtr + .asFunction Function(ffi.Pointer)>(); + + ffi.Pointer ZANO_PlainWallet_setAppconfig( + ffi.Pointer conf_str, + ffi.Pointer encryption_key, + ) { + return _ZANO_PlainWallet_setAppconfig( + conf_str, + encryption_key, + ); + } + + late final _ZANO_PlainWallet_setAppconfigPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer)>>('ZANO_PlainWallet_setAppconfig'); + late final _ZANO_PlainWallet_setAppconfig = + _ZANO_PlainWallet_setAppconfigPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer)>(); + + ffi.Pointer ZANO_PlainWallet_generateRandomKey( + int lenght, + ) { + return _ZANO_PlainWallet_generateRandomKey( + lenght, + ); + } + + late final _ZANO_PlainWallet_generateRandomKeyPtr = + _lookup Function(ffi.Uint64)>>( + 'ZANO_PlainWallet_generateRandomKey'); + late final _ZANO_PlainWallet_generateRandomKey = + _ZANO_PlainWallet_generateRandomKeyPtr.asFunction< + ffi.Pointer Function(int)>(); + + ffi.Pointer ZANO_PlainWallet_getLogsBuffer() { + return _ZANO_PlainWallet_getLogsBuffer(); + } + + late final _ZANO_PlainWallet_getLogsBufferPtr = + _lookup Function()>>( + 'ZANO_PlainWallet_getLogsBuffer'); + late final _ZANO_PlainWallet_getLogsBuffer = + _ZANO_PlainWallet_getLogsBufferPtr.asFunction< + ffi.Pointer Function()>(); + + ffi.Pointer ZANO_PlainWallet_truncateLog() { + return _ZANO_PlainWallet_truncateLog(); + } + + late final _ZANO_PlainWallet_truncateLogPtr = + _lookup Function()>>( + 'ZANO_PlainWallet_truncateLog'); + late final _ZANO_PlainWallet_truncateLog = _ZANO_PlainWallet_truncateLogPtr + .asFunction Function()>(); + + ffi.Pointer ZANO_PlainWallet_getConnectivityStatus() { + return _ZANO_PlainWallet_getConnectivityStatus(); + } + + late final _ZANO_PlainWallet_getConnectivityStatusPtr = + _lookup Function()>>( + 'ZANO_PlainWallet_getConnectivityStatus'); + late final _ZANO_PlainWallet_getConnectivityStatus = + _ZANO_PlainWallet_getConnectivityStatusPtr.asFunction< + ffi.Pointer Function()>(); + + ffi.Pointer ZANO_PlainWallet_open( + ffi.Pointer path, + ffi.Pointer password, + ) { + return _ZANO_PlainWallet_open( + path, + password, + ); + } + + late final _ZANO_PlainWallet_openPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer)>>('ZANO_PlainWallet_open'); + late final _ZANO_PlainWallet_open = _ZANO_PlainWallet_openPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer)>(); + + ffi.Pointer ZANO_PlainWallet_restore( + ffi.Pointer seed, + ffi.Pointer path, + ffi.Pointer password, + ffi.Pointer seed_password, + ) { + return _ZANO_PlainWallet_restore( + seed, + path, + password, + seed_password, + ); + } + + late final _ZANO_PlainWallet_restorePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>('ZANO_PlainWallet_restore'); + late final _ZANO_PlainWallet_restore = + _ZANO_PlainWallet_restorePtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>(); + + ffi.Pointer ZANO_PlainWallet_generate( + ffi.Pointer path, + ffi.Pointer password, + ) { + return _ZANO_PlainWallet_generate( + path, + password, + ); + } + + late final _ZANO_PlainWallet_generatePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer)>>('ZANO_PlainWallet_generate'); + late final _ZANO_PlainWallet_generate = + _ZANO_PlainWallet_generatePtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, ffi.Pointer)>(); + + ffi.Pointer ZANO_PlainWallet_getOpenWallets() { + return _ZANO_PlainWallet_getOpenWallets(); + } + + late final _ZANO_PlainWallet_getOpenWalletsPtr = + _lookup Function()>>( + 'ZANO_PlainWallet_getOpenWallets'); + late final _ZANO_PlainWallet_getOpenWallets = + _ZANO_PlainWallet_getOpenWalletsPtr.asFunction< + ffi.Pointer Function()>(); + + ffi.Pointer ZANO_PlainWallet_getWalletStatus( + int h, + ) { + return _ZANO_PlainWallet_getWalletStatus( + h, + ); + } + + late final _ZANO_PlainWallet_getWalletStatusPtr = + _lookup Function(ffi.Int64)>>( + 'ZANO_PlainWallet_getWalletStatus'); + late final _ZANO_PlainWallet_getWalletStatus = + _ZANO_PlainWallet_getWalletStatusPtr.asFunction< + ffi.Pointer Function(int)>(); + + ffi.Pointer ZANO_PlainWallet_closeWallet( + int h, + ) { + return _ZANO_PlainWallet_closeWallet( + h, + ); + } + + late final _ZANO_PlainWallet_closeWalletPtr = + _lookup Function(ffi.Int64)>>( + 'ZANO_PlainWallet_closeWallet'); + late final _ZANO_PlainWallet_closeWallet = _ZANO_PlainWallet_closeWalletPtr + .asFunction Function(int)>(); + + ffi.Pointer ZANO_PlainWallet_invoke( + int h, + ffi.Pointer params, + ) { + return _ZANO_PlainWallet_invoke( + h, + params, + ); + } + + late final _ZANO_PlainWallet_invokePtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Int64, ffi.Pointer)>>('ZANO_PlainWallet_invoke'); + late final _ZANO_PlainWallet_invoke = _ZANO_PlainWallet_invokePtr.asFunction< + ffi.Pointer Function(int, ffi.Pointer)>(); + + ffi.Pointer ZANO_PlainWallet_asyncCall( + ffi.Pointer method_name, + int instance_id, + ffi.Pointer params, + ) { + return _ZANO_PlainWallet_asyncCall( + method_name, + instance_id, + params, + ); + } + + late final _ZANO_PlainWallet_asyncCallPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, ffi.Uint64, + ffi.Pointer)>>('ZANO_PlainWallet_asyncCall'); + late final _ZANO_PlainWallet_asyncCall = + _ZANO_PlainWallet_asyncCallPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int, ffi.Pointer)>(); + + ffi.Pointer ZANO_PlainWallet_tryPullResult( + int instance_id, + ) { + return _ZANO_PlainWallet_tryPullResult( + instance_id, + ); + } + + late final _ZANO_PlainWallet_tryPullResultPtr = + _lookup Function(ffi.Uint64)>>( + 'ZANO_PlainWallet_tryPullResult'); + late final _ZANO_PlainWallet_tryPullResult = + _ZANO_PlainWallet_tryPullResultPtr.asFunction< + ffi.Pointer Function(int)>(); + + ffi.Pointer ZANO_PlainWallet_syncCall( + ffi.Pointer method_name, + int instance_id, + ffi.Pointer params, + ) { + return _ZANO_PlainWallet_syncCall( + method_name, + instance_id, + params, + ); + } + + late final _ZANO_PlainWallet_syncCallPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, ffi.Uint64, + ffi.Pointer)>>('ZANO_PlainWallet_syncCall'); + late final _ZANO_PlainWallet_syncCall = + _ZANO_PlainWallet_syncCallPtr.asFunction< + ffi.Pointer Function( + ffi.Pointer, int, ffi.Pointer)>(); + + bool ZANO_PlainWallet_isWalletExist( + ffi.Pointer path, + ) { + return _ZANO_PlainWallet_isWalletExist( + path, + ); + } + + late final _ZANO_PlainWallet_isWalletExistPtr = + _lookup)>>( + 'ZANO_PlainWallet_isWalletExist'); + late final _ZANO_PlainWallet_isWalletExist = + _ZANO_PlainWallet_isWalletExistPtr.asFunction< + bool Function(ffi.Pointer)>(); + + ffi.Pointer ZANO_PlainWallet_getWalletInfo( + int h, + ) { + return _ZANO_PlainWallet_getWalletInfo( + h, + ); + } + + late final _ZANO_PlainWallet_getWalletInfoPtr = + _lookup Function(ffi.Int64)>>( + 'ZANO_PlainWallet_getWalletInfo'); + late final _ZANO_PlainWallet_getWalletInfo = + _ZANO_PlainWallet_getWalletInfoPtr.asFunction< + ffi.Pointer Function(int)>(); + + ffi.Pointer ZANO_PlainWallet_resetWalletPassword( + int h, + ffi.Pointer password, + ) { + return _ZANO_PlainWallet_resetWalletPassword( + h, + password, + ); + } + + late final _ZANO_PlainWallet_resetWalletPasswordPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Int64, + ffi.Pointer)>>('ZANO_PlainWallet_resetWalletPassword'); + late final _ZANO_PlainWallet_resetWalletPassword = + _ZANO_PlainWallet_resetWalletPasswordPtr.asFunction< + ffi.Pointer Function(int, ffi.Pointer)>(); + + int ZANO_PlainWallet_getCurrentTxFee( + int priority, + ) { + return _ZANO_PlainWallet_getCurrentTxFee( + priority, + ); + } + + late final _ZANO_PlainWallet_getCurrentTxFeePtr = + _lookup>( + 'ZANO_PlainWallet_getCurrentTxFee'); + late final _ZANO_PlainWallet_getCurrentTxFee = + _ZANO_PlainWallet_getCurrentTxFeePtr.asFunction(); + + void ZANO_free( + ffi.Pointer ptr, + ) { + return _ZANO_free( + ptr, + ); + } + + late final _ZANO_freePtr = + _lookup)>>( + 'ZANO_free'); + late final _ZANO_free = + _ZANO_freePtr.asFunction)>(); + + ffi.Pointer ZANO_checksum_wallet2_api_c_h() { + return _ZANO_checksum_wallet2_api_c_h(); + } + + late final _ZANO_checksum_wallet2_api_c_hPtr = + _lookup Function()>>( + 'ZANO_checksum_wallet2_api_c_h'); + late final _ZANO_checksum_wallet2_api_c_h = _ZANO_checksum_wallet2_api_c_hPtr + .asFunction Function()>(); + + ffi.Pointer ZANO_checksum_wallet2_api_c_cpp() { + return _ZANO_checksum_wallet2_api_c_cpp(); + } + + late final _ZANO_checksum_wallet2_api_c_cppPtr = + _lookup Function()>>( + 'ZANO_checksum_wallet2_api_c_cpp'); + late final _ZANO_checksum_wallet2_api_c_cpp = + _ZANO_checksum_wallet2_api_c_cppPtr.asFunction< + ffi.Pointer Function()>(); + + ffi.Pointer ZANO_checksum_wallet2_api_c_exp() { + return _ZANO_checksum_wallet2_api_c_exp(); + } + + late final _ZANO_checksum_wallet2_api_c_expPtr = + _lookup Function()>>( + 'ZANO_checksum_wallet2_api_c_exp'); + late final _ZANO_checksum_wallet2_api_c_exp = + _ZANO_checksum_wallet2_api_c_expPtr.asFunction< + ffi.Pointer Function()>(); +} diff --git a/impls/monero.dart/lib/zano.dart b/impls/monero.dart/lib/zano.dart new file mode 100644 index 0000000..f17346a --- /dev/null +++ b/impls/monero.dart/lib/zano.dart @@ -0,0 +1,688 @@ + +// ignore_for_file: non_constant_identifier_names, camel_case_types + +import 'dart:ffi'; +import 'dart:io'; + +import 'package:ffi/ffi.dart'; +import 'package:monero/src/generated_bindings_zano.g.dart'; + +export 'src/checksum_monero.dart'; + +typedef PendingTransaction = Pointer; + +ZanoC? lib; +String libPath = (() { + if (Platform.isWindows) return 'zano_libwallet2_api_c.dll'; + if (Platform.isMacOS) return 'zano_libwallet2_api_c.dylib'; + if (Platform.isIOS) return 'ZanoWallet.framework/ZanoWallet'; + if (Platform.isAndroid) return 'libzano_libwallet2_api_c.so'; + return 'zano_libwallet2_api_c.so'; +})(); + +Map> debugCallLength = {}; + +final defaultSeparatorStr = ";"; +final defaultSeparator = defaultSeparatorStr.toNativeUtf8().cast(); +/* we don't call .free here, this comment serves one purpose - so the numbers match :) */ + +final Stopwatch sw = Stopwatch()..start(); + +bool printStarts = false; + +void Function(String call)? debugStart = (call) { + try { + if (printStarts) print("MONERO: $call"); + debugCallLength[call] ??= []; + debugCallLength[call]!.add(sw.elapsedMicroseconds); + } catch (e) {} +}; +void debugChores() { + for (var key in debugCallLength.keys) { + if (debugCallLength[key]!.length > 1000000) { + final elm = + debugCallLength[key]!.reduce((value, element) => value + element); + debugCallLength[key]!.clear(); + debugCallLength["${key}_1M"] ??= []; + debugCallLength["${key}_1M"]!.add(elm); + } + } +} + +int debugCount = 0; + +void Function(String call)? debugEnd = (call) { + try { + final id = debugCallLength[call]!.length - 1; + if (++debugCount > 1000000) { + debugCount = 0; + debugChores(); + } + debugCallLength[call]![id] = + sw.elapsedMicroseconds - debugCallLength[call]![id]; + } catch (e) {} +}; +void Function(String call, dynamic error)? errorHandler = (call, error) { + print("$call: $error"); +}; + +// extern ADDAPI const char* ZANO_PlainWallet_init(const char* address, const char* working_dir, int log_level); +String PlainWallet_init(String address, String working_dir, int log_level) { + debugStart?.call('ZANO_PlainWallet_init'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final address_ = address.toNativeUtf8(); + final working_dir_ = working_dir.toNativeUtf8(); + final txid = lib!.ZANO_PlainWallet_init(address_.cast(), working_dir_.cast(), log_level); + calloc.free(address_); + calloc.free(working_dir_); + debugEnd?.call('ZANO_PlainWallet_init'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_init'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_init', e); + debugEnd?.call('ZANO_PlainWallet_init'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_init2(const char* ip, const char* port, const char* working_dir, int log_level); +String PlainWallet_init2(String ip, String port, String working_dir, int log_level) { + debugStart?.call('ZANO_PlainWallet_init2'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final ip_ = ip.toNativeUtf8(); + final port_ = port.toNativeUtf8(); + final working_dir_ = working_dir.toNativeUtf8(); + final txid = lib!.ZANO_PlainWallet_init2(ip_.cast(), port_.cast(), working_dir_.cast(), log_level); + calloc.free(ip_); + calloc.free(port_); + calloc.free(working_dir_); + debugEnd?.call('ZANO_PlainWallet_init2'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_init2'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_init2', e); + debugEnd?.call('ZANO_PlainWallet_init2'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_reset(); +String PlainWallet_reset() { + debugStart?.call('ZANO_PlainWallet_reset'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_PlainWallet_reset(); + debugEnd?.call('ZANO_PlainWallet_reset'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_reset'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_reset', e); + debugEnd?.call('ZANO_PlainWallet_reset'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_setLogLevel(int log_level); +String PlainWallet_setLogLevel(int log_level) { + debugStart?.call('ZANO_PlainWallet_setLogLevel'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_PlainWallet_setLogLevel(log_level); + debugEnd?.call('ZANO_PlainWallet_setLogLevel'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_setLogLevel'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_setLogLevel', e); + debugEnd?.call('ZANO_PlainWallet_setLogLevel'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_getVersion(); +String PlainWallet_getVersion() { + debugStart?.call('ZANO_PlainWallet_getVersion'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_PlainWallet_getVersion(); + debugEnd?.call('ZANO_PlainWallet_getVersion'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_getVersion'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_getVersion', e); + debugEnd?.call('ZANO_PlainWallet_getVersion'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_getWalletFiles(); +String PlainWallet_getWalletFiles() { + debugStart?.call('ZANO_PlainWallet_getWalletFiles'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_PlainWallet_getWalletFiles(); + debugEnd?.call('ZANO_PlainWallet_getWalletFiles'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_getWalletFiles'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_getWalletFiles', e); + debugEnd?.call('ZANO_PlainWallet_getWalletFiles'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_getExportPrivateInfo(const char* target_dir); +String PlainWallet_getExportPrivateInfo(String target_dir) { + debugStart?.call('ZANO_PlainWallet_getExportPrivateInfo'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final target_dir_ = target_dir.toNativeUtf8(); + final txid = lib!.ZANO_PlainWallet_getExportPrivateInfo(target_dir_.cast()); + calloc.free(target_dir_); + debugEnd?.call('ZANO_PlainWallet_getExportPrivateInfo'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_getExportPrivateInfo'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_getExportPrivateInfo', e); + debugEnd?.call('ZANO_PlainWallet_getExportPrivateInfo'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_deleteWallet(const char* file_name); +String PlainWallet_deleteWallet(String file_name) { + debugStart?.call('ZANO_PlainWallet_deleteWallet'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final file_name_ = file_name.toNativeUtf8(); + final txid = lib!.ZANO_PlainWallet_deleteWallet(file_name_.cast()); + calloc.free(file_name_); + debugEnd?.call('ZANO_PlainWallet_deleteWallet'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_deleteWallet'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_deleteWallet', e); + debugEnd?.call('ZANO_PlainWallet_deleteWallet'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_getAddressInfo(const char* addr); +String PlainWallet_getAddressInfo(String addr) { + debugStart?.call('ZANO_PlainWallet_getAddressInfo'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final addr_ = addr.toNativeUtf8(); + final txid = lib!.ZANO_PlainWallet_getAddressInfo(addr_.cast()); + calloc.free(addr_); + debugEnd?.call('ZANO_PlainWallet_getAddressInfo'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_getAddressInfo'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_getAddressInfo', e); + debugEnd?.call('ZANO_PlainWallet_getAddressInfo'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_getAppconfig(const char* encryption_key); +String PlainWallet_getAppconfig(String encryption_key) { + debugStart?.call('ZANO_PlainWallet_getAppconfig'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final encryption_key_ = encryption_key.toNativeUtf8(); + final txid = lib!.ZANO_PlainWallet_getAppconfig(encryption_key_.cast()); + calloc.free(encryption_key_); + debugEnd?.call('ZANO_PlainWallet_getAppconfig'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_getAppconfig'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_getAppconfig', e); + debugEnd?.call('ZANO_PlainWallet_getAppconfig'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_setAppconfig(const char* conf_str, const char* encryption_key); +String PlainWallet_setAppconfig(String conf_str, String encryption_key) { + debugStart?.call('ZANO_PlainWallet_setAppconfig'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final conf_str_ = conf_str.toNativeUtf8(); + final encryption_key_ = encryption_key.toNativeUtf8(); + final txid = lib!.ZANO_PlainWallet_setAppconfig(conf_str_.cast(), encryption_key_.cast()); + calloc.free(conf_str_); + calloc.free(encryption_key_); + debugEnd?.call('ZANO_PlainWallet_setAppconfig'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_setAppconfig'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_setAppconfig', e); + debugEnd?.call('ZANO_PlainWallet_setAppconfig'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_generateRandomKey(uint64_t lenght); +String PlainWallet_generateRandomKey(int length) { + debugStart?.call('ZANO_PlainWallet_generateRandomKey'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_PlainWallet_generateRandomKey(length); + debugEnd?.call('ZANO_PlainWallet_generateRandomKey'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_generateRandomKey'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_generateRandomKey', e); + debugEnd?.call('ZANO_PlainWallet_generateRandomKey'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_getLogsBuffer(); +String PlainWallet_getLogsBuffer() { + debugStart?.call('ZANO_PlainWallet_getLogsBuffer'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_PlainWallet_getLogsBuffer(); + debugEnd?.call('ZANO_PlainWallet_getLogsBuffer'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_getLogsBuffer'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_getLogsBuffer', e); + debugEnd?.call('ZANO_PlainWallet_getLogsBuffer'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_truncateLog(); +String PlainWallet_truncateLog() { + debugStart?.call('ZANO_PlainWallet_truncateLog'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_PlainWallet_truncateLog(); + debugEnd?.call('ZANO_PlainWallet_truncateLog'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_truncateLog'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_truncateLog', e); + debugEnd?.call('ZANO_PlainWallet_truncateLog'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_getConnectivityStatus(); +String PlainWallet_getConnectivityStatus() { + debugStart?.call('ZANO_PlainWallet_getConnectivityStatus'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_PlainWallet_getConnectivityStatus(); + debugEnd?.call('ZANO_PlainWallet_getConnectivityStatus'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_getConnectivityStatus'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_getConnectivityStatus', e); + debugEnd?.call('ZANO_PlainWallet_getConnectivityStatus'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_open(const char* path, const char* password); +String PlainWallet_open(String path, String password) { + debugStart?.call('ZANO_PlainWallet_open'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final path_ = path.toNativeUtf8(); + final password_ = password.toNativeUtf8(); + final txid = lib!.ZANO_PlainWallet_open(path_.cast(), password_.cast()); + calloc.free(path_); + calloc.free(password_); + debugEnd?.call('ZANO_PlainWallet_open'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_open'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_open', e); + debugEnd?.call('ZANO_PlainWallet_open'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_restore(const char* seed, const char* path, const char* password, const char* seed_password); +String PlainWallet_restore(String seed, String path, String password, String seed_password) { + debugStart?.call('ZANO_PlainWallet_restore'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final seed_ = seed.toNativeUtf8(); + final path_ = path.toNativeUtf8(); + final password_ = password.toNativeUtf8(); + final seed_password_ = seed_password.toNativeUtf8(); + final txid = lib!.ZANO_PlainWallet_restore(seed_.cast(), path_.cast(), password_.cast(), seed_password_.cast()); + calloc.free(seed_); + calloc.free(path_); + calloc.free(password_); + calloc.free(seed_password_); + debugEnd?.call('ZANO_PlainWallet_restore'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_restore'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_restore', e); + debugEnd?.call('ZANO_PlainWallet_restore'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_generate(const char* path, const char* password); +String PlainWallet_generate(String path, String password) { + debugStart?.call('ZANO_PlainWallet_generate'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final path_ = path.toNativeUtf8(); + final password_ = password.toNativeUtf8(); + final txid = lib!.ZANO_PlainWallet_generate(path_.cast(), password_.cast()); + calloc.free(path_); + calloc.free(password_); + debugEnd?.call('ZANO_PlainWallet_generate'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_generate'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_generate', e); + debugEnd?.call('ZANO_PlainWallet_generate'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_getOpenWallets(); +String PlainWallet_getOpenWallets() { + debugStart?.call('ZANO_PlainWallet_getOpenWallets'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_PlainWallet_getOpenWallets(); + debugEnd?.call('ZANO_PlainWallet_getOpenWallets'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_getOpenWallets'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_getOpenWallets', e); + debugEnd?.call('ZANO_PlainWallet_getOpenWallets'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_getWalletStatus(int64_t h); +String PlainWallet_getWalletStatus(int h) { + debugStart?.call('ZANO_PlainWallet_getWalletStatus'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_PlainWallet_getWalletStatus(h); + debugEnd?.call('ZANO_PlainWallet_getWalletStatus'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_getWalletStatus'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_getWalletStatus', e); + debugEnd?.call('ZANO_PlainWallet_getWalletStatus'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_closeWallet(int64_t h); +String PlainWallet_closeWallet(int h) { + debugStart?.call('ZANO_PlainWallet_closeWallet'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_PlainWallet_closeWallet(h); + debugEnd?.call('ZANO_PlainWallet_closeWallet'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_closeWallet'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_closeWallet', e); + debugEnd?.call('ZANO_PlainWallet_closeWallet'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_invoke(int64_t h, const char* params); +String PlainWallet_invoke(int h, String params) { + debugStart?.call('ZANO_PlainWallet_invoke'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final params_ = params.toNativeUtf8(); + final txid = lib!.ZANO_PlainWallet_invoke(h, params_.cast()); + calloc.free(params_); + debugEnd?.call('ZANO_PlainWallet_invoke'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_invoke'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_invoke', e); + debugEnd?.call('ZANO_PlainWallet_invoke'); + return ""; + } +} + +// extern ADDAPI const char* ZANO_PlainWallet_asyncCall(const char* method_name, uint64_t instance_id, const char* params); +String PlainWallet_asyncCall(String method_name, int h, String params) { + debugStart?.call('ZANO_PlainWallet_asyncCall'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final params_ = params.toNativeUtf8(); + final method_name_ = method_name.toNativeUtf8(); + final txid = lib!.ZANO_PlainWallet_asyncCall(method_name_.cast(), h, params_.cast()); + calloc.free(params_); + calloc.free(method_name_); + debugEnd?.call('ZANO_PlainWallet_asyncCall'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_asyncCall'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_asyncCall', e); + debugEnd?.call('ZANO_PlainWallet_asyncCall'); + return ""; + } +} + +// extern ADDAPI const char* ZANO_PlainWallet_tryPullResult(uint64_t instance_id); +String PlainWallet_tryPullResult(int instance_id) { + debugStart?.call('ZANO_PlainWallet_tryPullResult'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_PlainWallet_tryPullResult(instance_id); + debugEnd?.call('ZANO_PlainWallet_tryPullResult'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_tryPullResult'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_tryPullResult', e); + debugEnd?.call('ZANO_PlainWallet_tryPullResult'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_syncCall(const char* method_name, uint64_t instance_id, const char* params); +String PlainWallet_syncCall(String method_name, int instance_id, String params) { + debugStart?.call('ZANO_PlainWallet_syncCall'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final method_name_ = method_name.toNativeUtf8(); + final params_ = params.toNativeUtf8(); + final txid = lib!.ZANO_PlainWallet_syncCall(method_name_.cast(), instance_id, params_.cast()); + calloc.free(method_name_); + calloc.free(params_); + debugEnd?.call('ZANO_PlainWallet_syncCall'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_syncCall'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_syncCall', e); + debugEnd?.call('ZANO_PlainWallet_syncCall'); + return ""; + } +} +// extern ADDAPI bool ZANO_PlainWallet_isWalletExist(const char* path); +bool PlainWallet_isWalletExist(String path) { + debugStart?.call('ZANO_PlainWallet_isWalletExist'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final path_ = path.toNativeUtf8(); + final txid = lib!.ZANO_PlainWallet_isWalletExist(path_.cast()); + calloc.free(path_); + debugEnd?.call('ZANO_PlainWallet_isWalletExist'); + return txid; +} +// extern ADDAPI const char* ZANO_PlainWallet_getWalletInfo(int64_t h); +String PlainWallet_getWalletInfo(int h) { + debugStart?.call('ZANO_PlainWallet_getWalletInfo'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_PlainWallet_getWalletInfo(h); + debugEnd?.call('ZANO_PlainWallet_getWalletInfo'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_getWalletInfo'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_getWalletInfo', e); + debugEnd?.call('ZANO_PlainWallet_getWalletInfo'); + return ""; + } +} +// extern ADDAPI const char* ZANO_PlainWallet_resetWalletPassword(int64_t h, const char* password); +String PlainWallet_resetWalletPassword(int h, String password) { + debugStart?.call('ZANO_PlainWallet_resetWalletPassword'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final password_ = password.toNativeUtf8(); + final txid = lib!.ZANO_PlainWallet_resetWalletPassword(h, password_.cast()); + calloc.free(password_); + debugEnd?.call('ZANO_PlainWallet_resetWalletPassword'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_PlainWallet_resetWalletPassword'); + return str; + } catch (e) { + errorHandler?.call('ZANO_PlainWallet_resetWalletPassword', e); + debugEnd?.call('ZANO_PlainWallet_resetWalletPassword'); + return ""; + } +} +// extern ADDAPI uint64_t ZANO_PlainWallet_getCurrentTxFee(uint64_t priority); +int PlainWallet_getCurrentTxFee(int priority) { + debugStart?.call('ZANO_PlainWallet_getCurrentTxFee'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_PlainWallet_getCurrentTxFee(priority); + debugEnd?.call('ZANO_PlainWallet_getCurrentTxFee'); + return txid; +} + +void ZANO_free(Pointer wlptr) { + debugStart?.call('ZANO_free'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + + final s = lib!.ZANO_free(wlptr); + debugEnd?.call('ZANO_free'); + return s; +} + +// extern ADDAPI const char* ZANO_checksum_wallet2_api_c_h(); +String checksum_wallet2_api_c_h() { + debugStart?.call('ZANO_checksum_wallet2_api_c_h'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_checksum_wallet2_api_c_h(); + debugEnd?.call('ZANO_checksum_wallet2_api_c_h'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_checksum_wallet2_api_c_h'); + return str; + } catch (e) { + errorHandler?.call('ZANO_checksum_wallet2_api_c_h', e); + debugEnd?.call('ZANO_checksum_wallet2_api_c_h'); + return ""; + } +} +// extern ADDAPI const char* ZANO_checksum_wallet2_api_c_cpp(); +String checksum_wallet2_api_c_cpp() { + debugStart?.call('ZANO_checksum_wallet2_api_c_cpp'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_checksum_wallet2_api_c_cpp(); + debugEnd?.call('ZANO_checksum_wallet2_api_c_cpp'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_checksum_wallet2_api_c_cpp'); + return str; + } catch (e) { + errorHandler?.call('ZANO_checksum_wallet2_api_c_cpp', e); + debugEnd?.call('ZANO_checksum_wallet2_api_c_cpp'); + return ""; + } +} +// extern ADDAPI const char* ZANO_checksum_wallet2_api_c_exp(); +String checksum_wallet2_api_c_exp() { + debugStart?.call('ZANO_checksum_wallet2_api_c_exp'); + lib ??= ZanoC(DynamicLibrary.open(libPath)); + final txid = lib!.ZANO_checksum_wallet2_api_c_exp(); + debugEnd?.call('ZANO_checksum_wallet2_api_c_exp'); + try { + final strPtr = txid.cast(); + final str = strPtr.toDartString(); + ZANO_free(strPtr.cast()); + debugEnd?.call('ZANO_checksum_wallet2_api_c_exp'); + return str; + } catch (e) { + errorHandler?.call('ZANO_checksum_wallet2_api_c_exp', e); + debugEnd?.call('ZANO_checksum_wallet2_api_c_exp'); + return ""; + } +} \ No newline at end of file diff --git a/impls/monero.dart/update_bindings.sh b/impls/monero.dart/update_bindings.sh index 8ac3cab..f1ba024 100755 --- a/impls/monero.dart/update_bindings.sh +++ b/impls/monero.dart/update_bindings.sh @@ -6,3 +6,4 @@ cd "$(realpath $(dirname $0))" dart run ffigen --config ffigen_wownero.yaml dart run ffigen --config ffigen_monero.yaml +dart run ffigen --config ffigen_zano.yaml diff --git a/impls/monero.ts/checksum_zano.ts b/impls/monero.ts/checksum_zano.ts new file mode 100644 index 0000000..2af89bd --- /dev/null +++ b/impls/monero.ts/checksum_zano.ts @@ -0,0 +1,5 @@ +export const zanoChecksum = { + wallet2_api_c_h_sha256: "8acaa95513b85a984c08e05cc3f2ac7530bb8f32946eeeb45357bd846aef33dd", + wallet2_api_c_cpp_sha256: "4efacd3812d53dd268b6869cc0a9560e7320574d96e09136cf067f796edfeba6-2817090c8ac7639d6f697d00fc8bcba2b3681d90", + wallet2_api_c_exp_sha256: "66f3ff655bbfd11ad28c318ab707090b5a93276f436b06f7b1c0f329dba3c9c2", +} diff --git a/monero_libwallet2_api_c/CMakeLists.txt b/monero_libwallet2_api_c/CMakeLists.txt index dadafc6..6790333 100644 --- a/monero_libwallet2_api_c/CMakeLists.txt +++ b/monero_libwallet2_api_c/CMakeLists.txt @@ -1,8 +1,11 @@ -cmake_minimum_required(VERSION 3.4.1) +cmake_minimum_required(VERSION 3.5) project(wallet2_api_c) message(STATUS ABI_INFO = ${HOST_ABI}) -set (CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE) +# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-lto") if(${HOST_ABI} STREQUAL "x86_64-w64-mingw32") set(CMAKE_SYSTEM_NAME Windows) @@ -34,7 +37,7 @@ if (${HOST_ABI} STREQUAL "host-apple-darwin" OR endif() endif() -if(${HOST_ABI} STREQUAL "x86_64-linux-android" OR +if(${HOST_ABI} STREQUAL "" OR ${HOST_ABI} STREQUAL "i686-linux-android" OR ${HOST_ABI} STREQUAL "aarch64-linux-android" OR ${HOST_ABI} STREQUAL "armv7a-linux-androideabi") @@ -76,26 +79,60 @@ if(${HOST_ABI} STREQUAL "x86_64-apple-darwin11" OR ${HOST_ABI} STREQUAL "aarch64 set_target_properties(wallet2_api_c PROPERTIES NO_SONAME 1) endif() +if (${MONERO_FLAVOR} STREQUAL "monero") + target_compile_definitions(wallet2_api_c PRIVATE FLAVOR_MONERO) + set(BCUR_ENABLED bc-ur) +elseif(${MONERO_FLAVOR} STREQUAL "wownero") + target_compile_definitions(wallet2_api_c PRIVATE FLAVOR_WOWNERO) +elseif(${MONERO_FLAVOR} STREQUAL "zano") + target_compile_definitions(wallet2_api_c PRIVATE FLAVOR_ZANO) +endif() + if(NOT ${HOST_ABI} STREQUAL "x86_64-apple-darwin11" AND NOT ${HOST_ABI} STREQUAL "aarch64-apple-darwin11" AND NOT ${HOST_ABI} STREQUAL "aarch64-apple-darwin" AND NOT ${HOST_ABI} STREQUAL "x86_64-apple-darwin" AND NOT ${HOST_ABI} STREQUAL "host-apple-darwin" AND NOT ${HOST_ABI} STREQUAL "x86_64-host-apple-darwin" AND NOT ${HOST_ABI} STREQUAL "aarch64-host-apple-darwin" AND NOT ${HOST_ABI} STREQUAL "host-apple-ios" AND NOT ${HOST_ABI} STREQUAL "aarch64-apple-ios") set_target_properties(wallet2_api_c PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL") endif() -add_subdirectory("${CMAKE_SOURCE_DIR}/../${MONERO_FLAVOR}" ${CMAKE_BINARY_DIR}/${MONERO_FLAVOR}_build EXCLUDE_FROM_ALL) - - +if (${MONERO_FLAVOR} STREQUAL "zano") + include_directories( + ${CMAKE_SOURCE_DIR}/build/${HOST_ABI}/zano_build/contrib/zlib + ) +endif() +add_subdirectory("${CMAKE_SOURCE_DIR}/../${MONERO_FLAVOR}" ${CMAKE_BINARY_DIR}/${MONERO_FLAVOR}_build EXCLUDE_FROM_ALL) -if(${HOST_ABI} STREQUAL "x86_64-apple-darwin11" OR ${HOST_ABI} STREQUAL "aarch64-apple-darwin11" OR ${HOST_ABI} STREQUAL "host-apple-darwin" OR ${HOST_ABI} STREQUAL "x86_64-host-apple-darwin" OR ${HOST_ABI} STREQUAL "aarch64-host-apple-darwin" OR ${HOST_ABI} STREQUAL "host-apple-ios" OR ${HOST_ABI} STREQUAL "aarch64-apple-ios") +if(${HOST_ABI} STREQUAL "x86_64-apple-darwin11" OR ${HOST_ABI} STREQUAL "aarch64-apple-darwin11" OR ${HOST_ABI} STREQUAL "x86_64-apple-darwin" OR ${HOST_ABI} STREQUAL "aarch64-apple-darwin" OR ${HOST_ABI} STREQUAL "host-apple-darwin" OR ${HOST_ABI} STREQUAL "x86_64-host-apple-darwin" OR ${HOST_ABI} STREQUAL "aarch64-host-apple-darwin" OR ${HOST_ABI} STREQUAL "host-apple-ios" OR ${HOST_ABI} STREQUAL "aarch64-apple-ios") if (${MONERO_FLAVOR} STREQUAL "monero") set(EXPORTED_SYMBOLS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/monero_libwallet2_api_c.exp) elseif(${MONERO_FLAVOR} STREQUAL "wownero") set(EXPORTED_SYMBOLS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/wownero_libwallet2_api_c.exp) + elseif(${MONERO_FLAVOR} STREQUAL "zano") + set(EXPORTED_SYMBOLS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/zano_libwallet2_api_c.exp) endif() set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -exported_symbols_list ${EXPORTED_SYMBOLS_FILE}") set_target_properties(${TARGET} PROPERTIES LINK_DEPENDS ${EXPORTED_SYMBOLS_FILE}) endif() +if (${MONERO_FLAVOR} STREQUAL "monero") + set(WALLET_TARGETS wallet_api ${wallet_api_LIB_DEPENDS}) # wallet_api_LIB_DEPENDS +elseif(${MONERO_FLAVOR} STREQUAL "wownero") + set(WALLET_TARGETS wallet_api ${wallet_api_LIB_DEPENDS}) # wallet_api_LIB_DEPENDS +elseif(${MONERO_FLAVOR} STREQUAL "zano") + find_package(Boost 1.71 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options) + find_package(OpenSSL REQUIRED) + set(WALLET_TARGETS + wallet + general + tor-connect + crypto + currency_core + common + zlibstatic + + ${Boost_LIBRARIES} + ${OpenSSL_LIBRARIES}) +endif() + if(${MONERO_FLAVOR} STREQUAL "wownero") add_subdirectory(wownero-seed EXCLUDE_FROM_ALL) set(EXTRA_LIBS_WOWNEROSEED wownero-seed) @@ -106,11 +143,14 @@ endif() #foreach (_variableName ${_variableNames}) # message(STATUS "${_variableName}=${${_variableName}}") #endforeach() +#message(SEND_ERROR "${Boost_LIBRARIES}") +#message(SEND_ERROR "${WALLET_TARGETS} +# ${EXTRA_LIBS_WOWNEROSEED} +# ${EXTRA_LIBS_ANDROID}") target_link_libraries( wallet2_api_c - wallet_api + ${WALLET_TARGETS} ${EXTRA_LIBS_WOWNEROSEED} ${EXTRA_LIBS_ANDROID} - ${wallet_api_LIB_DEPENDS} - ) \ No newline at end of file + ) diff --git a/monero_libwallet2_api_c/src/main/cpp/helpers.hpp b/monero_libwallet2_api_c/src/main/cpp/helpers.hpp index 2c64394..83cf33b 100644 --- a/monero_libwallet2_api_c/src/main/cpp/helpers.hpp +++ b/monero_libwallet2_api_c/src/main/cpp/helpers.hpp @@ -3,6 +3,7 @@ #include #include #include +#include // Debug macros #define DEBUG_START() \ diff --git a/patches/monero/0009-coin-control.patch b/patches/monero/0009-coin-control.patch index 4c4b842..5ce3669 100644 --- a/patches/monero/0009-coin-control.patch +++ b/patches/monero/0009-coin-control.patch @@ -1,4 +1,4 @@ -From d15a18cac55cb06d5421ecfef1118e439d0cd572 Mon Sep 17 00:00:00 2001 +From 5b7e0a2085f1e9804b0c4ae97f17d84419a1199b Mon Sep 17 00:00:00 2001 From: tobtoht Date: Tue, 12 Mar 2024 11:07:57 +0100 Subject: [PATCH 10/15] coin control @@ -10,12 +10,12 @@ Subject: [PATCH 10/15] coin control src/wallet/api/coins.h | 40 +++++++ src/wallet/api/coins_info.cpp | 122 ++++++++++++++++++++ src/wallet/api/coins_info.h | 71 ++++++++++++ - src/wallet/api/wallet.cpp | 106 ++++++++++++++++- + src/wallet/api/wallet.cpp | 170 +++++++++++++++++++++------ src/wallet/api/wallet.h | 10 +- src/wallet/api/wallet2_api.h | 52 ++++++++- src/wallet/wallet2.cpp | 46 +++++++- src/wallet/wallet2.h | 11 +- - 11 files changed, 635 insertions(+), 19 deletions(-) + 11 files changed, 667 insertions(+), 51 deletions(-) create mode 100644 src/wallet/api/coins.cpp create mode 100644 src/wallet/api/coins.h create mode 100644 src/wallet/api/coins_info.cpp @@ -504,7 +504,7 @@ index 000000000..c43e45abd + +#endif //FEATHER_COINS_INFO_H diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp -index 67ac90a46..a76d773ba 100644 +index 67ac90a46..06837ab61 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -35,6 +35,7 @@ @@ -532,87 +532,144 @@ index 67ac90a46..a76d773ba 100644 { clearStatus(); -@@ -2084,6 +2086,7 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vectornettype(), dst_addr[i])) { - // TODO: copy-paste 'if treating as an address fails, try as url' from simplewallet.cpp:1982 -@@ -2105,6 +2108,7 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vectornettype(), dst_addr[i])) { +- // TODO: copy-paste 'if treating as an address fails, try as url' from simplewallet.cpp:1982 +- setStatusError(tr("Invalid destination address")); +- error = true; +- break; +- } +- if (info.has_payment_id) { +- if (!extra_nonce.empty()) { +- setStatusError(tr("a single transaction cannot use more than one payment id")); ++ uint64_t max_coin_control_input = 0; ++ uint64_t max_frozen_input = 0; ++ try { ++ bool error = false; ++ uint64_t amountSum = 0; ++ for (size_t i = 0; i < dst_addr.size() && !error; i++) { ++ if(!cryptonote::get_account_address_from_str(info, m_wallet->nettype(), dst_addr[i])) { ++ // TODO: copy-paste 'if treating as an address fails, try as url' from simplewallet.cpp:1982 ++ setStatusError(tr("Invalid destination address")); + error = true; + break; } - } - } -+ // uint64_t maxAllowedSpend = m_wallet->unlocked_balance(subaddr_account, true); -+ // if (maxAllowedSpend < amountSum) { -+ // error = true; -+ // setStatusError(tr("Amount you are trying to spend is larger than unlocked amount")); -+ // break; -+ // } -+ std::vector preferred_input_list; -+ uint64_t max_coin_control_input = 0; -+ uint64_t max_frozen_input = 0; -+ if (!preferred_inputs.empty()) { -+ LOG_ERROR("not empty"); -+ -+ for (const auto &public_key : preferred_inputs) { -+ crypto::key_image keyImage; -+ bool r = epee::string_tools::hex_to_pod(public_key, keyImage); -+ if (!r) { -+ error = true; -+ setStatusError(tr("failed to parse key image")); -+ break; -+ } -+ if (m_wallet->frozen(keyImage)) { -+ error = true; -+ setStatusError(tr("refusing to spend frozen coin")); -+ break; -+ } -+ -+ for (size_t i = 0; i < m_wallet->get_num_transfer_details(); ++i) { -+ const tools::wallet2::transfer_details &td = m_wallet->get_transfer_details(i); -+ if (td.m_key_image == keyImage) { -+ max_coin_control_input += td.amount(); -+ } -+ if (td.m_frozen) { -+ max_frozen_input += td.amount(); +- set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id); ++ if (info.has_payment_id) { ++ if (!extra_nonce.empty()) { ++ setStatusError(tr("a single transaction cannot use more than one payment id")); ++ error = true; ++ break; ++ } ++ set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id); + } -+ } + -+ preferred_input_list.push_back(keyImage); -+ } -+ } else { ++ if (amount) { ++ cryptonote::tx_destination_entry de; ++ de.original = dst_addr[i]; ++ de.addr = info.address; ++ de.amount = (*amount)[i]; ++ amountSum += (*amount)[i]; ++ de.is_subaddress = info.is_subaddress; ++ de.is_integrated = info.has_payment_id; ++ dsts.push_back(de); ++ } else { ++ if (subaddr_indices.empty()) { ++ for (uint32_t index = 0; index < m_wallet->get_num_subaddresses(subaddr_account); ++index) ++ subaddr_indices.insert(index); ++ } ++ } + } ++ // uint64_t maxAllowedSpend = m_wallet->unlocked_balance(subaddr_account, true); ++ // if (maxAllowedSpend < amountSum) { ++ // error = true; ++ // setStatusError(tr("Amount you are trying to spend is larger than unlocked amount")); ++ // break; ++ // } ++ std::vector preferred_input_list; ++ if (!preferred_inputs.empty()) { + LOG_ERROR("not empty"); + -+ boost::shared_lock transfers_lock(m_wallet->m_transfers_mutex); -+ for (size_t i = 0; i < m_wallet->get_num_transfer_details(); ++i) { -+ const tools::wallet2::transfer_details &td = m_wallet->get_transfer_details(i); -+ LOG_ERROR("COIN: " << i << ": " << td.amount() << "; "<frozen(td)); -+ if (td.m_spent) continue; -+ LOG_ERROR("is frozen"); -+ if (!td.m_frozen) { -+ LOG_ERROR("isn't:"); -+ LOG_ERROR("hash: " << td.m_key_image << "; " << td.amount()); -+ preferred_input_list.push_back(td.m_key_image); ++ for (const auto &public_key : preferred_inputs) { ++ crypto::key_image keyImage; ++ bool r = epee::string_tools::hex_to_pod(public_key, keyImage); ++ if (!r) { ++ error = true; ++ setStatusError(tr("failed to parse key image")); ++ break; ++ } ++ if (m_wallet->frozen(keyImage)) { ++ error = true; ++ setStatusError(tr("refusing to spend frozen coin")); ++ break; ++ } + +- if (amount) { +- cryptonote::tx_destination_entry de; +- de.original = dst_addr[i]; +- de.addr = info.address; +- de.amount = (*amount)[i]; +- de.is_subaddress = info.is_subaddress; +- de.is_integrated = info.has_payment_id; +- dsts.push_back(de); ++ for (size_t i = 0; i < m_wallet->get_num_transfer_details(); ++i) { ++ const tools::wallet2::transfer_details &td = m_wallet->get_transfer_details(i); ++ if (td.m_key_image == keyImage) { ++ max_coin_control_input += td.amount(); ++ } ++ if (td.m_frozen) { ++ max_frozen_input += td.amount(); ++ } + } ++ ++ preferred_input_list.push_back(keyImage); + } -+ } -+ for (const auto &de : preferred_input_list) { -+ LOG_ERROR("preferred input: " << de); -+ } - if (error) { - break; - } -@@ -2129,11 +2190,11 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vectorget_num_subaddresses(subaddr_account); ++index) +- subaddr_indices.insert(index); ++ LOG_ERROR("not empty"); ++ ++ boost::shared_lock transfers_lock(m_wallet->m_transfers_mutex); ++ for (size_t i = 0; i < m_wallet->get_num_transfer_details(); ++i) { ++ const tools::wallet2::transfer_details &td = m_wallet->get_transfer_details(i); ++ LOG_ERROR("COIN: " << i << ": " << td.amount() << "; "<frozen(td)); ++ if (td.m_spent) continue; ++ LOG_ERROR("is frozen"); ++ if (!td.m_frozen) { ++ LOG_ERROR("isn't:"); ++ LOG_ERROR("hash: " << td.m_key_image << "; " << td.amount()); ++ preferred_input_list.push_back(td.m_key_image); ++ } + } + } +- } +- if (error) { +- break; +- } +- if (!extra_nonce.empty() && !add_extra_nonce_to_tx_extra(extra, extra_nonce)) { +- setStatusError(tr("failed to set up payment id, though it was decoded correctly")); +- break; +- } +- try { ++ for (const auto &de : preferred_input_list) { ++ LOG_ERROR("preferred input: " << de); ++ } ++ if (error) { ++ break; ++ } ++ if (!extra_nonce.empty() && !add_extra_nonce_to_tx_extra(extra, extra_nonce)) { ++ setStatusError(tr("failed to set up payment id, though it was decoded correctly")); ++ break; ++ } + size_t fake_outs_count = mixin_count > 0 ? mixin_count : m_wallet->default_mixin(); + fake_outs_count = m_wallet->adjust_mixin(mixin_count); + if (amount) { transaction->m_pending_tx = m_wallet->create_transactions_2(dsts, fake_outs_count, adjusted_priority, @@ -1038,5 +1095,5 @@ index 91cf2a376..bc16d528c 100644 void set_unspent(size_t idx); bool is_spent(const transfer_details &td, bool strict = true) const; -- -2.43.0 +2.39.5 (Apple Git-154) diff --git a/patches/zano/0001-add-missing-include.patch b/patches/zano/0001-add-missing-include.patch new file mode 100644 index 0000000..cd95528 --- /dev/null +++ b/patches/zano/0001-add-missing-include.patch @@ -0,0 +1,64 @@ +From a49fa9a64aebf69f15832291e70888ff18ed6040 Mon Sep 17 00:00:00 2001 +From: Czarek Nakamoto +Date: Thu, 31 Oct 2024 13:07:20 +0000 +Subject: [PATCH 1/5] add missing #include + +--- + src/currency_core/genesis.cpp | 1 + + src/currency_core/genesis.h | 2 +- + src/wallet/plain_wallet_api.cpp | 1 + + src/wallet/plain_wallet_api.h | 1 + + 4 files changed, 4 insertions(+), 1 deletion(-) + +diff --git a/src/currency_core/genesis.cpp b/src/currency_core/genesis.cpp +index a58dcb4e..c34b0285 100644 +--- a/src/currency_core/genesis.cpp ++++ b/src/currency_core/genesis.cpp +@@ -4,6 +4,7 @@ + // file COPYING or http://www.opensource.org/licenses/mit-license.php. + + #include "genesis.h" ++#include + + namespace currency + { +diff --git a/src/currency_core/genesis.h b/src/currency_core/genesis.h +index 8ea77d89..d78cec97 100644 +--- a/src/currency_core/genesis.h ++++ b/src/currency_core/genesis.h +@@ -3,7 +3,7 @@ + // Copyright (c) 2014-2018 The Louisdor Project + // Distributed under the MIT/X11 software license, see the accompanying + // file COPYING or http://www.opensource.org/licenses/mit-license.php. +- ++#include + #pragma once + #include + namespace currency +diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp +index bb322481..dccff76c 100644 +--- a/src/wallet/plain_wallet_api.cpp ++++ b/src/wallet/plain_wallet_api.cpp +@@ -6,6 +6,7 @@ + #ifdef ANDROID_BUILD + #include + #endif ++#include + #include "plain_wallet_api.h" + #include "plain_wallet_api_defs.h" + #include "currency_core/currency_config.h" +diff --git a/src/wallet/plain_wallet_api.h b/src/wallet/plain_wallet_api.h +index f12eba03..177b8173 100644 +--- a/src/wallet/plain_wallet_api.h ++++ b/src/wallet/plain_wallet_api.h +@@ -6,6 +6,7 @@ + #pragma once + + #include ++#include + #include "../common/error_codes.h" + + namespace plain_wallet +-- +2.39.5 (Apple Git-154) + diff --git a/patches/zano/0002-fix-build-issues.patch b/patches/zano/0002-fix-build-issues.patch new file mode 100644 index 0000000..9ff3f85 --- /dev/null +++ b/patches/zano/0002-fix-build-issues.patch @@ -0,0 +1,39 @@ +From 627750b0f1471c5d34755ca446d452429945d5d6 Mon Sep 17 00:00:00 2001 +From: cyan +Date: Sat, 2 Nov 2024 20:50:26 +0000 +Subject: [PATCH 2/5] fix build issues + +--- + contrib/db/libmdbx/CMakeLists.txt | 2 +- + contrib/db/libmdbx/packages/rpm/CMakeLists.txt | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/contrib/db/libmdbx/CMakeLists.txt b/contrib/db/libmdbx/CMakeLists.txt +index 75e9b3b0..01a5915c 100644 +--- a/contrib/db/libmdbx/CMakeLists.txt ++++ b/contrib/db/libmdbx/CMakeLists.txt +@@ -80,7 +80,7 @@ macro(add_mdbx_option NAME DESCRIPTION DEFAULT) + endmacro() + + # only for compatibility testing +-# set(CMAKE_CXX_STANDARD 14) ++set(CMAKE_CXX_STANDARD 17) + + if(NOT "$ENV{TEAMCITY_PROCESS_FLOW_ID}" STREQUAL "") + set(CI TEAMCITY) +diff --git a/contrib/db/libmdbx/packages/rpm/CMakeLists.txt b/contrib/db/libmdbx/packages/rpm/CMakeLists.txt +index 5949e9f0..e7b677bd 100644 +--- a/contrib/db/libmdbx/packages/rpm/CMakeLists.txt ++++ b/contrib/db/libmdbx/packages/rpm/CMakeLists.txt +@@ -12,7 +12,7 @@ set(MDBX_VERSION_STRING ${MDBX_VERSION_MAJOR}.${MDBX_VERSION_MINOR}.${MDBX_VERSI + enable_language(C) + enable_language(CXX) + +-set(CMAKE_CXX_STANDARD 11) ++set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED on) + + add_definitions(-DNDEBUG=1 -DMDBX_DEBUG=0 -DLIBMDBX_EXPORTS=1 -D_GNU_SOURCE=1) +-- +2.39.5 (Apple Git-154) + diff --git a/patches/zano/0003-fix-mingw-build-issues.patch b/patches/zano/0003-fix-mingw-build-issues.patch new file mode 100644 index 0000000..48b4d65 --- /dev/null +++ b/patches/zano/0003-fix-mingw-build-issues.patch @@ -0,0 +1,61 @@ +From 1f7604d5b661f4490a1757e5ed1d6ed367ffb739 Mon Sep 17 00:00:00 2001 +From: cyan +Date: Sun, 3 Nov 2024 08:59:22 +0000 +Subject: [PATCH 3/5] fix mingw build issues + +--- + contrib/epee/include/misc_os_dependent.h | 4 ++-- + src/common/callstack_helper.cpp | 2 +- + src/crypto/ecrypt-config.h | 2 +- + 3 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/contrib/epee/include/misc_os_dependent.h b/contrib/epee/include/misc_os_dependent.h +index c06e5d94..a2a979b9 100644 +--- a/contrib/epee/include/misc_os_dependent.h ++++ b/contrib/epee/include/misc_os_dependent.h +@@ -110,14 +110,14 @@ namespace misc_utils + } + + +-#if defined(__GNUC__) && !defined(__ANDROID__) ++#if defined(__GNUC__) && !defined(__ANDROID__) && !defined(_WIN32) + #include + #include + #endif + inline std::string print_trace_default() + { + std::stringstream ss; +-#if defined(__GNUC__) && !defined(__ANDROID__) ++#if defined(__GNUC__) && !defined(__ANDROID__) && !defined(_WIN32) + ss << std::endl << "STACK" << std::endl; + const size_t max_depth = 100; + size_t stack_depth; +diff --git a/src/common/callstack_helper.cpp b/src/common/callstack_helper.cpp +index b84fe5a8..c9eae839 100644 +--- a/src/common/callstack_helper.cpp ++++ b/src/common/callstack_helper.cpp +@@ -9,7 +9,7 @@ + #define NOMINMAX + #endif + #include +-#include ++#include + #pragma comment(lib, "psapi.lib") + #pragma comment(lib, "dbghelp.lib") + +diff --git a/src/crypto/ecrypt-config.h b/src/crypto/ecrypt-config.h +index 9176de17..8b488135 100644 +--- a/src/crypto/ecrypt-config.h ++++ b/src/crypto/ecrypt-config.h +@@ -257,7 +257,7 @@ + + #ifdef _UI64_MAX + +-#if (_UI64_MAX / 0xFFFFFFFFui64 > 0xFFFFFFFFui64) ++#if (_UI64_MAX / 0xFFFFFFFF > 0xFFFFFFFF) + #ifndef I64T + #define I64T __int64 + #define U64C(v) (v##ui64) +-- +2.39.5 (Apple Git-154) + diff --git a/patches/zano/0004-update-tor-connect.patch b/patches/zano/0004-update-tor-connect.patch new file mode 100644 index 0000000..76cc59d --- /dev/null +++ b/patches/zano/0004-update-tor-connect.patch @@ -0,0 +1,33 @@ +From 7d05e6a8d62ad3302bd1bb1818db36bde5885bab Mon Sep 17 00:00:00 2001 +From: Czarek Nakamoto +Date: Tue, 5 Nov 2024 10:35:03 -0500 +Subject: [PATCH 4/5] update tor-connect + +--- + .gitmodules | 2 +- + contrib/tor-connect | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/.gitmodules b/.gitmodules +index 57896bbb..4df859f8 100644 +--- a/.gitmodules ++++ b/.gitmodules +@@ -7,7 +7,7 @@ + branch = main + [submodule "contrib/tor-connect"] + path = contrib/tor-connect +- url = https://github.com/hyle-team/tor-connect.git ++ url = https://github.com/MrCyjaneK/tor-connect.git + branch = main + [submodule "contrib/jwt-cpp"] + path = contrib/jwt-cpp +diff --git a/contrib/tor-connect b/contrib/tor-connect +index b589edb1..cc445b2f 160000 +--- a/contrib/tor-connect ++++ b/contrib/tor-connect +@@ -1 +1 @@ +-Subproject commit b589edb1906dccb387cfeded6ed12286c5f0405f ++Subproject commit cd7f0c4b583488a7fe9b50de8e533a9853b6a5c7 +-- +2.39.5 (Apple Git-154) + diff --git a/patches/zano/0005-fix-ios-builds.patch b/patches/zano/0005-fix-ios-builds.patch new file mode 100644 index 0000000..f68244f --- /dev/null +++ b/patches/zano/0005-fix-ios-builds.patch @@ -0,0 +1,43 @@ +From 20975fed75b7255f6cb6df74a17f1923f7159c09 Mon Sep 17 00:00:00 2001 +From: Czarek Nakamoto +Date: Tue, 5 Nov 2024 16:52:23 +0100 +Subject: [PATCH 5/5] fix ios builds + +--- + CMakeLists.txt | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index c480300f..7087d796 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -136,6 +136,8 @@ else() + set(ARCH default CACHE STRING "CPU to build for: -march value or default") + if("${ARCH}" STREQUAL "default") + set(ARCH_FLAG "") ++ elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS") ++ set(ARCH_FLAG "") + else() + set(ARCH_FLAG "-march=${ARCH}") + endif() +@@ -207,7 +209,7 @@ else() + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${RELEASE_FLAGS}") + if(STATIC) + if(APPLE) +- message(SEND_ERROR "Static build is not supported on MacOS X") ++ message("Static build is not supported on MacOS X") + else() + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") + endif() +@@ -260,8 +262,6 @@ else() + find_package(Boost 1.70 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options locale log) + endif() + +- +- + message(STATUS "Boost: ${Boost_VERSION} from ${Boost_LIBRARY_DIRS}") + + +-- +2.39.5 (Apple Git-154) + diff --git a/patches/zano/0006-use-boost-filesystem-instead-of-stdfs.patch b/patches/zano/0006-use-boost-filesystem-instead-of-stdfs.patch new file mode 100644 index 0000000..64b7f4c --- /dev/null +++ b/patches/zano/0006-use-boost-filesystem-instead-of-stdfs.patch @@ -0,0 +1,80 @@ +From 033d71f4a8623dee3508c493431402bbbe5a8b2d Mon Sep 17 00:00:00 2001 +From: Czarek Nakamoto +Date: Wed, 4 Dec 2024 17:21:44 -0600 +Subject: [PATCH] use boost::filesystem instead of stdfs + +--- + CMakeLists.txt | 23 ++++------------------- + contrib/epee/include/file_io_utils.h | 6 +++--- + 2 files changed, 7 insertions(+), 22 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 7087d796..6ded9711 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -232,24 +232,9 @@ if(STATIC) + endif() + + message("CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") +-if(CMAKE_SYSTEM_NAME STREQUAL "iOS") +- set(CMAKE_OSX_DEPLOYMENT_TARGET 12.00) +- if(NOT DEFINED SKIP_BOOST_FATLIB_LIB OR NOT SKIP_BOOST_FATLIB_LIB) +- message("Ios: libboost.a included as library") +- set(Boost_LIBRARIES "libboost.a") +- else() +- message("Ios: libboost.a not included as library") +- endif() +- #workaround for new XCode 12 policy for builds(now it includes a slice for the "arm64" when builds for simulator) +- set(__iphoneos_archs "arm64") +- #set(__iphonesimulator_archs "arm64,x86_64") +- set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=iphoneos*] "${__iphoneos_archs}") +- set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphoneos*] "${__iphoneos_archs}") +- #set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=iphonesimulator*] "${__iphonesimulator_archs}") +- #set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphonesimulator*] "${__iphonesimulator_archs}") +-elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") ++if(CMAKE_SYSTEM_NAME STREQUAL "Android") + if(CAKEWALLET) +- find_package(Boost 1.71 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options locale) ++ find_package(Boost 1.71 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options) + else() + set(Boost_LIBRARY_DIRS "${Boost_LIBRARY_DIRS}/${CMAKE_ANDROID_ARCH_ABI}/") + set(Boost_LIBRARIES "${Boost_LIBRARY_DIRS}libboost_system.a;${Boost_LIBRARY_DIRS}libboost_filesystem.a;${Boost_LIBRARY_DIRS}libboost_thread.a;${Boost_LIBRARY_DIRS}libboost_timer.a;${Boost_LIBRARY_DIRS}libboost_date_time.a;${Boost_LIBRARY_DIRS}libboost_chrono.a;${Boost_LIBRARY_DIRS}libboost_regex.a;${Boost_LIBRARY_DIRS}libboost_serialization.a;${Boost_LIBRARY_DIRS}libboost_atomic.a;${Boost_LIBRARY_DIRS}libboost_program_options.a") +@@ -257,7 +242,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fPIC") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fPIC") + elseif(APPLE) +- find_package(Boost 1.71 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options locale) ++ find_package(Boost 1.71 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options) + else() + find_package(Boost 1.70 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options locale log) + endif() +@@ -302,7 +287,7 @@ else() + find_package(Git QUIET) + if(Git_FOUND OR GIT_FOUND) + message(STATUS "Found Git: ${GIT_EXECUTABLE}") +- add_custom_target(version ALL "${CMAKE_COMMAND}" "-D" "VERSION=${VERSION}" "-D" "GIT=${GIT_EXECUTABLE}" "-D" "TO=${CMAKE_BINARY_DIR}/version/version.h" "-P" "src/version.cmake" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") ++ add_custom_target(version ALL "${CMAKE_COMMAND}" "-D" "VERSION=${VERSION}" "-D" "GIT=${GIT_EXECUTABLE}" "-D" "TO=${CMAKE_BINARY_DIR}/version/version.h" "-P" "src/version.cmake" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + else() + message(STATUS "WARNING: Git was not found!") + set(VERSION "${VERSION}-unknown") +diff --git a/contrib/epee/include/file_io_utils.h b/contrib/epee/include/file_io_utils.h +index bb21ae99..ced01092 100644 +--- a/contrib/epee/include/file_io_utils.h ++++ b/contrib/epee/include/file_io_utils.h +@@ -574,10 +574,10 @@ namespace file_io_utils + try + { + +- stdfs::directory_iterator end_itr; // default construction yields past-the-end +- for (stdfs::directory_iterator itr( epee::string_encoding::utf8_to_wstring(path) ); itr != end_itr; ++itr ) ++ boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end ++ for ( boost::filesystem::directory_iterator itr( epee::string_encoding::utf8_to_wstring(path) ); itr != end_itr; ++itr ) + { +- if ( only_files && stdfs::is_directory(itr->status()) ) ++ if ( only_files && boost::filesystem::is_directory(itr->status()) ) + { + continue; + } +-- +2.39.5 (Apple Git-154) + diff --git a/patches/zano/0007-downgrade-cmake-version-so-LIB_DEPENDS-shows-up.patch b/patches/zano/0007-downgrade-cmake-version-so-LIB_DEPENDS-shows-up.patch new file mode 100644 index 0000000..0ac7e50 --- /dev/null +++ b/patches/zano/0007-downgrade-cmake-version-so-LIB_DEPENDS-shows-up.patch @@ -0,0 +1,22 @@ +From e6201106cd09416f96c8d83270c94565583cd356 Mon Sep 17 00:00:00 2001 +From: Czarek Nakamoto +Date: Thu, 5 Dec 2024 09:36:34 -0600 +Subject: [PATCH] downgrade cmake version so LIB_DEPENDS shows up + +--- + CMakeLists.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 6ded9711..47d24a81 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1,4 +1,4 @@ +-cmake_minimum_required(VERSION 3.16) ++cmake_minimum_required(VERSION 3.5) + + PROJECT(Zano) + +-- +2.39.5 (Apple Git-154) + diff --git a/patches/zano/0008-increase-max-password.patch b/patches/zano/0008-increase-max-password.patch new file mode 100644 index 0000000..0ce87c7 --- /dev/null +++ b/patches/zano/0008-increase-max-password.patch @@ -0,0 +1,25 @@ +From 6812b5de7e0a52e9341e54dbe2fc0b790dc6de5a Mon Sep 17 00:00:00 2001 +From: Czarek Nakamoto +Date: Thu, 12 Dec 2024 09:00:57 -0500 +Subject: [PATCH] increase max password + +--- + src/currency_core/currency_format_utils.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp +index 96d55b4..0c3d947 100644 +--- a/src/currency_core/currency_format_utils.cpp ++++ b/src/currency_core/currency_format_utils.cpp +@@ -3632,7 +3632,7 @@ namespace currency + return true; + } + //------------------------------------------------------------------ +- #define PASSWORD_REGEXP R"([A-Za-z0-9~!?@#$%^&*_+|{}\[\]()<>:;"'\-=/.,]{0,40})" ++ #define PASSWORD_REGEXP R"([A-Za-z0-9~!?@#$%^&*_+|{}\[\]()<>:;"'\-=/.,]{0,2048})" + bool validate_password(const std::string& password) + { + // OLD: static const std::string allowed_password_symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~!?@#$%^&*_+|{}[]()<>:;\"'-=\\/.,"; +-- +2.39.5 (Apple Git-154) + diff --git a/tests/.DS_Store b/tests/.DS_Store new file mode 100644 index 0000000..6914114 Binary files /dev/null and b/tests/.DS_Store differ diff --git a/tests/download_deps.ts b/tests/download_deps.ts index 808640e..8871fa5 100644 --- a/tests/download_deps.ts +++ b/tests/download_deps.ts @@ -4,8 +4,11 @@ import { Coin, getMoneroCTags } from "./utils.ts"; export type Target = `${typeof Deno["build"]["os"]}_${typeof Deno["build"]["arch"]}`; interface FileInfo { - overrideMirrors?: string[]; - name: string; + // List of mirrors that override DownloadInfo mirrors for this FileInfo + overrideMirrors?: [mainFilePath: string, ...fallbacks: string[]]; + // List of file names that fallback if previous failed + // If first name failed and got fallbacked by another, it will get renamed to the first entry + names: string[]; sha256?: string; } @@ -21,7 +24,7 @@ export function getFileInfo( downloadInfo: DownloadInfo, target: Target = `${Deno.build.os}_${Deno.build.arch}`, ): FileInfo { - const fileInfo = "name" in downloadInfo.file ? downloadInfo.file : downloadInfo.file[target]; + const fileInfo = "names" in downloadInfo.file ? downloadInfo.file : downloadInfo.file[target]; if (!fileInfo) { throw new Error(`No fileInfo set for target: ${target}`); } @@ -37,6 +40,61 @@ export async function downloadDependencies(...infos: DownloadInfo[]): Promise { + const url = `${mirror}/${fileName}`; + + const response = await fetch(url); + if (!response.ok) { + console.warn(`Could not reach file ${fileName} on mirror: ${mirror}`); + await response.body?.cancel(); + return; + } + + const responseBuffer = await response.bytes(); + + if (fileInfo.sha256) { + const responseChecksum = await sha256(responseBuffer); + if (responseChecksum !== fileInfo.sha256) { + console.warn( + `Checksum mismatch on file ${fileName} on mirror: ${mirror} (${responseChecksum} != ${fileInfo.sha256})`, + ); + return; + } + } + + return responseBuffer; +} + +async function validFileExists(filePath: string, fileInfo: FileInfo): Promise { + const [mainFileName] = fileInfo.names; + + let fileBuffer: Uint8Array; + try { + fileBuffer = await Deno.readFile(filePath); + } catch { + return false; + } + + // File exists, make sure checksum matches + if (fileInfo.sha256) { + const fileChecksum = await sha256(fileBuffer); + if (fileChecksum !== fileInfo.sha256) { + console.log( + `File ${mainFileName} already exists, but checksum is mismatched (${fileChecksum} != ${fileInfo.sha256}), redownloading`, + ); + await Deno.remove(filePath); + return false; + } + } + + console.log(`File ${mainFileName} already exists, skipping`); + return true; +} + export async function downloadFiles(outDir: string, target: Target, ...infos: DownloadInfo[]): Promise { try { await Deno.mkdir(outDir, { recursive: true }); @@ -48,65 +106,40 @@ export async function downloadFiles(outDir: string, target: Target, ...infos: Do for (const info of infos) { const fileInfo = getFileInfo(info, target); - const fileName = fileInfo.name; - const filePath = join(outDir, info.outDir ?? "", fileName); - - file_might_exist: try { - const fileBuffer = await Deno.readFile(filePath); - - // File exists, make sure checksum matches - if (fileInfo.sha256) { - const fileChecksum = await sha256(fileBuffer); - if (fileChecksum !== fileInfo.sha256) { - console.log( - `File ${fileName} already exists, but checksum is mismatched (${fileChecksum} != ${fileInfo.sha256}), redownloading`, - ); - await Deno.remove(filePath); - break file_might_exist; - } - } - - console.log(`File ${fileName} already exists, skipping`); + const [mainFileName] = fileInfo.names; + + if ( + await validFileExists( + join(outDir, info.outDir || ""), + fileInfo, + ) + ) { continue; - } catch { /**/ } + } let buffer: Uint8Array | undefined; + outer: for (const mirror of fileInfo.overrideMirrors ?? info.mirrors) { + for (const fileName of fileInfo.names) { + buffer = await tryToDownloadFile(mirror, fileInfo, fileName); - for (const mirror of fileInfo.overrideMirrors ?? info.mirrors) { - const url = `${mirror}/${fileName}`; - - const response = await fetch(url); - if (!response.ok) { - console.warn(`Could not reach file ${fileName} on mirror: ${mirror}`); - await response.body?.cancel(); - continue; - } - - const responseBuffer = await response.bytes(); - - if (fileInfo.sha256) { - const responseChecksum = await sha256(responseBuffer); - if (responseChecksum !== fileInfo.sha256) { - console.warn( - `Checksum mismatch on file ${fileName} on mirror: ${mirror} (${responseChecksum} != ${fileInfo.sha256})`, - ); - continue; + if (buffer) { + break outer; } } - - buffer = responseBuffer; } if (!buffer) { - throw new Error(`None of the mirrors for ${fileName} are available`); + throw new Error(`None of the mirrors for ${fileInfo.names} are available`); } + const filePath = join(outDir, info.outDir ?? "", mainFileName); + await Deno.mkdir(resolve(filePath, ".."), { recursive: true, }).catch(() => {}); await Deno.writeFile(filePath, buffer); - console.info("Downloaded file", fileInfo.name); + console.info("Downloaded file", filePath); } } @@ -117,25 +150,25 @@ export const wowneroCliInfo: DownloadInfo = { ], file: { linux_aarch64: { - name: "wownero-aarch64-linux-gnu-59db3fe8d.tar.bz2", + names: ["wownero-aarch64-linux-gnu-59db3fe8d.tar.bz2"], sha256: "07ce678302c07a6e79d90be65cbda243d843d414fbadb30f972d6c226575cfa7", }, linux_x86_64: { - name: "wownero-x86_64-linux-gnu-59db3fe8d.tar.bz2", + names: ["wownero-x86_64-linux-gnu-59db3fe8d.tar.bz2"], sha256: "03880967c70cc86558d962b8a281868c3934238ea457a36174ba72b99d70107e", }, darwin_aarch64: { - name: "wownero-aarch64-apple-darwin11-59db3fe8d.tar.bz2", + names: ["wownero-aarch64-apple-darwin11-59db3fe8d.tar.bz2"], sha256: "25ff454a92b1cf036df5f28cdd2c63dcaf4b03da7da9403087371f868827c957", }, darwin_x86_64: { - name: "wownero-x86_64-apple-darwin11-59db3fe8d.tar.bz2", + names: ["wownero-x86_64-apple-darwin11-59db3fe8d.tar.bz2"], sha256: "7e9b6a84a560ed7a9ed7117c6f07fb228d77a06afac863d0ea1dbf833c4eddf6", }, windows_x86_64: { - name: "wownero-x86_64-w64-mingw32-59db3fe8d.zip", + names: ["wownero-x86_64-w64-mingw32-59db3fe8d.zip"], sha256: "7e0ed84afa51e3b403d635c706042859094eb6850de21c9e82cb0a104425510e", }, @@ -144,7 +177,7 @@ export const wowneroCliInfo: DownloadInfo = { "https://static.mrcyjanek.net/download_mirror/", "https://codeberg.org/wownero/wownero/releases/download/v0.11.1.0/", ], - name: "wownero-aarch64-linux-android-v0.11.1.0.tar.bz2", + names: ["wownero-aarch64-linux-android-v0.11.1.0.tar.bz2"], sha256: "236188f8d8e7fad2ff35973f8c2417afffa8855d1a57b4c682fff5b199ea40f5", }, }, @@ -157,30 +190,30 @@ export const moneroCliInfo: DownloadInfo = { ], file: { linux_aarch64: { - name: "monero-linux-armv8-v0.18.3.4.tar.bz2", + names: ["monero-linux-armv8-v0.18.3.4.tar.bz2"], sha256: "33ca2f0055529d225b61314c56370e35606b40edad61c91c859f873ed67a1ea7", }, linux_x86_64: { - name: "monero-linux-x64-v0.18.3.4.tar.bz2", + names: ["monero-linux-x64-v0.18.3.4.tar.bz2"], sha256: "51ba03928d189c1c11b5379cab17dd9ae8d2230056dc05c872d0f8dba4a87f1d", }, darwin_aarch64: { - name: "monero-mac-armv8-v0.18.3.4.tar.bz2", + names: ["monero-mac-armv8-v0.18.3.4.tar.bz2"], sha256: "44520cb3a05c2518ca9aeae1b2e3080fe2bba1e3596d014ceff1090dfcba8ab4", }, darwin_x86_64: { - name: "monero-mac-x64-v0.18.3.4.tar.bz2", + names: ["monero-mac-x64-v0.18.3.4.tar.bz2"], sha256: "32c449f562216d3d83154e708471236d07db7477d6b67f1936a0a85a5005f2b8", }, windows_x86_64: { - name: "monero-win-x64-v0.18.3.4.zip", + names: ["monero-win-x64-v0.18.3.4.zip"], sha256: "54a66db6c892b2a0999754841f4ca68511741b88ea3ab20c7cd504a027f465f5", }, android_aarch64: { - name: "monero-android-armv8-v0.18.3.4.tar.bz2", + names: ["monero-android-armv8-v0.18.3.4.tar.bz2"], sha256: "d9c9249d1408822ce36b346c6b9fb6b896cda16714d62117fb1c588a5201763c", }, }, @@ -199,12 +232,22 @@ for (const tag of await getMoneroCTags()) { `https://github.com/MrCyjaneK/monero_c/releases/download/${tag}/`, ], file: { - linux_aarch64: { name: `${coin}_aarch64-linux-gnu_libwallet2_api_c.so.xz` }, - linux_x86_64: { name: `${coin}_x86_64-linux-gnu_libwallet2_api_c.so.xz` }, - darwin_aarch64: { name: `${coin}_aarch64-apple-darwin11_libwallet2_api_c.dylib.xz` }, - darwin_x86_64: { name: `${coin}_x86_64-apple-darwin11_libwallet2_api_c.dylib.xz` }, - windows_x86_64: { name: `${coin}_x86_64-w64-mingw32_libwallet2_api_c.dll.xz` }, - android_aarch64: { name: `${coin}_aarch64-linux-android_libwallet2_api_c.so.xz` }, + linux_aarch64: { names: [`${coin}_aarch64-linux-gnu_libwallet2_api_c.so.xz`] }, + linux_x86_64: { names: [`${coin}_x86_64-linux-gnu_libwallet2_api_c.so.xz`] }, + darwin_aarch64: { + names: [ + `${coin}_aarch64-apple-darwin11_libwallet2_api_c.dylib.xz`, + `${coin}_aarch64-apple-darwin_libwallet2_api_c.dylib.xz`, + ], + }, + darwin_x86_64: { + names: [ + `${coin}_x86_64-apple-darwin11_libwallet2_api_c.dylib.xz`, + `${coin}_x86_64-apple-darwin_libwallet2_api_c.dylib.xz`, + ], + }, + windows_x86_64: { names: [`${coin}_x86_64-w64-mingw32_libwallet2_api_c.dll.xz`] }, + android_aarch64: { names: [`${coin}_aarch64-linux-android_libwallet2_api_c.so.xz`] }, }, outDir: `libs/${tag}`, }); diff --git a/tests/integration.test.ts b/tests/integration.test.ts index 100bd43..2570874 100644 --- a/tests/integration.test.ts +++ b/tests/integration.test.ts @@ -443,7 +443,7 @@ Deno.test("0004-coin-control.patch", { assertEquals(await transaction.status(), 1); assertEquals( - await transaction.errorString(), + (await transaction.errorString())?.split("\n")[0], "not enough money to transfer, overall balance only 0.002000000000, sent amount 0.002000000000", ); }); diff --git a/tests/utils.ts b/tests/utils.ts index 86501a8..9408f54 100755 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -84,13 +84,13 @@ export async function extract(path: string, out: string) { export async function prepareMoneroCli() { await downloadDependencies(moneroCliInfo); - const path = join("./tests/dependencies", moneroCliInfo.outDir ?? "", getFileInfo(moneroCliInfo).name); + const path = join("./tests/dependencies", moneroCliInfo.outDir ?? "", getFileInfo(moneroCliInfo).names[0]); await extract(path, "./tests/dependencies/monero-cli/"); } export async function prepareWowneroCli() { await downloadDependencies(wowneroCliInfo); - const path = join("./tests/dependencies", wowneroCliInfo.outDir ?? "", getFileInfo(wowneroCliInfo).name); + const path = join("./tests/dependencies", wowneroCliInfo.outDir ?? "", getFileInfo(wowneroCliInfo).names[0]); await extract(path, "./tests/dependencies/wownero-cli/"); } diff --git a/zano b/zano new file mode 160000 index 0000000..2817090 --- /dev/null +++ b/zano @@ -0,0 +1 @@ +Subproject commit 2817090c8ac7639d6f697d00fc8bcba2b3681d90 diff --git a/zano_libwallet2_api_c/CMakeLists.txt b/zano_libwallet2_api_c/CMakeLists.txt new file mode 120000 index 0000000..73b40ff --- /dev/null +++ b/zano_libwallet2_api_c/CMakeLists.txt @@ -0,0 +1 @@ +../monero_libwallet2_api_c/CMakeLists.txt \ No newline at end of file diff --git a/zano_libwallet2_api_c/src/main/cpp/helpers.cpp b/zano_libwallet2_api_c/src/main/cpp/helpers.cpp new file mode 120000 index 0000000..524768b --- /dev/null +++ b/zano_libwallet2_api_c/src/main/cpp/helpers.cpp @@ -0,0 +1 @@ +../../../../monero_libwallet2_api_c/src/main/cpp/helpers.cpp \ No newline at end of file diff --git a/zano_libwallet2_api_c/src/main/cpp/helpers.hpp b/zano_libwallet2_api_c/src/main/cpp/helpers.hpp new file mode 120000 index 0000000..99d2733 --- /dev/null +++ b/zano_libwallet2_api_c/src/main/cpp/helpers.hpp @@ -0,0 +1 @@ +../../../../monero_libwallet2_api_c/src/main/cpp/helpers.hpp \ No newline at end of file diff --git a/zano_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp b/zano_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp new file mode 100644 index 0000000..11acc0a --- /dev/null +++ b/zano_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp @@ -0,0 +1,322 @@ +#include +#include "wallet2_api_c.h" +#include +#include +#include +#include "zano_checksum.h" +#include "helpers.hpp" +#include "../../../../zano/src/wallet/plain_wallet_api.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + +// namespace plain_wallet +// { +// typedef int64_t hwallet; +// std::string init(const std::string& address, const std::string& working_dir, int log_level); +const char* ZANO_PlainWallet_init(const char* address, const char* working_dir, int log_level) { + DEBUG_START() + std::string str = plain_wallet::init(std::string(address), std::string(working_dir), log_level); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string init(const std::string& ip, const std::string& port, const std::string& working_dir, int log_level); +const char* ZANO_PlainWallet_init2(const char* ip, const char* port, const char* working_dir, int log_level) { + DEBUG_START() + std::string str = plain_wallet::init(std::string(ip), std::string(port), std::string(working_dir), log_level); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string reset(); +const char* ZANO_PlainWallet_reset() { + DEBUG_START() + std::string str = plain_wallet::reset(); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string set_log_level(int log_level); +const char* ZANO_PlainWallet_setLogLevel(int log_level) { + DEBUG_START() + std::string str = plain_wallet::set_log_level(log_level); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string get_version(); +const char* ZANO_PlainWallet_getVersion() { + DEBUG_START() + std::string str = plain_wallet::get_version(); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string get_wallet_files(); +const char* ZANO_PlainWallet_getWalletFiles() { + DEBUG_START() + std::string str = plain_wallet::get_wallet_files(); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string get_export_private_info(const std::string& target_dir); +const char* ZANO_PlainWallet_getExportPrivateInfo(const char* target_dir) { + DEBUG_START() + std::string str = plain_wallet::get_export_private_info(std::string(target_dir)); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string delete_wallet(const std::string& file_name); +const char* ZANO_PlainWallet_deleteWallet(const char* file_name) { + DEBUG_START() + std::string str = plain_wallet::delete_wallet(std::string(file_name)); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string get_address_info(const std::string& addr); +const char* ZANO_PlainWallet_getAddressInfo(const char* addr) { + DEBUG_START() + std::string str = plain_wallet::get_address_info(std::string(addr)); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string get_appconfig(const std::string& encryption_key); +const char* ZANO_PlainWallet_getAppconfig(const char* encryption_key) { + DEBUG_START() + std::string str = plain_wallet::get_appconfig(std::string(encryption_key)); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string set_appconfig(const std::string& conf_str, const std::string& encryption_key); +const char* ZANO_PlainWallet_setAppconfig(const char* conf_str, const char* encryption_key) { + DEBUG_START() + std::string str = plain_wallet::set_appconfig(std::string(conf_str), std::string(encryption_key)); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string generate_random_key(uint64_t lenght); +const char* ZANO_PlainWallet_generateRandomKey(uint64_t lenght) { + DEBUG_START() + std::string str = plain_wallet::generate_random_key(lenght); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string get_logs_buffer(); +const char* ZANO_PlainWallet_getLogsBuffer() { + DEBUG_START() + std::string str = plain_wallet::get_logs_buffer(); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string truncate_log(); +const char* ZANO_PlainWallet_truncateLog() { + DEBUG_START() + std::string str = plain_wallet::truncate_log(); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string get_connectivity_status(); +const char* ZANO_PlainWallet_getConnectivityStatus() { + DEBUG_START() + std::string str = plain_wallet::get_connectivity_status(); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string open(const std::string& path, const std::string& password); +const char* ZANO_PlainWallet_open(const char* path, const char* password) { + DEBUG_START() + std::string str = plain_wallet::open(std::string(path), std::string(password)); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string restore(const std::string& seed, const std::string& path, const std::string& password, const std::string& seed_password); +const char* ZANO_PlainWallet_restore(const char* seed, const char* path, const char* password, const char* seed_password) { + DEBUG_START() + std::string str = plain_wallet::restore(std::string(seed), std::string(path), std::string(password), std::string(seed_password)); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string generate(const std::string& path, const std::string& password); +const char* ZANO_PlainWallet_generate(const char* path, const char* password) { + DEBUG_START() + std::string str = plain_wallet::generate(std::string(path), std::string(password)); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string get_opened_wallets(); +const char* ZANO_PlainWallet_getOpenWallets() { + DEBUG_START() + std::string str = plain_wallet::get_opened_wallets(); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} + +// std::string get_wallet_status(hwallet h); +const char* ZANO_PlainWallet_getWalletStatus(int64_t h) { + DEBUG_START() + std::string str = plain_wallet::get_wallet_status(h); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string close_wallet(hwallet h); +const char* ZANO_PlainWallet_closeWallet(int64_t h) { + DEBUG_START() + std::string str = plain_wallet::close_wallet(h); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string invoke(hwallet h, const std::string& params); +const char* ZANO_PlainWallet_invoke(int64_t h, const char* params) { + DEBUG_START() + std::string str = plain_wallet::invoke(h, std::string(params)); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// //async api +// std::string async_call(const std::string& method_name, uint64_t instance_id, const std::string& params); +const char* ZANO_PlainWallet_asyncCall(const char* method_name, uint64_t instance_id, const char* params) { + DEBUG_START() + std::string str = plain_wallet::async_call(std::string(method_name), instance_id, std::string(params)); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string try_pull_result(uint64_t); +const char* ZANO_PlainWallet_tryPullResult(uint64_t instance_id) { + DEBUG_START() + std::string str = plain_wallet::try_pull_result(instance_id); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string sync_call(const std::string& method_name, uint64_t instance_id, const std::string& params); +const char* ZANO_PlainWallet_syncCall(const char* method_name, uint64_t instance_id, const char* params) { + DEBUG_START() + std::string str = plain_wallet::sync_call(std::string(method_name), instance_id, std::string(params)); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// //cake wallet api extension +// bool is_wallet_exist(const std::string& path); +bool ZANO_PlainWallet_isWalletExist(const char* path) { + DEBUG_START() + return plain_wallet::is_wallet_exist(std::string(path)); + DEBUG_END() +} +// std::string get_wallet_info(hwallet h); +const char* ZANO_PlainWallet_getWalletInfo(int64_t h) { + DEBUG_START() + std::string str = plain_wallet::get_wallet_info(h); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// std::string reset_wallet_password(hwallet h, const std::string& password); +const char* ZANO_PlainWallet_resetWalletPassword(int64_t h, const char* password) { + DEBUG_START() + std::string str = plain_wallet::reset_wallet_password(h, std::string(password)); + const std::string::size_type size = str.size(); + char *buffer = new char[size + 1]; //we need extra char for NUL + memcpy(buffer, str.c_str(), size + 1); + return buffer; + DEBUG_END() +} +// uint64_t get_current_tx_fee(uint64_t priority); // 0 (default), 1 (unimportant), 2 (normal), 3 (elevated), 4 (priority) +uint64_t ZANO_PlainWallet_getCurrentTxFee(uint64_t priority) { + DEBUG_START() + return plain_wallet::get_current_tx_fee(priority); + DEBUG_END() +} +// } + +void ZANO_free(void* ptr) { + free(ptr); +} + +const char* ZANO_checksum_wallet2_api_c_h() { + return ZANO_wallet2_api_c_h_sha256; +} +const char* ZANO_checksum_wallet2_api_c_cpp() { + return ZANO_wallet2_api_c_cpp_sha256; +} +const char* ZANO_checksum_wallet2_api_c_exp() { + return ZANO_wallet2_api_c_exp_sha256; +} + +#ifdef __cplusplus +} +#endif diff --git a/zano_libwallet2_api_c/src/main/cpp/wallet2_api_c.h b/zano_libwallet2_api_c/src/main/cpp/wallet2_api_c.h new file mode 100644 index 0000000..df6d3ef --- /dev/null +++ b/zano_libwallet2_api_c/src/main/cpp/wallet2_api_c.h @@ -0,0 +1,67 @@ +/* +#include + +#define LOG_TAG "[NDK]" +#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) +#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__) +#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) +*/ +#include +#include +#include +#include +#include "zano_checksum.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifdef __MINGW32__ + #define ADDAPI __declspec(dllexport) +#else + #define ADDAPI __attribute__((__visibility__("default"))) +#endif + + +extern ADDAPI const char* ZANO_PlainWallet_init(const char* address, const char* working_dir, int log_level); +extern ADDAPI const char* ZANO_PlainWallet_init2(const char* ip, const char* port, const char* working_dir, int log_level); +extern ADDAPI const char* ZANO_PlainWallet_reset(); +extern ADDAPI const char* ZANO_PlainWallet_setLogLevel(int log_level); +extern ADDAPI const char* ZANO_PlainWallet_getVersion(); +extern ADDAPI const char* ZANO_PlainWallet_getWalletFiles(); +extern ADDAPI const char* ZANO_PlainWallet_getExportPrivateInfo(const char* target_dir); +extern ADDAPI const char* ZANO_PlainWallet_deleteWallet(const char* file_name); +extern ADDAPI const char* ZANO_PlainWallet_getAddressInfo(const char* addr); +extern ADDAPI const char* ZANO_PlainWallet_getAppconfig(const char* encryption_key); +extern ADDAPI const char* ZANO_PlainWallet_setAppconfig(const char* conf_str, const char* encryption_key); +extern ADDAPI const char* ZANO_PlainWallet_generateRandomKey(uint64_t lenght); +extern ADDAPI const char* ZANO_PlainWallet_getLogsBuffer(); +extern ADDAPI const char* ZANO_PlainWallet_truncateLog(); +extern ADDAPI const char* ZANO_PlainWallet_getConnectivityStatus(); +extern ADDAPI const char* ZANO_PlainWallet_open(const char* path, const char* password); +extern ADDAPI const char* ZANO_PlainWallet_restore(const char* seed, const char* path, const char* password, const char* seed_password); +extern ADDAPI const char* ZANO_PlainWallet_generate(const char* path, const char* password); +extern ADDAPI const char* ZANO_PlainWallet_getOpenWallets(); +extern ADDAPI const char* ZANO_PlainWallet_getWalletStatus(int64_t h); +extern ADDAPI const char* ZANO_PlainWallet_closeWallet(int64_t h); +extern ADDAPI const char* ZANO_PlainWallet_invoke(int64_t h, const char* params); + + +extern ADDAPI const char* ZANO_PlainWallet_asyncCall(const char* method_name, uint64_t instance_id, const char* params); +extern ADDAPI const char* ZANO_PlainWallet_tryPullResult(uint64_t instance_id); +extern ADDAPI const char* ZANO_PlainWallet_syncCall(const char* method_name, uint64_t instance_id, const char* params); +extern ADDAPI bool ZANO_PlainWallet_isWalletExist(const char* path); +extern ADDAPI const char* ZANO_PlainWallet_getWalletInfo(int64_t h); +extern ADDAPI const char* ZANO_PlainWallet_resetWalletPassword(int64_t h, const char* password); +extern ADDAPI uint64_t ZANO_PlainWallet_getCurrentTxFee(uint64_t priority); + +extern ADDAPI void ZANO_free(void* ptr); + +extern ADDAPI const char* ZANO_checksum_wallet2_api_c_h(); +extern ADDAPI const char* ZANO_checksum_wallet2_api_c_cpp(); +extern ADDAPI const char* ZANO_checksum_wallet2_api_c_exp(); + +#ifdef __cplusplus +} +#endif diff --git a/zano_libwallet2_api_c/src/main/cpp/zano_checksum.h b/zano_libwallet2_api_c/src/main/cpp/zano_checksum.h new file mode 100644 index 0000000..7f8d845 --- /dev/null +++ b/zano_libwallet2_api_c/src/main/cpp/zano_checksum.h @@ -0,0 +1,6 @@ +#ifndef MONEROC_CHECKSUMS +#define MONEROC_CHECKSUMS +const char * ZANO_wallet2_api_c_h_sha256 = "8acaa95513b85a984c08e05cc3f2ac7530bb8f32946eeeb45357bd846aef33dd"; +const char * ZANO_wallet2_api_c_cpp_sha256 = "4efacd3812d53dd268b6869cc0a9560e7320574d96e09136cf067f796edfeba6-2817090c8ac7639d6f697d00fc8bcba2b3681d90"; +const char * ZANO_wallet2_api_c_exp_sha256 = "66f3ff655bbfd11ad28c318ab707090b5a93276f436b06f7b1c0f329dba3c9c2"; +#endif diff --git a/zano_libwallet2_api_c/zano_libwallet2_api_c.exp b/zano_libwallet2_api_c/zano_libwallet2_api_c.exp new file mode 100644 index 0000000..423922a --- /dev/null +++ b/zano_libwallet2_api_c/zano_libwallet2_api_c.exp @@ -0,0 +1,33 @@ +_ZANO_PlainWallet_init +_ZANO_PlainWallet_init2 +_ZANO_PlainWallet_reset +_ZANO_PlainWallet_setLogLevel +_ZANO_PlainWallet_getVersion +_ZANO_PlainWallet_getWalletFiles +_ZANO_PlainWallet_getExportPrivateInfo +_ZANO_PlainWallet_deleteWallet +_ZANO_PlainWallet_getAddressInfo +_ZANO_PlainWallet_getAppconfig +_ZANO_PlainWallet_setAppconfig +_ZANO_PlainWallet_generateRandomKey +_ZANO_PlainWallet_getLogsBuffer +_ZANO_PlainWallet_truncateLog +_ZANO_PlainWallet_getConnectivityStatus +_ZANO_PlainWallet_open +_ZANO_PlainWallet_restore +_ZANO_PlainWallet_generate +_ZANO_PlainWallet_getOpenWallets +_ZANO_PlainWallet_getWalletStatus +_ZANO_PlainWallet_closeWallet +_ZANO_PlainWallet_invoke +_ZANO_PlainWallet_asyncCall +_ZANO_PlainWallet_tryPullResult +_ZANO_PlainWallet_syncCall +_ZANO_PlainWallet_isWalletExist +_ZANO_PlainWallet_getWalletInfo +_ZANO_PlainWallet_resetWalletPassword +_ZANO_PlainWallet_getCurrentTxFee +_ZANO_free +_ZANO_checksum_wallet2_api_c_h +_ZANO_checksum_wallet2_api_c_cpp +_ZANO_checksum_wallet2_api_c_exp \ No newline at end of file -- cgit v1.2.3