pub mod adaptor;
pub mod models;
#[cfg(feature = "sqlite")]
pub mod sqlite;
#[cfg(test)]
pub(crate) mod test_suite;
use bitcoin::{Amount, Transaction, Txid};
use bitcoin::secp256k1::PublicKey;
use chrono::DateTime;
use lightning_invoice::Bolt11Invoice;
#[cfg(feature = "onchain-bdk")]
use bdk_wallet::ChangeSet;
use ark::{Vtxo, VtxoId};
use ark::lightning::{Invoice, PaymentHash, Preimage};
use ark::vtxo::Full;
use bitcoin_ext::BlockDelta;
use crate::WalletProperties;
use crate::exit::ExitTxOrigin;
use crate::persist::models::{
LightningReceive, LightningSend, PendingBoard, RoundStateId, StoredExit, StoredRoundState,
Unlocked, PendingOffboard,
};
use crate::movement::{Movement, MovementId, MovementStatus, MovementSubsystem, PaymentMethod};
use crate::round::RoundState;
use crate::vtxo::{VtxoState, VtxoStateKind, WalletVtxo};
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait BarkPersister: Send + Sync + 'static {
async fn is_initialized(&self) -> anyhow::Result<bool> {
Ok(self.read_properties().await?.is_some())
}
async fn init_wallet(&self, properties: &WalletProperties) -> anyhow::Result<()>;
#[cfg(feature = "onchain-bdk")]
async fn initialize_bdk_wallet(&self) -> anyhow::Result<ChangeSet>;
#[cfg(feature = "onchain-bdk")]
async fn store_bdk_wallet_changeset(&self, changeset: &ChangeSet) -> anyhow::Result<()>;
async fn read_properties(&self) -> anyhow::Result<Option<WalletProperties>>;
async fn set_server_pubkey(&self, server_pubkey: PublicKey) -> anyhow::Result<()>;
async fn set_server_mailbox_pubkey(&self, server_mailbox_pubkey: PublicKey) -> anyhow::Result<()>;
async fn create_new_movement(&self,
status: MovementStatus,
subsystem: &MovementSubsystem,
time: DateTime<chrono::Local>,
) -> anyhow::Result<MovementId>;
async fn update_movement(&self, movement: &Movement) -> anyhow::Result<()>;
async fn get_movement_by_id(&self, movement_id: MovementId) -> anyhow::Result<Movement>;
async fn get_all_movements(&self) -> anyhow::Result<Vec<Movement>>;
async fn get_movements_by_payment_method(
&self,
payment_method: &PaymentMethod,
) -> anyhow::Result<Vec<Movement>>;
async fn store_pending_board(
&self,
vtxo: &Vtxo<Full>,
funding_tx: &Transaction,
movement_id: MovementId,
) -> anyhow::Result<()>;
async fn remove_pending_board(&self, vtxo_id: &VtxoId) -> anyhow::Result<()>;
async fn get_all_pending_board_ids(&self) -> anyhow::Result<Vec<VtxoId>>;
async fn get_pending_board_by_vtxo_id(&self, vtxo_id: VtxoId) -> anyhow::Result<Option<PendingBoard>>;
async fn store_round_state_lock_vtxos(&self, round_state: &RoundState) -> anyhow::Result<RoundStateId>;
async fn update_round_state(&self, round_state: &StoredRoundState) -> anyhow::Result<()>;
async fn remove_round_state(&self, round_state: &StoredRoundState) -> anyhow::Result<()>;
async fn get_round_state_by_id(&self, id: RoundStateId) -> anyhow::Result<Option<StoredRoundState<Unlocked>>>;
async fn get_pending_round_state_ids(&self) -> anyhow::Result<Vec<RoundStateId>>;
async fn store_vtxos(
&self,
vtxos: &[(&Vtxo<Full>, &VtxoState)],
) -> anyhow::Result<()>;
async fn get_wallet_vtxo(&self, id: VtxoId) -> anyhow::Result<Option<WalletVtxo>>;
async fn get_all_vtxos(&self) -> anyhow::Result<Vec<WalletVtxo>>;
async fn get_vtxos_by_state(&self, state: &[VtxoStateKind]) -> anyhow::Result<Vec<WalletVtxo>>;
async fn remove_vtxo(&self, id: VtxoId) -> anyhow::Result<Option<Vtxo<Full>>>;
async fn has_spent_vtxo(&self, id: VtxoId) -> anyhow::Result<bool>;
async fn store_vtxo_key(&self, index: u32, public_key: PublicKey) -> anyhow::Result<()>;
async fn get_last_vtxo_key_index(&self) -> anyhow::Result<Option<u32>>;
async fn get_public_key_idx(&self, public_key: &PublicKey) -> anyhow::Result<Option<u32>>;
async fn get_mailbox_checkpoint(&self) -> anyhow::Result<u64>;
async fn store_mailbox_checkpoint(&self, checkpoint: u64) -> anyhow::Result<()>;
async fn store_new_pending_lightning_send(
&self,
invoice: &Invoice,
amount: Amount,
fee: Amount,
vtxos: &[VtxoId],
movement_id: MovementId,
) -> anyhow::Result<LightningSend>;
async fn get_all_pending_lightning_send(&self) -> anyhow::Result<Vec<LightningSend>>;
async fn finish_lightning_send(
&self,
payment_hash: PaymentHash,
preimage: Option<Preimage>,
) -> anyhow::Result<()>;
async fn remove_lightning_send(&self, payment_hash: PaymentHash) -> anyhow::Result<()>;
async fn get_lightning_send(&self, payment_hash: PaymentHash) -> anyhow::Result<Option<LightningSend>>;
async fn store_lightning_receive(
&self,
payment_hash: PaymentHash,
preimage: Preimage,
invoice: &Bolt11Invoice,
htlc_recv_cltv_delta: BlockDelta,
) -> anyhow::Result<()>;
async fn get_all_pending_lightning_receives(&self) -> anyhow::Result<Vec<LightningReceive>>;
async fn set_preimage_revealed(&self, payment_hash: PaymentHash) -> anyhow::Result<()>;
async fn update_lightning_receive(
&self,
payment_hash: PaymentHash,
htlc_vtxo_ids: &[VtxoId],
movement_id: MovementId,
) -> anyhow::Result<()>;
async fn fetch_lightning_receive_by_payment_hash(
&self,
payment_hash: PaymentHash,
) -> anyhow::Result<Option<LightningReceive>>;
async fn finish_pending_lightning_receive(
&self,
payment_hash: PaymentHash,
) -> anyhow::Result<()>;
async fn store_exit_vtxo_entry(&self, exit: &StoredExit) -> anyhow::Result<()>;
async fn remove_exit_vtxo_entry(&self, id: &VtxoId) -> anyhow::Result<()>;
async fn get_exit_vtxo_entries(&self) -> anyhow::Result<Vec<StoredExit>>;
async fn store_exit_child_tx(
&self,
exit_txid: Txid,
child_tx: &Transaction,
origin: ExitTxOrigin,
) -> anyhow::Result<()>;
async fn get_exit_child_tx(
&self,
exit_txid: Txid,
) -> anyhow::Result<Option<(Transaction, ExitTxOrigin)>>;
async fn update_vtxo_state_checked(
&self,
vtxo_id: VtxoId,
new_state: VtxoState,
allowed_old_states: &[VtxoStateKind],
) -> anyhow::Result<WalletVtxo>;
async fn store_pending_offboard(
&self,
pending: &PendingOffboard,
) -> anyhow::Result<()>;
async fn get_pending_offboards(&self) -> anyhow::Result<Vec<PendingOffboard>>;
async fn remove_pending_offboard(&self, movement_id: MovementId) -> anyhow::Result<()>;
}