Skip to content

Commit 85da2af

Browse files
committed
Merge #201: Docs: add just example for using bdk-cli with bitcoind regtest node
2524da3 docs: reformat and simplify README steps for just & bitcoind (Steve Myers) b289a61 fix clippy warnings (Vihiga Tyonum) c2573fc docs: update README steps for `just` & `bitcoind` (Vihiga Tyonum) Pull request description: ### Description Fixes #199 Update README to show how to use `just` command runner to start, connect and fund your bdk-cli wallet with local bitcoind regtest node. Also, fixed clippy warnings. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk-cli/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: notmandatory: ACK 2524da3 tvpeter: ACK 2524da3 Tree-SHA512: bf177a651cf97b18b183d56f3d6a7b439a95fbcfd0343b6b9bd422fdc828183555d8afcb057531a2ebca67892a0cbebba32de62e00e343d78082a3f92c95e74e
2 parents f0b51cb + 2524da3 commit 85da2af

File tree

5 files changed

+90
-10
lines changed

5 files changed

+90
-10
lines changed

Justfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,8 @@ send n address wallet=default_wallet:
9595
[group('rpc')]
9696
descriptors private wallet=default_wallet:
9797
bitcoin-cli -datadir={{default_datadir}} -regtest -rpcwallet={{wallet}} -rpcuser={{rpc_user}} -rpcpassword={{rpc_password}} listdescriptors {{private}}
98+
99+
# run any bitcoin-cli rpc command
100+
[group('rpc')]
101+
rpc command wallet=default_wallet:
102+
bitcoin-cli -datadir={{default_datadir}} -regtest -rpcwallet={{wallet}} -rpcuser={{rpc_user}} -rpcpassword={{rpc_password}} {{command}}

README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,78 @@ The below are some of the commands included:
122122

123123
``` shell
124124
just # list all available recipes
125-
just start # start regtest bitcoind in default dir
126125
just test # test the project
127126
just build # build the project
128127
```
129128

129+
### Using `Justfile` to run `bitcoind` as a Client
130+
131+
If you are testing `bdk-cli` in regtest mode and wants to use your `bitcoind` node as a blockchain client, the `Justfile` can help you to quickly do so. Below are the steps to use your `bitcoind` node in *regtest* mode with `bdk-cli`:
132+
133+
Note: You can modify the `Justfile` to reflect your nodes' configuration values. These values are the default values used in `bdk-cli`
134+
> * default wallet: The set default wallet name is `regtest_default_wallet`
135+
> * default data directory: The set default data directory is `~/.bdk-bitcoin`
136+
> * RPC username: The set RPC username is `user`
137+
> * RPC password: The set RPC password is `password`
138+
139+
#### Steps
140+
141+
1. Start bitcoind
142+
```shell
143+
just start
144+
```
145+
146+
2. Create or load a bitcoind wallet with default wallet name
147+
148+
```shell
149+
just create
150+
```
151+
or
152+
```shell
153+
just load
154+
```
155+
156+
3. Generate a bitcoind wallet address to send regtest bitcoins to.
157+
158+
```shell
159+
just address
160+
```
161+
162+
4. Mine 101 blocks on regtest to bitcoind wallet address
163+
```shell
164+
just generate 101 $(just address)
165+
```
166+
167+
5. Check the bitcoind wallet balance
168+
```shell
169+
just balance
170+
```
171+
172+
6. Setup your `bdk-cli` wallet config and connect it to your regtest node to perform a `sync`
173+
```shell
174+
export NETWORK=regtest
175+
export EXT_DESCRIPTOR='wpkh(tprv8ZgxMBicQKsPdMzWj9KHvoExKJDqfZFuT5D8o9XVZ3wfyUcnPNPJKncq5df8kpDWnMxoKbGrpS44VawHG17ZSwTkdhEtVRzSYXd14vDYXKw/0/*)'
176+
export INT_DESCRIPTOR='wpkh(tprv8ZgxMBicQKsPdMzWj9KHvoExKJDqfZFuT5D8o9XVZ3wfyUcnPNPJKncq5df8kpDWnMxoKbGrpS44VawHG17ZSwTkdhEtVRzSYXd14vDYXKw/1/*)'
177+
export DATABASE_TYPE=sqlite
178+
cargo run --features rpc -- wallet -u "127.0.0.1:18443" -c rpc -a user:password sync
179+
```
180+
181+
7. Generate an address from your `bdk-cli` wallet and fund it with 10 bitcoins from your bitcoind node's wallet
182+
```shell
183+
export address=$(cargo run --features rpc -- wallet -u "127.0.0.1:18443" -c rpc -a user:password new_address | jq '.address')
184+
just send 10 $address
185+
```
186+
187+
8. Mine 6 more blocks to the bitcoind wallet
188+
```shell
189+
just generate 6 $(just address)
190+
```
191+
192+
9. You can `sync` your `bdk-cli` wallet now and the balance should reflect the regtest bitcoin you received
193+
```shell
194+
cargo run --features rpc -- wallet -u "127.0.0.1:18443" -c rpc -a user:password sync
195+
cargo run --features rpc -- wallet -u "127.0.0.1:18443" -c rpc -a user:password balance
196+
```
130197

131198
## Minimum Supported Rust Version (MSRV)
132199

src/handlers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ pub(crate) async fn handle_online_wallet_subcommand(
554554
mut warning_subscriber,
555555
update_subscriber: _,
556556
node,
557-
} = client;
557+
} = *client;
558558

559559
let subscriber = tracing_subscriber::FmtSubscriber::new();
560560
tracing::subscriber::set_global_default(subscriber)

src/utils.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub(crate) enum BlockchainClient {
140140
},
141141

142142
#[cfg(feature = "cbf")]
143-
KyotoClient { client: LightClient },
143+
KyotoClient { client: Box<LightClient> },
144144
}
145145

146146
#[cfg(any(
@@ -206,7 +206,9 @@ pub(crate) fn new_blockchain_client(
206206
.data_dir(&_datadir)
207207
.build_with_wallet(_wallet, scan_type)?;
208208

209-
BlockchainClient::KyotoClient { client }
209+
BlockchainClient::KyotoClient {
210+
client: Box::new(client),
211+
}
210212
}
211213
};
212214
Ok(client)
@@ -323,15 +325,15 @@ pub async fn trace_logger(
323325

324326
// Handle Kyoto Client sync
325327
#[cfg(feature = "cbf")]
326-
pub async fn sync_kyoto_client(wallet: &mut Wallet, client: LightClient) -> Result<(), Error> {
328+
pub async fn sync_kyoto_client(wallet: &mut Wallet, client: Box<LightClient>) -> Result<(), Error> {
327329
let LightClient {
328330
requester,
329331
log_subscriber,
330332
info_subscriber,
331333
warning_subscriber,
332334
mut update_subscriber,
333335
node,
334-
} = client;
336+
} = *client;
335337

336338
let subscriber = tracing_subscriber::FmtSubscriber::new();
337339
tracing::subscriber::set_global_default(subscriber)

tests/integration.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ mod test {
2020
use std::process::Command;
2121

2222
/// Testing errors for integration tests
23+
#[allow(dead_code)]
2324
#[derive(Debug)]
2425
enum IntTestError {
2526
// IO error
@@ -38,11 +39,12 @@ mod test {
3839

3940
// Helper function
4041
// Runs a system command with given args
42+
#[allow(dead_code)]
4143
fn run_cmd_with_args(cmd: &str, args: &[&str]) -> Result<serde_json::Value, IntTestError> {
4244
let output = Command::new(cmd).args(args).output().unwrap();
4345
let mut value = output.stdout;
4446
let error = output.stderr;
45-
if value.len() == 0 {
47+
if value.is_empty() {
4648
return Err(IntTestError::CmdExec(String::from_utf8(error).unwrap()));
4749
}
4850
value.pop(); // remove `\n` at end
@@ -56,6 +58,7 @@ mod test {
5658

5759
// Helper Function
5860
// Transforms a json value to string
61+
#[allow(dead_code)]
5962
fn value_to_string(value: &Value) -> Result<String, IntTestError> {
6063
match value {
6164
Value::Bool(bool) => match bool {
@@ -72,6 +75,7 @@ mod test {
7275

7376
// Helper Function
7477
// Extracts value from a given json object and key
78+
#[allow(dead_code)]
7579
fn get_value(json: &Value, key: &str) -> Result<String, IntTestError> {
7680
let map = json
7781
.as_object()
@@ -86,6 +90,7 @@ mod test {
8690

8791
/// The bdk-cli command struct
8892
/// Use it to perform all bdk-cli operations
93+
#[allow(dead_code)]
8994
#[derive(Debug)]
9095
struct BdkCli {
9196
target: String,
@@ -108,10 +113,10 @@ mod test {
108113
let mut feat = "--features=".to_string();
109114
for item in features {
110115
feat.push_str(item);
111-
feat.push_str(",");
116+
feat.push(',');
112117
}
113118
feat.pop(); // remove the last comma
114-
let _build = Command::new("cargo").args(&["build", &feat]).output()?;
119+
let _build = Command::new("cargo").args(["build", &feat]).output()?;
115120

116121
let mut bdk_cli = Self {
117122
target: "./target/debug/bdk-cli".to_string(),
@@ -159,7 +164,7 @@ mod test {
159164
wallet_args.push("-d");
160165
wallet_args.push(self.recv_desc.as_ref().unwrap());
161166
wallet_args.push("-c");
162-
wallet_args.push(&self.chang_desc.as_ref().unwrap());
167+
wallet_args.push(self.chang_desc.as_ref().unwrap());
163168

164169
for arg in args {
165170
wallet_args.push(arg);
@@ -195,6 +200,7 @@ mod test {
195200

196201
// Run A Basic wallet operation test, with given feature
197202
#[cfg(test)]
203+
#[allow(dead_code)]
198204
fn basic_wallet_ops(feature: &str) {
199205
// Create a temporary directory for testing env
200206
let mut test_dir = std::env::current_dir().unwrap();

0 commit comments

Comments
 (0)