2023-09-18 21:28:31 +00:00
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
import 'package:stackwallet/wallets/crypto_currency/bip39_currency.dart';
|
|
|
|
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
|
2023-09-18 21:56:57 +00:00
|
|
|
import 'package:stackwallet/wallets/example/libepiccash.dart';
|
2023-09-18 21:28:31 +00:00
|
|
|
|
|
|
|
class Epiccash extends Bip39Currency {
|
|
|
|
Epiccash(super.network) {
|
|
|
|
switch (network) {
|
|
|
|
case CryptoCurrencyNetwork.main:
|
|
|
|
coin = Coin.epicCash;
|
|
|
|
default:
|
|
|
|
throw Exception("Unsupported network: $network");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
// change this to change the number of confirms a tx needs in order to show as confirmed
|
|
|
|
int get minConfirms => 3;
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool validateAddress(String address) {
|
|
|
|
// Invalid address that contains HTTP and epicbox domain
|
|
|
|
if ((address.startsWith("http://") || address.startsWith("https://")) &&
|
|
|
|
address.contains("@")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (address.startsWith("http://") || address.startsWith("https://")) {
|
|
|
|
if (Uri.tryParse(address) != null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-18 21:56:57 +00:00
|
|
|
return LibEpiccash.validateSendAddress(address: address);
|
2023-09-18 21:28:31 +00:00
|
|
|
}
|
2023-09-20 14:12:48 +00:00
|
|
|
|
|
|
|
String getMnemonic() {
|
|
|
|
return LibEpiccash.getMnemonic();
|
|
|
|
}
|
|
|
|
|
2023-09-27 15:53:10 +00:00
|
|
|
Future<String?> createNewWallet(
|
2023-09-26 23:26:28 +00:00
|
|
|
({
|
|
|
|
String config,
|
|
|
|
String mnemonic,
|
|
|
|
String password,
|
|
|
|
String name,
|
|
|
|
})? data) async {
|
2023-09-27 15:53:10 +00:00
|
|
|
String result = await LibEpiccash.initializeNewWallet(
|
2023-09-20 14:12:48 +00:00
|
|
|
config: data!.config,
|
|
|
|
mnemonic: data.mnemonic,
|
|
|
|
password: data.password,
|
|
|
|
name: data.name);
|
2023-09-27 15:53:10 +00:00
|
|
|
|
2023-09-27 22:47:26 +00:00
|
|
|
if (result.isNotEmpty) {
|
2023-09-27 15:53:10 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-09-27 22:47:26 +00:00
|
|
|
Future<({double awaitingFinalization, double pending, double spendable, double total})>
|
|
|
|
getWalletInfo(
|
|
|
|
({
|
|
|
|
String wallet,
|
|
|
|
int refreshFromNode,
|
|
|
|
})? data) async {
|
|
|
|
var result = await LibEpiccash.getWalletBalances(
|
|
|
|
wallet: data!.wallet,
|
|
|
|
refreshFromNode: data.refreshFromNode,
|
|
|
|
minimumConfirmations: minConfirms);
|
2023-09-27 15:53:10 +00:00
|
|
|
return result;
|
2023-09-20 14:12:48 +00:00
|
|
|
}
|
2023-09-26 23:26:28 +00:00
|
|
|
|
2023-09-27 22:47:26 +00:00
|
|
|
Future<String?> scanOutputs(
|
2023-09-26 23:26:28 +00:00
|
|
|
({String wallet, int startHeight, int numberOfBlocks})? data) async {
|
2023-09-27 22:47:26 +00:00
|
|
|
var result = await LibEpiccash.scanOutputs(
|
2023-09-26 23:26:28 +00:00
|
|
|
wallet: data!.wallet,
|
|
|
|
startHeight: data.startHeight,
|
|
|
|
numberOfBlocks: data.numberOfBlocks,
|
|
|
|
);
|
2023-09-27 22:47:26 +00:00
|
|
|
|
|
|
|
if (result.isNotEmpty) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return null;
|
2023-09-26 23:26:28 +00:00
|
|
|
}
|
|
|
|
|
2023-09-27 22:47:26 +00:00
|
|
|
Future<String?> createTransaction(
|
2023-09-26 23:26:28 +00:00
|
|
|
({
|
|
|
|
String wallet,
|
|
|
|
int amount,
|
|
|
|
String address,
|
|
|
|
int secretKey,
|
|
|
|
String epicboxConfig,
|
|
|
|
String note,
|
|
|
|
})? data) async {
|
2023-09-27 22:47:26 +00:00
|
|
|
var result = await LibEpiccash.createTransaction(
|
|
|
|
wallet: data!.wallet,
|
|
|
|
amount: data.amount,
|
|
|
|
address: data.address,
|
|
|
|
secretKey: data.secretKey,
|
|
|
|
epicboxConfig: data.epicboxConfig,
|
|
|
|
minimumConfirmations: minConfirms,
|
|
|
|
note: data.note,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (result.isNotEmpty) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return null;
|
2023-09-26 23:26:28 +00:00
|
|
|
}
|
|
|
|
|
2023-09-27 22:47:26 +00:00
|
|
|
Future<String?> getTransaction(
|
2023-09-26 23:26:28 +00:00
|
|
|
({
|
|
|
|
String wallet,
|
|
|
|
int refreshFromNode,
|
|
|
|
})? data) async {
|
2023-09-27 22:47:26 +00:00
|
|
|
var result = await LibEpiccash.getTransaction(
|
2023-09-26 23:26:28 +00:00
|
|
|
wallet: data!.wallet,
|
|
|
|
refreshFromNode: data.refreshFromNode,
|
|
|
|
);
|
2023-09-27 22:47:26 +00:00
|
|
|
|
|
|
|
if (result.isNotEmpty) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return null;
|
2023-09-26 23:26:28 +00:00
|
|
|
}
|
|
|
|
|
2023-09-27 22:47:26 +00:00
|
|
|
Future<String?> cancelTransaction(
|
2023-09-26 23:26:28 +00:00
|
|
|
({
|
|
|
|
String wallet,
|
|
|
|
String transactionId,
|
|
|
|
})? data) async {
|
2023-09-27 22:47:26 +00:00
|
|
|
var result = await LibEpiccash.cancelTransaction(
|
2023-09-26 23:26:28 +00:00
|
|
|
wallet: data!.wallet,
|
|
|
|
transactionId: data.transactionId,
|
|
|
|
);
|
2023-09-27 22:47:26 +00:00
|
|
|
|
|
|
|
if (result.isNotEmpty) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return null;
|
2023-09-26 23:26:28 +00:00
|
|
|
}
|
|
|
|
|
2023-09-27 22:47:26 +00:00
|
|
|
Future<String?> getAddressInfo(
|
2023-09-26 23:26:28 +00:00
|
|
|
({
|
|
|
|
String wallet,
|
|
|
|
int index,
|
|
|
|
String epicboxConfig,
|
|
|
|
})? data) async {
|
2023-09-27 22:47:26 +00:00
|
|
|
var result = await LibEpiccash.getAddressInfo(
|
2023-09-26 23:26:28 +00:00
|
|
|
wallet: data!.wallet,
|
|
|
|
index: data.index,
|
|
|
|
epicboxConfig: data.epicboxConfig,
|
|
|
|
);
|
2023-09-27 22:47:26 +00:00
|
|
|
|
|
|
|
if (result.isNotEmpty) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<String?> transactionFees(
|
|
|
|
({
|
|
|
|
String wallet,
|
|
|
|
int amount,
|
|
|
|
int minimumConfirmations,
|
|
|
|
})? data,
|
|
|
|
) async {
|
|
|
|
var result = await LibEpiccash.getTransactionFees(
|
|
|
|
wallet: data!.wallet,
|
|
|
|
amount: data.amount,
|
|
|
|
minimumConfirmations: data.minimumConfirmations,
|
|
|
|
);
|
|
|
|
if (result.isNotEmpty) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<String?> deleteWallet(
|
|
|
|
({
|
|
|
|
String wallet,
|
|
|
|
String config,
|
|
|
|
})? data,
|
|
|
|
) async {
|
|
|
|
var result = await LibEpiccash.deleteWallet(
|
|
|
|
wallet: data!.wallet,
|
|
|
|
config: data.config,
|
|
|
|
);
|
|
|
|
if (result.isNotEmpty) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<String?> openWallet(
|
|
|
|
({
|
|
|
|
String config,
|
|
|
|
String password,
|
|
|
|
})? data,
|
|
|
|
) async {
|
|
|
|
var result = await LibEpiccash.openWallet(
|
|
|
|
config: data!.config,
|
|
|
|
password: data.password,
|
|
|
|
);
|
|
|
|
if (result.isNotEmpty) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<String?> txHttpSend(
|
|
|
|
({
|
|
|
|
String wallet,
|
|
|
|
int selectionStrategyIsAll,
|
|
|
|
int minimumConfirmations,
|
|
|
|
String message,
|
|
|
|
int amount,
|
|
|
|
String address,
|
|
|
|
})? data,
|
|
|
|
) async {
|
|
|
|
var result = await LibEpiccash.txHttpSend(
|
|
|
|
wallet: data!.wallet,
|
|
|
|
selectionStrategyIsAll: data.selectionStrategyIsAll,
|
|
|
|
minimumConfirmations: data.minimumConfirmations,
|
|
|
|
message: data.message,
|
|
|
|
amount: data.amount,
|
|
|
|
address: data.address,
|
|
|
|
);
|
|
|
|
if (result.isNotEmpty) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return null;
|
2023-09-26 23:26:28 +00:00
|
|
|
}
|
2023-09-18 21:28:31 +00:00
|
|
|
}
|