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_height(&self) -> Result<u32, Error>
pub fn get_height(&self) -> Result<u32, Error>
Get the current chain height.