Skip to content

Commit adc7137

Browse files
committed
Added impl for ImportDescriptorRequest and modified importdescriptors to accept a Vec<ImportDescriptorRequest>
1 parent 4c93f8b commit adc7137

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

client/src/client.rs

+2-21
Original file line numberDiff line numberDiff line change
@@ -297,28 +297,9 @@ pub trait RpcApi: Sized {
297297

298298
fn import_descriptors(
299299
&self,
300-
descriptor: &str,
301-
change_descriptor: &str,
300+
descriptors: Vec<json::ImportDescriptorRequest>,
302301
) -> Result<Vec<json::ImportDescriptorResult>> {
303-
let ex_descriptor = json::ImportDescriptorRequest {
304-
active: true,
305-
descriptor: descriptor.to_string(),
306-
range: [0, 100],
307-
next_index: 0,
308-
timestamp: "now".to_string(),
309-
internal: false,
310-
};
311-
312-
let in_descriptor = json::ImportDescriptorRequest {
313-
active: true,
314-
descriptor: change_descriptor.to_string(),
315-
range: [0, 100],
316-
next_index: 0,
317-
timestamp: "now".to_string(),
318-
internal: true,
319-
};
320-
321-
let arg = into_json([ex_descriptor, in_descriptor])?;
302+
let arg = into_json(descriptors)?;
322303
self.call("importdescriptors", &[arg])
323304
}
324305

integration_test/src/main.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1074,8 +1074,10 @@ fn test_descriptor_wallet(cl: &Client) {
10741074
.unwrap();
10751075

10761076
cl.import_descriptors(
1077-
"wpkh(tprv8ZgxMBicQKsPeRBCAfUGsZhyHy9dwWyPqhSJmaMnMJQWWtt8L2SkTeHaiF82CUCGtiTiHAs3cMkjdKckGKiCWeYtvMPF1jDTWYTryRMicpx/86h/1h/0h/0/*)#ymr4jlz6",
1078-
"wpkh(tprv8ZgxMBicQKsPeRBCAfUGsZhyHy9dwWyPqhSJmaMnMJQWWtt8L2SkTeHaiF82CUCGtiTiHAs3cMkjdKckGKiCWeYtvMPF1jDTWYTryRMicpx/86h/1h/0h/1/*)#40x502jz",
1077+
vec![
1078+
json::ImportDescriptorRequest::new("wpkh(tprv8ZgxMBicQKsPeRBCAfUGsZhyHy9dwWyPqhSJmaMnMJQWWtt8L2SkTeHaiF82CUCGtiTiHAs3cMkjdKckGKiCWeYtvMPF1jDTWYTryRMicpx/86h/1h/0h/0/*)#ymr4jlz6", false),
1079+
json::ImportDescriptorRequest::new("wpkh(tprv8ZgxMBicQKsPeRBCAfUGsZhyHy9dwWyPqhSJmaMnMJQWWtt8L2SkTeHaiF82CUCGtiTiHAs3cMkjdKckGKiCWeYtvMPF1jDTWYTryRMicpx/86h/1h/0h/1/*)#40x502jz", true),
1080+
]
10791081
).unwrap();
10801082

10811083
let add = cl.get_new_address(None, Some(json::AddressType::Bech32)).unwrap();

json/src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,20 @@ pub struct ImportDescriptorRequest {
17021702
pub internal: bool,
17031703
}
17041704

1705+
impl ImportDescriptorRequest {
1706+
/// Create a new Import Descriptor request providing just the descriptor and internal flags
1707+
pub fn new(descriptor: &str, internal: bool) -> Self {
1708+
ImportDescriptorRequest {
1709+
descriptor: descriptor.to_string(),
1710+
internal,
1711+
active: true,
1712+
range: [0, 100],
1713+
next_index: 0,
1714+
timestamp: "now".to_string(),
1715+
}
1716+
}
1717+
}
1718+
17051719
/// Imported Descriptor Result
17061720
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
17071721
pub struct ImportDescriptorResult {

0 commit comments

Comments
 (0)