Skip to content

Simplify public_descriptor by using get_descriptor and remove redundant API function. #1501

@KnowWhoami

Description

@KnowWhoami

Describe the enhancement

  • The public_descriptor function returns a reference to an ExtendedDescriptor, similar to get_descriptor on KeychainTxOutIndex, which returns an Option<Descriptor<DescriptorPublicKey>>

pub fn public_descriptor(&self, keychain: KeychainKind) -> &ExtendedDescriptor {

pub fn get_descriptor(&self, keychain: &K) -> Option<&Descriptor<DescriptorPublicKey>> {

Currently, public_descriptor finds the descriptor from scratch. Instead, it can directly call get_descriptor to simplify its implementation.

     pub fn public_descriptor(..) -> &ExtendedDescriptor {
     match self.indexed_graph.index.get_descriptor {
        // implementation
      }
     }
  • Additionally, the get_descriptor_for_keychain function is essentially a wrapper around public_descriptor:

pub fn get_descriptor_for_keychain(&self, keychain: KeychainKind) -> &ExtendedDescriptor {
.

Both functions logically serve the same purpose:

public_descriptor: Returns the public version of the descriptor.
get_descriptor_for_keychain: Returns the descriptor used to create addresses for a specific keychain

Therefore, we can eliminate get_descriptor_for_keychain and include its documentation in public_descriptor.
This change will reduce redundancy in Wallet API's.

Use case

  • Reduce redundancy in the API.
  • Simplify the implementation of public_descriptor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions