Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #9384 from EOSIO/sk-to-dev-account-query-db-port-f…
Browse files Browse the repository at this point in the history
…rom-20

develop version of "Account Query DB : maintain get_(key|controlled)_accounts"
  • Loading branch information
nksanthosh authored Aug 26, 2020
2 parents 2795d45 + 4c9e213 commit 444c09e
Show file tree
Hide file tree
Showing 12 changed files with 880 additions and 14 deletions.
60 changes: 60 additions & 0 deletions plugins/chain_api_plugin/chain.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,63 @@ paths:
more:
type: integer
description: "In case there's more activated protocol features than the input parameter `limit` requested, returns the ordinal of the next activated protocol feature which was not returned, otherwise zero."
/get_accounts_by_authorizers:
post:
description: Given a set of account names and public keys, find all account permission authorities that are, in part or whole, satisfiable
operationId: get_accounts_by_authorizers
requestBody:
content:
application/json:
schema:
type: object
properties:
accounts:
type: array
description: List of authorizing accounts and/or actor/permissions
items:
anyOf:
- $ref: "https://eosio.github.io/schemata/v2.0/oas/Name.yaml"
- $ref: "https://eosio.github.io/schemata/v2.0/oas/Authority.yaml"
keys:
type: array
description: List of authorizing keys
items:
$ref: "https://eosio.github.io/schemata/v2.0/oas/PublicKey.yaml"
responses:
"200":
description: OK
content:
application/json:
schema:
type: object
description: Result containing a list of accounts which are authorized, in whole or part, by the provided accounts and keys
required:
- accounts
properties:
accounts:
type: array
description: An array of each account,permission,authorizing-data triplet in the response
items:
type: object
description: the information for a single account,permission,authorizing-data triplet
required:
- account_name
- permission_name
- authorizer
- weight
- threshold
properties:
account_name:
$ref: "https://eosio.github.io/schemata/v2.0/oas/Name.yaml"
permission_name:
$ref: "https://eosio.github.io/schemata/v2.0/oas/Name.yaml"
authorizer:
oneOf:
- $ref: "https://eosio.github.io/schemata/v2.0/oas/PublicKey.yaml"
- $ref: "https://eosio.github.io/schemata/v2.0/oas/Authority.yaml"
weight:
type: "integer"
description: the weight that this authorizer adds to satisfy the permission
threshold:
type: "integer"
description: the sum of weights that must be met or exceeded to satisfy the permission
34 changes: 31 additions & 3 deletions plugins/chain_api_plugin/chain_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ struct async_result_visitor : public fc::visitor<fc::variant> {
}
};

namespace {
template<typename T>
T parse_params(const std::string& body) {
if (body.empty()) {
EOS_THROW(chain::invalid_http_request, "A Request body is required");
}

try {
try {
return fc::json::from_string(body).as<T>();
} catch (const chain::chain_exception& e) { // EOS_RETHROW_EXCEPTIONS does not re-type these so, re-code it
throw fc::exception(e);
}
} EOS_RETHROW_EXCEPTIONS(chain::invalid_http_request, "Unable to parse valid input from POST body");
}
}

#define CALL_WITH_400(api_name, api_handle, api_namespace, call_name, http_response_code, params_type) \
{std::string("/v1/" #api_name "/" #call_name), \
[api_handle](string, string body, url_response_callback cb) mutable { \
Expand Down Expand Up @@ -73,12 +90,17 @@ struct async_result_visitor : public fc::visitor<fc::variant> {
#define CHAIN_RO_CALL_ASYNC(call_name, call_result, http_response_code, params_type) CALL_ASYNC_WITH_400(chain, ro_api, chain_apis::read_only, call_name, call_result, http_response_code, params_type)
#define CHAIN_RW_CALL_ASYNC(call_name, call_result, http_response_code, params_type) CALL_ASYNC_WITH_400(chain, rw_api, chain_apis::read_write, call_name, call_result, http_response_code, params_type)

#define CHAIN_RO_CALL_WITH_400(call_name, http_response_code, params_type) CALL_WITH_400(chain, ro_api, chain_apis::read_only, call_name, http_response_code, params_type)



void chain_api_plugin::plugin_startup() {
ilog( "starting chain_api_plugin" );
my.reset(new chain_api_plugin_impl(app().get_plugin<chain_plugin>().chain()));
auto ro_api = app().get_plugin<chain_plugin>().get_read_only_api();
auto rw_api = app().get_plugin<chain_plugin>().get_read_write_api();

auto& chain = app().get_plugin<chain_plugin>();
auto ro_api = chain.get_read_only_api();
auto rw_api = chain.get_read_write_api();

auto& _http_plugin = app().get_plugin<http_plugin>();
ro_api.set_shorten_abi_errors( !_http_plugin.verbose_errors() );

Expand Down Expand Up @@ -111,6 +133,12 @@ void chain_api_plugin::plugin_startup() {
CHAIN_RW_CALL_ASYNC(push_transactions, chain_apis::read_write::push_transactions_results, 202, http_params_types::params_required),
CHAIN_RW_CALL_ASYNC(send_transaction, chain_apis::read_write::send_transaction_results, 202, http_params_types::params_required)
});

if (chain.account_queries_enabled()) {
_http_plugin.add_async_api({
CHAIN_RO_CALL_WITH_400(get_accounts_by_authorizers, 200, http_params_types::params_required),
});
}
}

void chain_api_plugin::plugin_shutdown() {}
Expand Down
3 changes: 3 additions & 0 deletions plugins/chain_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
file(GLOB HEADERS "include/eosio/chain_plugin/*.hpp")
add_library( chain_plugin
account_query_db.cpp
chain_plugin.cpp
${HEADERS} )

Expand All @@ -10,3 +11,5 @@ endif()

target_link_libraries( chain_plugin eosio_chain appbase resource_monitor_plugin )
target_include_directories( chain_plugin PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../chain_interface/include" "${CMAKE_CURRENT_SOURCE_DIR}/../../libraries/appbase/include" "${CMAKE_CURRENT_SOURCE_DIR}/../resource_monitor_plugin/include")

add_subdirectory( test )
Loading

0 comments on commit 444c09e

Please sign in to comment.