Struct BitcoinRpc

Source
pub struct BitcoinRpc { /* private fields */ }
Expand description

A Handle to a Bitcoin JSON-RPC connection

Implementations§

Source§

impl BitcoinRpc

Source

pub fn new(url: String, user: Option<String>, pass: Option<String>) -> Self

Creates a client to a bitcoind JSON-RPC server.

Source

pub fn getblockcount(&self) -> RpcResult<u64>

Returns the numbers of block in the longest chain.

Source

pub fn getbestblockhash(&self) -> RpcResult<String>

Returns the hash of the best (tip) block in the longest blockchain.

Source

pub fn waitfornewblock(&self, timeout: u64) -> RpcResult<BlockRef>

Waits for a specific new block and returns useful info about it. Returns the current block on timeout or exit.

§Arguments
  1. timeout: Time in milliseconds to wait for a response. 0 indicates no timeout.
Source

pub fn waitforblock( &self, blockhash: String, timeout: u64, ) -> RpcResult<BlockRef>

Waits for a specific new block and returns useful info about it. Returns the current block on timeout or exit.

§Arguments
  1. blockhash: Block hash to wait for.
  2. timeout: Time in milliseconds to wait for a response. 0 indicates no timeout.
Source

pub fn getblockchaininfo(&self) -> RpcResult<BlockchainInfo>

Returns a data structure containing various state info regarding blockchain processing.

Source

pub fn estimatesmartfee<E>( &self, conf_target: u16, estimate_mode: E, ) -> Result<EstimateSmartFee, Error>

Source

pub fn getconnectioncount(&self) -> RpcResult<u64>

Returns the number of connections to other nodes.

Source

pub fn ping(&self) -> RpcResult<()>

Requests that a ping be sent to all other nodes, to measure ping time.

Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.

Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping.

Source

pub fn getpeerinfo(&self) -> RpcResult<Vec<PeerInfo>>

Returns data about each connected network node as an array of PeerInfo

Source

pub fn addnode(&self, node: &str, commnad: AddNode) -> RpcResult<()>

Attempts to add or remove a node from the addnode list.

Or try a connection to a node once.

Nodes added using addnode (or -connect) are protected from DoS disconnection and are not required to be full nodes/support SegWit as other outbound peers are (though such peers will not be synced from).

§Arguments:
  1. node: The node (see getpeerinfo for nodes)
  2. command: AddNode::Add to add a node to the list, AddNode::Remove to remove a node from the list, AddNode::OneTry to try a connection to the node once
Source

pub fn getnetworkinfo(&self) -> RpcResult<NetworkInfo>

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T> Typeable for T
where T: Any,

Source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.