diff --git a/lib/services/coins/epiccash/epiccash_wallet.dart b/lib/services/coins/epiccash/epiccash_wallet.dart index 0f074fd98..fd492a555 100644 --- a/lib/services/coins/epiccash/epiccash_wallet.dart +++ b/lib/services/coins/epiccash/epiccash_wallet.dart @@ -291,204 +291,6 @@ Future _getChainHeightWrapper(String config) async { return chainHeight; } -const String EPICPOST_ADDRESS = 'https://epicpost.stackwallet.com'; - -Future postSlate(String receiveAddress, String slate) async { - Logging.instance.log("postSlate", level: LogLevel.Info); - final Client client = Client(); - try { - final uri = Uri.parse("$EPICPOST_ADDRESS/postSlate"); - - final epicpost = await client.post( - uri, - headers: {'Content-Type': 'application/json'}, - body: jsonEncode({ - "jsonrpc": "2.0", - "id": "0", - 'receivingAddress': receiveAddress, - 'slate': slate - }), - ); - - // TODO: should the following be removed for security reasons in production? - Logging.instance.log(epicpost.statusCode.toString(), level: LogLevel.Info); - Logging.instance.log(epicpost.body.toString(), level: LogLevel.Info); - final response = jsonDecode(epicpost.body.toString()); - if (response['status'] == 'success') { - return true; - } else { - return false; - } - } catch (e, s) { - Logging.instance.log("$e $s", level: LogLevel.Error); - return false; - } -} - -Future getSlates(String receiveAddress, String signature) async { - Logging.instance.log("getslates", level: LogLevel.Info); - final Client client = Client(); - try { - final uri = Uri.parse("$EPICPOST_ADDRESS/getSlates"); - - final epicpost = await client.post( - uri, - headers: {'Content-Type': 'application/json'}, - body: jsonEncode({ - "jsonrpc": "2.0", - "id": "0", - 'receivingAddress': receiveAddress, - 'signature': signature, - }), - ); - - // TODO: should the following be removed for security reasons in production? - Logging.instance.log(epicpost.statusCode.toString(), level: LogLevel.Info); - Logging.instance.log(epicpost.body.toString(), level: LogLevel.Info); - final response = jsonDecode(epicpost.body.toString()); - if (response['status'] == 'success') { - return response['slates']; - } else { - return response['error']; - } - } catch (e, s) { - Logging.instance.log("$e $s", level: LogLevel.Error); - return 'Error $e $s'; - } -} - -Future postCancel(String receiveAddress, String slateId, - String? signature, String sendersAddress) async { - Logging.instance.log("postCancel", level: LogLevel.Info); - final Client client = Client(); - try { - final uri = Uri.parse("$EPICPOST_ADDRESS/postCancel"); - - final body = jsonEncode({ - "jsonrpc": "2.0", - "id": "0", - 'receivingAddress': receiveAddress, - "signature": signature, - 'slate': slateId, - "sendersAddress": sendersAddress, - }); - final epicPost = await client.post( - uri, - headers: {'Content-Type': 'application/json'}, - body: body, - ); - // TODO: should the following be removed for security reasons in production? - Logging.instance.log(epicPost.statusCode.toString(), level: LogLevel.Info); - Logging.instance.log(epicPost.body.toString(), level: LogLevel.Info); - final response = jsonDecode(epicPost.body.toString()); - if (response['status'] == 'success') { - return true; - } else { - return false; - } - } catch (e, s) { - Logging.instance.log("$e $s", level: LogLevel.Error); - return false; - } -} - -Future getCancels(String receiveAddress, String signature) async { - Logging.instance.log("getCancels", level: LogLevel.Info); - final Client client = Client(); - try { - final uri = Uri.parse("$EPICPOST_ADDRESS/getCancels"); - - final epicpost = await client.post( - uri, - headers: {'Content-Type': 'application/json'}, - body: jsonEncode({ - "jsonrpc": "2.0", - "id": "0", - 'receivingAddress': receiveAddress, - 'signature': signature, - }), - ); - // TODO: should the following be removed for security reasons in production? - Logging.instance.log(epicpost.statusCode.toString(), level: LogLevel.Info); - Logging.instance.log(epicpost.body.toString(), level: LogLevel.Info); - final response = jsonDecode(epicpost.body.toString()); - if (response['status'] == 'success') { - return response['canceled_slates']; - } else { - return response['error']; - } - } catch (e, s) { - Logging.instance.log("$e $s", level: LogLevel.Error); - return 'Error $e $s'; - } -} - -Future deleteCancels( - String receiveAddress, String signature, String slate) async { - Logging.instance.log("deleteCancels", level: LogLevel.Info); - final Client client = Client(); - try { - final uri = Uri.parse("$EPICPOST_ADDRESS/deleteCancels"); - - final epicpost = await client.post( - uri, - headers: {'Content-Type': 'application/json'}, - body: jsonEncode({ - "jsonrpc": "2.0", - "id": "0", - 'receivingAddress': receiveAddress, - 'signature': signature, - 'slate': slate, - }), - ); - // TODO: should the following be removed for security reasons in production? - Logging.instance.log(epicpost.statusCode.toString(), level: LogLevel.Info); - Logging.instance.log(epicpost.body.toString(), level: LogLevel.Info); - final response = jsonDecode(epicpost.body.toString()); - if (response['status'] == 'success') { - return true; - } else { - return false; - } - } catch (e, s) { - Logging.instance.log("$e $s", level: LogLevel.Error); - return 'Error $e $s'; - } -} - -Future deleteSlate( - String receiveAddress, String signature, String slate) async { - Logging.instance.log("deleteSlate", level: LogLevel.Info); - final Client client = Client(); - try { - final uri = Uri.parse("$EPICPOST_ADDRESS/deleteSlate"); - - final epicpost = await client.post( - uri, - headers: {'Content-Type': 'application/json'}, - body: jsonEncode({ - "jsonrpc": "2.0", - "id": "0", - 'receivingAddress': receiveAddress, - 'signature': signature, - 'slate': slate, - }), - ); - // TODO: should the following be removed for security reasons in production? - Logging.instance.log(epicpost.statusCode.toString(), level: LogLevel.Info); - Logging.instance.log(epicpost.body.toString(), level: LogLevel.Info); - final response = jsonDecode(epicpost.body.toString()); - if (response['status'] == 'success') { - return true; - } else { - return false; - } - } catch (e, s) { - Logging.instance.log("$e $s", level: LogLevel.Info); - return 'Error $e $s'; - } -} - class EpicCashWallet extends CoinServiceAPI with WalletCache, WalletDB, EpicCashHive { static const integrationTestFlag = @@ -665,9 +467,6 @@ class EpicCashWallet extends CoinServiceAPI try { result = await cancelPendingTransaction(txSlateId); Logging.instance.log("result?: $result", level: LogLevel.Info); - if (!(result.toLowerCase().contains("error"))) { - await postCancel(receiveAddress, txSlateId, signature, sendersAddress); - } } catch (e, s) { Logging.instance.log("$e, $s", level: LogLevel.Error); } @@ -768,16 +567,6 @@ class EpicCashWallet extends CoinServiceAPI String errorMessage = decodeData[1] as String; throw Exception("Transaction failed with error code $errorMessage"); } else { - //If it's HTTP send no need to post to epicbox - if (!(receiverAddress.startsWith("http://") || - receiverAddress.startsWith("https://"))) { - final postSlateRequest = decodeData[1]; - final postToServer = await postSlate( - txData['addresss'] as String, postSlateRequest as String); - Logging.instance - .log("POST_SLATE_IS $postToServer", level: LogLevel.Info); - } - final txCreateResult = decodeData[0]; // //TODO: second problem final transaction = json.decode(txCreateResult as String); @@ -1560,82 +1349,6 @@ class EpicCashWallet extends CoinServiceAPI }); } - Future processAllCancels() async { - Logging.instance.log("processAllCancels", level: LogLevel.Info); - final wallet = await _secureStore.read(key: '${_walletId}_wallet'); - final epicboxConfig = - await _secureStore.read(key: '${_walletId}_epicboxConfig'); - final int? receivingIndex = epicGetReceivingIndex(); - - for (int currentReceivingIndex = 0; - receivingIndex != null && currentReceivingIndex <= receivingIndex; - currentReceivingIndex++) { - final receiveAddress = - await _getReceivingAddressForIndex(currentReceivingIndex); - - dynamic subscribeRequest; - await m.protect(() async { - ReceivePort receivePort = await getIsolate({ - "function": "subscribeRequest", - "wallet": wallet!, - "secretKeyIndex": currentReceivingIndex, - "epicboxConfig": epicboxConfig, - }, name: walletName); - - var result = await receivePort.first; - if (result is String) { - Logging.instance - .log("this is a message $result", level: LogLevel.Info); - stop(receivePort); - throw Exception("subscribeRequest isolate failed"); - } - subscribeRequest = jsonDecode(result['result'] as String); - stop(receivePort); - Logging.instance.log('Closing subscribeRequest! $subscribeRequest', - level: LogLevel.Info); - }); - String? signature = subscribeRequest['signature'] as String?; - final cancels = await getCancels(receiveAddress.value, signature!); - - final slatesToCommits = await getSlatesToCommits(); - for (final cancel in cancels as List) { - final txSlateId = cancel.keys.first as String; - if (slatesToCommits[txSlateId] == null) { - continue; - } - final cancelRequestSender = ((cancel as Map).values.first) as String; - final receiveAddressFromMap = - slatesToCommits[txSlateId]['to'] as String; - final sendersAddressFromMap = - slatesToCommits[txSlateId]['from'] as String; - final commitId = slatesToCommits[txSlateId]['commitId'] as String; - - if (sendersAddressFromMap != cancelRequestSender) { - Logging.instance.log("this was not signed by the correct address", - level: LogLevel.Error); - continue; - } - - try { - await cancelPendingTransaction(txSlateId); - final tx = await db - .getTransactions(walletId) - .filter() - .txidEqualTo(commitId) - .findFirst(); - if ((tx?.isCancelled ?? false) == true) { - await deleteCancels(receiveAddressFromMap, signature, txSlateId); - } - } catch (e, s) { - Logging.instance.log("$e, $s", level: LogLevel.Error); - return false; - } - } - continue; - } - return true; - } - /// Refreshes display data for the wallet @override Future refresh() async {