Solidity 0.6.11 更新

时间:2022-07-22
本文章向大家介绍Solidity 0.6.11 更新,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Solidity v0.6.11[1] 为 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);

参考资料

[1]

Solidity v0.6.11: https://github.com/ethereum/solidity/releases/tag/v0.6.11


本文作者:Tiny熊

作者主页:

https://learnblockchain.cn/people/15