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 ...
随机推荐
- python之文件读写(2)
2. 写入数据到文件中 读取文件用read,那么写用什么嘞?用write!实际操作一下. 2.1 简单的写入数据到文件中 file = open("write_data", &qu ...
- stiff chemistry模型出现NaN错误
通过定位可以看到,是usr_rates.f中出现了奇异值,因为我的代码中有这样一句话: 而同时我的ConH2在声明后没有赋初值,因此,当X_g(IJK,H2) < c_Limiter后,ConH ...
- CodeForces - 1110C-Meaningless Operation(打表找规律)
Can the greatest common divisor and bitwise operations have anything in common? It is time to answer ...
- python-sort()/sorted()比较
Sorting Lists sorted(iterable,key=None,reverse=False),does not mutate list, must assign result to a ...
- 剑指offer——面试题11:旋转数组的最小数字
#include"iostream" using namespace std; int GetMinNumber(int *data,int len) { ,right=len-, ...
- web app与app的区别,即html5与app的区别
公司准备要做一个项目,是p2p配资的app.在网上问了一些人后,发现有的是直接有html5做好后,用软件封装的.之前我学过app的开发,当时Android版本的,知道开发Android app时写的代 ...
- 在ASP.NET Core Web API 项目里无法访问(wwwroot)下的文件
解决办法:在“ Startup.cs ” 文件里的 Configur方法里添加一句代码“ app.UseStaticFiles() ”,这样就可以访问wwwroot下的文件了. - 方法代码是: - ...
- vue自定义指令clickoutside使用以及扩展用法
vue自定义指令clickoutside使用以及扩展用法 产品使用vue+element作为前端框架.在功能开发过程中,难免遇到使用element的组件没办法满足特殊的业务需要,需要对其进行定制,例如 ...
- logrtate 切割详解
Logrotate是Linux下一款日志管理工具,可用于日志文件的转储(即删除旧日志文件,创建新日志文件).可以根据日志大小或者按照某时段间隔来转储,内部使用cron程序来执行.Logrotate还可 ...
- PHP Mongodb API参考
<?php /*** Mongodb类** examples: * $mongo = new HMongodb("127.0.0.1:11223"); * $mongo-&g ...