forked from LtbLightning/payjoin-ffi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replicate rust-payjoin directory structure
Add bitcoin, ohttp, request modules. Remove types module.
- Loading branch information
Showing
11 changed files
with
128 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use std::str::FromStr; | ||
|
||
use payjoin::bitcoin; | ||
|
||
/// A reference to a transaction output. | ||
#[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||
pub struct OutPoint { | ||
/// The referenced transaction's txid. | ||
pub txid: String, | ||
/// The index of the referenced output in its transaction's vout. | ||
pub vout: u32, | ||
} | ||
|
||
impl From<OutPoint> for bitcoin::OutPoint { | ||
fn from(outpoint: OutPoint) -> Self { | ||
bitcoin::OutPoint { | ||
txid: bitcoin::Txid::from_str(&outpoint.txid).expect("Invalid txid"), | ||
vout: outpoint.vout, | ||
} | ||
} | ||
} | ||
|
||
impl From<bitcoin::OutPoint> for OutPoint { | ||
fn from(outpoint: bitcoin::OutPoint) -> Self { | ||
OutPoint { txid: outpoint.txid.to_string(), vout: outpoint.vout } | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct TxOut { | ||
/// The value of the output, in satoshis. | ||
pub value: u64, | ||
/// The address of the output. | ||
pub script_pubkey: Vec<u8>, | ||
} | ||
|
||
impl From<TxOut> for bitcoin::TxOut { | ||
fn from(tx_out: TxOut) -> Self { | ||
bitcoin::TxOut { | ||
value: bitcoin::amount::Amount::from_sat(tx_out.value), | ||
script_pubkey: bitcoin::ScriptBuf::from_bytes(tx_out.script_pubkey), | ||
} | ||
} | ||
} | ||
|
||
impl From<bitcoin::TxOut> for TxOut { | ||
fn from(tx_out: bitcoin::TxOut) -> Self { | ||
TxOut { value: tx_out.value.to_sat(), script_pubkey: tx_out.script_pubkey.to_bytes() } | ||
} | ||
} | ||
|
||
#[derive(Clone, Default)] | ||
pub enum Network { | ||
///Bitcoin’s testnet | ||
Testnet, | ||
///Bitcoin’s regtest | ||
Regtest, | ||
#[default] | ||
///Classic Bitcoin | ||
Bitcoin, | ||
///Bitcoin’s signet | ||
Signet, | ||
} | ||
|
||
impl From<Network> for bitcoin::Network { | ||
fn from(network: Network) -> Self { | ||
match network { | ||
Network::Signet => bitcoin::Network::Signet, | ||
Network::Testnet => bitcoin::Network::Testnet, | ||
Network::Regtest => bitcoin::Network::Regtest, | ||
Network::Bitcoin => bitcoin::Network::Bitcoin, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,42 @@ | ||
#![crate_name = "payjoin_ffi"] | ||
|
||
pub mod bitcoin; | ||
pub mod error; | ||
pub mod io; | ||
pub mod ohttp; | ||
pub mod receive; | ||
pub mod send; | ||
pub mod types; | ||
pub mod uri; | ||
|
||
pub use crate::bitcoin::*; | ||
use crate::error::PayjoinError; | ||
pub use crate::ohttp::*; | ||
pub use crate::receive::v1::*; | ||
pub use crate::receive::v2::*; | ||
pub use crate::send::v1::*; | ||
pub use crate::send::v2::*; | ||
pub use crate::types::*; | ||
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 } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use crate::error::PayjoinError; | ||
|
||
impl From<payjoin::OhttpKeys> for OhttpKeys { | ||
fn from(value: payjoin::OhttpKeys) -> Self { | ||
Self(value) | ||
} | ||
} | ||
impl From<OhttpKeys> for payjoin::OhttpKeys { | ||
fn from(value: OhttpKeys) -> Self { | ||
value.0 | ||
} | ||
} | ||
#[derive(Debug, Clone)] | ||
pub struct OhttpKeys(pub payjoin::OhttpKeys); | ||
impl OhttpKeys { | ||
/// Decode an OHTTP KeyConfig | ||
pub fn decode(bytes: Vec<u8>) -> Result<Self, PayjoinError> { | ||
payjoin::OhttpKeys::decode(bytes.as_slice()).map(|e| e.into()).map_err(|e| e.into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters