solidity语言11
函数修饰符
pragma solidity ^0.4.11;
contract owned {
address owner;
// 构造函数
function owned() public {
owner = msg.sender;
}
// 此合约定义的函数修饰符不使用,用于衍生的合约
modifier onlyOwner {
require(msg.sender == owner);
_; // 引用的函数体部分
}
}
contract mortal is owned {
function close() public onlyOwner {
selfdestruct(owner);
}
}
/* 相当于
function close() public onlyOwner {
require(msg.sender == owner);
selfdestruct(owner);
}
*/
contract priced {
modifier costs(uint price) {
if (msg.value >= price) {
_;
}
}
}
// 继承合约priced,owned
contract Register is priced, owned {
mapping (address => bool) registeredAddresses;
uint price;
function Register(uint initialPrice) public {
price = initialPrice;
}
// 这里使用关键字payable很重要,否则函数将自动拒绝所有以太的转帐
function register() public payable costs(price) {
registeredAddresses[msg.sender] = true;
}
/* 相当于
function register() public payable costs(price) {
if (msg.value >= price) {
registeredAddresses[msg.sender] = true;
}
}
*/
function changePrice(uint _price) public onlyOwner {
price = _price;
}
/* 相当于
function changePrice(uint _price) public onlyOwner {
require(msg.sender == owner);
price = _price;
}
*/
}
contract Mutex {
bool locked;
modifier noReentrancy() {
require(!locked);
locked = true;
_;
locked = false;
}
function f() public noReentrancy returns (uint) {
require(msg.sender.call());
return 7;
}
/* 相当于
function f() public noReentrancy returns (uint) {
require(!locked);
locked = true;
require(msg.sender.call());
return 7;
locked = false;
}
*/
}
常量
pragma solidity ^0.4.0;
contract C {
uint constant NUMER = 32 ** 22 + 8;
string constant TEXT = "abc";
bytes32 constant MYHASH = keccak256("abc");
}
solidity语言11的更多相关文章
- Solidity语言系列教程
Solidity 是一门面向合约的.为实现智能合约而创建的高级编程语言.这门语言受到了 C++,Python 和 Javascript 语言的影响,设计的目的是能在 以太坊虚拟机(EVM) 上运行. ...
- 用solidity语言开发代币智能合约
智能合约开发是以太坊编程的核心之一,而代币是区块链应用的关键环节,下面我们来用solidity语言开发一个代币合约的实例,希望对大家有帮助. 以太坊的应用被称为去中心化应用(DApp),DApp的开发 ...
- 第一行代码:以太坊(2)-使用Solidity语言开发和测试智能合约
智能合约是以太坊的核心之一,用户可以利用智能合约实现更灵活的代币以及其他DApp.不过在深入讲解如何开发智能合约之前,需要先介绍一下以太坊中用于开发智能合约的Solidity语言,以及相关的开发和测试 ...
- solidity语言介绍以及开发环境准备
solidity语言介绍以及开发环境准备 Solidity 是一门面向合约的.为实现智能合约而创建的高级编程语言.这门语言受到了 C++,Python 和 Javascript 语言的影响,设计的 ...
- 用C++生成solidity语言描述的buchi自动机的初级经验
我的项目rvtool(https://github.com/Zeraka/rvtool)中增加了生成solidity语言格式的监控器的模块. solidity特殊之处在于,它是运行在以太坊虚拟机环境中 ...
- solidity语言5
结构体 pragma solidity ^0.4.11; // 众筹合约 contract CrowdFunding { // 投资者 struct Funder { address addr; ui ...
- solidity语言3
#函数类型(function type) function (<parameter types>) {internal|external(public)} [pure|constant|v ...
- solidity语言1
合约(contract)由变量(variable).函数(functions).函数修饰符(function modifiers).事件(events).结构体类型(struct type).枚举类型 ...
- Solidity语言基础 和 Etherum ERC20合约基础
1. 类型只能从第一次赋值中推断出来,因此以下代码中的循环是无限的, 小. for (var i = 0; i < 2000; i++) { ... } --- Solidity Types ...
随机推荐
- pyc和pycodeobject
Python是一个先编译再解释的语言. 执行过程:先寻找pyc文件,找到则载入,没找到则把编译的结果保存在pycodeobject中,运行结束则写到pyc文件中
- 教你搭建SpringMVC框架( 附源码)
一.项目目录结构 二.SpringMVC需要使用的jar包 commons-logging-1.2.jar junit-4.10.jar log4j-api-2.0.2.jar log4j-core- ...
- js中点和向量的基本方法
var Point=function(x,y){ this.x= Number(x.toFixed(2))||0; this.y=Number(y.toFixed(2))||0; } Point.pr ...
- PIE SDK图层树伙伴控件示例
1. 功能简介 TocControl控件的主要作用是显示当前加载的图层有哪些.采用什么样的符号等,目的是使用户对当前加载的数据和结构有一个总体的把握.与之相关联的伙伴控件有MapControl,Pa ...
- 使用Tomcat搭建一个可以通过公网访问的服务器(转)
转自:http://wenku.baidu.com/link?url=kGLhiO1xiiepXa9Q2OJDmm6Zr8dQmpSYYPVTFmc3CZtD6Z7HvFi2miCYDiQdTYF2T ...
- html5使用local storage存储的数据在本地是以何种形式保存的
html5使用local storage存储的数据是如何保存在本地的?(我使用的是chrome浏览器,chrom浏览器是用sqlite来保存本地数据的) Html5 的local storage 是通 ...
- python 生成嵌套字典
import collections import json tree=lambda:collections.defaultdict(tree) some_dict=tree() some_dict[ ...
- 企业DevOps构建 (一)
一,环境: tomcat 7.0.92 jenkins 1.658 maven mysql 5.5.23 mongodb 2.6.11 redis 4.0.12 01, 安装jenkins wge ...
- DP Intro - OBST
http://radford.edu/~nokie/classes/360/dp-opt-bst.html Overview Optimal Binary Search Trees - Problem ...
- opensuse install oracle 11gR2 Error in invoking target 'agent nmhs' of makefile '../ins_emagent.mk'
转自 http://blog.csdn.net/ly5156/article/details/6647563 遭遇Error in invoking target 'agent nmhs' of ma ...