Created
April 11, 2023 08:06
-
-
Save SethDusek/0356e3f7b3ba8293561c77433a82ce7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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