Skip to content

Commit

Permalink
Fixed FunctionModifier code in Solidity tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
zie1ony committed Jul 3, 2024
1 parent 8e3374b commit 88a6529
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 8 additions & 3 deletions docusaurus/docs/tutorials/odra-sol.md
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ In Odra, you don't need to specify `view` or `pure` functions explicitly. All fu
<TabItem value="rust" label="Odra">

```rust showLineNumbers
use odra::Var;
use odra::{module::Module, Var};

#[odra::module]
pub struct FunctionModifier {
Expand All @@ -753,7 +753,7 @@ pub struct FunctionModifier {

#[odra::module]
impl FunctionModifier {
pub fn decrement(&mut self, i: u32) -> u32 {
pub fn decrement(&mut self, i: u32) {
self.lock();
self.x.set(self.x.get_or_default() - i);

Expand All @@ -766,7 +766,7 @@ impl FunctionModifier {
#[inline]
fn lock(&mut self) {
if self.locked.get_or_default() {
self.env().revert("No reentrancy");
self.env().revert(Error::NoReentrancy);
}

self.locked.set(true);
Expand All @@ -778,6 +778,11 @@ impl FunctionModifier {
}
}

#[odra::odra_error]
pub enum Error {
NoReentrancy = 1,
}

```
</TabItem>

Expand Down
11 changes: 8 additions & 3 deletions docusaurus/versioned_docs/version-1.1.0/tutorials/odra-sol.md
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ In Odra, you don't need to specify `view` or `pure` functions explicitly. All fu
<TabItem value="rust" label="Odra">

```rust showLineNumbers
use odra::Var;
use odra::{module::Module, Var};

#[odra::module]
pub struct FunctionModifier {
Expand All @@ -753,7 +753,7 @@ pub struct FunctionModifier {

#[odra::module]
impl FunctionModifier {
pub fn decrement(&mut self, i: u32) -> u32 {
pub fn decrement(&mut self, i: u32) {
self.lock();
self.x.set(self.x.get_or_default() - i);

Expand All @@ -766,7 +766,7 @@ impl FunctionModifier {
#[inline]
fn lock(&mut self) {
if self.locked.get_or_default() {
self.env().revert("No reentrancy");
self.env().revert(Error::NoReentrancy);
}

self.locked.set(true);
Expand All @@ -778,6 +778,11 @@ impl FunctionModifier {
}
}

#[odra::odra_error]
pub enum Error {
NoReentrancy = 1,
}

```
</TabItem>

Expand Down

0 comments on commit 88a6529

Please sign in to comment.