EOS多索引表使用指南

下面是多索引表的使用指南。

为了深入和清晰的了解多索引表,最终的.cpp文件部分将被进一步详细讨论和讨论。注意,完整的.cpp文件可以在页面的底部找到。

词汇表

  • code :是指已公布智能合约的account_name
  • scope:account_name所涉及数据范围。
  • table_name: 存储在内存中的表的名称。

代码分解

要存储的结构

要在多索引表中存储的数据是limit_order结构。primary_key()get_expiration()get_price()函数用于返回表。返回的表将根据调用的函数排序。

struct limit_order {
  uint64_t     id;
  uint128_t    price;
  uint64_t     expiration;
  account_name owner;

  auto primary_key() const { return id; }
  uint64_t get_expiration() const { return expiration; }
  uint128_t get_price() const { return price; }

  EOSLIB_SERIALIZE( limit_order, ( id )( price )( expiration )( owner ) )
};
建一个多索引表
auto payer = ilm.get_account();
...

payer是保存帐户的变量,它将账单元素添加到多索引表中,并修改已经在多索引表中的元素。

...
eosio::multi_index< N( orders ), limit_order, 
...

N(orders)是多索引表的名称,limit_order是要存储在表中的数据。

...  
indexed_by< N( byexp ), const_mem_fun< limit_order, uint64_t, 
&limit_order::get_expiration> >,
...

indexed_by< N( byexp ), const_mem_fun< limit_order, uint64_t, &limit_order::get_expiration> >定义了多索引表的索引方式。N(byexp)是这个索引的名称。const_mem_fun表示正在查询的数据类型、limit_order的变量的类型是uint64_t,将使用get_expiration函数获取变量。

...
  indexed_by< N( byprice ), const_mem_fun< limit_order, uint128_t, &limit_order::get_price> >
...

indexed_by< N( byprice ), const_mem_fun< limit_order, uint128_t, &limit_order::get_price> >定义了多索引表的索引方式。N(byprice)是这个索引的名称。const_mem_fun表示正在查询的数据类型、limit_order的变量的类型是uint128_t,将使用get_price函数获取变量。

orders( N( limitorders ), N( limitorders )

orders即是多索引表。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值