Skip to content

Commit

Permalink
Release 0.21.1 after merge #39
Browse files Browse the repository at this point in the history
Expose de/serialize for Sender, Receiver

via to_json/from_json
  • Loading branch information
DanGould authored Dec 7, 2024
2 parents 5230f19 + 437bdac commit b2dc431
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [0.21.1]
- Add `to_json` and `from_json` methods to `Sender` and `Receiver` UniFFI types. ([#39](https://github.com/LtbLightning/payjoin-ffi/pull/39))

## [0.21.0]
This release updates the bindings libraries to `payjoin` version `0.21.0`.
#### APIs changed
Expand Down
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "payjoin_ffi"
version = "0.21.0"
version = "0.21.1"
edition = "2021"
license = "MIT OR Apache-2.0"
exclude = ["tests"]
Expand All @@ -26,6 +26,7 @@ bitcoin-ffi = { git = "https://github.com/bitcoindevkit/bitcoin-ffi.git", rev =
hex = "0.4.3"
ohttp = { package = "bitcoin-ohttp", version = "0.6.0" }
payjoin = { version = "0.21.0", features = ["send", "receive", "base64", "v2", "io"] }
serde_json = "1.0.128"
thiserror = "1.0.58"
uniffi = { version = "0.28.0", optional = true }
url = "2.5.0"
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ pub enum PayjoinError {

#[error("{message}")]
InputPairError { message: String },

#[error("{message}")]
SerdeJsonError { message: String },
}

macro_rules! impl_from_error {
Expand All @@ -99,6 +102,7 @@ impl_from_error! {
OutputSubstitutionError => OutputSubstitutionError,
InputContributionError => InputContributionError,
PsbtInputError => InputPairError,
serde_json::Error => SerdeJsonError,
}

#[cfg(feature = "uniffi")]
Expand Down
10 changes: 10 additions & 0 deletions src/receive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ impl Receiver {
pub fn id(&self) -> String {
<Self as Into<payjoin::receive::v2::Receiver>>::into(self.clone()).id().to_string()
}

pub fn to_json(&self) -> Result<String, PayjoinError> {
serde_json::to_string(&self.0).map_err(|e| e.into())
}

pub fn from_json(json: &str) -> Result<Self, PayjoinError> {
let receiver = serde_json::from_str::<payjoin::receive::v2::Receiver>(json)
.map_err(<serde_json::Error as Into<PayjoinError>>::into)?;
Ok(receiver.into())
}
}

#[derive(Clone)]
Expand Down
9 changes: 9 additions & 0 deletions src/receive/uni.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ impl Receiver {
pub fn id(&self) -> String {
self.0.id()
}

pub fn to_json(&self) -> Result<String, PayjoinError> {
self.0.to_json()
}

#[uniffi::constructor]
pub fn from_json(json: &str) -> Result<Self, PayjoinError> {
super::Receiver::from_json(json).map(Into::into)
}
}

#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
Expand Down
10 changes: 10 additions & 0 deletions src/send/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ impl Sender {
Err(e) => Err(e.into()),
}
}

pub fn to_json(&self) -> Result<String, PayjoinError> {
serde_json::to_string(&self.0).map_err(|e| e.into())
}

pub fn from_json(json: &str) -> Result<Self, PayjoinError> {
let sender = serde_json::from_str::<payjoin::send::Sender>(json)
.map_err(<serde_json::Error as Into<PayjoinError>>::into)?;
Ok(sender.into())
}
}

/// Data required for validation of response.
Expand Down
9 changes: 9 additions & 0 deletions src/send/uni.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ impl Sender {
Err(e) => Err(e),
}
}

pub fn to_json(&self) -> Result<String, PayjoinError> {
self.0.to_json()
}

#[uniffi::constructor]
pub fn from_json(json: &str) -> Result<Self, PayjoinError> {
super::Sender::from_json(json).map(Into::into)
}
}

#[derive(uniffi::Object)]
Expand Down

0 comments on commit b2dc431

Please sign in to comment.