#miraland #cli

miraland-cli-config

Blockchain for community beyond the horizon

10 releases (6 stable)

1.18.2 Dec 14, 2023
1.18.1 Dec 1, 2023
1.18.0 Nov 27, 2023
1.14.17 Aug 31, 2023
1.14.17-rc1 Apr 23, 2023

#2299 in Magic Beans

Download history 136/week @ 2023-10-29 199/week @ 2023-11-05 272/week @ 2023-11-12 420/week @ 2023-11-19 370/week @ 2023-11-26 139/week @ 2023-12-03 229/week @ 2023-12-10 151/week @ 2023-12-17 167/week @ 2023-12-24 100/week @ 2023-12-31 138/week @ 2024-01-07 133/week @ 2024-01-14 98/week @ 2024-01-21 103/week @ 2024-01-28 118/week @ 2024-02-04 315/week @ 2024-02-11

635 downloads per month
Used in 32 crates (16 directly)

Apache-2.0

635KB
13K SLoC

Rust 12K SLoC // 0.0% comments Bitbake 1K SLoC // 0.2% comments Shell 441 SLoC // 0.1% comments

Loading and saving the Miraland CLI configuration file.

The configuration file used by the Miraland CLI includes information about the RPC node to connect to, the path to the user's signing source, and more. Other software than the Miraland CLI may wish to access the same configuration and signer.

The default path to the configuration file can be retrieved from CONFIG_FILE, which is a lazy_static of Option<String>, the value of which is

~/.config/miraland/cli/config.yml

CONFIG_FILE will only be None if it is unable to identify the user's home directory, which should not happen under typical OS environments.

The CLI configuration is defined by the Config struct, and its value is loaded with Config::load and saved with Config::save.

Two important fields of Config are

  • json_rpc_url, the URL to pass to miraland_rpc_client::rpc_client::RpcClient.
  • keypair_path, a signing source, which may be a keypair file, but may also represent several other types of signers, as described in the documentation for miraland_clap_utils::keypair::signer_from_path.

Examples

Loading and saving the configuration. Note that this uses the anyhow crate for error handling.

use anyhow::anyhow;
use miraland_cli_config::{CONFIG_FILE, Config};

let config_file = miraland_cli_config::CONFIG_FILE.as_ref()
    .ok_or_else(|| anyhow!("unable to get config file path"))?;
let mut cli_config = Config::load(&config_file)?;
// Set the RPC URL to devnet
cli_config.json_rpc_url = "https://api.devnet-mln.miraland.top".to_string();
cli_config.save(&config_file)?;

Dependencies

~20–33MB
~560K SLoC