Skip to content

Commit

Permalink
Update dependencies to Odra framework v1.4.0, update imports in code …
Browse files Browse the repository at this point in the history
…snippets
  • Loading branch information
kpob committed Oct 18, 2024
1 parent 910e16d commit b372416
Show file tree
Hide file tree
Showing 27 changed files with 74 additions and 114 deletions.
12 changes: 2 additions & 10 deletions docusaurus/docs/advanced/01-delegate.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ Consider the following basic example for better understanding:

```rust
use crate::{erc20::Erc20, ownable::Ownable};
use odra::{
Address, casper_types::U256,
module::SubModule,
prelude::*
};
use odra::{casper_types::U256, prelude::*};

#[odra::module]
pub struct OwnedToken {
Expand Down Expand Up @@ -70,11 +66,7 @@ Let's take a look at another example.

```rust
use crate::{erc20::Erc20, ownable::Ownable, exchange::Exchange};
use odra::{
Address, casper_types::U256,
module::SubModule,
prelude::*
};
use odra::{casper_types::U256, prelude::*};

#[odra::module]
pub struct DeFiPlatform {
Expand Down
4 changes: 2 additions & 2 deletions docusaurus/docs/advanced/02-advanced-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ However, there are more advanced scenarios where the value of the Mapping repres
Let's consider the following example:

```rust title="examples/src/features/storage/mapping.rs"
use odra::{casper_types::U256, Mapping, UnwrapOrRevert};
use odra::casper_types::U256;
use odra::prelude::*;
use crate::owned_token::OwnedToken;

Expand Down Expand Up @@ -87,7 +87,7 @@ Secondly, rather than utilizing the `Mapping::get()` function, call `Mapping::mo
The given code snippet showcases the `AdvancedStorage` contract that incorporates these storage concepts.

```rust
use odra::{Address, casper_types::U512, Sequence, Mapping};
use odra::casper_types::U512;
use odra::prelude::*;
use crate::modules::Token;

Expand Down
2 changes: 1 addition & 1 deletion docusaurus/docs/advanced/03-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl NonReentrantCounter {
#[cfg(test)]
mod test {
use super::*;
use odra::{host::{Deployer, NoArgs}, ExecutionError};
use odra::host::{Deployer, NoArgs};

#[test]
fn ref_recursion_not_allowed() {
Expand Down
6 changes: 3 additions & 3 deletions docusaurus/docs/basics/02-directory-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ version = "0.1.0"
edition = "2021"

[dependencies]
odra = "1.1.0"
odra = "1.4.0"

[dev-dependencies]
odra-test = "1.1.0"
odra-test = "1.4.0"

[build-dependencies]
odra-build = "1.1.0"
odra-build = "1.4.0"

[[bin]]
name = "sample_build_contract"
Expand Down
8 changes: 3 additions & 5 deletions docusaurus/docs/basics/05-storage-interaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ variable in the `Var` type. Let's look at a "real world" example of a contract t

```rust title="examples/src/features/storage/variable.rs"
use odra::prelude::*;
use odra::Var;

#[odra::module]
pub struct DogContract {
Expand Down Expand Up @@ -105,7 +104,6 @@ uses `Mapping` to store information about our dog's friends and how many times t

```rust title="examples/src/features/storage/mapping.rs"
use odra::prelude::*;
use odra::{Mapping, Var};

#[odra::module]
pub struct DogContract2 {
Expand Down Expand Up @@ -139,7 +137,7 @@ If you take a look into List implementation in Odra, you'll see that in fact it
a Var working together:

```rust title="core/src/list.rs"
use odra::{List, Var};
use odra::prelude::*;

pub struct List<T> {
values: Mapping<u32, T>,
Expand All @@ -153,7 +151,7 @@ Going back to our DogContract example - let's revisit the walk case. This time,
we'll use the list:

```rust title="examples/src/features/storage/list.rs"
use odra::{prelude::*, List, Var};
use odra::prelude::*;

#[odra::module]
pub struct DogContract3 {
Expand Down Expand Up @@ -206,7 +204,7 @@ By default you can store only built-in types like numbers, Options, Results, Str
Implementing custom types is straightforward, your type must add `#[odra::odra_type]` attribute. Let's see how to implement a `Dog` type:

```rust
use odra::Address;
use odra::prelude::*;

#[odra::odra_type]
pub struct Dog {
Expand Down
1 change: 0 additions & 1 deletion docusaurus/docs/basics/06-communicating-with-host.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ what is the current time? Who called me? Following example shows how to do this:

```rust title="examples/src/features/host_functions.rs"
use odra::prelude::*;
use odra::{Address, Var};

#[odra::module]
pub struct HostContract {
Expand Down
2 changes: 1 addition & 1 deletion docusaurus/docs/basics/07-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ regular Rust unit and integration tests. Have a look at how we test the Dog Cont
previous article:

```rust title="examples/src/features/storage/list.rs"
use odra::{List, Var};
use odra::prelude::*;

#[cfg(test)]
mod tests {
Expand Down
1 change: 0 additions & 1 deletion docusaurus/docs/basics/08-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ following example of a simple owned contract:

```rust title="examples/src/features/handling_errors.rs"
use odra::prelude::*;
use odra::{Address, Var};

#[odra::module(errors = Error)]
pub struct OwnedContract {
Expand Down
1 change: 0 additions & 1 deletion docusaurus/docs/basics/09-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ In the EVM world events are stored as logs within the blockchain's transaction r

```rust title="examples/src/features/events.rs"
use odra::prelude::*;
use odra::Address;

#[odra::module(events = [PartyStarted])]
pub struct PartyContract;
Expand Down
4 changes: 2 additions & 2 deletions docusaurus/docs/basics/10-cross-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: Contracts calling contracts
To show how to handle calls between contracts, first, let's implement two of them:

```rust title="examples/src/features/cross_calls.rs"
use odra::{prelude::*, Address, External};
use odra::prelude::*;

#[odra::module]
pub struct CrossContract {
Expand Down Expand Up @@ -149,7 +149,7 @@ Let's continue assuming there is a contract featuring the `add()` function that
#[cfg(test)]
mod tests {
use super::*;
use odra::{Address, host::{Deployer, HostRef, NoArgs}};
use odra::{host::{Deployer, HostRef, NoArgs}};

#[test]
fn test_ext() {
Expand Down
1 change: 0 additions & 1 deletion docusaurus/docs/basics/11-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ example from the previous article, to use a single contract, but still separate

```rust title="examples/src/features/modules.rs"
use crate::features::cross_calls::MathEngine;
use odra::module::SubModule;
use odra::prelude::*;

#[odra::module]
Expand Down
2 changes: 1 addition & 1 deletion docusaurus/docs/basics/12-native-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ their funds and anyone can withdraw them:

```rust title="examples/src/features/native_token.rs"
use odra::prelude::*;
use odra::{casper_types::U512, module::Module};
use odra::casper_types::U512;

#[odra::module]
pub struct PublicWallet;
Expand Down
1 change: 0 additions & 1 deletion docusaurus/docs/basics/13-casper-contract-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ If you forget to register events and errors in the module attribute, the definit

```rust showLineNumbers title="src/contract.rs"
use odra::prelude::*;
use odra::{Address, Var};

#[odra::module(
// the name of the contract, default is the module name
Expand Down
12 changes: 6 additions & 6 deletions docusaurus/docs/examples/using-odra-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ version = "0.1.0"
edition = "2021"

[dependencies]
odra = "1.1.0"
odra = "1.4.0"

[dev-dependencies]
odra-test = "1.1.0"
odra-test = "1.4.0"

[build-dependencies]
odra-build = "1.1.0"
odra-build = "1.4.0"

[[bin]]
name = "my_project_build_contract"
Expand All @@ -45,8 +45,8 @@ To use `odra-modules`, edit your `dependency` and `features` sections.

```toml title=Cargo.toml
[dependencies]
odra = "1.1.0"
odra-modules = "1.1.0"
odra = "1.4.0"
odra-modules = "1.4.0"
```

Now, the only thing left is to add a module to your contract.
Expand All @@ -55,7 +55,7 @@ Let's write an example of `MyToken` based on `Erc20` module.

```rust
use odra::prelude::*;
use odra::{Address, casper_types::U256, module::SubModule};
use odra::casper_types::U256;
use odra_modules::erc20::Erc20;

#[odra::module]
Expand Down
2 changes: 1 addition & 1 deletion docusaurus/docs/getting-started/flipper.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ For further explanation of how this code works, see [Flipper Internals](../basic
## Let's flip

```rust title="flipper.rs" showLineNumbers
use odra::Var;
use odra::prelude::*;

/// A module definition. Each module struct consists Vars and Mappings
/// or/and another modules.
Expand Down
4 changes: 2 additions & 2 deletions docusaurus/docs/migrations/to-1.3.0.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
sidebar_position: 1
description: Migration guide to v0.8.0
sidebar_position: 3
description: Migration guide to v1.3.0
---

import Tabs from '@theme/Tabs';
Expand Down
24 changes: 11 additions & 13 deletions docusaurus/docs/tutorials/access-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ There are three actions that can be performed concerning a `Role`: granting, rev

```rust title=events.rs showLineNumbers
use odra::prelude::*;
use odra::Address;
use super::access_control::Role;

#[odra::event]
Expand All @@ -66,8 +65,8 @@ pub struct RoleAdminChanged {
pub new_admin_role: Role
}
```
* **L5-L17** - to describe the grant or revoke actions, our events specify the `Role`, and `Address`es indicating who receives or loses access and who provides or withdraws it.
* **L19-L24** - the event describing the admin role change, requires the subject `Role`, the previous and the current admin `Role`.
* **L4-L16** - to describe the grant or revoke actions, our events specify the `Role`, and `Address`es indicating who receives or loses access and who provides or withdraws it.
* **L18-L23** - the event describing the admin role change, requires the subject `Role`, the previous and the current admin `Role`.

```rust title=errors.rs
#[odra::odra_error]
Expand All @@ -89,7 +88,6 @@ Now, we are stepping into the most interesting part: the module definition and i
use super::events::*;
use super::errors::Error;
use odra::prelude::*;
use odra::{Address, Mapping};

pub type Role = [u8; 32];

Expand Down Expand Up @@ -174,15 +172,15 @@ impl AccessControl {
}
}
```
* **L6** - Firstly, we need the `Role` type. It is simply an alias for a 32-byte array.
* **L8** - The default role is an array filled with zeros.
* **L5** - Firstly, we need the `Role` type. It is simply an alias for a 32-byte array.
* **L7** - The default role is an array filled with zeros.
* **L10-L13** - The storage consists of two mappings:
1. `roles` - a nested mapping that stores information about whether a certain Role is granted to a given `Address`.
2. `role_admin` - each `Role` can have a single admin `Role`.
* **L18-L20** - This is a simple check to determine if a `Role` has been granted to a given `Address`. It is an exposed entry point and an important building block widely used throughout the entire module.
* **L49** - This is a non-exported block containing helper functions.
* **L50-L54** - The `check_role()` function serves as a guard function. Before a `Role` is granted or revoked, we must ensure that the caller is allowed to do so. For this purpose, the function reads the roles mapping. If the role has not been granted to the address, the contract reverts with `Error::MissingRole`.
* **L56-L64** - The `set_admin_role()` function simply updates the role_admin mapping and emits the `RoleAdminChanged` event.
* **L66-L86** - The `unchecked_grant_role()` and `unchecked_revoke_role()` functions are mirror functions that update the roles mapping and post `RoleGranted` or `RoleRevoked` events. If the role is already granted, `unchecked_grant_role()` has no effect (the opposite check is made in the case of revoking a role).
* **L22-L29** - The `get_role_admin()` entry point reads the role_admin. If there is no admin role for a given role, it returns the default role.
* **L31-L46** - This is a combination of `check_role()` and `unchecked_*_role()`. Entry points fail on unauthorized access.
* **L17-L19** - This is a simple check to determine if a `Role` has been granted to a given `Address`. It is an exposed entry point and an important building block widely used throughout the entire module.
* **L48** - This is a non-exported block containing helper functions.
* **L49-L53** - The `check_role()` function serves as a guard function. Before a `Role` is granted or revoked, we must ensure that the caller is allowed to do so. For this purpose, the function reads the roles mapping. If the role has not been granted to the address, the contract reverts with `Error::MissingRole`.
* **L55-L63** - The `set_admin_role()` function simply updates the role_admin mapping and emits the `RoleAdminChanged` event.
* **L65-L85** - The `unchecked_grant_role()` and `unchecked_revoke_role()` functions are mirror functions that update the roles mapping and post `RoleGranted` or `RoleRevoked` events. If the role is already granted, `unchecked_grant_role()` has no effect (the opposite check is made in the case of revoking a role).
* **L21-L28** - The `get_role_admin()` entry point reads the role_admin. If there is no admin role for a given role, it returns the default role.
* **L30-L45** - This is a combination of `check_role()` and `unchecked_*_role()`. Entry points fail on unauthorized access.
2 changes: 1 addition & 1 deletion docusaurus/docs/tutorials/build-deploy-read.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ We will expose two methods:
2. The method `set_data` which sets the value of the numeric field and the values of the mapping.

```rust title=custom_item.rs showLineNumbers
use odra::{casper_types::U256, prelude::*, Mapping, SubModule, Var};
use odra::{casper_types::U256, prelude::*};

// A custom type with a vector of another custom type
#[odra::odra_type]
Expand Down
2 changes: 1 addition & 1 deletion docusaurus/docs/tutorials/cep18.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ and using tools from the Casper Ecosystem to interact with it.
Here is the complete code of the `OurToken` module:

```rust showLineNumbers title="src/token.rs"
use odra::{casper_types::U256, prelude::*, Address, List, SubModule, Var};
use odra::{casper_types::U256, prelude::*};
use odra_modules::cep18_token::Cep18;

/// A ballot cast by a voter.
Expand Down
12 changes: 6 additions & 6 deletions docusaurus/docs/tutorials/deploying-on-casper.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use std::str::FromStr;

use odra::casper_types::U256;
use odra::host::{Deployer, HostEnv, HostRef, HostRefLoader};
use odra::Address;
use odra::prelude::Address;
use ourcoin::token::{OurToken, OurToken, OurTokenInitArgs};

fn main() {
Expand Down Expand Up @@ -141,15 +141,15 @@ version = "0.1.0"
edition = "2021"

[dependencies]
odra = { version = "1.1.0", features = [], default-features = false }
odra-modules = { version = "1.1.0", features = [], default-features = false }
odra-casper-livenet-env = { version = "1.1.0", optional = true }
odra = { version = "1.4.0", features = [], default-features = false }
odra-modules = { version = "1.4.0", features = [], default-features = false }
odra-casper-livenet-env = { version = "1.4.0", optional = true }

[dev-dependencies]
odra-test = { version = "1.1.0", features = [], default-features = false }
odra-test = { version = "1.4.0", features = [], default-features = false }

[build-dependencies]
odra-build = { version = "1.1.0", features = [], default-features = false }
odra-build = { version = "1.4.0", features = [], default-features = false }

[features]
default = []
Expand Down
4 changes: 1 addition & 3 deletions docusaurus/docs/tutorials/erc20.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ It is designed to store the following data:
## Module definition
```rust title=erc20.rs showLineNumbers
use odra::prelude::*;
use odra::{Address, casper_types::U256, Mapping, Var};
use odra::casper_types::U256;

#[odra::module(events = [Transfer, Approval])]
pub struct Erc20 {
Expand Down Expand Up @@ -99,8 +99,6 @@ pub struct Transfer {
* **L28** - The second `impl` is not an Odra module; in other words, these functions will not be part of the contract's public interface.
* **L29-L38** - The `mint` function is public, so, like in regular Rust code, it will be accessible from the outside. `mint()` uses the notation `self.balances.add(address, *amount);`, which is syntactic sugar for:
```rust
use odra::UnwrapOrRevert;

let current_balance = self.balances.get(address).unwrap_or_default();
let new_balance = <U256 as OverflowingAdd>::overflowing_add(current_balance, current_balance).unwrap_or_revert(&self.env());
self.balances.set(address, new_balance);
Expand Down
Loading

0 comments on commit b372416

Please sign in to comment.