diff --git a/README.md b/README.md index c56d5b7..4d5e50c 100644 --- a/README.md +++ b/README.md @@ -66,8 +66,36 @@ Libraries on CI are build using the following docker images: It is entirely possible to use upstream debian:buster / debian:bookworm +## Design + +Functions are as simple as reasonably possible as few steps should be performed to get from the exposed C api to actual wallet2 (or wallet3 in future) api calls. + +The only things passed in and out are: + +- void +- bool +- int +- uint64_t +- void* +- const char* + +All more complex structures are serialized into `const char*`, take look at MONERO_Wallet_createTransaction which uses `splitString(std::string(preferredInputs), std::string(separator));` to convert string into a std::set, so no implementation will need to worry about that. + +Is there more effective way to do that? Probably. Is there more universal way to pass that (JSON, or others?)? Most likely. That being said, I'm against doing that. You can easily join a string in any language, and I like to keep dependency count as low as possible. + +As for function naming `${COIN}_namespaceOrClass_functionName` is being used, currently these cryptocurrencies are supported + +- monero +- wownero + +both using wallet2 api, and both being patched with our secret ingredient(tm) (check patches directory). + +Since monero_c aims to be one-fits-all solution for monero wallets, there are some special things inside, like functions prefixed with `DEBUG_*`, these are not quarenteed to stay in the code, and can be changed, the only reason they are in is because I needed some testing early in the development when bringing support for variety of platforms. + +If you are a wallet developer and you **really** need this one function that doesn't exist, feel free to let me know I'll be happy to implement that. + +Currently there are enterprise resitents in our library: `${COIN}_cw_*` these functions are not guaranteed to stay stable, and are made for cake wallet to implement features that are not used in xmruw nor in stack_wallet (which I need to double-check later?). + ## Contributing -To contribute you can visit git.mrcyjanek.net/mrcyjanek/monero_c and open a PR, alternatively use any other code mirror or send patches directly. - -**IMPORTANT** I don't have time to write better README, please check `build_single.sh` for build instructions, in general it comes down to running the script. \ No newline at end of file +To contribute you can visit git.mrcyjanek.net/mrcyjanek/monero_c and open a PR, alternatively use any other code mirror or send patches directly. \ No newline at end of file diff --git a/monero_libwallet2_api_c/monero_libwallet2_api_c.exp b/monero_libwallet2_api_c/monero_libwallet2_api_c.exp index 7308be3..1f6a5cc 100644 --- a/monero_libwallet2_api_c/monero_libwallet2_api_c.exp +++ b/monero_libwallet2_api_c/monero_libwallet2_api_c.exp @@ -266,4 +266,10 @@ _MONERO_Wallet_unlockedBalance _MONERO_Wallet_useForkRules _MONERO_Wallet_verifySignedMessage _MONERO_Wallet_viewOnlyBalance -_MONERO_Wallet_watchOnly \ No newline at end of file +_MONERO_Wallet_watchOnly +_MONERO_cw_getWalletListener +_MONERO_cw_WalletListener_resetNeedToRefresh +_MONERO_cw_WalletListener_isNeedToRefresh +_MONERO_cw_WalletListener_isNewTransactionExist +_MONERO_cw_WalletListener_resetIsNewTransactionExist +_MONERO_cw_WalletListener_height diff --git a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp index a39182c..ab13e15 100644 --- a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp +++ b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp @@ -1697,6 +1697,114 @@ bool MONERO_DEBUG_isPointerNull(void* wallet_ptr) { return (wallet != NULL); } +// cake wallet world +// TODO(mrcyjanek): https://api.dart.dev/stable/3.3.3/dart-ffi/Pointer/fromFunction.html +// callback to dart should be possible..? I mean why not? But I need to +// wait for other implementation (Go preferably) to see if this approach +// will work as expected. +struct MONERO_cw_WalletListener; +struct MONERO_cw_WalletListener : Monero::WalletListener +{ + uint64_t m_height; + bool m_need_to_refresh; + bool m_new_transaction; + + MONERO_cw_WalletListener() + { + m_height = 0; + m_need_to_refresh = false; + m_new_transaction = false; + } + + void moneySpent(const std::string &txId, uint64_t amount) + { + m_new_transaction = true; + } + + void moneyReceived(const std::string &txId, uint64_t amount) + { + m_new_transaction = true; + } + + void unconfirmedMoneyReceived(const std::string &txId, uint64_t amount) + { + m_new_transaction = true; + } + + void newBlock(uint64_t height) + { + m_height = height; + } + + void updated() + { + m_new_transaction = true; + } + + void refreshed() + { + m_need_to_refresh = true; + } + + + void cw_resetNeedToRefresh() + { + m_need_to_refresh = false; + } + + bool cw_isNeedToRefresh() + { + return m_need_to_refresh; + } + + bool cw_isNewTransactionExist() + { + return m_new_transaction; + } + + void cw_resetIsNewTransactionExist() + { + m_new_transaction = false; + } + + uint64_t cw_height() + { + return m_height; + } +}; + +void* MONERO_cw_getWalletListener(void* wallet_ptr) { + Monero::Wallet *wallet = reinterpret_cast(wallet_ptr); + MONERO_cw_WalletListener *listener = new MONERO_cw_WalletListener(); + wallet->setListener(listener); + return reinterpret_cast(listener); +} + +void MONERO_cw_WalletListener_resetNeedToRefresh(void* cw_walletListener_ptr) { + MONERO_cw_WalletListener *listener = reinterpret_cast(cw_walletListener_ptr); + listener->cw_resetNeedToRefresh(); +} + +bool MONERO_cw_WalletListener_isNeedToRefresh(void* cw_walletListener_ptr) { + MONERO_cw_WalletListener *listener = reinterpret_cast(cw_walletListener_ptr); + return listener->cw_isNeedToRefresh(); +}; + +bool MONERO_cw_WalletListener_isNewTransactionExist(void* cw_walletListener_ptr) { + MONERO_cw_WalletListener *listener = reinterpret_cast(cw_walletListener_ptr); + return listener->cw_isNeedToRefresh(); +}; + +void MONERO_cw_WalletListener_resetIsNewTransactionExist(void* cw_walletListener_ptr) { + MONERO_cw_WalletListener *listener = reinterpret_cast(cw_walletListener_ptr); + listener->cw_isNeedToRefresh(); +}; + +uint64_t MONERO_cw_WalletListener_height(void* cw_walletListener_ptr) { + MONERO_cw_WalletListener *listener = reinterpret_cast(cw_walletListener_ptr); + return listener->cw_isNeedToRefresh(); +}; + #ifdef __cplusplus } #endif diff --git a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h index afa2a71..f0bd66e 100644 --- a/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h +++ b/monero_libwallet2_api_c/src/main/cpp/wallet2_api_c.h @@ -976,6 +976,15 @@ extern ADDAPI const char* MONERO_DEBUG_test5(); extern ADDAPI const char* MONERO_DEBUG_test5_std(); extern ADDAPI bool MONERO_DEBUG_isPointerNull(void* wallet_ptr); +// cake world + +extern ADDAPI void* MONERO_cw_getWalletListener(void* wallet_ptr); +extern ADDAPI void MONERO_cw_WalletListener_resetNeedToRefresh(void* cw_walletListener_ptr); +extern ADDAPI bool MONERO_cw_WalletListener_isNeedToRefresh(void* cw_walletListener_ptr); +extern ADDAPI bool MONERO_cw_WalletListener_isNewTransactionExist(void* cw_walletListener_ptr); +extern ADDAPI void MONERO_cw_WalletListener_resetIsNewTransactionExist(void* cw_walletListener_ptr); +extern ADDAPI uint64_t MONERO_cw_WalletListener_height(void* cw_walletListener_ptr); + #ifdef __cplusplus } #endif \ No newline at end of file