From 38c9de21f4b22f2efd88b7bf15478e67efbd09e5 Mon Sep 17 00:00:00 2001 From: likho Date: Wed, 28 Feb 2024 07:04:55 +0200 Subject: [PATCH 1/4] WIP: Update to latest Epic release --- crypto_plugins/flutter_libepiccash | 2 +- .../transaction_views/tx_v2/transaction_v2_details_view.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto_plugins/flutter_libepiccash b/crypto_plugins/flutter_libepiccash index 9eb24dd00..396d519a4 160000 --- a/crypto_plugins/flutter_libepiccash +++ b/crypto_plugins/flutter_libepiccash @@ -1 +1 @@ -Subproject commit 9eb24dd00cd0e1df08624ece1ca47090c158c08c +Subproject commit 396d519a4c3ae1c47c8406e5506b0966f1f7098f diff --git a/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart b/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart index d44588b3c..5a1ae2032 100644 --- a/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart +++ b/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart @@ -1048,7 +1048,7 @@ class _TransactionV2DetailsViewState pTransactionNote( ( txid: (coin == Coin.epicCash) ? - _transaction.slateId as String + _transaction.slateId.toString() : _transaction.txid, walletId: walletId ), From ab3df052d43871d5b683466b097004774d2f4bb8 Mon Sep 17 00:00:00 2001 From: likho Date: Wed, 28 Feb 2024 15:43:53 +0200 Subject: [PATCH 2/4] Check if default Epicbox is up on start up, always update wallet address to connected Epicbox server --- lib/utilities/default_epicboxes.dart | 2 +- lib/wallets/wallet/impl/epiccash_wallet.dart | 115 +++++++++---------- 2 files changed, 58 insertions(+), 59 deletions(-) diff --git a/lib/utilities/default_epicboxes.dart b/lib/utilities/default_epicboxes.dart index 6f0fbc7c5..f83f84cf5 100644 --- a/lib/utilities/default_epicboxes.dart +++ b/lib/utilities/default_epicboxes.dart @@ -17,7 +17,7 @@ abstract class DefaultEpicBoxes { static List get defaultIds => ['americas', 'asia', 'europe']; static EpicBoxServerModel get americas => EpicBoxServerModel( - host: 'stackwallet.epicbox.com', + host: 'epicbox.stackwallet.com', port: 443, name: 'Americas', id: 'americas', diff --git a/lib/wallets/wallet/impl/epiccash_wallet.dart b/lib/wallets/wallet/impl/epiccash_wallet.dart index 7f37aa318..bca8453bc 100644 --- a/lib/wallets/wallet/impl/epiccash_wallet.dart +++ b/lib/wallets/wallet/impl/epiccash_wallet.dart @@ -104,45 +104,28 @@ class EpiccashWallet extends Bip39Wallet { Future getEpicBoxConfig() async { EpicBoxConfigModel? _epicBoxConfig; - // read epicbox config from secure store - String? storedConfig = - await secureStorageInterface.read(key: '${walletId}_epicboxConfig'); - // we should move to storing the primary server model like we do with nodes, and build the config from that (see epic-mobile) - // EpicBoxServerModel? _epicBox = epicBox ?? - // DB.instance.get( - // boxName: DB.boxNamePrimaryEpicBox, key: 'primary'); - // Logging.instance.log( - // "Read primary Epic Box config: ${jsonEncode(_epicBox)}", - // level: LogLevel.Info); + //Get the default Epicbox server and check if it's conected + bool isEpicboxConnected = await _testEpicboxServer( + DefaultEpicBoxes.defaultEpicBoxServer.host, DefaultEpicBoxes.defaultEpicBoxServer.port ?? 443); - if (storedConfig == null) { - // if no config stored, use the default epicbox server as config + if (isEpicboxConnected) { + //Use default server for as Epicbox config _epicBoxConfig = EpicBoxConfigModel.fromServer(DefaultEpicBoxes.defaultEpicBoxServer); } else { - // if a config is stored, test it - - _epicBoxConfig = EpicBoxConfigModel.fromString( - storedConfig); // fromString handles checking old config formats - } - - bool isEpicboxConnected = await _testEpicboxServer( - _epicBoxConfig.host, _epicBoxConfig.port ?? 443); - - if (!isEpicboxConnected) { - // default Epicbox is not connected, default to Europe + //Use Europe config _epicBoxConfig = EpicBoxConfigModel.fromServer(DefaultEpicBoxes.europe); - - // example of selecting another random server from the default list - // alternative servers: copy list of all default EB servers but remove the default default - // List alternativeServers = DefaultEpicBoxes.all; - // alternativeServers.removeWhere((opt) => opt.name == DefaultEpicBoxes.defaultEpicBoxServer.name); - // alternativeServers.shuffle(); // randomize which server is used - // _epicBoxConfig = EpicBoxConfigModel.fromServer(alternativeServers.first); - - // TODO test this connection before returning it } + // // example of selecting another random server from the default list + // // alternative servers: copy list of all default EB servers but remove the default default + // // List alternativeServers = DefaultEpicBoxes.all; + // // alternativeServers.removeWhere((opt) => opt.name == DefaultEpicBoxes.defaultEpicBoxServer.name); + // // alternativeServers.shuffle(); // randomize which server is used + // // _epicBoxConfig = EpicBoxConfigModel.fromServer(alternativeServers.first); + // + // // TODO test this connection before returning it + // } return _epicBoxConfig; } @@ -334,36 +317,52 @@ class EpiccashWallet extends Bip39Wallet { int index, ) async { Address? address = await getCurrentReceivingAddress(); + EpicBoxConfigModel epicboxConfig = await getEpicBoxConfig(); - if (address == null) { - final wallet = - await secureStorageInterface.read(key: '${walletId}_wallet'); - EpicBoxConfigModel epicboxConfig = await getEpicBoxConfig(); + if (address != null) { + final splitted = address.value.split('@'); + //Check if the address is the same as the current epicbox index + if (splitted[1] != epicboxConfig.host) { + //Update the address + address = await thisWalletAddress(index, epicboxConfig); + } - final walletAddress = await epiccash.LibEpiccash.getAddressInfo( - wallet: wallet!, - index: index, - epicboxConfig: epicboxConfig.toString(), - ); - - Logging.instance.log( - "WALLET_ADDRESS_IS $walletAddress", - level: LogLevel.Info, - ); - - address = Address( - walletId: walletId, - value: walletAddress, - derivationIndex: index, - derivationPath: null, - type: AddressType.mimbleWimble, - subType: AddressSubType.receiving, - publicKey: [], // ?? - ); - - await mainDB.updateOrPutAddresses([address]); + } else { + address = await thisWalletAddress(index, epicboxConfig); } + + // print("NOW THIS ADDRESS IS $address"); + return address; + } + + Future
thisWalletAddress(int index, EpicBoxConfigModel epicboxConfig) async { + final wallet = + await secureStorageInterface.read(key: '${walletId}_wallet'); + // EpicBoxConfigModel epicboxConfig = await getEpicBoxConfig(); + + final walletAddress = await epiccash.LibEpiccash.getAddressInfo( + wallet: wallet!, + index: index, + epicboxConfig: epicboxConfig.toString(), + ); + + Logging.instance.log( + "WALLET_ADDRESS_IS $walletAddress", + level: LogLevel.Info, + ); + + final address = Address( + walletId: walletId, + value: walletAddress, + derivationIndex: index, + derivationPath: null, + type: AddressType.mimbleWimble, + subType: AddressSubType.receiving, + publicKey: [], // ?? + ); + + await mainDB.updateOrPutAddresses([address]); return address; } From 891f2d8702d55b5d05d2f10a23082a592cbe8fde Mon Sep 17 00:00:00 2001 From: likho Date: Wed, 28 Feb 2024 19:23:55 +0200 Subject: [PATCH 3/4] Attemp to update cached receiving address --- lib/wallets/wallet/impl/epiccash_wallet.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/wallets/wallet/impl/epiccash_wallet.dart b/lib/wallets/wallet/impl/epiccash_wallet.dart index bca8453bc..3509ca08a 100644 --- a/lib/wallets/wallet/impl/epiccash_wallet.dart +++ b/lib/wallets/wallet/impl/epiccash_wallet.dart @@ -332,7 +332,7 @@ class EpiccashWallet extends Bip39Wallet { } - // print("NOW THIS ADDRESS IS $address"); + print("NOW THIS ADDRESS IS $address"); return address; } @@ -363,6 +363,12 @@ class EpiccashWallet extends Bip39Wallet { ); await mainDB.updateOrPutAddresses([address]); + if (info.cachedReceivingAddress != address.value) { + await info.updateReceivingAddress( + newAddress: address.value, + isar: mainDB.isar, + ); + } return address; } @@ -935,6 +941,7 @@ class EpiccashWallet extends Bip39Wallet { .findAll(); final myAddressesSet = myAddresses.toSet(); + final transactions = await epiccash.LibEpiccash.getTransactions( wallet: wallet!, refreshFromNode: refreshFromNode, From 41d71f0529c4556494b831c19486ceef6011f03d Mon Sep 17 00:00:00 2001 From: likho Date: Wed, 28 Feb 2024 20:11:18 +0200 Subject: [PATCH 4/4] Remove failover options for Epicbox --- lib/wallets/wallet/impl/epiccash_wallet.dart | 35 ++++++++------------ 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/lib/wallets/wallet/impl/epiccash_wallet.dart b/lib/wallets/wallet/impl/epiccash_wallet.dart index 3509ca08a..8228ab7c8 100644 --- a/lib/wallets/wallet/impl/epiccash_wallet.dart +++ b/lib/wallets/wallet/impl/epiccash_wallet.dart @@ -103,20 +103,21 @@ class EpiccashWallet extends Bip39Wallet { } Future getEpicBoxConfig() async { - EpicBoxConfigModel? _epicBoxConfig; + EpicBoxConfigModel? _epicBoxConfig = + EpicBoxConfigModel.fromServer(DefaultEpicBoxes.defaultEpicBoxServer); //Get the default Epicbox server and check if it's conected - bool isEpicboxConnected = await _testEpicboxServer( - DefaultEpicBoxes.defaultEpicBoxServer.host, DefaultEpicBoxes.defaultEpicBoxServer.port ?? 443); + // bool isEpicboxConnected = await _testEpicboxServer( + // DefaultEpicBoxes.defaultEpicBoxServer.host, DefaultEpicBoxes.defaultEpicBoxServer.port ?? 443); - if (isEpicboxConnected) { + // if (isEpicboxConnected) { //Use default server for as Epicbox config - _epicBoxConfig = - EpicBoxConfigModel.fromServer(DefaultEpicBoxes.defaultEpicBoxServer); - } else { - //Use Europe config - _epicBoxConfig = EpicBoxConfigModel.fromServer(DefaultEpicBoxes.europe); - } + + // } + // else { + // //Use Europe config + // _epicBoxConfig = EpicBoxConfigModel.fromServer(DefaultEpicBoxes.europe); + // } // // example of selecting another random server from the default list // // alternative servers: copy list of all default EB servers but remove the default default // // List alternativeServers = DefaultEpicBoxes.all; @@ -321,18 +322,16 @@ class EpiccashWallet extends Bip39Wallet { if (address != null) { final splitted = address.value.split('@'); - //Check if the address is the same as the current epicbox index + //Check if the address is the same as the current epicbox domain + //Since we're only using one epicbpox now this doesn't apply but will be + // useful in the future if (splitted[1] != epicboxConfig.host) { //Update the address address = await thisWalletAddress(index, epicboxConfig); } - } else { address = await thisWalletAddress(index, epicboxConfig); } - - - print("NOW THIS ADDRESS IS $address"); return address; } @@ -363,12 +362,6 @@ class EpiccashWallet extends Bip39Wallet { ); await mainDB.updateOrPutAddresses([address]); - if (info.cachedReceivingAddress != address.value) { - await info.updateReceivingAddress( - newAddress: address.value, - isar: mainDB.isar, - ); - } return address; }