Skip to content

Commit

Permalink
Remove dependency on ord-bitcoincore-rpc crate (#3959)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph authored Sep 21, 2024
1 parent 34ce19a commit 4b109f9
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 14 deletions.
28 changes: 27 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mime = "0.3.16"
mime_guess = "2.0.4"
miniscript = "10.0.0"
mp4 = "0.14.0"
ord-bitcoincore-rpc = "0.17.2"
bitcoincore-rpc = "0.17.0"
ordinals = { version = "0.0.10", path = "crates/ordinals" }
redb = "2.1.1"
ref-cast = "1.0.23"
Expand Down
3 changes: 1 addition & 2 deletions src/subcommand/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use {
super::*,
crate::wallet::{batch, wallet_constructor::WalletConstructor, Wallet},
bitcoincore_rpc::bitcoincore_rpc_json::ListDescriptorsResult,
crate::wallet::{batch, wallet_constructor::WalletConstructor, ListDescriptorsResult, Wallet},
shared_args::SharedArgs,
};

Expand Down
4 changes: 3 additions & 1 deletion src/subcommand/wallet/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub(crate) fn run(wallet: Wallet) -> SubcommandResult {
);

Ok(Some(Box::new(
wallet.bitcoin_client().list_descriptors(Some(true))?,
wallet
.bitcoin_client()
.call::<ListDescriptorsResult>("listdescriptors", &[serde_json::to_value(true)?])?,
)))
}
24 changes: 20 additions & 4 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use {
bip32::{ChildNumber, DerivationPath, ExtendedPrivKey, Fingerprint},
psbt::Psbt,
},
bitcoincore_rpc::bitcoincore_rpc_json::{Descriptor, ImportDescriptors, Timestamp},
bitcoincore_rpc::bitcoincore_rpc_json::{ImportDescriptors, Timestamp},
entry::{EtchingEntry, EtchingEntryValue},
fee_rate::FeeRate,
index::entry::Entry,
Expand Down Expand Up @@ -47,6 +47,22 @@ impl From<Statistic> for u64 {
}
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct Descriptor {
pub desc: String,
pub timestamp: bitcoincore_rpc::bitcoincore_rpc_json::Timestamp,
pub active: bool,
pub internal: Option<bool>,
pub range: Option<(u64, u64)>,
pub next: Option<u64>,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct ListDescriptorsResult {
pub wallet_name: String,
pub descriptors: Vec<Descriptor>,
}

#[derive(Debug, PartialEq)]
pub(crate) enum Maturity {
BelowMinimumHeight(u64),
Expand Down Expand Up @@ -465,7 +481,7 @@ impl Wallet {
})
.collect::<Vec<ImportDescriptors>>();

client.import_descriptors(descriptors)?;
client.call::<serde_json::Value>("importdescriptors", &[serde_json::to_value(descriptors)?])?;

Ok(())
}
Expand Down Expand Up @@ -536,15 +552,15 @@ impl Wallet {

settings
.bitcoin_rpc_client(Some(name.clone()))?
.import_descriptors(vec![ImportDescriptors {
.import_descriptors(ImportDescriptors {
descriptor: descriptor.to_string_with_secret(&key_map),
timestamp: Timestamp::Now,
active: Some(true),
range: None,
next_index: None,
internal: Some(change),
label: None,
}])?;
})?;

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/batch/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,15 +687,15 @@ impl Plan {

let response = wallet
.bitcoin_client()
.import_descriptors(vec![ImportDescriptors {
.import_descriptors(ImportDescriptors {
descriptor: format!("rawtr({})#{}", recovery_private_key.to_wif(), info.checksum),
timestamp: Timestamp::Now,
active: Some(false),
range: None,
next_index: None,
internal: Some(false),
label: Some("commit tx recovery key".to_string()),
}])?;
})?;

for result in response {
if !result.success {
Expand Down
7 changes: 6 additions & 1 deletion src/wallet/wallet_constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ impl WalletConstructor {
}

if client.get_wallet_info()?.private_keys_enabled {
Wallet::check_descriptors(&self.name, client.list_descriptors(None)?.descriptors)?;
Wallet::check_descriptors(
&self.name,
client
.call::<ListDescriptorsResult>("listdescriptors", &[serde_json::Value::Null])?
.descriptors,
)?;
}

client
Expand Down
3 changes: 1 addition & 2 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ use {
blockdata::constants::COIN_VALUE,
Network, OutPoint, Sequence, Txid, Witness,
},
bitcoincore_rpc::bitcoincore_rpc_json::ListDescriptorsResult,
chrono::{DateTime, Utc},
executable_path::executable_path,
mockcore::TransactionTemplate,
ord::{
api, chain::Chain, decimal::Decimal, outgoing::Outgoing, subcommand::runes::RuneInfo,
wallet::batch, InscriptionId, RuneEntry,
wallet::batch, wallet::ListDescriptorsResult, InscriptionId, RuneEntry,
},
ordinals::{
Artifact, Charm, Edict, Pile, Rarity, Rune, RuneId, Runestone, Sat, SatPoint, SpacedRune,
Expand Down

0 comments on commit 4b109f9

Please sign in to comment.