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

  1. Solidity语言系列教程

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

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

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

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

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

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

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

  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语言13

    函数过载 合约内允许定义同名函数,但是输入参数不一致 pragma solidity ^0.4.17; contract A { function f(uint _in) public pure re ...

随机推荐

  1. C++_基础1-基本数据类型

    面向对象(OOP)的本质是设计并扩展自己的数据类型.设计自己的数据类型就是让类型与数据匹配. 如果正确做到这一点,就会发现以后使用数据会容易很多.然而创建自己的类型之前,必须了解并理解C++内置类型. ...

  2. 洛谷 P1155 【NOIP2008】双栈排序

    题目链接 题解 这题有点神啊.. 我们仔细观察一下,发现两个栈内元素必须为降序 那么有结论 如果有\(i < j < k\) 且 \(a[k] < a[i] < a[j]\)则 ...

  3. C. Magic Ship (思维+二分)

    https://codeforces.com/contest/1117/problem/C 你是一个船长.最初你在点 (x1,y1) (显然,大海上的所有点都可以用平面直角坐标描述),你想去点 (x2 ...

  4. D3.js v4版本 按住shift键框选节点demo

    http://download.csdn.net/download/qq_25042329/10139649

  5. [源代码]List的增加与删除

    // Removes the element at the given index. The size of the list is // decreased by one. // public vo ...

  6. hybrid app开发工具

    hybrid app开发工具 1.AppCan AppCan是国内Hybrid App混合模式开发的倡导者,AppCan应用引擎支持Hybrid App的开发和运行.并且着重解决了基于HTML5的移动 ...

  7. Oracle PL/SQL之WITH查询

    [转自] http://blog.csdn.net/t0nsha/article/details/6730855 为什么要用WITH? 1. 如果需要在一段复杂查询里多次应用同一个查询,用WITH可实 ...

  8. 解决Resharper在Core项目中无法执行单元测试的问题

    项目升级core了,resharper最近升级到2018.1版本,但是安装后还是无法直接运行单元测试,昨天小姐姐发了解决方法,贼有用.所以记录一下,给自己以后或者其他遇到此问题的小伙伴用.  解决Re ...

  9. Lakeshore

    用来做 html5 特效,Egret游戏引擎 为什么用Egret开发的游戏在某些Android设备上特别卡? { 在 Android 早期版本( 4.4 之前) ,Android WebView 并不 ...

  10. Rsa2加密报错java.security.spec.InvalidKeySpecException的解决办法

    最近在和支付宝支付做个对接,Java项目中用到了RSA2进行加解密,在加密过程中遇到了错误: java.security.spec.InvalidKeySpecException: java.secu ...