-
-
Save 0xB10C/edc6e50ce755d4e0e5f9f4a1c2a7d8d0 to your computer and use it in GitHub Desktop.
Quick and dirty rustlang code used to create a transaction donating anyone-can-spend P2TR outputs (before taproot activation) to brink.dev https://b10c.me/blog/007-spending-p2tr-pre-activation/
This file contains 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 core::str::FromStr; | |
use bitcoin::consensus::serialize; | |
use bitcoin::hash_types::{ScriptHash, Txid}; | |
use bitcoin::hashes::hash160::Hash as Hash160; | |
use bitcoin::hashes::Hash; | |
use bitcoin::util::base58; | |
use bitcoin::{OutPoint, Script, Transaction, TxIn, TxOut}; | |
fn main() { | |
let first_p2tr_output_value = 5431; | |
let first_p2tr_output = OutPoint::new( | |
Txid::from_str("b53e3bc5edbb41b34a963ecf67eb045266cf841cab73a780940ce6845377f141").unwrap(), | |
0, | |
); | |
let third_p2tr_output_value = 3656; | |
let third_p2tr_output = OutPoint::new( | |
Txid::from_str("b48a59fa9e036e997ba733904f631b1a64f5274be646698e49fd542141ca9404").unwrap(), | |
0, | |
); | |
let fourth_p2tr_output_value = 50_000; | |
let fourth_p2tr_output = OutPoint::new( | |
Txid::from_str("7641c08f4bd299abfef26dcc6b477938f4a6c2eed2f224d1f5c1c86b4e09739d").unwrap(), | |
1, | |
); | |
let fifth_p2tr_output_value = 100_000; | |
let fifth_p2tr_output = OutPoint::new( | |
Txid::from_str("fd43650477e0ba6825ae0482a8b0b2b509d5443fa2a8cdd101872752a9171dd6").unwrap(), | |
1, | |
); | |
let input1 = TxIn { | |
previous_output: third_p2tr_output, | |
script_sig: Script::new(), | |
sequence: 0xb10c, | |
witness: vec![], | |
}; | |
let input2 = TxIn { | |
previous_output: fourth_p2tr_output, | |
script_sig: Script::new(), | |
sequence: 0xb10c, | |
witness: vec![], | |
}; | |
let input3 = TxIn { | |
previous_output: fifth_p2tr_output, | |
script_sig: Script::new(), | |
sequence: 0xb10c, | |
witness: vec![], | |
}; | |
let brink_dev_donation_address = "3QdFzfpU3u92GeRN4U5pLLezbBaHbj2ppr"; | |
let address_bytes = base58::from_check(brink_dev_donation_address).unwrap(); | |
let script_hash = ScriptHash::from_hash(Hash160::from_slice(&address_bytes[1..]).unwrap()); | |
let donation_out = TxOut { | |
value: first_p2tr_output_value | |
+ third_p2tr_output_value | |
+ fourth_p2tr_output_value | |
+ fifth_p2tr_output_value, | |
script_pubkey: Script::new_p2sh(&script_hash), | |
}; | |
let opreturn_out = TxOut { | |
value: 0, | |
script_pubkey: Script::new_op_return("https://b10c.me/7".as_bytes()), | |
}; | |
let mut sequence_in_0 = 6817749; | |
while sequence_in_0 < 0xFFFF_FFFFu32 { | |
let input0 = TxIn { | |
previous_output: first_p2tr_output, | |
script_sig: Script::new(), | |
sequence: sequence_in_0, | |
witness: vec![], | |
}; | |
let tx = Transaction { | |
version: 1, | |
lock_time: 45324, | |
input: vec![input0, input1.clone(), input2.clone(), input3.clone()], | |
output: vec![donation_out.clone(), opreturn_out.clone()], | |
}; | |
if tx.txid()[29..] == vec![0x00, 0x0c, 0xb1] { | |
println!("Sequence: {}", sequence_in_0); | |
let tx_ser = serialize(&tx); | |
println!("{} {}", tx.txid(), hex::encode(&tx_ser)); | |
break; | |
} | |
sequence_in_0 += 1; | |
} | |
} |
I can use this to explain to my students
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice