Skip to content

Commit

Permalink
Prune lib.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
DanGould committed Oct 16, 2024
1 parent 23f863a commit 34a2fa2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 30 deletions.
27 changes: 3 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,15 @@ pub mod error;
pub mod io;
pub mod ohttp;
pub mod receive;
pub mod request;
pub mod send;
pub mod uri;

pub use crate::bitcoin::*;
use crate::error::PayjoinError;
#[cfg(feature = "uniffi")]
pub use crate::receive::*;
pub use crate::send::*;
pub use crate::ohttp::OhttpKeys;
pub use crate::request::Request;
pub use crate::uri::{PjUri, PjUriBuilder, Uri, Url};

#[cfg(feature = "uniffi")]
uniffi::include_scaffolding!("payjoin_ffi");

use std::sync::Arc;
///Represents data that needs to be transmitted to the receiver.
///You need to send this request over HTTP(S) to the receiver.
#[derive(Clone, Debug)]
pub struct Request {
///URL to send the request to.
///
///This is full URL with scheme etc - you can pass it right to reqwest or a similar library.
pub url: Arc<Url>,
///Bytes to be sent to the receiver.
///
///This is properly encoded PSBT, already in base64. You only need to make sure Content-Type is text/plain and Content-Length is body.len() (most libraries do the latter automatically).
pub body: Vec<u8>,
}

impl From<payjoin::Request> for Request {
fn from(value: payjoin::Request) -> Self {
Self { url: Arc::new(value.url.into()), body: value.body }
}
}
5 changes: 3 additions & 2 deletions src/receive/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ use crate::ohttp::OhttpKeys;
use crate::receive::v1::{
CanBroadcast, GenerateScript, IsOutputKnown, IsScriptOwned, ProcessPartiallySignedTransaction,
};
use crate::uri::PjUriBuilder;
use crate::{OutPoint, PayjoinError, Request, TxOut, Url};
use crate::request::Request;
use crate::uri::{PjUriBuilder, Url};
use crate::{OutPoint, PayjoinError, TxOut};

pub struct ClientResponse(Mutex<Option<ohttp::ClientResponse>>);

Expand Down
23 changes: 23 additions & 0 deletions src/request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::sync::Arc;

use crate::uri::Url;

///Represents data that needs to be transmitted to the receiver.
///You need to send this request over HTTP(S) to the receiver.
#[derive(Clone, Debug)]
pub struct Request {
///URL to send the request to.
///
///This is full URL with scheme etc - you can pass it right to reqwest or a similar library.
pub url: Arc<Url>,
///Bytes to be sent to the receiver.
///
///This is properly encoded PSBT, already in base64. You only need to make sure Content-Type is text/plain and Content-Length is body.len() (most libraries do the latter automatically).
pub body: Vec<u8>,
}

impl From<payjoin::Request> for Request {
fn from(value: payjoin::Request) -> Self {
Self { url: Arc::new(value.url.into()), body: value.body }
}
}
2 changes: 1 addition & 1 deletion src/send/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::sync::Arc;
pub use payjoin::send as pdk;

use crate::error::PayjoinError;
use crate::request::Request;
use crate::send::v2::ContextV2;
use crate::uri::{PjUri, Url};
use crate::Request;

///Builder for sender-side payjoin parameters
///
Expand Down
6 changes: 4 additions & 2 deletions tests/bdk_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ use bdk::database::MemoryDatabase;
use bdk::wallet::AddressIndex;
use bdk::{FeeRate, LocalUtxo, SignOptions, Wallet as BdkWallet};
use bitcoincore_rpc::{Auth, Client, RpcApi};
use payjoin_ffi::bitcoin::{OutPoint, TxOut};
use payjoin_ffi::error::PayjoinError;
use payjoin_ffi::receive::v1::{Headers, PayjoinProposal, UncheckedProposal};
use payjoin_ffi::types::{OutPoint, Request, TxOut};
use payjoin_ffi::uri::{PjUri, Uri};
use payjoin_ffi::Request;
use uniffi::deps::log::debug;

// Set up RPC connections
Expand Down Expand Up @@ -380,13 +381,14 @@ mod v2 {
use bdk::bitcoin::{Address, Script};
use bdk::wallet::AddressIndex;
use http::StatusCode;
use payjoin_ffi::bitcoin::{Network, OutPoint, TxOut};
use payjoin_ffi::error::PayjoinError;
use payjoin_ffi::receive::v2::{
ActiveSession, SessionInitializer, V2PayjoinProposal, V2UncheckedProposal,
};
use payjoin_ffi::send::v1::RequestBuilder;
use payjoin_ffi::types::{Network, OhttpKeys, OutPoint, TxOut};
use payjoin_ffi::uri::{Uri, Url};
use payjoin_ffi::OhttpKeys;
use reqwest::{Client, ClientBuilder};
use testcontainers::clients::Cli;
use testcontainers_modules::redis::Redis;
Expand Down
2 changes: 1 addition & 1 deletion tests/bitcoin_core_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::Arc;

use bitcoincore_rpc::bitcoincore_rpc_json::WalletProcessPsbtResult;
use bitcoincore_rpc::{Auth, Client, RpcApi};
use payjoin_ffi::bitcoin::{OutPoint, Request, TxOut};
use payjoin_ffi::bitcoin::{OutPoint, TxOut};
use payjoin_ffi::receive::v1::{Headers, PayjoinProposal, UncheckedProposal};
use payjoin_ffi::send::v1::RequestBuilder;
use payjoin_ffi::uri::{PjUriBuilder, Uri, Url};
Expand Down

0 comments on commit 34a2fa2

Please sign in to comment.