action.hpp 2.0 KB
Newer Older
1 2 3 4
/**
 *  @file
 *  @copyright defined in eos/LICENSE.txt
 */
5
#pragma once
6
#include <eoslib/action.h>
7
#include <eoslib/print.hpp>
8

P
Pravin 已提交
9
namespace eosio {
10 11

   /**
12 13 14
    * @defgroup actioncppapi Action C++ API
    * @ingroup actionapi
    * @brief Type-safe C++ wrapers for Action C API
15
    *
16
    * @note There are some methods from the @ref actioncapi that can be used directly from C++
17
    *
18
    * @{
19 20 21
    */

   /**
22
    *
23 24
    *  This method attempts to reinterpret the action body as type T. This will only work
    *  if the action has no dynamic fields and the struct packing on type T is properly defined.
25
    *
26
    *  @brief Interpret the action body as type T
27 28
    *  
    *  Example:
29
    *  @code
30
    *  struct dummy_action {
31 32 33
    *    char a; //1
    *    unsigned long long b; //8
    *    int  c; //4
34
    *  };
35
    *  dummy_action msg = current_action<dummy_action>();
36
    *  @endcode
37 38
    */
   template<typename T>
39
   T current_action() {
40
      T value;
41 42
      auto read = read_action( &value, sizeof(value) );
      assert( read >= sizeof(value), "action shorter than expected" );
43 44 45
      return value;
   }

46 47
   using ::require_auth;
   using ::require_notice;
48 49

   /**
50
    *  All of the listed accounts will be added to the set of accounts to be notified
51
    *
52
    *  This helper method enables you to add multiple accounts to accounts to be notified list with a single
53 54
    *  call rather than having to call the similar C API multiple times.
    *
55
    *  @note action.code is also considered as part of the set of notified accounts
56 57
    *
    *  @brief Verify specified accounts exist in the set of notified accounts
58 59
    *
    *  Example:
60
    *  @code
61
    *  require_notice(N(Account1), N(Account2), N(Account3)); // throws exception if any of them not in set.
62
    *  @endcode
63
    */
64 65
   template<typename... accounts>
   void require_notice( account_name name, accounts... remaining_accounts ){
66
      require_notice( name );
67
      require_notice( remaining_accounts... );
68 69 70
   }


71
 ///@} actioncpp api
72 73

} // namespace eos