Skip to content

Commit

Permalink
Get working bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
DanGould committed Nov 6, 2024
1 parent 79cc692 commit 5d83263
Show file tree
Hide file tree
Showing 15 changed files with 551 additions and 710 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bdk = { version = "0.29.0", features = ["all-keys", "use-esplora-ureq", "keys-bi
bitcoind = { version = "0.36.0", features = ["0_21_2"] }
bitcoincore-rpc = "0.19.0"
http = "1"
payjoin-directory = { git = "https://github.com/payjoin/rust-payjoin", features = ["danger-local-https"] }
payjoin-directory = { path = "../payjoin/payjoin-directory", features = ["danger-local-https"] }
ohttp-relay = "0.0.8"
rcgen = { version = "0.11" }
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"] }
Expand All @@ -28,7 +28,7 @@ testcontainers-modules = { version = "0.1.3", features = ["redis"] }
tokio = { version = "1.12.0", features = ["full"] }
[dependencies]

payjoin = { git = "https://github.com/payjoin/rust-payjoin", features = ["send", "receive", "base64", "v2", "io"] }
payjoin = { path = "../payjoin/payjoin", features = ["send", "receive", "base64", "v2", "io"] }
uniffi = { version = "0.28.0" }
thiserror = "1.0.47"
ohttp = { package = "bitcoin-ohttp", version = "0.6.0" }
Expand Down
9 changes: 9 additions & 0 deletions src/bitcoin.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::str::FromStr;
use std::sync::Arc;

use payjoin::bitcoin;

/// A reference to a transaction output.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct OutPoint {
/// The referenced transaction's txid.
pub txid: String,
Expand All @@ -27,6 +29,7 @@ impl From<bitcoin::OutPoint> for OutPoint {
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct PsbtInput {
pub witness_utxo: Option<TxOut>,
pub redeem_script: Option<Arc<Script>>,
Expand Down Expand Up @@ -65,6 +68,7 @@ impl From<PsbtInput> for bitcoin::psbt::Input {
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct TxIn {
pub previous_output: OutPoint,
}
Expand All @@ -82,6 +86,7 @@ impl From<bitcoin::TxIn> for TxIn {
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct TxOut {
/// The value of the output, in satoshis.
pub value: u64,
Expand All @@ -105,6 +110,7 @@ impl From<bitcoin::TxOut> for TxOut {
}

#[derive(Clone, Default)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
pub enum Network {
///Bitcoin’s testnet
Testnet,
Expand All @@ -129,9 +135,12 @@ impl From<Network> for bitcoin::Network {
}

#[derive(Clone, Debug)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Object))]
pub struct Script(pub payjoin::bitcoin::ScriptBuf);

#[cfg_attr(feature = "uniffi", uniffi::export)]
impl Script {
#[cfg_attr(feature = "uniffi", uniffi::constructor)]
pub fn new(script: Vec<u8>) -> Self {
Self(payjoin::bitcoin::ScriptBuf::from_bytes(script))
}
Expand Down
9 changes: 4 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ pub mod send;
pub mod uri;

pub use crate::bitcoin::*;
pub use crate::receive::*;
pub use crate::send::v1::*;
pub use crate::send::v2::*;
pub use crate::send::Context;
use crate::error::PayjoinError;
pub use crate::ohttp::*;
pub use crate::receive::*;
pub use crate::request::Request;
pub use crate::send::v1::*;
pub use crate::send::v2::*;
pub use crate::uri::{PjUri, PjUriBuilder, Uri, Url};

#[cfg(feature = "uniffi")]
uniffi::include_scaffolding!("payjoin_ffi");
uniffi::setup_scaffolding!();
5 changes: 5 additions & 0 deletions src/ohttp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ impl From<OhttpKeys> for payjoin::OhttpKeys {
value.0
}
}
#[cfg_attr(feature = "uniffi", derive(uniffi::Object))]
#[derive(Debug, Clone)]
pub struct OhttpKeys(pub payjoin::OhttpKeys);

#[cfg_attr(feature = "uniffi", uniffi::export)]
impl OhttpKeys {
/// Decode an OHTTP KeyConfig
#[cfg_attr(feature = "uniffi", uniffi::constructor)]
pub fn decode(bytes: Vec<u8>) -> Result<Self, PayjoinError> {
payjoin::OhttpKeys::decode(bytes.as_slice()).map(|e| e.into()).map_err(|e| e.into())
}
}

use std::sync::Mutex;

#[cfg_attr(feature = "uniffi", derive(uniffi::Object))]
pub struct ClientResponse(Mutex<Option<ohttp::ClientResponse>>);

impl From<&ClientResponse> for ohttp::ClientResponse {
Expand Down
Loading

0 comments on commit 5d83263

Please sign in to comment.