当前位置: 首页 > news >正文

网站代码软件厦门建设网站建站

网站代码软件,厦门建设网站建站,网站开发要求,国内wordpress免费主题编写使用数据库的智能合约 前面一直在捣鼓EOS网络搭建的相关东西。然而今天比较不走运的是#xff0c;兴致勃勃的把源码版本升到4.0#xff0c;在编译的时候如我所猜想的出现了一系列问题#xff0c;正一筹莫展的时候#xff0c;导师突然问了我一个关于合约如何操作数据库的… 编写使用数据库的智能合约 前面一直在捣鼓EOS网络搭建的相关东西。然而今天比较不走运的是兴致勃勃的把源码版本升到4.0在编译的时候如我所猜想的出现了一系列问题正一筹莫展的时候导师突然问了我一个关于合约如何操作数据库的问题。没办法前面没怎么关注这一块于是乎吞吞吐吐没能回答老师的问题。心想反正现在源码有问题搭不了网络干脆花点时间看看合约的内容。 于是乎就有了今天的学习笔记内容如下 直接上实例合约源码 addressbook.cpp源码 include eosiolib/eosio.hpp include using eosio::indexed_by; using eosio::const_mem_fun; using std::string; class addressbook : public eosio::contract { public: //构造函数 explicit addressbook(action_name self) : contract(self) {} //添加联系人 //abi action void add(const account_name account, const string name, uint64_t phone) {//获取授权如果没有授权Action调用会中止事务会回滚require_auth(account);//eosio::multi_index多索引表可以用来读取和修改EOS数据库//address_index是自己定义的eosio::multi_index//实例化address数据表multi_index参数用于建立对表的访问权限//如果访问自己的合约则具有读写权限访问其他人的合约则具有只读权限address_index addresses(_self, _self);//multi_index的find函数通过主键primary_key查询数据返回迭代器itr//auto关键字会自动匹配类型auto itr addresses.find(account);//如果判断条件不成立则终止执行并打印错误信息eosio_assert(itr addresses.end(), Address for account already exists);//添加数据//使用存储需要付费第一个参数account是付费的账户addresses.emplace(account, [](auto address){address.account account;address.name name;address.phone phone;}); }//修改联系人信息 //abi action void update(const account_name account, const string name, uint64_t phone) {require_auth(account);address_index addresses(_self, _self);auto itr addresses.find(account);//如果没有找到account打印错误信息并终止eosio_assert(itr ! addresses.end(), Address for account not found);addresses.modify(itr, account, [](auto address){address.account account;address.name name;address.phone phone;}); }//删除联系人 //abi action void remove(const account_name account) {require_auth(account);address_index addresses(_self, _self);auto itr addresses.find(account);eosio_assert(itr ! addresses.end(), Address for account not found);//删除addresses.erase(itr); }//设置联系人为特别关注 //abi action void like(const account_name account) {//无需获取授权每个人都可以调用like Actionaddress_index addresses(_self, _self);auto itr addresses.find(account);eosio_assert(itr ! addresses.end(), Address for account not found);//修改相应的liked字段addresses.modify(itr, 0, [](auto address){//打印提示信息eosio::print(Liking: , address.name.c_str(), \n);address.liked;}); }//功能和like()相同但通过phone查询数据而不是主键 //abi action void likebyphone(uint64_t phone) {address_index addresses(_self, _self);//获取自定义索引auto phone_index addresses.get_indexN(phone)();auto itr phone_index.lower_bound(phone);for(; itr ! phone_index.end() itr-phone phone; itr) {phone_index.modify(itr, 0, [](auto address){eosio::print(Liking: , address.name.c_str(), \n);address.liked;});} } private: //定义address表i64表示索引使用默认的uint64_t类型 //abi table address i64 struct address { uint64_t account; string name; uint64_t phone; uint64_t liked; //定义address表的主键address表是一个multi-index表uint64_t primary_key() const { return account; }uint64_t get_phone() const {return phone; }EOSLIB_SERIALIZE(address, (account)(name)(phone)(liked)); };//默认通过主键索引使用indexed_by可以通过自定义函数进行索引 //这里是get_phone即通过phone字段进行索引 typedef eosio::multi_index N(address), address,indexed_byN(phone), const_mem_funaddress, uint64_t, address::get_phone address_index; }; EOSIO_ABI(addressbook, (add)(update)(remove)(like)(likebyphone)) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 该合约业务逻辑是实现一个通讯录的功能其中包括增加联系人、更新联系人信息、删除联系人以及将联系人标记为特别关注。 接下来我们来一步步来看该合约是如何实现的。 创建表格 1)定义结构体 该结构体的成员变量为表的字段成员函数primary_key()定义主键get_phone()定义二级索引EOSLIB_SERIALIZE宏定义序列化表字段如下 struct address {uint64_t account;string name;uint64_t phone;uint64_t liked;//定义address表的主键address表是一个multi-index表uint64_t primary_key() const { return account; }uint64_t get_phone() const {return phone; }EOSLIB_SERIALIZE(address, (account)(name)(phone)(liked)); }; 1 2 3 4 5 6 7 8 9 10 11 12 其中宏EOSLIB_SERIALIZE定义如下 #define EOSLIB_SERIALIZE( TYPE, MEMBERS ) template friend DataStream operator ( DataStream ds, const TYPE t ){ return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, , MEMBERS ); } template friend DataStream operator ( DataStream ds, TYPE t ){ return ds BOOST_PP_SEQ_FOR_EACH( EOSLIB_REFLECT_MEMBER_OP, , MEMBERS ); } 转载于:https://www.cnblogs.com/xiaocongcong888/p/9892714.html
http://www.zqtcl.cn/news/321268/

相关文章:

  • 无法连接到wordpress站点网站建设的 几点
  • 网站免费空间购买wordpress支持页面模版
  • 腾讯建设网站视频宁波城乡住房建设厅网站
  • 乐清网站开发公司个人网站建设工作室
  • 网站空间升级通知手机端怎么看世界杯
  • 广西南宁网站推广建设网站视频教程
  • 福州专业网站建设推广费用nas可做网站服务器吗
  • 齐鲁建设网站福建省高速公路建设管理网站
  • 比格设计网站官网收录网站查询
  • 国外做直播网站淘宝电商网站怎么做的
  • 国外私人网站网站由那些组成
  • 网站备案多久通过机械设备网站
  • 企业自建站案例网站基础知识域名5个点
  • 咸宁建设网站海口市网站建设
  • 认识电子商务网站建设技术网站交换链接怎么做?
  • 定制商城网站建设全球搜索引擎排名2021
  • 徐州百度网站快速优化做网站视频图片加载不出来
  • 网站被host重定向处理浙江网新股吧
  • asp国外网站什么页游好玩
  • 高端简约30平米办公室装修广州搜索seo网站优化
  • 海口的网站建设公司wordpress二次元极简主题
  • 南京快速建站公司国家网站域名
  • 兰州装修公司哪家好网站seo推广员招聘
  • 郑州网站推广 汉狮网络易企秀类似的软件
  • 做外单网站成都网页制作公司排名
  • 成都优化网站关键词搜索引擎有哪些平台
  • 福建百川建设有限公司网站郑州手机软件开发公司
  • 盐城企业做网站多少钱88建网站
  • 南京网站制作报价wordpress主题 yusi
  • 北京建网站已备案网站新增接入