Monday, December 5, 2022
HomeBitcoinsegregated witness - How do you decide to the earlier output's quantity...

segregated witness – How do you decide to the earlier output’s quantity when signing a segwit enter with rust-bitcoin?

I am attempting to signal a segwit transaction in rust-bitcoin. To begin with, my transaction setup seems as follows:

let previous_output = OutPoint::new(Txid::from_hex("991ab2b13f6bc6c13002d79d5e9775626a5e7328e14cd16837d50d1cc637dc6a").unwrap(), 0);
let tx_input = TxIn {
    previous_output,
    script_sig: Default::default(),
    sequence: 0xffffffff,
    witness: Default::default()
};

let tx_output = TxOut {
    worth: 4999995000,
    script_pubkey: output_details.script_pubkey() // don't fret about this
};

let mut transaction = Transaction {
    model: 2,
    lock_time: 0,
    enter: vec![tx_input],
    output: vec![tx_output]
};

To be able to signal the transaction (utilizing Schnorr, by the way in which), I extract the sighash as follows:

let signature_hash = transaction.signature_hash(0, &output_details.script_pubkey(), 0); // is that actually essentially the most idiomatic means of passing a sighash flag in rust-bitcoin?
let message = Message::from_slice(&signature_hash.to_vec()).unwrap();

After I print the hex-serialized message, I get the next worth: fa42b9b0f54972b31712b2efbc86db1bf78aa833bc9c969ea7860ef38a25fbaf.

Nonetheless, with a view to signal a segwit transaction, the earlier output’s quantity should even be dedicated to, and I am not seeing a means to do this. So far as I can inform, the sighash I must be signing is actually 61746ec9baa14bbe82586c7f149926b1492871c67dc7fe21e7cfe2f2260a1405.

Lastly, although much less relevantly, if issues had been to work fantastic, this is how my signature course of would conlude:

let signature = private_key.sign_schnorr(message);
let signature_vec = signature.as_ref().to_vec();
transaction.enter[0].witness = Witness::from_vec(vec![signature_vec]);

Thanks prematurely for serving to me determine this out!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments