pub struct Database { /* private fields */ }
Expand description
PostgreSQL database connection details.
Implementations§
Source§impl Database
impl Database
Sourcepub async fn set_signed_emergency_stop_tx(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
move_txid: &Txid,
emergency_stop_tx: &Transaction,
) -> Result<(), BridgeError>
pub async fn set_signed_emergency_stop_tx( &self, tx: Option<DatabaseTransaction<'_, '_>>, move_txid: &Txid, emergency_stop_tx: &Transaction, ) -> Result<(), BridgeError>
Sets a signed emergency stop transaction for a given move transaction ID
Sourcepub async fn get_emergency_stop_txs(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
move_txids: Vec<Txid>,
) -> Result<Vec<(Txid, Transaction)>, BridgeError>
pub async fn get_emergency_stop_txs( &self, tx: Option<DatabaseTransaction<'_, '_>>, move_txids: Vec<Txid>, ) -> Result<Vec<(Txid, Transaction)>, BridgeError>
Gets emergency stop transactions for a list of move transaction IDs
Source§impl Database
impl Database
Sourcepub async fn add_block_info(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
block_hash: &BlockHash,
prev_block_hash: &BlockHash,
block_height: u32,
) -> Result<u32, BridgeError>
pub async fn add_block_info( &self, tx: Option<DatabaseTransaction<'_, '_>>, block_hash: &BlockHash, prev_block_hash: &BlockHash, block_height: u32, ) -> Result<u32, BridgeError>
pub async fn set_block_as_canonical_if_exists( &self, tx: Option<DatabaseTransaction<'_, '_>>, block_hash: BlockHash, ) -> Result<Option<u32>, BridgeError>
Sourcepub async fn get_block_info_from_hash(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
block_hash: BlockHash,
) -> Result<Option<(BlockHash, u32)>, BridgeError>
pub async fn get_block_info_from_hash( &self, tx: Option<DatabaseTransaction<'_, '_>>, block_hash: BlockHash, ) -> Result<Option<(BlockHash, u32)>, BridgeError>
pub async fn get_block_info_from_id( &self, tx: Option<DatabaseTransaction<'_, '_>>, block_id: u32, ) -> Result<Option<(BlockHash, u32)>, BridgeError>
pub async fn store_full_block( &self, tx: Option<DatabaseTransaction<'_, '_>>, block: &Block, block_height: u32, ) -> Result<(), BridgeError>
pub async fn get_full_block( &self, tx: Option<DatabaseTransaction<'_, '_>>, block_height: u32, ) -> Result<Option<Block>, BridgeError>
pub async fn get_full_block_from_hash( &self, tx: Option<DatabaseTransaction<'_, '_>>, block_hash: BlockHash, ) -> Result<Option<(u32, Block)>, BridgeError>
pub async fn get_max_height( &self, tx: Option<DatabaseTransaction<'_, '_>>, ) -> Result<Option<u32>, BridgeError>
Sourcepub async fn set_non_canonical_block_hashes(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
height: u32,
) -> Result<Vec<u32>, BridgeError>
pub async fn set_non_canonical_block_hashes( &self, tx: Option<DatabaseTransaction<'_, '_>>, height: u32, ) -> Result<Vec<u32>, BridgeError>
Gets the block hashes that have height bigger then the given height and deletes them.
pub async fn get_canonical_block_id_from_height( &self, tx: Option<DatabaseTransaction<'_, '_>>, height: u32, ) -> Result<Option<u32>, BridgeError>
pub async fn add_txid_to_block( &self, tx: DatabaseTransaction<'_, '_>, block_id: u32, txid: &Txid, ) -> Result<(), BridgeError>
pub async fn get_block_txids( &self, tx: Option<DatabaseTransaction<'_, '_>>, block_id: u32, ) -> Result<Vec<Txid>, BridgeError>
pub async fn insert_spent_utxo( &self, tx: DatabaseTransaction<'_, '_>, block_id: u32, spending_txid: &Txid, txid: &Txid, vout: i64, ) -> Result<(), BridgeError>
pub async fn get_spent_utxos_for_txid( &self, tx: Option<DatabaseTransaction<'_, '_>>, txid: Txid, ) -> Result<Vec<(i64, OutPoint)>, BridgeError>
pub async fn add_event( &self, tx: Option<DatabaseTransaction<'_, '_>>, event_type: BitcoinSyncerEvent, ) -> Result<(), BridgeError>
pub async fn fetch_next_bitcoin_syncer_evt( &self, tx: DatabaseTransaction<'_, '_>, consumer_handle: &str, ) -> Result<Option<BitcoinSyncerEvent>, BridgeError>
Source§impl Database
impl Database
Sourcepub async fn save_unproven_finalized_block(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
block_hash: BlockHash,
block_header: Header,
block_height: u64,
) -> Result<(), BridgeError>
pub async fn save_unproven_finalized_block( &self, tx: Option<DatabaseTransaction<'_, '_>>, block_hash: BlockHash, block_header: Header, block_height: u64, ) -> Result<(), BridgeError>
Adds a new finalized block to the database, later to be updated with a proof.
Sourcepub async fn fetch_and_save_missing_blocks(
&self,
rpc: &ExtendedRpc,
genesis_height: u32,
until_height: u32,
) -> Result<(), BridgeError>
pub async fn fetch_and_save_missing_blocks( &self, rpc: &ExtendedRpc, genesis_height: u32, until_height: u32, ) -> Result<(), BridgeError>
This function assumes there are no blocks or some contiguous blocks starting from 0 already in the table. Saves the block hashes and headers until given height(exclusive) as they are needed for spv and hcp proofs.
Sourcepub async fn get_block_info_from_range(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
start_height: u64,
end_height: u64,
) -> Result<Vec<(BlockHash, Header)>, BridgeError>
pub async fn get_block_info_from_range( &self, tx: Option<DatabaseTransaction<'_, '_>>, start_height: u64, end_height: u64, ) -> Result<Vec<(BlockHash, Header)>, BridgeError>
Returns block hash and header for a given range of heights. Ranges are inclusive on both ends.
Sourcepub async fn get_block_info_from_hash_hcp(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
block_hash: BlockHash,
) -> Result<Option<(BlockHash, Header, u32)>, BridgeError>
pub async fn get_block_info_from_hash_hcp( &self, tx: Option<DatabaseTransaction<'_, '_>>, block_hash: BlockHash, ) -> Result<Option<(BlockHash, Header, u32)>, BridgeError>
Sourcepub async fn get_latest_finalized_block_height(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
) -> Result<Option<u64>, BridgeError>
pub async fn get_latest_finalized_block_height( &self, tx: Option<DatabaseTransaction<'_, '_>>, ) -> Result<Option<u64>, BridgeError>
Returns latest finalized blocks height from the database.
Sourcepub async fn get_next_unproven_block(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
) -> Result<Option<(BlockHash, Header, u64, Receipt)>, BridgeError>
pub async fn get_next_unproven_block( &self, tx: Option<DatabaseTransaction<'_, '_>>, ) -> Result<Option<(BlockHash, Header, u64, Receipt)>, BridgeError>
Gets the first finalized block after the latest proven block (i.e. proof != null). This block will be the candidate block for the prover.
§Returns
Returns None
if either no proved blocks are exists or blockchain tip
is already proven.
- [
BlockHash
] - Hash of the block - [
Header
] - Header of the block u64
- Height of the block- [
Receipt
] - Previous block’s proof
Sourcepub async fn get_next_n_non_proven_block(
&self,
count: u32,
) -> Result<Option<(Vec<(BlockHash, Header, u64)>, Receipt)>, BridgeError>
pub async fn get_next_n_non_proven_block( &self, count: u32, ) -> Result<Option<(Vec<(BlockHash, Header, u64)>, Receipt)>, BridgeError>
Gets the newest n number of block’s info that their previous block has proven before. These blocks will be the candidate blocks for the prover.
§Returns
Returns None
if either no proved blocks are exists or blockchain tip
is already proven.
- [
BlockHash
] - Hash of last block in the batch - [
Header
] - Headers of the blocks u64
- Height of the last block in the batch- [
Receipt
] - Previous block’s proof
Sourcepub async fn get_latest_proven_block_info(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
) -> Result<Option<(BlockHash, Header, u64)>, BridgeError>
pub async fn get_latest_proven_block_info( &self, tx: Option<DatabaseTransaction<'_, '_>>, ) -> Result<Option<(BlockHash, Header, u64)>, BridgeError>
Sourcepub async fn get_latest_proven_block_info_until_height(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
height: u32,
) -> Result<Option<(BlockHash, Header, u64)>, BridgeError>
pub async fn get_latest_proven_block_info_until_height( &self, tx: Option<DatabaseTransaction<'_, '_>>, height: u32, ) -> Result<Option<(BlockHash, Header, u64)>, BridgeError>
Sourcepub async fn set_block_proof(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
hash: BlockHash,
proof: Receipt,
) -> Result<(), BridgeError>
pub async fn set_block_proof( &self, tx: Option<DatabaseTransaction<'_, '_>>, hash: BlockHash, proof: Receipt, ) -> Result<(), BridgeError>
Sets an existing block’s (in database) proof by referring to it by it’s hash.
Sourcepub async fn get_block_proof_by_hash(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
hash: BlockHash,
) -> Result<Option<Receipt>, BridgeError>
pub async fn get_block_proof_by_hash( &self, tx: Option<DatabaseTransaction<'_, '_>>, hash: BlockHash, ) -> Result<Option<Receipt>, BridgeError>
Gets a block’s proof by referring to it by it’s hash.
Source§impl Database
impl Database
Sourcepub async fn set_operator(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
xonly_pubkey: XOnlyPublicKey,
wallet_address: &Address,
collateral_funding_outpoint: OutPoint,
) -> Result<(), BridgeError>
pub async fn set_operator( &self, tx: Option<DatabaseTransaction<'_, '_>>, xonly_pubkey: XOnlyPublicKey, wallet_address: &Address, collateral_funding_outpoint: OutPoint, ) -> Result<(), BridgeError>
Sets the operator details to the db. This function additionally checks if the operator data already exists in the db. As we don’t want to overwrite operator data on the db, as it can prevent us slash malicious operators that signed previous deposits. This function should give an error if an operator changed its data.
pub async fn get_operators( &self, tx: Option<DatabaseTransaction<'_, '_>>, ) -> Result<Vec<(XOnlyPublicKey, Address, OutPoint)>, BridgeError>
pub async fn get_operator( &self, tx: Option<DatabaseTransaction<'_, '_>>, operator_xonly_pk: XOnlyPublicKey, ) -> Result<Option<OperatorData>, BridgeError>
Sourcepub async fn set_funding_utxo(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
funding_utxo: UTXO,
) -> Result<(), BridgeError>
pub async fn set_funding_utxo( &self, tx: Option<DatabaseTransaction<'_, '_>>, funding_utxo: UTXO, ) -> Result<(), BridgeError>
Sets the funding UTXO for kickoffs.
Sourcepub async fn get_funding_utxo(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
) -> Result<Option<UTXO>, BridgeError>
pub async fn get_funding_utxo( &self, tx: Option<DatabaseTransaction<'_, '_>>, ) -> Result<Option<UTXO>, BridgeError>
Gets the funding UTXO for kickoffs
Sourcepub async fn set_unspent_kickoff_sigs(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
operator_xonly_pk: XOnlyPublicKey,
round_idx: RoundIndex,
signatures: Vec<TaggedSignature>,
) -> Result<(), BridgeError>
pub async fn set_unspent_kickoff_sigs( &self, tx: Option<DatabaseTransaction<'_, '_>>, operator_xonly_pk: XOnlyPublicKey, round_idx: RoundIndex, signatures: Vec<TaggedSignature>, ) -> Result<(), BridgeError>
Sets the unspent kickoff sigs received from operators during initial setup. Sigs of each round are stored together in the same row. On conflict, do not update the existing sigs. Although technically, as long as kickoff winternitz keys and operator data(collateral funding outpoint and reimburse address) are not changed, the sigs are still valid even if they are changed.
Sourcepub async fn get_unspent_kickoff_sigs(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
operator_xonly_pk: XOnlyPublicKey,
round_idx: RoundIndex,
) -> Result<Option<Vec<TaggedSignature>>, BridgeError>
pub async fn get_unspent_kickoff_sigs( &self, tx: Option<DatabaseTransaction<'_, '_>>, operator_xonly_pk: XOnlyPublicKey, round_idx: RoundIndex, ) -> Result<Option<Vec<TaggedSignature>>, BridgeError>
Get unspent kickoff sigs for a specific operator and round.
Sourcepub async fn set_operator_bitvm_keys(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
operator_xonly_pk: XOnlyPublicKey,
deposit_outpoint: OutPoint,
winternitz_public_key: Vec<WinternitzPublicKey>,
) -> Result<(), BridgeError>
pub async fn set_operator_bitvm_keys( &self, tx: Option<DatabaseTransaction<'_, '_>>, operator_xonly_pk: XOnlyPublicKey, deposit_outpoint: OutPoint, winternitz_public_key: Vec<WinternitzPublicKey>, ) -> Result<(), BridgeError>
Sets Winternitz public keys for bitvm related inputs of an operator.
Sourcepub async fn get_operator_bitvm_keys(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
operator_xonly_pk: XOnlyPublicKey,
deposit_outpoint: OutPoint,
) -> Result<Vec<PublicKey>, BridgeError>
pub async fn get_operator_bitvm_keys( &self, tx: Option<DatabaseTransaction<'_, '_>>, operator_xonly_pk: XOnlyPublicKey, deposit_outpoint: OutPoint, ) -> Result<Vec<PublicKey>, BridgeError>
Gets Winternitz public keys for bitvm related inputs of an operator.
Sourcepub async fn set_operator_kickoff_winternitz_public_keys(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
operator_xonly_pk: XOnlyPublicKey,
winternitz_public_key: Vec<WinternitzPublicKey>,
) -> Result<(), BridgeError>
pub async fn set_operator_kickoff_winternitz_public_keys( &self, tx: Option<DatabaseTransaction<'_, '_>>, operator_xonly_pk: XOnlyPublicKey, winternitz_public_key: Vec<WinternitzPublicKey>, ) -> Result<(), BridgeError>
Sets Winternitz public keys (only for kickoff blockhash commit) for an operator. On conflict, do not update the existing keys. This is very important, as otherwise the txids of operators round tx’s will change.
Sourcepub async fn get_operator_kickoff_winternitz_public_keys(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
op_xonly_pk: XOnlyPublicKey,
) -> Result<Vec<PublicKey>, BridgeError>
pub async fn get_operator_kickoff_winternitz_public_keys( &self, tx: Option<DatabaseTransaction<'_, '_>>, op_xonly_pk: XOnlyPublicKey, ) -> Result<Vec<PublicKey>, BridgeError>
Gets Winternitz public keys for every sequential collateral tx of an operator and a watchtower.
Sourcepub async fn set_operator_challenge_ack_hashes(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
operator_xonly_pk: XOnlyPublicKey,
deposit_outpoint: OutPoint,
public_hashes: &Vec<[u8; 20]>,
) -> Result<(), BridgeError>
pub async fn set_operator_challenge_ack_hashes( &self, tx: Option<DatabaseTransaction<'_, '_>>, operator_xonly_pk: XOnlyPublicKey, deposit_outpoint: OutPoint, public_hashes: &Vec<[u8; 20]>, ) -> Result<(), BridgeError>
Sets public hashes for a specific operator, sequential collateral tx and kickoff index combination. If there is hashes for given indexes, they will be overwritten by the new hashes.
Sourcepub async fn get_operators_challenge_ack_hashes(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
operator_xonly_pk: XOnlyPublicKey,
deposit_outpoint: OutPoint,
) -> Result<Option<Vec<PublicHash>>, BridgeError>
pub async fn get_operators_challenge_ack_hashes( &self, tx: Option<DatabaseTransaction<'_, '_>>, operator_xonly_pk: XOnlyPublicKey, deposit_outpoint: OutPoint, ) -> Result<Option<Vec<PublicHash>>, BridgeError>
Retrieves public hashes for a specific operator, sequential collateral tx and kickoff index combination.
Sourcepub async fn set_deposit_data(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
deposit_data: &mut DepositData,
paramset: &'static ProtocolParamset,
) -> Result<u32, BridgeError>
pub async fn set_deposit_data( &self, tx: Option<DatabaseTransaction<'_, '_>>, deposit_data: &mut DepositData, paramset: &'static ProtocolParamset, ) -> Result<u32, BridgeError>
Saves deposit infos, and returns the deposit_id This function additionally checks if the deposit data already exists in the db. As we don’t want to overwrite deposit data on the db, this function should give an error if deposit data is changed.
pub async fn get_deposit_data_with_move_tx( &self, tx: Option<DatabaseTransaction<'_, '_>>, move_to_vault_txid: Txid, ) -> Result<Option<DepositData>, BridgeError>
pub async fn get_deposit_data( &self, tx: Option<DatabaseTransaction<'_, '_>>, deposit_outpoint: OutPoint, ) -> Result<Option<(u32, DepositData)>, BridgeError>
Sourcepub async fn set_deposit_signatures(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
deposit_outpoint: OutPoint,
operator_xonly_pk: XOnlyPublicKey,
round_idx: RoundIndex,
kickoff_idx: usize,
kickoff_txid: Txid,
signatures: Vec<TaggedSignature>,
) -> Result<(), BridgeError>
pub async fn set_deposit_signatures( &self, tx: Option<DatabaseTransaction<'_, '_>>, deposit_outpoint: OutPoint, operator_xonly_pk: XOnlyPublicKey, round_idx: RoundIndex, kickoff_idx: usize, kickoff_txid: Txid, signatures: Vec<TaggedSignature>, ) -> Result<(), BridgeError>
Saves the deposit signatures to the database for a single operator.
The signatures array is identified by the deposit_outpoint and operator_idx.
For the order of signatures, please check crate::builder::sighash::create_nofn_sighash_stream
which determines the order of the sighashes that are signed.
Sourcepub async fn get_deposit_id(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
deposit_outpoint: OutPoint,
) -> Result<u32, BridgeError>
pub async fn get_deposit_id( &self, tx: Option<DatabaseTransaction<'_, '_>>, deposit_outpoint: OutPoint, ) -> Result<u32, BridgeError>
Gets a unique int for a deposit outpoint
Sourcepub async fn get_deposit_signatures(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
deposit_outpoint: OutPoint,
operator_xonly_pk: XOnlyPublicKey,
round_idx: RoundIndex,
kickoff_idx: usize,
) -> Result<Option<Vec<TaggedSignature>>, BridgeError>
pub async fn get_deposit_signatures( &self, tx: Option<DatabaseTransaction<'_, '_>>, deposit_outpoint: OutPoint, operator_xonly_pk: XOnlyPublicKey, round_idx: RoundIndex, kickoff_idx: usize, ) -> Result<Option<Vec<TaggedSignature>>, BridgeError>
Retrieves the deposit signatures for a single operator for a single reimburse process (single kickoff utxo). The signatures are tagged so that each signature can be matched with the correct txin it belongs to easily.
pub async fn get_deposit_data_with_kickoff_txid( &self, tx: Option<DatabaseTransaction<'_, '_>>, kickoff_txid: Txid, ) -> Result<Option<(DepositData, KickoffData)>, BridgeError>
Sourcepub async fn set_bitvm_setup(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
operator_xonly_pk: XOnlyPublicKey,
deposit_outpoint: OutPoint,
assert_tx_addrs: impl AsRef<[[u8; 32]]>,
root_hash: &[u8; 32],
latest_blockhash_root_hash: &[u8; 32],
) -> Result<(), BridgeError>
pub async fn set_bitvm_setup( &self, tx: Option<DatabaseTransaction<'_, '_>>, operator_xonly_pk: XOnlyPublicKey, deposit_outpoint: OutPoint, assert_tx_addrs: impl AsRef<[[u8; 32]]>, root_hash: &[u8; 32], latest_blockhash_root_hash: &[u8; 32], ) -> Result<(), BridgeError>
Sets BitVM setup data for a specific operator and deposit combination. This function additionally checks if the BitVM setup data already exists in the db. As we don’t want to overwrite BitVM setup data on the db, as maliciously overwriting can prevent us to regenerate previously signed kickoff tx’s.
Sourcepub async fn get_bitvm_setup(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
operator_xonly_pk: XOnlyPublicKey,
deposit_outpoint: OutPoint,
) -> Result<Option<(Vec<[u8; 32]>, [u8; 32], [u8; 32])>, BridgeError>
pub async fn get_bitvm_setup( &self, tx: Option<DatabaseTransaction<'_, '_>>, operator_xonly_pk: XOnlyPublicKey, deposit_outpoint: OutPoint, ) -> Result<Option<(Vec<[u8; 32]>, [u8; 32], [u8; 32])>, BridgeError>
Retrieves BitVM setup data for a specific operator, sequential collateral tx and kickoff index combination
pub async fn set_kickoff_connector_as_used( &self, tx: Option<DatabaseTransaction<'_, '_>>, round_idx: RoundIndex, kickoff_connector_idx: u32, kickoff_txid: Option<Txid>, ) -> Result<(), BridgeError>
pub async fn get_kickoff_txid_for_used_kickoff_connector( &self, tx: Option<DatabaseTransaction<'_, '_>>, round_idx: RoundIndex, kickoff_connector_idx: u32, ) -> Result<Option<Txid>, BridgeError>
pub async fn get_unused_and_signed_kickoff_connector( &self, tx: Option<DatabaseTransaction<'_, '_>>, deposit_id: u32, operator_xonly_pk: XOnlyPublicKey, ) -> Result<Option<(u32, u32)>, BridgeError>
pub async fn get_current_round_index( &self, tx: Option<DatabaseTransaction<'_, '_>>, ) -> Result<Option<u32>, BridgeError>
pub async fn update_current_round_index( &self, tx: Option<DatabaseTransaction<'_, '_>>, round_idx: RoundIndex, ) -> Result<(), BridgeError>
Source§impl Database
impl Database
Sourcepub async fn get_last_deposit_idx(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
) -> Result<Option<u32>, BridgeError>
pub async fn get_last_deposit_idx( &self, tx: Option<DatabaseTransaction<'_, '_>>, ) -> Result<Option<u32>, BridgeError>
Returns the last deposit index. If no deposits exist, returns None
Sourcepub async fn get_last_withdrawal_idx(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
) -> Result<Option<u32>, BridgeError>
pub async fn get_last_withdrawal_idx( &self, tx: Option<DatabaseTransaction<'_, '_>>, ) -> Result<Option<u32>, BridgeError>
Returns the last withdrawal index where withdrawal_utxo_txid exists. If no withdrawals with UTXOs exist, returns None.
pub async fn set_move_to_vault_txid_from_citrea_deposit( &self, tx: Option<DatabaseTransaction<'_, '_>>, citrea_idx: u32, move_to_vault_txid: &Txid, ) -> Result<(), BridgeError>
pub async fn get_move_to_vault_txid_from_citrea_deposit( &self, tx: Option<DatabaseTransaction<'_, '_>>, citrea_idx: u32, ) -> Result<Option<Txid>, BridgeError>
pub async fn set_replacement_deposit_move_txid( &self, tx: DatabaseTransaction<'_, '_>, idx: u32, new_move_txid: Txid, ) -> Result<(), BridgeError>
pub async fn set_withdrawal_utxo_from_citrea_withdrawal( &self, tx: Option<DatabaseTransaction<'_, '_>>, citrea_idx: u32, withdrawal_utxo: OutPoint, withdrawal_batch_proof_bitcoin_block_height: u32, ) -> Result<(), BridgeError>
pub async fn get_withdrawal_utxo_from_citrea_withdrawal( &self, tx: Option<DatabaseTransaction<'_, '_>>, citrea_idx: u32, ) -> Result<Option<OutPoint>, BridgeError>
Sourcepub async fn get_payout_txs_for_withdrawal_utxos(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
block_id: u32,
) -> Result<Vec<(u32, Txid)>, BridgeError>
pub async fn get_payout_txs_for_withdrawal_utxos( &self, tx: Option<DatabaseTransaction<'_, '_>>, block_id: u32, ) -> Result<Vec<(u32, Txid)>, BridgeError>
Returns the withdrawal indexes and their spending txid for the given block id.
Sourcepub async fn set_payout_txs_and_payer_operator_xonly_pk(
&self,
tx: Option<DatabaseTransaction<'_, '_>>,
payout_txs_and_payer_operator_xonly_pk: Vec<(u32, Txid, Option<XOnlyPublicKey>, BlockHash)>,
) -> Result<(), BridgeError>
pub async fn set_payout_txs_and_payer_operator_xonly_pk( &self, tx: Option<DatabaseTransaction<'_, '_>>, payout_txs_and_payer_operator_xonly_pk: Vec<(u32, Txid, Option<XOnlyPublicKey>, BlockHash)>, ) -> Result<(), BridgeError>
Sets the given payout txs’ txid and operator index for the given index.
pub async fn get_payout_info_from_move_txid( &self, tx: Option<DatabaseTransaction<'_, '_>>, move_to_vault_txid: Txid, ) -> Result<Option<(Option<XOnlyPublicKey>, BlockHash, Txid, i32)>, BridgeError>
pub async fn get_first_unhandled_payout_by_operator_xonly_pk( &self, tx: Option<DatabaseTransaction<'_, '_>>, operator_xonly_pk: XOnlyPublicKey, ) -> Result<Option<(u32, Txid, BlockHash)>, BridgeError>
pub async fn set_payout_handled( &self, tx: Option<DatabaseTransaction<'_, '_>>, citrea_idx: u32, kickoff_txid: Txid, ) -> Result<(), BridgeError>
pub async fn get_handled_payout_kickoff_txid( &self, tx: Option<DatabaseTransaction<'_, '_>>, payout_txid: Txid, ) -> Result<Option<Txid>, BridgeError>
Source§impl Database
impl Database
Sourcepub async fn new(config: &BridgeConfig) -> Result<Self, BridgeError>
pub async fn new(config: &BridgeConfig) -> Result<Self, BridgeError>
Establishes a new connection to a PostgreSQL database with given configuration.
§Errors
Returns a BridgeError
if database is not accessible.
pub fn get_pool(&self) -> Pool<Postgres>
pub async fn is_pgmq_installed( &self, tx: Option<DatabaseTransaction<'_, '_>>, ) -> Result<bool, BridgeError>
Sourcepub async fn run_schema_script(
config: &BridgeConfig,
is_verifier: bool,
) -> Result<(), BridgeError>
pub async fn run_schema_script( config: &BridgeConfig, is_verifier: bool, ) -> Result<(), BridgeError>
Runs the schema script on a database for the given configuration.
§Errors
Will return BridgeError
if there was a problem with database
connection.
Sourcepub fn get_postgresql_url(config: &BridgeConfig) -> String
pub fn get_postgresql_url(config: &BridgeConfig) -> String
Prepares a valid PostgreSQL URL.
URL contains user, password, host and port fields, which are picked from the given configuration.
Sourcepub fn get_postgresql_database_url(config: &BridgeConfig) -> String
pub fn get_postgresql_database_url(config: &BridgeConfig) -> String
Prepares a valid PostgreSQL URL to a specific database.
URL contains user, password, host, port and database name fields, which are picked from the given configuration.
Sourcepub async fn begin_transaction(
&self,
) -> Result<Transaction<'_, Postgres>, BridgeError>
pub async fn begin_transaction( &self, ) -> Result<Transaction<'_, Postgres>, BridgeError>
Starts a database transaction.
Return value can be used for committing changes. If not committed, database will rollback every operation done after that call.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Database
impl !RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl !UnwindSafe for Database
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T, U> ExactFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> ExactFrom<T> for Uwhere
U: TryFrom<T>,
fn exact_from(value: T) -> U
§impl<T, U> ExactInto<U> for Twhere
U: ExactFrom<T>,
impl<T, U> ExactInto<U> for Twhere
U: ExactFrom<T>,
fn exact_into(self) -> U
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
§impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
fn overflowing_into(self) -> (U, bool)
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T, U> RoundingInto<U> for Twhere
U: RoundingFrom<T>,
impl<T, U> RoundingInto<U> for Twhere
U: RoundingFrom<T>,
fn rounding_into(self, rm: RoundingMode) -> (U, Ordering)
§impl<T, U> SaturatingInto<U> for Twhere
U: SaturatingFrom<T>,
impl<T, U> SaturatingInto<U> for Twhere
U: SaturatingFrom<T>,
fn saturating_into(self) -> U
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.