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