Skip to content

Commit

Permalink
Expose Sender::extract_v2 for bindings
Browse files Browse the repository at this point in the history
The send::Context typestate enum is not simple to bind to in UniFFI and
would require abstracting distinct extract_v1 extract_v2 functions in order
to cross the FFI boundary. Exposing this method is a simple fix to make such
abstraction unnecessary.
  • Loading branch information
DanGould committed Nov 6, 2024
1 parent e7c290f commit 1970a59
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions payjoin/src/send/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ impl Sender {
}

match self.extract_rs_pubkey() {
Ok(rs) => self.extract_v2(ohttp_relay, rs),
Ok(_rs) => {
let (req, context_v2) = self.extract_v2(ohttp_relay)?;
Ok((req, Context::V2(context_v2)))
}
Err(e) => {
log::warn!("Failed to extract `rs` pubkey, falling back to v1: {}", e);
let (req, context_v1) = self.extract_v1()?;
Expand All @@ -302,12 +305,12 @@ impl Sender {
/// This method requires the `rs` pubkey to be extracted from the endpoint
/// and has no fallback to v1.
#[cfg(feature = "v2")]
fn extract_v2(
&mut self,
pub fn extract_v2(
&self,
ohttp_relay: Url,
rs: HpkePublicKey,
) -> Result<(Request, Context), CreateRequestError> {
) -> Result<(Request, V2PostContext), CreateRequestError> {
use crate::uri::UrlExt;
let rs = self.extract_rs_pubkey()?;
let url = self.endpoint.clone();
let body = serialize_v2_body(
&self.psbt,
Expand All @@ -329,7 +332,7 @@ impl Sender {
log::debug!("ohttp_relay_url: {:?}", ohttp_relay);
Ok((
Request::new_v2(ohttp_relay, body),
Context::V2(V2PostContext {
V2PostContext {
endpoint: self.endpoint.clone(),
psbt_ctx: PsbtContext {
original_psbt: self.psbt.clone(),
Expand All @@ -341,7 +344,7 @@ impl Sender {
},
hpke_ctx,
ohttp_ctx,
}),
},
))
}

Expand Down

0 comments on commit 1970a59

Please sign in to comment.