pub struct BitcoinD { /* private fields */ }Expand description
A running bitcoind regtest node.
The node is started in BitcoinD::from_bin (or one of its siblings) and
stopped — and its temporary files removed — when this value is dropped.
§Wallet
A wallet named "wallet" is created (or loaded) automatically on startup.
All RPC helpers that require a wallet (generate, new_address, …) use
this wallet.
§Networking
Both the RPC and P2P ports are chosen from the OS’s ephemeral range at
startup. Use rpc_socket and
get_p2p_socket to discover them after
construction.
Implementations§
Source§impl BitcoinD
impl BitcoinD
Sourcepub fn new() -> Result<BitcoinD, Error>
pub fn new() -> Result<BitcoinD, Error>
Start a BitcoinD node using the binary located by get_bitcoind_path, with the default BitcoinDConf.
If the binary is not cached under target/bin/, it will fetch one from bitcoincore.org per build.rs.
Sourcepub fn new_with_conf(conf: &BitcoinDConf<'_>) -> Result<BitcoinD, Error>
pub fn new_with_conf(conf: &BitcoinDConf<'_>) -> Result<BitcoinD, Error>
Start a BitcoinD node using the binary located by get_bitcoind_path, with a custom BitcoinDConf.
If the binary is not cached under target/bin/, it will fetch one from bitcoincore.org per build.rs.
Sourcepub fn from_bin<P: AsRef<Path>>(bitcoind_bin: P) -> Result<BitcoinD, Error>
pub fn from_bin<P: AsRef<Path>>(bitcoind_bin: P) -> Result<BitcoinD, Error>
Create a BitcoinD instance running the binary at Path with the default BitcoinDConf.
Sourcepub fn from_bin_with_conf<P: AsRef<Path>>(
bitcoind_bin: P,
conf: &BitcoinDConf<'_>,
) -> Result<BitcoinD, Error>
pub fn from_bin_with_conf<P: AsRef<Path>>( bitcoind_bin: P, conf: &BitcoinDConf<'_>, ) -> Result<BitcoinD, Error>
Create a BitcoinD instance running the binary at Path with a custom BitcoinDConf.
The method retries up to BitcoinDConf::max_retries times. On each
attempt it:
- Picks fresh ephemeral RPC and P2P ports.
- Spawns
bitcoindwith those ports and a fresh data directory. - Waits for the cookie file to appear (up to 5 s).
- Creates or loads the default wallet and builds an RPC client.
- Waits for the node to become responsive (up to 5 s).
Returns an error if all attempts are exhausted.
Sourcepub fn stop(&mut self) -> Result<ExitStatus, Error>
pub fn stop(&mut self) -> Result<ExitStatus, Error>
Send stop via RPC and wait for the process to exit.
Calling this method is not required in normal usage because Drop
kills the process automatically. It is provided for cases where you
need the exit status or want to ensure the node has fully shut down
before proceeding.
Sourcepub fn get_working_directory(&self) -> PathBuf
pub fn get_working_directory(&self) -> PathBuf
Get BitcoinD’s data directory.
Sourcepub fn get_p2p_socket(&self) -> SocketAddr
pub fn get_p2p_socket(&self) -> SocketAddr
Get BitcoinD’s P2P SocketAddr.
Pass this to BitcoinD::add_peer on another node to connect the two.
Sourcepub fn get_rpc_client(&self) -> &Client
pub fn get_rpc_client(&self) -> &Client
Sourcepub fn rpc_socket(&self) -> SocketAddr
pub fn rpc_socket(&self) -> SocketAddr
Get BitcoinD’s JSON-RPC SocketAddr.
Sourcepub fn get_chain_tip(&self) -> Result<u32, Error>
pub fn get_chain_tip(&self) -> Result<u32, Error>
Get the current chain height.
Sourcepub fn get_filter_tip(&self) -> Result<u32, Error>
pub fn get_filter_tip(&self) -> Result<u32, Error>
Get the current filter height.
Sourcepub fn get_block_hash(&self, height: u32) -> Result<BlockHash, Error>
pub fn get_block_hash(&self, height: u32) -> Result<BlockHash, Error>
Get the BlockHash of the block at height height.
Sourcepub fn has_peer(&self, socket: SocketAddr) -> Result<bool, Error>
pub fn has_peer(&self, socket: SocketAddr) -> Result<bool, Error>
Check whether this BitcoinD has a peer with a specific SocketAddr.
Trait Implementations§
Source§impl Drop for BitcoinD
impl Drop for BitcoinD
Source§impl Node for BitcoinD
impl Node for BitcoinD
Source§fn get_bin_name() -> &'static str
fn get_bin_name() -> &'static str
Node’s binary name.Source§fn get_p2p_socket(&self) -> SocketAddr
fn get_p2p_socket(&self) -> SocketAddr
Node’s P2P SocketAddr.Source§fn has_peer(&self, socket: SocketAddr) -> Result<bool, Error>
fn has_peer(&self, socket: SocketAddr) -> Result<bool, Error>
Node is connected to a peer with a specific SocketAddr.Source§fn add_peer(&self, socket: SocketAddr) -> Result<(), Error>
fn add_peer(&self, socket: SocketAddr) -> Result<(), Error>
Node to a peer at socket over P2P.fn get_block_hash(&self, height: u32) -> Result<BlockHash, Error>
Source§fn poll_interval() -> Duration
fn poll_interval() -> Duration
get_height RPC calls. Read moreSource§fn wait_timeout() -> Duration
fn wait_timeout() -> Duration
wait_for_height will poll before giving up. Read more