pub struct Service { /* private fields */ }Expand description
Central service for Bittensor chain interactions with connection pooling and retry mechanisms
Implementations§
Source§impl Service
impl Service
Sourcepub async fn new(config: BittensorConfig) -> Result<Self, BittensorError>
pub async fn new(config: BittensorConfig) -> Result<Self, BittensorError>
Creates a new Service instance with the provided configuration.
§Arguments
config- The Bittensor configuration containing network and wallet settings
§Returns
Result<Self, BittensorError>- A Result containing either the initialized Service or an error
§Errors
NetworkError- If connection to the client network failsWalletError- If wallet key loading or signer creation fails
Sourcepub async fn serve_axon(
&self,
netuid: u16,
axon_addr: SocketAddr,
) -> Result<(), BittensorError>
pub async fn serve_axon( &self, netuid: u16, axon_addr: SocketAddr, ) -> Result<(), BittensorError>
Serves an axon on the Bittensor network with retry logic.
§Arguments
netuid- The subnet UID to serve the axon onaxon_addr- The socket address where the axon will be served
§Returns
Result<(), BittensorError>- A Result indicating success or failure
§Errors
TxSubmissionError- If the serve_axon transaction fails to submitMaxRetriesExceeded- If all retry attempts are exhausted
Sourcepub async fn set_weights(
&self,
netuid: u16,
weights: Vec<(u16, u16)>,
) -> Result<(), BittensorError>
pub async fn set_weights( &self, netuid: u16, weights: Vec<(u16, u16)>, ) -> Result<(), BittensorError>
Sets weights for neurons in the subnet with retry logic.
§Arguments
netuid- The subnet UID to set weights forweights- Vector of (uid, weight) pairs representing neuron weights
§Returns
Result<(), BittensorError>- A Result indicating success or failure
§Errors
TxSubmissionError- If the set_weights transaction fails to submitInvalidWeights- If the weight vector is invalidMaxRetriesExceeded- If all retry attempts are exhausted
Sourcepub async fn get_neuron(
&self,
netuid: u16,
uid: u16,
) -> Result<Option<NeuronInfo>, BittensorError>
pub async fn get_neuron( &self, netuid: u16, uid: u16, ) -> Result<Option<NeuronInfo>, BittensorError>
Sourcepub async fn get_metagraph(
&self,
netuid: u16,
) -> Result<Metagraph, BittensorError>
pub async fn get_metagraph( &self, netuid: u16, ) -> Result<Metagraph, BittensorError>
Gets the complete metagraph for a subnet with circuit breaker protection.
§Arguments
netuid- The subnet UID to get the metagraph for
§Returns
Result<Metagraph, BittensorError>- A Result containing either the metagraph or an error
§Errors
RpcError- If the RPC call failsSubnetNotFound- If the subnet doesn’t existServiceUnavailable- If circuit breaker is open
Sourcepub async fn get_selective_metagraph(
&self,
netuid: u16,
fields: Vec<u16>,
) -> Result<SelectiveMetagraph, BittensorError>
pub async fn get_selective_metagraph( &self, netuid: u16, fields: Vec<u16>, ) -> Result<SelectiveMetagraph, BittensorError>
Retrieves a selective metagraph for a specific subnet, containing only the requested fields.
§Arguments
netuid- The subnet UID to get the selective metagraph forfields- Vector of field indices to include in the selective metagraph
§Returns
Result<SelectiveMetagraph, BittensorError>- A Result containing either the selective metagraph or an error
§Errors
RpcError- If connection to the runtime API failsRpcError- If the selective metagraph call failsRpcError- If no selective metagraph is found for the subnet
§Example
let fields = vec![0, 1, 2]; // Include first three fields
let selective_metagraph = service.get_selective_metagraph(1, fields).await?;Sourcepub async fn get_block_number(&self) -> Result<u64, BittensorError>
pub async fn get_block_number(&self) -> Result<u64, BittensorError>
Retrieves the current block number from the Bittensor network.
§Returns
Result<u64, BittensorError>- A Result containing either the current block number or an error
§Errors
RpcError- If connection to the latest block fails
§Example
let block_number = service.get_block_number().await?;
println!("Current block: {}", block_number);Sourcepub fn get_account_id(&self) -> AccountId
pub fn get_account_id(&self) -> AccountId
Sourcepub async fn get_current_block(&self) -> Result<u64, BittensorError>
pub async fn get_current_block(&self) -> Result<u64, BittensorError>
Get current block number (alias for get_block_number)
Sourcepub async fn submit_extrinsic<T>(
&self,
payload: T,
) -> Result<(), BittensorError>where
T: Payload,
pub async fn submit_extrinsic<T>(
&self,
payload: T,
) -> Result<(), BittensorError>where
T: Payload,
Submit an extrinsic (transaction) to the chain
Sourcepub fn get_network(&self) -> &str
pub fn get_network(&self) -> &str
Sourcepub fn get_netuid(&self) -> u16
pub fn get_netuid(&self) -> u16
Sourcepub fn sign_data(&self, data: &[u8]) -> Result<String, BittensorError>
pub fn sign_data(&self, data: &[u8]) -> Result<String, BittensorError>
Sign data with the service’s signer (hotkey)
This method signs arbitrary data with the validator/miner’s hotkey.
The signature can be verified using verify_bittensor_signature.
§Arguments
data- The data to sign
§Returns
Result<String, BittensorError>- Hex-encoded signature string
§Example
let nonce = "test-nonce-123";
let signature = service.sign_data(nonce.as_bytes())?;
println!("Signature: {}", signature);Source§impl Service
impl Service
Sourcepub async fn get_retry_stats(&self) -> RetryStats
pub async fn get_retry_stats(&self) -> RetryStats
Gets retry statistics for monitoring
Sourcepub async fn reset_circuit_breaker(&self)
pub async fn reset_circuit_breaker(&self)
Resets the circuit breaker state (for recovery operations)
Sourcepub async fn connection_metrics(&self) -> ConnectionPoolMetrics
pub async fn connection_metrics(&self) -> ConnectionPoolMetrics
Get connection pool metrics for monitoring
Sourcepub async fn force_reconnect(&self) -> Result<(), BittensorError>
pub async fn force_reconnect(&self) -> Result<(), BittensorError>
Force reconnection of all connections
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Service
impl !RefUnwindSafe for Service
impl Send for Service
impl Sync for Service
impl Unpin for Service
impl !UnwindSafe for Service
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
Source§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
Source§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T. Read moreSource§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.Source§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
Source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from.Source§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
Source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T.