Add Inline Actions

1、为了使用 inline action,需要给 eosio.code 账号添加active权限。

  To use the 'activeauthority inline you will need your contract's to give active authority to eosio.code` pseudo-authority

  In order for the inline actions to be sent from addressbook, add the eosio.code permission to the contract's account's active permission.

cleos set account permission addressbook active '{"threshold": 1,"keys": [{"key": "EOS5NKJziczzVQefMxp3n1cp1X3FUegS7jw8LtxLvubZehqBKGiWT","weight": 1}], "accounts": [{"permission":{"actor":"addressbook","permission":"eosio.code"},"weight":1}]}' -p addressbook@owner

  The eosio.code authority is a pseudo authority implemented to enhance security, and enable contracts to execute inline actions.

2、Notify方法

  [[eosio::action]]
void notify(name user, std::string msg) {
require_auth(get_self());
require_recipient(user);
}

  get_self:Get this contract name. 对于本例,就是addressbook。

  require_recipient:对 name 账号调用本方法。

3、send_summary()方法

  private:
void send_summary(name user, std::string message){
action(
//permission_level,
//code,
//action,
//data
);
}

The action constructor requires a number of parameters.

  • permission_level struct
  • The contract to call (initialised using eosio::name type)
  • The action (initialised using eosio::name type)
  • The data to pass to the action, a tuple of positionals that correlate to the actions being called.

4、实现 send_summary

  private:
void send_summary(name user, std::string message){
action(
permission_level{get_self(),"active"_n},
get_self(),
"notify"_n,
std::make_tuple(user, name{user}.to_string() + message)
).send();
}

  make_tuplea function available through std C++ library. Data passed in the tuple is positional, and determined by the order of the parameters accepted by the action that being called.

5、合约发布后,我们测试一下。

  1)尝试插入数据

cleos push action addressbook upsert '["alice", "alice", "liddell", 21, "123 drink me way", "wonderland", "amsterdam"]' -p alice@active

  我们发现会触发3个action。下图,第二个#表明 addressbook 触发了 notify, 第三个#表明 alice 触发了 notify。

executed transaction: e9e30524186bb6501cf490ceb744fe50654eb393ce0dd733f3bb6c68ff4b5622   bytes   us
# addressbook <= addressbook::upsert {"user":"alice","first_name":"alice","last_name":"liddell","age":,"street":"123 drink me way","cit...
# addressbook <= addressbook::notify {"user":"alice","msg":"alicesuccessfully emplaced record to addressbook"}
# alice <= addressbook::notify {"user":"alice","msg":"alicesuccessfully emplaced record to addressbook"}

  2)查看alice动作

cleos get actions alice

  结果如下,有两个动作

  

  

参考:https://developers.eos.io/eosio-home/docs/inline-actions

Add Inline Actions的更多相关文章

  1. outlook使用inline style回复邮件

    Reply with inline comments within the original message text When you reply to email messages in Outl ...

  2. 使用 Github Actions 自动部署 Angular 应用到 Github Pages

    前言 最近在学习 Angular,一些基础的语法也学习的差不多了,就在 github 上新建了一个代码仓库,准备用 ng-zorro 搭个后台应用的模板,方便自己以后写些小东西时可以直接使用.前端项目 ...

  3. GitHub Actions in Action

    GitHub Actions in Action https://lab.github.com/githubtraining/github-actions:-hello-world https://g ...

  4. Github Actions All In One

    Github Actions All In One https://github.com/features/actions https://github.com/marketplace?type=ac ...

  5. [转] How to dispatch a Redux action with a timeout?

    How to dispatch a Redux action with a timeout? Q I have an action that updates notification state of ...

  6. Angular2 ng2-smart-table

    ng2-smart-table 入门 安装 你要做的就是运行以下命令: npm install --save ng2-smart-table 此命令将创建在你的`package.json`文件和安装包 ...

  7. [Win10应用开发] 如何使用Windows通知

    消息通知,是一个应用中必不可少的组成部分.Win10下提供了多种消息通知机制,Toast通知只是其中一种.这篇博文和大家分享一下,如何使用Toast通知. 上图是一个基本的Toast通知,那我们该如何 ...

  8. BZOJ 3626: [LNOI2014]LCA [树链剖分 离线|主席树]

    3626: [LNOI2014]LCA Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2050  Solved: 817[Submit][Status ...

  9. Android AppBar

    AppBar官方文档摘记 2016-6-12 本文摘自Android官方文档,为方便自己及其他开发者朋友阅读. 章节目录为"Develop > Training > Best P ...

随机推荐

  1. 【开发遇到的问题】Spring Mvc使用Jackson进行json转对象时,遇到的字符串转日期的异常处理(JSON parse error: Can not deserialize value of type java.util.Date from String[)

    1.问题排查 - 项目配置 springboot 2.1 maven配置jackson - 出现的场景: 服务端通过springmvc写了一个对外的接口,查询数据中的表,表中有一个字段属性是时间戳,返 ...

  2. es6学习日记3

    函数的扩展 ES6 之前,不能直接为函数的参数指定默认值,只能采用变通的方法. function log(x, y) { y = y || 'World'; console.log(x, y); } ...

  3. PythonStudy——字符串重要方法 String important method

    # 1.索引(目标字符串的索引位置) s1 = '123abc呵呵' print(s1.index('b')) # 2.去留白(默认去两端留白,也可以去指定字符) s2 = '***好 * 的 *** ...

  4. Excel转datatable

    如果想支持 .xls,.xlsx 两种格式 则必须安装一个exe文件,下载路径https://www.microsoft.com/zh-CN/download/details.aspx?id=1325 ...

  5. 在子页面操作父页面元素和iframe说明

    实现功能:在子页面操作父页面元素. 在实际编码的过程中,大家一定有这种需求:在父级页面有一个<iframe scrolling='auto'></iframe>内联框架,而我们 ...

  6. 聊聊Java happens-before原则

    无论处理器.JVM.编译器都会都保证程序正确的前提下尽可能的对指令执行效率进行优化,进行指令重排等操作.而要保证程序的执行结果的正确,则必须要遵循JMM中规定的happens-before原则. 在J ...

  7. [ZZ] UIUC同学Jia-Bin Huang收集的计算机视觉代码合集

    UIUC同学Jia-Bin Huang收集的计算机视觉代码合集 http://blog.sina.com.cn/s/blog_4a1853330100zwgm.htmlv UIUC的Jia-Bin H ...

  8. 关于rtsp的时间戳问题

    这里主要关注的rtp包的时间戳,在rtsp中,播放器的1S钟的定义是和媒体的采样率有关的. 例如视频的采样率是90K,那么最小时间粒度(单位)是1/90000秒,再转换成ms就是 1/90毫秒,这个就 ...

  9. LINUX 查看当前系统的内存使用情况 vmstat

    Linux vmstat 命令 Vmstat命令是最常见的Linux/Unix监控工具,可以展现给定时间间隔的服务器的状态值,包括服务器的CPU使用率,内存使用,虚拟内存交换情况,IO读写情况. 相比 ...

  10. node升级的正确方法

    本文主要是针对安装了node的用户如何对node进行升级或者安装指定版本:没有安装node的可以参考连接node安装方法 . 安装方法: 1.产看node版本,没安装的请先安装: $  node -v ...