Skip to content

Commit fff0b66

Browse files
authored
Merge pull request #108 from threefoldtech/main_add_logger
Add logger to stellar
2 parents 6e1987b + 4ec7682 commit fff0b66

File tree

4 files changed

+35
-22
lines changed

4 files changed

+35
-22
lines changed

packages/stellar_client/lib/src/client.dart

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class Client {
1212
String get secretSeed => _keyPair.secretSeed;
1313
Uint8List? get privateKey => _keyPair.privateKey;
1414

15+
var logger = Logger(
16+
printer: PrettyPrinter(),
17+
);
18+
1519
Client(this._network, String secretSeed) {
1620
_keyPair = KeyPair.fromSecretSeed(secretSeed);
1721
_initialize();
@@ -70,8 +74,8 @@ class Client {
7074
if (transaction != null) {
7175
transaction.sign(_keyPair, _stellarNetwork);
7276
await _sdk.submitTransaction(transaction);
73-
print("Account Activated Successfully.");
74-
print("TFT Asset was added Successfully ");
77+
logger.i("Account Activated Successfully.");
78+
logger.i("TFT Asset was added Successfully ");
7579
return true;
7680
} else {
7781
throw Exception("Failed to retrieve activation transaction.");
@@ -109,13 +113,13 @@ class Client {
109113
try {
110114
bool funded = await FriendBot.fundTestAccount(accountId);
111115
if (funded) {
112-
print("Account funded successfully");
116+
logger.i("Account funded successfully");
113117
} else {
114-
print("Failed to fund account");
118+
logger.e("Failed to fund account");
115119
}
116120
return funded;
117121
} catch (error) {
118-
print("Error while funding account: $error");
122+
logger.e("Error while funding account: $error");
119123
return false;
120124
}
121125
}
@@ -143,15 +147,15 @@ class Client {
143147
await _sdk.submitTransaction(transaction);
144148

145149
if (!response.success) {
146-
print("Failed to add trustline for $currencyCode");
150+
logger.e("Failed to add trustline for $currencyCode");
147151
return false;
148152
} else {
149-
print("trustline for $currencyCode was added successfully");
153+
logger.i("trustline for $currencyCode was added successfully");
150154
return true;
151155
}
152156
}
153157

154-
print("No trustlines were processed");
158+
logger.i("No trustlines were processed");
155159
return false;
156160
}
157161

@@ -169,10 +173,10 @@ class Client {
169173

170174
transaction!.sign(_keyPair, _stellarNetwork);
171175
await _sdk.submitTransaction(transaction);
172-
print("Transaction successful.");
176+
logger.i("Transaction successful.");
173177
return true;
174178
} catch (error) {
175-
print("Failed to send transaction: $error");
179+
logger.e("Failed to send transaction: $error");
176180
return false;
177181
}
178182
}
@@ -194,7 +198,7 @@ class Client {
194198
await _sdk.submitTransaction(transaction);
195199
return true;
196200
} catch (error) {
197-
print("Failed to create account $error");
201+
logger.e("Failed to create account $error");
198202
return false;
199203
}
200204
}
@@ -232,10 +236,10 @@ class Client {
232236
await _sdk.submitTransaction(transaction);
233237

234238
if (response2.success) {
235-
print("Trustline for $asset_code added successfully.");
239+
logger.i("Trustline for $asset_code added successfully.");
236240
return true;
237241
} else {
238-
print("Failed to add trustline for $asset_code.");
242+
logger.e("Failed to add trustline for $asset_code.");
239243
return false;
240244
}
241245
} catch (error) {
@@ -263,10 +267,10 @@ class Client {
263267

264268
if (details != null) {
265269
TransactionData transactionData = TransactionData.fromJson(details);
266-
print(transactionData);
270+
logger.i(transactionData);
267271
return transactionData;
268272
} else {
269-
print('Failed to details for asset: ');
273+
logger.e('Failed to details for asset: ');
270274
}
271275

272276
return null;
@@ -358,8 +362,8 @@ class Client {
358362

359363
fundedTransaction!.sign(_keyPair, _stellarNetwork);
360364

361-
print('Sending to');
362-
print(
365+
logger.i('Sending to');
366+
logger.i(
363367
'${_serviceUrls[_network.toString()]}/transactionfunding_service/fund_transaction');
364368

365369
try {
@@ -371,7 +375,7 @@ class Client {
371375
{'transaction': fundedTransaction.toEnvelopeXdrBase64()}),
372376
);
373377

374-
print(response.body);
378+
logger.i(response.body);
375379
} catch (error) {
376380
throw Exception('Something went wrong! $error');
377381
}
@@ -407,11 +411,11 @@ class Client {
407411
transactionDetails.add(details);
408412
}
409413
} else {
410-
print("Unhandled operation type: ${response.runtimeType}");
414+
logger.i("Unhandled operation type: ${response.runtimeType}");
411415
}
412416
}
413417
} else {
414-
print("No payment records found.");
418+
logger.i("No payment records found.");
415419
}
416420
return transactionDetails;
417421
}
@@ -438,7 +442,7 @@ class Client {
438442
final body = jsonDecode(response.body);
439443
if (body['vesting_accounts'] is List &&
440444
body['vesting_accounts'].isEmpty) {
441-
print("no vesting account found");
445+
logger.i("no vesting account found");
442446
return [];
443447
} else {
444448
List<VestingAccount> accountsList = [];

packages/stellar_client/lib/stellar_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package:stellar_client/models/transaction.dart';
1111
import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart';
1212
import 'package:http/http.dart' as http;
1313
import 'package:convert/convert.dart';
14-
14+
import 'package:logger/logger.dart';
1515
part 'src/client.dart';
1616
part 'src/network_types.dart';
1717
part 'src/helpers.dart';

packages/stellar_client/pubspec.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ packages:
206206
url: "https://pub.dev"
207207
source: hosted
208208
version: "3.0.0"
209+
logger:
210+
dependency: "direct dev"
211+
description:
212+
name: logger
213+
sha256: "697d067c60c20999686a0add96cf6aba723b3aa1f83ecf806a8097231529ec32"
214+
url: "https://pub.dev"
215+
source: hosted
216+
version: "2.4.0"
209217
logging:
210218
dependency: transitive
211219
description:

packages/stellar_client/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dependencies:
1313
dev_dependencies:
1414
lints: ^3.0.0
1515
test: ^1.24.0
16+
logger: ^2.4.0
1617

1718
scripts:
1819
test: --coverage=coverage

0 commit comments

Comments
 (0)