Skip to content

Commit 36144c0

Browse files
committed
Implement importmulti method and test
Remove redundant code from types and args
1 parent 414ba10 commit 36144c0

File tree

42 files changed

+341
-191
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+341
-191
lines changed

client/src/client_sync/v17/mod.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ crate::impl_client_v17__get_transaction!();
128128
crate::impl_client_v17__get_unconfirmed_balance!();
129129
crate::impl_client_v17__get_wallet_info!();
130130
crate::impl_client_v17__import_address!();
131+
crate::impl_client_v17__import_multi!();
131132
crate::impl_client_v17__import_privkey!();
132133
crate::impl_client_v17__import_pruned_funds!();
133134
crate::impl_client_v17__list_address_groupings!();
@@ -246,3 +247,41 @@ pub enum SetBanCommand {
246247
Add,
247248
Remove,
248249
}
250+
251+
/// Args for the `importmulti` method
252+
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
253+
pub struct ImportMultiRequest {
254+
/// Descriptor to import. If using descriptor, donot also provide address/scriptPubKey, scripts, or pubkeys.
255+
pub desc: Option<String>,
256+
/// Type of scriptPubKey (string for script, json for address). Should not be provided if using descriptor.
257+
#[serde(rename = "scriptPubKey")]
258+
pub script_pub_key: Option<ImportMultiScriptPubKey>,
259+
/// Creation time of the key expressed in UNIX epoch time, or the string "now" to substitute the current synced blockchain time.
260+
pub timestamp: ImportMultiTimestamp,
261+
}
262+
263+
/// `scriptPubKey` can be a string for script or json for address.
264+
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
265+
#[serde(untagged)]
266+
pub enum ImportMultiScriptPubKey {
267+
/// The script.
268+
Script(String),
269+
/// The address.
270+
Address { address: String },
271+
}
272+
273+
/// `timestamp` can be a number (UNIX epoch time) or the string `"now"`
274+
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
275+
#[serde(untagged)]
276+
pub enum ImportMultiTimestamp {
277+
/// The string "now".
278+
Now(String),
279+
/// The UNIX epoch time.
280+
Time(u64),
281+
}
282+
283+
impl Default for ImportMultiTimestamp {
284+
fn default() -> Self {
285+
ImportMultiTimestamp::Now("now".to_string())
286+
}
287+
}

client/src/client_sync/v17/wallet.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,18 @@ macro_rules! impl_client_v17__import_address {
298298
};
299299
}
300300

301+
/// Implements Bitcoin Core JSON-RPC API method `importmulti`
302+
#[macro_export]
303+
macro_rules! impl_client_v17__import_multi {
304+
() => {
305+
impl Client {
306+
pub fn import_multi( &self, requests: &[ImportMultiRequest]) -> Result<ImportMulti> {
307+
self.call("importmulti", &[into_json(requests)?])
308+
}
309+
}
310+
};
311+
}
312+
301313
/// Implements Bitcoin Core JSON-RPC API method `importprivkey`.
302314
#[macro_export]
303315
macro_rules! impl_client_v17__import_privkey {

client/src/client_sync/v18/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::types::v18::*;
2424
pub use crate::client_sync::{
2525
v17::{
2626
AddNodeCommand, AddressType, Input, Output, SetBanCommand, TemplateRequest,
27-
TemplateRules, WalletCreateFundedPsbtInput
27+
TemplateRules, WalletCreateFundedPsbtInput, ImportMultiRequest, ImportMultiScriptPubKey, ImportMultiTimestamp,
2828
},
2929
};
3030

@@ -143,6 +143,7 @@ crate::impl_client_v17__get_transaction!();
143143
crate::impl_client_v17__get_unconfirmed_balance!();
144144
crate::impl_client_v17__get_wallet_info!();
145145
crate::impl_client_v17__import_address!();
146+
crate::impl_client_v17__import_multi!();
146147
crate::impl_client_v17__import_privkey!();
147148
crate::impl_client_v17__import_pruned_funds!();
148149
crate::impl_client_v17__list_address_groupings!();

client/src/client_sync/v19/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::types::v19::*;
2020
pub use crate::client_sync::{
2121
v17::{
2222
AddNodeCommand, AddressType, Input, Output, SetBanCommand, TemplateRequest,
23-
TemplateRules, WalletCreateFundedPsbtInput
23+
TemplateRules, WalletCreateFundedPsbtInput, ImportMultiRequest, ImportMultiScriptPubKey, ImportMultiTimestamp,
2424
},
2525
};
2626

@@ -139,6 +139,7 @@ crate::impl_client_v17__get_transaction!();
139139
crate::impl_client_v17__get_unconfirmed_balance!();
140140
crate::impl_client_v17__get_wallet_info!();
141141
crate::impl_client_v17__import_address!();
142+
crate::impl_client_v17__import_multi!();
142143
crate::impl_client_v17__import_privkey!();
143144
crate::impl_client_v17__import_pruned_funds!();
144145
crate::impl_client_v17__list_address_groupings!();

client/src/client_sync/v20/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::types::v20::*;
1717
pub use crate::client_sync::{
1818
v17::{
1919
AddressType, AddNodeCommand, Input, Output, SetBanCommand, TemplateRequest, TemplateRules,
20-
WalletCreateFundedPsbtInput
20+
WalletCreateFundedPsbtInput, ImportMultiRequest, ImportMultiScriptPubKey, ImportMultiTimestamp,
2121
},
2222
};
2323

@@ -136,6 +136,7 @@ crate::impl_client_v17__get_transaction!();
136136
crate::impl_client_v17__get_unconfirmed_balance!();
137137
crate::impl_client_v17__get_wallet_info!();
138138
crate::impl_client_v17__import_address!();
139+
crate::impl_client_v17__import_multi!();
139140
crate::impl_client_v17__import_privkey!();
140141
crate::impl_client_v17__import_pruned_funds!();
141142
crate::impl_client_v17__list_address_groupings!();

client/src/client_sync/v21/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::types::v21::*;
1919
pub use crate::client_sync::{
2020
v17::{
2121
AddNodeCommand, AddressType, Input, Output, SetBanCommand, TemplateRequest,
22-
TemplateRules, WalletCreateFundedPsbtInput
22+
TemplateRules, WalletCreateFundedPsbtInput, ImportMultiRequest, ImportMultiScriptPubKey, ImportMultiTimestamp,
2323
},
2424
};
2525

@@ -138,6 +138,7 @@ crate::impl_client_v17__get_transaction!();
138138
crate::impl_client_v17__get_unconfirmed_balance!();
139139
crate::impl_client_v17__get_wallet_info!();
140140
crate::impl_client_v17__import_address!();
141+
crate::impl_client_v17__import_multi!();
141142
crate::impl_client_v17__import_privkey!();
142143
crate::impl_client_v17__import_pruned_funds!();
143144
crate::impl_client_v17__list_address_groupings!();

client/src/client_sync/v22/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::types::v22::*;
1919
pub use crate::client_sync::{
2020
v17::{
2121
AddNodeCommand, AddressType, Input, Output, SetBanCommand, TemplateRequest,
22-
TemplateRules, WalletCreateFundedPsbtInput
22+
TemplateRules, WalletCreateFundedPsbtInput, ImportMultiRequest, ImportMultiScriptPubKey, ImportMultiTimestamp,
2323
},
2424
};
2525

@@ -138,6 +138,7 @@ crate::impl_client_v17__get_transaction!();
138138
crate::impl_client_v17__get_unconfirmed_balance!();
139139
crate::impl_client_v17__get_wallet_info!();
140140
crate::impl_client_v17__import_address!();
141+
crate::impl_client_v17__import_multi!();
141142
crate::impl_client_v17__import_privkey!();
142143
crate::impl_client_v17__import_pruned_funds!();
143144
crate::impl_client_v17__list_address_groupings!();

client/src/client_sync/v23/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::types::v23::*;
2121
pub use crate::client_sync::{
2222
v17::{
2323
AddNodeCommand, Input, Output, SetBanCommand, TemplateRequest, TemplateRules,
24-
WalletCreateFundedPsbtInput
24+
WalletCreateFundedPsbtInput, ImportMultiRequest, ImportMultiScriptPubKey, ImportMultiTimestamp,
2525
},
2626
};
2727

@@ -140,6 +140,7 @@ crate::impl_client_v17__get_transaction!();
140140
crate::impl_client_v17__get_unconfirmed_balance!();
141141
crate::impl_client_v17__get_wallet_info!();
142142
crate::impl_client_v17__import_address!();
143+
crate::impl_client_v17__import_multi!();
143144
crate::impl_client_v17__import_privkey!();
144145
crate::impl_client_v17__import_pruned_funds!();
145146
crate::impl_client_v17__list_address_groupings!();

client/src/client_sync/v24/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::types::v24::*;
1717
pub use crate::client_sync::{
1818
v17::{
1919
AddNodeCommand, Input, Output, SetBanCommand, TemplateRequest, TemplateRules,
20-
WalletCreateFundedPsbtInput
20+
WalletCreateFundedPsbtInput, ImportMultiRequest, ImportMultiScriptPubKey, ImportMultiTimestamp,
2121
},
2222
v23::AddressType,
2323
};
@@ -137,6 +137,7 @@ crate::impl_client_v17__get_transaction!();
137137
crate::impl_client_v17__get_unconfirmed_balance!();
138138
crate::impl_client_v17__get_wallet_info!();
139139
crate::impl_client_v17__import_address!();
140+
crate::impl_client_v17__import_multi!();
140141
crate::impl_client_v17__import_privkey!();
141142
crate::impl_client_v17__import_pruned_funds!();
142143
crate::impl_client_v17__list_address_groupings!();

client/src/client_sync/v25/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::types::v25::*;
1717
pub use crate::client_sync::{
1818
v17::{
1919
AddNodeCommand, Input, Output, SetBanCommand, TemplateRequest, TemplateRules,
20-
WalletCreateFundedPsbtInput
20+
WalletCreateFundedPsbtInput, ImportMultiRequest, ImportMultiScriptPubKey, ImportMultiTimestamp,
2121
},
2222
v23::AddressType,
2323
};
@@ -137,6 +137,7 @@ crate::impl_client_v17__get_transaction!();
137137
crate::impl_client_v17__get_unconfirmed_balance!();
138138
crate::impl_client_v17__get_wallet_info!();
139139
crate::impl_client_v17__import_address!();
140+
crate::impl_client_v17__import_multi!();
140141
crate::impl_client_v17__import_privkey!();
141142
crate::impl_client_v17__import_pruned_funds!();
142143
crate::impl_client_v17__list_address_groupings!();

0 commit comments

Comments
 (0)