Nayuta_ja
Published in

Nayuta_ja

[Ethereum]Solidity v0.7リリース (2)

はじめに

前回に引き続き、Solidity v0.7のBreaking Changesを見ていく。

今回はRemix IDEを使って、コンパイルして確認する。

“http://remix.ethereum.org/”とhttpを要求されました

答え合わせのようなものなので、さらっと見ていく。「 nowはなくなって block.timestampになった」のようにあからさまな内容はスルーだ。

Changes to the Syntax

gasとvalueの指定

// SPDX-License-Identifier: Apache-2.0
pragma solidity >= 0.7.0;
contract Storage {
uint256 number;
function store(uint256 num) public payable {
number = num;
}
}
contract Storage2 {
Storage s;
function gasCall() public {
s.store{gas: 10000, value: 10000}(1000);
}
}

コンパイルの確認だけなので、 s に値を入れてないとか、そういうのは無視だ。

value の指定がなければ payable でなくてよい。

NatSpecコメント

// SPDX-License-Identifier: Apache-2.0
pragma solidity >= 0.7.0;
contract Storage {/**
* @dev The number
*/
uint256 number;
function store(uint256 num) public {
/**
* @dev Tom cat
*/
uint256 tom;
number = num;
}
}

tom のコメントがそれだが、コンパイルエラーは変数定義の行になった。

ParserError: Only state variables can have a docstring.

Unicode String literal

function store() public  {
//str = unicode"こんばんは";
str = "こんばんは"
}

コメントアウトした方の書き方だとOKなのだが、 unicode を付けていないとエラーになる。

ParserError: Invalid character in string.

State Mutability

例えば、これはv0.6でエラーになった。

// SPDX-License-Identifier: Apache-2.0
pragma solidity >= 0.6.0;
contract Storage {
uint256 number;
string str;
function store(uint256 num) public virtual returns(uint256) {
uint256 bak = number;
number = num;
return bak;
}
}
contract Storage2 is Storage {
function store(uint256) public override view returns(uint256) {
return 256;
}
}

Storage2の store() でエラーになる。

TypeError: Overriding function changes state mutability from “nonpayable” to “view”.

もちろん viewpure にしても同じ。

v0.7だとOKだ(pragmaも変更すること)。

Removal of Unused or Unsafe Features

Mappings outside Storage

これは mappingしているのは storageだからOKだ。

// SPDX-License-Identifier: Apache-2.0
pragma solidity >= 0.7.0;
contract Storage {
struct Neko {
string name;
}

mapping(uint256 => Neko) nekos;
function store(uint256 num) public {
nekos[num].name = "Tom";
}
}

memory 指定してローカル変数にしてみればよいのかと思ったのだが、これはv0.6でもエラーになる。

// SPDX-License-Identifier: Apache-2.0
pragma solidity >= 0.6.0;
contract Storage {
struct Neko {
uint256 age;
}
mapping(uint256 => Neko) nekos;function store(uint256 num) public {
mapping(uint256 => Neko) neko;
neko[num].age = nekos[num].age;
nekos[num].age = 126;
}
}

うーん、これは今回はあきらめよう。
わからん!

おわりに

そんなに影響はない、少なくとも私が練習で書いたSolidity程度では問題ない内容だ。

宿題が残ってしまったので、それは今後やっていこう。

https://ethereum.org/en/

Bitcoin2nd Layer技術-Lightning Networkのプロトコルとアプリケーションの開発を両輪で行う。最新のリリースの中にはBitcoin&Lightning MobileのWallet、Nayuta Coreがある。外部アプリと連携可能で自動的にBitcoinが手に入るストリーミングペイメント機能が特徴的。 また、様々なタイプのブロックチェーンが共存する時代が近づいていることから、エンタープライズ向けブロックチェーンに関するビジネスも行っている。

Share your ideas with millions of readers.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ueno

ueno

engineer

More from Medium

From Children of 80’s to the Children of 2000s:

https://www.wakefieldexpress.co.uk/images-a.jpimedia.uk/imagefetch/http://www.wakefieldexpress.co.uk/webimage/Prestige.Item.1.84061576!image/image.jpg?&width=990

USERSDAO

LAUSDland