transaction.hpp 1.9 KB
Newer Older
1 2 3 4
/**
 *  @file
 *  @copyright defined in eos/LICENSE.txt
 */
5
#pragma once
6 7 8 9 10
#include <eosiolib/transaction.h>
#include <eosiolib/action.hpp>
#include <eosiolib/print.hpp>
#include <eosiolib/types.hpp>
#include <eosiolib/serialize.hpp>
11

P
Pravin 已提交
12
namespace eosio {
13 14

   /**
15
    * @defgroup transactioncppapi Transaction C++ API
16
    * @ingroup transactionapi
17
    * @brief Type-safe C++ wrappers for transaction C API
18 19 20 21 22 23
    *
    * @note There are some methods from the @ref transactioncapi that can be used directly from C++
    *
    * @{ 
    */

24

25
   class transaction {
26
   public:
27 28
      transaction(time exp = now() + 60, region_id r = 0)
      :expiration(exp),region(r)
29 30
      {}

31
      void send(uint32_t sender_id, time delay_until = 0) const {
32
         auto serialize = pack(*this);
33
         send_deferred(sender_id, delay_until, serialize.data(), serialize.size());
34 35
      }

36 37 38
      time            expiration;
      region_id       region;
      uint16_t        ref_block_num;
D
Daniel Larimer 已提交
39 40 41
      uint32_t        ref_block_prefix;
      uint16_t        packed_bandwidth_words = 0; /// number of 8 byte words this transaction can compress into
      uint16_t        context_free_cpu_bandwidth = 0; /// number of CPU usage units to bill transaction for
42

D
Daniel Larimer 已提交
43
      vector<action>  context_free_actions;
44
      vector<action>  actions;
45

46
      EOSLIB_SERIALIZE( transaction, (expiration)(region)(ref_block_num)(ref_block_prefix)(packed_bandwidth_words)(context_free_cpu_bandwidth)(context_free_actions)(actions) )
47 48
   };

49
   class deferred_transaction : public transaction {
50
      public:
51 52 53
         uint32_t     sender_id;
         account_name sender;
         time         delay_until;
54

55
         static deferred_transaction from_current_action() {
56
            return unpack_action_data<deferred_transaction>();
57 58
         }

59
         EOSLIB_SERIALIZE_DERIVED( deferred_transaction, transaction, (sender_id)(sender)(delay_until) )
60
   };
61 62 63 64

 ///@} transactioncpp api

} // namespace eos
65