multiversx_sc_meta_lib/cli/
cli_contract_main.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use std::path::Path;

use crate::{
    cli::{ContractCliAction, ContractCliArgs},
    contract::{meta_config::MetaConfig, sc_config::ScConfig},
};
use clap::Parser;
use multiversx_sc::contract_base::ContractAbiProvider;

/// Entry point in the program from the contract meta crates.
pub fn cli_main<AbiObj: ContractAbiProvider>() {
    let cli_args = ContractCliArgs::parse();
    let mut meta_config_opt = process_original_abi::<AbiObj>(&cli_args);
    match cli_args.command {
        ContractCliAction::Abi => {},
        ContractCliAction::Build(build_args) => meta_config_opt.build(build_args),
        ContractCliAction::BuildDbg(build_args) => {
            meta_config_opt.build(build_args.into_build_args())
        },
        ContractCliAction::Twiggy(build_args) => {
            meta_config_opt.build(build_args.into_build_args())
        },
        ContractCliAction::Clean => meta_config_opt.clean(),
        ContractCliAction::Update => meta_config_opt.update(),
        ContractCliAction::GenerateSnippets(gs_arg) => {
            meta_config_opt.generate_rust_snippets(&gs_arg);
            meta_config_opt.reload_sc_config();
            meta_config_opt.generate_proxy()
        },
        ContractCliAction::GenerateProxies(proxy_args) => {
            if proxy_args.compare {
                meta_config_opt.compare_proxy()
            } else {
                meta_config_opt.generate_proxy()
            }
        },
    }
}

fn process_original_abi<AbiObj: ContractAbiProvider>(cli_args: &ContractCliArgs) -> MetaConfig {
    let input_abi = <AbiObj as ContractAbiProvider>::abi();
    let mut meta_config = MetaConfig::create(input_abi, cli_args.load_abi_git_version);
    meta_config.sc_config.validate_contract_variants();
    meta_config.write_contract_abis();
    meta_config.write_esdt_attribute_abis();
    meta_config.generate_wasm_crates();
    meta_config
}

pub fn multi_contract_config<AbiObj>(contract_crate_path: &Path) -> ScConfig
where
    AbiObj: ContractAbiProvider,
{
    let original_contract_abi = <AbiObj as ContractAbiProvider>::abi();

    let sc_config =
        ScConfig::load_from_crate_or_default(contract_crate_path, &original_contract_abi);
    sc_config.validate_contract_variants();
    sc_config
}