mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
Cw 872 nano enhancements (#1909)
* fix headers on all api calls * fix duplicate nano nodes on fresh install, api key fixes * fix liveness indicators + false positive responses to queries
This commit is contained in:
parent
214fc7113c
commit
831a6d9f9a
3 changed files with 62 additions and 28 deletions
|
@ -54,12 +54,12 @@ class NanoClient {
|
|||
}
|
||||
}
|
||||
|
||||
Map<String, String> getHeaders() {
|
||||
Map<String, String> getHeaders(String host) {
|
||||
final headers = Map<String, String>.from(CAKE_HEADERS);
|
||||
if (_node!.uri.host == "rpc.nano.to") {
|
||||
if (host == "rpc.nano.to") {
|
||||
headers["key"] = nano_secrets.nano2ApiKey;
|
||||
}
|
||||
if (_node!.uri.host == "nano.nownodes.io") {
|
||||
if (host == "nano.nownodes.io") {
|
||||
headers["api-key"] = nano_secrets.nanoNowNodesApiKey;
|
||||
}
|
||||
return headers;
|
||||
|
@ -68,7 +68,7 @@ class NanoClient {
|
|||
Future<NanoBalance> getBalance(String address) async {
|
||||
final response = await http.post(
|
||||
_node!.uri,
|
||||
headers: getHeaders(),
|
||||
headers: getHeaders(_node!.uri.host),
|
||||
body: jsonEncode(
|
||||
{
|
||||
"action": "account_balance",
|
||||
|
@ -95,7 +95,7 @@ class NanoClient {
|
|||
try {
|
||||
final response = await http.post(
|
||||
_node!.uri,
|
||||
headers: getHeaders(),
|
||||
headers: getHeaders(_node!.uri.host),
|
||||
body: jsonEncode(
|
||||
{
|
||||
"action": "account_info",
|
||||
|
@ -116,7 +116,7 @@ class NanoClient {
|
|||
try {
|
||||
final response = await http.post(
|
||||
_node!.uri,
|
||||
headers: CAKE_HEADERS,
|
||||
headers: getHeaders(_node!.uri.host),
|
||||
body: jsonEncode(
|
||||
{
|
||||
"action": "block_info",
|
||||
|
@ -183,7 +183,7 @@ class NanoClient {
|
|||
Future<String> requestWork(String hash) async {
|
||||
final response = await http.post(
|
||||
_powNode!.uri,
|
||||
headers: getHeaders(),
|
||||
headers: getHeaders(_powNode!.uri.host),
|
||||
body: json.encode(
|
||||
{
|
||||
"action": "work_generate",
|
||||
|
@ -226,7 +226,7 @@ class NanoClient {
|
|||
|
||||
final processResponse = await http.post(
|
||||
_node!.uri,
|
||||
headers: getHeaders(),
|
||||
headers: getHeaders(_node!.uri.host),
|
||||
body: processBody,
|
||||
);
|
||||
|
||||
|
@ -425,7 +425,7 @@ class NanoClient {
|
|||
});
|
||||
final processResponse = await http.post(
|
||||
_node!.uri,
|
||||
headers: getHeaders(),
|
||||
headers: getHeaders(_node!.uri.host),
|
||||
body: processBody,
|
||||
);
|
||||
|
||||
|
@ -441,7 +441,7 @@ class NanoClient {
|
|||
required String privateKey,
|
||||
}) async {
|
||||
final receivableResponse = await http.post(_node!.uri,
|
||||
headers: getHeaders(),
|
||||
headers: getHeaders(_node!.uri.host),
|
||||
body: jsonEncode({
|
||||
"action": "receivable",
|
||||
"account": destinationAddress,
|
||||
|
@ -493,7 +493,7 @@ class NanoClient {
|
|||
Future<List<NanoTransactionModel>> fetchTransactions(String address) async {
|
||||
try {
|
||||
final response = await http.post(_node!.uri,
|
||||
headers: getHeaders(),
|
||||
headers: getHeaders(_node!.uri.host),
|
||||
body: jsonEncode({
|
||||
"action": "account_history",
|
||||
"account": address,
|
||||
|
@ -509,15 +509,16 @@ class NanoClient {
|
|||
.map<NanoTransactionModel>((transaction) => NanoTransactionModel.fromJson(transaction))
|
||||
.toList();
|
||||
} catch (e) {
|
||||
printV(e);
|
||||
return [];
|
||||
printV("error fetching transactions: $e");
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<N2Node>> getN2Reps() async {
|
||||
final uri = Uri.parse(N2_REPS_ENDPOINT);
|
||||
final response = await http.post(
|
||||
Uri.parse(N2_REPS_ENDPOINT),
|
||||
headers: CAKE_HEADERS,
|
||||
uri,
|
||||
headers: getHeaders(uri.host),
|
||||
body: jsonEncode({"action": "reps"}),
|
||||
);
|
||||
try {
|
||||
|
@ -531,9 +532,10 @@ class NanoClient {
|
|||
}
|
||||
|
||||
Future<int> getRepScore(String rep) async {
|
||||
final uri = Uri.parse(N2_REPS_ENDPOINT);
|
||||
final response = await http.post(
|
||||
Uri.parse(N2_REPS_ENDPOINT),
|
||||
headers: CAKE_HEADERS,
|
||||
uri,
|
||||
headers: getHeaders(uri.host),
|
||||
body: jsonEncode({
|
||||
"action": "rep_info",
|
||||
"account": rep,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue