import 'package:decimal/decimal.dart'; import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart'; import 'package:stackwallet/electrumx_rpc/electrumx.dart'; import 'package:stackwallet/models/models.dart'; import 'package:stackwallet/models/node_model.dart'; import 'package:stackwallet/services/coins/bitcoin/bitcoin_wallet.dart'; import 'package:stackwallet/services/coins/bitcoincash/bitcoincash_wallet.dart'; import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart'; import 'package:stackwallet/services/coins/epiccash/epiccash_wallet.dart'; import 'package:stackwallet/services/coins/firo/firo_wallet.dart'; import 'package:stackwallet/services/coins/monero/monero_wallet.dart'; import 'package:stackwallet/services/coins/namecoin/namecoin_wallet.dart'; import 'package:stackwallet/services/transaction_notification_tracker.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/prefs.dart'; abstract class CoinServiceAPI { CoinServiceAPI(); factory CoinServiceAPI.from( Coin coin, String walletId, String walletName, NodeModel node, TransactionNotificationTracker tracker, Prefs prefs, List failovers, ) { final electrumxNode = ElectrumXNode( address: node.host, port: node.port, name: node.name, id: node.id, useSSL: node.useSSL, ); final client = ElectrumX.from( node: electrumxNode, failovers: failovers .map((e) => ElectrumXNode( address: e.host, port: e.port, name: e.name, id: e.id, useSSL: e.useSSL, )) .toList(), prefs: prefs, ); final cachedClient = CachedElectrumX.from( node: electrumxNode, failovers: failovers .map((e) => ElectrumXNode( address: e.host, port: e.port, name: e.name, id: e.id, useSSL: e.useSSL, )) .toList(), prefs: prefs, ); switch (coin) { case Coin.firo: return FiroWallet( walletId: walletId, walletName: walletName, coin: coin, client: client, cachedClient: cachedClient, tracker: tracker, ); case Coin.firoTestNet: return FiroWallet( walletId: walletId, walletName: walletName, coin: coin, client: client, cachedClient: cachedClient, tracker: tracker, ); case Coin.bitcoin: return BitcoinWallet( walletId: walletId, walletName: walletName, coin: coin, client: client, cachedClient: cachedClient, tracker: tracker, ); case Coin.bitcoinTestNet: return BitcoinWallet( walletId: walletId, walletName: walletName, coin: coin, client: client, cachedClient: cachedClient, tracker: tracker, ); case Coin.bitcoincash: return BitcoinCashWallet( walletId: walletId, walletName: walletName, coin: coin, client: client, cachedClient: cachedClient, tracker: tracker, ); case Coin.bitcoincashTestnet: return BitcoinCashWallet( walletId: walletId, walletName: walletName, coin: coin, client: client, cachedClient: cachedClient, tracker: tracker, ); case Coin.dogecoin: return DogecoinWallet( walletId: walletId, walletName: walletName, coin: coin, client: client, cachedClient: cachedClient, tracker: tracker, ); case Coin.epicCash: return EpicCashWallet( walletId: walletId, walletName: walletName, coin: coin, // tracker: tracker, ); case Coin.monero: return MoneroWallet( walletId: walletId, walletName: walletName, coin: coin, // tracker: tracker, ); case Coin.namecoin: return NamecoinWallet( walletId: walletId, walletName: walletName, coin: coin, tracker: tracker, cachedClient: cachedClient, client: client, ); case Coin.dogecoinTestNet: return DogecoinWallet( walletId: walletId, walletName: walletName, coin: coin, client: client, cachedClient: cachedClient, tracker: tracker, ); } } Coin get coin; bool get isRefreshing; bool get shouldAutoSync; set shouldAutoSync(bool shouldAutoSync); bool get isFavorite; set isFavorite(bool markFavorite); Future> prepareSend({ required String address, required int satoshiAmount, Map? args, }); Future confirmSend({required Map txData}); /// create and submit tx to network /// /// Returns the txid of the sent tx /// will throw exceptions on failure Future send( {required String toAddress, required int amount, Map args}); Future get fees; Future get maxFee; Future get currentReceivingAddress; // Future get currentLegacyReceivingAddress; Future get availableBalance; Future get pendingBalance; Future get totalBalance; Future get balanceMinusMaxFee; Future> get allOwnAddresses; Future get transactionData; Future> get unspentOutputs; Future refresh(); Future updateNode(bool shouldRefresh); // setter for updating on rename set walletName(String newName); String get walletName; String get walletId; bool validateAddress(String address); Future> get mnemonic; Future testNetworkConnection(); Future recoverFromMnemonic({ required String mnemonic, required int maxUnusedAddressGap, required int maxNumberOfIndexesToCheck, required int height, }); Future initializeNew(); Future initializeExisting(); Future exit(); bool get hasCalledExit; Future fullRescan( int maxUnusedAddressGap, int maxNumberOfIndexesToCheck); void Function(bool isActive)? onIsActiveWalletChanged; bool get isConnected; Future estimateFeeFor(int satoshiAmount, int feeRate); Future generateNewAddress(); }