函数过载

合约内允许定义同名函数,但是输入参数不一致

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的更多相关文章

  1. Solidity语言系列教程

    Solidity 是一门面向合约的.为实现智能合约而创建的高级编程语言.这门语言受到了 C++,Python 和 Javascript 语言的影响,设计的目的是能在 以太坊虚拟机(EVM) 上运行. ...

  2. 用solidity语言开发代币智能合约

    智能合约开发是以太坊编程的核心之一,而代币是区块链应用的关键环节,下面我们来用solidity语言开发一个代币合约的实例,希望对大家有帮助. 以太坊的应用被称为去中心化应用(DApp),DApp的开发 ...

  3. 第一行代码:以太坊(2)-使用Solidity语言开发和测试智能合约

    智能合约是以太坊的核心之一,用户可以利用智能合约实现更灵活的代币以及其他DApp.不过在深入讲解如何开发智能合约之前,需要先介绍一下以太坊中用于开发智能合约的Solidity语言,以及相关的开发和测试 ...

  4. solidity语言介绍以及开发环境准备

    solidity语言介绍以及开发环境准备   Solidity 是一门面向合约的.为实现智能合约而创建的高级编程语言.这门语言受到了 C++,Python 和 Javascript 语言的影响,设计的 ...

  5. 用C++生成solidity语言描述的buchi自动机的初级经验

    我的项目rvtool(https://github.com/Zeraka/rvtool)中增加了生成solidity语言格式的监控器的模块. solidity特殊之处在于,它是运行在以太坊虚拟机环境中 ...

  6. Solidity语言基础 和 Etherum ERC20合约基础

    1. 类型只能从第一次赋值中推断出来,因此以下代码中的循环是无限的,  小. for (var i = 0; i < 2000; i++) { ... } --- Solidity Types ...

  7. solidity语言

    IDE:Atom 插件:autocomplete-solidity 代码自动补齐   linter-solium,linter-solidity代码检查错误   language-ethereum支持 ...

  8. solidity语言14

    库(Libraries) 库类似合约,实现仅在专门地址部署一次,使用EVM的DELEGATECALL的功能重复使用的目的.意思是当库函数被调用后,代码执行在被调用的合约的环境.例如,使用this调用合 ...

  9. solidity语言12

    View Functions 函数声明为视图,将无权修改状态 pragma solidity ^0.4.16; contract C { function f(uint a, uint b) publ ...

随机推荐

  1. LeetCode231.2的幂

    231.2的幂 描述 给定一个整数,编写一个函数来判断它是否是 2 的幂次方. 示例 示例 1: 输入: 1 输出: true 解释: 2^0 = 1 示例 2: 输入: 16 输出: true 解释 ...

  2. Loj 6432. 「PKUSC2018」真实排名 (组合数)

    题面 Loj 题解 枚举每一个点 分两种情况 翻倍or不翻倍 \(1.\)如果这个点\(i\)翻倍, 要保持排名不变,哪些必须翻倍,哪些可以翻倍? 必须翻倍: \(a[i] \leq a[x] < ...

  3. loj 2038 / 洛谷 P4345 [SHOI2015] 超能粒子炮・改 题解

    好玩的推式子 题目描述 曾经发明了脑洞治疗仪与超能粒子炮的发明家 SHTSC 又公开了他的新发明:超能粒子炮・改--一种可以发射威力更加强大的粒子流的神秘装置. 超能粒子炮・改相比超能粒子炮,在威力上 ...

  4. bzoj1934 Vote 善意的投票 最小割(最大匹配)

    题目传送门 题目大意:很多小朋友,每个小朋友都有自己的立场,赞成或者反对,如果投了和自己立场不同的票会得到一个能量.又有很多朋友关系,如果一个人和他的一个朋友投的票不同,也会得到一个能量,现在问,通过 ...

  5. UESTC - 1610 递推方程+矩阵快速幂

    感觉像是HDU Keyboard的加强版,先推出3张牌时的所有组合,然后递推出n张牌 看到n=1e18时吓尿了 最后24那里还是推错了.. (5行1列 dp[1][n],dp[2][n],dp[3][ ...

  6. jquery 方法总结

    1.   给列表中 某个 标签添加 点击方法 $(function(){ $(".delete").click(function(){ var href = $(this).att ...

  7. Spring4 笔记

    1. 通过 xml 赋值给 bean 1) 通过set 方法赋值 (必须要有空的构造方法) <bean id="user" class="com.test.User ...

  8. php 的基本语法

    八种数据类型: 4种标量类型:boolean.integer.float.string 2种复合类型:array.object 2种特殊类型:resource.NULL 如果想看某个表达式的值和类型用 ...

  9. Q680 验证回文字符串 Ⅱ

    给定一个非空字符串 s,最多删除一个字符.判断是否能成为回文字符串. 示例 1: 输入: "aba" 输出: True 示例 2: 输入: "abca" 输出: ...

  10. jquery 去除字符串左右空格

    /*** 删除左右两端的空格*/String.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/g, '');} 调用方式: v ...