cake_wallet/lib/entities/node_list.dart
Serhii 66301ff247
CW-432-Add-Bitcoin-Cash-BCH (#1041)
* initial commit

* creating and restoring a wallet

* [skip ci] add transaction priority

* fix send and unspent screen

* fix transaction priority type

* replace Unspend with BitcoinUnspent

* add transaction creation

* fix transaction details screen

* minor fix

* fix create side wallet

* basic transaction creation flow

* fix fiat amount calculation

* edit wallet

* minor fix

* fix address book parsing

* merge commit fixes

* minor fixes

* Update gradle.properties

* fix bch unspent coins

* minor fix

* fix BitcoinCashTransactionPriority

* Fetch tags first before switching to one of them

* Update build_haven.sh

* Update build_haven.sh

* Update build_haven.sh

* Update build_haven.sh

* update transaction build function

* Update build_haven.sh

* add ability to rename and delete

* fix address format

* Update pubspec.lock

* Revert "fix address format"

This reverts commit 1549bf4d8c.

* fix address format for exange

* restore from qr

* Update configure.dart

* [skip ci] minor fix

* fix default fee rate

* Update onramper_buy_provider.dart

* Update wallet_address_list_view_model.dart

* PR comments fixes

* Update exchange_view_model.dart

* fix merge conflict

* Update address_validator.dart

* merge fixes

* update initialMigrationVersion

* move cw_bitbox to Cake tech

* PR fixes

* PR fixes

* Fix configure.dart brackets

* update the new version text after macos 

* dummy change to run workflow

* Fix Nano restore from QR issue
Fix Conflicts with main

* PR fixes

* Update app_config.sh 

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2023-10-13 01:50:16 +03:00

162 lines
No EOL
4.6 KiB
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<List<Node>> loadDefaultNodes() async {
final nodesRaw = await rootBundle.loadString('assets/node_list.yml');
final loadedNodes = loadYaml(nodesRaw) as YamlList;
final nodes = <Node>[];
for (final raw in loadedNodes) {
if (raw is Map) {
final node = Node.fromMap(Map<String, Object>.from(raw));
node.type = WalletType.monero;
nodes.add(node);
}
}
return nodes;
}
Future<List<Node>> loadBitcoinElectrumServerList() async {
final serverListRaw = await rootBundle.loadString('assets/bitcoin_electrum_server_list.yml');
final loadedServerList = loadYaml(serverListRaw) as YamlList;
final serverList = <Node>[];
for (final raw in loadedServerList) {
if (raw is Map) {
final node = Node.fromMap(Map<String, Object>.from(raw));
node.type = WalletType.bitcoin;
serverList.add(node);
}
}
return serverList;
}
Future<List<Node>> loadLitecoinElectrumServerList() async {
final serverListRaw = await rootBundle.loadString('assets/litecoin_electrum_server_list.yml');
final loadedServerList = loadYaml(serverListRaw) as YamlList;
final serverList = <Node>[];
for (final raw in loadedServerList) {
if (raw is Map) {
final node = Node.fromMap(Map<String, Object>.from(raw));
node.type = WalletType.litecoin;
serverList.add(node);
}
}
return serverList;
}
Future<List<Node>> loadDefaultHavenNodes() async {
final nodesRaw = await rootBundle.loadString('assets/haven_node_list.yml');
final loadedNodes = loadYaml(nodesRaw) as YamlList;
final nodes = <Node>[];
for (final raw in loadedNodes) {
if (raw is Map) {
final node = Node.fromMap(Map<String, Object>.from(raw));
node.type = WalletType.haven;
nodes.add(node);
}
}
return nodes;
}
Future<List<Node>> loadDefaultEthereumNodes() async {
final nodesRaw = await rootBundle.loadString('assets/ethereum_server_list.yml');
final loadedNodes = loadYaml(nodesRaw) as YamlList;
final nodes = <Node>[];
for (final raw in loadedNodes) {
if (raw is Map) {
final node = Node.fromMap(Map<String, Object>.from(raw));
node.type = WalletType.ethereum;
nodes.add(node);
}
}
return nodes;
}
Future<List<Node>> loadBitcoinCashElectrumServerList() async {
final serverListRaw =
await rootBundle.loadString('assets/bitcoin_cash_electrum_server_list.yml');
final loadedServerList = loadYaml(serverListRaw) as YamlList;
final serverList = <Node>[];
for (final raw in loadedServerList) {
if (raw is Map) {
final node = Node.fromMap(Map<String, Object>.from(raw));
node.type = WalletType.bitcoinCash;
serverList.add(node);
}
}
return serverList;
}
Future<List<Node>> loadDefaultNanoNodes() async {
final nodesRaw = await rootBundle.loadString('assets/nano_node_list.yml');
final loadedNodes = loadYaml(nodesRaw) as YamlList;
final nodes = <Node>[];
for (final raw in loadedNodes) {
if (raw is Map) {
final node = Node.fromMap(Map<String, Object>.from(raw));
node.type = WalletType.nano;
nodes.add(node);
}
}
return nodes;
}
Future<List<Node>> loadDefaultNanoPowNodes() async {
final powNodesRaw = await rootBundle.loadString('assets/nano_pow_node_list.yml');
final loadedPowNodes = loadYaml(powNodesRaw) as YamlList;
final nodes = <Node>[];
for (final raw in loadedPowNodes) {
if (raw is Map) {
final node = Node.fromMap(Map<String, Object>.from(raw));
node.type = WalletType.nano;
nodes.add(node);
}
}
return nodes;
}
Future<void> resetToDefault(Box<Node> nodeSource) async {
final moneroNodes = await loadDefaultNodes();
final bitcoinElectrumServerList = await loadBitcoinElectrumServerList();
final litecoinElectrumServerList = await loadLitecoinElectrumServerList();
final bitcoinCashElectrumServerList = await loadBitcoinCashElectrumServerList();
final havenNodes = await loadDefaultHavenNodes();
final ethereumNodes = await loadDefaultEthereumNodes();
final nanoNodes = await loadDefaultNanoNodes();
final nodes = moneroNodes +
bitcoinElectrumServerList +
litecoinElectrumServerList +
havenNodes +
ethereumNodes +
bitcoinCashElectrumServerList +
nanoNodes;
await nodeSource.clear();
await nodeSource.addAll(nodes);
}
Future<void> resetPowToDefault(Box<Node> powNodeSource) async {
final nanoPowNodes = await loadDefaultNanoPowNodes();
final nodes = nanoPowNodes;
await powNodeSource.clear();
await powNodeSource.addAll(nodes);
}