action.h 5.1 KB
Newer Older
1 2 3 4
/**
 *  @file
 *  @copyright defined in eos/LICENSE.txt
 */
5
#pragma once
6
#include <eosiolib/system.h>
7 8 9

extern "C" {
   /**
10
    * @defgroup actionapi Action API
11
    * @ingroup contractdev
K
Kevin Heifner 已提交
12
    * @brief Define API for querying action properties
13
    *
A
Andrianto Lie 已提交
14 15 16
    */

   /**
K
Kevin Heifner 已提交
17 18 19
    * @defgroup actioncapi Action C API
    * @ingroup actionapi
    * @brief Define API for querying action properties
A
Andrianto Lie 已提交
20 21
    *
    *
K
Kevin Heifner 已提交
22
    * A EOS.IO action has the following abstract structure:
23 24
    *
    * ```
K
Kevin Heifner 已提交
25 26 27 28
    *   struct action {
    *     scope_name scope; // the contract defining the primary code to execute for code/type
    *     action_name name; // the action to be taken
    *     permission_level[] authorization; // the accounts and permission levels provided
29
    *     bytes data; // opaque data processed by code
30 31
    *   };
    * ```
32
    *
K
Kevin Heifner 已提交
33
    * This API enables your contract to inspect the fields on the current action and act accordingly.
34
    *
A
Andrianto Lie 已提交
35 36
    * Example:
    * @code
K
Kevin Heifner 已提交
37
    * // Assume this action is used for the following examples:
A
Andrianto Lie 已提交
38 39 40 41 42 43 44 45 46 47 48 49
    * // {
    * //  "code": "eos",
    * //  "type": "transfer",
    * //  "authorization": [{ "account": "inita", "permission": "active" }],
    * //  "data": {
    * //    "from": "inita",
    * //    "to": "initb",
    * //    "amount": 1000
    * //  }
    * // }
    *
    * char buffer[128];
K
Kevin Heifner 已提交
50
    * uint32_t total = read_action(buffer, 5); // buffer contains the content of the action up to 5 bytes
A
Andrianto Lie 已提交
51 52
    * print(total); // Output: 5
    *
53
    * uint32_t msgsize = action_size();
K
Kevin Heifner 已提交
54
    * print(msgsize); // Output: size of the above action's data field
A
Andrianto Lie 已提交
55
    *
K
Kevin Heifner 已提交
56
    * require_recipient(N(initc)); // initc account will be notified for this action
A
Andrianto Lie 已提交
57
    *
58 59
    * require_auth(N(inita)); // Do nothing since inita exists in the auth list
    * require_auth(N(initb)); // Throws an exception
A
Andrianto Lie 已提交
60 61 62 63 64
    *
    * print(now()); // Output: timestamp of last accepted block
    *
    * @endcode
    *
65 66 67 68 69
    *
    * @{
    */

   /**
70 71 72 73
    *  Copy up to @ref len bytes of current action data to the specified location
    *  @brief Copy current action data to the specified location
    *  @param msg - a pointer where up to @ref len bytes of the current action data will be copied
    *  @param len - len of the current action data to be copied
74 75
    *  @return the number of bytes copied to msg
    */
76
   uint32_t read_action_data( void* msg, uint32_t len );
77 78

   /**
K
Kevin Heifner 已提交
79 80 81 82
    * Get the length of the current action's data field
    * This method is useful for dynamically sized actions
    * @brief Get the length of current action's data field
    * @return the length of the current action's data field
83
    */
84
   uint32_t action_data_size();
85 86

   /**
87 88
    *  Add the specified account to set of accounts to be notified
    *  @brief Add the specified account to set of accounts to be notified
89
    *  @param name - name of the account to be verified
90
    */
91
   void require_recipient( account_name name );
92 93

   /**
K
Kevin Heifner 已提交
94
    *  Verifies that @ref name exists in the set of provided auths on a action. Throws if not found
95 96
    *  @brief Verify specified account exists in the set of provided auths
    *  @param name - name of the account to be verified
97
    */
98
   void require_auth( account_name name );
D
Daniel Larimer 已提交
99
   bool has_auth( account_name name );
100

101 102 103 104 105 106 107 108
   /**
    *  Verifies that @ref name exists in the set of provided auths on a action. Throws if not found
    *  @brief Verify specified account exists in the set of provided auths
    *  @param name - name of the account to be verified
    *  @param permission - permission level to be verified
    */
   void require_auth2( account_name name, permission_name permission );

109 110
   /**
    *  Send an inline action in the context of this action's parent transaction
111 112
    * @param serialized_action - serialized action 
    * @param size - size of serialized action in bytes
113 114 115
    */
   void send_inline(char *serialized_action, size_t size);

M
Matias Romeo 已提交
116 117 118 119 120 121 122
   /**
    *  Send an inline context free action in the context of this action's parent transaction
    * @param serialized_action - serialized action
    * @param size - size of serialized action in bytes
    */
   void send_context_free_inline(char *serialized_action, size_t size);

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
   /**
    *  Verifies that @ref name exists in the set of write locks held on a action. Throws if not found
    *  @brief Verifies that @ref name exists in the set of write locks held
    *  @param name - name of the account to be verified
    */
   void require_write_lock( account_name name );

   /**
    *  Verifies that @ref name exists in the set of read locks held on a action. Throws if not found
    *  @brief Verifies that @ref name exists in the set of read locks held
    *  @param name - name of the account to be verified
    */
   void require_read_lock( account_name name );

   /**
    *  Returns the time in seconds from 1970 of the publication_time
    *  @brief Get the publication time
    *  @return the time in seconds from 1970 of the publication_time
    */
   time  publication_time();

   /**
    *  Get the account which specifies the sender of the action
    *  @brief Get the sender of the action
    *  @return the account which specifies the sender of the action
    */
   account_name current_sender();
K
Kevin Heifner 已提交
150
   ///@ } actioncapi
151
}