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

Make Address Clone #30

Merged
merged 1 commit into from
Dec 31, 2024
Merged

Make Address Clone #30

merged 1 commit into from
Dec 31, 2024

Conversation

DanGould
Copy link
Contributor

@DanGould DanGould commented Dec 2, 2024

The lack of this derive seems to be an oversight.

Having this clone makes it more ergonomic to use Address as a dependency binding downstream

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 a298c61

Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

LGTM

Seems simple enough and indeed like an oversight.

That said, @DanGould I'm not fully sure I understand why you need this in the Payjoin FFI API. Out of interest, mind pointing me towards an example that requires it?

@tnull tnull merged commit 08478a3 into bitcoindevkit:master Dec 31, 2024
7 checks passed
@DanGould
Copy link
Contributor Author

I want to require an Arc<bitcoin_ffi::Address> parameter to a UniFFI function which ultimately passes bitcoin_ffi::Address out of the arc to a general FFI function used for both flutter bindings and uniffi, but to get bitcoin_ffi::Address from Arc::unwrap_or_clone bitcoin_ffi::Address needs to be Clone:

impl Receiver {
    /// Creates a new `SessionInitializer` with the provided parameters.
    ///
    /// # Parameters
    /// - `address`: The Bitcoin address for the payjoin session.
    /// - `network`: The network to use for address verification.
    /// - `directory`: The URL of the store-and-forward payjoin directory.
    /// - `ohttp_keys`: The OHTTP keys used for encrypting and decrypting HTTP requests and responses.
    /// - `ohttp_relay`: The URL of the OHTTP relay, used to keep client IP address confidential.
    /// - `expire_after`: The duration in seconds after which the session expires.
    ///
    /// # Returns
    /// A new instance of `SessionInitializer`.
    ///
    /// # References
    /// - [BIP 77: Payjoin Version 2: Serverless Payjoin](https://github.com/bitcoin/bips/pull/1483)
    #[uniffi::constructor]
    pub fn new(
        address: Arc<Address>,
        directory: Arc<Url>,
        ohttp_keys: Arc<OhttpKeys>,
        ohttp_relay: Arc<Url>,
        expire_after: Option<u64>,
    ) -> Result<Self, PayjoinError> {
        // TODO Arc::try_unwrap(address).unwrap_or_else(|arc| (*arc).clone()) once bitcoin-ffi makes Address Clone
        super::Receiver::new(
            Arc::try_unwrap(address).unwrap_or_else(|arc| (*arc).clone()),
            (*directory).clone(),
            (*ohttp_keys).clone(),
            (*ohttp_relay).clone(),
            expire_after,
        )
        .map(Into::into)
    }
// ...
}

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.

3 participants