Skip to content

Instantly share code, notes, and snippets.

@SethDusek
Created April 11, 2023 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SethDusek/0356e3f7b3ba8293561c77433a82ce7e to your computer and use it in GitHub Desktop.
Save SethDusek/0356e3f7b3ba8293561c77433a82ce7e to your computer and use it in GitHub Desktop.
use bitcoin::consensus::encode::serialize_hex;
use bitcoin::consensus::Decodable;
use bitcoin::Transaction;
use std::fs::File;
use std::io::prelude::*;
fn main() {
println!("Enter tx hex: ");
let mut l = String::new();
std::io::stdin().read_line(&mut l).unwrap();
let mut bytes = vec![];
let mut i = 0;
// decode transaction hex
while i < l.len() - 1 {
let byte = u8::from_str_radix(&l[i..i + 2], 16).unwrap();
i += 2;
bytes.push(byte);
}
let mut tx = Transaction::consensus_decode(&mut &*bytes).unwrap();
println!("{}", tx.txid());
for input in &mut tx.input {
let witness = input.witness.to_vec();
input.witness.clear();
input.witness.push(&witness[0]); // we're only interested in the first push: the signature
}
println!("{}", tx.vsize());
println!("Final tx: {}", serialize_hex(&tx));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment