Skip to content

Commit

Permalink
Merge pull request steemit#3169 from steemit/3144-smt-token-apis
Browse files Browse the repository at this point in the history
Add smt token API calls
  • Loading branch information
Michael Vandeberg authored Nov 19, 2018
2 parents 9f0fb32 + 08ea8c5 commit 55a2797
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,12 @@ typedef multi_index_container <
member< smt_token_object, smt_token_id_type, &smt_token_object::id > >,
ordered_unique< tag< by_symbol >,
member< smt_token_object, asset_symbol_type, &smt_token_object::liquid_symbol > >,
ordered_non_unique< tag< by_control_account >,
member< smt_token_object, account_name_type, &smt_token_object::control_account > >
ordered_unique< tag< by_control_account >,
composite_key< smt_token_object,
member< smt_token_object, account_name_type, &smt_token_object::control_account >,
member< smt_token_object, asset_symbol_type, &smt_token_object::liquid_symbol >
>
>
>,
allocator< smt_token_object >
> smt_token_index;
Expand Down
82 changes: 82 additions & 0 deletions libraries/plugins/apis/database_api/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <steem/protocol/exceptions.hpp>
#include <steem/protocol/transaction_util.hpp>

#include <steem/chain/util/smt_token.hpp>

#include <steem/utilities/git_revision.hpp>

#include <fc/git_revision.hpp>
Expand Down Expand Up @@ -70,6 +72,8 @@ class database_api_impl
(verify_signatures)
#ifdef STEEM_ENABLE_SMT
(get_nai_pool)
(list_smt_tokens)
(find_smt_tokens)
(list_smt_token_emissions)
(find_smt_token_emissions)
#endif
Expand Down Expand Up @@ -1456,6 +1460,82 @@ DEFINE_API_IMPL( database_api_impl, get_nai_pool )
return result;
}

DEFINE_API_IMPL( database_api_impl, list_smt_tokens )
{
FC_ASSERT( args.limit <= DATABASE_API_SINGLE_QUERY_LIMIT );

list_smt_tokens_return result;
result.tokens.reserve( args.limit );

switch( args.order )
{
case( by_symbol ):
{
asset_symbol_type start;

if( args.start.get_object().size() > 0 )
{
start = args.start.as< asset_symbol_type >();
}

iterate_results< chain::smt_token_index, chain::by_symbol >(
start,
result.tokens,
args.limit,
&database_api_impl::on_push_default< chain::smt_token_object > );

break;
}
case( by_control_account ):
{
boost::tuple< account_name_type, asset_symbol_type > start;

if( args.start.is_string() )
{
start = boost::make_tuple( args.start.as< account_name_type >(), asset_symbol_type() );
}
else
{
auto key = args.start.get_array();
FC_ASSERT( key.size() == 2, "The parameter 'start' must be an account name or an array containing an account name and an asset symbol" );

start = boost::make_tuple( key[0].as< account_name_type >(), key[1].as< asset_symbol_type >() );
}

iterate_results< chain::smt_token_index, chain::by_control_account >(
start,
result.tokens,
args.limit,
&database_api_impl::on_push_default< chain::smt_token_object > );

break;
}
default:
FC_ASSERT( false, "Unknown or unsupported sort order" );
}

return result;
}

DEFINE_API_IMPL( database_api_impl, find_smt_tokens )
{
FC_ASSERT( args.symbols.size() <= DATABASE_API_SINGLE_QUERY_LIMIT );

find_smt_tokens_return result;
result.tokens.reserve( args.symbols.size() );

for( auto& symbol : args.symbols )
{
const auto token = chain::util::smt::find_token( _db, symbol, args.ignore_precision );
if( token != nullptr )
{
result.tokens.push_back( *token );
}
}

return result;
}

DEFINE_API_IMPL( database_api_impl, list_smt_token_emissions )
{
FC_ASSERT( args.limit <= DATABASE_API_SINGLE_QUERY_LIMIT );
Expand Down Expand Up @@ -1558,6 +1638,8 @@ DEFINE_READ_APIS( database_api,
(verify_signatures)
#ifdef STEEM_ENABLE_SMT
(get_nai_pool)
(list_smt_tokens)
(find_smt_tokens)
(list_smt_token_emissions)
(find_smt_token_emissions)
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ class database_api
*/
(get_nai_pool)

(list_smt_tokens)
(find_smt_tokens)

(list_smt_token_emissions)
(find_smt_token_emissions)
#endif
Expand Down
Loading

0 comments on commit 55a2797

Please sign in to comment.