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

Better names for types #665

Closed
evanlinjin opened this issue Jul 11, 2022 · 5 comments
Closed

Better names for types #665

evanlinjin opened this issue Jul 11, 2022 · 5 comments
Assignees
Labels
api A breaking API change discussion There's still a discussion ongoing module-wallet
Milestone

Comments

@evanlinjin
Copy link
Member

evanlinjin commented Jul 11, 2022

Description

After going through the codebase of the wallet module, I felt like we could do with some improvements in naming. I will list some suggestions below.

ChangeSpendPolicy -> InternalSpendPolicy

/// Policy regarding the use of change outputs when creating a transaction
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy)]
pub enum ChangeSpendPolicy {
/// Use both change and non-change outputs (default)
ChangeAllowed,
/// Only use change outputs (see [`TxBuilder::only_spend_change`])
OnlyChange,
/// Only use non-change outputs (see [`TxBuilder::do_not_spend_change`])
ChangeForbidden,
}

Right now we do not keep track of which outputs are change/not-change in the database. We only differentiate based on whether the scriptPubKey is derived from the external descriptor or internal descriptor.

pub(crate) change_policy: ChangeSpendPolicy,

Similarly, this field should be called spend_internal_policy.

LocalUtxo::is_spent -> LocalUtxo::is_used

bdk/src/types.rs

Lines 134 to 135 in dd51380

/// Whether this UTXO is spent or not
pub is_spent: bool,

Considering that UTXO is an acronym for "Unspent Transaction Output", this naming is very confusing. "Spent" for me means that the transaction is already included in a mined block. By calling it is_used, we will know whether it has already been used as input during tx creation.

@evanlinjin evanlinjin added the bug Something isn't working label Jul 11, 2022
@notmandatory notmandatory added discussion There's still a discussion ongoing and removed bug Something isn't working labels Jul 12, 2022
@notmandatory
Copy link
Member

Thanks for writing this up! I re-tagged it for discussion since there's nothing broken you just want to discuss some naming improvements.

My two cents on the naming, your suggestions sound fine to me, but we need to be careful not to change names that break a public API unless there is compelling reason to do it. Don't forget some users maybe forced to change their code for only a small readability gain.

@danielabrozzoni
Copy link
Member

LocalUtxo::is_spent -> LocalUtxo::is_used
Considering that UTXO is an acronym for "Unspent Transaction Output", this naming is very confusing. "Spent" for me means that the transaction is already included in a mined block. By calling it is_used, we will know whether it has already been used as input during tx creation.

Mh, I don't really like is_used: saying that an "unspent tx output" is spent is for sure confusing, but some LocalUtxo in our database are effectively spent, not just "used" (we never delete LocalUtxos, even if they've been spent thousands of blocks ago -> see #573).
Instead, I think we should go for LocalUtxo -> LocalTxout/LocalTxOut/LocalTxo as @LLFourn / @afilini were discussing here

@notmandatory
Copy link
Member

This sounds like something to tackle as part of the 1.0.0 API changes.

@notmandatory notmandatory removed this from the 1.0.0-alpha.0 milestone Mar 3, 2023
@notmandatory notmandatory moved this to Todo in BDK Wallet Jan 2, 2024
@notmandatory notmandatory added module-wallet api A breaking API change labels Mar 17, 2024
@notmandatory notmandatory added this to the 1.0.0-alpha milestone Mar 17, 2024
@notmandatory
Copy link
Member

These look like small changes but I think we should move to the 2.0 milestone.

@notmandatory
Copy link
Member

Already fixed.

@github-project-automation github-project-automation bot moved this from Todo to Done in BDK Wallet Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api A breaking API change discussion There's still a discussion ongoing module-wallet
Projects
Archived in project
Development

No branches or pull requests

4 participants