@@ -18,6 +18,25 @@ use bitcoin::{psbt, Weight};
1818
1919use serde:: { Deserialize , Serialize } ;
2020
21+ /// Trait that determines if a keychain variant is trusted.
22+ pub trait WalletKeychain {
23+ const DEFAULT_CHANGE_VARIANT : Self ;
24+
25+ /// Returns whether the keychain variant is trusted.
26+ fn is_trusted_variant ( & self ) -> bool ;
27+ }
28+
29+ impl WalletKeychain for KeychainKind {
30+ const DEFAULT_CHANGE_VARIANT : Self = KeychainKind :: Internal ;
31+
32+ fn is_trusted_variant ( & self ) -> bool {
33+ match self {
34+ KeychainKind :: External => false ,
35+ KeychainKind :: Internal => true ,
36+ }
37+ }
38+ }
39+
2140/// Types of keychains
2241#[ derive( Serialize , Deserialize , Debug , Clone , Copy , PartialEq , Eq , Hash , Ord , PartialOrd ) ]
2342pub enum KeychainKind {
@@ -50,13 +69,13 @@ impl AsRef<[u8]> for KeychainKind {
5069///
5170/// [`Wallet`]: crate::Wallet
5271#[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Eq , Hash ) ]
53- pub struct LocalOutput {
72+ pub struct LocalOutput < K > {
5473 /// Reference to a transaction output
5574 pub outpoint : OutPoint ,
5675 /// Transaction output
5776 pub txout : TxOut ,
5877 /// Type of keychain
59- pub keychain : KeychainKind ,
78+ pub keychain : K ,
6079 /// Whether this UTXO is spent or not
6180 pub is_spent : bool ,
6281 /// The derivation index for the script pubkey in the wallet
@@ -67,21 +86,21 @@ pub struct LocalOutput {
6786
6887/// A [`Utxo`] with its `satisfaction_weight`.
6988#[ derive( Debug , Clone , PartialEq , Eq ) ]
70- pub struct WeightedUtxo {
89+ pub struct WeightedUtxo < K > {
7190 /// The weight of the witness data and `scriptSig` expressed in [weight units]. This is used to
7291 /// properly maintain the feerate when adding this input to a transaction during coin selection.
7392 ///
7493 /// [weight units]: https://en.bitcoin.it/wiki/Weight_units
7594 pub satisfaction_weight : Weight ,
7695 /// The UTXO
77- pub utxo : Utxo ,
96+ pub utxo : Utxo < K > ,
7897}
7998
8099#[ derive( Debug , Clone , PartialEq , Eq ) ]
81100/// An unspent transaction output (UTXO).
82- pub enum Utxo {
101+ pub enum Utxo < K > {
83102 /// A UTXO owned by the local wallet.
84- Local ( LocalOutput ) ,
103+ Local ( LocalOutput < K > ) ,
85104 /// A UTXO owned by another wallet.
86105 Foreign {
87106 /// The location of the output.
@@ -94,7 +113,7 @@ pub enum Utxo {
94113 } ,
95114}
96115
97- impl Utxo {
116+ impl < K > Utxo < K > {
98117 /// Get the location of the UTXO
99118 pub fn outpoint ( & self ) -> OutPoint {
100119 match & self {
0 commit comments