update nano default node (#1408)
Some checks failed
Cache Dependencies / test (push) Has been cancelled

* update nano default node

* fix node indicator

* Update pr_test_build.yml

* Update pr_test_build.yml

* update default nano node for new wallets

* support extra args on tool script

* remove nano secrets from node.dart

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
Matthew Fosse 2024-07-04 21:44:08 +02:00 committed by GitHub
parent 36eacd8698
commit 73492ad865
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 75 additions and 88 deletions

View file

@ -121,6 +121,8 @@ jobs:
touch lib/.secrets.g.dart touch lib/.secrets.g.dart
touch cw_evm/lib/.secrets.g.dart touch cw_evm/lib/.secrets.g.dart
touch cw_solana/lib/.secrets.g.dart touch cw_solana/lib/.secrets.g.dart
touch cw_core/lib/.secrets.g.dart
touch cw_nano/lib/.secrets.g.dart
touch cw_tron/lib/.secrets.g.dart touch cw_tron/lib/.secrets.g.dart
echo "const salt = '${{ secrets.SALT }}';" > lib/.secrets.g.dart echo "const salt = '${{ secrets.SALT }}';" > lib/.secrets.g.dart
echo "const keychainSalt = '${{ secrets.KEY_CHAIN_SALT }}';" >> lib/.secrets.g.dart echo "const keychainSalt = '${{ secrets.KEY_CHAIN_SALT }}';" >> lib/.secrets.g.dart
@ -165,6 +167,7 @@ jobs:
echo "const CSRFToken = '${{ secrets.CSRF_TOKEN }}';" >> lib/.secrets.g.dart echo "const CSRFToken = '${{ secrets.CSRF_TOKEN }}';" >> lib/.secrets.g.dart
echo "const quantexExchangeMarkup = '${{ secrets.QUANTEX_EXCHANGE_MARKUP }}';" >> lib/.secrets.g.dart echo "const quantexExchangeMarkup = '${{ secrets.QUANTEX_EXCHANGE_MARKUP }}';" >> lib/.secrets.g.dart
echo "const nano2ApiKey = '${{ secrets.NANO2_API_KEY }}';" >> cw_nano/lib/.secrets.g.dart echo "const nano2ApiKey = '${{ secrets.NANO2_API_KEY }}';" >> cw_nano/lib/.secrets.g.dart
echo "const nanoNowNodesApiKey = '${{ secrets.NANO_NOW_NODES_API_KEY }}';" >> cw_nano/lib/.secrets.g.dart
echo "const tronGridApiKey = '${{ secrets.TRON_GRID_API_KEY }}';" >> cw_tron/lib/.secrets.g.dart echo "const tronGridApiKey = '${{ secrets.TRON_GRID_API_KEY }}';" >> cw_tron/lib/.secrets.g.dart
echo "const tronNowNodesApiKey = '${{ secrets.TRON_NOW_NODES_API_KEY }}';" >> cw_tron/lib/.secrets.g.dart echo "const tronNowNodesApiKey = '${{ secrets.TRON_NOW_NODES_API_KEY }}';" >> cw_tron/lib/.secrets.g.dart

View file

@ -1,7 +1,10 @@
-
uri: nano.nownodes.io
useSSL: true
is_default: true
- -
uri: rpc.nano.to uri: rpc.nano.to
useSSL: true useSSL: true
is_default: true
- -
uri: node.nautilus.io uri: node.nautilus.io
path: /api path: /api

View file

@ -6,6 +6,7 @@ import 'package:hive/hive.dart';
import 'package:cw_core/hive_type_ids.dart'; import 'package:cw_core/hive_type_ids.dart';
import 'package:cw_core/wallet_type.dart'; import 'package:cw_core/wallet_type.dart';
import 'package:http/io_client.dart' as ioc; import 'package:http/io_client.dart' as ioc;
// import 'package:tor/tor.dart'; // import 'package:tor/tor.dart';
part 'node.g.dart'; part 'node.g.dart';
@ -148,7 +149,6 @@ class Node extends HiveObject with Keyable {
return requestMoneroNode(); return requestMoneroNode();
case WalletType.nano: case WalletType.nano:
case WalletType.banano: case WalletType.banano:
return requestNanoNode();
case WalletType.bitcoin: case WalletType.bitcoin:
case WalletType.litecoin: case WalletType.litecoin:
case WalletType.bitcoinCash: case WalletType.bitcoinCash:
@ -203,23 +203,6 @@ class Node extends HiveObject with Keyable {
} }
} }
Future<bool> requestNanoNode() async {
http.Response response = await http.post(
uri,
headers: {'Content-type': 'application/json'},
body: json.encode(
{
"action": "block_count",
},
),
);
if (response.statusCode == 200) {
return true;
} else {
return false;
}
}
Future<bool> requestNodeWithProxy() async { Future<bool> requestNodeWithProxy() async {
if (!isValidProxyAddress /* && !Tor.instance.enabled*/) { if (!isValidProxyAddress /* && !Tor.instance.enabled*/) {
return false; return false;

View file

@ -10,7 +10,7 @@ import 'package:nanodart/nanodart.dart';
import 'package:cw_core/node.dart'; import 'package:cw_core/node.dart';
import 'package:nanoutil/nanoutil.dart'; import 'package:nanoutil/nanoutil.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:cw_nano/.secrets.g.dart' as secrets; import 'package:cw_nano/.secrets.g.dart' as nano_secrets;
class NanoClient { class NanoClient {
static const Map<String, String> CAKE_HEADERS = { static const Map<String, String> CAKE_HEADERS = {
@ -54,12 +54,14 @@ class NanoClient {
} }
Map<String, String> getHeaders() { Map<String, String> getHeaders() {
if (_node!.uri == "https://rpc.nano.to") { final headers = Map<String, String>.from(CAKE_HEADERS);
return CAKE_HEADERS..addAll({ if (_node!.uri.host == "rpc.nano.to") {
"key": secrets.nano2ApiKey, headers["key"] = nano_secrets.nano2ApiKey;
});
} }
return CAKE_HEADERS; if (_node!.uri.host == "nano.nownodes.io") {
headers["api-key"] = nano_secrets.nanoNowNodesApiKey;
}
return headers;
} }
Future<NanoBalance> getBalance(String address) async { Future<NanoBalance> getBalance(String address) async {

View file

@ -34,7 +34,7 @@ const havenDefaultNodeUri = 'nodes.havenprotocol.org:443';
const ethereumDefaultNodeUri = 'ethereum.publicnode.com'; const ethereumDefaultNodeUri = 'ethereum.publicnode.com';
const polygonDefaultNodeUri = 'polygon-bor.publicnode.com'; const polygonDefaultNodeUri = 'polygon-bor.publicnode.com';
const cakeWalletBitcoinCashDefaultNodeUri = 'bitcoincash.stackwallet.com:50002'; const cakeWalletBitcoinCashDefaultNodeUri = 'bitcoincash.stackwallet.com:50002';
const nanoDefaultNodeUri = 'rpc.nano.to'; const nanoDefaultNodeUri = 'nano.nownodes.io';
const nanoDefaultPowNodeUri = 'rpc.nano.to'; const nanoDefaultPowNodeUri = 'rpc.nano.to';
const solanaDefaultNodeUri = 'rpc.ankr.com'; const solanaDefaultNodeUri = 'rpc.ankr.com';
const tronDefaultNodeUri = 'trx.nownodes.io'; const tronDefaultNodeUri = 'trx.nownodes.io';
@ -241,6 +241,9 @@ Future<void> defaultSettingsMigration(
case 38: case 38:
await fixBtcDerivationPaths(walletInfoSource); await fixBtcDerivationPaths(walletInfoSource);
break; break;
case 39:
await changeDefaultNanoNode(nodes, sharedPreferences);
break;
default: default:
break; break;
} }
@ -836,6 +839,25 @@ Future<void> updateBtcNanoWalletInfos(Box<WalletInfo> walletsInfoSource) async {
} }
} }
Future<void> changeDefaultNanoNode(
Box<Node> nodeSource, SharedPreferences sharedPreferences) async {
const oldNanoNodeUriPattern = 'rpc.nano.to';
final currentNanoNodeId = sharedPreferences.getInt(PreferencesKey.currentNodeIdKey);
final currentNanoNode = nodeSource.values.firstWhere((node) => node.key == currentNanoNodeId);
final newCakeWalletNode = Node(
uri: nanoDefaultNodeUri,
type: WalletType.nano,
useSSL: true,
);
await nodeSource.add(newCakeWalletNode);
if (currentNanoNode.uri.toString().contains(oldNanoNodeUriPattern)) {
await sharedPreferences.setInt(PreferencesKey.currentNodeIdKey, newCakeWalletNode.key as int);
}
}
Future<void> changeDefaultBitcoinNode( Future<void> changeDefaultBitcoinNode(
Box<Node> nodeSource, SharedPreferences sharedPreferences) async { Box<Node> nodeSource, SharedPreferences sharedPreferences) async {
const cakeWalletBitcoinNodeUriPattern = '.cakewallet.com'; const cakeWalletBitcoinNodeUriPattern = '.cakewallet.com';

View file

@ -203,7 +203,7 @@ Future<void> initializeAppConfigs() async {
transactionDescriptions: transactionDescriptions, transactionDescriptions: transactionDescriptions,
secureStorage: secureStorage, secureStorage: secureStorage,
anonpayInvoiceInfo: anonpayInvoiceInfo, anonpayInvoiceInfo: anonpayInvoiceInfo,
initialMigrationVersion: 38, initialMigrationVersion: 39,
); );
} }

View file

@ -3,7 +3,8 @@ import 'dart:io';
import 'utils/secret_key.dart'; import 'utils/secret_key.dart';
import 'utils/utils.dart'; import 'utils/utils.dart';
const configPath = 'tool/.secrets-config.json'; const baseConfigPath = 'tool/.secrets-config.json';
const coreConfigPath = 'tool/.core-secrets-config.json';
const evmChainsConfigPath = 'tool/.evm-secrets-config.json'; const evmChainsConfigPath = 'tool/.evm-secrets-config.json';
const solanaConfigPath = 'tool/.solana-secrets-config.json'; const solanaConfigPath = 'tool/.solana-secrets-config.json';
const nanoConfigPath = 'tool/.nano-secrets-config.json'; const nanoConfigPath = 'tool/.nano-secrets-config.json';
@ -11,6 +12,23 @@ const tronConfigPath = 'tool/.tron-secrets-config.json';
Future<void> main(List<String> args) async => generateSecretsConfig(args); Future<void> main(List<String> args) async => generateSecretsConfig(args);
Future<void> writeConfig(
File configFile,
List<SecretKey> newSecrets, {
Map<String, dynamic>? existingSecrets,
}) async {
final secrets = existingSecrets ?? <String, dynamic>{};
newSecrets.forEach((sec) {
if (secrets[sec.name] != null) {
return;
}
secrets[sec.name] = sec.generate();
});
String secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
await configFile.writeAsString(secretsJson);
secrets.clear();
}
Future<void> generateSecretsConfig(List<String> args) async { Future<void> generateSecretsConfig(List<String> args) async {
final extraInfo = args.fold(<String, dynamic>{}, (Map<String, dynamic> acc, String arg) { final extraInfo = args.fold(<String, dynamic>{}, (Map<String, dynamic> acc, String arg) {
final parts = arg.split('='); final parts = arg.split('=');
@ -19,7 +37,8 @@ Future<void> generateSecretsConfig(List<String> args) async {
return acc; return acc;
}); });
final configFile = File(configPath); final baseConfigFile = File(baseConfigPath);
final coreConfigFile = File(coreConfigPath);
final evmChainsConfigFile = File(evmChainsConfigPath); final evmChainsConfigFile = File(evmChainsConfigPath);
final solanaConfigFile = File(solanaConfigPath); final solanaConfigFile = File(solanaConfigPath);
final nanoConfigFile = File(nanoConfigPath); final nanoConfigFile = File(nanoConfigPath);
@ -32,70 +51,22 @@ Future<void> generateSecretsConfig(List<String> args) async {
if (key.contains('--')) { if (key.contains('--')) {
return true; return true;
} }
return false; return false;
}); });
if (configFile.existsSync()) { if (baseConfigFile.existsSync()) {
if (extraInfo['--force'] == 1) { if (extraInfo['--force'] == 1) {
await configFile.delete(); await baseConfigFile.delete();
} else { } else {
return; return;
} }
} }
// base: await writeConfig(baseConfigFile, SecretKey.base, existingSecrets: secrets);
SecretKey.base.forEach((sec) {
if (secrets[sec.name] != null) {
return;
}
secrets[sec.name] = sec.generate();
});
var secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
await configFile.writeAsString(secretsJson);
secrets.clear();
// evm chains: await writeConfig(coreConfigFile, SecretKey.coreSecrets);
SecretKey.evmChainsSecrets.forEach((sec) { await writeConfig(evmChainsConfigFile, SecretKey.evmChainsSecrets);
if (secrets[sec.name] != null) { await writeConfig(solanaConfigFile, SecretKey.solanaSecrets);
return; await writeConfig(nanoConfigFile, SecretKey.nanoSecrets);
} await writeConfig(tronConfigFile, SecretKey.tronSecrets);
secrets[sec.name] = sec.generate();
});
secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
await evmChainsConfigFile.writeAsString(secretsJson);
secrets.clear();
// solana:
SecretKey.solanaSecrets.forEach((sec) {
if (secrets[sec.name] != null) {
return;
}
secrets[sec.name] = sec.generate();
});
secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
await solanaConfigFile.writeAsString(secretsJson);
secrets.clear();
// nano:
SecretKey.nanoSecrets.forEach((sec) {
if (secrets[sec.name] != null) {
return;
}
secrets[sec.name] = sec.generate();
});
secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
await nanoConfigFile.writeAsString(secretsJson);
secrets.clear();
SecretKey.tronSecrets.forEach((sec) {
if (secrets[sec.name] != null) {
return;
}
secrets[sec.name] = sec.generate();
});
secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
await tronConfigFile.writeAsString(secretsJson);
secrets.clear();
} }

View file

@ -45,6 +45,8 @@ class SecretKey {
SecretKey('authorization', () => ''), SecretKey('authorization', () => ''),
]; ];
static final coreSecrets = [];
static final evmChainsSecrets = [ static final evmChainsSecrets = [
SecretKey('etherScanApiKey', () => ''), SecretKey('etherScanApiKey', () => ''),
SecretKey('polygonScanApiKey', () => ''), SecretKey('polygonScanApiKey', () => ''),
@ -57,6 +59,7 @@ class SecretKey {
static final nanoSecrets = [ static final nanoSecrets = [
SecretKey('nano2ApiKey', () => ''), SecretKey('nano2ApiKey', () => ''),
SecretKey('nanoNowNodesApiKey', () => ''),
]; ];
static final tronSecrets = [ static final tronSecrets = [