bittensor_rs/
lib.rs

1//! # Bittensor Rust SDK
2//!
3//! A standalone Rust SDK for interacting with the Bittensor blockchain network.
4//!
5//! This crate provides:
6//! - **Connection Management**: Connection pooling, health checks, and automatic failover
7//! - **Wallet Management**: Key loading, signing, and transaction submission
8//! - **Chain Queries**: Metagraph data, neuron info, and subnet information
9//! - **Extrinsics**: Weight setting, axon serving, staking, and more
10//!
11//! # Quick Start
12//!
13//! ```rust,no_run
14//! use bittensor_rs::{config::BittensorConfig, Service};
15//!
16//! #[tokio::main]
17//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
18//!     // Create configuration
19//!     let config = BittensorConfig::finney("my_wallet", "my_hotkey", 1);
20//!     
21//!     // Initialize the service
22//!     let service = Service::new(config).await?;
23//!     
24//!     // Get the metagraph
25//!     let metagraph = service.get_metagraph(1).await?;
26//!     println!("Found {} neurons", metagraph.hotkeys.len());
27//!     
28//!     Ok(())
29//! }
30//! ```
31//!
32//! # Modules
33//!
34//! - [`config`]: Configuration types for network and wallet settings
35//! - [`types`]: Core types including `Hotkey`, `Balance`, and identity types
36//! - [`connect`]: Connection pooling and health monitoring
37//! - [`error`]: Error types and retry configuration
38//! - [`service`]: Main `Service` struct for chain interactions
39//! - [`discovery`]: Neuron discovery from metagraph data
40//! - [`registration`]: Chain registration for miners and validators
41
42// Core modules
43pub mod api;
44pub mod config;
45pub mod connect;
46pub mod discovery;
47pub mod error;
48pub mod extrinsics;
49pub mod queries;
50pub mod registration;
51pub mod retry;
52pub mod service;
53pub mod types;
54pub mod utils;
55pub mod wallet;
56
57#[cfg(test)]
58mod error_tests;
59
60// Re-export config types
61pub use config::BittensorConfig;
62
63// Re-export connection types
64pub use connect::{
65    ConnectionManager, ConnectionMetricsSnapshot, ConnectionPool, ConnectionPoolBuilder,
66    ConnectionState, HealthCheckMetrics, HealthChecker,
67};
68
69// Re-export discovery
70pub use discovery::NeuronDiscovery;
71
72// Re-export error types
73pub use error::{BittensorError, ErrorCategory, RetryConfig};
74
75// Re-export registration
76pub use registration::{
77    ChainRegistration, RegistrationConfig, RegistrationConfigBuilder, RegistrationStateSnapshot,
78};
79
80// Re-export retry utilities
81pub use retry::{retry_operation, retry_operation_with_timeout, CircuitBreaker, RetryNode};
82
83// Re-export service
84pub use service::{ConnectionPoolMetrics, Service};
85
86// Re-export types
87pub use types::{
88    account_id_to_hotkey, hotkey_to_account_id, rao_to_tao, tao_to_rao, Balance, Hotkey, MinerUid,
89    ValidatorUid,
90};
91
92// Re-export utility functions
93pub use utils::{
94    create_signature, normalize_weights, set_weights_payload, sign_message_hex, sign_with_keypair,
95    verify_bittensor_signature, BittensorSignature, NormalizedWeight,
96};
97
98// Re-export wallet types
99pub use wallet::{Wallet, WalletSigner};
100
101// Re-export extrinsics
102pub use extrinsics::{
103    add_stake, burned_register, commit_weights, delegate_stake, register_network,
104    register_network_with_identity, remove_stake, reveal_weights, revoke_children, root_register,
105    serve_axon, serve_prometheus, set_childkey_take, set_children, set_root_weights,
106    set_subnet_identity, set_weights, transfer, transfer_all, transfer_keep_alive,
107    undelegate_stake, ChildKey, CommitRevealParams, ExtrinsicResponse, ExtrinsicStatus,
108    RootWeightsParams, ServeAxonParams, ServePrometheusParams, SetChildrenParams, StakeParams,
109    SubnetIdentity, TransferParams, WeightsParams,
110};
111
112// Re-export queries
113pub use queries::{
114    fields as metagraph_fields, get_balance, get_metagraph, get_neuron, get_neuron_lite, get_stake,
115    get_stake_info_for_coldkey, get_subnet_hyperparameters, get_subnet_info,
116    get_total_network_stake, get_total_subnets, get_uid_for_hotkey, subnet_exists, Metagraph,
117    NeuronInfo, NeuronInfoLite, SelectiveMetagraph, StakeInfo, SubnetHyperparameters, SubnetInfo,
118};
119
120// Re-export key types from our generated API
121pub use crate::api::api::runtime_types::pallet_subtensor::pallet::{AxonInfo, PrometheusInfo};
122
123// Type alias for AccountId
124pub type AccountId = subxt::config::polkadot::AccountId32;
125
126/// Re-export sp_core for cryptographic operations
127///
128/// This allows dependents to use bittensor's bundled sp_core without
129/// adding it as a direct dependency.
130pub mod crypto {
131    pub use sp_core::crypto::{Pair, Ss58AddressFormat, Ss58Codec};
132    pub use sp_core::sr25519;
133    pub use sp_core::Pair as PairTrait;
134}