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 ...
随机推荐
- 不要重复发明轮子-C++STL
闫常友 著. 中国铁道出版社. 2013/5 标准的C++模板库,是算法和其他一些标准组件的集合. . 1.类模板简介 2.c++中的字符串 3.容器 4.c++中的算法 5.迭代器 6.STL 数值 ...
- 51Nod - 1179
给出N个正整数,找出N个数两两之间最大公约数的最大值.例如:N = 4,4个数为:9 15 25 16,两两之间最大公约数的最大值是15同25的最大公约数5. Input第1行:一个数N,表示输入 ...
- failed to push some refs to 'git@github.com:xxx/xxx.git' 解决方法
此时很多人会尝试下面的命令把当前分支代码上传到master分支上. $ git push -u origin master 但依然没能解决问题 会出现: failed to push some ref ...
- 图解DTS和PTS
由于把视频编码成I,B,P等帧,如下图 假设现在有I,B,P帧,那么要传输和显示呢?? 如果按照显示顺序传输的话: 传输顺序就是I->B>P 当对B帧进行解码后,由于B帧无法单独显 ...
- 抓包来看ftp状态码
1.quit退出 客户端输入退出命令: 退出的抓包数据交换过程: 2.用户登录,输入正确用户名和错误用户名都是返回331请求输入密码,这里不再将错误用户名的抓包数据交换过程截图. 数据交换过程: 服务 ...
- TOJ 2119 Tangled in Cables
描述 You are the owner of SmallCableCo and have purchased the franchise rights for a small town. Unfor ...
- 很有用的PHP笔试题系列二
1.如何用php的环境变量得到一个网页地址的内容?ip地址又要怎样得到? Gethostbyname() echo $_SERVER ["PHP_SELF"];echo $_SER ...
- 简单springboot及springboot cloud环境搭建
springboot使用特定的方式,简化了spring的各种xml配置文件,并通过maven或者gradle,完成所需依赖,使用springboot maven插件,可直接输出可运行的jar包,省去了 ...
- 使用 Azure CLI 创建虚拟机
使用 az vm create 命令创建虚拟机. 创建虚拟机时,可使用多个选项,例如操作系统映像.磁盘大小调整和管理凭据. 在此示例中,创建了一个名为“myVM”的运行 Ubuntu Server 的 ...
- Starting MySQL. ERROR! The server quit without updating PID file如何解决
今天数据库突然挂了.重启提示: Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql/v ...