Skip to content

Commit

Permalink
Some refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
keithtensor committed Nov 27, 2024
1 parent cbd5bcb commit 09253e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
17 changes: 2 additions & 15 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ pub fn is_valid_ss58_address(address: &str) -> bool {
return false;
}

match sp_core::sr25519::Public::from_ss58check(address) {
Ok(_) => true,
Err(_) => {
// Possibly there could be a debug log, but not a print
// utils::print(format!("Invalid SS58 address format"));
false
}
}
sp_core::sr25519::Public::from_ss58check(address).is_ok()
}

/// Checks if the given public_key is a valid ed25519 key.
Expand All @@ -53,13 +46,7 @@ pub fn is_valid_ed25519_pubkey(public_key: &[u8]) -> bool {
let keypair_result = Keypair::new(None, pub_key_var, None, SS58_FORMAT, None, 1);

match keypair_result {
Ok(keypair) => {
if let Some(_) = keypair.ss58_address() {
true
} else {
false
}
}
Ok(keypair) => keypair.ss58_address().is_some(),
Err(_) => false,
}
}
Expand Down
40 changes: 22 additions & 18 deletions src/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use colored::Colorize;
use std::borrow::Cow;
use std::env;
use std::{env, fmt};
use std::path::PathBuf;

use crate::config::Config;
Expand Down Expand Up @@ -50,6 +49,27 @@ pub struct Wallet {
_coldkeypub: Option<Keypair>,
_hotkey: Option<Keypair>,
}

impl fmt::Display for Wallet {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Wallet (Name: '{:}', Hotkey: '{:}', Path: '{:}')",
self.name, self.hotkey, self.path
)
}
}

impl fmt::Debug for Wallet {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"name: '{:?}', hotkey: '{:?}', path: '{:?}'",
self.name, self.hotkey, self.path
)
}
}

impl Wallet {
/// Initialize the bittensor wallet object containing a hot and coldkey.
///
Expand Down Expand Up @@ -100,22 +120,6 @@ impl Wallet {
}
}

/// Returns string representation of the wallet
pub fn to_string(&self) -> String {
format!(
"Wallet (Name: '{:}', Hotkey: '{:}', Path: '{:}')",
self.name, self.hotkey, self.path
)
}

/// Returns debug representation of the wallet
pub fn debug_string(&self) -> String {
format!(
"name: '{:}', hotkey: '{:}', path: '{:}'",
self.name, self.hotkey, self.path
)
}

/// Get default config
pub fn config() -> Config {
Config::new(None, None, None)
Expand Down

0 comments on commit 09253e4

Please sign in to comment.