rustywallet_tx/
lib.rs

1//! # rustywallet-tx
2//!
3//! Bitcoin transaction building, signing, and serialization.
4//!
5//! ## Features
6//!
7//! - Build transactions with multiple inputs and outputs
8//! - Automatic coin selection
9//! - Fee calculation (vsize-based)
10//! - Sign P2PKH and P2WPKH inputs
11//! - Serialize transactions for broadcasting
12//!
13//! ## Quick Start
14//!
15//! ```rust
16//! use rustywallet_tx::prelude::*;
17//! use rustywallet_keys::prelude::PrivateKey;
18//!
19//! // Create a UTXO
20//! let utxo = Utxo {
21//!     txid: [0u8; 32],
22//!     vout: 0,
23//!     value: 100_000,
24//!     script_pubkey: vec![0x00, 0x14, /* ... 20 bytes ... */],
25//!     address: "bc1q...".to_string(),
26//! };
27//!
28//! // Build transaction
29//! let unsigned = TxBuilder::new()
30//!     .add_input(utxo)
31//!     .add_output(50_000, vec![/* scriptPubKey */])
32//!     .set_fee_rate(10) // 10 sat/vB
33//!     .build()
34//!     .unwrap();
35//!
36//! println!("Fee: {} sats", unsigned.fee());
37//! ```
38//!
39//! ## Signing
40//!
41//! ```rust,ignore
42//! use rustywallet_tx::{sign_p2wpkh, Transaction};
43//! use rustywallet_keys::prelude::PrivateKey;
44//!
45//! let private_key = PrivateKey::random();
46//! let mut tx = unsigned.tx;
47//!
48//! // Sign P2WPKH input
49//! sign_p2wpkh(&mut tx, 0, 100_000, &private_key).unwrap();
50//!
51//! // Serialize for broadcast
52//! let hex = tx.to_hex();
53//! ```
54
55pub mod error;
56pub mod types;
57pub mod fee;
58pub mod script;
59pub mod coin_selection;
60pub mod sighash;
61pub mod builder;
62pub mod signing;
63pub mod rbf;
64pub mod taproot;
65
66pub use error::{TxError, Result};
67pub use types::{Transaction, TxInput, TxOutput, Utxo};
68pub use fee::{estimate_vsize, calculate_fee, estimate_fee, is_dust};
69pub use script::{
70    build_p2pkh_script, build_p2wpkh_script, build_p2tr_script,
71    hash160, is_p2pkh, is_p2wpkh, is_p2tr,
72};
73pub use coin_selection::select_coins;
74pub use sighash::{sighash_legacy, sighash_segwit, sighash_type};
75pub use builder::{TxBuilder, UnsignedTx, InputInfo};
76pub use signing::{sign_p2pkh, sign_p2wpkh, sign_all};
77pub use rbf::{
78    is_rbf_enabled, enable_rbf, disable_rbf, 
79    create_replacement, bump_fee, RbfBuilder,
80    sequence as rbf_sequence,
81};
82pub use taproot::{
83    sign_p2tr_key_path, sign_p2tr_key_path_with_sighash,
84    sign_all_p2tr, is_p2tr_script, extract_p2tr_pubkey,
85};
86
87/// Prelude module for convenient imports.
88pub mod prelude {
89    pub use crate::{
90        Transaction, TxInput, TxOutput, Utxo,
91        TxBuilder, UnsignedTx,
92        TxError, Result,
93        sign_p2pkh, sign_p2wpkh, sign_all,
94        sign_p2tr_key_path, sign_all_p2tr,
95        estimate_fee, calculate_fee, is_dust,
96        select_coins,
97        is_rbf_enabled, enable_rbf, disable_rbf,
98        bump_fee, RbfBuilder,
99    };
100}