2022-08-26 08:11:35 +00:00
|
|
|
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';
|
2022-09-26 20:32:53 +00:00
|
|
|
import 'package:stackwallet/services/coins/bitcoincash/bitcoincash_wallet.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
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';
|
2022-09-23 21:02:53 +00:00
|
|
|
import 'package:stackwallet/services/coins/namecoin/namecoin_wallet.dart';
|
2022-11-29 19:11:30 +00:00
|
|
|
import 'package:stackwallet/services/coins/particl/particl_wallet.dart';
|
2022-11-07 16:24:08 +00:00
|
|
|
import 'package:stackwallet/services/coins/wownero/wownero_wallet.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
2022-11-09 22:43:26 +00:00
|
|
|
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/utilities/prefs.dart';
|
|
|
|
|
2022-10-28 18:03:52 +00:00
|
|
|
import 'litecoin/litecoin_wallet.dart';
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
abstract class CoinServiceAPI {
|
|
|
|
CoinServiceAPI();
|
|
|
|
|
|
|
|
factory CoinServiceAPI.from(
|
|
|
|
Coin coin,
|
|
|
|
String walletId,
|
|
|
|
String walletName,
|
2022-11-09 23:48:43 +00:00
|
|
|
SecureStorageInterface secureStorageInterface,
|
2022-08-26 08:11:35 +00:00
|
|
|
NodeModel node,
|
|
|
|
TransactionNotificationTracker tracker,
|
|
|
|
Prefs prefs,
|
|
|
|
List<NodeModel> 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,
|
2022-11-09 22:43:26 +00:00
|
|
|
secureStore: secureStorageInterface,
|
2022-08-26 08:11:35 +00:00
|
|
|
client: client,
|
|
|
|
cachedClient: cachedClient,
|
|
|
|
tracker: tracker,
|
|
|
|
);
|
|
|
|
case Coin.firoTestNet:
|
|
|
|
return FiroWallet(
|
|
|
|
walletId: walletId,
|
|
|
|
walletName: walletName,
|
|
|
|
coin: coin,
|
2022-11-09 22:43:26 +00:00
|
|
|
secureStore: secureStorageInterface,
|
2022-08-26 08:11:35 +00:00
|
|
|
client: client,
|
|
|
|
cachedClient: cachedClient,
|
|
|
|
tracker: tracker,
|
|
|
|
);
|
|
|
|
|
|
|
|
case Coin.bitcoin:
|
|
|
|
return BitcoinWallet(
|
|
|
|
walletId: walletId,
|
|
|
|
walletName: walletName,
|
|
|
|
coin: coin,
|
2022-11-09 22:43:26 +00:00
|
|
|
secureStore: secureStorageInterface,
|
2022-08-26 08:11:35 +00:00
|
|
|
client: client,
|
|
|
|
cachedClient: cachedClient,
|
2022-10-28 18:03:52 +00:00
|
|
|
tracker: tracker,
|
|
|
|
);
|
|
|
|
|
|
|
|
case Coin.litecoin:
|
|
|
|
return LitecoinWallet(
|
|
|
|
walletId: walletId,
|
|
|
|
walletName: walletName,
|
|
|
|
coin: coin,
|
2022-11-09 22:43:26 +00:00
|
|
|
secureStore: secureStorageInterface,
|
2022-10-28 18:03:52 +00:00
|
|
|
client: client,
|
|
|
|
cachedClient: cachedClient,
|
|
|
|
tracker: tracker,
|
|
|
|
);
|
|
|
|
|
|
|
|
case Coin.litecoinTestNet:
|
|
|
|
return LitecoinWallet(
|
|
|
|
walletId: walletId,
|
|
|
|
walletName: walletName,
|
|
|
|
coin: coin,
|
2022-11-09 22:43:26 +00:00
|
|
|
secureStore: secureStorageInterface,
|
2022-10-28 18:03:52 +00:00
|
|
|
client: client,
|
|
|
|
cachedClient: cachedClient,
|
2022-08-26 08:11:35 +00:00
|
|
|
tracker: tracker,
|
|
|
|
);
|
|
|
|
|
|
|
|
case Coin.bitcoinTestNet:
|
|
|
|
return BitcoinWallet(
|
|
|
|
walletId: walletId,
|
|
|
|
walletName: walletName,
|
|
|
|
coin: coin,
|
2022-11-09 22:43:26 +00:00
|
|
|
secureStore: secureStorageInterface,
|
2022-08-26 08:11:35 +00:00
|
|
|
client: client,
|
|
|
|
cachedClient: cachedClient,
|
|
|
|
tracker: tracker,
|
|
|
|
);
|
|
|
|
|
2022-09-26 20:32:53 +00:00
|
|
|
case Coin.bitcoincash:
|
|
|
|
return BitcoinCashWallet(
|
|
|
|
walletId: walletId,
|
|
|
|
walletName: walletName,
|
|
|
|
coin: coin,
|
2022-11-09 22:43:26 +00:00
|
|
|
secureStore: secureStorageInterface,
|
2022-09-26 20:32:53 +00:00
|
|
|
client: client,
|
|
|
|
cachedClient: cachedClient,
|
|
|
|
tracker: tracker,
|
|
|
|
);
|
|
|
|
|
|
|
|
case Coin.bitcoincashTestnet:
|
|
|
|
return BitcoinCashWallet(
|
|
|
|
walletId: walletId,
|
|
|
|
walletName: walletName,
|
|
|
|
coin: coin,
|
2022-11-09 22:43:26 +00:00
|
|
|
secureStore: secureStorageInterface,
|
2022-09-26 20:32:53 +00:00
|
|
|
client: client,
|
|
|
|
cachedClient: cachedClient,
|
|
|
|
tracker: tracker,
|
|
|
|
);
|
2022-09-16 11:13:30 +00:00
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
case Coin.dogecoin:
|
|
|
|
return DogecoinWallet(
|
|
|
|
walletId: walletId,
|
|
|
|
walletName: walletName,
|
|
|
|
coin: coin,
|
2022-11-09 22:43:26 +00:00
|
|
|
secureStore: secureStorageInterface,
|
2022-08-26 08:11:35 +00:00
|
|
|
client: client,
|
|
|
|
cachedClient: cachedClient,
|
|
|
|
tracker: tracker,
|
|
|
|
);
|
|
|
|
|
|
|
|
case Coin.epicCash:
|
|
|
|
return EpicCashWallet(
|
|
|
|
walletId: walletId,
|
|
|
|
walletName: walletName,
|
|
|
|
coin: coin,
|
2022-11-09 22:43:26 +00:00
|
|
|
secureStore: secureStorageInterface,
|
2022-08-26 08:11:35 +00:00
|
|
|
// tracker: tracker,
|
|
|
|
);
|
|
|
|
|
|
|
|
case Coin.monero:
|
|
|
|
return MoneroWallet(
|
|
|
|
walletId: walletId,
|
|
|
|
walletName: walletName,
|
|
|
|
coin: coin,
|
2022-11-09 22:43:26 +00:00
|
|
|
secureStore: secureStorageInterface,
|
2022-08-26 08:11:35 +00:00
|
|
|
// tracker: tracker,
|
|
|
|
);
|
|
|
|
|
2022-11-29 19:11:30 +00:00
|
|
|
case Coin.particl:
|
|
|
|
return ParticlWallet(
|
|
|
|
walletId: walletId,
|
|
|
|
walletName: walletName,
|
|
|
|
coin: coin,
|
2022-11-29 19:40:51 +00:00
|
|
|
secureStore: secureStorageInterface,
|
2022-11-29 19:11:30 +00:00
|
|
|
client: client,
|
|
|
|
cachedClient: cachedClient,
|
|
|
|
tracker: tracker);
|
|
|
|
|
2022-09-27 08:09:31 +00:00
|
|
|
case Coin.wownero:
|
|
|
|
return WowneroWallet(
|
|
|
|
walletId: walletId,
|
|
|
|
walletName: walletName,
|
|
|
|
coin: coin,
|
2022-11-09 22:43:26 +00:00
|
|
|
secureStore: secureStorageInterface,
|
2022-09-27 08:09:31 +00:00
|
|
|
// tracker: tracker,
|
|
|
|
);
|
|
|
|
|
2022-09-23 21:02:53 +00:00
|
|
|
case Coin.namecoin:
|
|
|
|
return NamecoinWallet(
|
|
|
|
walletId: walletId,
|
|
|
|
walletName: walletName,
|
|
|
|
coin: coin,
|
2022-11-09 22:43:26 +00:00
|
|
|
secureStore: secureStorageInterface,
|
2022-09-23 21:02:53 +00:00
|
|
|
tracker: tracker,
|
|
|
|
cachedClient: cachedClient,
|
|
|
|
client: client,
|
|
|
|
);
|
2022-09-12 12:01:42 +00:00
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
case Coin.dogecoinTestNet:
|
|
|
|
return DogecoinWallet(
|
|
|
|
walletId: walletId,
|
|
|
|
walletName: walletName,
|
|
|
|
coin: coin,
|
2022-11-09 22:43:26 +00:00
|
|
|
secureStore: secureStorageInterface,
|
2022-08-26 08:11:35 +00:00
|
|
|
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<Map<String, dynamic>> prepareSend({
|
|
|
|
required String address,
|
|
|
|
required int satoshiAmount,
|
|
|
|
Map<String, dynamic>? args,
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<String> confirmSend({required Map<String, dynamic> txData});
|
|
|
|
|
|
|
|
/// create and submit tx to network
|
|
|
|
///
|
|
|
|
/// Returns the txid of the sent tx
|
|
|
|
/// will throw exceptions on failure
|
|
|
|
Future<String> send(
|
|
|
|
{required String toAddress,
|
|
|
|
required int amount,
|
|
|
|
Map<String, String> args});
|
|
|
|
|
|
|
|
Future<FeeObject> get fees;
|
|
|
|
Future<int> get maxFee;
|
|
|
|
|
|
|
|
Future<String> get currentReceivingAddress;
|
|
|
|
// Future<String> get currentLegacyReceivingAddress;
|
|
|
|
|
|
|
|
Future<Decimal> get availableBalance;
|
|
|
|
Future<Decimal> get pendingBalance;
|
|
|
|
Future<Decimal> get totalBalance;
|
|
|
|
Future<Decimal> get balanceMinusMaxFee;
|
|
|
|
|
|
|
|
Future<List<String>> get allOwnAddresses;
|
|
|
|
|
|
|
|
Future<TransactionData> get transactionData;
|
|
|
|
Future<List<UtxoObject>> get unspentOutputs;
|
|
|
|
|
|
|
|
Future<void> refresh();
|
|
|
|
|
|
|
|
Future<void> updateNode(bool shouldRefresh);
|
|
|
|
|
|
|
|
// setter for updating on rename
|
|
|
|
set walletName(String newName);
|
|
|
|
|
|
|
|
String get walletName;
|
|
|
|
String get walletId;
|
|
|
|
|
|
|
|
bool validateAddress(String address);
|
|
|
|
|
|
|
|
Future<List<String>> get mnemonic;
|
|
|
|
|
|
|
|
Future<bool> testNetworkConnection();
|
|
|
|
|
|
|
|
Future<void> recoverFromMnemonic({
|
|
|
|
required String mnemonic,
|
|
|
|
required int maxUnusedAddressGap,
|
|
|
|
required int maxNumberOfIndexesToCheck,
|
|
|
|
required int height,
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<void> initializeNew();
|
|
|
|
Future<void> initializeExisting();
|
|
|
|
|
|
|
|
Future<void> exit();
|
|
|
|
bool get hasCalledExit;
|
|
|
|
|
|
|
|
Future<void> fullRescan(
|
|
|
|
int maxUnusedAddressGap, int maxNumberOfIndexesToCheck);
|
|
|
|
|
|
|
|
void Function(bool isActive)? onIsActiveWalletChanged;
|
|
|
|
|
|
|
|
bool get isConnected;
|
|
|
|
|
|
|
|
Future<int> estimateFeeFor(int satoshiAmount, int feeRate);
|
2022-09-06 01:18:45 +00:00
|
|
|
|
|
|
|
Future<bool> generateNewAddress();
|
2022-11-07 16:24:08 +00:00
|
|
|
|
|
|
|
// used for electrumx coins
|
|
|
|
Future<void> updateSentCachedTxData(Map<String, dynamic> txData);
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|