fix issues from code review
Godwin Asuquo committed
Feb 3, 2022 at 11:16 UTC
1bc5dd9e468acbe1b73b383d905c94f3c1b9640c
2 files changed
+28
-44
cw_core/lib/digest_auth.dart
deleted
-41
@@ -1,41 +0,0 @@
1
-import 'dart:convert';
2
-import 'dart:io';
3
-
4
-import 'package:http/http.dart' as http;
5
-import 'package:http/io_client.dart' as ioc;
6
-
7
-class DigestAuth{
8
- Future<http.Response>request({
9
- String uri,
10
- String login = "",
11
- String password = "",
12
- }) async {
13
- final path = '/json_rpc';
14
- final rpcUri = Uri.http(uri, path);
15
- final realm = 'monero-rpc';
16
- final postMap = {
17
- 'jsonrpc': '2.0',
18
- 'id': '0',
19
- 'method': 'get_info'
20
- };
21
- final authenticatingClient = HttpClient();
22
-
23
- authenticatingClient.addCredentials(
24
- rpcUri,
25
- realm,
26
- HttpClientDigestCredentials(login ?? "", password ?? ""),
27
- );
28
-
29
- final http.Client client = ioc.IOClient(authenticatingClient);
30
-
31
- final response = await client.post(
32
- rpcUri,
33
- headers: {'Content-Type': 'application/json'},
34
- body: json.encode(postMap),
35
- );
36
-
37
- client.close();
38
-
39
- return response;
40
- }
41
-}
\ No newline at end of file
cw_core/lib/node.dart
+28
-3
@@ -1,12 +1,12 @@
1
import 'dart:io';
2
3
-import 'package:cw_core/digest_auth.dart';
3
import 'package:cw_core/keyable.dart';
4
import 'package:flutter/foundation.dart';
5
import 'dart:convert';
6
import 'package:http/http.dart' as http;
7
import 'package:hive/hive.dart';
8
import 'package:cw_core/wallet_type.dart';
9
+import 'package:http/io_client.dart' as ioc;
10
//import 'package:cake_wallet/entities/digest_request.dart';
11
12
part 'node.g.dart';
@@ -96,9 +96,34 @@ class Node extends HiveObject with Keyable {
96
}
97
98
Future<bool> requestMoneroNode() async {
99
- final digestAuth = DigestAuth();
99
+
100
try {
101
- final response = await digestAuth.request(uri: uri.authority, login: login, password: password);
101
+ final path = '/json_rpc';
102
+ final rpcUri = isSSL ? Uri.https(uri.authority, path) : Uri.http(uri.authority, path);
103
+ final realm = 'monero-rpc';
104
+ final body = {
105
+ 'jsonrpc': '2.0',
106
+ 'id': '0',
107
+ 'method': 'get_info'
108
+ };
109
+ final authenticatingClient = HttpClient();
110
+
111
+ authenticatingClient.addCredentials(
112
+ rpcUri,
113
+ realm,
114
+ HttpClientDigestCredentials(login ?? '', password ?? ''),
115
+ );
116
+
117
+ final http.Client client = ioc.IOClient(authenticatingClient);
118
+
119
+ final response = await client.post(
120
+ rpcUri,
121
+ headers: {'Content-Type': 'application/json'},
122
+ body: json.encode(body),
123
+ );
124
+
125
+ client.close();
126
+
127
final resBody = json.decode(response.body) as Map<String, dynamic>;
128
return !(resBody['result']['offline'] as bool);
129
} catch (_) {