Skip to content

Commit

Permalink
adding API call to get potential address sigs: Fix #337
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemaster committed Sep 23, 2015
1 parent 2afe62f commit 738abf0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
30 changes: 30 additions & 0 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
std::string get_transaction_hex(const signed_transaction& trx)const;
set<public_key_type> get_required_signatures( const signed_transaction& trx, const flat_set<public_key_type>& available_keys )const;
set<public_key_type> get_potential_signatures( const signed_transaction& trx )const;
set<address> 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<public_key_type>& signers )const;
processed_transaction validate_transaction( const signed_transaction& trx )const;
Expand Down Expand Up @@ -1213,6 +1214,10 @@ set<public_key_type> database_api::get_potential_signatures( const signed_transa
{
return my->get_potential_signatures( trx );
}
set<address> database_api::get_potential_address_signatures( const signed_transaction& trx )const
{
return my->get_potential_address_signatures( trx );
}

set<public_key_type> database_api_impl::get_potential_signatures( const signed_transaction& trx )const
{
Expand Down Expand Up @@ -1242,6 +1247,31 @@ set<public_key_type> database_api_impl::get_potential_signatures( const signed_t
return result;
}

set<address> database_api_impl::get_potential_address_signatures( const signed_transaction& trx )const
{
set<address> result;
trx.get_required_signatures(
_db.get_chain_id(),
flat_set<public_key_type>(),
[&]( 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 );
Expand Down
2 changes: 2 additions & 0 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ class database_api
* to get the minimum subset.
*/
set<public_key_type> get_potential_signatures( const signed_transaction& trx )const;
set<address> 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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions libraries/chain/include/graphene/chain/protocol/authority.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ namespace graphene { namespace chain {
result.push_back(k.first);
return result;
}
vector<address> get_addresses() const
{
vector<address> 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 )
{
Expand Down

0 comments on commit 738abf0

Please sign in to comment.