mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
remove redundant null check operator
This commit is contained in:
parent
e97ccf812e
commit
57814fab4b
1 changed files with 34 additions and 44 deletions
|
@ -77,11 +77,8 @@ Future<void> executeNative(Map<String, dynamic> arguments) async {
|
||||||
final startHeight = arguments['startHeight'] as int?;
|
final startHeight = arguments['startHeight'] as int?;
|
||||||
final numberOfBlocks = arguments['numberOfBlocks'] as int?;
|
final numberOfBlocks = arguments['numberOfBlocks'] as int?;
|
||||||
Map<String, dynamic> result = {};
|
Map<String, dynamic> result = {};
|
||||||
if (!(wallet == null ||
|
if (!(wallet == null || startHeight == null || numberOfBlocks == null)) {
|
||||||
startHeight == null ||
|
var outputs = await scanOutPuts(wallet, startHeight, numberOfBlocks);
|
||||||
numberOfBlocks == null)) {
|
|
||||||
var outputs =
|
|
||||||
await scanOutPuts(wallet, startHeight, numberOfBlocks);
|
|
||||||
result['outputs'] = outputs;
|
result['outputs'] = outputs;
|
||||||
sendPort.send(result);
|
sendPort.send(result);
|
||||||
return;
|
return;
|
||||||
|
@ -111,8 +108,8 @@ Future<void> executeNative(Map<String, dynamic> arguments) async {
|
||||||
epicboxConfig == null)) {
|
epicboxConfig == null)) {
|
||||||
Logging.instance
|
Logging.instance
|
||||||
.log("SECRET_KEY_INDEX_IS $secretKeyIndex", level: LogLevel.Info);
|
.log("SECRET_KEY_INDEX_IS $secretKeyIndex", level: LogLevel.Info);
|
||||||
result['result'] = await getSubscribeRequest(
|
result['result'] =
|
||||||
wallet, secretKeyIndex, epicboxConfig);
|
await getSubscribeRequest(wallet, secretKeyIndex, epicboxConfig);
|
||||||
sendPort.send(result);
|
sendPort.send(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -122,8 +119,7 @@ Future<void> executeNative(Map<String, dynamic> arguments) async {
|
||||||
Map<String, dynamic> result = {};
|
Map<String, dynamic> result = {};
|
||||||
|
|
||||||
if (!(wallet == null || slates == null)) {
|
if (!(wallet == null || slates == null)) {
|
||||||
result['result'] =
|
result['result'] = await processSlates(wallet, slates.toString());
|
||||||
await processSlates(wallet, slates.toString());
|
|
||||||
sendPort.send(result);
|
sendPort.send(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -135,8 +131,8 @@ Future<void> executeNative(Map<String, dynamic> arguments) async {
|
||||||
if (!(wallet == null ||
|
if (!(wallet == null ||
|
||||||
refreshFromNode == null ||
|
refreshFromNode == null ||
|
||||||
minimumConfirmations == null)) {
|
minimumConfirmations == null)) {
|
||||||
var res = await getWalletInfo(
|
var res =
|
||||||
wallet, refreshFromNode, minimumConfirmations);
|
await getWalletInfo(wallet, refreshFromNode, minimumConfirmations);
|
||||||
result['result'] = res;
|
result['result'] = res;
|
||||||
sendPort.send(result);
|
sendPort.send(result);
|
||||||
return;
|
return;
|
||||||
|
@ -166,11 +162,9 @@ Future<void> executeNative(Map<String, dynamic> arguments) async {
|
||||||
final amount = arguments['amount'] as int?;
|
final amount = arguments['amount'] as int?;
|
||||||
final minimumConfirmations = arguments['minimumConfirmations'] as int?;
|
final minimumConfirmations = arguments['minimumConfirmations'] as int?;
|
||||||
Map<String, dynamic> result = {};
|
Map<String, dynamic> result = {};
|
||||||
if (!(wallet == null ||
|
if (!(wallet == null || amount == null || minimumConfirmations == null)) {
|
||||||
amount == null ||
|
var res =
|
||||||
minimumConfirmations == null)) {
|
await getTransactionFees(wallet, amount, minimumConfirmations);
|
||||||
var res = await getTransactionFees(
|
|
||||||
wallet, amount, minimumConfirmations);
|
|
||||||
result['result'] = res;
|
result['result'] = res;
|
||||||
sendPort.send(result);
|
sendPort.send(result);
|
||||||
return;
|
return;
|
||||||
|
@ -198,7 +192,8 @@ Future<void> executeNative(Map<String, dynamic> arguments) async {
|
||||||
}
|
}
|
||||||
} else if (function == "txHttpSend") {
|
} else if (function == "txHttpSend") {
|
||||||
final wallet = arguments['wallet'] as String?;
|
final wallet = arguments['wallet'] as String?;
|
||||||
final selectionStrategyIsAll = arguments['selectionStrategyIsAll'] as int?;
|
final selectionStrategyIsAll =
|
||||||
|
arguments['selectionStrategyIsAll'] as int?;
|
||||||
final minimumConfirmations = arguments['minimumConfirmations'] as int?;
|
final minimumConfirmations = arguments['minimumConfirmations'] as int?;
|
||||||
final message = arguments['message'] as String?;
|
final message = arguments['message'] as String?;
|
||||||
final amount = arguments['amount'] as int?;
|
final amount = arguments['amount'] as int?;
|
||||||
|
@ -218,7 +213,6 @@ Future<void> executeNative(Map<String, dynamic> arguments) async {
|
||||||
sendPort.send(result);
|
sendPort.send(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"Error Arguments for $function not formatted correctly",
|
"Error Arguments for $function not formatted correctly",
|
||||||
|
@ -245,8 +239,7 @@ void stop(ReceivePort port) {
|
||||||
|
|
||||||
// Keep Wrapper functions outside of the class to avoid memory leaks and errors about receive ports and illegal arguments.
|
// Keep Wrapper functions outside of the class to avoid memory leaks and errors about receive ports and illegal arguments.
|
||||||
// TODO: Can get rid of this wrapper and call it in a full isolate instead of compute() if we want more control over this
|
// TODO: Can get rid of this wrapper and call it in a full isolate instead of compute() if we want more control over this
|
||||||
Future<String> _cancelTransactionWrapper(
|
Future<String> _cancelTransactionWrapper(Tuple2<String, String> data) async {
|
||||||
Tuple2<String, String> data) async {
|
|
||||||
// assuming this returns an empty string on success
|
// assuming this returns an empty string on success
|
||||||
// or an error message string on failure
|
// or an error message string on failure
|
||||||
return cancelTransaction(data.item1, data.item2);
|
return cancelTransaction(data.item1, data.item2);
|
||||||
|
@ -290,8 +283,7 @@ Future<String> _initWalletWrapper(
|
||||||
|
|
||||||
Future<String> _initGetAddressInfoWrapper(
|
Future<String> _initGetAddressInfoWrapper(
|
||||||
Tuple3<String, int, String> data) async {
|
Tuple3<String, int, String> data) async {
|
||||||
String walletAddress =
|
String walletAddress = getAddressInfo(data.item1, data.item2, data.item3);
|
||||||
getAddressInfo(data.item1, data.item2, data.item3);
|
|
||||||
return walletAddress;
|
return walletAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -727,7 +719,7 @@ class EpicCashWallet extends CoinServiceAPI {
|
||||||
/// returns an empty String on success, error message on failure
|
/// returns an empty String on success, error message on failure
|
||||||
Future<String> cancelPendingTransaction(String tx_slate_id) async {
|
Future<String> cancelPendingTransaction(String tx_slate_id) async {
|
||||||
final String wallet =
|
final String wallet =
|
||||||
(await _secureStore.read(key: '${_walletId}_wallet'))!;
|
(await _secureStore.read(key: '${_walletId}_wallet'))!;
|
||||||
|
|
||||||
String? result;
|
String? result;
|
||||||
await m.protect(() async {
|
await m.protect(() async {
|
||||||
|
@ -754,7 +746,8 @@ class EpicCashWallet extends CoinServiceAPI {
|
||||||
|
|
||||||
String receiverAddress = txData['addresss'] as String;
|
String receiverAddress = txData['addresss'] as String;
|
||||||
await m.protect(() async {
|
await m.protect(() async {
|
||||||
if (receiverAddress.startsWith("http://") || receiverAddress.startsWith("https://")) {
|
if (receiverAddress.startsWith("http://") ||
|
||||||
|
receiverAddress.startsWith("https://")) {
|
||||||
const int selectionStrategyIsAll = 0;
|
const int selectionStrategyIsAll = 0;
|
||||||
ReceivePort receivePort = await getIsolate({
|
ReceivePort receivePort = await getIsolate({
|
||||||
"function": "txHttpSend",
|
"function": "txHttpSend",
|
||||||
|
@ -774,9 +767,8 @@ class EpicCashWallet extends CoinServiceAPI {
|
||||||
throw Exception("txHttpSend isolate failed");
|
throw Exception("txHttpSend isolate failed");
|
||||||
}
|
}
|
||||||
stop(receivePort);
|
stop(receivePort);
|
||||||
Logging.instance.log('Closing txHttpSend!\n $message',
|
Logging.instance
|
||||||
level: LogLevel.Info);
|
.log('Closing txHttpSend!\n $message', level: LogLevel.Info);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ReceivePort receivePort = await getIsolate({
|
ReceivePort receivePort = await getIsolate({
|
||||||
"function": "createTransaction",
|
"function": "createTransaction",
|
||||||
|
@ -809,7 +801,6 @@ class EpicCashWallet extends CoinServiceAPI {
|
||||||
|
|
||||||
await putSendToAddresses(sendTx);
|
await putSendToAddresses(sendTx);
|
||||||
|
|
||||||
|
|
||||||
Logging.instance.log("CONFIRM_RESULT_IS $sendTx", level: LogLevel.Info);
|
Logging.instance.log("CONFIRM_RESULT_IS $sendTx", level: LogLevel.Info);
|
||||||
|
|
||||||
final decodeData = json.decode(sendTx);
|
final decodeData = json.decode(sendTx);
|
||||||
|
@ -818,9 +809,9 @@ class EpicCashWallet extends CoinServiceAPI {
|
||||||
String errorMessage = decodeData[1] as String;
|
String errorMessage = decodeData[1] as String;
|
||||||
throw Exception("Transaction failed with error code $errorMessage");
|
throw Exception("Transaction failed with error code $errorMessage");
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
//If it's HTTP send no need to post to epicbox
|
//If it's HTTP send no need to post to epicbox
|
||||||
if (!(receiverAddress.startsWith("http://") || receiverAddress.startsWith("https://"))) {
|
if (!(receiverAddress.startsWith("http://") ||
|
||||||
|
receiverAddress.startsWith("https://"))) {
|
||||||
final postSlateRequest = decodeData[1];
|
final postSlateRequest = decodeData[1];
|
||||||
final postToServer = await postSlate(
|
final postToServer = await postSlate(
|
||||||
txData['addresss'] as String, postSlateRequest as String);
|
txData['addresss'] as String, postSlateRequest as String);
|
||||||
|
@ -969,10 +960,9 @@ class EpicCashWallet extends CoinServiceAPI {
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
|
|
||||||
final config = await getRealConfig();
|
final config = await getRealConfig();
|
||||||
final password =
|
final password = await _secureStore.read(key: '${_walletId}_password');
|
||||||
await _secureStore.read(key: '${_walletId}_password');
|
|
||||||
|
|
||||||
final walletOpen = openWallet(config!, password!);
|
final walletOpen = openWallet(config, password!);
|
||||||
await _secureStore.write(key: '${_walletId}_wallet', value: walletOpen);
|
await _secureStore.write(key: '${_walletId}_wallet', value: walletOpen);
|
||||||
|
|
||||||
if ((DB.instance.get<dynamic>(boxName: walletId, key: "id")) == null) {
|
if ((DB.instance.get<dynamic>(boxName: walletId, key: "id")) == null) {
|
||||||
|
@ -1297,7 +1287,6 @@ class EpicCashWallet extends CoinServiceAPI {
|
||||||
|
|
||||||
Future<bool> startScans() async {
|
Future<bool> startScans() async {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
final wallet = await _secureStore.read(key: '${_walletId}_wallet');
|
final wallet = await _secureStore.read(key: '${_walletId}_wallet');
|
||||||
|
|
||||||
var restoreHeight =
|
var restoreHeight =
|
||||||
|
@ -1445,7 +1434,6 @@ class EpicCashWallet extends CoinServiceAPI {
|
||||||
|
|
||||||
//Store Epic box address info
|
//Store Epic box address info
|
||||||
await storeEpicboxInfo();
|
await storeEpicboxInfo();
|
||||||
|
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance
|
Logging.instance
|
||||||
.log("Error recovering wallet $e\n$s", level: LogLevel.Error);
|
.log("Error recovering wallet $e\n$s", level: LogLevel.Error);
|
||||||
|
@ -1724,11 +1712,13 @@ class EpicCashWallet extends CoinServiceAPI {
|
||||||
subscribeRequest['signature'] as String, slate as String);
|
subscribeRequest['signature'] as String, slate as String);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.contains("Error Wallet store error: DB Not Found Error")) {
|
if (response
|
||||||
|
.contains("Error Wallet store error: DB Not Found Error")) {
|
||||||
//Already processed - to be deleted
|
//Already processed - to be deleted
|
||||||
Logging.instance.log("DELETING_PROCESSED_SLATE",
|
Logging.instance
|
||||||
level: LogLevel.Info);
|
.log("DELETING_PROCESSED_SLATE", level: LogLevel.Info);
|
||||||
final slateDelete = await deleteSlate(currentAddress, subscribeRequest['signature'] as String, slate as String);
|
final slateDelete = await deleteSlate(currentAddress,
|
||||||
|
subscribeRequest['signature'] as String, slate as String);
|
||||||
Logging.instance.log("DELETE_SLATE_RESPONSE $slateDelete",
|
Logging.instance.log("DELETE_SLATE_RESPONSE $slateDelete",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1738,14 +1728,14 @@ class EpicCashWallet extends CoinServiceAPI {
|
||||||
if (slateStatus == "PendingProcessing") {
|
if (slateStatus == "PendingProcessing") {
|
||||||
//Encrypt slate
|
//Encrypt slate
|
||||||
String encryptedSlate = await getEncryptedSlate(
|
String encryptedSlate = await getEncryptedSlate(
|
||||||
wallet!,
|
wallet,
|
||||||
slateSender,
|
slateSender,
|
||||||
currentReceivingIndex,
|
currentReceivingIndex,
|
||||||
epicboxConfig!,
|
epicboxConfig!,
|
||||||
decodedResponse[1] as String);
|
decodedResponse[1] as String);
|
||||||
|
|
||||||
final postSlateToServer =
|
final postSlateToServer =
|
||||||
await postSlate(slateSender, encryptedSlate);
|
await postSlate(slateSender, encryptedSlate);
|
||||||
|
|
||||||
await deleteSlate(currentAddress,
|
await deleteSlate(currentAddress,
|
||||||
subscribeRequest['signature'] as String, slate as String);
|
subscribeRequest['signature'] as String, slate as String);
|
||||||
|
@ -1753,7 +1743,8 @@ class EpicCashWallet extends CoinServiceAPI {
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
} else {
|
} else {
|
||||||
//Finalise Slate
|
//Finalise Slate
|
||||||
final processSlate = json.decode(decodedResponse[1] as String);
|
final processSlate =
|
||||||
|
json.decode(decodedResponse[1] as String);
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"PROCESSED_SLATE_TO_FINALIZE $processSlate",
|
"PROCESSED_SLATE_TO_FINALIZE $processSlate",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
|
@ -1762,8 +1753,7 @@ class EpicCashWallet extends CoinServiceAPI {
|
||||||
String txSlateId = tx[0]['tx_slate_id'] as String;
|
String txSlateId = tx[0]['tx_slate_id'] as String;
|
||||||
Logging.instance
|
Logging.instance
|
||||||
.log("TX_SLATE_ID_IS $txSlateId", level: LogLevel.Info);
|
.log("TX_SLATE_ID_IS $txSlateId", level: LogLevel.Info);
|
||||||
final postToNode = await postSlateToNode(
|
final postToNode = await postSlateToNode(wallet, txSlateId);
|
||||||
wallet!, txSlateId);
|
|
||||||
await deleteSlate(currentAddress,
|
await deleteSlate(currentAddress,
|
||||||
subscribeRequest['signature'] as String, slate as String);
|
subscribeRequest['signature'] as String, slate as String);
|
||||||
Logging.instance.log("POST_SLATE_RESPONSE $postToNode",
|
Logging.instance.log("POST_SLATE_RESPONSE $postToNode",
|
||||||
|
|
Loading…
Reference in a new issue