14

Solidity 0.6.11 更新

 3 years ago
source link: https://learnblockchain.cn/article/1284
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Solidity 0.6.11 更新

Solidity 0.6.11 更新:

Solidity v0.6.11 adds inheritance to NatSpec comments, improves debugging data output and fixes some minor issues with opening up calldata for non-external functions.

Notable New Features

NatSpec Inheritance and on Events

NatSpec comments are a way to describe the behaviour of a function to end-users. It also allows to provide more detailed information to developers.

One regular use-case is that you document the behaviour of an interface and then implement the interface in a derived contract. Previously, you had to repeat the documentation in the derived contract. This is now obsolete: The compiler will automatically inherit the documentation of the base function if the derived function does not provide any NatSpec tag.

If you provide any of the tags ( @param , @dev , …), 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!

Furhermore, NatSpec is now supported on events.

// 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);
  }
}

The derived contract MyGathering in the example code above will produce the following 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
}

Unit Denomination gwei

You can now use gwei as a unit denomination alongside wei , szabo , finney and ether :

reqire(msg.value >= 10 gwei);

Solidity 0.6.11 更新:

Solidity v0.6.11 adds inheritance to NatSpec comments, improves debugging data output and fixes some minor issues with opening up calldata for non-external functions.

Notable New Features

NatSpec Inheritance and on Events

NatSpec comments are a way to describe the behaviour of a function to end-users. It also allows to provide more detailed information to developers.

One regular use-case is that you document the behaviour of an interface and then implement the interface in a derived contract. Previously, you had to repeat the documentation in the derived contract. This is now obsolete: The compiler will automatically inherit the documentation of the base function if the derived function does not provide any NatSpec tag.

If you provide any of the tags ( @param , @dev , …), 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!

Furhermore, NatSpec is now supported on events.

// 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);
  }
}

The derived contract MyGathering in the example code above will produce the following 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
}

Unit Denomination gwei

You can now use gwei as a unit denomination alongside wei , szabo , finney and ether :

reqire(msg.value >= 10 gwei);

本文参与登链社区写作激励计划 ,好文好收益,欢迎正在阅读的你也加入。

  • 发表于 24分钟前
  • 阅读 ( 12 )
  • 学分 ( 0 )
  • 分类:Solidity

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK