Scorum
database_api.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #define API_DATABASE "database_api"
4 
5 #include <scorum/app/state.hpp>
6 
10 
12 
14 
16 
17 #include <fc/api.hpp>
18 #include <fc/optional.hpp>
19 #include <fc/variant_object.hpp>
20 
21 #include <fc/network/ip.hpp>
22 
23 #include <boost/container/flat_set.hpp>
24 
25 #include <functional>
26 #include <map>
27 #include <memory>
28 #include <vector>
29 
30 namespace scorum {
31 namespace app {
32 
33 using namespace scorum::chain;
34 using namespace scorum::protocol;
35 
36 struct api_context;
37 
39 {
40  std::string from_account;
41  std::string to_account;
42  uint16_t percent;
43  bool auto_vest;
44 };
45 
47 {
50  all
51 };
52 
53 class database_api_impl;
54 
66 {
67 public:
69  ~database_api();
70 
72  // Handlers - not exposed //
74  void on_api_startup();
75 
80 
81  void set_block_applied_callback(std::function<void(const variant& block_header)> cb);
82 
84 
89 
93  fc::variant_object get_config() const;
94 
98  chain_id_type get_chain_id() const;
99 
104  dynamic_global_property_api_obj get_dynamic_global_properties() const;
105 
111 
113 
118 
119  std::vector<std::set<std::string>> get_key_references(std::vector<public_key_type> key) const;
120 
121  std::vector<extended_account> get_accounts(const std::vector<std::string>& names) const;
122 
126  std::vector<account_id_type> get_account_references(account_id_type account_id) const;
127 
135  std::vector<optional<account_api_obj>> lookup_account_names(const std::vector<std::string>& account_names) const;
136 
143  std::set<std::string> lookup_accounts(const std::string& lower_bound_name, uint32_t limit) const;
144 
148  uint64_t get_account_count() const;
149 
150  std::vector<owner_authority_history_api_obj> get_owner_history(const std::string& account) const;
151 
152  optional<account_recovery_request_api_obj> get_recovery_request(const std::string& account) const;
153 
154  optional<escrow_api_obj> get_escrow(const std::string& from, uint32_t escrow_id) const;
155 
156  std::vector<withdraw_route> get_withdraw_routes(const std::string& account,
157  withdraw_route_type type = outgoing) const;
158 
159  optional<account_bandwidth_api_obj> get_account_bandwidth(const std::string& account,
160  witness::bandwidth_type type) const;
161 
162  std::vector<scorumpower_delegation_api_obj> get_scorumpower_delegations(const std::string& account,
163  const std::string& from,
164  uint32_t limit = 100) const;
165 
166  std::vector<scorumpower_delegation_expiration_api_obj> get_expiring_scorumpower_delegations(
167  const std::string& account, time_point_sec from, uint32_t limit = 100) const;
168 
170 
176 
177  std::vector<budget_api_obj> get_budgets(const budget_type, const std::set<std::string>& account_names) const;
178 
179  std::set<std::string>
180  lookup_budget_owners(const budget_type, const std::string& lower_bound_name, uint32_t limit) const;
181 
183 
188 
189  std::vector<atomicswap_contract_api_obj> get_atomicswap_contracts(const std::string& owner) const;
190 
192  get_atomicswap_contract(const std::string& from, const std::string& to, const std::string& secret_hash) const;
193 
195 
200 
208  std::vector<optional<witness_api_obj>> get_witnesses(const std::vector<witness_id_type>& witness_ids) const;
209 
215  fc::optional<witness_api_obj> get_witness_by_account(const std::string& account_name) const;
216 
222  std::vector<witness_api_obj> get_witnesses_by_vote(const std::string& from, uint32_t limit) const;
223 
230  std::set<account_name_type> lookup_witness_accounts(const std::string& lower_bound_name, uint32_t limit) const;
231 
232  std::vector<account_name_type> get_active_witnesses() const;
233 
237  uint64_t get_witness_count() const;
238 
240 
246 
250  std::set<account_name_type> lookup_registration_committee_members(const std::string& lower_bound_name,
251  uint32_t limit) const;
252 
256  std::set<account_name_type> lookup_development_committee_members(const std::string& lower_bound_name,
257  uint32_t limit) const;
258 
262  std::vector<proposal_api_obj> lookup_proposals() const;
263 
267  development_committee_api_obj get_development_committee() const;
268 
272  registration_committee_api_obj get_registration_committee() const;
273 
277  advertising_property_api_obj get_advertising_property() const;
278 
280 
285 
287  std::string get_transaction_hex(const signed_transaction& trx) const;
288 
294  std::set<public_key_type> get_required_signatures(const signed_transaction& trx,
295  const flat_set<public_key_type>& available_keys) const;
296 
304  std::set<public_key_type> get_potential_signatures(const signed_transaction& trx) const;
305 
309  bool verify_authority(const signed_transaction& trx) const;
310 
311  /*
312  * @return true if the signers have enough authority to authorize an account
313  */
314  bool verify_account_authority(const std::string& name_or_id, const flat_set<public_key_type>& signers) const;
315 
317 
322 
326  std::vector<vote_state> get_active_votes(const std::string& author, const std::string& permlink) const;
327  std::vector<account_vote> get_account_votes(const std::string& voter) const;
328 
330 
335 
341  nft_api_obj get_nft_by_id(int64_t id) const;
342 
348  nft_api_obj get_nft_by_name(const account_name_type& name) const;
349 
355  nft_api_obj get_nft_by_uuid(const uuid_type& uuid) const;
356 
363  std::vector<nft_api_obj> lookup_nft(int64_t from, uint32_t limit) const;
364 
370  game_round_api_obj get_game_round_by_uuid(const uuid_type& uuid) const;
371 
378  std::vector<game_round_api_obj> lookup_game_round(int64_t id, uint32_t limit) const;
379 
381 
382 private:
383  std::shared_ptr<database_api_impl> my;
384 };
385 } // namespace app
386 } // namespace scorum
387 
388 // clang-format off
389 
390 FC_REFLECT( scorum::app::withdraw_route, (from_account)(to_account)(percent)(auto_vest) )
391 
393 
395  // Subscriptions
396  (set_block_applied_callback)
397 
398  // Globals
399  (get_config)
400  (get_chain_id)
401  (get_dynamic_global_properties)
403 
404  // Accounts
405  (get_key_references)
406  (get_accounts)
407  (get_account_references)
408  (lookup_account_names)
409  (lookup_accounts)
410  (get_account_count)
411  (get_owner_history)
412  (get_recovery_request)
413  (get_escrow)
414  (get_withdraw_routes)
415  (get_account_bandwidth)
416  (get_scorumpower_delegations)
417  (get_expiring_scorumpower_delegations)
418 
419  // Authority / validation
420  (get_transaction_hex)
421  (get_required_signatures)
422  (get_potential_signatures)
424  (verify_account_authority)
425 
426  // votes
427  (get_active_votes)
428  (get_account_votes)
429 
430  // Witnesses
431  (get_witnesses)
432  (get_witness_by_account)
433  (get_witnesses_by_vote)
434  (lookup_witness_accounts)
435 
436  (get_active_witnesses)
437  (get_witness_count)
438 
439  // Budget
440  (get_budgets)
441  (lookup_budget_owners)
442 
443  // Committee
444  (lookup_registration_committee_members)
445  (lookup_development_committee_members)
446  (lookup_proposals)
447  (get_registration_committee)
448  (get_development_committee)
449  (get_advertising_property)
450 
451  // Atomic Swap
452  (get_atomicswap_contracts)
453  (get_atomicswap_contract)
454 
455  // NFT
456  (get_nft_by_id)
457  (get_nft_by_name)
458  (get_nft_by_uuid)
459  (lookup_nft)
460  (get_game_round_by_uuid)
461  (lookup_game_round)
462 )
463 
464 // clang-format on
FC_REFLECT_ENUM(scorum::protocol::game_status,(created)(started)(finished)(resolved)(expired)(cancelled)) namespace fc
Definition: game_status.hpp:18
FC_REFLECT(appender_args,(appender)(stream)) FC_REFLECT_DERIVED(file_appender_args
printable_schedule get_witness_schedule(const witness_schedule_object &wso, witness_service_i &witness_service)
const config & get_config()
Definition: config.cpp:164
fc::fixed_string_16 account_name_type
Definition: types.hpp:62
fc::sha256 chain_id_type
Definition: types.hpp:61
void verify_authority(const std::vector< operation > &ops, const flat_set< public_key_type > &sigs, const authority_getter &get_active, const authority_getter &get_owner, const authority_getter &get_posting, uint32_t max_recursion=SCORUM_MAX_SIG_CHECK_DEPTH, bool allow_committe=false, const flat_set< account_name_type > &active_aprovals=flat_set< account_name_type >(), const flat_set< account_name_type > &owner_aprovals=flat_set< account_name_type >(), const flat_set< account_name_type > &posting_approvals=flat_set< account_name_type >())
Definition: transaction.cpp:88
Definition: asset.cpp:15
boost::uuids::uuid uuid_type
Definition: types.hpp:53