Skip to content

Commit

Permalink
update nano default node (#1408)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
fossephate and OmarHatem28 authored Jul 4, 2024
1 parent 36eacd8 commit 73492ad
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 88 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pr_test_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion assets/nano_node_list.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
-
uri: rpc.nano.to
uri: nano.nownodes.io
useSSL: true
is_default: true
-
uri: rpc.nano.to
useSSL: true
-
uri: node.nautilus.io
path: /api
Expand Down
19 changes: 1 addition & 18 deletions cw_core/lib/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 8 additions & 6 deletions cw_nano/lib/nano_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 {
Expand Down
26 changes: 24 additions & 2 deletions lib/entities/default_settings_migration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -241,6 +241,9 @@ Future<void> defaultSettingsMigration(
case 38:
await fixBtcDerivationPaths(walletInfoSource);
break;
case 39:
await changeDefaultNanoNode(nodes, sharedPreferences);
break;
default:
break;
}
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -1225,4 +1247,4 @@ Future<void> replaceTronDefaultNode({

// If it's not, we switch user to the new default node: NowNodes
await changeTronCurrentNodeToDefault(sharedPreferences: sharedPreferences, nodes: nodes);
}
}
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ Future<void> initializeAppConfigs() async {
transactionDescriptions: transactionDescriptions,
secureStorage: secureStorage,
anonpayInvoiceInfo: anonpayInvoiceInfo,
initialMigrationVersion: 38,
initialMigrationVersion: 39,
);
}

Expand Down
91 changes: 31 additions & 60 deletions tool/generate_secrets_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,32 @@ 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';
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('=');
Expand All @@ -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);
Expand All @@ -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();

// 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(baseConfigFile, SecretKey.base, existingSecrets: secrets);

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);
}
3 changes: 3 additions & 0 deletions tool/utils/secret_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class SecretKey {
SecretKey('authorization', () => ''),
];

static final coreSecrets = [];

static final evmChainsSecrets = [
SecretKey('etherScanApiKey', () => ''),
SecretKey('polygonScanApiKey', () => ''),
Expand All @@ -57,6 +59,7 @@ class SecretKey {

static final nanoSecrets = [
SecretKey('nano2ApiKey', () => ''),
SecretKey('nanoNowNodesApiKey', () => ''),
];

static final tronSecrets = [
Expand Down

0 comments on commit 73492ad

Please sign in to comment.