Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions bittensor-rs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::path::Path;

use parity_scale_codec::Decode;
use sha2::{Digest, Sha256};
use subxt_codegen::CodegenBuilder;
use subxt_codegen::{syn::parse_quote, CodegenBuilder};
use subxt_metadata::Metadata;
use subxt_utils_fetchmetadata::{from_url_blocking, MetadataVersion, Url};

Expand Down Expand Up @@ -125,8 +125,27 @@ fn generate_code(metadata_bytes: &[u8], code_path: &Path, hash_path: &Path) {
// Decode metadata
let metadata = Metadata::decode(&mut &metadata_bytes[..]).expect("Failed to decode metadata");

// Preserve the primitive client API for SCALE-compatible runtime newtypes.
let mut codegen = CodegenBuilder::new();
codegen.set_type_substitute(
parse_quote!(subtensor_runtime_common::NetUid),
parse_quote!(::core::primitive::u16),
);
codegen.set_type_substitute(
parse_quote!(subtensor_runtime_common::currency::TaoBalance),
parse_quote!(::core::primitive::u64),
);
codegen.set_type_substitute(
parse_quote!(subtensor_runtime_common::currency::AlphaBalance),
parse_quote!(::core::primitive::u64),
);
codegen.set_type_substitute(
parse_quote!(sp_arithmetic::per_things::PerU16),
parse_quote!(::core::primitive::u16),
);

// Generate Rust code
let code = CodegenBuilder::new()
let code = codegen
.generate(metadata)
.expect("Failed to generate code from metadata");

Expand Down
7 changes: 6 additions & 1 deletion lightning-tensor/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ impl App {
}

/// Connect to the Bittensor network
pub async fn connect(&mut self, wallet_name: &str, hotkey_name: &str, netuid: u16) -> Result<(), AppError> {
pub async fn connect(
&mut self,
wallet_name: &str,
hotkey_name: &str,
netuid: u16,
) -> Result<(), AppError> {
let config = BittensorConfig::local(wallet_name, hotkey_name, netuid);
let service = Service::new(config).await?;
self.subtensor = Some(service);
Expand Down
4 changes: 1 addition & 3 deletions lightning-tensor/src/ui/subnets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ pub async fn draw<'a>(f: &mut Frame<'a>, app: &mut App, area: ratatui::layout::R
.map(|subnet| {
ListItem::new(Line::from(format!(
"Subnet {}: {} neurons (max {})",
subnet.netuid,
subnet.n,
subnet.max_n
subnet.netuid, subnet.n, subnet.max_n
)))
})
.collect();
Expand Down
30 changes: 21 additions & 9 deletions lightning-tensor/src/wallet_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,24 @@ impl Wallet {
}

/// Create a new wallet with a generated keypair
pub fn create_new_wallet(&mut self, _word_count: u32, _password: &str) -> Result<(), WalletError> {
pub fn create_new_wallet(
&mut self,
_word_count: u32,
_password: &str,
) -> Result<(), WalletError> {
// Generate a random keypair (always 12 words for simplicity)
let (pair, phrase, _) = Pair::generate_with_phrase(None);

self.keypair = Some(pair);

// Save mnemonic to wallet directory
let wallet_dir = self.path.join(&self.name);
std::fs::create_dir_all(&wallet_dir)?;

// Note: In production, this should be encrypted with the password
let mnemonic_path = wallet_dir.join("mnemonic.txt");
std::fs::write(mnemonic_path, phrase)?;

Ok(())
}

Expand Down Expand Up @@ -99,19 +103,28 @@ impl Wallet {
}

/// Verify a signature
pub fn verify(&self, message: &[u8], signature: &[u8], _password: &str) -> Result<bool, WalletError> {
pub fn verify(
&self,
message: &[u8],
signature: &[u8],
_password: &str,
) -> Result<bool, WalletError> {
let sig: Signature = signature
.try_into()
.map_err(|_| WalletError::KeypairError("Invalid signature length".to_string()))?;

match &self.keypair {
Some(pair) => Ok(Pair::verify(&sig, message, &pair.public())),
None => Err(WalletError::NotFound("No keypair loaded".to_string())),
}
}

/// Change the wallet password (stub)
pub async fn change_password(&mut self, _old_password: &str, _new_password: &str) -> Result<(), WalletError> {
pub async fn change_password(
&mut self,
_old_password: &str,
_new_password: &str,
) -> Result<(), WalletError> {
// TODO: Implement actual password change with re-encryption
Ok(())
}
Expand All @@ -127,4 +140,3 @@ impl KeypairWrapper {
Ok(self.0.sign(message))
}
}

Loading