Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Solidity class fields to Rust struct #264

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
0xf333 marked this conversation as resolved.
Show resolved Hide resolved
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;
0xf333 marked this conversation as resolved.
Show resolved Hide resolved

if self.the_bool == new_bool{
bool_changed = false;
Expand Down