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;
63
64pub use error::{TxError, Result};
65pub use types::{Transaction, TxInput, TxOutput, Utxo};
66pub use fee::{estimate_vsize, calculate_fee, estimate_fee, is_dust};
67pub use script::{
68    build_p2pkh_script, build_p2wpkh_script, build_p2tr_script,
69    hash160, is_p2pkh, is_p2wpkh, is_p2tr,
70};
71pub use coin_selection::select_coins;
72pub use sighash::{sighash_legacy, sighash_segwit, sighash_type};
73pub use builder::{TxBuilder, UnsignedTx, InputInfo};
74pub use signing::{sign_p2pkh, sign_p2wpkh, sign_all};
75
76/// Prelude module for convenient imports.
77pub mod prelude {
78    pub use crate::{
79        Transaction, TxInput, TxOutput, Utxo,
80        TxBuilder, UnsignedTx,
81        TxError, Result,
82        sign_p2pkh, sign_p2wpkh, sign_all,
83        estimate_fee, calculate_fee, is_dust,
84        select_coins,
85    };
86}