solidity语言13
函数过载
合约内允许定义同名函数,但是输入参数不一致
pragma solidity ^0.4.17;
contract A {
function f(uint _in) public pure returns (uint out) {
out = 1;
}
function f(uint _in, bytes32 _key) public pure returns (uint out) {
out = 2;
}
}
pragma solidity ^0.4.16;
contract A {
function f(B _in) public pure returns (B out) {
out = _in;
}
function f(address _in) public pure returns (address out) {
out = _in;
}
}
contract B {
}
事件
// 事件可方便使用EVM的日志工具,通过dapp的用户接口调用回调函数进行监听。
pragma solidity ^0.4.0;
contract ClientReceipt {
event Deposit(
address indexed _from,
bytes32 indexed _id,
uint _value
);
function deposit(bytes32 _id) public payable {
// 任何调用当前函数的操作都会被检测到
Deposit(msg.sender, _id, msg.value);
}
}
var abi = /* abi as generated by the compiler */;
var ClientReceipt = web3.eth.contract(abi);
var clientReceipt = ClientReceipt.at("0x1234...ab67"); /* address */
var event = clientReceipt.Deposit();
event.watch(
function(error, result) {
if (!error)
console.log(result);
});
/*或者
var event = clientReceipt.Deposit(function(error, result) {
if (!error)
console.log(result);
});
*/
使用log低层接口
log0, log1, log2, log3, log4 ~ logN
pragma solidity ^0.4.10;
contract C {
function f() public payable {
bytes32 _id = 0x420042;
log3(
bytes32(msg.value),
bytes32(0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20),
bytes32(msg.sender),
_id
);
}
}
用于理解事件的其他资源
接口
当合约继承其他合约,仅一个单独的合约被区位链建立,代码从基础合约复制到建立的合约中。
pragma solidity ^0.4.16;
contract owned {
address owner;
// 构造函数
function owned() {
owner = msg.sender;
}
}
// 继承合约owned的所有属性,但不能使用通过this进行外部访问
contract mortal is owned {
function kill() {
if (msg.sender == owner)
selfdestruct(owner);
}
}
// These abstract contracts are only provided to make the
// interface known to the compiler. Note the function
// without body. If a contract does not implement all
// functions it can only be used as an interface.
contract Config {
function lookup(uint id) public returns (address adr);
}
contract NameReg {
function register(bytes32 name) public;
function unregister() public;
}
contract named is owned, mortal {
function named(bytes32 name) {
Config config = Config(0xD5f9D8D94886E70b06E474c3fB14Fd43E2f23970);
NameReg(config.lookup(1)).register(name);
}
function kill() public {
if (msg.sender == owner) {
Config config = Config(0xD5f9D8D94886E70b06E474c3fB14Fd43E2f23970);
NameReg(config.lookup(1)).unregister();
mortal.kill();
}
}
}
contract PriceFeed is owned, mortal, named("GoldFeed") {
function updateInfo(uint newInfo) public {
if (msg.sender == owner)
info = newInfo;
}
function get() public view returns(uint r) {
return info;
}
uint info;
}
pragma solidity ^0.4.0;
contract owned {
address owner;
function owned() public {
owner = msg.sender;
}
}
contract mortal is owned {
function kill() public {
if (msg.sender == owner)
selfdestruct(owner);
}
}
contract Base1 is mortal {
function kill() public {
/* do cleanup 1 */
mortal.kill();
}
}
contract Base2 is mortal {
function kill() public {
/* do cleanup 2 */
mortal.kill();
}
}
contract Final is Base1, Base2 {
}
pragma solidity ^0.4.0;
contract owned {
function owned() public {
owner = msg.sender;
}
address owner;
}
contract mortal is owned {
function kill() public {
if (msg.sender == owner)
selfdestruct(owner);
}
}
contract Base1 is mortal {
function kill() public {
/* do cleanup 1 */
super.kill();
}
}
contract Base2 is mortal {
function kill() public {
/* do cleanup 2 */
super.kill(); }
}
contract Final is Base1, Base2 {
}
solidity语言13的更多相关文章
- Solidity语言系列教程
Solidity 是一门面向合约的.为实现智能合约而创建的高级编程语言.这门语言受到了 C++,Python 和 Javascript 语言的影响,设计的目的是能在 以太坊虚拟机(EVM) 上运行. ...
- 用solidity语言开发代币智能合约
智能合约开发是以太坊编程的核心之一,而代币是区块链应用的关键环节,下面我们来用solidity语言开发一个代币合约的实例,希望对大家有帮助. 以太坊的应用被称为去中心化应用(DApp),DApp的开发 ...
- 第一行代码:以太坊(2)-使用Solidity语言开发和测试智能合约
智能合约是以太坊的核心之一,用户可以利用智能合约实现更灵活的代币以及其他DApp.不过在深入讲解如何开发智能合约之前,需要先介绍一下以太坊中用于开发智能合约的Solidity语言,以及相关的开发和测试 ...
- solidity语言介绍以及开发环境准备
solidity语言介绍以及开发环境准备 Solidity 是一门面向合约的.为实现智能合约而创建的高级编程语言.这门语言受到了 C++,Python 和 Javascript 语言的影响,设计的 ...
- 用C++生成solidity语言描述的buchi自动机的初级经验
我的项目rvtool(https://github.com/Zeraka/rvtool)中增加了生成solidity语言格式的监控器的模块. solidity特殊之处在于,它是运行在以太坊虚拟机环境中 ...
- Solidity语言基础 和 Etherum ERC20合约基础
1. 类型只能从第一次赋值中推断出来,因此以下代码中的循环是无限的, 小. for (var i = 0; i < 2000; i++) { ... } --- Solidity Types ...
- solidity语言
IDE:Atom 插件:autocomplete-solidity 代码自动补齐 linter-solium,linter-solidity代码检查错误 language-ethereum支持 ...
- solidity语言14
库(Libraries) 库类似合约,实现仅在专门地址部署一次,使用EVM的DELEGATECALL的功能重复使用的目的.意思是当库函数被调用后,代码执行在被调用的合约的环境.例如,使用this调用合 ...
- solidity语言12
View Functions 函数声明为视图,将无权修改状态 pragma solidity ^0.4.16; contract C { function f(uint a, uint b) publ ...
随机推荐
- 打开页面时就提交,可以做一些自动登陆 还有SICLOGIN的测试代码
<HTML> <head> <title> Untitled Document</title > (1)自动提交表单: <meta http- ...
- Luogu P2243 电路维修 双端队列BFS
当转移的代价是0和一个分明不同的权值时,可以用双端队列BFS去跑(你跑最短路也没问题..QWQ) 而对于这道题,边旋转代价是1,不旋转代价是0:可以直接建图最短路,也可以跑BFS 这个题建图很有意思: ...
- Oracle date和timestamp区别
<转自> http://blog.csdn.net/huaguoming/article/details/8693679 在今天的工作中,学到了以下几个知识点: 一.date和timest ...
- 神马是代码简单的cmd模式,这就是!
小狼正在研究 “怎么查找连在一起的同色方块?”算法问题 ,突然感觉我是不是需要一种开发模式,不然感觉自己的代码好乱的. 可能是研究算法吧,导致小狼的思路特别清晰,加上也用了差不多1年的nodejs.s ...
- Java 不可变对象
不可变对象(immutable objects):一旦对象被创建,它们的状态就不能被改变(包括基本数据类型的值不能改变,引用类型的变量不能指向其他的对象,引用类型指向的对象的状态也不能改变),每次对他 ...
- 分享一个js方法
这是一个关于参数合并的方法,这个场景也经常遇到,比如我们现在要对微信小程序的wx.request进行再一次封装,会涉及到一些默认的参数和每次使用自己传递的参数合并问题,分享代码. var extend ...
- Python I/O及FIle方法
一.文件操作 文件的编码格式: ASCII与UNICODE: 计算机有256个ASCII字符(8个0/1的排列组合方式一共有256种, 2**8) UTF-8是UNICODE的一种编码格式,计算机中使 ...
- vue搭建后台管理页面(点击左侧导航,切换右侧内容)
home.vue页面 <template> <div style="background-color: #EBEBEB;min-height:900px"> ...
- 有关tensorflow一些问题
1.python版本 采用64位的python 2.系统不支持高版本tensorflow(>1.6),运行报错如下: 问题描述如下: ImportError: DLL load failed: ...
- 踩坑--http返回码之302状态码
项目介绍:springboot+shiro+maven 业务需求:拦截一切不登录的盗链URL,除了问卷调查,可以给任意用户填写和提交意外. 问题重现:表单提交过程中返回302状态码,我就觉得很奇怪.在 ...