Skip to content

Commit

Permalink
missing print statements, error fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCyjaneK committed Nov 26, 2024
1 parent 76bba3a commit c8242e3
Show file tree
Hide file tree
Showing 27 changed files with 84 additions and 88 deletions.
2 changes: 1 addition & 1 deletion cw_bitcoin/lib/electrum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class ElectrumClient {
socket = null;
},
onDone: () {
print("SOCKET CLOSED!!!!!");
printV("SOCKET CLOSED!!!!!");
unterminatedString = '';
try {
if (host == socket?.address.host || socket == null) {
Expand Down
16 changes: 8 additions & 8 deletions cw_bitcoin/lib/electrum_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ abstract class ElectrumWalletBase
_feeRates = [slowFee, mediumFee, fastFee];
return;
} catch (e) {
print(e);
printV(e);
}
}

Expand Down Expand Up @@ -1953,7 +1953,7 @@ abstract class ElectrumWalletBase
}

Future<void> updateTransactions() async {
print("updateTransactions() called!");
printV("updateTransactions() called!");
try {
if (_isTransactionUpdating) {
return;
Expand Down Expand Up @@ -2004,13 +2004,13 @@ abstract class ElectrumWalletBase
try {
await _scripthashesUpdateSubject[sh]?.close();
} catch (e) {
print("failed to close: $e");
printV("failed to close: $e");
}
}
try {
_scripthashesUpdateSubject[sh] = await electrumClient.scripthashUpdate(sh);
} catch (e) {
print("failed scripthashUpdate: $e");
printV("failed scripthashUpdate: $e");
}
_scripthashesUpdateSubject[sh]?.listen((event) async {
try {
Expand All @@ -2028,7 +2028,7 @@ abstract class ElectrumWalletBase
));
}
}, onError: (e, s) {
print("sub_listen error: $e $s");
printV("sub_listen error: $e $s");
});
}));
}
Expand Down Expand Up @@ -2080,7 +2080,7 @@ abstract class ElectrumWalletBase

if (balances.isNotEmpty && balances.first['confirmed'] == null) {
// if we got null balance responses from the server, set our connection status to lost and return our last known balance:
print("got null balance responses from the server, setting connection status to lost");
printV("got null balance responses from the server, setting connection status to lost");
syncStatus = LostConnectionSyncStatus();
return balance[currency] ?? ElectrumBalance(confirmed: 0, unconfirmed: 0, frozen: 0);
}
Expand All @@ -2107,7 +2107,7 @@ abstract class ElectrumWalletBase
}

Future<void> updateBalance() async {
print("updateBalance() called!");
printV("updateBalance() called!");
balance[currency] = await fetchBalances();
await save();
}
Expand Down Expand Up @@ -2247,7 +2247,7 @@ abstract class ElectrumWalletBase
}

void _syncStatusReaction(SyncStatus syncStatus) async {
print("SYNC_STATUS_CHANGE: ${syncStatus}");
printV("SYNC_STATUS_CHANGE: ${syncStatus}");
if (syncStatus is SyncingSyncStatus) {
return;
}
Expand Down
41 changes: 15 additions & 26 deletions cw_bitcoin/lib/litecoin_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
}

Future<void> waitForMwebAddresses() async {
print("waitForMwebAddresses() called!");
printV("waitForMwebAddresses() called!");
// ensure that we have the full 1000 mweb addresses generated before continuing:
// should no longer be needed, but leaving here just in case
await (walletAddresses as LitecoinWalletAddresses).ensureMwebAddressUpToIndexExists(1020);
Expand Down Expand Up @@ -325,7 +325,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
try {
await subscribeForUpdates();
} catch (e) {
print("failed to subcribe for updates: $e");
printV("failed to subcribe for updates: $e");
}
updateFeeRates();
_feeRatesTimer?.cancel();
Expand All @@ -345,17 +345,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
}

_syncTimer?.cancel();
_syncTimer = Timer.periodic(const Duration(milliseconds: 1500), (timer) async {
if (syncStatus is FailedSyncStatus) return;

printV("SYNCING....");
printV("DONE SYNC FUNCS");
} catch (e, s) {
printV("mweb sync failed: $e $s");
mwebSyncStatus = FailedSyncStatus(error: "mweb sync failed: $e");
return;
}

_syncTimer = Timer.periodic(const Duration(milliseconds: 3000), (timer) async {
if (mwebSyncStatus is FailedSyncStatus) {
_syncTimer?.cancel();
Expand Down Expand Up @@ -413,7 +402,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
for (var coin in tx.unspents!) {
final utxo = mwebUtxosBox.get(coin.address);
if (utxo != null) {
print("deleting utxo ${coin.address} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
printV("deleting utxo ${coin.address} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
await mwebUtxosBox.delete(coin.address);
}
}
Expand Down Expand Up @@ -449,12 +438,12 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
@action
@override
Future<void> stopSync() async {
print("stopSync() called!");
printV("stopSync() called!");
_syncTimer?.cancel();
_utxoStream?.cancel();
_feeRatesTimer?.cancel();
await CwMweb.stop();
print("stopped syncing!");
printV("stopped syncing!");
}

Future<void> initMwebUtxosBox() async {
Expand Down Expand Up @@ -592,7 +581,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
}

Future<void> processMwebUtxos() async {
print("processMwebUtxos() called!");
printV("processMwebUtxos() called!");
if (!mwebEnabled) {
return;
}
Expand Down Expand Up @@ -633,7 +622,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
// but do update the utxo height if it's somehow different:
final existingUtxo = mwebUtxosBox.get(utxo.outputId);
if (existingUtxo!.height != utxo.height) {
print(
printV(
"updating utxo height for $utxo.outputId: ${existingUtxo.height} -> ${utxo.height}");
existingUtxo.height = utxo.height;
await mwebUtxosBox.put(utxo.outputId, existingUtxo);
Expand All @@ -656,15 +645,15 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
await handleIncoming(utxo);
},
onError: (error) {
print("error in utxo stream: $error");
printV("error in utxo stream: $error");
mwebSyncStatus = FailedSyncStatus(error: error.toString());
},
cancelOnError: true,
);
}

Future<void> deleteSpentUtxos() async {
print("deleteSpentUtxos() called!");
printV("deleteSpentUtxos() called!");
final chainHeight = await electrumClient.getCurrentBlockChainTip();
final status = await CwMweb.status(StatusRequest());
if (chainHeight == null || status.blockHeaderHeight != chainHeight) return;
Expand All @@ -688,7 +677,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
}

Future<void> checkMwebUtxosSpent() async {
print("checkMwebUtxosSpent() called!");
printV("checkMwebUtxosSpent() called!");
if (!mwebEnabled) {
return;
}
Expand Down Expand Up @@ -803,7 +792,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
}

Future<void> updateUnspent() async {
print("updateUnspent() called!");
printV("updateUnspent() called!");
await checkMwebUtxosSpent();
await updateAllUnspents();
}
Expand Down Expand Up @@ -875,7 +864,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
mwebUtxosBox.values.forEach((utxo) {
bool isConfirmed = utxo.height > 0;

print(
printV(
"utxo: ${isConfirmed ? "confirmed" : "unconfirmed"} ${utxo.spent ? "spent" : "unspent"} ${utxo.outputId} ${utxo.height} ${utxo.value}");

if (isConfirmed) {
Expand Down Expand Up @@ -1013,7 +1002,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
final sum1 = _sumOutputAmounts(outputs.map((e) => e.toOutput).toList()) + fee;
final sum2 = utxos.sumOfUtxosValue();
if (sum1 != sum2) {
print("@@@@@ WE HAD TO ADJUST THE FEE! @@@@@@@@");
printV("@@@@@ WE HAD TO ADJUST THE FEE! @@@@@@@@");
final diff = sum2 - sum1;
// add the difference to the fee (abs value):
fee += diff.abs();
Expand Down Expand Up @@ -1178,7 +1167,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
addressRecord.balance -= utxo.value.toInt();
});
transaction.inputAddresses?.addAll(addresses);
print("isPegIn: $isPegIn, isPegOut: $isPegOut");
printV("isPegIn: $isPegIn, isPegOut: $isPegOut");
transaction.additionalInfo["isPegIn"] = isPegIn;
transaction.additionalInfo["isPegOut"] = isPegOut;
transactionHistory.addOne(transaction);
Expand All @@ -1189,7 +1178,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
printV(e);
printV(s);
if (e.toString().contains("commit failed")) {
print(e);
printV(e);
throw Exception("Transaction commit failed (no peers responded), please try again.");
}
rethrow;
Expand Down
8 changes: 4 additions & 4 deletions cw_bitcoin/lib/litecoin_wallet_addresses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,25 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
}

while (generating) {
print("generating.....");
printV("generating.....");
// this function was called multiple times in multiple places:
await Future.delayed(const Duration(milliseconds: 100));
}

print("Generating MWEB addresses up to index $index");
printV("Generating MWEB addresses up to index $index");
generating = true;
try {
while (mwebAddrs.length <= (index + 1)) {
final addresses =
await CwMweb.addresses(scan, spend, mwebAddrs.length, mwebAddrs.length + 50);
print("generated up to index ${mwebAddrs.length}");
printV("generated up to index ${mwebAddrs.length}");
// sleep for a bit to avoid making the main thread unresponsive:
await Future.delayed(Duration(milliseconds: 200));
mwebAddrs.addAll(addresses!);
}
} catch (_) {}
generating = false;
print("Done generating MWEB addresses len: ${mwebAddrs.length}");
printV("Done generating MWEB addresses len: ${mwebAddrs.length}");

// ensure mweb addresses are up to date:
// This is the Case if the Litecoin Wallet is a hardware Wallet
Expand Down
4 changes: 2 additions & 2 deletions cw_core/lib/utils/print_verbose.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
void printV(dynamic content) {
CustomTrace programInfo = CustomTrace(StackTrace.current);
print("${programInfo.fileName}#${programInfo.lineNumber}:${programInfo.columnNumber} ${programInfo.callerFunctionName}: $content");
printV("${programInfo.fileName}#${programInfo.lineNumber}:${programInfo.columnNumber} ${programInfo.callerFunctionName}: $content");
}

// https://stackoverflow.com/a/59386101
Expand All @@ -18,7 +18,7 @@ class CustomTrace {
try {
_parseTrace();
} catch (e) {
print("Unable to parse trace (printV): $e");
printV("Unable to parse trace (printV): $e");
}
}

Expand Down
3 changes: 2 additions & 1 deletion cw_evm/lib/evm_ledger_credentials.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:typed_data';

import 'package:cw_core/hardware/device_not_connected_exception.dart'
as exception;
import 'package:cw_core/utils/print_verbose.dart';
import 'package:ledger_ethereum/ledger_ethereum.dart';
import 'package:ledger_flutter_plus/ledger_flutter_plus.dart';
import 'package:web3dart/crypto.dart';
Expand Down Expand Up @@ -96,7 +97,7 @@ class EvmLedgerCredentials extends CredentialsWithKnownAddress {
await ethereumLedgerApp!.getAndProvideERC20TokenInformation(
erc20ContractAddress: erc20ContractAddress, chainId: chainId);
} catch (e) {
print(e);
printV(e);
rethrow;
// if (e.errorCode != -28672) rethrow;
}
Expand Down
4 changes: 2 additions & 2 deletions cw_monero/lib/ledger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ void enableLedgerExchange(monero.wallet ptr, LedgerConnection connection) {
ptr, emptyPointer.cast<UnsignedChar>(), 0);
malloc.free(emptyPointer);

// print("> ${ledgerRequest.toHexString()}");
// printV("> ${ledgerRequest.toHexString()}");
final response = await exchange(connection, ledgerRequest);
// print("< ${response.toHexString()}");
// printV("< ${response.toHexString()}");

final Pointer<Uint8> result = malloc<Uint8>(response.length);
for (var i = 0; i < response.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion cw_monero/lib/monero_wallet_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class MoneroWalletService extends WalletService<
return wallet;
} catch (e) {
// TODO: Implement Exception for wallet list service.
print('MoneroWalletsManager Error: $e');
printV('MoneroWalletsManager Error: $e');
rethrow;
}
}
Expand Down
2 changes: 1 addition & 1 deletion cw_mweb/lib/cw_mweb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CwMweb {
}

static Future<void> _initializeClient() async {
print("_initializeClient() called!");
printV("_initializeClient() called!");
final appDir = await getApplicationSupportDirectory();
const ltcNodeUri = "ltc-electrum.cakewallet.com:9333";

Expand Down
6 changes: 4 additions & 2 deletions cw_wownero/lib/mywownero.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:cw_core/utils/print_verbose.dart';

const prefixLength = 3;

String swapEndianBytes(String original) {
Expand Down Expand Up @@ -37,14 +39,14 @@ String mnemonicDecode(String seed) {
.indexOf(wlist[i + 2].substring(0, prefixLength));

if (w1 == -1 || w2 == -1 || w3 == -1) {
print("invalid word in mnemonic");
printV("invalid word in mnemonic");
return '';
}

final x = w1 + n * (((n - w1) + w2) % n) + n * n * (((n - w2) + w3) % n);

if (x % n != w1) {
print("Something went wrong when decoding your private key, please try again");
printV("Something went wrong when decoding your private key, please try again");
return '';
}

Expand Down
Binary file added ios/ZanoWallet.framework/ZanoWallet
Binary file not shown.
1 change: 1 addition & 0 deletions ios/zano_libwallet2_api_c.dylib
2 changes: 1 addition & 1 deletion lib/bitcoin/cw_bitcoin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ class CWBitcoin extends Bitcoin {
try {
return hardwareWalletService.getAvailableAccounts(index: index, limit: limit);
} catch (err) {
print(err);
printV(err);
throw err;
}
}
Expand Down
11 changes: 6 additions & 5 deletions lib/buy/dfx/dfx_buy_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/view_model/hardware_wallet/ledger_view_model.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -136,7 +137,7 @@ class DFXBuyProvider extends BuyProvider {
return {};
}
} catch (e) {
print('DFX Error fetching fiat currencies: $e');
printV('DFX Error fetching fiat currencies: $e');
return {};
}
}
Expand Down Expand Up @@ -266,19 +267,19 @@ class DFXBuyProvider extends BuyProvider {
quote.setCryptoCurrency = cryptoCurrency;
return [quote];
} else {
print('DFX: Unexpected data type: ${responseData.runtimeType}');
printV('DFX: Unexpected data type: ${responseData.runtimeType}');
return null;
}
} else {
if (responseData is Map<String, dynamic> && responseData.containsKey('message')) {
print('DFX Error: ${responseData['message']}');
printV('DFX Error: ${responseData['message']}');
} else {
print('DFX Failed to fetch buy quote: ${response.statusCode}');
printV('DFX Failed to fetch buy quote: ${response.statusCode}');
}
return null;
}
} catch (e) {
print('DFX Error fetching buy quote: $e');
printV('DFX Error fetching buy quote: $e');
return null;
}
}
Expand Down
Loading

0 comments on commit c8242e3

Please sign in to comment.