Skip to content

Commit

Permalink
revert e6ef68e new import API /chain/get_accounts_by_authorizers
Browse files Browse the repository at this point in the history
  • Loading branch information
chuck-h committed Jun 11, 2024
1 parent 3e99a29 commit b0c0df6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 31 deletions.
19 changes: 4 additions & 15 deletions lib/crypto/eosdart/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,10 @@ class EOSClient {
}

/// Get Key Accounts
// Get Key Accounts using new API: new get_accounts_by_authorizers API
Future<AccountNames> getAccountsByKey(String pubKey) async {
try {
return _post('/chain/get_accounts_by_authorizers', {
'accounts': [],
'keys': [pubKey]
}).then((response) {
final List<String> accountNames = List.from(response['accounts'].map((e) => e['account_name']));
return AccountNames()..accountNames = accountNames.toSet().toList();
});
} catch (e) {
print("getAccountsByKey error $e");
return AccountNames();
}
Future<AccountNames> getKeyAccounts(String pubKey) async {
return _post('/history/get_key_accounts', {'public_key': pubKey}).then((accountNames) {
return AccountNames.fromJson(accountNames as Map<String, dynamic>);
});
}

// Get Key Accounts using new API: new get_accounts_by_authorizers API
Expand Down
28 changes: 14 additions & 14 deletions lib/datasource/remote/api/key_accounts_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,47 @@ import 'package:seeds/datasource/remote/api/http_repo/http_repository.dart';

class KeyAccountsRepository extends HttpRepository {

Future<Result<dynamic>> getAccountsByKey(String publicKey) {
print('[http] getAccountsByKey');
Future<Result<dynamic>> getKeyAccounts(String publicKey) {
print('[http] getKeyAccounts');

final url = Uri.parse('$baseURL/v1/chain/get_accounts_by_authorizers');
final body = '{ "accounts": [], "keys": ["$publicKey"] }';
final url = Uri.parse('$baseURL/v1/history/get_key_accounts');
final body = '{ "public_key": "$publicKey" }';

return http
.post(url, headers: headers, body: body)
.then((http.Response response) => mapHttpResponse(response, (dynamic body) {
print('result: $body');
// restriction to `active` permission matches ProfileRepository.getAccountPublicKeys
final result =
List<dynamic>.from(body['accounts'] as List).cast<Map<String, dynamic>>()
.where((e) => e['permission_name'] as String == 'active')
.map((e) => e['account_name'] as String).toList().toSet().toList();

final result = List<String>.from(body['account_names'] as Iterable);

result.sort();

return result;
}))
.catchError((dynamic error) => mapHttpError(error));
}

}

// Future<Result<dynamic>> getAccountsByKey(String publicKey) {
// print('[http] getAccountsByKey');

// final url = Uri.parse('$baseURL/v1/chain/get_accounts_by_authorizers');
// final body = '{ "accounts": [], "keys": []"$publicKey"] }';
// final body = '{ "accounts": [], "keys": ["$publicKey"] }';

// return http
// .post(url, headers: headers, body: body)
// .then((http.Response response) => mapHttpResponse(response, (dynamic body) {
// print('result: $body');

// // restriction to `active` permission matches ProfileRepository.getAccountPublicKeys
// final result =
// List<dynamic>.from(body['accounts']).map((e) => e['account_name']).toList().toSet().toList();
// List<dynamic>.from(body['accounts'] as List).cast<Map<String, dynamic>>()
// .where((e) => e['permission_name'] as String == 'active')
// .map((e) => e['account_name'] as String).toList().toSet().toList();

// result.sort();

// return result;
// }))
// .catchError((dynamic error) => mapHttpError(error));
// }
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ImportKeyUseCase {
final ProfileRepository _profileRepository = ProfileRepository();

Future<List<Result>> run(String publicKey) async {
final accountsResponse = await _keyAccountsRepository.getAccountsByKey(publicKey);
final accountsResponse = await _keyAccountsRepository.getKeyAccounts(publicKey);
if (accountsResponse.isError) {
final List<Result> items = [accountsResponse];
return items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ImportAccountsUseCase {

Future<List<Result>> run(List<String> publicKeys) async {
final List<Future<Result>> getKeyAccountsFutures =
publicKeys.map((i) => _keyAccountsRepository.getAccountsByKey(i)).toList();
publicKeys.map((i) => _keyAccountsRepository.getKeyAccounts(i)).toList();

final List<Result> keyAccountsResponse = await Future.wait(getKeyAccountsFutures);
if (keyAccountsResponse.singleWhereOrNull((i) => i.isError) != null) {
Expand Down

0 comments on commit b0c0df6

Please sign in to comment.