Skip to content
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

descriptors: add a method to get a PSBT's change outputs #922

Merged
merged 2 commits into from
Jan 24, 2024

Conversation

darosior
Copy link
Member

Fixes #857.

@darosior darosior force-pushed the 2401_change_indexes branch 3 times, most recently from fdb75ad to f71fa97 Compare January 16, 2024 09:39
@darosior darosior marked this pull request as ready for review January 16, 2024 09:41
@darosior darosior force-pushed the 2401_change_indexes branch from f71fa97 to c86e6b6 Compare January 16, 2024 09:41
@darosior darosior changed the title WIP: descriptors: add a method to get a PSBT's change outputs descriptors: add a method to get a PSBT's change outputs Jan 16, 2024
@darosior darosior requested a review from edouardparis January 16, 2024 09:41
Copy link
Member

@edouardparis edouardparis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK c86e6b6

nits:
Maybe would be nice to have a pub fn index(&self) -> usize method for ChangeOutput.
Maybe change index for vout because it can be confused with derivation index.

@darosior darosior force-pushed the 2401_change_indexes branch from c86e6b6 to 3929926 Compare January 24, 2024 10:26
@darosior
Copy link
Member Author

Maybe would be nice to have a pub fn index(&self) -> usize method for ChangeOutput.

Done:

diff --git a/src/descriptors/mod.rs b/src/descriptors/mod.rs
index b04dc7f..cc88645 100644
--- a/src/descriptors/mod.rs
+++ b/src/descriptors/mod.rs
@@ -124,6 +124,17 @@ pub enum ChangeOutput {
     DepositAddress { index: usize },
 }
 
+impl ChangeOutput {
+    /// Get the index of the change output in the transaction's list of outputs regardless of its
+    /// type.
+    pub fn index(&self) -> usize {
+        match self {
+            Self::ChangeAddress { index } => *index,
+            Self::DepositAddress { index } => *index,
+        }
+    }
+}
+
 impl LianaDescriptor {
     pub fn new(spending_policy: LianaPolicy) -> LianaDescriptor {
         // Get the descriptor from the chosen spending policy.

Maybe change index for vout because it can be confused with derivation index.

I think vout is equally confusing if not more. It's just a peculiar heritage of Satoshi's usage of hungarian notation in C++ (Vout stands for Vector of outputs).

@darosior
Copy link
Member Author

ACK 3929926 -- re-applying Edouard's ACK. Only change is the addition of an index() method on the ChangeOutput enum.

@darosior darosior merged commit 3aa9550 into wizardsardine:master Jan 24, 2024
18 checks passed
@darosior darosior deleted the 2401_change_indexes branch January 24, 2024 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

liana SDK: add a method to the descriptor to list the change outputs of a given PSBT
2 participants