Skip to content

Commit c58897b

Browse files
committed
failing at generation of address, says no available keys
1 parent 1d9b199 commit c58897b

File tree

4 files changed

+59
-28
lines changed

4 files changed

+59
-28
lines changed

client/src/client.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ pub trait RpcApi: Sized {
264264
self.call("loadwallet", &[wallet.into()])
265265
}
266266

267-
fn unload_wallet(&self, wallet: Option<&str>) -> Result<()> {
267+
fn unload_wallet(&self, wallet: Option<&str>) -> Result<json::UnloadWalletResult> {
268268
let mut args = [opt_into_json(wallet)?];
269269
self.call("unloadwallet", handle_defaults(&mut args, &[null()]))
270270
}
@@ -295,25 +295,34 @@ pub trait RpcApi: Sized {
295295
)
296296
}
297297

298-
fn import_descriptors(&self, descriptor: &str, change_descriptor: &str) -> Result<bool> {
299-
let ex_descriptor = json::DescriptorFormat {
300-
descriptor: descriptor.to_string(),
301-
timestamp: "now".to_string(),
298+
fn import_descriptors(
299+
&self,
300+
descriptor: &str,
301+
change_descriptor: &str,
302+
) -> Result<Vec<json::ImportDescriptorResult>> {
303+
let ex_descriptor = json::ImportDescriptorRequest {
302304
active: true,
303-
range: [0, 100],
305+
descriptor: descriptor.to_string(),
306+
range: [0, 1000],
307+
next_index: 0,
308+
timestamp: 1455191478,
304309
internal: false,
305310
};
306311

307-
let in_descriptor = json::DescriptorFormat {
308-
descriptor: change_descriptor.to_string(),
309-
timestamp: "now".to_string(),
312+
let in_descriptor = json::ImportDescriptorRequest {
310313
active: true,
311-
range: [0, 999],
314+
descriptor: change_descriptor.to_string(),
315+
range: [0, 1000],
316+
next_index: 0,
317+
timestamp: 1455191478,
312318
internal: true,
313319
};
314320

315-
let args = [into_json(ex_descriptor)?, into_json(in_descriptor)?];
316-
self.call("importdescriptors", &args)
321+
let arg = into_json([ex_descriptor, in_descriptor])?;
322+
println!("arg: {}", arg);
323+
let result = self.call("importdescriptors", &[arg]);
324+
println!("result: {:?}", result);
325+
result
317326
}
318327

319328
fn list_wallets(&self) -> Result<Vec<String>> {
@@ -1162,8 +1171,10 @@ impl RpcApi for Client {
11621171
if log_enabled!(Debug) {
11631172
debug!(target: "bitcoincore_rpc", "JSON-RPC request: {} {}", cmd, serde_json::Value::from(args));
11641173
}
1165-
1174+
println!("client req: {:?}", req);
11661175
let resp = self.client.send_request(req).map_err(Error::from);
1176+
println!("client resp: {:?}", resp);
1177+
println!("client resp.result: {:?}", resp.as_ref().map(|r| r.result.as_ref()));
11671178
log_response(cmd, &resp);
11681179
Ok(resp?.result()?)
11691180
}

integration_test/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ RPC_URL=http://localhost:12349 \
4747

4848
RESULT=$?
4949

50-
kill -9 $PID1 $PID2
50+
# kill -9 $PID1 $PID2
5151

5252
exit $RESULT

integration_test/src/main.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,18 @@ fn get_auth() -> bitcoincore_rpc::Auth {
124124
fn main() {
125125
log::set_logger(&LOGGER).map(|()| log::set_max_level(log::LevelFilter::max())).unwrap();
126126

127-
let rpc_url = format!("{}/wallet/testwallet", get_rpc_url());
127+
let mut rpc_url = format!("{}/wallet/testdescriptorwallet", get_rpc_url());
128128
let auth = get_auth();
129-
130-
let cl = Client::new(&rpc_url, auth).unwrap();
129+
let mut cl = Client::new(&rpc_url, auth).unwrap();
131130

132131
test_get_network_info(&cl);
133132
unsafe { VERSION = cl.version().unwrap() };
134133
println!("Version: {}", version());
135134

136135
test_import_descriptors(&cl);
137136

137+
rpc_url = format!("{}/wallet/testwallet", get_rpc_url());
138+
cl = Client::new(&rpc_url, get_auth()).unwrap();
138139
cl.create_wallet("testwallet", None, None, None, None, None).unwrap();
139140

140141
test_get_mining_info(&cl);
@@ -1008,14 +1009,20 @@ fn test_create_wallet(cl: &Client) {
10081009
}
10091010

10101011
fn test_import_descriptors(cl: &Client) {
1011-
cl.create_wallet("testwallet", Some(false), Some(true), Some(""), Some(false), Some(true))
1012-
.unwrap();
1012+
cl.create_wallet(
1013+
"testdescriptorwallet",
1014+
Some(false),
1015+
Some(true),
1016+
Some(""),
1017+
Some(false),
1018+
Some(true),
1019+
)
1020+
.unwrap();
10131021

10141022
let descriptor = "wpkh(tprv8ZgxMBicQKsPeTNzU5evMToRhHA9h3UCxbpzrzjUWUd6TQktkhmY82dQx5f6QaFpSWMzZxKz16xQFGeW7ykPjYuTetU6ep9aFTpAt7jKhPU/44'/0'/0'/0/*)#w2lyh4jx";
1015-
let x = cl.import_descriptors(descriptor, descriptor);
1016-
x.unwrap();
1023+
cl.import_descriptors(descriptor, descriptor).unwrap();
10171024
cl.get_new_address(None, Some(json::AddressType::Bech32m)).unwrap();
1018-
cl.unload_wallet(Some("testwallet")).unwrap();
1025+
cl.unload_wallet(Some("testdescriptorwallet")).unwrap();
10191026
}
10201027

10211028
fn test_get_tx_out_set_info(cl: &Client) {

json/src/lib.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ pub struct LoadWalletResult {
130130
pub warning: Option<String>,
131131
}
132132

133+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
134+
pub struct UnloadWalletResult {
135+
pub warning: Option<String>,
136+
}
137+
133138
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
134139
pub struct GetWalletInfoResult {
135140
#[serde(rename = "walletname")]
@@ -1066,7 +1071,7 @@ pub struct GetPeerInfoResult {
10661071
}
10671072

10681073
#[derive(Copy, Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
1069-
#[serde(rename_all = "lowercase")]
1074+
#[serde(rename_all = "snake_case")]
10701075
pub enum GetPeerInfoResultNetwork {
10711076
Ipv4,
10721077
Ipv6,
@@ -1690,14 +1695,22 @@ where
16901695
Ok(Some(res))
16911696
}
16921697

1693-
/// Descriptor Format
1698+
/// Import Descriptor Request
16941699
#[derive(Serialize, Clone, PartialEq, Eq, Debug)]
1695-
#[serde(rename_all = "camelCase")]
1696-
pub struct DescriptorFormat {
1700+
pub struct ImportDescriptorRequest {
1701+
pub active: bool,
16971702
#[serde(rename = "desc")]
16981703
pub descriptor: String,
1699-
pub active: bool,
17001704
pub range: [i64; 2],
1701-
pub timestamp: String,
1705+
pub next_index: i64,
1706+
pub timestamp: i64,
17021707
pub internal: bool,
17031708
}
1709+
1710+
/// Imported Descriptor
1711+
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
1712+
pub struct ImportDescriptorResult {
1713+
pub success: bool,
1714+
pub warnings: Option<Vec<String>>,
1715+
pub error: Option<String>,
1716+
}

0 commit comments

Comments
 (0)