From b802fa942c06d76e7b12f6971ca7eae2ca648bbf Mon Sep 17 00:00:00 2001 From: 0xf333 <0x333@tuta.io> Date: Sun, 27 Aug 2023 15:32:54 -0400 Subject: [PATCH] doc: Solidity class fields to Rust struct Fix solidity example and update ink example to conform with v4 Description ============ - Added SPDX license identifier for Solidity. - Fixed the syntax for the `if` condition in Solidity. - Fixed event emit syntax. - Added `no_main` attribute in ink! contract. --- docs/intro/ink-vs-solidity.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/docs/intro/ink-vs-solidity.md b/docs/intro/ink-vs-solidity.md index a49232f8bc..f13cdba174 100644 --- a/docs/intro/ink-vs-solidity.md +++ b/docs/intro/ink-vs-solidity.md @@ -94,27 +94,31 @@ An example Solidity class looks like: -```c++ +```C++ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.1; + contract MyContract { bool private _theBool; event UpdatedBool(bool indexed _theBool); - constructor(bool theBool_) { - require(theBool_ == true, "theBool_ must start as true"); + constructor(bool theBool) { + require(theBool == true, "theBool must start as true"); - _theBool = theBool_; + _theBool = theBool; } function setBool(bool newBool) public returns (bool boolChanged) { - if _theBool == newBool { - boolChanged = false; + if (_theBool == newBool) { + boolChanged = false; } else { boolChanged = true; } _theBool = newBool; + // emit event - UpdatedBool(newBool); + emit UpdatedBool(newBool); } } ``` @@ -122,9 +126,7 @@ contract MyContract { And the equivalent contract in ink! looks like: ```rust -#![cfg_attr(not(feature = "std"), no_std)] - -use ink_lang as ink; +#![cfg_attr(not(feature = "std"), no_std, no_main)] #[ink::contract] mod mycontract { @@ -148,7 +150,7 @@ mod mycontract { #[ink(message)] // functions become struct implementations pub fn set_bool(&mut self, new_bool: bool) -> bool { - let bool_changed = true; + let bool_changed: bool; if self.the_bool == new_bool{ bool_changed = false;