Skip to content

Implement importpubkey method and test #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/src/client_sync/v17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ crate::impl_client_v17__get_wallet_info!();
crate::impl_client_v17__import_address!();
crate::impl_client_v17__import_privkey!();
crate::impl_client_v17__import_pruned_funds!();
crate::impl_client_v17__import_pubkey!();
crate::impl_client_v17__list_address_groupings!();
crate::impl_client_v17__list_labels!();
crate::impl_client_v17__list_lock_unspent!();
Expand Down
16 changes: 16 additions & 0 deletions client/src/client_sync/v17/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,22 @@ macro_rules! impl_client_v17__import_pruned_funds {
};
}

/// Implements Bitcoin Core JSON-RPC API method `importpubkey`.
#[macro_export]
macro_rules! impl_client_v17__import_pubkey {
() => {
impl Client {
pub fn import_pubkey(&self, pubkey: &bitcoin::PublicKey) -> Result<()> {
match self.call("importpubkey", &[into_json(pubkey)?]) {
Ok(serde_json::Value::Null) => Ok(()),
Ok(res) => Err(Error::Returned(res.to_string())),
Err(err) => Err(err.into()),
}
}
}
};
}

/// Implements Bitcoin Core JSON-RPC API method `listaddressgroupings`.
#[macro_export]
macro_rules! impl_client_v17__list_address_groupings {
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v18/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ crate::impl_client_v17__get_wallet_info!();
crate::impl_client_v17__import_address!();
crate::impl_client_v17__import_privkey!();
crate::impl_client_v17__import_pruned_funds!();
crate::impl_client_v17__import_pubkey!();
crate::impl_client_v17__list_address_groupings!();
crate::impl_client_v17__list_labels!();
crate::impl_client_v17__list_lock_unspent!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v19/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ crate::impl_client_v17__get_wallet_info!();
crate::impl_client_v17__import_address!();
crate::impl_client_v17__import_privkey!();
crate::impl_client_v17__import_pruned_funds!();
crate::impl_client_v17__import_pubkey!();
crate::impl_client_v17__list_address_groupings!();
crate::impl_client_v18__list_received_by_label!();
crate::impl_client_v17__list_labels!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ crate::impl_client_v17__get_wallet_info!();
crate::impl_client_v17__import_address!();
crate::impl_client_v17__import_privkey!();
crate::impl_client_v17__import_pruned_funds!();
crate::impl_client_v17__import_pubkey!();
crate::impl_client_v17__list_address_groupings!();
crate::impl_client_v17__list_labels!();
crate::impl_client_v18__list_received_by_label!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v21/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ crate::impl_client_v17__get_wallet_info!();
crate::impl_client_v17__import_address!();
crate::impl_client_v17__import_privkey!();
crate::impl_client_v17__import_pruned_funds!();
crate::impl_client_v17__import_pubkey!();
crate::impl_client_v17__list_address_groupings!();
crate::impl_client_v17__list_labels!();
crate::impl_client_v18__list_received_by_label!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v22/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ crate::impl_client_v17__get_wallet_info!();
crate::impl_client_v17__import_address!();
crate::impl_client_v17__import_privkey!();
crate::impl_client_v17__import_pruned_funds!();
crate::impl_client_v17__import_pubkey!();
crate::impl_client_v17__list_address_groupings!();
crate::impl_client_v18__list_received_by_label!();
crate::impl_client_v17__list_labels!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v23/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ crate::impl_client_v17__get_wallet_info!();
crate::impl_client_v17__import_address!();
crate::impl_client_v17__import_privkey!();
crate::impl_client_v17__import_pruned_funds!();
crate::impl_client_v17__import_pubkey!();
crate::impl_client_v17__list_address_groupings!();
crate::impl_client_v18__list_received_by_label!();
crate::impl_client_v17__list_labels!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v24/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ crate::impl_client_v17__get_wallet_info!();
crate::impl_client_v17__import_address!();
crate::impl_client_v17__import_privkey!();
crate::impl_client_v17__import_pruned_funds!();
crate::impl_client_v17__import_pubkey!();
crate::impl_client_v17__list_address_groupings!();
crate::impl_client_v18__list_received_by_label!();
crate::impl_client_v17__list_labels!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v25/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ crate::impl_client_v17__get_wallet_info!();
crate::impl_client_v17__import_address!();
crate::impl_client_v17__import_privkey!();
crate::impl_client_v17__import_pruned_funds!();
crate::impl_client_v17__import_pubkey!();
crate::impl_client_v17__list_address_groupings!();
crate::impl_client_v18__list_received_by_label!();
crate::impl_client_v17__list_labels!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v26/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ crate::impl_client_v17__get_wallet_info!();
crate::impl_client_v17__import_address!();
crate::impl_client_v17__import_privkey!();
crate::impl_client_v17__import_pruned_funds!();
crate::impl_client_v17__import_pubkey!();
crate::impl_client_v17__list_address_groupings!();
crate::impl_client_v17__list_labels!();
crate::impl_client_v18__list_received_by_label!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v27/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ crate::impl_client_v17__get_wallet_info!();
crate::impl_client_v17__import_address!();
crate::impl_client_v17__import_privkey!();
crate::impl_client_v17__import_pruned_funds!();
crate::impl_client_v17__import_pubkey!();
crate::impl_client_v17__list_address_groupings!();
crate::impl_client_v18__list_received_by_label!();
crate::impl_client_v17__list_labels!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v28/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ crate::impl_client_v17__get_wallet_info!();
crate::impl_client_v17__import_address!();
crate::impl_client_v17__import_privkey!();
crate::impl_client_v17__import_pruned_funds!();
crate::impl_client_v17__import_pubkey!();
crate::impl_client_v17__list_address_groupings!();
crate::impl_client_v18__list_received_by_label!();
crate::impl_client_v17__list_labels!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v29/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ crate::impl_client_v17__get_wallet_info!();
crate::impl_client_v17__import_address!();
crate::impl_client_v17__import_privkey!();
crate::impl_client_v17__import_pruned_funds!();
crate::impl_client_v17__import_pubkey!();
crate::impl_client_v17__list_address_groupings!();
crate::impl_client_v18__list_received_by_label!();
crate::impl_client_v17__list_labels!();
Expand Down
22 changes: 21 additions & 1 deletion integration_test/tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#[cfg(feature = "TODO")]
use bitcoin::address::{Address, NetworkChecked};
use bitcoin::{Amount, PrivateKey};
use bitcoin::{Amount, PrivateKey, PublicKey};
use integration_test::{Node, NodeExt as _, Wallet};
use node::{mtype,AddressType};
use node::vtype::*; // All the version specific types.
Expand Down Expand Up @@ -362,6 +362,26 @@ fn wallet__import_privkey() {
let _: () = node.client.import_privkey(&privkey).expect("importprivkey");
}

#[test]
fn wallet__import_pubkey() {
let node = match () {
#[cfg(feature = "v22_and_below")]
() => Node::with_wallet(Wallet::Default, &[]),
#[cfg(not(feature = "v22_and_below"))]
() => {
let node = Node::with_wallet(Wallet::None, &["-deprecatedrpc=create_bdb"]);
node.client.create_legacy_wallet("wallet_name").expect("createlegacywallet");
node
}
};

let pubkey = "02ff12471208c14bd580709cb2358d98975247d8765f92bc25eab3b2763ed605f8"
.parse::<PublicKey>()
.unwrap();

let _: () = node.client.import_pubkey(&pubkey).expect("importpubkey");
}

#[test]
fn wallet__list_unspent__modelled() {
let node = match () {
Expand Down