Add Native setTrustedDaemon and trustedDaemon functions and integrate them with their wallets
OmarHatem committed
Oct 7, 2022 at 15:25 UTC
cb9f69074563e0e81199413f54ab9f279dc16033
12 files changed
+83
-5
cw_haven/ios/Classes/haven_api.cpp
+10
@@ -927,6 +927,16 @@ extern "C"
927
return static_cast<int32_t>(rates.size());
928
}
929
930
+ void set_trusted_daemon(bool arg)
931
+ {
932
+ m_wallet->setTrustedDaemon(arg);
933
+ }
934
+
935
+ bool trusted_daemon()
936
+ {
937
+ return m_wallet->trustedDaemon();
938
+ }
939
+
940
#ifdef __cplusplus
941
}
942
#endif
cw_haven/lib/api/signatures.dart
+5
-1
@@ -137,4 +137,8 @@ typedef get_rate = Pointer<Int64> Function();
137
138
typedef size_of_rate = Int32 Function();
139
140
-typedef update_rate = Void Function();
\ No newline at end of file
140
+typedef update_rate = Void Function();
141
+
142
+typedef set_trusted_daemon = Void Function(Int8 trusted);
143
+
144
+typedef trusted_daemon = Int8 Function();
\ No newline at end of file
cw_haven/lib/api/types.dart
+5
-1
@@ -135,4 +135,8 @@ typedef GetRate = Pointer<Int64> Function();
135
136
typedef SizeOfRate = int Function();
137
138
-typedef UpdateRate = void Function();
\ No newline at end of file
138
+typedef UpdateRate = void Function();
139
+
140
+typedef SetTrustedDaemon = void Function(int);
141
+
142
+typedef TrustedDaemon = int Function();
\ No newline at end of file
cw_haven/lib/api/wallet.dart
+12
@@ -116,6 +116,14 @@ final rescanBlockchainAsyncNative = havenApi
116
.lookup<NativeFunction<rescan_blockchain>>('rescan_blockchain')
117
.asFunction<RescanBlockchainAsync>();
118
119
+final setTrustedDaemonNative = havenApi
120
+ .lookup<NativeFunction<set_trusted_daemon>>('set_trusted_daemon')
121
+ .asFunction<SetTrustedDaemon>();
122
+
123
+final trustedDaemonNative = havenApi
124
+ .lookup<NativeFunction<trusted_daemon>>('trusted_daemon')
125
+ .asFunction<TrustedDaemon>();
126
+
127
int getSyncingHeight() => getSyncingHeightNative();
128
129
bool isNeededToRefresh() => isNeededToRefreshNative() != 0;
@@ -346,3 +354,7 @@ Future<bool> isConnected() => compute(_isConnected, 0);
354
Future<int> getNodeHeight() => compute(_getNodeHeight, 0);
355
356
void rescanBlockchainAsync() => rescanBlockchainAsyncNative();
357
+
358
+Future setTrustedDaemon(bool trusted) async => setTrustedDaemonNative(_boolToInt(trusted));
359
+
360
+Future<bool> trustedDaemon() async => trustedDaemonNative() != 0;
cw_haven/lib/haven_wallet.dart
+4
@@ -390,4 +390,8 @@ abstract class HavenWalletBase extends WalletBase<MoneroBalance,
390
print(e.toString());
391
}
392
}
393
+
394
+ void setTrustedDaemon(bool arg) => haven_wallet.setTrustedDaemon(arg);
395
+
396
+ Future<bool> trustedDaemon() async => haven_wallet.trustedDaemon();
397
}
cw_monero/ios/Classes/monero_api.cpp
+10
@@ -783,6 +783,16 @@ extern "C"
783
return strdup(get_current_wallet()->getSubaddressLabel(accountIndex, addressIndex).c_str());
784
}
785
786
+ void set_trusted_daemon(bool arg)
787
+ {
788
+ m_wallet->setTrustedDaemon(arg);
789
+ }
790
+
791
+ bool trusted_daemon()
792
+ {
793
+ return m_wallet->trustedDaemon();
794
+ }
795
+
796
#ifdef __cplusplus
797
}
798
#endif
cw_monero/ios/Classes/monero_api.h
+3
@@ -30,6 +30,9 @@ void set_refresh_from_block_height(uint64_t height);
30
void set_recovering_from_seed(bool is_recovery);
31
void store(char *path);
32
33
+void set_trusted_daemon(bool arg);
34
+bool trusted_daemon();
35
+
36
#ifdef __cplusplus
37
}
38
#endif
\ No newline at end of file
cw_monero/lib/api/signatures.dart
+5
-1
@@ -125,4 +125,8 @@ typedef rescan_blockchain = Void Function();
125
126
typedef get_subaddress_label = Pointer<Utf8> Function(
127
Int32 accountIndex,
128
- Int32 addressIndex);
\ No newline at end of file
128
+ Int32 addressIndex);
129
+
130
+typedef set_trusted_daemon = Void Function(Int8 trusted);
131
+
132
+typedef trusted_daemon = Int8 Function();
\ No newline at end of file
cw_monero/lib/api/types.dart
+5
-1
@@ -123,4 +123,8 @@ typedef RescanBlockchainAsync = void Function();
123
124
typedef GetSubaddressLabel = Pointer<Utf8> Function(
125
int accountIndex,
126
- int addressIndex);
\ No newline at end of file
126
+ int addressIndex);
127
+
128
+typedef SetTrustedDaemon = void Function(int);
129
+
130
+typedef TrustedDaemon = int Function();
\ No newline at end of file
cw_monero/lib/api/wallet.dart
+13
-1
@@ -120,6 +120,14 @@ final getSubaddressLabelNative = moneroApi
120
.lookup<NativeFunction<get_subaddress_label>>('get_subaddress_label')
121
.asFunction<GetSubaddressLabel>();
122
123
+final setTrustedDaemonNative = moneroApi
124
+ .lookup<NativeFunction<set_trusted_daemon>>('set_trusted_daemon')
125
+ .asFunction<SetTrustedDaemon>();
126
+
127
+final trustedDaemonNative = moneroApi
128
+ .lookup<NativeFunction<trusted_daemon>>('trusted_daemon')
129
+ .asFunction<TrustedDaemon>();
130
+
131
int getSyncingHeight() => getSyncingHeightNative();
132
133
bool isNeededToRefresh() => isNeededToRefreshNative() != 0;
@@ -353,4 +361,8 @@ void rescanBlockchainAsync() => rescanBlockchainAsyncNative();
361
362
String getSubaddressLabel(int accountIndex, int addressIndex) {
363
return convertUTF8ToString(pointer: getSubaddressLabelNative(accountIndex, addressIndex));
356
-}
\ No newline at end of file
364
+}
365
+
366
+Future setTrustedDaemon(bool trusted) async => setTrustedDaemonNative(_boolToInt(trusted));
367
+
368
+Future<bool> trustedDaemon() async => trustedDaemonNative() != 0;
\ No newline at end of file
cw_monero/lib/monero_wallet.dart
+4
@@ -427,4 +427,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
427
print(e.toString());
428
}
429
}
430
+
431
+ void setTrustedDaemon(bool arg) => monero_wallet.setTrustedDaemon(arg);
432
+
433
+ Future<bool> trustedDaemon() async => monero_wallet.trustedDaemon();
434
}
lib/view_model/node_list/node_create_or_edit_view_model.dart
+7
@@ -1,4 +1,6 @@
1
import 'package:cake_wallet/core/execution_state.dart';
2
+import 'package:cw_haven/haven_wallet.dart';
3
+import 'package:cw_monero/monero_wallet.dart';
4
import 'package:hive/hive.dart';
5
import 'package:mobx/mobx.dart';
6
import 'package:cw_core/wallet_base.dart';
@@ -78,6 +80,11 @@ abstract class NodeCreateOrEditViewModelBase with Store {
80
final node =
81
Node(uri: uri, type: _wallet.type, login: login, password: password,
82
useSSL: useSSL, trusted: trusted);
83
+ if (_wallet.type == WalletType.monero) {
84
+ (_wallet as MoneroWallet).setTrustedDaemon(trusted);
85
+ } else if (_wallet.type == WalletType.haven) {
86
+ (_wallet as HavenWallet).setTrustedDaemon(trusted);
87
+ }
88
await _nodeSource.add(node);
89
state = ExecutedSuccessfullyState();
90
} catch (e) {