diff --git a/packages/stellar_client/lib/src/client.dart b/packages/stellar_client/lib/src/client.dart index 99b99320..38cd6b46 100644 --- a/packages/stellar_client/lib/src/client.dart +++ b/packages/stellar_client/lib/src/client.dart @@ -12,6 +12,10 @@ class Client { String get secretSeed => _keyPair.secretSeed; Uint8List? get privateKey => _keyPair.privateKey; + var logger = Logger( + printer: PrettyPrinter(), + ); + Client(this._network, String secretSeed) { _keyPair = KeyPair.fromSecretSeed(secretSeed); _initialize(); @@ -70,8 +74,8 @@ class Client { if (transaction != null) { transaction.sign(_keyPair, _stellarNetwork); await _sdk.submitTransaction(transaction); - print("Account Activated Successfully."); - print("TFT Asset was added Successfully "); + logger.i("Account Activated Successfully."); + logger.i("TFT Asset was added Successfully "); return true; } else { throw Exception("Failed to retrieve activation transaction."); @@ -109,13 +113,13 @@ class Client { try { bool funded = await FriendBot.fundTestAccount(accountId); if (funded) { - print("Account funded successfully"); + logger.i("Account funded successfully"); } else { - print("Failed to fund account"); + logger.e("Failed to fund account"); } return funded; } catch (error) { - print("Error while funding account: $error"); + logger.e("Error while funding account: $error"); return false; } } @@ -143,15 +147,15 @@ class Client { await _sdk.submitTransaction(transaction); if (!response.success) { - print("Failed to add trustline for $currencyCode"); + logger.e("Failed to add trustline for $currencyCode"); return false; } else { - print("trustline for $currencyCode was added successfully"); + logger.i("trustline for $currencyCode was added successfully"); return true; } } - print("No trustlines were processed"); + logger.i("No trustlines were processed"); return false; } @@ -169,10 +173,10 @@ class Client { transaction!.sign(_keyPair, _stellarNetwork); await _sdk.submitTransaction(transaction); - print("Transaction successful."); + logger.i("Transaction successful."); return true; } catch (error) { - print("Failed to send transaction: $error"); + logger.e("Failed to send transaction: $error"); return false; } } @@ -194,7 +198,7 @@ class Client { await _sdk.submitTransaction(transaction); return true; } catch (error) { - print("Failed to create account $error"); + logger.e("Failed to create account $error"); return false; } } @@ -232,10 +236,10 @@ class Client { await _sdk.submitTransaction(transaction); if (response2.success) { - print("Trustline for $asset_code added successfully."); + logger.i("Trustline for $asset_code added successfully."); return true; } else { - print("Failed to add trustline for $asset_code."); + logger.e("Failed to add trustline for $asset_code."); return false; } } catch (error) { @@ -263,10 +267,10 @@ class Client { if (details != null) { TransactionData transactionData = TransactionData.fromJson(details); - print(transactionData); + logger.i(transactionData); return transactionData; } else { - print('Failed to details for asset: '); + logger.e('Failed to details for asset: '); } return null; @@ -358,8 +362,8 @@ class Client { fundedTransaction!.sign(_keyPair, _stellarNetwork); - print('Sending to'); - print( + logger.i('Sending to'); + logger.i( '${_serviceUrls[_network.toString()]}/transactionfunding_service/fund_transaction'); try { @@ -371,7 +375,7 @@ class Client { {'transaction': fundedTransaction.toEnvelopeXdrBase64()}), ); - print(response.body); + logger.i(response.body); } catch (error) { throw Exception('Something went wrong! $error'); } @@ -407,11 +411,11 @@ class Client { transactionDetails.add(details); } } else { - print("Unhandled operation type: ${response.runtimeType}"); + logger.i("Unhandled operation type: ${response.runtimeType}"); } } } else { - print("No payment records found."); + logger.i("No payment records found."); } return transactionDetails; } @@ -448,7 +452,7 @@ class Client { final body = jsonDecode(response.body); if (body['vesting_accounts'] is List && body['vesting_accounts'].isEmpty) { - print("no vesting account found"); + logger.i("no vesting account found"); return []; } else { List accountsList = []; diff --git a/packages/stellar_client/lib/stellar_client.dart b/packages/stellar_client/lib/stellar_client.dart index ab471557..fe24030b 100644 --- a/packages/stellar_client/lib/stellar_client.dart +++ b/packages/stellar_client/lib/stellar_client.dart @@ -11,6 +11,6 @@ import 'package:stellar_client/models/transaction.dart'; import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart'; import 'package:http/http.dart' as http; import 'package:convert/convert.dart'; - +import 'package:logger/logger.dart'; part 'src/client.dart'; part 'src/network_types.dart'; diff --git a/packages/stellar_client/pubspec.lock b/packages/stellar_client/pubspec.lock index f6f8069d..e5b0e43b 100644 --- a/packages/stellar_client/pubspec.lock +++ b/packages/stellar_client/pubspec.lock @@ -206,6 +206,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0" + logger: + dependency: "direct dev" + description: + name: logger + sha256: "697d067c60c20999686a0add96cf6aba723b3aa1f83ecf806a8097231529ec32" + url: "https://pub.dev" + source: hosted + version: "2.4.0" logging: dependency: transitive description: diff --git a/packages/stellar_client/pubspec.yaml b/packages/stellar_client/pubspec.yaml index 738d613d..a13017f1 100644 --- a/packages/stellar_client/pubspec.yaml +++ b/packages/stellar_client/pubspec.yaml @@ -13,6 +13,7 @@ dependencies: dev_dependencies: lints: ^3.0.0 test: ^1.24.0 + logger: ^2.4.0 scripts: test: --coverage=coverage