solidity语言12
View Functions
函数声明为视图,将无权修改状态
pragma solidity ^0.4.16;
contract C {
function f(uint a, uint b) public view returns (uint) {
return a * (b + 42) + now;
}
}
以下操作属违规操作
1. Writing to state variables.
2. Emitting events.
3. Creating other contracts.
4. Using selfdestruct.
5. Sending Ether via calls.
6. Calling any function not marked view or pure.
7. Using low-level calls.
8. Using inline assembly that contains certain opcodes.
Pure Functions
函数声明为视图,将无权读取或者修改状态
pragma solidity ^0.4.16;
contract C {
function f(uint a, uint b) public pure returns (uint) {
return a * (b + 42);
}
}
以下操作属违规操作
1. Reading from state variables.
2. Accessing this.balance or <address>.balance.
3. Accessing any of the members of block, tx, msg (with the exception of msg.sig and msg.data).
4. Calling any function not marked pure.
5. Using inline assembly that contains certain opcodes.
Fallback Function
合约可以有一个匿名函数,这个函数不能有参数,也不能返回结果。假如没有函数匹配给定的函数标识,合约将调用。
函数在合约收到以太后执行,另外,为了能接收以太,回退函数必须使用关键字payable。这次调用花费很少,大约2300 gas
pragma solidity ^0.4.0;
contract Test {
// This function is called for all messages sent to
// this contract (there is no other function).
// Sending Ether to this contract will cause an exception,
// because the fallback function does not have the `payable`
// modifier.
uint x;
function() public {
x = 1;
}
}
// This contract keeps all Ether sent to it with no way to get it back.
contract Sink {
function() public payable {}
}
contract Caller {
function callTest(Test test) public {
test.call(0xabcdef01);
// hash does not exist results in test.x becoming == 1.
// The following will not compile, but even if someone sends ether to that contract,
// the transaction will fail and reject the Ether.
//test.send(2 ether);
}
}
solidity语言12的更多相关文章
- Solidity语言系列教程
Solidity 是一门面向合约的.为实现智能合约而创建的高级编程语言.这门语言受到了 C++,Python 和 Javascript 语言的影响,设计的目的是能在 以太坊虚拟机(EVM) 上运行. ...
- solidity语言介绍以及开发环境准备
solidity语言介绍以及开发环境准备 Solidity 是一门面向合约的.为实现智能合约而创建的高级编程语言.这门语言受到了 C++,Python 和 Javascript 语言的影响,设计的 ...
- 用solidity语言开发代币智能合约
智能合约开发是以太坊编程的核心之一,而代币是区块链应用的关键环节,下面我们来用solidity语言开发一个代币合约的实例,希望对大家有帮助. 以太坊的应用被称为去中心化应用(DApp),DApp的开发 ...
- 第一行代码:以太坊(2)-使用Solidity语言开发和测试智能合约
智能合约是以太坊的核心之一,用户可以利用智能合约实现更灵活的代币以及其他DApp.不过在深入讲解如何开发智能合约之前,需要先介绍一下以太坊中用于开发智能合约的Solidity语言,以及相关的开发和测试 ...
- 用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语言13
函数过载 合约内允许定义同名函数,但是输入参数不一致 pragma solidity ^0.4.17; contract A { function f(uint _in) public pure re ...
随机推荐
- rest-assured的日志使用介绍
在许多测试用例当中,为了帮助我们创建正确的断言和发送正确的请求,打印出详细的响应和请求数据是非常有用的.为此我们可以使用rest-assured提供的预定义过滤器或者使用其中的一些快捷方法. 一.请求 ...
- 洛谷 P3239 [HNOI2015]亚瑟王(期望dp)
题面 luogu 题解 一道复杂的期望\(dp\) 思路来源:__stdcall 容易想到,只要把每张牌打出的概率算出来就可以求出\(ans\) 设\(fp[i]\)表示把第\(i\)张牌打出来的概率 ...
- POJ_1850 Code【组合的运用】
题目: Transmitting and memorizing information is a task that requires different coding systems for the ...
- Codeforces - 912B 位运算
求[1,n]内k的值的异或和使其值最大 k=1是肯定是n k>1,设pos是n的最高位,那答案就是(1ll<<(pos+1))-1 这里用到一个性质是当S=2^i-1时,a xor ...
- 解决linux一段时间不操作失去连接的问题
解决mac下ssh空闲一段时间自动断开的问题 http://www.haorooms.com/post/mac_iterm2_ssh 问题现象 用 ssh 命令连接服务器之后,如果一段时间不操作,再次 ...
- Spring对外部属性文件指定的某个属性进行加密、解密
[From] http://blog.csdn.net/ethanq/article/details/7333897 在我们开发当中,经常会用到spring框架来读取属性文件的属性值,然后使用占位符引 ...
- docker 安装使用gitlab
官方镜像地址 ce版本: https://hub.docker.com/r/gitlab/gitlab-ce 文档地址: https://docs.gitlab.com/omnibus/docker ...
- js 替换中间四位手机号为 *
replace(/(\d{})\d{}(\d{})/, '$1****$2')
- html中的flv视频播放器
项目中要播放flv视屏,第一时间想到html5的<video>标签,只是很可惜<video>兼容性差也就算了,居然还对格式有明确限制,也就是说只支持Ogg.MPEG4.WebM ...
- JS如何获取屏幕、浏览器及网页高度宽度?
屏幕的尺寸是指当前分辨率下的高度.宽度,而不是物理高度.宽度. 如:一个22寸的显示器,屏幕分辨率为1366 * 768,那么我们可以获取到的屏幕高度为1366px,宽度为768px. 屏幕宽度和高度 ...