diff --git a/lib/wallets/crypto_currency/coins/epiccash.dart b/lib/wallets/crypto_currency/coins/epiccash.dart index 797179e5e..921fdaaff 100644 --- a/lib/wallets/crypto_currency/coins/epiccash.dart +++ b/lib/wallets/crypto_currency/coins/epiccash.dart @@ -50,35 +50,40 @@ class Epiccash extends Bip39Currency { password: data.password, name: data.name); - if(result.isNotEmpty) { + if (result.isNotEmpty) { return result; } return null; - } - 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); + 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); return result; - } - Future scanOutputs( + Future scanOutputs( ({String wallet, int startHeight, int numberOfBlocks})? data) async { - await LibEpiccash.scanOutputs( + var result = await LibEpiccash.scanOutputs( wallet: data!.wallet, startHeight: data.startHeight, numberOfBlocks: data.numberOfBlocks, ); + + if (result.isNotEmpty) { + return result; + } + return null; } - Future createTransaction( + Future createTransaction( ({ String wallet, int amount, @@ -87,48 +92,143 @@ class Epiccash extends Bip39Currency { String epicboxConfig, String note, })? data) async { - await LibEpiccash.createTransaction( - wallet: data!.wallet, - amount: data.amount, - address: data.address, - secretKey: data.secretKey, - epicboxConfig: data.epicboxConfig, - minimumConfirmations: minConfirms, - note: data.note); + 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; } - Future getTransaction( + Future getTransaction( ({ String wallet, int refreshFromNode, })? data) async { - await LibEpiccash.getTransaction( + var result = await LibEpiccash.getTransaction( wallet: data!.wallet, refreshFromNode: data.refreshFromNode, ); + + if (result.isNotEmpty) { + return result; + } + return null; } - Future cancelTransaction( + Future cancelTransaction( ({ String wallet, String transactionId, })? data) async { - await LibEpiccash.cancelTransaction( + var result = await LibEpiccash.cancelTransaction( wallet: data!.wallet, transactionId: data.transactionId, ); + + if (result.isNotEmpty) { + return result; + } + return null; } - Future getAddressInfo( + Future getAddressInfo( ({ String wallet, int index, String epicboxConfig, })? data) async { - await LibEpiccash.getAddressInfo( + var result = await LibEpiccash.getAddressInfo( wallet: data!.wallet, index: data.index, epicboxConfig: data.epicboxConfig, ); + + if (result.isNotEmpty) { + return result; + } + return null; + } + + static Future 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 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 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 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; } } diff --git a/lib/wallets/example/libepiccash.dart b/lib/wallets/example/libepiccash.dart index acf48c3dd..74fb278f3 100644 --- a/lib/wallets/example/libepiccash.dart +++ b/lib/wallets/example/libepiccash.dart @@ -103,10 +103,17 @@ abstract class LibEpiccash { /// /// Get balance information for the currently open wallet /// - static Future<({double awaitingFinalization, double pending, double spendable, double total})> getWalletBalances( - {required String wallet, - required int refreshFromNode, - required int minimumConfirmations}) async { + static Future< + ({ + double awaitingFinalization, + double pending, + double spendable, + double total + })> + getWalletBalances( + {required String wallet, + required int refreshFromNode, + required int minimumConfirmations}) async { try { String balances = await compute(_walletBalancesWrapper, ( wallet: wallet, @@ -121,12 +128,15 @@ abstract class LibEpiccash { var jsonBalances = json.decode(balances); //Return balances as record ({ - double spendable, double pending, double total, double awaitingFinalization + double spendable, + double pending, + double total, + double awaitingFinalization }) balancesRecord = ( - spendable: jsonBalances['amount_currently_spendable'], - pending: jsonBalances['amount_awaiting_finalization'], - total: jsonBalances['total'], - awaitingFinalization: jsonBalances['amount_awaiting_finalization'], + spendable: jsonBalances['amount_currently_spendable'], + pending: jsonBalances['amount_awaiting_finalization'], + total: jsonBalances['total'], + awaitingFinalization: jsonBalances['amount_awaiting_finalization'], ); return balancesRecord; } catch (e) { @@ -150,13 +160,13 @@ abstract class LibEpiccash { /// /// Scan Epic outputs /// - static Future scanOutputs({ + static Future scanOutputs({ required String wallet, required int startHeight, required int numberOfBlocks, }) async { try { - await compute(_scanOutputsWrapper, ( + return await compute(_scanOutputsWrapper, ( wallet: wallet, startHeight: startHeight, numberOfBlocks: numberOfBlocks, @@ -193,7 +203,7 @@ abstract class LibEpiccash { /// /// Create an Epic transaction /// - static Future createTransaction({ + static Future createTransaction({ required String wallet, required int amount, required String address, @@ -203,7 +213,7 @@ abstract class LibEpiccash { required String note, }) async { try { - await compute(_createTransactionWrapper, ( + return await compute(_createTransactionWrapper, ( wallet: wallet, amount: amount, address: address, @@ -235,12 +245,12 @@ abstract class LibEpiccash { /// /// /// - static Future getTransaction({ + static Future getTransaction({ required String wallet, required int refreshFromNode, }) async { try { - await compute(_getTransactionsWrapper, ( + return await compute(_getTransactionsWrapper, ( wallet: wallet, refreshFromNode: refreshFromNode, )); @@ -265,14 +275,14 @@ abstract class LibEpiccash { } /// + /// Cancel current Epic transaction /// - /// - static Future cancelTransaction({ + static Future cancelTransaction({ required String wallet, required String transactionId, }) async { try { - await compute(_cancelTransactionWrapper, ( + return await compute(_cancelTransactionWrapper, ( wallet: wallet, transactionId: transactionId, )); @@ -281,7 +291,10 @@ abstract class LibEpiccash { } } - static Future addressInfoWrapper( + /// + /// Private function for address info function + /// + static Future _addressInfoWrapper( ({ String wallet, int index, @@ -295,12 +308,59 @@ abstract class LibEpiccash { ); } - static Future getAddressInfo({ + /// + /// get Epic address info + /// + static Future getAddressInfo({ required String wallet, required int index, required String epicboxConfig, }) async { - try {} catch (e) {} + try { + return await compute(_addressInfoWrapper, ( + wallet: wallet, + index: index, + epicboxConfig: epicboxConfig, + )); + } catch (e) { + throw ("Error getting address info : ${e.toString()}"); + } + } + + /// + /// Private function for getting transaction fees + /// + static Future _transactionFeesWrapper( + ({ + String wallet, + int amount, + int minimumConfirmations, + }) data, + ) async { + return lib_epiccash.getTransactionFees( + data.wallet, + data.amount, + data.minimumConfirmations, + ); + } + + /// + /// get transaction fees for Epic + /// + static Future getTransactionFees({ + required String wallet, + required int amount, + required int minimumConfirmations, + }) async { + try { + return await compute(_transactionFeesWrapper, ( + wallet: wallet, + amount: amount, + minimumConfirmations: minimumConfirmations, + )); + } catch (e) { + throw ("Error getting transaction fees : ${e.toString()}"); + } } /// @@ -341,4 +401,116 @@ abstract class LibEpiccash { throw ("Error recovering wallet : ${e.toString()}"); } } + + /// + /// Private function wrapper for delete wallet function + /// + static Future _deleteWalletWrapper( + ({ + String wallet, + String config, + }) data, + ) async { + return lib_epiccash.deleteWallet( + data.wallet, + data.config, + ); + } + + /// + /// Delete an Epic wallet + /// + static Future deleteWallet({ + required String wallet, + required String config, + }) async { + try { + return await compute(_deleteWalletWrapper, ( + wallet: wallet, + config: config, + )); + } catch (e) { + throw ("Error deleting wallet : ${e.toString()}"); + } + } + + /// + /// Private function wrapper for open wallet function + /// + static Future _openWalletWrapper( + ({ + String config, + String password, + }) data, + ) async { + return lib_epiccash.openWallet( + data.config, + data.password, + ); + } + + /// + /// Open an Epic wallet + /// + static Future openWallet({ + required String config, + required String password, + }) async { + try { + return await compute(_openWalletWrapper, ( + config: config, + password: password, + )); + } catch (e) { + throw ("Error opening wallet : ${e.toString()}"); + } + } + + /// + /// Private function for txHttpSend function + /// + static Future _txHttpSendWrapper( + ({ + String wallet, + int selectionStrategyIsAll, + int minimumConfirmations, + String message, + int amount, + String address, + }) data, + ) async { + return lib_epiccash.txHttpSend( + data.wallet, + data.selectionStrategyIsAll, + data.minimumConfirmations, + data.message, + data.amount, + data.address, + ); + } + + /// + /// + /// + static Future txHttpSend({ + required String wallet, + required int selectionStrategyIsAll, + required int minimumConfirmations, + required String message, + required int amount, + required String address, + }) async { + try { + return await compute(_txHttpSendWrapper, ( + wallet: wallet, + selectionStrategyIsAll: selectionStrategyIsAll, + minimumConfirmations: minimumConfirmations, + message: message, + amount: amount, + address: address, + )); + } catch (e) { + throw ("Error sending tx HTTP : ${e.toString()}"); + } + } }