Solidity 0.6.11 更新

  • Tiny熊
  • 更新于 2020-07-21 09:15
  • 阅读 2342

Solidity 0.6.11 更新: 文档注释防范(NatSpec)支持了继承及事件, 新的单位面值 gwei

Solidity v0.6.11 为NatSpec注释添加了继承性,改进了调试数据输出,并修复了为非外部函数打开calldata的一些小问题。

值得关注的改进

文档注释防范(NatSpec)支持了继承及事件

NatSpec注释是一种向最终用户描述函数行为的方式。 以便为开发者提供更详细的信息。

一个常见的用例是用来记录接口的行为,然后在派生合约(子合约)中实现该接口。 以前,必须派生合约中复制文档。 现在不需要了,如果派生函数不提供任何NatSpec标签,则编译器将自动继承父合约函数的文档。

如果在派生合约函数中使用了任何标签(@param, @dev, …),则不会继承,在这种情况下,下一个发行版将提供一项功能,以明确地从某个特定父合约继承,因此请继续关注!

If you provide any of the tags (), then nothing will be inherited. The next release will provide a feature to explicitly inherit from a certain base also in that case, so stay tuned!

此外,事件现在支持NatSpec。

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.11;
interface Gathering {
  /// The address `participant` just registered for the gathering.
  event Registered(address participant);

  /// Registers `msg.sender` to take part in the gathering.
  function register() external;
}

contract MyGathering is Gathering {
  mapping(address => bool) public participants;

  function register() public override {
    participants[msg.sender] = true;
    emit Registered(msg.sender);
  }
}

在以上示例的派生合约MyGathering 会生成一下的用户文档(userdoc):

{
    "events": {
        "Registered(address)": {
            "notice": "The address `participant` just registered for the gathering."
        }
    },
    "kind": "user",
    "methods": {
        "register()": {
            "notice": "Registers `msg.sender` to take part in the gathering."
        }
    },
    "version": 1
}

新的单位面值 gwei

现在可以使用 gwei 作为单位了,就像使用 wei, szabo, finneyether 一样:

reqire(msg.value >= 10 gwei);
点赞 0
收藏 0
分享
本文参与登链社区写作激励计划 ,好文好收益,欢迎正在阅读的你也加入。

相关问题

0 条评论

请先 登录 后评论
Tiny熊
Tiny熊
0xD682...E8AB
登链社区发起人 通过区块链技术让世界变得更好而尽一份力。