mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-22 23:28:48 +00:00
add mutex to libepiccash
This commit is contained in:
parent
bde7af7b45
commit
4632659e21
1 changed files with 191 additions and 170 deletions
|
@ -13,6 +13,7 @@ import 'package:stackwallet/models/isar/models/blockchain_data/epic_transaction.
|
|||
///
|
||||
abstract class LibEpiccash {
|
||||
static final Mutex _mutex = Mutex();
|
||||
static final Mutex m = Mutex();
|
||||
|
||||
///
|
||||
/// Check if [address] is a valid epiccash address according to libepiccash
|
||||
|
@ -36,6 +37,7 @@ abstract class LibEpiccash {
|
|||
// TODO: ensure the above documentation comment is correct
|
||||
// TODO: ensure this will always return the mnemonic. If not, this function should throw an exception
|
||||
//Function is used in _getMnemonicList()
|
||||
// wrap in mutex? -> would need to be Future<String>
|
||||
static String getMnemonic() {
|
||||
try {
|
||||
String mnemonic = lib_epiccash.walletMnemonic();
|
||||
|
@ -77,6 +79,7 @@ abstract class LibEpiccash {
|
|||
required String password,
|
||||
required String name,
|
||||
}) async {
|
||||
return await m.protect(() async {
|
||||
try {
|
||||
return await compute(
|
||||
_initializeWalletWrapper,
|
||||
|
@ -90,6 +93,7 @@ abstract class LibEpiccash {
|
|||
} catch (e) {
|
||||
throw ("Error creating new wallet : ${e.toString()}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -116,6 +120,7 @@ abstract class LibEpiccash {
|
|||
{required String wallet,
|
||||
required int refreshFromNode,
|
||||
required int minimumConfirmations}) async {
|
||||
return await m.protect(() async {
|
||||
try {
|
||||
String balances = await compute(_walletBalancesWrapper, (
|
||||
wallet: wallet,
|
||||
|
@ -144,6 +149,7 @@ abstract class LibEpiccash {
|
|||
} catch (e) {
|
||||
throw ("Error getting wallet info : ${e.toString()}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -167,6 +173,7 @@ abstract class LibEpiccash {
|
|||
required int startHeight,
|
||||
required int numberOfBlocks,
|
||||
}) async {
|
||||
return await m.protect(() async {
|
||||
try {
|
||||
return await compute(_scanOutputsWrapper, (
|
||||
wallet: wallet,
|
||||
|
@ -176,6 +183,7 @@ abstract class LibEpiccash {
|
|||
} catch (e) {
|
||||
throw ("Error getting scanning outputs : ${e.toString()}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -214,6 +222,7 @@ abstract class LibEpiccash {
|
|||
required int minimumConfirmations,
|
||||
required String note,
|
||||
}) async {
|
||||
return await m.protect(() async {
|
||||
try {
|
||||
String result = await compute(_createTransactionWrapper, (
|
||||
wallet: wallet,
|
||||
|
@ -244,6 +253,7 @@ abstract class LibEpiccash {
|
|||
} catch (e) {
|
||||
throw ("Error creating epic transaction : ${e.toString()}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -268,6 +278,7 @@ abstract class LibEpiccash {
|
|||
required String wallet,
|
||||
required int refreshFromNode,
|
||||
}) async {
|
||||
return await m.protect(() async {
|
||||
try {
|
||||
var result = await compute(_getTransactionsWrapper, (
|
||||
wallet: wallet,
|
||||
|
@ -275,7 +286,8 @@ abstract class LibEpiccash {
|
|||
));
|
||||
|
||||
if (result.toUpperCase().contains("ERROR")) {
|
||||
throw Exception("Error getting epic transactions ${result.toString()}");
|
||||
throw Exception(
|
||||
"Error getting epic transactions ${result.toString()}");
|
||||
}
|
||||
|
||||
//Parse the returned data as an EpicTransaction
|
||||
|
@ -290,6 +302,7 @@ abstract class LibEpiccash {
|
|||
} catch (e) {
|
||||
throw ("Error getting epic transactions : ${e.toString()}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -315,6 +328,7 @@ abstract class LibEpiccash {
|
|||
required String wallet,
|
||||
required String transactionId,
|
||||
}) async {
|
||||
return await m.protect(() async {
|
||||
try {
|
||||
return await compute(_cancelTransactionWrapper, (
|
||||
wallet: wallet,
|
||||
|
@ -323,6 +337,7 @@ abstract class LibEpiccash {
|
|||
} catch (e) {
|
||||
throw ("Error canceling epic transaction : ${e.toString()}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static Future<int> _chainHeightWrapper(
|
||||
|
@ -336,11 +351,13 @@ abstract class LibEpiccash {
|
|||
static Future<int> getChainHeight({
|
||||
required String config,
|
||||
}) async {
|
||||
return await m.protect(() async {
|
||||
try {
|
||||
return await compute(_chainHeightWrapper, (config: config,));
|
||||
} catch (e) {
|
||||
throw ("Error getting chain height : ${e.toString()}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -368,6 +385,7 @@ abstract class LibEpiccash {
|
|||
required int index,
|
||||
required String epicboxConfig,
|
||||
}) async {
|
||||
return await m.protect(() async {
|
||||
try {
|
||||
return await compute(_addressInfoWrapper, (
|
||||
wallet: wallet,
|
||||
|
@ -377,6 +395,7 @@ abstract class LibEpiccash {
|
|||
} catch (e) {
|
||||
throw ("Error getting address info : ${e.toString()}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -406,6 +425,7 @@ abstract class LibEpiccash {
|
|||
required int minimumConfirmations,
|
||||
required int available,
|
||||
}) async {
|
||||
return await m.protect(() async {
|
||||
try {
|
||||
String fees = await compute(_transactionFeesWrapper, (
|
||||
wallet: wallet,
|
||||
|
@ -464,6 +484,7 @@ abstract class LibEpiccash {
|
|||
} catch (e) {
|
||||
throw (e.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
///
|
||||
|
|
Loading…
Reference in a new issue