Skip to content

Commit 27064bb

Browse files
authored
Merge pull request #989 from oxarbitrage/issue969
support account names or ids in all api calls
2 parents e11bb80 + 3081938 commit 27064bb

File tree

6 files changed

+262
-226
lines changed

6 files changed

+262
-226
lines changed

libraries/app/api.cpp

+18-9
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ namespace graphene { namespace app {
308308
return result;
309309
}
310310

311-
vector<operation_history_object> history_api::get_account_history( account_id_type account,
311+
vector<operation_history_object> history_api::get_account_history( const std::string account_id_or_name,
312312
operation_history_id_type stop,
313313
unsigned limit,
314314
operation_history_id_type start ) const
@@ -317,7 +317,9 @@ namespace graphene { namespace app {
317317
const auto& db = *_app.chain_database();
318318
FC_ASSERT( limit <= 100 );
319319
vector<operation_history_object> result;
320+
account_id_type account;
320321
try {
322+
account = database_api.get_account_id_from_string(account_id_or_name);
321323
const account_transaction_history_object& node = account(db).statistics(db).most_recent_op(db);
322324
if(start == operation_history_id_type() || start.instance.value > node.operation_id.instance.value)
323325
start = node.operation_id;
@@ -341,7 +343,7 @@ namespace graphene { namespace app {
341343
return result;
342344
}
343345

344-
vector<operation_history_object> history_api::get_account_history_operations( account_id_type account,
346+
vector<operation_history_object> history_api::get_account_history_operations( const std::string account_id_or_name,
345347
int operation_id,
346348
operation_history_id_type start,
347349
operation_history_id_type stop,
@@ -351,6 +353,10 @@ namespace graphene { namespace app {
351353
const auto& db = *_app.chain_database();
352354
FC_ASSERT( limit <= 100 );
353355
vector<operation_history_object> result;
356+
account_id_type account;
357+
try {
358+
account = database_api.get_account_id_from_string(account_id_or_name);
359+
} catch(...) { return result; }
354360
const auto& stats = account(db).statistics(db);
355361
if( stats.most_recent_op == account_transaction_history_id_type() ) return result;
356362
const account_transaction_history_object* node = &stats.most_recent_op(db);
@@ -377,7 +383,7 @@ namespace graphene { namespace app {
377383
}
378384

379385

380-
vector<operation_history_object> history_api::get_relative_account_history( account_id_type account,
386+
vector<operation_history_object> history_api::get_relative_account_history( const std::string account_id_or_name,
381387
uint32_t stop,
382388
unsigned limit,
383389
uint32_t start) const
@@ -386,13 +392,16 @@ namespace graphene { namespace app {
386392
const auto& db = *_app.chain_database();
387393
FC_ASSERT(limit <= 100);
388394
vector<operation_history_object> result;
395+
account_id_type account;
396+
try {
397+
account = database_api.get_account_id_from_string(account_id_or_name);
398+
} catch(...) { return result; }
389399
const auto& stats = account(db).statistics(db);
390400
if( start == 0 )
391401
start = stats.total_ops;
392402
else
393403
start = min( stats.total_ops, start );
394404

395-
396405
if( start >= stop && start > stats.removed_ops && limit > 0 )
397406
{
398407
const auto& hist_idx = db.get_index_type<account_transaction_history_index>();
@@ -418,12 +427,12 @@ namespace graphene { namespace app {
418427
return hist->tracked_buckets();
419428
}
420429

421-
history_operation_detail history_api::get_account_history_by_operations(account_id_type account, vector<uint16_t> operation_types, uint32_t start, unsigned limit)
430+
history_operation_detail history_api::get_account_history_by_operations(const std::string account_id_or_name, vector<uint16_t> operation_types, uint32_t start, unsigned limit)
422431
{
423-
FC_ASSERT(limit <= 100);
424-
history_operation_detail result;
425-
vector<operation_history_object> objs = get_relative_account_history(account, start, limit, limit + start - 1);
426-
std::for_each(objs.begin(), objs.end(), [&](const operation_history_object &o) {
432+
FC_ASSERT(limit <= 100);
433+
history_operation_detail result;
434+
vector<operation_history_object> objs = get_relative_account_history(account_id_or_name, start, limit, limit + start - 1);
435+
std::for_each(objs.begin(), objs.end(), [&](const operation_history_object &o) {
427436
if (operation_types.empty() || find(operation_types.begin(), operation_types.end(), o.op.which()) != operation_types.end()) {
428437
result.operation_history_objs.push_back(o);
429438
}

0 commit comments

Comments
 (0)