EOS 智能合约源代码解读 class contract

Posted thefist11

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了EOS 智能合约源代码解读 class contract相关的知识,希望对你有一定的参考价值。

1. 所有合约的基类

#define CONTRACT class [[eosio::contract]] // 合约
#define ACTION [[eosio::action]] //动作
#define TABLE struct [[eosio::table]] //表

namespace eosio{

/**
 * new contract should derive from this class, so it can make use of eosio_ABI macro.
 */
class contract {
   public:
      /**
       * Construct a new contract given the contract name
       *
       * @param self - The name of the account this contract is deployed on
       * @param first_receiver - The account the incoming action was first received at.
       * @param ds - The datastream used
       */
      contract( name self, name first_receiver, datastream<const char*> ds ):_self(self),_first_receiver(first_receiver),_ds(ds) {}

      /**
       *       * Get this contract name       *
       * @return name - The name of this contract
       */
      inline name get_self()const { return _self; }

      /**
       * The first_receiver name of the action this contract is processing.
       *
       * @return name - The first_receiver name of the action this contract is processing.
       */
      [[deprecated]]
      inline name get_code()const { return _first_receiver; }

      /**
       * The account the incoming action was first received at.
       *
       * @return name - The first_receiver name of the action this contract is processing.
       */
      inline name get_first_receiver()const { return _first_receiver; }

      /**
       * Get the datastream for this contract
       *
       * @return datastream<const char*> - The datastream for this contract
       */
      inline datastream<const char*>& get_datastream() { return _ds; }

      /**
       * Get the datastream for this contract
       *
       * @return datastream<const char*> - The datastream for this contract
       */
      inline const datastream<const char*>& get_datastream()const { return _ds; }

   protected:
      /**       * The name of the account this contract is deployed on.       */
      name _self;//合约的名字,准确的说,是部署当前合约的账号

      /**       * The account the incoming action was first received at.       */
      name _first_receiver;//调用合约 动作的账号,一般是当前合约所在的账号

      /**       * The datastream for this contract       */
      datastream<const char*> _ds = datastream<const char*>(nullptr, 0);// 保存了那些使用 eosio::ignore 忽略的字段
};

  

以上是关于EOS 智能合约源代码解读 class contract的主要内容,如果未能解决你的问题,请参考以下文章

EOS 智能合约源代码解读 (10)token合约“简介”

EOS 智能合约源代码解读 (12)system合约“native.hpp”

EOS 智能合约源代码解读 boot合约

EOS 智能合约源代码解读 总体说明

EOS 智能合约源代码解读 合约开发示例

EOS 智能合约源代码解读 合约之action