From 8af6b773b71e3121c7faeadd30763531556103a3 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Sun, 30 Jun 2024 11:53:21 +0000 Subject: fix: wownero seed giving incorrect add: pr-comment.yaml --- .../src/main/cpp/wallet2_api_c.cpp | 63 +++++++++++++--------- 1 file changed, 38 insertions(+), 25 deletions(-) (limited to 'wownero_libwallet2_api_c') diff --git a/wownero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp b/wownero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp index 2ba0ef9..6afdfe4 100644 --- a/wownero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp +++ b/wownero_libwallet2_api_c/src/main/cpp/wallet2_api_c.cpp @@ -1870,32 +1870,45 @@ uint64_t WOWNERO_cw_WalletListener_height(void* cw_walletListener_ptr) { // https://github.com/cypherstack/flutter_libmonero/blob/2c684cedba6c3d9353c7ea748cadb5a246008027/cw_wownero/ios/Classes/wownero_api.cpp#L240 // this code slightly goes against the way of being simple void* WOWNERO_deprecated_restore14WordSeed(char *path, char *password, char *seed, int32_t networkType) { - Monero::NetworkType _networkType = static_cast(networkType); Monero::WalletManager *walletManager = Monero::WalletManagerFactory::getWalletManager(); - - // 14 word seeds /* - wownero_seed wow_seed(seed, "wownero"); - - std::stringstream seed_stream; - seed_stream << wow_seed; - std::string seed_str = seed_stream.str(); - - std::stringstream key_stream; - key_stream << wow_seed.key(); - std::string spendKey = key_stream.str(); - - uint64_t restoreHeight = wow_seed.blockheight(); - - Monero::Wallet *wallet = walletManager->createDeterministicWalletFromSpendKey( - std::string(path), - std::string(password), - "English", - static_cast(_networkType), - (uint64_t)restoreHeight, - spendKey, - 1); - wallet->setCacheAttribute("cake.seed", seed_str); - return reinterpret_cast(wallet); + try { + Monero::NetworkType _networkType = static_cast(networkType); + + // 14 word seeds /* + wownero_seed wow_seed(seed, "wownero"); + + std::stringstream seed_stream; + seed_stream << wow_seed; + std::string seed_str = seed_stream.str(); + + std::stringstream key_stream; + key_stream << wow_seed.key(); + std::string spendKey = key_stream.str(); + + uint64_t restoreHeight = wow_seed.blockheight(); + + Monero::Wallet *wallet = walletManager->createDeterministicWalletFromSpendKey( + std::string(path), + std::string(password), + "English", + static_cast(_networkType), + (uint64_t)restoreHeight, + spendKey, + 1); + wallet->setCacheAttribute("cake.seed", seed_str); + return reinterpret_cast(wallet); + } catch (...) { + // fallback code so wallet->status() returns at least something.. eh.. + Monero::Wallet *wallet = walletManager->recoveryWallet( + "/", + "", + "invalid mnemonic", + static_cast(networkType), + 0, + 1, + ""); + return reinterpret_cast(wallet); + } } uint64_t WOWNERO_deprecated_14WordSeedHeight(char *seed) { -- cgit v1.2.3