Scorum
auth_util_api.cpp
Go to the documentation of this file.
1 
4 
7 
10 
13 
14 #include <fc/container/flat.hpp>
15 
16 namespace scorum {
17 namespace plugin {
18 namespace auth_util {
19 
20 using boost::container::flat_set;
21 
22 namespace detail {
23 
25 {
26 public:
30 
31  std::shared_ptr<scorum::plugin::auth_util::auth_util_plugin> get_plugin();
32 
34 };
35 
37  : app(_app)
38 {
39 }
40 
41 std::shared_ptr<scorum::plugin::auth_util::auth_util_plugin> auth_util_api_impl::get_plugin()
42 {
43  return app.get_plugin<auth_util_plugin>("auth_util");
44 }
45 
48 {
49  std::shared_ptr<chain::database> db = app.chain_database();
50  const chain::account_authority_object& acct
51  = db->get<chain::account_authority_object, chain::by_account>(args.account_name);
53  if ((args.level == "posting") || (args.level == "p"))
54  {
55  auth = protocol::authority(acct.posting);
56  }
57  else if ((args.level == "active") || (args.level == "a") || (args.level == ""))
58  {
59  auth = protocol::authority(acct.active);
60  }
61  else if ((args.level == "owner") || (args.level == "o"))
62  {
63  auth = protocol::authority(acct.owner);
64  }
65  else
66  {
67  FC_ASSERT(false, "invalid level specified");
68  }
69  flat_set<protocol::public_key_type> signing_keys;
70  for (const protocol::signature_type& sig : args.sigs)
71  {
72  result.keys.emplace_back(fc::ecc::public_key(sig, args.dig, true));
73  signing_keys.insert(result.keys.back());
74  }
75 
76  flat_set<protocol::public_key_type> avail;
77  protocol::sign_state ss(signing_keys,
78  [&db](const std::string& account_name) -> const protocol::authority {
79  return protocol::authority(
80  db->get<chain::account_authority_object, chain::by_account>(account_name).active);
81  },
82  avail);
83 
84  bool has_authority = ss.check_authority(auth);
85  FC_ASSERT(has_authority);
86 
87  return;
88 }
89 
90 } // detail
91 
93 {
94  my = std::make_shared<detail::auth_util_api_impl>(ctx.app);
95 }
96 
98 {
99 }
100 
102 {
104  my->check_authority_signature(args, result);
105  return result;
106 }
107 }
108 }
109 } // scorum::plugin::auth_util
std::shared_ptr< chain::database > chain_database() const
std::shared_ptr< abstract_plugin > get_plugin(const std::string &name) const
auth_util_api(const scorum::app::api_context &ctx)
auth_util_api_impl(scorum::app::application &_app)
void check_authority_signature(const check_authority_signature_params &args, check_authority_signature_result &result)
std::shared_ptr< scorum::plugin::auth_util::auth_util_plugin > get_plugin()
check_authority_signature_result check_authority_signature(check_authority_signature_params args)
check_authority_signature
fc::ecc::compact_signature signature_type
Definition: types.hpp:67
Definition: asset.cpp:15
bool check_authority(const std::string &id)
Definition: sign_state.cpp:20