Expand description
§builder::transaction
This module provides the core logic for constructing, handling, and signing the various Bitcoin transactions required by the Clementine bridge protocol. It defines the creation, and validation of transaction flows involving operators, verifiers, watchtowers, and the security council, aimed to make it easy to create transactions and sign them properly.
§Overview
The transaction builder is responsible for:
- Defining all transaction types and their flows in the protocol (see
TransactionType). - Building and signing transactions for deposit, withdrawal, challenge, reimbursement, and related operations.
- Storing transaction inputs/outputs, scripts, and Taproot spend information.
- Providing utilities to speed up transaction creating during a deposit using caching tx and db data.
§Main Components
- [
mod.rs] - The main entry point, re-exporting key types and functions. Defines some helper functions for creating taproot outputs. - [
creator.rs] - Contains the functions to create multiple TxHandler’s for a deposit and related structs for caching. In particular, it contains the functions to create TxHandler’s for all transactions generated during a deposit from a single kickoff. - [
operator_collateral.rs] - Handles the creation of operator-specific collateral-related transactions, such as round, ready-to-reimburse, and unspent kickoff transactions. - [
operator_reimburse.rs] - Implements the creation of reimbursement and payout transactions, including logic for operator compensation and optimistic payouts. - [
operator_assert.rs] - Provides functions for creating BitVM assertion and timeout transactions. - [
challenge.rs] - Handles the creation of challenge, disprove, and watchtower challenge transactions, supporting protocol dispute resolution and fraud proofs. - [
sign.rs] - Contains logic for signing transactions using data in theTxHandler. - [
txhandler.rs] - Defines theTxHandlerabstraction, which wraps a transaction and its metadata, and provides methods for signing, finalizing, and extracting transaction data. - [
input.rs] - Defines types and utilities for transaction inputs used in theTxHandler. - [
output.rs] - Defines types and utilities for transaction outputs used in theTxHandler. - [
deposit_signature_owner.rs] - Maps which TxIn signatures are signed by which protocol entities, additionally supporting different Sighash types.
Modules§
- challenge
- Challenge Transaction Logic
- creator 🔒
- Transaction Handler Creation Logic
- deposit_
signature_ owner - Deposit Signature Ownership Mapping
- input
- Transaction Input Types and Utilities
- operator_
assert 🔒 - This module contains the creation of BitVM operator assertion transactions and timeout transactions related to assertions.
- operator_
collateral 🔒 - Collaterals
- operator_
reimburse 🔒 - Operator Reimburse Transactions
- output
- Transaction Output Types and Utilities
- sign
- Transaction Signing Utilities
- txhandler 🔒
- Transaction Handler Module
Structs§
- Contract
Context - Context for a single operator and round, and optionally a single deposit. Data about deposit and kickoff idx is needed to create the deposit-related transactions. For non deposit related transactions, like the round tx and ready to reimburse tx, the round idx is enough.
- Kickoff
Winternitz Keys - Helper struct to get specific kickoff winternitz keys for a sequential collateral tx
- Reimburse
DbCache - Struct to retrieve and cache data from DB for creating TxHandlers on demand It can only store information for one deposit and operator pair. It has two context modes, for rounds or for deposits. Deposit context needs additional information, like the deposit outpoint, which is not needed for rounds. Round context can only create transactions that do not depend on the deposit, like the round tx and ready to reimburse tx. Deposit context can create all transactions. Note: This cache is specific to a single operator, for each operator a new cache is needed.
- Signed
- Marker type for signed transactions.
- TxHandler
- Handler for protocol transactions, wrapping inputs, outputs, and cached transaction data.
- TxHandler
Builder - Builder for
TxHandler, allowing stepwise construction of inputs and outputs. - TxHandler
Cache - Stores and manages cached transaction handlers for efficient flow construction.
- Unsigned
- Marker type for unsigned transactions.
Enums§
- Transaction
Type - Types of all transactions that can be created. Some transactions have a (usize) index as there are multiple instances of the same transaction type per kickoff.
- TxError
Constants§
Traits§
Functions§
- anchor_
output - Creates a P2A (anchor) output for Child Pays For Parent (CPFP) fee bumping.
- combine_
emergency_ stop_ txhandler - Combines multiple emergency stop transactions into a single transaction.
- create_
burn_ unused_ kickoff_ connectors_ txhandler - Creates a
TxHandlerfor burning unused kickoff connectors. - create_
disprove_ taproot_ output - Creates a Taproot output for a disprove path, combining a script, an additional disprove script, and a hidden node containing the BitVM disprove scripts.
- create_
emergency_ stop_ txhandler - Creates a
TxHandlerfor theemergency_stop_tx. - create_
move_ to_ vault_ txhandler - Creates a
TxHandlerfor themove_to_vault_tx. - create_
optimistic_ payout_ txhandler - Creates a
TxHandlerfor theoptimistic_payout_tx. - create_
payout_ txhandler - Creates a
TxHandlerfor thepayout_tx. - create_
replacement_ deposit_ txhandler - Creates a
TxHandlerfor thereplacement_deposit_tx. - create_
round_ nth_ txhandler - Creates the nth (1-indexed)
round_txhandlerandreimburse_generator_txhandlerpair for a specific operator. - create_
round_ txhandlers - Creates the round and ready-to-reimburse txhandlers for a specific operator and round index. These transactions currently include round tx, ready to reimburse tx, and unspent kickoff txs.
- create_
taproot_ output_ with_ hidden_ node - Helper function to create a Taproot output that combines a single script and a root hash containing any number of scripts. The main use case for this function is to speed up the tx creating during a deposit. We don’t need to create and combine all the scripts in the taproot repeatedly, but cache and combine the common scripts for each kickoff tx to a root hash, and add an additional script that depends on the specific operator or nofn_pk that is signing the deposit.
- create_
txhandlers - Creates all required transaction handlers for a given context and transaction type.
- non_
ephemeral_ anchor_ output - A non-ephemeral anchor output. It is used in tx’s that should have a non-ephemeral anchor. Because ephemeral anchors force the tx to have 0 fee.
- op_
return_ txout - Creates an OP_RETURN output with the given data slice.
- remove_
txhandler_ from_ map - Removes a
TxHandlerfrom a map by transaction type, returning an error if not found.