pub struct RpcClient { /* private fields */ }
Available on crate feature rpc-client only.
Expand description

A simple RPC client for calling methods using HTTP POST.

Implementations§

source§

impl RpcClient

source

pub fn new(credentials: &str, endpoint: HttpEndpoint) -> Result<Self>

Creates a new RPC client connected to the given endpoint with the provided credentials. The credentials should be a base64 encoding of a user name and password joined by a colon, as is required for HTTP basic access authentication.

source

pub async fn call_method<T>(&self, method: &str, params: &[Value]) -> Result<T>where JsonResponse: TryFrom<Vec<u8>, Error = Error> + TryInto<T, Error = Error>,

Calls a method with the response encoded in JSON format and interpreted as type T.

Trait Implementations§

source§

impl BlockSource for RpcClient

source§

fn get_header<'a>( &'a self, header_hash: &'a BlockHash, _height: Option<u32> ) -> AsyncBlockSourceResult<'a, BlockHeaderData>

Returns the header for a given hash. A height hint may be provided in case a block source cannot easily find headers based on a hash. This is merely a hint and thus the returned header must have the same hash as was requested. Otherwise, an error must be returned. Read more
source§

fn get_block<'a>( &'a self, header_hash: &'a BlockHash ) -> AsyncBlockSourceResult<'a, BlockData>

Returns the block for a given hash. A headers-only block source should return a Transient error.
source§

fn get_best_block<'a>( &'a self ) -> AsyncBlockSourceResult<'a, (BlockHash, Option<u32>)>

Returns the hash of the best block and, optionally, its height. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.