Skip to content

Commit 4a320b1

Browse files
committed
refactor: Change path type to DerivationPath
1 parent ad08d1d commit 4a320b1

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

bdk-ffi/src/bitcoin.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use crate::error::{
33
PsbtParseError, TransactionError,
44
};
55
use crate::error::{ParseAmountError, PsbtFinalizeError};
6+
use crate::keys::DerivationPath;
7+
68
use crate::{impl_from_core_type, impl_hash_like, impl_into_core_type};
79
use std::collections::HashMap;
810

@@ -502,31 +504,35 @@ impl Display for Transaction {
502504
}
503505
}
504506

505-
#[derive(Clone, Debug, uniffi::Record)]
507+
#[derive(Clone, Debug)]
508+
#[derive(uniffi::Record)]
506509
pub struct TapScriptEntry {
507510
/// script (reuse existing `Script` FFI type)
508511
pub script: Arc<Script>,
509512
/// leaf version
510513
pub leaf_version: u8,
511514
}
512515

513-
#[derive(Clone, Debug, uniffi::Record, Hash, Eq, PartialEq)]
516+
#[derive(Clone, Debug)]
517+
#[derive(uniffi::Record)]
514518
pub struct TapKeyOrigin {
515519
/// leaf hashes as hex strings
516520
pub tap_leaf_hashes: Vec<String>,
517521
/// key source
518522
pub key_source: KeySource,
519523
}
520524

521-
#[derive(Clone, Debug, uniffi::Record, Hash, Eq, PartialEq)]
525+
#[derive(Clone, Debug)]
526+
#[derive(uniffi::Record)]
522527
pub struct KeySource {
523528
/// A fingerprint
524529
pub fingerprint: String,
525530
/// A BIP-32 derivation path.
526-
pub path: String,
531+
pub path: Arc<DerivationPath>,
527532
}
528533

529-
#[derive(Clone, Debug, uniffi::Record, Hash, Eq, PartialEq)]
534+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
535+
#[derive(uniffi::Record)]
530536
pub struct Key {
531537
/// The type of this PSBT key.
532538
pub type_value: u8,
@@ -535,7 +541,8 @@ pub struct Key {
535541
pub key: Vec<u8>,
536542
}
537543

538-
#[derive(Clone, Debug, uniffi::Record, Hash, Eq, PartialEq)]
544+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
545+
#[derive(uniffi::Record)]
539546
pub struct ProprietaryKey {
540547
/// Proprietary type prefix used for grouping together keys under some
541548
/// application and avoid namespace collision
@@ -546,7 +553,8 @@ pub struct ProprietaryKey {
546553
pub key: Vec<u8>,
547554
}
548555

549-
#[derive(Clone, Debug, uniffi::Record, Hash, Eq, PartialEq)]
556+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
557+
#[derive(uniffi::Record)]
550558
pub struct ControlBlock {
551559
/// The internal key.
552560
pub internal_key: Vec<u8>,
@@ -558,7 +566,8 @@ pub struct ControlBlock {
558566
pub leaf_version: u8,
559567
}
560568

561-
#[derive(Clone, Debug, uniffi::Record, Hash, Eq, PartialEq)]
569+
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
570+
#[derive(uniffi::Record)]
562571
pub struct TapScriptSigKey {
563572
/// An x-only public key, used for verification of Taproot signatures and serialized according to BIP-340.
564573
pub xonly_pubkey: String,
@@ -568,7 +577,8 @@ pub struct TapScriptSigKey {
568577
}
569578

570579
/// A key-value map for an input of the corresponding index in the unsigned transaction.
571-
#[derive(Clone, Debug, uniffi::Record)]
580+
#[derive(Clone, Debug)]
581+
#[derive(uniffi::Record)]
572582
pub struct Input {
573583
/// The non-witness transaction this input spends from. Should only be
574584
/// `Option::Some` for inputs which spend non-segwit outputs or
@@ -655,7 +665,7 @@ impl From<&BdkInput> for Input {
655665
pk.to_string(),
656666
KeySource {
657667
fingerprint: fingerprint.to_string(),
658-
path: deriv_path.to_string(),
668+
path: Arc::new(deriv_path.clone().into()),
659669
},
660670
)
661671
})
@@ -723,7 +733,7 @@ impl From<&BdkInput> for Input {
723733
tap_leaf_hashes: v.0.iter().map(|h| h.to_string()).collect(),
724734
key_source: KeySource {
725735
fingerprint: v.1 .0.to_string(),
726-
path: v.1 .1.to_string(),
736+
path: Arc::new(v.1 .1.clone().into()),
727737
},
728738
};
729739
(key, value)

bdk-ffi/src/keys.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ impl Display for Mnemonic {
6565
}
6666

6767
/// A BIP-32 derivation path.
68-
#[derive(Clone, Debug, Hash, Eq, PartialEq, uniffi::Object)]
68+
#[derive(Clone, Debug, uniffi::Object)]
69+
#[uniffi::export(Display)]
6970
pub struct DerivationPath(pub(crate) BdkDerivationPath);
7071

7172
#[uniffi::export]

bdk-ffi/src/tests/bitcoin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ fn test_psbt_input_bip32_derivation() {
442442
"Fingerprint does not match the expected value"
443443
);
444444

445-
let derivation_path = &derivation.unwrap().path;
445+
let derivation_path = &derivation.unwrap().path.to_string();
446446
let expected_derivation_path = "84'/1'/0'/0/0";
447447
assert_eq!(
448448
derivation_path, &expected_derivation_path,

0 commit comments

Comments
 (0)