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