xmr-btc-swap/bitcoin-wallet/src/lib.rs
Mohan 4ae47e57f9
refactor: swap-core / swap-machine (#530)
* progress

* fix thread safety

* move monero types from swap into swap_core

* just fmt

* move non test code above test code

* revert removed tracing in bitcoin-wallet/src/primitives.rs

* Use existing private_key_from_secp256k1_scalar

* remove unused monero chose code

* fix some clippy warnings due to imports

* move state machine types into the new `swap-machine` crate

* remove monero_c orphan submodule

* rm bdk_test and sqlx_test from ci

* move proptest.rs into swap-proptest

* increase stack size to 12mb

* properly increase stack size

* fix merge conflict in ci.yml

* don't increase stack size on mac

* fix infinite recursion

* fix integration tests

* fix some compile errors

* fix compilation errors

* rustfmt

* ignore unstaged patches we applied to monero submodule when running git status

* fix some test compilation errors

* use BitcoinWallet trait instead of concrete type everywhere

* add just test command to run integration tests

* remove test_utils features from bdk in swap-core

---------

Co-authored-by: einliterflasche <einliterflasche@pm.me>
Co-authored-by: binarybaron <binarybaron@mail.mail>
2025-10-10 16:29:00 +02:00

65 lines
1.8 KiB
Rust

pub mod primitives;
pub use crate::primitives::{ScriptStatus, Subscription, Watchable};
use anyhow::Result;
use bdk_wallet::{export::FullyNodedExport, Balance};
use bitcoin::{Address, Amount, Network, Psbt, Txid, Weight};
#[async_trait::async_trait]
pub trait BitcoinWallet: Send + Sync {
async fn balance(&self) -> Result<Amount>;
async fn balance_info(&self) -> Result<Balance>;
async fn new_address(&self) -> Result<Address>;
async fn send_to_address(
&self,
address: Address,
amount: Amount,
spending_fee: Amount,
change_override: Option<Address>,
) -> Result<Psbt>;
async fn send_to_address_dynamic_fee(
&self,
address: Address,
amount: Amount,
change_override: Option<Address>,
) -> Result<bitcoin::psbt::Psbt>;
async fn sweep_balance_to_address_dynamic_fee(
&self,
address: Address,
) -> Result<bitcoin::psbt::Psbt>;
async fn sign_and_finalize(&self, psbt: bitcoin::psbt::Psbt) -> Result<bitcoin::Transaction>;
async fn broadcast(
&self,
transaction: bitcoin::Transaction,
kind: &str,
) -> Result<(Txid, Subscription)>;
async fn sync(&self) -> Result<()>;
async fn subscribe_to(&self, tx: Box<dyn Watchable>) -> Subscription;
async fn status_of_script(&self, tx: &dyn Watchable) -> Result<ScriptStatus>;
async fn get_raw_transaction(
&self,
txid: Txid,
) -> Result<Option<std::sync::Arc<bitcoin::Transaction>>>;
async fn max_giveable(&self, locking_script_size: usize) -> Result<(Amount, Amount)>;
async fn estimate_fee(&self, weight: Weight, transfer_amount: Option<Amount>)
-> Result<Amount>;
fn network(&self) -> Network;
fn finality_confirmations(&self) -> u32;
async fn wallet_export(&self, role: &str) -> Result<FullyNodedExport>;
}