fedimint_testing/btc/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
pub mod mock;
pub mod real;

use async_trait::async_trait;
use bitcoin30::{Address, Transaction, Txid};
use fedimint_core::txoproof::TxOutProof;
use fedimint_core::Amount;

#[async_trait]
pub trait BitcoinTest {
    /// Make the underlying instance act as if it was exclusively available
    /// for the existence of the returned guard.
    async fn lock_exclusive(&self) -> Box<dyn BitcoinTest + Send + Sync>;

    /// Mines a given number of blocks
    async fn mine_blocks(&self, block_num: u64) -> Vec<bitcoin30::BlockHash>;

    /// Prepare funding wallet
    ///
    /// If needed will mine initial 100 blocks for `send_and_mine_block` to
    /// work.
    async fn prepare_funding_wallet(&self);

    /// Send some bitcoin to an address then mine a block to confirm it.
    /// Returns the proof that the transaction occurred.
    ///
    /// The implementation is responsible for making sure the funds can
    /// be sent (e.g. first 100 blocks are mined to make funds available)
    async fn send_and_mine_block(
        &self,
        address: &Address,
        amount: bitcoin30::Amount,
    ) -> (TxOutProof, Transaction);

    /// Returns a new address.
    async fn get_new_address(&self) -> Address;

    /// Mine a block to include any pending transactions then get the amount
    /// received to an address
    async fn mine_block_and_get_received(&self, address: &Address) -> Amount;

    /// Waits till tx is found in mempool and returns the fees
    async fn get_mempool_tx_fee(&self, txid: &Txid) -> Amount;

    /// Returns the block height for the txid if found.
    ///
    /// Note: this exists since there's a bug for using bitcoind without txindex
    /// for finding a tx block height.
    /// see: `<https://github.com/fedimint/fedimint/issues/5329>`
    async fn get_tx_block_height(&self, txid: &Txid) -> Option<u64>;

    /// Returns the current block count
    async fn get_block_count(&self) -> u64;

    /// Returns a transaction with the provided txid if it exists in the mempool
    async fn get_mempool_tx(&self, txid: &Txid) -> Option<bitcoin30::Transaction>;
}