solidity语言11

摘要:
自毁(所有者);拥有的{mapping(address=>bool)registeredAddresses;}functionf()publicnoReentransycreturns(uint){require(msg.ssenter.call());locked=true;require(message.ssenter/call();locked=false;

函数修饰符

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》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇ZH奶酪:Linux/Ubuntu 安装/卸载 软件Bootstrap: 样式CSS:carousel轮换 图片的使用下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

php实现文件下载代码一例

php实现文件下载代码 需要用到header函数来发送相关信息给客户端浏览器,同时再结合filesize函数来读取文件大小并进行下载操作。简单的文件下载只需要使用HTML的连接标记<a>,并将属性href的URL值指定为下载的文件即可。 文件下载,只能处理一些浏览器不能默认识别的MIME类型文件,例如当访问book.rar文件时,浏览器并没有直...

Qt入门之常用Qt标准对话框之QMessageBox

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://devbean.blog.51cto.com/448512/217694 好久没有更新博客,主要是公司里面还在验收一些东西,所以没有及时更新。而且也在写一个基于Qt的画图程序,基本上类似于PS的东西,主要用到的是Qt Graphics...

PHP中define和defined的区别

PHP中define和defined的区别   对于初学者会混淆这两个函数1.define用来定义一个常量,常量也是全局范围的。不用管作用域就可以在脚本的任何地方访问常量。一个常量一旦被定义,就不能再改变或者取消定义如:  define("path","mlx1036@163.com")  define为常mlx1036@163.com为常量的值     2...

AssertValid函数学习

转自http://tsitao.blog.163.com/blog/static/29795822006914105840496/ VC的调试中,AssertValid和Dump函数的应用 CObject::AssertValid 成员函数提供对对象内部状态的运行时检查。虽然从 CObject 派生类时不须要重写 AssertValid,但能...

malloc函数分配内存失败的常见原因

malloc()函数分配内存失败的常见原因:  1. 内存不足。  2. 在前面的程序中出现了内存的越界访问,导致malloc()分配函数所涉及的一些信息被破坏。下次再使用malloc()函数申请内存就会失败,返回空指针NULL(0)。 malloc中做了哪些事情:  简单的说就是系统中有一个位置标记,标记了 当前已经用掉的内存用到了什么位置,系统中还有...

Mongoose

Mongoose轻松搞定MongoDB MEAN开发栈中使用MongoDB的时候,与之配对的ORM最好的选择就是Mongoose了。本文就和大家一起探讨一下如何使用Mongoose来实现MongoDB的增删改查。 为了能使文中的例子更加生动,我们会实现一个对于用户的增删改查的RESTful API。 Mongoose简介 mongoose是一个nodejs...