mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 01:37:54 +00:00
WIP: move get transaction fees, delete wallet, open wallet, and tx http send
This commit is contained in:
parent
13a171f3ef
commit
9762ffd180
2 changed files with 321 additions and 49 deletions
|
@ -50,35 +50,40 @@ class Epiccash extends Bip39Currency {
|
||||||
password: data.password,
|
password: data.password,
|
||||||
name: data.name);
|
name: data.name);
|
||||||
|
|
||||||
if(result.isNotEmpty) {
|
if (result.isNotEmpty) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<({double awaitingFinalization, double pending, double spendable, double total})> getWalletInfo(
|
Future<({double awaitingFinalization, double pending, double spendable, double total})>
|
||||||
({
|
getWalletInfo(
|
||||||
String wallet,
|
({
|
||||||
int refreshFromNode,
|
String wallet,
|
||||||
})? data
|
int refreshFromNode,
|
||||||
) async {
|
})? data) async {
|
||||||
|
var result = await LibEpiccash.getWalletBalances(
|
||||||
var result = await LibEpiccash.getWalletBalances(wallet: data!.wallet, refreshFromNode: data.refreshFromNode, minimumConfirmations: minConfirms);
|
wallet: data!.wallet,
|
||||||
|
refreshFromNode: data.refreshFromNode,
|
||||||
|
minimumConfirmations: minConfirms);
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> scanOutputs(
|
Future<String?> scanOutputs(
|
||||||
({String wallet, int startHeight, int numberOfBlocks})? data) async {
|
({String wallet, int startHeight, int numberOfBlocks})? data) async {
|
||||||
await LibEpiccash.scanOutputs(
|
var result = await LibEpiccash.scanOutputs(
|
||||||
wallet: data!.wallet,
|
wallet: data!.wallet,
|
||||||
startHeight: data.startHeight,
|
startHeight: data.startHeight,
|
||||||
numberOfBlocks: data.numberOfBlocks,
|
numberOfBlocks: data.numberOfBlocks,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (result.isNotEmpty) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> createTransaction(
|
Future<String?> createTransaction(
|
||||||
({
|
({
|
||||||
String wallet,
|
String wallet,
|
||||||
int amount,
|
int amount,
|
||||||
|
@ -87,48 +92,143 @@ class Epiccash extends Bip39Currency {
|
||||||
String epicboxConfig,
|
String epicboxConfig,
|
||||||
String note,
|
String note,
|
||||||
})? data) async {
|
})? data) async {
|
||||||
await LibEpiccash.createTransaction(
|
var result = await LibEpiccash.createTransaction(
|
||||||
wallet: data!.wallet,
|
wallet: data!.wallet,
|
||||||
amount: data.amount,
|
amount: data.amount,
|
||||||
address: data.address,
|
address: data.address,
|
||||||
secretKey: data.secretKey,
|
secretKey: data.secretKey,
|
||||||
epicboxConfig: data.epicboxConfig,
|
epicboxConfig: data.epicboxConfig,
|
||||||
minimumConfirmations: minConfirms,
|
minimumConfirmations: minConfirms,
|
||||||
note: data.note);
|
note: data.note,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.isNotEmpty) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getTransaction(
|
Future<String?> getTransaction(
|
||||||
({
|
({
|
||||||
String wallet,
|
String wallet,
|
||||||
int refreshFromNode,
|
int refreshFromNode,
|
||||||
})? data) async {
|
})? data) async {
|
||||||
await LibEpiccash.getTransaction(
|
var result = await LibEpiccash.getTransaction(
|
||||||
wallet: data!.wallet,
|
wallet: data!.wallet,
|
||||||
refreshFromNode: data.refreshFromNode,
|
refreshFromNode: data.refreshFromNode,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (result.isNotEmpty) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> cancelTransaction(
|
Future<String?> cancelTransaction(
|
||||||
({
|
({
|
||||||
String wallet,
|
String wallet,
|
||||||
String transactionId,
|
String transactionId,
|
||||||
})? data) async {
|
})? data) async {
|
||||||
await LibEpiccash.cancelTransaction(
|
var result = await LibEpiccash.cancelTransaction(
|
||||||
wallet: data!.wallet,
|
wallet: data!.wallet,
|
||||||
transactionId: data.transactionId,
|
transactionId: data.transactionId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (result.isNotEmpty) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getAddressInfo(
|
Future<String?> getAddressInfo(
|
||||||
({
|
({
|
||||||
String wallet,
|
String wallet,
|
||||||
int index,
|
int index,
|
||||||
String epicboxConfig,
|
String epicboxConfig,
|
||||||
})? data) async {
|
})? data) async {
|
||||||
await LibEpiccash.getAddressInfo(
|
var result = await LibEpiccash.getAddressInfo(
|
||||||
wallet: data!.wallet,
|
wallet: data!.wallet,
|
||||||
index: data.index,
|
index: data.index,
|
||||||
epicboxConfig: data.epicboxConfig,
|
epicboxConfig: data.epicboxConfig,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,10 +103,17 @@ abstract class LibEpiccash {
|
||||||
///
|
///
|
||||||
/// Get balance information for the currently open wallet
|
/// Get balance information for the currently open wallet
|
||||||
///
|
///
|
||||||
static Future<({double awaitingFinalization, double pending, double spendable, double total})> getWalletBalances(
|
static Future<
|
||||||
{required String wallet,
|
({
|
||||||
required int refreshFromNode,
|
double awaitingFinalization,
|
||||||
required int minimumConfirmations}) async {
|
double pending,
|
||||||
|
double spendable,
|
||||||
|
double total
|
||||||
|
})>
|
||||||
|
getWalletBalances(
|
||||||
|
{required String wallet,
|
||||||
|
required int refreshFromNode,
|
||||||
|
required int minimumConfirmations}) async {
|
||||||
try {
|
try {
|
||||||
String balances = await compute(_walletBalancesWrapper, (
|
String balances = await compute(_walletBalancesWrapper, (
|
||||||
wallet: wallet,
|
wallet: wallet,
|
||||||
|
@ -121,12 +128,15 @@ abstract class LibEpiccash {
|
||||||
var jsonBalances = json.decode(balances);
|
var jsonBalances = json.decode(balances);
|
||||||
//Return balances as record
|
//Return balances as record
|
||||||
({
|
({
|
||||||
double spendable, double pending, double total, double awaitingFinalization
|
double spendable,
|
||||||
|
double pending,
|
||||||
|
double total,
|
||||||
|
double awaitingFinalization
|
||||||
}) balancesRecord = (
|
}) balancesRecord = (
|
||||||
spendable: jsonBalances['amount_currently_spendable'],
|
spendable: jsonBalances['amount_currently_spendable'],
|
||||||
pending: jsonBalances['amount_awaiting_finalization'],
|
pending: jsonBalances['amount_awaiting_finalization'],
|
||||||
total: jsonBalances['total'],
|
total: jsonBalances['total'],
|
||||||
awaitingFinalization: jsonBalances['amount_awaiting_finalization'],
|
awaitingFinalization: jsonBalances['amount_awaiting_finalization'],
|
||||||
);
|
);
|
||||||
return balancesRecord;
|
return balancesRecord;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -150,13 +160,13 @@ abstract class LibEpiccash {
|
||||||
///
|
///
|
||||||
/// Scan Epic outputs
|
/// Scan Epic outputs
|
||||||
///
|
///
|
||||||
static Future<void> scanOutputs({
|
static Future<String> scanOutputs({
|
||||||
required String wallet,
|
required String wallet,
|
||||||
required int startHeight,
|
required int startHeight,
|
||||||
required int numberOfBlocks,
|
required int numberOfBlocks,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
await compute(_scanOutputsWrapper, (
|
return await compute(_scanOutputsWrapper, (
|
||||||
wallet: wallet,
|
wallet: wallet,
|
||||||
startHeight: startHeight,
|
startHeight: startHeight,
|
||||||
numberOfBlocks: numberOfBlocks,
|
numberOfBlocks: numberOfBlocks,
|
||||||
|
@ -193,7 +203,7 @@ abstract class LibEpiccash {
|
||||||
///
|
///
|
||||||
/// Create an Epic transaction
|
/// Create an Epic transaction
|
||||||
///
|
///
|
||||||
static Future<void> createTransaction({
|
static Future<String> createTransaction({
|
||||||
required String wallet,
|
required String wallet,
|
||||||
required int amount,
|
required int amount,
|
||||||
required String address,
|
required String address,
|
||||||
|
@ -203,7 +213,7 @@ abstract class LibEpiccash {
|
||||||
required String note,
|
required String note,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
await compute(_createTransactionWrapper, (
|
return await compute(_createTransactionWrapper, (
|
||||||
wallet: wallet,
|
wallet: wallet,
|
||||||
amount: amount,
|
amount: amount,
|
||||||
address: address,
|
address: address,
|
||||||
|
@ -235,12 +245,12 @@ abstract class LibEpiccash {
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
static Future<void> getTransaction({
|
static Future<String> getTransaction({
|
||||||
required String wallet,
|
required String wallet,
|
||||||
required int refreshFromNode,
|
required int refreshFromNode,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
await compute(_getTransactionsWrapper, (
|
return await compute(_getTransactionsWrapper, (
|
||||||
wallet: wallet,
|
wallet: wallet,
|
||||||
refreshFromNode: refreshFromNode,
|
refreshFromNode: refreshFromNode,
|
||||||
));
|
));
|
||||||
|
@ -265,14 +275,14 @@ abstract class LibEpiccash {
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
/// Cancel current Epic transaction
|
||||||
///
|
///
|
||||||
///
|
static Future<String> cancelTransaction({
|
||||||
static Future<void> cancelTransaction({
|
|
||||||
required String wallet,
|
required String wallet,
|
||||||
required String transactionId,
|
required String transactionId,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
await compute(_cancelTransactionWrapper, (
|
return await compute(_cancelTransactionWrapper, (
|
||||||
wallet: wallet,
|
wallet: wallet,
|
||||||
transactionId: transactionId,
|
transactionId: transactionId,
|
||||||
));
|
));
|
||||||
|
@ -281,7 +291,10 @@ abstract class LibEpiccash {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String> addressInfoWrapper(
|
///
|
||||||
|
/// Private function for address info function
|
||||||
|
///
|
||||||
|
static Future<String> _addressInfoWrapper(
|
||||||
({
|
({
|
||||||
String wallet,
|
String wallet,
|
||||||
int index,
|
int index,
|
||||||
|
@ -295,12 +308,59 @@ abstract class LibEpiccash {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> getAddressInfo({
|
///
|
||||||
|
/// get Epic address info
|
||||||
|
///
|
||||||
|
static Future<String> getAddressInfo({
|
||||||
required String wallet,
|
required String wallet,
|
||||||
required int index,
|
required int index,
|
||||||
required String epicboxConfig,
|
required String epicboxConfig,
|
||||||
}) async {
|
}) 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<String> _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<String> 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()}");
|
throw ("Error recovering wallet : ${e.toString()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Private function wrapper for delete wallet function
|
||||||
|
///
|
||||||
|
static Future<String> _deleteWalletWrapper(
|
||||||
|
({
|
||||||
|
String wallet,
|
||||||
|
String config,
|
||||||
|
}) data,
|
||||||
|
) async {
|
||||||
|
return lib_epiccash.deleteWallet(
|
||||||
|
data.wallet,
|
||||||
|
data.config,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Delete an Epic wallet
|
||||||
|
///
|
||||||
|
static Future<String> 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<String> _openWalletWrapper(
|
||||||
|
({
|
||||||
|
String config,
|
||||||
|
String password,
|
||||||
|
}) data,
|
||||||
|
) async {
|
||||||
|
return lib_epiccash.openWallet(
|
||||||
|
data.config,
|
||||||
|
data.password,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Open an Epic wallet
|
||||||
|
///
|
||||||
|
static Future<String> 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<String> _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<String> 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()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue