#config-file #safecoin #cli-config #file-path #key-pair #rpc #security

safecoin-cli-config

Safecoin: Enterprise Security for the Community by the Community

9 stable releases

1.14.17 Mar 8, 2023
1.14.3 Oct 15, 2022
1.10.34 Jul 23, 2022
1.9.29 Jun 6, 2022
1.6.18 Aug 8, 2021

#2725 in Magic Beans

Download history 22/week @ 2023-12-13 27/week @ 2023-12-20 10/week @ 2023-12-27 5/week @ 2024-01-03 20/week @ 2024-01-10 18/week @ 2024-01-17 7/week @ 2024-01-24 10/week @ 2024-01-31 14/week @ 2024-02-07 28/week @ 2024-02-14 23/week @ 2024-02-21 63/week @ 2024-02-28 141/week @ 2024-03-06 33/week @ 2024-03-13 52/week @ 2024-03-20 43/week @ 2024-03-27

273 downloads per month
Used in 13 crates (2 directly)

Apache-2.0

560KB
11K SLoC

Loading and saving the Safecoin CLI configuration file.

The configuration file used by the Safecoin CLI includes information about the RPC node to connect to, the path to the user's signing source, and more. Other software than the Safecoin 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/solana/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 safecoin_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 safecoin_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 safecoin_cli_config::{CONFIG_FILE, Config};

let config_file = safecoin_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.safecoin.org".to_string();
cli_config.save(&config_file)?;

Dependencies

~20–36MB
~626K SLoC