From d748f12e4441a7383c0a86c169c94053a4815314 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Tue, 4 Oct 2022 14:54:39 +0200 Subject: [PATCH 1/4] Allow marking Monero Nodes as trusted --- cw_core/lib/node.dart | 11 +++++++++-- .../screens/nodes/node_create_or_edit_page.dart | 17 ++++++++++++++++- .../node_create_or_edit_view_model.dart | 9 +++++++-- res/values/strings_de.arb | 1 + res/values/strings_en.arb | 1 + res/values/strings_es.arb | 1 + res/values/strings_fr.arb | 1 + res/values/strings_hi.arb | 1 + res/values/strings_hr.arb | 1 + res/values/strings_it.arb | 1 + res/values/strings_ja.arb | 1 + res/values/strings_ko.arb | 1 + res/values/strings_nl.arb | 1 + res/values/strings_pl.arb | 1 + res/values/strings_pt.arb | 2 +- res/values/strings_ru.arb | 1 + res/values/strings_uk.arb | 1 + res/values/strings_zh.arb | 1 + 18 files changed, 47 insertions(+), 6 deletions(-) diff --git a/cw_core/lib/node.dart b/cw_core/lib/node.dart index 7de2e84b6..dd5969b99 100644 --- a/cw_core/lib/node.dart +++ b/cw_core/lib/node.dart @@ -20,7 +20,8 @@ class Node extends HiveObject with Keyable { @required WalletType type, this.login, this.password, - this.useSSL}) { + this.useSSL, + this.trusted}) { uriRaw = uri; this.type = type; } @@ -30,7 +31,8 @@ class Node extends HiveObject with Keyable { login = map['login'] as String, password = map['password'] as String, typeRaw = map['typeRaw'] as int, - useSSL = map['useSSL'] as bool; + useSSL = map['useSSL'] as bool, + trusted = map['trusted'] as bool ?? false; static const typeId = 1; static const boxName = 'Nodes'; @@ -50,8 +52,13 @@ class Node extends HiveObject with Keyable { @HiveField(4) bool useSSL; + @HiveField(5) + bool trusted; + bool get isSSL => useSSL ?? false; + bool get isTrusted => trusted ?? false; + Uri get uri { switch (type) { case WalletType.monero: diff --git a/lib/src/screens/nodes/node_create_or_edit_page.dart b/lib/src/screens/nodes/node_create_or_edit_page.dart index 6cfa67285..857bde023 100644 --- a/lib/src/screens/nodes/node_create_or_edit_page.dart +++ b/lib/src/screens/nodes/node_create_or_edit_page.dart @@ -174,7 +174,22 @@ class NodeCreateOrEditPage extends BasePage { caption: S.of(context).use_ssl, )) ], - )) + )), + Padding( + padding: EdgeInsets.only(top: 20), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + Observer( + builder: (_) => StandardCheckbox( + value: nodeCreateOrEditViewModel.trusted, + onChanged: (value) => + nodeCreateOrEditViewModel.trusted = value, + caption: S.of(context).trusted, + )) + ], + )), ] ], )), diff --git a/lib/view_model/node_list/node_create_or_edit_view_model.dart b/lib/view_model/node_list/node_create_or_edit_view_model.dart index ef7e03189..c14bdda5e 100644 --- a/lib/view_model/node_list/node_create_or_edit_view_model.dart +++ b/lib/view_model/node_list/node_create_or_edit_view_model.dart @@ -14,7 +14,8 @@ abstract class NodeCreateOrEditViewModelBase with Store { NodeCreateOrEditViewModelBase(this._nodeSource, this._wallet) : state = InitialExecutionState(), connectionState = InitialExecutionState(), - useSSL = false; + useSSL = false, + trusted = false; @observable ExecutionState state; @@ -37,6 +38,9 @@ abstract class NodeCreateOrEditViewModelBase with Store { @observable bool useSSL; + @observable + bool trusted; + @computed bool get isReady => (address?.isNotEmpty ?? false) && (port?.isNotEmpty ?? false); @@ -64,6 +68,7 @@ abstract class NodeCreateOrEditViewModelBase with Store { login = ''; password = ''; useSSL = false; + trusted = false; } @action @@ -72,7 +77,7 @@ abstract class NodeCreateOrEditViewModelBase with Store { state = IsExecutingState(); final node = Node(uri: uri, type: _wallet.type, login: login, password: password, - useSSL: useSSL); + useSSL: useSSL, trusted: trusted); await _nodeSource.add(node); state = ExecutedSuccessfullyState(); } catch (e) { diff --git a/res/values/strings_de.arb b/res/values/strings_de.arb index 3457f8ab2..fa04a6a8e 100644 --- a/res/values/strings_de.arb +++ b/res/values/strings_de.arb @@ -436,6 +436,7 @@ "provider_error" : "${provider}-Fehler", "use_ssl" : "SSL verwenden", + "trusted" : "Vertrauenswürdige", "color_theme" : "Farbthema", "light_theme" : "Hell", diff --git a/res/values/strings_en.arb b/res/values/strings_en.arb index ef8e6e495..4a46d36c8 100644 --- a/res/values/strings_en.arb +++ b/res/values/strings_en.arb @@ -436,6 +436,7 @@ "provider_error" : "${provider} error", "use_ssl" : "Use SSL", + "trusted" : "Trusted", "color_theme" : "Color theme", "light_theme" : "Light", diff --git a/res/values/strings_es.arb b/res/values/strings_es.arb index 7c996134e..756ac3e11 100644 --- a/res/values/strings_es.arb +++ b/res/values/strings_es.arb @@ -436,6 +436,7 @@ "provider_error" : "${provider} error", "use_ssl" : "Utilice SSL", + "trusted" : "de confianza", "color_theme" : "Tema de color", "light_theme" : "Ligera", diff --git a/res/values/strings_fr.arb b/res/values/strings_fr.arb index b347086ae..04462943e 100644 --- a/res/values/strings_fr.arb +++ b/res/values/strings_fr.arb @@ -434,6 +434,7 @@ "provider_error" : "Erreur de ${provider}", "use_ssl" : "Utiliser SSL", + "trusted" : "de confiance", "color_theme" : "Thème", "light_theme" : "Clair", diff --git a/res/values/strings_hi.arb b/res/values/strings_hi.arb index 83c0808c4..f8bad76e2 100644 --- a/res/values/strings_hi.arb +++ b/res/values/strings_hi.arb @@ -436,6 +436,7 @@ "provider_error" : "${provider} त्रुटि", "use_ssl" : "उपयोग SSL", + "trusted" : "भरोसा", "color_theme" : "रंग विषय", "light_theme" : "रोशनी", diff --git a/res/values/strings_hr.arb b/res/values/strings_hr.arb index 97d4d335c..0e27e3a2c 100644 --- a/res/values/strings_hr.arb +++ b/res/values/strings_hr.arb @@ -436,6 +436,7 @@ "provider_error" : "${provider} greška", "use_ssl" : "Koristi SSL", + "trusted" : "vjerovao", "color_theme" : "Shema boja", "light_theme" : "Svijetla", diff --git a/res/values/strings_it.arb b/res/values/strings_it.arb index cd779471f..ea9bbd5be 100644 --- a/res/values/strings_it.arb +++ b/res/values/strings_it.arb @@ -436,6 +436,7 @@ "provider_error" : "${provider} errore", "use_ssl" : "Usa SSL", + "trusted" : "di fiducia", "color_theme" : "Colore tema", "light_theme" : "Bianco", diff --git a/res/values/strings_ja.arb b/res/values/strings_ja.arb index 2b3920862..5ae3a5a1a 100644 --- a/res/values/strings_ja.arb +++ b/res/values/strings_ja.arb @@ -436,6 +436,7 @@ "provider_error" : "${provider} エラー", "use_ssl" : "SSLを使用する", + "trusted" : "信頼できる", "color_theme" : "カラーテーマ", "light_theme" : "光", diff --git a/res/values/strings_ko.arb b/res/values/strings_ko.arb index 85ece0603..f934784ba 100644 --- a/res/values/strings_ko.arb +++ b/res/values/strings_ko.arb @@ -436,6 +436,7 @@ "provider_error" : "${provider} 오류", "use_ssl" : "SSL 사용", + "trusted" : "신뢰할 수 있는", "color_theme" : "색상 테마", "light_theme" : "빛", diff --git a/res/values/strings_nl.arb b/res/values/strings_nl.arb index 15da6fd7b..428da3d76 100644 --- a/res/values/strings_nl.arb +++ b/res/values/strings_nl.arb @@ -436,6 +436,7 @@ "provider_error" : "${provider} fout", "use_ssl" : "Gebruik SSL", + "trusted" : "vertrouwd", "color_theme" : "Kleur thema", "light_theme" : "Licht", diff --git a/res/values/strings_pl.arb b/res/values/strings_pl.arb index 26d8a38d4..fda0ea721 100644 --- a/res/values/strings_pl.arb +++ b/res/values/strings_pl.arb @@ -436,6 +436,7 @@ "provider_error" : "${provider} pomyłka", "use_ssl" : "Użyj SSL", + "trusted" : "zaufany", "color_theme" : "Motyw kolorystyczny", "light_theme" : "Lekki", diff --git a/res/values/strings_pt.arb b/res/values/strings_pt.arb index bfb4a2d0a..6a55cf534 100644 --- a/res/values/strings_pt.arb +++ b/res/values/strings_pt.arb @@ -436,6 +436,7 @@ "provider_error" : "${provider} erro", "use_ssl" : "Use SSL", + "trusted" : "confiável", "color_theme" : "Tema de cor", "light_theme" : "Luz", @@ -544,7 +545,6 @@ "create_account": "Criar conta", "privacy_policy": "Política de privacidade", "welcome_to_cakepay": "Bem-vindo ao Cake Pay!", - "create_account": "Registar-se", "forgot_password": "Esqueci a senha", "reset_password": "Redefinir senha", "gift_cards": "Cartões de presente", diff --git a/res/values/strings_ru.arb b/res/values/strings_ru.arb index 94a5b3c0b..ebc4a615c 100644 --- a/res/values/strings_ru.arb +++ b/res/values/strings_ru.arb @@ -436,6 +436,7 @@ "provider_error" : "${provider} ошибка", "use_ssl" : "Использовать SSL", + "trusted" : "доверенный", "color_theme" : "Цветовая тема", "light_theme" : "Светлая", diff --git a/res/values/strings_uk.arb b/res/values/strings_uk.arb index b139750be..efbd5a3b8 100644 --- a/res/values/strings_uk.arb +++ b/res/values/strings_uk.arb @@ -435,6 +435,7 @@ "provider_error" : "${provider} помилка", "use_ssl" : "Використати SSL", + "trusted" : "довіряють", "color_theme" : "Кольорова тема", "light_theme" : "Світла", diff --git a/res/values/strings_zh.arb b/res/values/strings_zh.arb index 487c6be52..83990cf2e 100644 --- a/res/values/strings_zh.arb +++ b/res/values/strings_zh.arb @@ -435,6 +435,7 @@ "provider_error" : "${provider} 错误", "use_ssl" : "使用SSL", + "trusted" : "值得信赖", "color_theme" : "主题", "light_theme" : "艳丽", From cb9f69074563e0e81199413f54ab9f279dc16033 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Fri, 7 Oct 2022 15:25:20 +0200 Subject: [PATCH 2/4] Add Native setTrustedDaemon and trustedDaemon functions and integrate them with their wallets --- cw_haven/ios/Classes/haven_api.cpp | 10 ++++++++++ cw_haven/lib/api/signatures.dart | 6 +++++- cw_haven/lib/api/types.dart | 6 +++++- cw_haven/lib/api/wallet.dart | 12 ++++++++++++ cw_haven/lib/haven_wallet.dart | 4 ++++ cw_monero/ios/Classes/monero_api.cpp | 10 ++++++++++ cw_monero/ios/Classes/monero_api.h | 3 +++ cw_monero/lib/api/signatures.dart | 6 +++++- cw_monero/lib/api/types.dart | 6 +++++- cw_monero/lib/api/wallet.dart | 14 +++++++++++++- cw_monero/lib/monero_wallet.dart | 4 ++++ .../node_list/node_create_or_edit_view_model.dart | 7 +++++++ 12 files changed, 83 insertions(+), 5 deletions(-) diff --git a/cw_haven/ios/Classes/haven_api.cpp b/cw_haven/ios/Classes/haven_api.cpp index c1013bf87..aecaf0016 100644 --- a/cw_haven/ios/Classes/haven_api.cpp +++ b/cw_haven/ios/Classes/haven_api.cpp @@ -927,6 +927,16 @@ extern "C" return static_cast(rates.size()); } + void set_trusted_daemon(bool arg) + { + m_wallet->setTrustedDaemon(arg); + } + + bool trusted_daemon() + { + return m_wallet->trustedDaemon(); + } + #ifdef __cplusplus } #endif diff --git a/cw_haven/lib/api/signatures.dart b/cw_haven/lib/api/signatures.dart index 9dd1c8dac..c98926c51 100644 --- a/cw_haven/lib/api/signatures.dart +++ b/cw_haven/lib/api/signatures.dart @@ -137,4 +137,8 @@ typedef get_rate = Pointer Function(); typedef size_of_rate = Int32 Function(); -typedef update_rate = Void Function(); \ No newline at end of file +typedef update_rate = Void Function(); + +typedef set_trusted_daemon = Void Function(Int8 trusted); + +typedef trusted_daemon = Int8 Function(); \ No newline at end of file diff --git a/cw_haven/lib/api/types.dart b/cw_haven/lib/api/types.dart index 878297501..81661afc2 100644 --- a/cw_haven/lib/api/types.dart +++ b/cw_haven/lib/api/types.dart @@ -135,4 +135,8 @@ typedef GetRate = Pointer Function(); typedef SizeOfRate = int Function(); -typedef UpdateRate = void Function(); \ No newline at end of file +typedef UpdateRate = void Function(); + +typedef SetTrustedDaemon = void Function(int); + +typedef TrustedDaemon = int Function(); \ No newline at end of file diff --git a/cw_haven/lib/api/wallet.dart b/cw_haven/lib/api/wallet.dart index 3370fd3e0..96e6e80a6 100644 --- a/cw_haven/lib/api/wallet.dart +++ b/cw_haven/lib/api/wallet.dart @@ -116,6 +116,14 @@ final rescanBlockchainAsyncNative = havenApi .lookup>('rescan_blockchain') .asFunction(); +final setTrustedDaemonNative = havenApi + .lookup>('set_trusted_daemon') + .asFunction(); + +final trustedDaemonNative = havenApi + .lookup>('trusted_daemon') + .asFunction(); + int getSyncingHeight() => getSyncingHeightNative(); bool isNeededToRefresh() => isNeededToRefreshNative() != 0; @@ -346,3 +354,7 @@ Future isConnected() => compute(_isConnected, 0); Future getNodeHeight() => compute(_getNodeHeight, 0); void rescanBlockchainAsync() => rescanBlockchainAsyncNative(); + +Future setTrustedDaemon(bool trusted) async => setTrustedDaemonNative(_boolToInt(trusted)); + +Future trustedDaemon() async => trustedDaemonNative() != 0; diff --git a/cw_haven/lib/haven_wallet.dart b/cw_haven/lib/haven_wallet.dart index c107d2f52..4a08a183a 100644 --- a/cw_haven/lib/haven_wallet.dart +++ b/cw_haven/lib/haven_wallet.dart @@ -390,4 +390,8 @@ abstract class HavenWalletBase extends WalletBase haven_wallet.setTrustedDaemon(arg); + + Future trustedDaemon() async => haven_wallet.trustedDaemon(); } diff --git a/cw_monero/ios/Classes/monero_api.cpp b/cw_monero/ios/Classes/monero_api.cpp index 6bb251dcf..117214295 100644 --- a/cw_monero/ios/Classes/monero_api.cpp +++ b/cw_monero/ios/Classes/monero_api.cpp @@ -783,6 +783,16 @@ extern "C" return strdup(get_current_wallet()->getSubaddressLabel(accountIndex, addressIndex).c_str()); } + void set_trusted_daemon(bool arg) + { + m_wallet->setTrustedDaemon(arg); + } + + bool trusted_daemon() + { + return m_wallet->trustedDaemon(); + } + #ifdef __cplusplus } #endif diff --git a/cw_monero/ios/Classes/monero_api.h b/cw_monero/ios/Classes/monero_api.h index 3e2ebcff2..74258ba4c 100644 --- a/cw_monero/ios/Classes/monero_api.h +++ b/cw_monero/ios/Classes/monero_api.h @@ -30,6 +30,9 @@ void set_refresh_from_block_height(uint64_t height); void set_recovering_from_seed(bool is_recovery); void store(char *path); +void set_trusted_daemon(bool arg); +bool trusted_daemon(); + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/cw_monero/lib/api/signatures.dart b/cw_monero/lib/api/signatures.dart index 16f983480..3de4fd1a5 100644 --- a/cw_monero/lib/api/signatures.dart +++ b/cw_monero/lib/api/signatures.dart @@ -125,4 +125,8 @@ typedef rescan_blockchain = Void Function(); typedef get_subaddress_label = Pointer Function( Int32 accountIndex, - Int32 addressIndex); \ No newline at end of file + Int32 addressIndex); + +typedef set_trusted_daemon = Void Function(Int8 trusted); + +typedef trusted_daemon = Int8 Function(); \ No newline at end of file diff --git a/cw_monero/lib/api/types.dart b/cw_monero/lib/api/types.dart index 3438b89fc..e328b776a 100644 --- a/cw_monero/lib/api/types.dart +++ b/cw_monero/lib/api/types.dart @@ -123,4 +123,8 @@ typedef RescanBlockchainAsync = void Function(); typedef GetSubaddressLabel = Pointer Function( int accountIndex, - int addressIndex); \ No newline at end of file + int addressIndex); + +typedef SetTrustedDaemon = void Function(int); + +typedef TrustedDaemon = int Function(); \ No newline at end of file diff --git a/cw_monero/lib/api/wallet.dart b/cw_monero/lib/api/wallet.dart index 9e84d7865..aeda971d8 100644 --- a/cw_monero/lib/api/wallet.dart +++ b/cw_monero/lib/api/wallet.dart @@ -120,6 +120,14 @@ final getSubaddressLabelNative = moneroApi .lookup>('get_subaddress_label') .asFunction(); +final setTrustedDaemonNative = moneroApi + .lookup>('set_trusted_daemon') + .asFunction(); + +final trustedDaemonNative = moneroApi + .lookup>('trusted_daemon') + .asFunction(); + int getSyncingHeight() => getSyncingHeightNative(); bool isNeededToRefresh() => isNeededToRefreshNative() != 0; @@ -353,4 +361,8 @@ void rescanBlockchainAsync() => rescanBlockchainAsyncNative(); String getSubaddressLabel(int accountIndex, int addressIndex) { return convertUTF8ToString(pointer: getSubaddressLabelNative(accountIndex, addressIndex)); -} \ No newline at end of file +} + +Future setTrustedDaemon(bool trusted) async => setTrustedDaemonNative(_boolToInt(trusted)); + +Future trustedDaemon() async => trustedDaemonNative() != 0; \ No newline at end of file diff --git a/cw_monero/lib/monero_wallet.dart b/cw_monero/lib/monero_wallet.dart index 175bd96f5..772df420c 100644 --- a/cw_monero/lib/monero_wallet.dart +++ b/cw_monero/lib/monero_wallet.dart @@ -427,4 +427,8 @@ abstract class MoneroWalletBase extends WalletBase monero_wallet.setTrustedDaemon(arg); + + Future trustedDaemon() async => monero_wallet.trustedDaemon(); } diff --git a/lib/view_model/node_list/node_create_or_edit_view_model.dart b/lib/view_model/node_list/node_create_or_edit_view_model.dart index c14bdda5e..4b7e0ddc9 100644 --- a/lib/view_model/node_list/node_create_or_edit_view_model.dart +++ b/lib/view_model/node_list/node_create_or_edit_view_model.dart @@ -1,4 +1,6 @@ import 'package:cake_wallet/core/execution_state.dart'; +import 'package:cw_haven/haven_wallet.dart'; +import 'package:cw_monero/monero_wallet.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cw_core/wallet_base.dart'; @@ -78,6 +80,11 @@ abstract class NodeCreateOrEditViewModelBase with Store { final node = Node(uri: uri, type: _wallet.type, login: login, password: password, useSSL: useSSL, trusted: trusted); + if (_wallet.type == WalletType.monero) { + (_wallet as MoneroWallet).setTrustedDaemon(trusted); + } else if (_wallet.type == WalletType.haven) { + (_wallet as HavenWallet).setTrustedDaemon(trusted); + } await _nodeSource.add(node); state = ExecutedSuccessfullyState(); } catch (e) { From b0e188c0bd154ca9b95658a74d9369b0274bcc31 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Fri, 7 Oct 2022 20:06:33 +0200 Subject: [PATCH 3/4] Remove unused getter --- cw_core/lib/node.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/cw_core/lib/node.dart b/cw_core/lib/node.dart index dd5969b99..dca429482 100644 --- a/cw_core/lib/node.dart +++ b/cw_core/lib/node.dart @@ -57,8 +57,6 @@ class Node extends HiveObject with Keyable { bool get isSSL => useSSL ?? false; - bool get isTrusted => trusted ?? false; - Uri get uri { switch (type) { case WalletType.monero: From 1eb9e65617e85ef2d70d7c324865c8cde8137565 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Thu, 20 Oct 2022 20:24:01 +0200 Subject: [PATCH 4/4] Set trusted daemon after node connection --- cw_haven/lib/haven_wallet.dart | 6 ++---- cw_monero/lib/monero_wallet.dart | 6 ++---- .../node_list/node_create_or_edit_view_model.dart | 7 ------- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/cw_haven/lib/haven_wallet.dart b/cw_haven/lib/haven_wallet.dart index 00d37ee08..14ff2f88e 100644 --- a/cw_haven/lib/haven_wallet.dart +++ b/cw_haven/lib/haven_wallet.dart @@ -121,6 +121,8 @@ abstract class HavenWalletBase extends WalletBase haven_wallet.setTrustedDaemon(arg); - - Future trustedDaemon() async => haven_wallet.trustedDaemon(); } diff --git a/cw_monero/lib/monero_wallet.dart b/cw_monero/lib/monero_wallet.dart index ff0104015..86a0358f0 100644 --- a/cw_monero/lib/monero_wallet.dart +++ b/cw_monero/lib/monero_wallet.dart @@ -136,6 +136,8 @@ abstract class MoneroWalletBase extends WalletBase monero_wallet.setTrustedDaemon(arg); - - Future trustedDaemon() async => monero_wallet.trustedDaemon(); } diff --git a/lib/view_model/node_list/node_create_or_edit_view_model.dart b/lib/view_model/node_list/node_create_or_edit_view_model.dart index 7b481f356..e24692059 100644 --- a/lib/view_model/node_list/node_create_or_edit_view_model.dart +++ b/lib/view_model/node_list/node_create_or_edit_view_model.dart @@ -1,6 +1,4 @@ import 'package:cake_wallet/core/execution_state.dart'; -import 'package:cw_haven/haven_wallet.dart'; -import 'package:cw_monero/monero_wallet.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cw_core/wallet_base.dart'; @@ -84,11 +82,6 @@ abstract class NodeCreateOrEditViewModelBase with Store { final node = Node(uri: uri, type: _wallet.type, login: login, password: password, useSSL: useSSL, trusted: trusted); - if (_wallet.type == WalletType.monero) { - (_wallet as MoneroWallet).setTrustedDaemon(trusted); - } else if (_wallet.type == WalletType.haven) { - (_wallet as HavenWallet).setTrustedDaemon(trusted); - } await _nodeSource.add(node); state = ExecutedSuccessfullyState(); } catch (e) {