Skip to content

Replace print w logger #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions packages/stellar_client/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -371,7 +375,7 @@ class Client {
{'transaction': fundedTransaction.toEnvelopeXdrBase64()}),
);

print(response.body);
logger.i(response.body);
} catch (error) {
throw Exception('Something went wrong! $error');
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<VestingAccount> accountsList = [];
Expand Down
1 change: 1 addition & 0 deletions packages/stellar_client/lib/stellar_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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';
8 changes: 8 additions & 0 deletions packages/stellar_client/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.0"
logger:
dependency: "direct main"
description:
name: logger
sha256: "697d067c60c20999686a0add96cf6aba723b3aa1f83ecf806a8097231529ec32"
url: "https://pub.dev"
source: hosted
version: "2.4.0"
logging:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions packages/stellar_client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ environment:
# Add regular dependencies here.
dependencies:
http: 1.2.0
logger: ^2.4.0
stellar_flutter_sdk: ^1.7.5

dev_dependencies:
Expand Down