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. web 服务器安全防范

    apache 关闭目录 配置文件:安装目录/Apache/conf/httpd.conf <Directory /> #默认就会把/ 的目录暴漏出来:关闭方法: Options -Inde ...

  2. org.hibernate.QueryException: Unable to resolve path [SecWilldosetdate.name],xxxxxxxx...异常处理

    今天在写hql语句的时候出现了这个错误,然后一直运行到执行hql这儿就出错了.页面报500. 原hql如下: String hql = "from SecWilldosetdate wher ...

  3. 学习python-跨平台获取键盘事件

    class _Getch: """Gets a single character from standard input. Does not echo to the sc ...

  4. android apk重新[签名]

    1,删除之前的签名文件 用解压缩工具打开,删除 [META-INF] 文件夹 2,打开命令行窗口 3,[保证签名文件和apk在同一级目录下] 然后执行如下命令,将 (xx) 处替换自己的签名.apk ...

  5. 使用 .NET Core CLI 创建 .NET Core 全局工具

    https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=2&ch=&tn=baiduhome_pg& ...

  6. 远程上传下载文件-Xftp5

    Xftp5下载 链接:https://pan.baidu.com/s/1Wzso_Q7mPy5uGOUlripEWg 密码:xfx9 安装选择家庭版 由于21端口没有开,所以不能选FTP,  选择SF ...

  7. How to Setup a Private Proxy Server on EC2 in Under 10 Minutes

    How to Setup a Private Proxy Server on EC2 in Under 10 Minutes I’ve been slacking a bit with regular ...

  8. 使用bind配置DNS服务(CentOS 6.5)

    DNS域名解析服务(Domain Name System)是用于解析域名与IP地址对应关系的服务,功能上可以实现正向解析与反向解析: 正向解析:根据主机名(域名)查找对应的IP地址. 反向解析:根据I ...

  9. Myeclipse编辑JSP文件时,可以点击重口顶部的箭头来切换全屏状态

  10. MySQL搭建Amoeba_读写分离

    一.背景知识 Amoeba(变形虫)项目,专注 分布式数据库 proxy 开发.座落与Client.DB Server(s)之间.对客户端透明.具有负载均衡.高可用性.sql过滤.读写分离.可路由相关 ...