Skip to content

Conversation

@rustaceanrob
Copy link
Contributor

Description

I would imagine many users would be handling a Address<NetworkChecked> when building a transaction. They may pass this structure directly with this patch, or continue to use ScriptBuf.

Notes to the reviewers

To my knowledge this is non-breaking, but it is a change in the function signature so I am not sure.

Changelog notice

Accept any type that is convertible to a ScriptBuf in TxBuilder::add_recipient

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@ValuedMammal
Copy link
Collaborator

Concept ACK, I guess the same could be done for set_recipients?

@rustaceanrob
Copy link
Contributor Author

That change would require a Box for the dyn Into trait. I am not necessarily opposed to that, but that does feel a little bit strange. I don't think it's the end of the world if this doesn't get in.

For 2.0.0, I would consider adding a Recipient type with the script and amount, and having useful constructors on it that use the impl Into syntax

Copy link
Collaborator

@ValuedMammal ValuedMammal left a comment

Choose a reason for hiding this comment

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

ACK 3bb94e4

@ValuedMammal ValuedMammal modified the milestones: 2.0.0, 1.2.0 Feb 19, 2025
@evanlinjin
Copy link
Member

That change would require a Box for the dyn Into trait. I am not necessarily opposed to that, but that does feel a little bit strange. I don't think it's the end of the world if this doesn't get in.

Why would that change require a Box?

    pub fn set_recipients(
        &mut self,
        recipients: impl IntoIterator<Item = (impl Into<ScriptBuf>, Amount)>,
    ) -> &mut Self {
        self.params.recipients = recipients
            .into_iter()
            .map(|(spk, amount)| (spk.into(), amount))
            .collect();
        self
    }

The only problem with this is that it will be a breaking change because the compiler needs to know the explicit type of recipients. I.e. tx_builder.set_recipients(Vec::new()) will no longer work because of missing annotations.

Copy link
Member

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

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

ACK 3bb94e4

@rustaceanrob
Copy link
Contributor Author

Why would that change require a Box?

I was thinking dynamic dispatch would be required, but it is cool to see that is not the case. Good catch on the potentially missing annotations in set_recipients if the change were to be applied. Cheers

Copy link
Contributor

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

utACK 3bb94e4

Copy link
Collaborator

@ValuedMammal ValuedMammal left a comment

Choose a reason for hiding this comment

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

reACK de2c44f

@ValuedMammal ValuedMammal merged commit 89bd47b into bitcoindevkit:master Mar 10, 2025
22 checks passed
@github-project-automation github-project-automation bot moved this from Needs Review to Done in BDK Wallet Mar 10, 2025
@rustaceanrob rustaceanrob deleted the tx-builder-2-16 branch March 10, 2025 16:38
@ValuedMammal ValuedMammal mentioned this pull request Apr 3, 2025
41 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants