Skip to content

Commit

Permalink
doc: Solidity class fields to Rust struct
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
0xf333 committed Aug 28, 2023
1 parent cd352e3 commit b802fa9
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions docs/intro/ink-vs-solidity.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,37 +94,39 @@ An example Solidity class looks like:

<!-- Markdown syntax highlighting does not support Solidity. C++ seems to be the best match -->

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

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 {
Expand All @@ -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;
Expand Down

0 comments on commit b802fa9

Please sign in to comment.