Skip to content

Commit

Permalink
replace all print statements with printV
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCyjaneK committed Oct 8, 2024
1 parent 37b822b commit cd8d0f0
Show file tree
Hide file tree
Showing 112 changed files with 487 additions and 276 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/no_print_in_dart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: No print statements in dart files

on:
pull_request:
branches: [main]

jobs:
PR_test_build:
runs-on: ubuntu-20.04

steps:
- name: Check for print() statements in dart code (use printV() instead)
if: github.event_name == 'pull_request'
run: |
GIT_GREP_OUT="$(git grep ' print(' | grep .dart | grep -v print_verbose.dart) || true)"
if [[ "x$GIT_GREP_OUT" == "x" ]] && exit 0
echo "$GIT_GREP_OUT"
echo "There are .dart files which use print() statements"
echo "Please use printV from package: cw_core/utils/print_verbose.dart"
3 changes: 2 additions & 1 deletion cw_bitcoin/lib/bitcoin_hardware_wallet_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:cw_bitcoin/utils.dart';
import 'package:cw_core/hardware/hardware_account_data.dart';
import 'package:ledger_bitcoin/ledger_bitcoin.dart';
import 'package:ledger_flutter/ledger_flutter.dart';
import 'package:cw_core/utils/print_verbose.dart';

class BitcoinHardwareWalletService {
BitcoinHardwareWalletService(this.ledger, this.device);
Expand All @@ -17,7 +18,7 @@ class BitcoinHardwareWalletService {
final bitcoinLedgerApp = BitcoinLedgerApp(ledger);

final masterFp = await bitcoinLedgerApp.getMasterFingerprint(device);
print(masterFp);
printV(masterFp);

final accounts = <HardwareAccountData>[];
final indexRange = List.generate(limit, (i) => i + index);
Expand Down
15 changes: 8 additions & 7 deletions cw_bitcoin/lib/electrum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:io';
import 'dart:typed_data';
import 'package:bitcoin_base/bitcoin_base.dart';
import 'package:cw_bitcoin/bitcoin_amount_format.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:flutter/foundation.dart';
import 'package:rxdart/rxdart.dart';

Expand Down Expand Up @@ -116,12 +117,12 @@ class ElectrumClient {
_parseResponse(message);
}
} catch (e) {
print(e.toString());
printV(e.toString());
}
},
onError: (Object error) {
final errorMsg = error.toString();
print(errorMsg);
printV(errorMsg);
unterminatedString = '';
},
onDone: () {
Expand All @@ -132,7 +133,7 @@ class ElectrumClient {
_setConnectionStatus(ConnectionStatus.disconnected);
}
} catch (e) {
print(e.toString());
printV(e.toString());
}
},
cancelOnError: true,
Expand Down Expand Up @@ -177,7 +178,7 @@ class ElectrumClient {
unterminatedString = '';
}
} catch (e) {
print(e.toString());
printV(e.toString());
}
}

Expand Down Expand Up @@ -399,7 +400,7 @@ class ElectrumClient {
} on RequestFailedTimeoutException catch (_) {
return null;
} catch (e) {
print("getCurrentBlockChainTip: ${e.toString()}");
printV("getCurrentBlockChainTip: ${e.toString()}");
return null;
}
}
Expand Down Expand Up @@ -430,7 +431,7 @@ class ElectrumClient {

return subscription;
} catch (e) {
print(e.toString());
printV(e.toString());
return null;
}
}
Expand Down Expand Up @@ -469,7 +470,7 @@ class ElectrumClient {

return completer.future;
} catch (e) {
print(e.toString());
printV(e.toString());
}
}

Expand Down
5 changes: 3 additions & 2 deletions cw_bitcoin/lib/electrum_transaction_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:cw_bitcoin/electrum_transaction_info.dart';
import 'package:cw_core/pathForWallet.dart';
import 'package:cw_core/transaction_history.dart';
import 'package:cw_core/utils/file.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:mobx/mobx.dart';
import 'package:cw_core/transaction_history.dart';
Expand Down Expand Up @@ -51,7 +52,7 @@ abstract class ElectrumTransactionHistoryBase
final data = json.encode({'height': _height, 'transactions': txjson});
await encryptionFileUtils.write(path: path, password: _password, data: data);
} catch (e) {
print('Error while save bitcoin transaction history: ${e.toString()}');
printV('Error while save bitcoin transaction history: ${e.toString()}');
}
}

Expand Down Expand Up @@ -88,7 +89,7 @@ abstract class ElectrumTransactionHistoryBase

_height = content['height'] as int;
} catch (e) {
print(e);
printV(e);
}
}

Expand Down
23 changes: 12 additions & 11 deletions cw_bitcoin/lib/electrum_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:isolate';

import 'package:bitcoin_base/bitcoin_base.dart';
import 'package:cw_bitcoin/litecoin_wallet_addresses.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:cw_core/encryption_file_utils.dart';
import 'package:blockchain_utils/blockchain_utils.dart';
Expand Down Expand Up @@ -464,8 +465,8 @@ abstract class ElectrumWalletBase
syncStatus = SyncedSyncStatus();
}
} catch (e, stacktrace) {
print(stacktrace);
print(e.toString());
printV(stacktrace);
printV(e.toString());
syncStatus = FailedSyncStatus();
}
}
Expand Down Expand Up @@ -568,8 +569,8 @@ abstract class ElectrumWalletBase

await electrumClient.connectToUri(node.uri, useSSL: node.useSSL);
} catch (e, stacktrace) {
print(stacktrace);
print(e.toString());
printV(stacktrace);
printV(e.toString());
syncStatus = FailedSyncStatus();
}
}
Expand Down Expand Up @@ -831,7 +832,7 @@ abstract class ElectrumWalletBase
final lastOutput = outputs.last;
final amountLeftForChange = amountLeftForChangeAndFee - fee;

print(amountLeftForChangeAndFee);
printV(amountLeftForChangeAndFee);

if (!_isBelowDust(amountLeftForChange)) {
// Here, lastOutput already is change, return the amount left without the fee to the user's address.
Expand Down Expand Up @@ -1426,7 +1427,7 @@ abstract class ElectrumWalletBase
await unspentCoinsInfo.deleteAll(keys);
}
} catch (e) {
print(e.toString());
printV(e.toString());
}
}

Expand Down Expand Up @@ -1770,7 +1771,7 @@ abstract class ElectrumWalletBase

return historiesWithDetails;
} catch (e) {
print(e.toString());
printV(e.toString());
return {};
}
}
Expand Down Expand Up @@ -1866,7 +1867,7 @@ abstract class ElectrumWalletBase

return historiesWithDetails;
} catch (e) {
print(e.toString());
printV(e.toString());
return {};
}
}
Expand All @@ -1889,8 +1890,8 @@ abstract class ElectrumWalletBase
walletAddresses.updateReceiveAddresses();
_isTransactionUpdating = false;
} catch (e, stacktrace) {
print(stacktrace);
print(e);
printV(stacktrace);
printV(e);
_isTransactionUpdating = false;
}
}
Expand All @@ -1912,7 +1913,7 @@ abstract class ElectrumWalletBase

await _fetchAddressHistory(address, await getCurrentChainTip());
} catch (e, s) {
print(e.toString());
printV(e.toString());
_onError?.call(FlutterErrorDetails(
exception: e,
stack: s,
Expand Down
5 changes: 3 additions & 2 deletions cw_bitcoin/lib/electrum_wallet_addresses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:bitcoin_base/bitcoin_base.dart';
import 'package:blockchain_utils/blockchain_utils.dart';
import 'package:cw_bitcoin/bitcoin_address_record.dart';
import 'package:cw_bitcoin/electrum_wallet.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_core/wallet_addresses.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_type.dart';
Expand Down Expand Up @@ -188,7 +189,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
receiveAddresses.remove(addressRecord);
receiveAddresses.insert(0, addressRecord);
} catch (e) {
print("ElectrumWalletAddressBase: set address ($addr): $e");
printV("ElectrumWalletAddressBase: set address ($addr): $e");
}
}

Expand Down Expand Up @@ -474,7 +475,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {

await saveAddressesInBox();
} catch (e) {
print(e.toString());
printV(e.toString());
}
}

Expand Down
29 changes: 15 additions & 14 deletions cw_bitcoin/lib/litecoin_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:crypto/crypto.dart';
import 'package:cw_bitcoin/bitcoin_transaction_credentials.dart';
import 'package:cw_core/cake_hive.dart';
import 'package:cw_core/mweb_utxo.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_mweb/mwebd.pbgrpc.dart';
import 'package:fixnum/fixnum.dart';
import 'package:bip39/bip39.dart' as bip39;
Expand Down Expand Up @@ -238,7 +239,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
// should no longer be needed, but leaving here just in case
// final mwebAddrs = (walletAddresses as LitecoinWalletAddresses).mwebAddrs;
// while (mwebAddrs.length < 1000) {
// print("waiting for mweb addresses to finish generating...");
// printV("waiting for mweb addresses to finish generating...");
// await Future.delayed(const Duration(milliseconds: 1000));
// }
await (walletAddresses as LitecoinWalletAddresses).ensureMwebAddressUpToIndexExists(1020);
Expand All @@ -247,11 +248,11 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
@action
@override
Future<void> startSync() async {
print("startSync() called!");
printV("startSync() called!");
if (syncStatus is SyncronizingSyncStatus) {
return;
}
print("STARTING SYNC - MWEB ENABLED: $mwebEnabled");
printV("STARTING SYNC - MWEB ENABLED: $mwebEnabled");
try {
syncStatus = SyncronizingSyncStatus();
await subscribeForUpdates();
Expand All @@ -268,8 +269,8 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
await updateBalance();
syncStatus = SyncedSyncStatus();
} catch (e, s) {
print(e);
print(s);
printV(e);
printV(s);
syncStatus = FailedSyncStatus();
}
return;
Expand All @@ -282,7 +283,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
await updateUnspent();
await updateBalance();
} catch (e) {
print("failed to start mweb sync: $e");
printV("failed to start mweb sync: $e");
syncStatus = FailedSyncStatus();
return;
}
Expand All @@ -291,7 +292,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
_syncTimer = Timer.periodic(const Duration(milliseconds: 1500), (timer) async {
if (syncStatus is FailedSyncStatus) return;

print("SYNCING....");
printV("SYNCING....");

final nodeHeight =
await electrumClient.getCurrentBlockChainTip() ?? 0; // current block height of our node
Expand Down Expand Up @@ -341,7 +342,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
return;
}
} catch (e) {
print("error syncing: $e");
printV("error syncing: $e");
syncStatus = FailedSyncStatus(error: e.toString());
}
});
Expand Down Expand Up @@ -426,7 +427,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
}

Future<void> handleIncoming(MwebUtxo utxo, RpcClient stub) async {
print("handleIncoming() called!");
printV("handleIncoming() called!");
final status = await stub.status(StatusRequest());
var date = DateTime.now();
var confirmations = 0;
Expand Down Expand Up @@ -472,7 +473,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
final addressRecord = walletAddresses.allAddresses
.firstWhereOrNull((addressRecord) => addressRecord.address == utxo.address);
if (addressRecord == null) {
print("we don't have this address in the wallet! ${utxo.address}");
printV("we don't have this address in the wallet! ${utxo.address}");
return;
}

Expand All @@ -498,7 +499,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
}

int restoreHeight = walletInfo.restoreHeight;
print("SCANNING FROM HEIGHT: $restoreHeight");
printV("SCANNING FROM HEIGHT: $restoreHeight");
final req = UtxosRequest(scanSecret: scanSecret, fromHeight: restoreHeight);

// process new utxos as they come in:
Expand Down Expand Up @@ -695,7 +696,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
.firstWhereOrNull((addressRecord) => addressRecord.address == utxo.address);

if (addressRecord == null) {
print("utxo contains an address that is not in the wallet: ${utxo.address}");
printV("utxo contains an address that is not in the wallet: ${utxo.address}");
return;
}
final unspent = BitcoinUnspent(
Expand Down Expand Up @@ -985,8 +986,8 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
await updateBalance();
});
} catch (e, s) {
print(e);
print(s);
printV(e);
printV(s);
if (e.toString().contains("commit failed")) {
throw Exception("Transaction commit failed (no peers responded), please try again.");
}
Expand Down
Loading

0 comments on commit cd8d0f0

Please sign in to comment.