mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 11:39:22 +00:00
Merge pull request #529 from cake-tech/CW-182-allow-trusted-nodes
Cw 182 allow trusted nodes
This commit is contained in:
commit
dc60123f79
29 changed files with 123 additions and 17 deletions
|
@ -17,6 +17,7 @@ class Node extends HiveObject with Keyable {
|
|||
{this.login,
|
||||
this.password,
|
||||
this.useSSL,
|
||||
this.trusted = false,
|
||||
String? uri,
|
||||
WalletType? type,}) {
|
||||
if (uri != null) {
|
||||
|
@ -31,7 +32,8 @@ class Node extends HiveObject with Keyable {
|
|||
: uriRaw = map['uri'] as String? ?? '',
|
||||
login = map['login'] as String?,
|
||||
password = map['password'] as String?,
|
||||
useSSL = map['useSSL'] as bool?;
|
||||
useSSL = map['useSSL'] as bool?,
|
||||
trusted = map['trusted'] as bool? ?? false;
|
||||
|
||||
static const typeId = 1;
|
||||
static const boxName = 'Nodes';
|
||||
|
@ -51,6 +53,9 @@ class Node extends HiveObject with Keyable {
|
|||
@HiveField(4)
|
||||
bool? useSSL;
|
||||
|
||||
@HiveField(5)
|
||||
bool trusted;
|
||||
|
||||
bool get isSSL => useSSL ?? false;
|
||||
|
||||
Uri get uri {
|
||||
|
@ -104,28 +109,28 @@ class Node extends HiveObject with Keyable {
|
|||
final rpcUri = isSSL ? Uri.https(uri.authority, path) : Uri.http(uri.authority, path);
|
||||
final realm = 'monero-rpc';
|
||||
final body = {
|
||||
'jsonrpc': '2.0',
|
||||
'id': '0',
|
||||
'jsonrpc': '2.0',
|
||||
'id': '0',
|
||||
'method': 'get_info'
|
||||
};
|
||||
|
||||
try {
|
||||
final authenticatingClient = HttpClient();
|
||||
|
||||
|
||||
authenticatingClient.addCredentials(
|
||||
rpcUri,
|
||||
realm,
|
||||
realm,
|
||||
HttpClientDigestCredentials(login ?? '', password ?? ''),
|
||||
);
|
||||
|
||||
|
||||
final http.Client client = ioc.IOClient(authenticatingClient);
|
||||
|
||||
|
||||
final response = await client.post(
|
||||
rpcUri,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: json.encode(body),
|
||||
);
|
||||
|
||||
|
||||
client.close();
|
||||
|
||||
final resBody = json.decode(response.body) as Map<String, dynamic>;
|
||||
|
|
|
@ -927,6 +927,16 @@ extern "C"
|
|||
return static_cast<int32_t>(rates.size());
|
||||
}
|
||||
|
||||
void set_trusted_daemon(bool arg)
|
||||
{
|
||||
m_wallet->setTrustedDaemon(arg);
|
||||
}
|
||||
|
||||
bool trusted_daemon()
|
||||
{
|
||||
return m_wallet->trustedDaemon();
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -137,4 +137,8 @@ typedef get_rate = Pointer<Int64> Function();
|
|||
|
||||
typedef size_of_rate = Int32 Function();
|
||||
|
||||
typedef update_rate = Void Function();
|
||||
typedef update_rate = Void Function();
|
||||
|
||||
typedef set_trusted_daemon = Void Function(Int8 trusted);
|
||||
|
||||
typedef trusted_daemon = Int8 Function();
|
|
@ -135,4 +135,8 @@ typedef GetRate = Pointer<Int64> Function();
|
|||
|
||||
typedef SizeOfRate = int Function();
|
||||
|
||||
typedef UpdateRate = void Function();
|
||||
typedef UpdateRate = void Function();
|
||||
|
||||
typedef SetTrustedDaemon = void Function(int);
|
||||
|
||||
typedef TrustedDaemon = int Function();
|
|
@ -116,6 +116,14 @@ final rescanBlockchainAsyncNative = havenApi
|
|||
.lookup<NativeFunction<rescan_blockchain>>('rescan_blockchain')
|
||||
.asFunction<RescanBlockchainAsync>();
|
||||
|
||||
final setTrustedDaemonNative = havenApi
|
||||
.lookup<NativeFunction<set_trusted_daemon>>('set_trusted_daemon')
|
||||
.asFunction<SetTrustedDaemon>();
|
||||
|
||||
final trustedDaemonNative = havenApi
|
||||
.lookup<NativeFunction<trusted_daemon>>('trusted_daemon')
|
||||
.asFunction<TrustedDaemon>();
|
||||
|
||||
int getSyncingHeight() => getSyncingHeightNative();
|
||||
|
||||
bool isNeededToRefresh() => isNeededToRefreshNative() != 0;
|
||||
|
@ -351,3 +359,7 @@ Future<bool> isConnected() => compute(_isConnected, 0);
|
|||
Future<int> getNodeHeight() => compute(_getNodeHeight, 0);
|
||||
|
||||
void rescanBlockchainAsync() => rescanBlockchainAsyncNative();
|
||||
|
||||
Future setTrustedDaemon(bool trusted) async => setTrustedDaemonNative(_boolToInt(trusted));
|
||||
|
||||
Future<bool> trustedDaemon() async => trustedDaemonNative() != 0;
|
||||
|
|
|
@ -121,6 +121,8 @@ abstract class HavenWalletBase extends WalletBase<MoneroBalance,
|
|||
password: node.password,
|
||||
useSSL: node.useSSL ?? false,
|
||||
isLightWallet: false); // FIXME: hardcoded value
|
||||
|
||||
haven_wallet.setTrustedDaemon(node.trusted);
|
||||
syncStatus = ConnectedSyncStatus();
|
||||
} catch (e) {
|
||||
syncStatus = FailedSyncStatus();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -125,4 +125,8 @@ typedef rescan_blockchain = Void Function();
|
|||
|
||||
typedef get_subaddress_label = Pointer<Utf8> Function(
|
||||
Int32 accountIndex,
|
||||
Int32 addressIndex);
|
||||
Int32 addressIndex);
|
||||
|
||||
typedef set_trusted_daemon = Void Function(Int8 trusted);
|
||||
|
||||
typedef trusted_daemon = Int8 Function();
|
|
@ -123,4 +123,8 @@ typedef RescanBlockchainAsync = void Function();
|
|||
|
||||
typedef GetSubaddressLabel = Pointer<Utf8> Function(
|
||||
int accountIndex,
|
||||
int addressIndex);
|
||||
int addressIndex);
|
||||
|
||||
typedef SetTrustedDaemon = void Function(int);
|
||||
|
||||
typedef TrustedDaemon = int Function();
|
|
@ -120,6 +120,14 @@ final getSubaddressLabelNative = moneroApi
|
|||
.lookup<NativeFunction<get_subaddress_label>>('get_subaddress_label')
|
||||
.asFunction<GetSubaddressLabel>();
|
||||
|
||||
final setTrustedDaemonNative = moneroApi
|
||||
.lookup<NativeFunction<set_trusted_daemon>>('set_trusted_daemon')
|
||||
.asFunction<SetTrustedDaemon>();
|
||||
|
||||
final trustedDaemonNative = moneroApi
|
||||
.lookup<NativeFunction<trusted_daemon>>('trusted_daemon')
|
||||
.asFunction<TrustedDaemon>();
|
||||
|
||||
int getSyncingHeight() => getSyncingHeightNative();
|
||||
|
||||
bool isNeededToRefresh() => isNeededToRefreshNative() != 0;
|
||||
|
@ -359,4 +367,8 @@ void rescanBlockchainAsync() => rescanBlockchainAsyncNative();
|
|||
|
||||
String getSubaddressLabel(int accountIndex, int addressIndex) {
|
||||
return convertUTF8ToString(pointer: getSubaddressLabelNative(accountIndex, addressIndex));
|
||||
}
|
||||
}
|
||||
|
||||
Future setTrustedDaemon(bool trusted) async => setTrustedDaemonNative(_boolToInt(trusted));
|
||||
|
||||
Future<bool> trustedDaemon() async => trustedDaemonNative() != 0;
|
|
@ -136,6 +136,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
|||
password: node.password,
|
||||
useSSL: node.isSSL,
|
||||
isLightWallet: false); // FIXME: hardcoded value
|
||||
|
||||
monero_wallet.setTrustedDaemon(node.trusted);
|
||||
syncStatus = ConnectedSyncStatus();
|
||||
} catch (e) {
|
||||
syncStatus = FailedSyncStatus();
|
||||
|
|
|
@ -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,
|
||||
))
|
||||
],
|
||||
)),
|
||||
]
|
||||
],
|
||||
)),
|
||||
|
|
|
@ -18,7 +18,8 @@ abstract class NodeCreateOrEditViewModelBase with Store {
|
|||
address = '',
|
||||
port = '',
|
||||
login = '',
|
||||
password = '';
|
||||
password = '',
|
||||
trusted = false;
|
||||
|
||||
@observable
|
||||
ExecutionState state;
|
||||
|
@ -41,6 +42,9 @@ abstract class NodeCreateOrEditViewModelBase with Store {
|
|||
@observable
|
||||
bool useSSL;
|
||||
|
||||
@observable
|
||||
bool trusted;
|
||||
|
||||
@computed
|
||||
bool get isReady =>
|
||||
address.isNotEmpty && port.isNotEmpty;
|
||||
|
@ -68,6 +72,7 @@ abstract class NodeCreateOrEditViewModelBase with Store {
|
|||
login = '';
|
||||
password = '';
|
||||
useSSL = false;
|
||||
trusted = false;
|
||||
}
|
||||
|
||||
@action
|
||||
|
@ -76,7 +81,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) {
|
||||
|
|
|
@ -437,6 +437,7 @@
|
|||
"provider_error" : "${provider}-Fehler",
|
||||
|
||||
"use_ssl" : "SSL verwenden",
|
||||
"trusted" : "Vertrauenswürdige",
|
||||
|
||||
"color_theme" : "Farbthema",
|
||||
"light_theme" : "Hell",
|
||||
|
|
|
@ -437,6 +437,7 @@
|
|||
"provider_error" : "${provider} error",
|
||||
|
||||
"use_ssl" : "Use SSL",
|
||||
"trusted" : "Trusted",
|
||||
|
||||
"color_theme" : "Color theme",
|
||||
"light_theme" : "Light",
|
||||
|
|
|
@ -437,6 +437,7 @@
|
|||
"provider_error" : "${provider} error",
|
||||
|
||||
"use_ssl" : "Utilice SSL",
|
||||
"trusted" : "de confianza",
|
||||
|
||||
"color_theme" : "Tema de color",
|
||||
"light_theme" : "Ligera",
|
||||
|
|
|
@ -435,6 +435,7 @@
|
|||
"provider_error" : "Erreur de ${provider}",
|
||||
|
||||
"use_ssl" : "Utiliser SSL",
|
||||
"trusted" : "de confiance",
|
||||
|
||||
"color_theme" : "Thème",
|
||||
"light_theme" : "Clair",
|
||||
|
|
|
@ -437,6 +437,7 @@
|
|||
"provider_error" : "${provider} त्रुटि",
|
||||
|
||||
"use_ssl" : "उपयोग SSL",
|
||||
"trusted" : "भरोसा",
|
||||
|
||||
"color_theme" : "रंग विषय",
|
||||
"light_theme" : "रोशनी",
|
||||
|
|
|
@ -437,6 +437,7 @@
|
|||
"provider_error" : "${provider} greška",
|
||||
|
||||
"use_ssl" : "Koristi SSL",
|
||||
"trusted" : "vjerovao",
|
||||
|
||||
"color_theme" : "Shema boja",
|
||||
"light_theme" : "Svijetla",
|
||||
|
|
|
@ -437,6 +437,7 @@
|
|||
"provider_error" : "${provider} errore",
|
||||
|
||||
"use_ssl" : "Usa SSL",
|
||||
"trusted" : "di fiducia",
|
||||
|
||||
"color_theme" : "Colore tema",
|
||||
"light_theme" : "Bianco",
|
||||
|
|
|
@ -437,6 +437,7 @@
|
|||
"provider_error" : "${provider} エラー",
|
||||
|
||||
"use_ssl" : "SSLを使用する",
|
||||
"trusted" : "信頼できる",
|
||||
|
||||
"color_theme" : "カラーテーマ",
|
||||
"light_theme" : "光",
|
||||
|
|
|
@ -437,6 +437,7 @@
|
|||
"provider_error" : "${provider} 오류",
|
||||
|
||||
"use_ssl" : "SSL 사용",
|
||||
"trusted" : "신뢰할 수 있는",
|
||||
|
||||
"color_theme" : "색상 테마",
|
||||
"light_theme" : "빛",
|
||||
|
|
|
@ -437,6 +437,7 @@
|
|||
"provider_error" : "${provider} fout",
|
||||
|
||||
"use_ssl" : "Gebruik SSL",
|
||||
"trusted" : "vertrouwd",
|
||||
|
||||
"color_theme" : "Kleur thema",
|
||||
"light_theme" : "Licht",
|
||||
|
|
|
@ -437,6 +437,7 @@
|
|||
"provider_error" : "${provider} pomyłka",
|
||||
|
||||
"use_ssl" : "Użyj SSL",
|
||||
"trusted" : "zaufany",
|
||||
|
||||
"color_theme" : "Motyw kolorystyczny",
|
||||
"light_theme" : "Lekki",
|
||||
|
|
|
@ -437,6 +437,7 @@
|
|||
"provider_error" : "${provider} erro",
|
||||
|
||||
"use_ssl" : "Use SSL",
|
||||
"trusted" : "confiável",
|
||||
|
||||
"color_theme" : "Tema de cor",
|
||||
"light_theme" : "Luz",
|
||||
|
@ -545,7 +546,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",
|
||||
|
|
|
@ -437,6 +437,7 @@
|
|||
"provider_error" : "${provider} ошибка",
|
||||
|
||||
"use_ssl" : "Использовать SSL",
|
||||
"trusted" : "доверенный",
|
||||
|
||||
"color_theme" : "Цветовая тема",
|
||||
"light_theme" : "Светлая",
|
||||
|
|
|
@ -436,6 +436,7 @@
|
|||
"provider_error" : "${provider} помилка",
|
||||
|
||||
"use_ssl" : "Використати SSL",
|
||||
"trusted" : "довіряють",
|
||||
|
||||
"color_theme" : "Кольорова тема",
|
||||
"light_theme" : "Світла",
|
||||
|
|
|
@ -436,6 +436,7 @@
|
|||
"provider_error" : "${provider} 错误",
|
||||
|
||||
"use_ssl" : "使用SSL",
|
||||
"trusted" : "值得信赖",
|
||||
|
||||
"color_theme" : "主题",
|
||||
"light_theme" : "艳丽",
|
||||
|
|
Loading…
Reference in a new issue