import 'package:cw_core/pow_node.dart'; import 'package:flutter/services.dart'; import 'package:hive/hive.dart'; import "package:yaml/yaml.dart"; import 'package:cw_core/node.dart'; import 'package:cw_core/wallet_type.dart'; Future> loadDefaultNodes() async { final nodesRaw = await rootBundle.loadString('assets/node_list.yml'); final loadedNodes = loadYaml(nodesRaw) as YamlList; final nodes = []; for (final raw in loadedNodes) { if (raw is Map) { final node = Node.fromMap(Map.from(raw)); node.type = WalletType.monero; nodes.add(node); } } return nodes; } Future> loadBitcoinElectrumServerList() async { final serverListRaw = await rootBundle.loadString('assets/bitcoin_electrum_server_list.yml'); final loadedServerList = loadYaml(serverListRaw) as YamlList; final serverList = []; for (final raw in loadedServerList) { if (raw is Map) { final node = Node.fromMap(Map.from(raw)); node.type = WalletType.bitcoin; serverList.add(node); } } return serverList; } Future> loadLitecoinElectrumServerList() async { final serverListRaw = await rootBundle.loadString('assets/litecoin_electrum_server_list.yml'); final loadedServerList = loadYaml(serverListRaw) as YamlList; final serverList = []; for (final raw in loadedServerList) { if (raw is Map) { final node = Node.fromMap(Map.from(raw)); node.type = WalletType.litecoin; serverList.add(node); } } return serverList; } Future> loadDefaultHavenNodes() async { final nodesRaw = await rootBundle.loadString('assets/haven_node_list.yml'); final loadedNodes = loadYaml(nodesRaw) as YamlList; final nodes = []; for (final raw in loadedNodes) { if (raw is Map) { final node = Node.fromMap(Map.from(raw)); node.type = WalletType.haven; nodes.add(node); } } return nodes; } Future> loadDefaultEthereumNodes() async { final nodesRaw = await rootBundle.loadString('assets/ethereum_server_list.yml'); final loadedNodes = loadYaml(nodesRaw) as YamlList; final nodes = []; for (final raw in loadedNodes) { if (raw is Map) { final node = Node.fromMap(Map.from(raw)); node.type = WalletType.ethereum; nodes.add(node); } } return nodes; } Future> loadDefaultNanoNodes() async { final nodesRaw = await rootBundle.loadString('assets/nano_node_list.yml'); final loadedNodes = loadYaml(nodesRaw) as YamlList; final nodes = []; for (final raw in loadedNodes) { if (raw is Map) { final node = Node.fromMap(Map.from(raw)); node.type = WalletType.nano; nodes.add(node); } } return nodes; } Future> loadDefaultNanoPowNodes() async { final powNodesRaw = await rootBundle.loadString('assets/nano_pow_node_list.yml'); final loadedPowNodes = loadYaml(powNodesRaw) as YamlList; final nodes = []; for (final raw in loadedPowNodes) { if (raw is Map) { final node = PowNode.fromMap(Map.from(raw)); node.type = WalletType.nano; nodes.add(node); } } return nodes; } Future resetToDefault(Box nodeSource) async { final moneroNodes = await loadDefaultNodes(); final bitcoinElectrumServerList = await loadBitcoinElectrumServerList(); final litecoinElectrumServerList = await loadLitecoinElectrumServerList(); final havenNodes = await loadDefaultHavenNodes(); final ethereumNodes = await loadDefaultEthereumNodes(); final nanoNodes = await loadDefaultNanoNodes(); final nodes = moneroNodes + bitcoinElectrumServerList + litecoinElectrumServerList + havenNodes + ethereumNodes + nanoNodes; await nodeSource.clear(); await nodeSource.addAll(nodes); } Future resetPowToDefault(Box powNodeSource) async { final nanoPowNodes = await loadDefaultNanoPowNodes(); final nodes = nanoPowNodes; await powNodeSource.clear(); await powNodeSource.addAll(nodes); }