Add Inline Actions
【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.
- A permission_level struct
- The contract to call (initialised using
eosio::nametype) - The action (initialised using
eosio::nametype) - 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_tuple:a 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的更多相关文章
- outlook使用inline style回复邮件
Reply with inline comments within the original message text When you reply to email messages in Outl ...
- 使用 Github Actions 自动部署 Angular 应用到 Github Pages
前言 最近在学习 Angular,一些基础的语法也学习的差不多了,就在 github 上新建了一个代码仓库,准备用 ng-zorro 搭个后台应用的模板,方便自己以后写些小东西时可以直接使用.前端项目 ...
- GitHub Actions in Action
GitHub Actions in Action https://lab.github.com/githubtraining/github-actions:-hello-world https://g ...
- Github Actions All In One
Github Actions All In One https://github.com/features/actions https://github.com/marketplace?type=ac ...
- [转] 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 ...
- Angular2 ng2-smart-table
ng2-smart-table 入门 安装 你要做的就是运行以下命令: npm install --save ng2-smart-table 此命令将创建在你的`package.json`文件和安装包 ...
- [Win10应用开发] 如何使用Windows通知
消息通知,是一个应用中必不可少的组成部分.Win10下提供了多种消息通知机制,Toast通知只是其中一种.这篇博文和大家分享一下,如何使用Toast通知. 上图是一个基本的Toast通知,那我们该如何 ...
- BZOJ 3626: [LNOI2014]LCA [树链剖分 离线|主席树]
3626: [LNOI2014]LCA Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2050 Solved: 817[Submit][Status ...
- Android AppBar
AppBar官方文档摘记 2016-6-12 本文摘自Android官方文档,为方便自己及其他开发者朋友阅读. 章节目录为"Develop > Training > Best P ...
随机推荐
- Codeforces1062A. A Prank(暴力)
题目链接:传送门 题目: A. A Prank time limit per test second memory limit per test megabytes input standard in ...
- HDU 2062:Subset sequence(思维)
Subset sequence Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- 1.Python
一.Python基础:1.第一句python文件后缀名:文件后缀名是.py2.两种执行方式:(1)把文件地址交给python解释器,python解释器去找到这个文件读到内存执行(2)进入解释器:解释器 ...
- 《Linux内核原理与分析》第三周作业
实验:基于kernel的简单的时间片轮转多道程序内核 1.实验要求 完成一个简单的时间片轮转多道程序内核代码 2.实验过程 进入实验楼的linux环境,打开shell,输入以下代码: cd Linux ...
- python函数之第一类对象
目录 python函数之第一类对象 python函数之第一类对象 第一类对象(英语:First-class object)在计算机科学中指可以在执行期创造并作为参数传递给其他函数或存入一个变数的实体. ...
- python set 集合复习--点滴
一.set特性: set是一个无序不重复的元素集合. 集合对象是一组无序排列的可哈希的值,集合成员可以做字典中的键.集合支持用in和not in操作符检查成员,由len()内建函数得到集合的基数(大小 ...
- 文件内容比较difflib
#!/usr/bin/env python#-*- coding:utf-8 -*-import difflibimport sys,osos.chdir('E:\\PythonWrok')a = o ...
- 解决WPF中异常导致的程序Crash
通常在WPF中出现异常,会导致程序Crash,即使把异常Throw出来,依旧会报错,解决方法只需在App.xaml.cs中进行处理即可,废话不说,代码如下: private int exception ...
- 关于IE无法访问本机网络的问题
多次遇到IE无法访问本机站点的情况,比如架设了一个花生壳,所有人都可以访问,唯独本机不行(服务器),还需要把这个域名加入信任站点,这TMD什么情况.今天又遇到访问本地restful service,用 ...
- CentOS 7 快速部署 ELK
先简单说一下部署思路及原理(不一定正确,只是个人理解而已) 1.修改系统参数,以便安装软件 2.安装配置elasticsearch,这个相当于总监测中心,用来收集logstash监测的各种服务应用日志 ...