Skip to content

Commit ffcae65

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

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

bdk-ffi/src/bitcoin.rs

Lines changed: 15 additions & 10 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

@@ -510,23 +512,23 @@ pub struct TapScriptEntry {
510512
pub leaf_version: u8,
511513
}
512514

513-
#[derive(Clone, Debug, uniffi::Record, Hash, Eq, PartialEq)]
515+
#[derive(Clone, Debug, uniffi::Record)]
514516
pub struct TapKeyOrigin {
515517
/// leaf hashes as hex strings
516518
pub tap_leaf_hashes: Vec<String>,
517519
/// key source
518520
pub key_source: KeySource,
519521
}
520522

521-
#[derive(Clone, Debug, uniffi::Record, Hash, Eq, PartialEq)]
523+
#[derive(Clone, Debug, uniffi::Record)]
522524
pub struct KeySource {
523525
/// A fingerprint
524526
pub fingerprint: String,
525527
/// A BIP-32 derivation path.
526-
pub path: String,
528+
pub path: Arc<DerivationPath>,
527529
}
528530

529-
#[derive(Clone, Debug, uniffi::Record, Hash, Eq, PartialEq)]
531+
#[derive(Clone, Debug, Hash, Eq, PartialEq, uniffi::Record)]
530532
pub struct Key {
531533
/// The type of this PSBT key.
532534
pub type_value: u8,
@@ -535,7 +537,7 @@ pub struct Key {
535537
pub key: Vec<u8>,
536538
}
537539

538-
#[derive(Clone, Debug, uniffi::Record, Hash, Eq, PartialEq)]
540+
#[derive(Clone, Debug, Hash, Eq, PartialEq, uniffi::Record)]
539541
pub struct ProprietaryKey {
540542
/// Proprietary type prefix used for grouping together keys under some
541543
/// application and avoid namespace collision
@@ -546,7 +548,7 @@ pub struct ProprietaryKey {
546548
pub key: Vec<u8>,
547549
}
548550

549-
#[derive(Clone, Debug, uniffi::Record, Hash, Eq, PartialEq)]
551+
#[derive(Clone, Debug, Hash, Eq, PartialEq, uniffi::Record)]
550552
pub struct ControlBlock {
551553
/// The internal key.
552554
pub internal_key: Vec<u8>,
@@ -558,7 +560,7 @@ pub struct ControlBlock {
558560
pub leaf_version: u8,
559561
}
560562

561-
#[derive(Clone, Debug, uniffi::Record, Hash, Eq, PartialEq)]
563+
#[derive(Clone, Debug, Hash, Eq, PartialEq, uniffi::Record)]
562564
pub struct TapScriptSigKey {
563565
/// An x-only public key, used for verification of Taproot signatures and serialized according to BIP-340.
564566
pub xonly_pubkey: String,
@@ -655,7 +657,7 @@ impl From<&BdkInput> for Input {
655657
pk.to_string(),
656658
KeySource {
657659
fingerprint: fingerprint.to_string(),
658-
path: deriv_path.to_string(),
660+
path: Arc::new(deriv_path.clone().into()),
659661
},
660662
)
661663
})
@@ -722,8 +724,11 @@ impl From<&BdkInput> for Input {
722724
let value = TapKeyOrigin {
723725
tap_leaf_hashes: v.0.iter().map(|h| h.to_string()).collect(),
724726
key_source: KeySource {
725-
fingerprint: v.1 .0.to_string(),
726-
path: v.1 .1.to_string(),
727+
// Unnecessary spaces being added by fmt. We use #[rustfmt::skip] to avoid them for now.
728+
#[rustfmt::skip]
729+
fingerprint: v.1.0.to_string(),
730+
#[rustfmt::skip]
731+
path: Arc::new(v.1.1.clone().into()),
727732
},
728733
};
729734
(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)