From 738abf03afe3eb4fd41ac83166c7877dbc10fb9e Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Wed, 23 Sep 2015 18:22:38 -0400 Subject: [PATCH] adding API call to get potential address sigs: Fix #337 --- libraries/app/database_api.cpp | 30 +++++++++++++++++++ .../app/include/graphene/app/database_api.hpp | 2 ++ .../graphene/chain/protocol/authority.hpp | 9 ++++++ 3 files changed, 41 insertions(+) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 3d371bae15..5554f5ab1a 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -92,6 +92,7 @@ class database_api_impl : public std::enable_shared_from_this std::string get_transaction_hex(const signed_transaction& trx)const; set get_required_signatures( const signed_transaction& trx, const flat_set& available_keys )const; set get_potential_signatures( const signed_transaction& trx )const; + set
get_potential_address_signatures( const signed_transaction& trx )const; bool verify_authority( const signed_transaction& trx )const; bool verify_account_authority( const string& name_or_id, const flat_set& signers )const; processed_transaction validate_transaction( const signed_transaction& trx )const; @@ -1213,6 +1214,10 @@ set database_api::get_potential_signatures( const signed_transa { return my->get_potential_signatures( trx ); } +set
database_api::get_potential_address_signatures( const signed_transaction& trx )const +{ + return my->get_potential_address_signatures( trx ); +} set database_api_impl::get_potential_signatures( const signed_transaction& trx )const { @@ -1242,6 +1247,31 @@ set database_api_impl::get_potential_signatures( const signed_t return result; } +set
database_api_impl::get_potential_address_signatures( const signed_transaction& trx )const +{ + set
result; + trx.get_required_signatures( + _db.get_chain_id(), + flat_set(), + [&]( account_id_type id ) + { + const auto& auth = id(_db).active; + for( const auto& k : auth.get_addresses() ) + result.insert(k); + return &auth; + }, + [&]( account_id_type id ) + { + const auto& auth = id(_db).owner; + for( const auto& k : auth.get_addresses() ) + result.insert(k); + return &auth; + }, + _db.get_global_properties().parameters.max_authority_depth + ); + return result; +} + bool database_api::verify_authority( const signed_transaction& trx )const { return my->verify_authority( trx ); diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 4aedd0edc2..a0503fd6a2 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -416,6 +416,7 @@ class database_api * to get the minimum subset. */ set get_potential_signatures( const signed_transaction& trx )const; + set
get_potential_address_signatures( const signed_transaction& trx )const; /** * @return true of the @ref trx has all of the required signatures, otherwise throws an exception @@ -536,6 +537,7 @@ FC_API(graphene::app::database_api, (get_transaction_hex) (get_required_signatures) (get_potential_signatures) + (get_potential_address_signatures) (verify_authority) (verify_account_authority) (validate_transaction) diff --git a/libraries/chain/include/graphene/chain/protocol/authority.hpp b/libraries/chain/include/graphene/chain/protocol/authority.hpp index 0c7d1ac027..b297fb6b2c 100644 --- a/libraries/chain/include/graphene/chain/protocol/authority.hpp +++ b/libraries/chain/include/graphene/chain/protocol/authority.hpp @@ -83,6 +83,15 @@ namespace graphene { namespace chain { result.push_back(k.first); return result; } + vector
get_addresses() const + { + vector
result; + result.reserve( address_auths.size() ); + for( const auto& k : address_auths ) + result.push_back(k.first); + return result; + } + friend bool operator == ( const authority& a, const authority& b ) {