pub struct BitcoinRpc { /* private fields */ }Expand description
A Handle to a Bitcoin JSON-RPC connection
Implementations§
Source§impl BitcoinRpc
impl BitcoinRpc
Sourcepub fn new(url: String, user: Option<String>, pass: Option<String>) -> Self
pub fn new(url: String, user: Option<String>, pass: Option<String>) -> Self
Creates a client to a bitcoind JSON-RPC server.
Sourcepub fn getblockcount(&self) -> RpcResult<u64>
pub fn getblockcount(&self) -> RpcResult<u64>
Returns the numbers of block in the longest chain.
Sourcepub fn getbestblockhash(&self) -> RpcResult<String>
pub fn getbestblockhash(&self) -> RpcResult<String>
Returns the hash of the best (tip) block in the longest blockchain.
Sourcepub fn waitfornewblock(&self, timeout: u64) -> RpcResult<BlockRef>
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
timeout: Time in milliseconds to wait for a response. 0 indicates no timeout.
Sourcepub fn waitforblock(
&self,
blockhash: String,
timeout: u64,
) -> RpcResult<BlockRef>
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
blockhash: Block hash to wait for.timeout: Time in milliseconds to wait for a response. 0 indicates no timeout.
Sourcepub fn getblockchaininfo(&self) -> RpcResult<BlockchainInfo>
pub fn getblockchaininfo(&self) -> RpcResult<BlockchainInfo>
Returns a data structure containing various state info regarding blockchain processing.
pub fn estimatesmartfee<E>( &self, conf_target: u16, estimate_mode: E, ) -> Result<EstimateSmartFee, Error>
Sourcepub fn getconnectioncount(&self) -> RpcResult<u64>
pub fn getconnectioncount(&self) -> RpcResult<u64>
Returns the number of connections to other nodes.
Sourcepub fn ping(&self) -> RpcResult<()>
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.
Sourcepub fn getpeerinfo(&self) -> RpcResult<Vec<PeerInfo>>
pub fn getpeerinfo(&self) -> RpcResult<Vec<PeerInfo>>
Returns data about each connected network node as an array of
PeerInfo
Sourcepub fn addnode(&self, node: &str, commnad: AddNode) -> RpcResult<()>
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:
node: The node (seegetpeerinfofor nodes)command:AddNode::Addto add a node to the list,AddNode::Removeto remove a node from the list,AddNode::OneTryto try a connection to the node once