Skip to main content

bittensor_wallet/
config.rs

1use std::fmt::Display;
2
3use crate::constants::{BT_WALLET_HOTKEY, BT_WALLET_NAME, BT_WALLET_PATH};
4
5#[derive(Clone)]
6pub struct WalletConfig {
7    pub name: String,
8    pub path: String,
9    pub hotkey: String,
10}
11
12impl WalletConfig {
13    /// Creates a new WalletConfig instance.
14    ///
15    ///     Arguments:
16    ///         name (Option<String>): Optional wallet name. Defaults to "default" if not provided.
17    ///         hotkey (Option<String>): Optional hotkey name. Defaults to "default" if not provided.
18    ///         path (Option<String>): Optional wallet path. Defaults to "~/.bittensor/wallets/" if not provided.
19    ///     Returns:
20    ///         wallet_config (WalletConfig): A new WalletConfig instance.
21    pub fn new(name: Option<String>, hotkey: Option<String>, path: Option<String>) -> Self {
22        WalletConfig {
23            name: name.unwrap_or_else(|| BT_WALLET_NAME.to_string()),
24            hotkey: hotkey.unwrap_or_else(|| BT_WALLET_HOTKEY.to_string()),
25            path: path.unwrap_or_else(|| BT_WALLET_PATH.to_string()),
26        }
27    }
28}
29
30#[derive(Clone)]
31pub struct Config {
32    pub wallet: WalletConfig,
33}
34
35impl Display for Config {
36    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37        write!(
38            f,
39            "Config(name: '{}', path: '{}', hotkey: '{}'",
40            self.wallet.name, self.wallet.path, self.wallet.hotkey
41        )
42    }
43}
44
45impl Config {
46    /// Creates a new Config instance.
47    ///
48    ///     Arguments:
49    ///         name (Option<String>): Optional wallet name. Defaults to "default" if not provided.
50    ///         hotkey (Option<String>): Optional hotkey name. Defaults to "default" if not provided.
51    ///         path (Option<String>): Optional wallet path. Defaults to "~/.bittensor/wallets/" if not provided.
52    ///     Returns:
53    ///         config (Config): A new Config instance.
54    pub fn new(name: Option<String>, hotkey: Option<String>, path: Option<String>) -> Config {
55        Config {
56            wallet: WalletConfig::new(name, hotkey, path),
57        }
58    }
59
60    /// Returns the wallet name.
61    pub fn name(&self) -> String {
62        self.wallet.name.clone()
63    }
64
65    /// Returns the wallet path.
66    pub fn path(&self) -> String {
67        self.wallet.path.clone()
68    }
69
70    /// Returns the hotkey name.
71    pub fn hotkey(&self) -> String {
72        self.wallet.hotkey.clone()
73    }
74}