mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-25 19:55:52 +00:00
move scan outputs, create tx, get tx, cancel tx, and address info to abstract class
This commit is contained in:
parent
098a69eded
commit
dc457e7266
2 changed files with 275 additions and 46 deletions
|
@ -37,11 +37,81 @@ class Epiccash extends Bip39Currency {
|
||||||
return LibEpiccash.getMnemonic();
|
return LibEpiccash.getMnemonic();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> createNewWallet(({String config, String mnemonic, String password, String name})? data) async {
|
Future<void> createNewWallet(
|
||||||
|
({
|
||||||
|
String config,
|
||||||
|
String mnemonic,
|
||||||
|
String password,
|
||||||
|
String name,
|
||||||
|
})? data) async {
|
||||||
await LibEpiccash.initializeNewWallet(
|
await LibEpiccash.initializeNewWallet(
|
||||||
config: data!.config,
|
config: data!.config,
|
||||||
mnemonic: data.mnemonic,
|
mnemonic: data.mnemonic,
|
||||||
password: data.password,
|
password: data.password,
|
||||||
name: data.name);
|
name: data.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> scanOutputs(
|
||||||
|
({String wallet, int startHeight, int numberOfBlocks})? data) async {
|
||||||
|
await LibEpiccash.scanOutputs(
|
||||||
|
wallet: data!.wallet,
|
||||||
|
startHeight: data.startHeight,
|
||||||
|
numberOfBlocks: data.numberOfBlocks,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> createTransaction(
|
||||||
|
({
|
||||||
|
String wallet,
|
||||||
|
int amount,
|
||||||
|
String address,
|
||||||
|
int secretKey,
|
||||||
|
String epicboxConfig,
|
||||||
|
int minimumConfirmations,
|
||||||
|
String note,
|
||||||
|
})? data) async {
|
||||||
|
await LibEpiccash.createTransaction(
|
||||||
|
wallet: data!.wallet,
|
||||||
|
amount: data.amount,
|
||||||
|
address: data.address,
|
||||||
|
secretKey: data.secretKey,
|
||||||
|
epicboxConfig: data.epicboxConfig,
|
||||||
|
minimumConfirmations: data.minimumConfirmations,
|
||||||
|
note: data.note);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> getTransaction(
|
||||||
|
({
|
||||||
|
String wallet,
|
||||||
|
int refreshFromNode,
|
||||||
|
})? data) async {
|
||||||
|
await LibEpiccash.getTransaction(
|
||||||
|
wallet: data!.wallet,
|
||||||
|
refreshFromNode: data.refreshFromNode,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> cancelTransaction(
|
||||||
|
({
|
||||||
|
String wallet,
|
||||||
|
String transactionId,
|
||||||
|
})? data) async {
|
||||||
|
await LibEpiccash.cancelTransaction(
|
||||||
|
wallet: data!.wallet,
|
||||||
|
transactionId: data.transactionId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> getAddressInfo(
|
||||||
|
({
|
||||||
|
String wallet,
|
||||||
|
int index,
|
||||||
|
String epicboxConfig,
|
||||||
|
})? data) async {
|
||||||
|
await LibEpiccash.getAddressInfo(
|
||||||
|
wallet: data!.wallet,
|
||||||
|
index: data.index,
|
||||||
|
epicboxConfig: data.epicboxConfig,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ abstract class LibEpiccash {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception(e.toString());
|
throw Exception(e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private function wrapper for compute
|
// Private function wrapper for compute
|
||||||
|
@ -74,14 +73,14 @@ abstract class LibEpiccash {
|
||||||
await compute(
|
await compute(
|
||||||
_initializeWalletWrapper,
|
_initializeWalletWrapper,
|
||||||
(
|
(
|
||||||
config: config,
|
config: config,
|
||||||
mnemonic: mnemonic,
|
mnemonic: mnemonic,
|
||||||
password: password,
|
password: password,
|
||||||
name: name,
|
name: name,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw("Error creating new wallet : ${e.toString()}");
|
throw ("Error creating new wallet : ${e.toString()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,76 +88,236 @@ abstract class LibEpiccash {
|
||||||
/// Private function wrapper for wallet balances
|
/// Private function wrapper for wallet balances
|
||||||
///
|
///
|
||||||
static Future<String> _walletBalancesWrapper(
|
static Future<String> _walletBalancesWrapper(
|
||||||
({
|
({String wallet, int refreshFromNode, int minimumConfirmations}) data,
|
||||||
String wallet,
|
) async {
|
||||||
int refreshFromNode,
|
return lib_epiccash.getWalletInfo(
|
||||||
int minimumConfirmations
|
data.wallet, data.refreshFromNode, data.minimumConfirmations);
|
||||||
}) data,) async {
|
|
||||||
return lib_epiccash.getWalletInfo(
|
|
||||||
data.wallet,
|
|
||||||
data.refreshFromNode,
|
|
||||||
data.minimumConfirmations
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Get balance information for the currently open wallet
|
/// Get balance information for the currently open wallet
|
||||||
///
|
///
|
||||||
static Future<String> getWalletBalances({
|
static Future<String> getWalletBalances(
|
||||||
required String wallet,
|
{required String wallet,
|
||||||
required int refreshFromNode,
|
required int refreshFromNode,
|
||||||
required int minimumConfirmations
|
required int minimumConfirmations}) async {
|
||||||
}) async {
|
|
||||||
try {
|
try {
|
||||||
String balances = await compute(_walletBalancesWrapper, (
|
String balances = await compute(_walletBalancesWrapper, (
|
||||||
wallet: wallet,
|
wallet: wallet,
|
||||||
refreshFromNode: refreshFromNode,
|
refreshFromNode: refreshFromNode,
|
||||||
minimumConfirmations: minimumConfirmations,
|
minimumConfirmations: minimumConfirmations,
|
||||||
));
|
));
|
||||||
return balances;
|
return balances;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw("Error getting wallet info : ${e.toString()}");
|
throw ("Error getting wallet info : ${e.toString()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Private function wrapper for scanning output function
|
||||||
|
///
|
||||||
|
static Future<String> _scanOutputsWrapper(
|
||||||
|
({String wallet, int startHeight, int numberOfBlocks}) data,
|
||||||
|
) async {
|
||||||
|
return lib_epiccash.scanOutPuts(
|
||||||
|
data.wallet,
|
||||||
|
data.startHeight,
|
||||||
|
data.numberOfBlocks,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Scan Epic outputs
|
||||||
|
///
|
||||||
|
static Future<void> scanOutputs({
|
||||||
|
required String wallet,
|
||||||
|
required int startHeight,
|
||||||
|
required int numberOfBlocks,
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
|
await compute(_scanOutputsWrapper, (
|
||||||
|
wallet: wallet,
|
||||||
|
startHeight: startHeight,
|
||||||
|
numberOfBlocks: numberOfBlocks,
|
||||||
|
));
|
||||||
|
} catch (e) {
|
||||||
|
throw ("Error getting scanning outputs : ${e.toString()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Private function wrapper for create transactions
|
||||||
|
///
|
||||||
|
static Future<String> _createTransactionWrapper(
|
||||||
|
({
|
||||||
|
String wallet,
|
||||||
|
int amount,
|
||||||
|
String address,
|
||||||
|
int secretKey,
|
||||||
|
String epicboxConfig,
|
||||||
|
int minimumConfirmations,
|
||||||
|
String note,
|
||||||
|
}) data,
|
||||||
|
) async {
|
||||||
|
return lib_epiccash.createTransaction(
|
||||||
|
data.wallet,
|
||||||
|
data.amount,
|
||||||
|
data.address,
|
||||||
|
data.secretKey,
|
||||||
|
data.epicboxConfig,
|
||||||
|
data.minimumConfirmations,
|
||||||
|
data.note);
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Create an Epic transaction
|
||||||
|
///
|
||||||
|
static Future<void> createTransaction({
|
||||||
|
required String wallet,
|
||||||
|
required int amount,
|
||||||
|
required String address,
|
||||||
|
required int secretKey,
|
||||||
|
required String epicboxConfig,
|
||||||
|
required int minimumConfirmations,
|
||||||
|
required String note,
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
|
await compute(_createTransactionWrapper, (
|
||||||
|
wallet: wallet,
|
||||||
|
amount: amount,
|
||||||
|
address: address,
|
||||||
|
secretKey: secretKey,
|
||||||
|
epicboxConfig: epicboxConfig,
|
||||||
|
minimumConfirmations: minimumConfirmations,
|
||||||
|
note: note,
|
||||||
|
));
|
||||||
|
} catch (e) {
|
||||||
|
throw ("Error creating epic transaction : ${e.toString()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Private function wrapper for get transactions
|
||||||
|
///
|
||||||
|
static Future<String> _getTransactionsWrapper(
|
||||||
|
({
|
||||||
|
String wallet,
|
||||||
|
int refreshFromNode,
|
||||||
|
}) data,
|
||||||
|
) async {
|
||||||
|
return lib_epiccash.getTransactions(
|
||||||
|
data.wallet,
|
||||||
|
data.refreshFromNode,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
static Future<void> getTransaction({
|
||||||
|
required String wallet,
|
||||||
|
required int refreshFromNode,
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
|
await compute(_getTransactionsWrapper, (
|
||||||
|
wallet: wallet,
|
||||||
|
refreshFromNode: refreshFromNode,
|
||||||
|
));
|
||||||
|
} catch (e) {
|
||||||
|
throw ("Error getting epic transaction : ${e.toString()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Private function for cancel transaction function
|
||||||
|
///
|
||||||
|
static Future<String> _cancelTransactionWrapper(
|
||||||
|
({
|
||||||
|
String wallet,
|
||||||
|
String transactionId,
|
||||||
|
}) data,
|
||||||
|
) async {
|
||||||
|
return lib_epiccash.cancelTransaction(
|
||||||
|
data.wallet,
|
||||||
|
data.transactionId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
static Future<void> cancelTransaction({
|
||||||
|
required String wallet,
|
||||||
|
required String transactionId,
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
|
await compute(_cancelTransactionWrapper, (
|
||||||
|
wallet: wallet,
|
||||||
|
transactionId: transactionId,
|
||||||
|
));
|
||||||
|
} catch (e) {
|
||||||
|
throw ("Error canceling epic transaction : ${e.toString()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<String> addressInfoWrapper(
|
||||||
|
({
|
||||||
|
String wallet,
|
||||||
|
int index,
|
||||||
|
String epicboxConfig,
|
||||||
|
}) data,
|
||||||
|
) async {
|
||||||
|
return lib_epiccash.getAddressInfo(
|
||||||
|
data.wallet,
|
||||||
|
data.index,
|
||||||
|
data.epicboxConfig,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> getAddressInfo({
|
||||||
|
required String wallet,
|
||||||
|
required int index,
|
||||||
|
required String epicboxConfig,
|
||||||
|
}) async {
|
||||||
|
try {} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Private function wrapper for recover wallet function
|
/// Private function wrapper for recover wallet function
|
||||||
///
|
///
|
||||||
static Future<String> _recoverWalletWrapper(
|
static Future<String> _recoverWalletWrapper(
|
||||||
({
|
({
|
||||||
String config,
|
String config,
|
||||||
String password,
|
String password,
|
||||||
String mnemonic,
|
String mnemonic,
|
||||||
String name,
|
String name,
|
||||||
}) data,) async {
|
}) data,
|
||||||
return lib_epiccash.recoverWallet(
|
) async {
|
||||||
data.config,
|
return lib_epiccash.recoverWallet(
|
||||||
data.password,
|
data.config,
|
||||||
data.mnemonic,
|
data.password,
|
||||||
data.name,
|
data.mnemonic,
|
||||||
|
data.name,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Recover an Epic wallet using a mnemonic
|
/// Recover an Epic wallet using a mnemonic
|
||||||
///
|
///
|
||||||
static Future<void> recoverWallet({
|
static Future<void> recoverWallet(
|
||||||
required String config,
|
{required String config,
|
||||||
required String password,
|
required String password,
|
||||||
required String mnemonic,
|
required String mnemonic,
|
||||||
required String name
|
required String name}) async {
|
||||||
}) async {
|
|
||||||
try {
|
try {
|
||||||
await compute(_recoverWalletWrapper, (
|
await compute(_recoverWalletWrapper, (
|
||||||
config: config,
|
config: config,
|
||||||
password: password,
|
password: password,
|
||||||
mnemonic: mnemonic,
|
mnemonic: mnemonic,
|
||||||
name: name,
|
name: name,
|
||||||
));
|
));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw("Error recovering wallet : ${e.toString()}");
|
throw ("Error recovering wallet : ${e.toString()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue