Crate rustywallet_tx

Crate rustywallet_tx 

Source
Expand description

§rustywallet-tx

Bitcoin transaction building, signing, and serialization.

§Features

  • Build transactions with multiple inputs and outputs
  • Automatic coin selection
  • Fee calculation (vsize-based)
  • Sign P2PKH and P2WPKH inputs
  • Serialize transactions for broadcasting

§Quick Start

use rustywallet_tx::prelude::*;
use rustywallet_keys::prelude::PrivateKey;

// Create a UTXO
let utxo = Utxo {
    txid: [0u8; 32],
    vout: 0,
    value: 100_000,
    script_pubkey: vec![0x00, 0x14, /* ... 20 bytes ... */],
    address: "bc1q...".to_string(),
};

// Build transaction
let unsigned = TxBuilder::new()
    .add_input(utxo)
    .add_output(50_000, vec![/* scriptPubKey */])
    .set_fee_rate(10) // 10 sat/vB
    .build()
    .unwrap();

println!("Fee: {} sats", unsigned.fee());

§Signing

use rustywallet_tx::{sign_p2wpkh, Transaction};
use rustywallet_keys::prelude::PrivateKey;

let private_key = PrivateKey::random();
let mut tx = unsigned.tx;

// Sign P2WPKH input
sign_p2wpkh(&mut tx, 0, 100_000, &private_key).unwrap();

// Serialize for broadcast
let hex = tx.to_hex();

Re-exports§

pub use error::TxError;
pub use error::Result;
pub use types::Transaction;
pub use types::TxInput;
pub use types::TxOutput;
pub use types::Utxo;
pub use fee::estimate_vsize;
pub use fee::calculate_fee;
pub use fee::estimate_fee;
pub use fee::is_dust;
pub use script::build_p2pkh_script;
pub use script::build_p2wpkh_script;
pub use script::build_p2tr_script;
pub use script::hash160;
pub use script::is_p2pkh;
pub use script::is_p2wpkh;
pub use script::is_p2tr;
pub use coin_selection::select_coins;
pub use sighash::sighash_legacy;
pub use sighash::sighash_segwit;
pub use sighash::sighash_type;
pub use builder::TxBuilder;
pub use builder::UnsignedTx;
pub use builder::InputInfo;
pub use signing::sign_p2pkh;
pub use signing::sign_p2wpkh;
pub use signing::sign_all;

Modules§

builder
Transaction builder.
coin_selection
Coin selection algorithms.
error
Error types for transaction operations.
fee
Fee calculation utilities.
prelude
Prelude module for convenient imports.
script
Script building utilities.
sighash
Sighash calculation for transaction signing.
signing
Transaction signing.
types
Core transaction types.