Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions bdk-ffi/src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use std::ops::Deref;
use std::str::FromStr;
use std::sync::{Arc, Mutex};

pub(crate) type DescriptorType = bdk_wallet::miniscript::descriptor::DescriptorType;
pub type DescriptorType = bdk_wallet::miniscript::descriptor::DescriptorType;
pub type Network = bdk_wallet::bitcoin::Network;

/// A reference to an unspent output by TXID and output index.
Expand Down Expand Up @@ -121,7 +121,7 @@ impl HashableOutPoint {
/// This is an integer type representing fee rate in sat/kwu. It provides protection against mixing
/// up the types as well as basic formatting features.
#[derive(Clone, Debug, uniffi::Object)]
pub struct FeeRate(pub BdkFeeRate);
pub struct FeeRate(pub(crate) BdkFeeRate);

#[uniffi::export]
impl FeeRate {
Expand Down Expand Up @@ -160,7 +160,7 @@ impl_into_core_type!(FeeRate, BdkFeeRate);
/// underflow occurs. Also note that since the internal representation of amounts is unsigned,
/// subtracting below zero is considered an underflow and will cause a panic.
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Object)]
pub struct Amount(pub BdkAmount);
pub struct Amount(pub(crate) BdkAmount);

#[uniffi::export]
impl Amount {
Expand Down Expand Up @@ -195,7 +195,7 @@ impl_into_core_type!(Amount, BdkAmount);
/// A bitcoin script: https://en.bitcoin.it/wiki/Script
#[derive(Clone, Debug, uniffi::Object)]
#[uniffi::export(Display)]
pub struct Script(pub BdkScriptBuf);
pub struct Script(pub(crate) BdkScriptBuf);

#[uniffi::export]
impl Script {
Expand Down Expand Up @@ -508,7 +508,7 @@ pub struct Psbt(pub(crate) Mutex<BdkPsbt>);
impl Psbt {
/// Creates a new `Psbt` instance from a base64-encoded string.
#[uniffi::constructor]
pub(crate) fn new(psbt_base64: String) -> Result<Self, PsbtParseError> {
pub fn new(psbt_base64: String) -> Result<Self, PsbtParseError> {
let psbt: BdkPsbt = BdkPsbt::from_str(&psbt_base64)?;
Ok(Psbt(Mutex::new(psbt)))
}
Expand All @@ -519,22 +519,22 @@ impl Psbt {
///
/// If transactions is not unsigned.
#[uniffi::constructor]
pub(crate) fn from_unsigned_tx(tx: Arc<Transaction>) -> Result<Arc<Psbt>, PsbtError> {
pub fn from_unsigned_tx(tx: Arc<Transaction>) -> Result<Arc<Psbt>, PsbtError> {
let psbt: BdkPsbt = BdkPsbt::from_unsigned_tx(tx.0.clone())?;
Ok(Arc::new(Psbt(Mutex::new(psbt))))
}

/// Create a new `Psbt` from a `.psbt` file.
#[uniffi::constructor]
pub(crate) fn from_file(path: String) -> Result<Self, PsbtError> {
pub fn from_file(path: String) -> Result<Self, PsbtError> {
let file = File::open(path)?;
let mut buf_read = BufReader::new(file);
let psbt: BdkPsbt = BdkPsbt::deserialize_from_reader(&mut buf_read)?;
Ok(Psbt(Mutex::new(psbt)))
}

/// Serialize the PSBT into a base64-encoded string.
pub(crate) fn serialize(&self) -> String {
pub fn serialize(&self) -> String {
let psbt = self.0.lock().unwrap().clone();
psbt.to_string()
}
Expand All @@ -546,7 +546,7 @@ impl Psbt {
/// `ExtractTxError` variants will contain either the `Psbt` itself or the `Transaction`
/// that was extracted. These can be extracted from the Errors in order to recover.
/// See the error documentation for info on the variants. In general, it covers large fees.
pub(crate) fn extract_tx(&self) -> Result<Arc<Transaction>, ExtractTxError> {
pub fn extract_tx(&self) -> Result<Arc<Transaction>, ExtractTxError> {
let tx: BdkTransaction = self.0.lock().unwrap().clone().extract_tx()?;
let transaction: Transaction = tx.into();
Ok(Arc::new(transaction))
Expand All @@ -562,7 +562,7 @@ impl Psbt {
/// - `MissingUtxo` when UTXO information for any input is not present or is invalid.
/// - `NegativeFee` if calculated value is negative.
/// - `FeeOverflow` if an integer overflow occurs.
pub(crate) fn fee(&self) -> Result<u64, PsbtError> {
pub fn fee(&self) -> Result<u64, PsbtError> {
self.0
.lock()
.unwrap()
Expand All @@ -574,7 +574,7 @@ impl Psbt {
/// Combines this `Psbt` with `other` PSBT as described by BIP 174.
///
/// In accordance with BIP 174 this function is commutative i.e., `A.combine(B) == B.combine(A)`
pub(crate) fn combine(&self, other: Arc<Psbt>) -> Result<Arc<Psbt>, PsbtError> {
pub fn combine(&self, other: Arc<Psbt>) -> Result<Arc<Psbt>, PsbtError> {
let mut original_psbt = self.0.lock().unwrap().clone();
let other_psbt = other.0.lock().unwrap().clone();
original_psbt.combine(other_psbt)?;
Expand All @@ -584,7 +584,7 @@ impl Psbt {
/// Finalizes the current PSBT and produces a result indicating
///
/// whether the finalization was successful or not.
pub(crate) fn finalize(&self) -> FinalizedPsbtResult {
pub fn finalize(&self) -> FinalizedPsbtResult {
let curve = Secp256k1::verification_only();
let finalized = self.0.lock().unwrap().clone().finalize(&curve);
match finalized {
Expand All @@ -605,7 +605,7 @@ impl Psbt {
}

/// Write the `Psbt` to a file. Note that the file must not yet exist.
pub(crate) fn write_to_file(&self, path: String) -> Result<(), PsbtError> {
pub fn write_to_file(&self, path: String) -> Result<(), PsbtError> {
let file = File::create_new(path)?;
let mut writer = BufWriter::new(file);
let psbt = self.0.lock().unwrap();
Expand All @@ -614,13 +614,13 @@ impl Psbt {
}

/// Serializes the PSBT into a JSON string representation.
pub(crate) fn json_serialize(&self) -> String {
pub fn json_serialize(&self) -> String {
let psbt = self.0.lock().unwrap();
serde_json::to_string(psbt.deref()).unwrap()
}

/// Returns the spending utxo for this PSBT's input at `input_index`.
pub(crate) fn spend_utxo(&self, input_index: u64) -> String {
pub fn spend_utxo(&self, input_index: u64) -> String {
let psbt = self.0.lock().unwrap();
let utxo = psbt.spend_utxo(input_index as usize).unwrap();
serde_json::to_string(&utxo).unwrap()
Expand Down
Loading