Skip to content

Commit 15495c4

Browse files
authored
Merge branch 'bitcoindevkit:master' into adding_descriptor_generator
2 parents 31f256a + 85da2af commit 15495c4

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
@@ -557,7 +557,7 @@ pub(crate) async fn handle_online_wallet_subcommand(
557557
mut warning_subscriber,
558558
update_subscriber: _,
559559
node,
560-
} = client;
560+
} = *client;
561561

562562
let subscriber = tracing_subscriber::FmtSubscriber::new();
563563
tracing::subscriber::set_global_default(subscriber)

src/utils.rs

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

155155
#[cfg(feature = "cbf")]
156-
KyotoClient { client: LightClient },
156+
KyotoClient { client: Box<LightClient> },
157157
}
158158

159159
#[cfg(any(
@@ -219,7 +219,9 @@ pub(crate) fn new_blockchain_client(
219219
.data_dir(&_datadir)
220220
.build_with_wallet(_wallet, scan_type)?;
221221

222-
BlockchainClient::KyotoClient { client }
222+
BlockchainClient::KyotoClient {
223+
client: Box::new(client),
224+
}
223225
}
224226
};
225227
Ok(client)
@@ -336,15 +338,15 @@ pub async fn trace_logger(
336338

337339
// Handle Kyoto Client sync
338340
#[cfg(feature = "cbf")]
339-
pub async fn sync_kyoto_client(wallet: &mut Wallet, client: LightClient) -> Result<(), Error> {
341+
pub async fn sync_kyoto_client(wallet: &mut Wallet, client: Box<LightClient>) -> Result<(), Error> {
340342
let LightClient {
341343
requester,
342344
log_subscriber,
343345
info_subscriber,
344346
warning_subscriber,
345347
mut update_subscriber,
346348
node,
347-
} = client;
349+
} = *client;
348350

349351
let subscriber = tracing_subscriber::FmtSubscriber::new();
350352
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)