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 cw_evm/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
echo "const salt = '${{ secrets.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 quantexExchangeMarkup = '${{ secrets.QUANTEX_EXCHANGE_MARKUP }}';" >> 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 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
useSSL: true
is_default: true
-
uri: node.nautilus.io
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/wallet_type.dart';
import 'package:http/io_client.dart' as ioc;
// import 'package:tor/tor.dart';
part 'node.g.dart';
@ -148,7 +149,6 @@ class Node extends HiveObject with Keyable {
return requestMoneroNode();
case WalletType.nano:
case WalletType.banano:
return requestNanoNode();
case WalletType.bitcoin:
case WalletType.litecoin:
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 {
if (!isValidProxyAddress /* && !Tor.instance.enabled*/) {
return false;

View file

@ -10,7 +10,7 @@ import 'package:nanodart/nanodart.dart';
import 'package:cw_core/node.dart';
import 'package:nanoutil/nanoutil.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 {
static const Map<String, String> CAKE_HEADERS = {
@ -54,12 +54,14 @@ class NanoClient {
}
Map<String, String> getHeaders() {
if (_node!.uri == "https://rpc.nano.to") {
return CAKE_HEADERS..addAll({
"key": secrets.nano2ApiKey,
});
final headers = Map<String, String>.from(CAKE_HEADERS);
if (_node!.uri.host == "rpc.nano.to") {
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 {

View file

@ -34,7 +34,7 @@ const havenDefaultNodeUri = 'nodes.havenprotocol.org:443';
const ethereumDefaultNodeUri = 'ethereum.publicnode.com';
const polygonDefaultNodeUri = 'polygon-bor.publicnode.com';
const cakeWalletBitcoinCashDefaultNodeUri = 'bitcoincash.stackwallet.com:50002';
const nanoDefaultNodeUri = 'rpc.nano.to';
const nanoDefaultNodeUri = 'nano.nownodes.io';
const nanoDefaultPowNodeUri = 'rpc.nano.to';
const solanaDefaultNodeUri = 'rpc.ankr.com';
const tronDefaultNodeUri = 'trx.nownodes.io';
@ -241,6 +241,9 @@ Future<void> defaultSettingsMigration(
case 38:
await fixBtcDerivationPaths(walletInfoSource);
break;
case 39:
await changeDefaultNanoNode(nodes, sharedPreferences);
break;
default:
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(
Box<Node> nodeSource, SharedPreferences sharedPreferences) async {
const cakeWalletBitcoinNodeUriPattern = '.cakewallet.com';

View file

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

View file

@ -3,7 +3,8 @@ import 'dart:io';
import 'utils/secret_key.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 solanaConfigPath = 'tool/.solana-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> 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 {
final extraInfo = args.fold(<String, dynamic>{}, (Map<String, dynamic> acc, String arg) {
final parts = arg.split('=');
@ -19,7 +37,8 @@ Future<void> generateSecretsConfig(List<String> args) async {
return acc;
});
final configFile = File(configPath);
final baseConfigFile = File(baseConfigPath);
final coreConfigFile = File(coreConfigPath);
final evmChainsConfigFile = File(evmChainsConfigPath);
final solanaConfigFile = File(solanaConfigPath);
final nanoConfigFile = File(nanoConfigPath);
@ -32,70 +51,22 @@ Future<void> generateSecretsConfig(List<String> args) async {
if (key.contains('--')) {
return true;
}
return false;
});
if (configFile.existsSync()) {
if (baseConfigFile.existsSync()) {
if (extraInfo['--force'] == 1) {
await configFile.delete();
await baseConfigFile.delete();
} else {
return;
}
}
// base:
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();
await writeConfig(baseConfigFile, SecretKey.base, existingSecrets: secrets);
// evm chains:
SecretKey.evmChainsSecrets.forEach((sec) {
if (secrets[sec.name] != null) {
return;
}
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();
await writeConfig(coreConfigFile, SecretKey.coreSecrets);
await writeConfig(evmChainsConfigFile, SecretKey.evmChainsSecrets);
await writeConfig(solanaConfigFile, SecretKey.solanaSecrets);
await writeConfig(nanoConfigFile, SecretKey.nanoSecrets);
await writeConfig(tronConfigFile, SecretKey.tronSecrets);
}

View file

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