2023-09-20 14:12:48 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2023-09-18 21:56:57 +00:00
|
|
|
import 'package:flutter_libepiccash/epic_cash.dart' as lib_epiccash;
|
2023-09-20 23:04:37 +00:00
|
|
|
import 'package:mutex/mutex.dart';
|
2023-09-18 21:56:57 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Wrapped up calls to flutter_libepiccash.
|
|
|
|
///
|
|
|
|
/// Should all be static calls (no state stored in this class)
|
|
|
|
///
|
|
|
|
abstract class LibEpiccash {
|
2023-09-20 23:08:22 +00:00
|
|
|
static final Mutex _mutex = Mutex();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Check if [address] is a valid epiccash address according to libepiccash
|
|
|
|
///
|
2023-09-18 21:56:57 +00:00
|
|
|
static bool validateSendAddress({required String address}) {
|
|
|
|
final String validate = lib_epiccash.validateSendAddress(address);
|
|
|
|
if (int.parse(validate) == 1) {
|
|
|
|
// Check if address contains a domain
|
|
|
|
if (address.contains("@")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-09-20 14:12:48 +00:00
|
|
|
|
2023-09-20 23:04:37 +00:00
|
|
|
///
|
|
|
|
/// Fetch the mnemonic of (some? current?) wallet
|
|
|
|
///
|
|
|
|
// TODO: ensure the above documentation comment is correct
|
|
|
|
// TODO: ensure this will always return the mnemonic. If not, this function should throw an exception
|
|
|
|
// TODO: probably remove this as we don't use it in stack wallet. We store the mnemonic separately
|
2023-09-20 14:12:48 +00:00
|
|
|
static String getMnemonic() {
|
|
|
|
return lib_epiccash.walletMnemonic();
|
|
|
|
}
|
|
|
|
|
2023-09-20 23:04:37 +00:00
|
|
|
// Private function wrapper for compute
|
2023-09-20 14:12:48 +00:00
|
|
|
static Future<String> _initializeWalletWrapper(
|
2023-09-20 23:04:37 +00:00
|
|
|
({
|
|
|
|
String config,
|
|
|
|
String mnemonic,
|
|
|
|
String password,
|
|
|
|
String name,
|
|
|
|
}) data,
|
|
|
|
) async {
|
|
|
|
final String initWalletStr = lib_epiccash.initWallet(
|
|
|
|
data.config,
|
|
|
|
data.mnemonic,
|
|
|
|
data.password,
|
|
|
|
data.name,
|
|
|
|
);
|
2023-09-20 14:12:48 +00:00
|
|
|
return initWalletStr;
|
|
|
|
}
|
|
|
|
|
2023-09-20 23:04:37 +00:00
|
|
|
///
|
|
|
|
/// Create and or initialize a new epiccash wallet.
|
|
|
|
///
|
|
|
|
// TODO: Complete/modify the documentation comment above
|
|
|
|
// TODO: Should return a void future. On error this function should throw and exception
|
2023-09-20 14:12:48 +00:00
|
|
|
static Future<String> initializeNewWallet({
|
|
|
|
required String config,
|
|
|
|
required String mnemonic,
|
|
|
|
required String password,
|
2023-09-20 23:04:37 +00:00
|
|
|
required String name,
|
|
|
|
}) async {
|
|
|
|
final String result = await compute(
|
2023-09-20 14:12:48 +00:00
|
|
|
_initializeWalletWrapper,
|
2023-09-20 23:04:37 +00:00
|
|
|
(
|
|
|
|
config: config,
|
|
|
|
mnemonic: mnemonic,
|
|
|
|
password: password,
|
|
|
|
name: name,
|
2023-09-20 14:12:48 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2023-09-18 21:56:57 +00:00
|
|
|
}
|