Skip to main content

odra_cli/
lib.rs

1//! A rust library for building command line interfaces for Odra smart contracts.
2//!
3//! The Odra CLI is a command line interface built on top of the [clap] crate
4//! that allows users to interact with smart contracts.
5
6#![feature(box_patterns, error_generic_member_access)]
7mod cli;
8mod cmd;
9mod container;
10mod custom_types;
11mod entry_point;
12mod output;
13mod parser;
14#[cfg(test)]
15mod test_utils;
16mod types;
17mod utils;
18
19pub use cli::OdraCli;
20pub use cmd::args::CommandArg;
21pub use container::{ContractProvider, DeployedContractsContainer};
22pub use utils::{log, DeployerExt};
23
24pub mod scenario {
25    //! Traits and structs for defining custom scenarios.
26    //!
27    //! A scenario is a user-defined set of actions that can be run in the Odra CLI.
28    //! If you want to run a custom scenario that calls multiple entry points,
29    //! you need to implement the [Scenario] and [ScenarioMetadata] traits.
30    pub use crate::cmd::{
31        Scenario, ScenarioArgs as Args, ScenarioError as Error, ScenarioMetadata
32    };
33}
34
35pub mod deploy {
36    //! Traits and structs for defining deploy scripts.
37    //!
38    //! In a deploy script, you can define the contracts that you want to deploy to the blockchain
39    //! and write metadata to the container.
40    pub use crate::cmd::{DeployError as Error, DeployScript};
41}
42
43#[macro_export]
44macro_rules! cspr {
45    ($val:literal) => {{
46        const MOTES_PER_CSPR: u64 = 1_000_000_000;
47        ($val as f64 * MOTES_PER_CSPR as f64) as u64
48    }};
49    ($val:expr) => {{
50        const MOTES_PER_CSPR: u64 = 1_000_000_000;
51        let parsed: f64 = {
52            if let Some(s) = $val.as_ref().downcast_ref::<&str>() {
53                s.parse().expect("Invalid number string")
54            } else if let Some(s) = $val.as_ref().downcast_ref::<String>() {
55                s.parse().expect("Invalid number string")
56            } else {
57                $val as f64
58            }
59        };
60        (parsed * MOTES_PER_CSPR as f64) as u64
61    }};
62}