From 34a2fa2ca7c749f57da82a446d5ba4b60854c04a Mon Sep 17 00:00:00 2001 From: DanGould Date: Wed, 16 Oct 2024 14:59:37 -0400 Subject: [PATCH] Prune lib.rs --- src/lib.rs | 27 +++------------------------ src/receive/v2.rs | 5 +++-- src/request.rs | 23 +++++++++++++++++++++++ src/send/v1.rs | 2 +- tests/bdk_integration_test.rs | 6 ++++-- tests/bitcoin_core_integration.rs | 2 +- 6 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 81405e6..e81b95f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, - ///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, -} - -impl From for Request { - fn from(value: payjoin::Request) -> Self { - Self { url: Arc::new(value.url.into()), body: value.body } - } -} diff --git a/src/receive/v2.rs b/src/receive/v2.rs index 156299f..48e4ec5 100644 --- a/src/receive/v2.rs +++ b/src/receive/v2.rs @@ -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>); diff --git a/src/request.rs b/src/request.rs index e69de29..26f6b38 100644 --- a/src/request.rs +++ b/src/request.rs @@ -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, + ///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, +} + +impl From for Request { + fn from(value: payjoin::Request) -> Self { + Self { url: Arc::new(value.url.into()), body: value.body } + } +} diff --git a/src/send/v1.rs b/src/send/v1.rs index e625e77..00490e7 100644 --- a/src/send/v1.rs +++ b/src/send/v1.rs @@ -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 /// diff --git a/tests/bdk_integration_test.rs b/tests/bdk_integration_test.rs index d56edf4..39e002c 100644 --- a/tests/bdk_integration_test.rs +++ b/tests/bdk_integration_test.rs @@ -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 @@ -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; diff --git a/tests/bitcoin_core_integration.rs b/tests/bitcoin_core_integration.rs index a214557..bde0cca 100644 --- a/tests/bitcoin_core_integration.rs +++ b/tests/bitcoin_core_integration.rs @@ -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};