pub struct RpcClient { /* private fields */ }
Available on crate feature
rpc-client
only.Expand description
A simple RPC client for calling methods using HTTP POST
.
Implements BlockSource
and may return an Err
containing RpcError
. See
RpcClient::call_method
for details.
Implementations§
Source§impl RpcClient
impl RpcClient
Sourcepub fn new(credentials: &str, endpoint: HttpEndpoint) -> Self
pub fn new(credentials: &str, endpoint: HttpEndpoint) -> 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.
Sourcepub async fn call_method<T>(&self, method: &str, params: &[Value]) -> Result<T>
pub async fn call_method<T>(&self, method: &str, params: &[Value]) -> Result<T>
Calls a method with the response encoded in JSON format and interpreted as type T
.
When an Err
is returned, std::io::Error::into_inner
may contain an RpcError
if
std::io::Error::kind
is std::io::ErrorKind::Other
.
Trait Implementations§
Source§impl BlockSource for RpcClient
impl BlockSource for RpcClient
Source§fn get_header<'a>(
&'a self,
header_hash: &'a BlockHash,
_height: Option<u32>,
) -> AsyncBlockSourceResult<'a, BlockHeaderData>
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>
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>)>
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
Source§impl UtxoSource for RpcClient
impl UtxoSource for RpcClient
Source§fn get_block_hash_by_height<'a>(
&'a self,
block_height: u32,
) -> AsyncBlockSourceResult<'a, BlockHash>
fn get_block_hash_by_height<'a>( &'a self, block_height: u32, ) -> AsyncBlockSourceResult<'a, BlockHash>
Fetches the block hash of the block at the given height. Read more
Source§fn is_output_unspent<'a>(
&'a self,
outpoint: OutPoint,
) -> AsyncBlockSourceResult<'a, bool>
fn is_output_unspent<'a>( &'a self, outpoint: OutPoint, ) -> AsyncBlockSourceResult<'a, bool>
Returns true if the given output has not been spent, i.e. is a member of the current UTXO
set.
Auto Trait Implementations§
impl !Freeze for RpcClient
impl RefUnwindSafe for RpcClient
impl Send for RpcClient
impl Sync for RpcClient
impl Unpin for RpcClient
impl UnwindSafe for RpcClient
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
Mutably borrows from an owned value. Read more