From b3724168ddbc4b59bf6b0b925ac020cca62b4b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Pobiar=C5=BCyn?= Date: Fri, 18 Oct 2024 11:27:01 +0200 Subject: [PATCH] Update dependencies to Odra framework v1.4.0, update imports in code snippets --- docusaurus/docs/advanced/01-delegate.md | 12 +----- .../docs/advanced/02-advanced-storage.md | 4 +- docusaurus/docs/advanced/03-attributes.md | 2 +- .../docs/basics/02-directory-structure.md | 6 +-- .../docs/basics/05-storage-interaction.md | 8 ++-- .../docs/basics/06-communicating-with-host.md | 1 - docusaurus/docs/basics/07-testing.md | 2 +- docusaurus/docs/basics/08-errors.md | 1 - docusaurus/docs/basics/09-events.md | 1 - docusaurus/docs/basics/10-cross-calls.md | 4 +- docusaurus/docs/basics/11-modules.md | 1 - docusaurus/docs/basics/12-native-token.md | 2 +- .../docs/basics/13-casper-contract-schema.md | 1 - .../docs/examples/using-odra-modules.md | 12 +++--- docusaurus/docs/getting-started/flipper.md | 2 +- docusaurus/docs/migrations/to-1.3.0.md | 4 +- docusaurus/docs/tutorials/access-control.md | 24 +++++------ .../docs/tutorials/build-deploy-read.md | 2 +- docusaurus/docs/tutorials/cep18.md | 2 +- .../docs/tutorials/deploying-on-casper.md | 12 +++--- docusaurus/docs/tutorials/erc20.md | 4 +- docusaurus/docs/tutorials/nft.md | 18 ++++---- docusaurus/docs/tutorials/odra-sol.md | 41 ++++++++----------- docusaurus/docs/tutorials/ownable.md | 5 +-- docusaurus/docs/tutorials/owned-token.md | 3 +- docusaurus/docs/tutorials/pauseable.md | 6 --- .../docs/tutorials/using-proxy-caller.md | 8 ++-- 27 files changed, 74 insertions(+), 114 deletions(-) diff --git a/docusaurus/docs/advanced/01-delegate.md b/docusaurus/docs/advanced/01-delegate.md index 32b9b5f56..32caf3336 100644 --- a/docusaurus/docs/advanced/01-delegate.md +++ b/docusaurus/docs/advanced/01-delegate.md @@ -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 { @@ -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 { diff --git a/docusaurus/docs/advanced/02-advanced-storage.md b/docusaurus/docs/advanced/02-advanced-storage.md index c14252873..a6a92194d 100644 --- a/docusaurus/docs/advanced/02-advanced-storage.md +++ b/docusaurus/docs/advanced/02-advanced-storage.md @@ -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; @@ -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; diff --git a/docusaurus/docs/advanced/03-attributes.md b/docusaurus/docs/advanced/03-attributes.md index 6706e5241..bc27b784d 100644 --- a/docusaurus/docs/advanced/03-attributes.md +++ b/docusaurus/docs/advanced/03-attributes.md @@ -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() { diff --git a/docusaurus/docs/basics/02-directory-structure.md b/docusaurus/docs/basics/02-directory-structure.md index d2fbac53c..e551de2cd 100644 --- a/docusaurus/docs/basics/02-directory-structure.md +++ b/docusaurus/docs/basics/02-directory-structure.md @@ -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" diff --git a/docusaurus/docs/basics/05-storage-interaction.md b/docusaurus/docs/basics/05-storage-interaction.md index 759a053f6..5977227cf 100644 --- a/docusaurus/docs/basics/05-storage-interaction.md +++ b/docusaurus/docs/basics/05-storage-interaction.md @@ -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 { @@ -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 { @@ -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 { values: Mapping, @@ -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 { @@ -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 { diff --git a/docusaurus/docs/basics/06-communicating-with-host.md b/docusaurus/docs/basics/06-communicating-with-host.md index 56449105c..8278ffe89 100644 --- a/docusaurus/docs/basics/06-communicating-with-host.md +++ b/docusaurus/docs/basics/06-communicating-with-host.md @@ -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 { diff --git a/docusaurus/docs/basics/07-testing.md b/docusaurus/docs/basics/07-testing.md index 70d1cee5f..980e32e14 100644 --- a/docusaurus/docs/basics/07-testing.md +++ b/docusaurus/docs/basics/07-testing.md @@ -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 { diff --git a/docusaurus/docs/basics/08-errors.md b/docusaurus/docs/basics/08-errors.md index 6c73ac5d2..3cd4e6b83 100644 --- a/docusaurus/docs/basics/08-errors.md +++ b/docusaurus/docs/basics/08-errors.md @@ -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 { diff --git a/docusaurus/docs/basics/09-events.md b/docusaurus/docs/basics/09-events.md index 5d59d0674..94b091de3 100644 --- a/docusaurus/docs/basics/09-events.md +++ b/docusaurus/docs/basics/09-events.md @@ -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; diff --git a/docusaurus/docs/basics/10-cross-calls.md b/docusaurus/docs/basics/10-cross-calls.md index deec637a2..fe259388e 100644 --- a/docusaurus/docs/basics/10-cross-calls.md +++ b/docusaurus/docs/basics/10-cross-calls.md @@ -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 { @@ -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() { diff --git a/docusaurus/docs/basics/11-modules.md b/docusaurus/docs/basics/11-modules.md index 02418f754..60be6bbd6 100644 --- a/docusaurus/docs/basics/11-modules.md +++ b/docusaurus/docs/basics/11-modules.md @@ -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] diff --git a/docusaurus/docs/basics/12-native-token.md b/docusaurus/docs/basics/12-native-token.md index 2600e636f..46079473c 100644 --- a/docusaurus/docs/basics/12-native-token.md +++ b/docusaurus/docs/basics/12-native-token.md @@ -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; diff --git a/docusaurus/docs/basics/13-casper-contract-schema.md b/docusaurus/docs/basics/13-casper-contract-schema.md index 059093e06..bb7f2a672 100644 --- a/docusaurus/docs/basics/13-casper-contract-schema.md +++ b/docusaurus/docs/basics/13-casper-contract-schema.md @@ -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 diff --git a/docusaurus/docs/examples/using-odra-modules.md b/docusaurus/docs/examples/using-odra-modules.md index d10b624b2..e0741b7d8 100644 --- a/docusaurus/docs/examples/using-odra-modules.md +++ b/docusaurus/docs/examples/using-odra-modules.md @@ -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" @@ -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. @@ -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] diff --git a/docusaurus/docs/getting-started/flipper.md b/docusaurus/docs/getting-started/flipper.md index 37dfc6b6a..e1c8c9af6 100644 --- a/docusaurus/docs/getting-started/flipper.md +++ b/docusaurus/docs/getting-started/flipper.md @@ -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. diff --git a/docusaurus/docs/migrations/to-1.3.0.md b/docusaurus/docs/migrations/to-1.3.0.md index 8d95c4bcf..e43623318 100644 --- a/docusaurus/docs/migrations/to-1.3.0.md +++ b/docusaurus/docs/migrations/to-1.3.0.md @@ -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'; diff --git a/docusaurus/docs/tutorials/access-control.md b/docusaurus/docs/tutorials/access-control.md index e03c56f4e..c7851bee6 100644 --- a/docusaurus/docs/tutorials/access-control.md +++ b/docusaurus/docs/tutorials/access-control.md @@ -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] @@ -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] @@ -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]; @@ -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. diff --git a/docusaurus/docs/tutorials/build-deploy-read.md b/docusaurus/docs/tutorials/build-deploy-read.md index 2a050a49b..79e42f999 100644 --- a/docusaurus/docs/tutorials/build-deploy-read.md +++ b/docusaurus/docs/tutorials/build-deploy-read.md @@ -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] diff --git a/docusaurus/docs/tutorials/cep18.md b/docusaurus/docs/tutorials/cep18.md index 842ea3596..7dcee4390 100644 --- a/docusaurus/docs/tutorials/cep18.md +++ b/docusaurus/docs/tutorials/cep18.md @@ -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. diff --git a/docusaurus/docs/tutorials/deploying-on-casper.md b/docusaurus/docs/tutorials/deploying-on-casper.md index 3e576f4d6..49194540d 100644 --- a/docusaurus/docs/tutorials/deploying-on-casper.md +++ b/docusaurus/docs/tutorials/deploying-on-casper.md @@ -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() { @@ -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 = [] diff --git a/docusaurus/docs/tutorials/erc20.md b/docusaurus/docs/tutorials/erc20.md index 2ece97725..755e530fb 100644 --- a/docusaurus/docs/tutorials/erc20.md +++ b/docusaurus/docs/tutorials/erc20.md @@ -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 { @@ -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 = ::overflowing_add(current_balance, current_balance).unwrap_or_revert(&self.env()); self.balances.set(address, new_balance); diff --git a/docusaurus/docs/tutorials/nft.md b/docusaurus/docs/tutorials/nft.md index f27b365fb..76cee417d 100644 --- a/docusaurus/docs/tutorials/nft.md +++ b/docusaurus/docs/tutorials/nft.md @@ -33,7 +33,7 @@ Let's start implementing the `TicketOffice` contract by modify the code generate ```rust showLineNumbers title="src/token.rs" use odra::{ - args::Maybe, casper_types::U512, prelude::*, Address, Mapping, SubModule, UnwrapOrRevert + args::Maybe, casper_types::U512, prelude::* }; use odra_modules::access::Ownable; use odra_modules::cep78::{ @@ -294,7 +294,7 @@ cargo odra generate -c ticket_operator ```rust showLineNumbers title="src/ticket_operator.rs" use crate::token::{TicketId, TicketOfficeContractRef}; -use odra::{casper_types::U512, prelude::*, Address, UnwrapOrRevert, Var}; +use odra::{casper_types::U512, prelude::*}; #[odra::odra_error] pub enum Error { @@ -342,10 +342,6 @@ impl TicketOperator { Now we need to adjust the `TicketOffice` contract to use the `TicketOperator` contract to buy tickets. ```rust showLineNumbers title="src/token.rs" -use odra::Var; - -... - #[odra::odra_error] pub enum Error { ... @@ -413,10 +409,10 @@ impl TicketOffice { } } ``` -* **L15** - the contract stores the operator address. -* **L22-L29** - a new function `register_operator` allows the owner to register an operator. Also calls the `register` entry point on the operator contract. -* **L36-38** - modify the `issue_ticket` function: once a new token is minted, approves the operator to transfer the ticket later. -* **L44-L57** - modify the `buy_ticket` function: check if the caller is the operator, do not transfer cspr to the contract - now the operator collect funds. +* **L11** - the contract stores the operator address. +* **L18-L25** - a new function `register_operator` allows the owner to register an operator. Also calls the `register` entry point on the operator contract. +* **L32-36** - modify the `issue_ticket` function: once a new token is minted, approves the operator to transfer the ticket later. +* **L40-L53** - modify the `buy_ticket` function: check if the caller is the operator, do not transfer cspr to the contract - now the operator collect funds. * We also added two helper functions: `is_operator` and `operator` to check if the caller is the operator and get the operator address. Two new errors were added: `MissingOperator` and `Unauthorized`. Now we need to update our tests to create a scenario we presented in the sequence diagram. @@ -425,7 +421,7 @@ Now we need to update our tests to create a scenario we presented in the sequenc use odra::{ casper_types::U512, host::{Deployer, HostRef, NoArgs}, - OdraResult, + prelude::* }; use crate::{ diff --git a/docusaurus/docs/tutorials/odra-sol.md b/docusaurus/docs/tutorials/odra-sol.md index fba4342a3..bc9b517c6 100644 --- a/docusaurus/docs/tutorials/odra-sol.md +++ b/docusaurus/docs/tutorials/odra-sol.md @@ -29,7 +29,7 @@ Let's start with a simple "Hello World" contract in Odra. The following code sni ```rust showLineNumbers -use odra::{prelude::*, Var}; +use odra::prelude::*; #[odra::module] pub struct HelloWorld { @@ -76,12 +76,7 @@ Two key differences are: ```rust showLineNumbers use core::str::FromStr; -use odra::{ - casper_types::{bytesrepr::Bytes, U256}, - module::Module, - prelude::*, - Address, UnwrapOrRevert, Var, -}; +use odra::{casper_types::{bytesrepr::Bytes, U256}, prelude::*}; #[odra::module] pub struct Primitives { @@ -185,7 +180,7 @@ Values are stored in units called `Named Keys` and `Dictionaries`. Additionally, ```rust showLineNumbers -use odra::{casper_types::{account::AccountHash, U256}, Address}; +use odra::{casper_types::{account::AccountHash, U256}, prelude::*}; #[odra::module] pub struct Constants; @@ -224,7 +219,7 @@ In Odra, you can define constants using the `const` keyword. Constants are immut ```rust showLineNumbers -use odra::{casper_types::U256, prelude::*, Var}; +use odra::{casper_types::U256, prelude::*}; #[odra::module] pub struct Variables { @@ -282,7 +277,7 @@ In Solidity there are three types of variables: state variables, local variables ```rust showLineNumbers -use odra::{casper_types::U256, Address, Mapping}; +use odra::{casper_types::U256, prelude::*}; #[odra::module] pub struct MappingContract { @@ -374,7 +369,7 @@ contract NestedMapping { ```rust showLineNumbers -use odra::{prelude::*, Var}; +use odra::prelude::*; #[odra::module] pub struct Array { @@ -479,7 +474,7 @@ For storing a collection of data as a single unit, Odra uses the Vec type for dy ```rust showLineNumbers -use odra::{prelude::*, Var}; +use odra::prelude::*; #[odra::odra_type] #[derive(Default)] @@ -571,7 +566,7 @@ In Odra, custom types are defined using the `#[odra::odra_type]` attribute. The ```rust showLineNumbers -use odra::{prelude::*, List}; +use odra::prelude::*; #[odra::odra_type] pub struct Todo { @@ -692,7 +687,7 @@ Functions can modify contract state and emit events using the [`ContractEnv`](.. ```rust showLineNumbers -use odra::Var; +use odra::prelude::*; #[odra::module] pub struct ViewAndPure { @@ -743,7 +738,7 @@ In Odra, you don't need to specify `view` or `pure` functions explicitly. All fu ```rust showLineNumbers -use odra::{module::Module, Var}; +use odra::prelude::*; #[odra::module] pub struct FunctionModifier { @@ -854,7 +849,7 @@ State variables can be declared as public, private, or internal but not external ```rust showLineNumbers -use odra::{casper_types::U512, prelude::*, Address, ExecutionError, Var}; +use odra::{casper_types::U512, prelude::*}; #[odra::module] pub struct Payable { @@ -951,7 +946,7 @@ Odra does not support such a mechanism. You must have access to the contract int ```rust showLineNumbers -use odra::{prelude::*, Address}; +use odra::prelude::*; #[odra::event] pub struct Log { @@ -1109,7 +1104,7 @@ Let's take a look at the difference between inheritance in Solidity and composit ```rust showLineNumbers -use odra::{prelude::*, SubModule}; +use odra::prelude::*; #[odra::module] pub struct A; @@ -1262,7 +1257,7 @@ In contrast, Rust does not have a direct equivalent to the inheritance model, bu ```rust showLineNumbers -use odra::{casper_types::U256, prelude::*, UnwrapOrRevert, Var}; +use odra::{casper_types::U256, prelude::*}; mod math { use odra::casper_types::U256; @@ -1413,11 +1408,7 @@ Odra does not have a direct equivalent to the `receive()` and `fallback()` funct ```rust showLineNumbers -use odra::{ - casper_types::{bytesrepr::ToBytes, U256}, - prelude::*, - Address, UnwrapOrRevert, Var, -}; +use odra::{casper_types::{bytesrepr::ToBytes, U256}, prelude::*}; #[odra::module] pub struct HashFunction; @@ -1497,7 +1488,7 @@ The key difference between the two is that in Solidity, the `keccak256` function ```rust showLineNumbers -use odra::{module::Module, Address, ContractRef, External, Var}; +use odra::prelude::*; #[odra::module] pub struct Example { diff --git a/docusaurus/docs/tutorials/ownable.md b/docusaurus/docs/tutorials/ownable.md index 444eb7c42..aa382af30 100644 --- a/docusaurus/docs/tutorials/ownable.md +++ b/docusaurus/docs/tutorials/ownable.md @@ -29,7 +29,6 @@ Before we write any code, we define functionalities we would like to implement. ```rust title=ownable.rs showLineNumbers use odra::prelude::*; -use odra::{Address, Var}; #[odra::module(events = [OwnershipChanged])] pub struct Ownable { @@ -38,8 +37,8 @@ pub struct Ownable { ``` That was easy, but it is crucial to understand the basics before we move on. -* **L4** - Firstly, we need to create a struct called `Ownable` and apply `#[odra::module(events = [OwnershipChanged])]` attribute to it. The `events` attribute is optional but informs the Odra toolchain about the events that will be emitted by the module and includes them in the contract's metadata. `OwnershipChanged` is a type that will be defined later. -* **L6** - Then we can define the layout of our module. It is extremely simple - just a single state value. What is most important is that you can never leave a raw type; you must always wrap it with `Var`. +* **L3** - Firstly, we need to create a struct called `Ownable` and apply `#[odra::module(events = [OwnershipChanged])]` attribute to it. The `events` attribute is optional but informs the Odra toolchain about the events that will be emitted by the module and includes them in the contract's metadata. `OwnershipChanged` is a type that will be defined later. +* **L5** - Then we can define the layout of our module. It is extremely simple - just a single state value. What is most important is that you can never leave a raw type; you must always wrap it with `Var`. ### Init the module diff --git a/docusaurus/docs/tutorials/owned-token.md b/docusaurus/docs/tutorials/owned-token.md index 3f2b32791..d12b08133 100644 --- a/docusaurus/docs/tutorials/owned-token.md +++ b/docusaurus/docs/tutorials/owned-token.md @@ -21,7 +21,6 @@ Let's define a module called `OwnedToken` that is a composition of `Ownable` and ```rust title=owned_token.rs showLineNumbers use crate::{erc20::Erc20, ownable::Ownable}; use odra::prelude::*; -use odra::module::SubModule; #[odra::module] pub struct OwnedToken { @@ -36,7 +35,7 @@ As you can see, we do not need any storage definition - we just take advantage o ```rust title=owned_token.rs showLineNumbers ... -use odra::{Address, casper_types::U256}; +use odra::casper_types::U256; ... #[odra::module] diff --git a/docusaurus/docs/tutorials/pauseable.md b/docusaurus/docs/tutorials/pauseable.md index 4667bb4c5..c6480d2e9 100644 --- a/docusaurus/docs/tutorials/pauseable.md +++ b/docusaurus/docs/tutorials/pauseable.md @@ -22,7 +22,6 @@ Events definition is highly uncomplicated: `Paused` and `Unpaused` events holds ```rust title=pauseable.rs showLineNumbers use odra::prelude::*; -use odra::Address; #[odra::odra_error] pub enum Error { @@ -46,9 +45,6 @@ pub struct Unpaused { The module storage is extremely simple - has a single `Var` of type bool, that indicates if a contract is paused. ```rust title=pauseable.rs showLineNumbers -use odra::Var; -... - #[odra::module(events = [Paused, Unpaused])] pub struct Pausable { is_paused: Var @@ -118,8 +114,6 @@ In the end, let's use the module in a contract. For this purpose, we will implem ```rust title=pauseable.rs showLineNumbers ... -use odra::SubModule; -... #[odra::module] pub struct PausableCounter { diff --git a/docusaurus/docs/tutorials/using-proxy-caller.md b/docusaurus/docs/tutorials/using-proxy-caller.md index 381b9d91a..2dd21455a 100644 --- a/docusaurus/docs/tutorials/using-proxy-caller.md +++ b/docusaurus/docs/tutorials/using-proxy-caller.md @@ -16,7 +16,7 @@ For this tutorial, we will use the `TimeLockWallet` contract from our examples. ```rust title=examples/src/contracts/tlw.rs showLineNumbers use odra::prelude::*; -use odra::{casper_types::U512, Address, Mapping, Var}; +use odra::casper_types::U512; #[odra::module(errors = Error, events = [Deposit, Withdrawal])] pub struct TimeLockWallet { @@ -122,13 +122,13 @@ To interact with the contract, we use the `livenet` backend. It allows to write ```toml title=Cargo.toml [package] name = "odra-examples" -version = "1.1.0" +version = "1.4.0" edition = "2021" [dependencies] odra = { path = "../odra", default-features = false } ... # other dependencies -odra-casper-livenet-env = { version = "1.1.0", optional = true } +odra-casper-livenet-env = { version = "1.4.0", optional = true } ... # other sections @@ -151,7 +151,7 @@ test = false //! Deploys an [odra_examples::contracts::tlw::TimeLockWallet] contract, then deposits and withdraw some CSPRs. use odra::casper_types::{AsymmetricType, PublicKey, U512}; use odra::host::{Deployer, HostRef}; -use odra::Address; +use odra::prelude::*; use odra_examples::contracts::tlw::{TimeLockWallet, TimeLockWalletInitArgs}; const DEPOSIT: u64 = 100;