本文主要是介绍EOS 智能合约源代码解读 (5)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 智能合约源代码解读 (5)class contract的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!