• About
  • FAQ
  • Earn Bitcoin while Surfing the net
  • Buy & Sell Crypto on Paxful
Newsletter
Approx Foundation
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
Approx Foundation
No Result
View All Result
Home Bitcoin

Incorrect Transaction ID being calculated for a p2wpkh transaction

Moussa by Moussa
February 13, 2024
in Bitcoin
0
peer discovery – how to obtain the IP addresses of nodes for mining pools?
189
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter


RAW Signed transaction (signet)

020000000001013ccb46c8366e39d7ff36df4f199813aa8b9dc4bed143a0eb9205cf698ca16298e400000000ffffffff0240420f00000000002200202d67ce38ba266a68f0f7c4668e9d0f5584c6da7c454bcc2368bf9fff10135157a086010000000000160014d765749aa66430b85765bdedee488f5fe3c82a8e02483045022100f71bd596f18d3caf1297a74f5619cd6c823d58acaf5f9172bea7d7d6ef82cfd502206c7c7960accd4409cccb1ca97d8268af12664de50b905d1c3579e6237c0fb823012102d3428014dd5ccf1927c6dc164e6324e2c0945a9f50b84769592e195ae6a40e8a00000000

Transaction id returned .

    "txid": "1d81e1dae9d956fd61cf79efa6a64de11465d6a1ead46e24ba043e278360fb35",
    "wtxid": "d9e69e8d05c61c78796b2d73b731a705334e07c013e7e714e10eaf45885a144c"

Transaction id calculated by following Raw_tx.

22d008e988b168165bd6c06dc4200ad57d456f1b152d25e540e75e38bb023c40

Transaction id calculated by hashing the Raw signed transaction

82fbc313fec14a7cf05309544b24bc97dc785bb82e4a9a713bb6e8d5f3cf4aeb

I have followed the above transaction formats. The signed raw transaction follows the specification given in bicoin developers raw transaction format.

Given are the implementation codes in Rust

fn get_txid(inputs: Vec<Vec<u8>>, outputs: Vec<Vec<u8>>) -> [u8; 32] {
    let mut tx = Vec::new();

    //adding version
    let version: u32 = 0x00000002;
    tx.extend_from_slice(&version.to_le_bytes());

    let inputs_length: u32 = inputs.len() as u32;
    tx.extend_from_slice(&inputs_length.to_le_bytes());

    for input in inputs {
        tx.extend_from_slice(&input);
    }

    let outputs_length: u32 = outputs.len() as u32;
    tx.extend_from_slice(&outputs_length.to_le_bytes());

    for output in outputs {
        tx.extend_from_slice(&output);
    }

    let locktime: u32 = 0x00000000;
    tx.extend_from_slice(&locktime.to_le_bytes());
    let txid = sha256_hash(&sha256_hash(&tx));
    //output

    let tx_array: [u8; 32] = match txid.try_into() {
        Ok(arr) => arr,
        Err(_) => panic!("Expected a Vec of length 32, but it was {}", tx.len()),
    };

    // reverse txid
    let mut reversed_txid = [0; 32];
    for i in 0..32 {
        reversed_txid[i] = tx_array[31 - i];
    }

    reversed_txid
}

Output serialization

fn output_from_options(script: &[u8], value: u32) -> Vec<u8> {
    
    let mut output = Vec::new();
    let valhue: u64 = value as u64;
    let value_in_8_bytes_in_little_endian = valhue.to_le_bytes();
    output.extend_from_slice(&value_in_8_bytes_in_little_endian);

    let script_length = script.len() as u64; 
    let script_length_varint = turn_to_varint(script_length);
    
    output.extend_from_slice(&script_length_varint);
    output.extend_from_slice(script); //scriptpubkey {p2wpkh and p2wsh}
    output

    //OK
}

Input Serialization

fn input_from_utxo(txid: &[u8], index: u32) -> Vec<u8> {
    let mut input = Vec::new();

    //txid
    let reversed_txid: Vec<u8> = txid.iter().rev().cloned().collect();
    input.extend_from_slice(&reversed_txid);

    //index
    let index_in_little_endian_bytes = index.to_le_bytes();  // fixed 4 bytes
    input.extend_from_slice(&index_in_little_endian_bytes);
    
    //script length (default is zero for us)
    input.push(0x00);

    //sequence
    let sequence: u32 = 0xffffffff;
    input.extend_from_slice(&sequence.to_le_bytes());

    input

    //OK
}



Source link

Related articles

Transactions confirmed on Blockchain but nothing received to my Blockchain wallet

August 25, 2026
BlackRock’s IBIT Takes the Lead as Bitcoin ETFs Draw $337.6 Million

BlackRock’s IBIT Takes the Lead as Bitcoin ETFs Draw $337.6 Million

August 25, 2026
Share76Tweet47

Related Posts

Transactions confirmed on Blockchain but nothing received to my Blockchain wallet

by Moussa
August 25, 2026
0

I need some info/help. I have sent some Bitcoins to my Blockchain wallet. They have all be confirmed and done...

BlackRock’s IBIT Takes the Lead as Bitcoin ETFs Draw $337.6 Million

BlackRock’s IBIT Takes the Lead as Bitcoin ETFs Draw $337.6 Million

by Moussa
August 25, 2026
0

In the latest Bitcoin ETF News, BlackRock’s iShares Bitcoin Trust (IBIT) recorded $208.9 million in net inflows on August 24,...

TAC Sidechain Halts After Supply Exploit As TON Mainnet Remains Separate

TAC Sidechain Halts After Supply Exploit As TON Mainnet Remains Separate

by Moussa
August 25, 2026
0

Trusted Editorial content, reviewed by leading industry experts and seasoned editors. Ad Disclosure TAC, a Cosmos-based EVM sidechain connected to...

Treasury Proposes Stablecoin Licensing Rules Under GENIUS Act

Treasury Proposes Stablecoin Licensing Rules Under GENIUS Act

by Moussa
August 25, 2026
0

The US Treasury Department has proposed new licensing rules for payment stablecoin issuers under Section 3 of the GENIUS Act,...

Bitcoin Treasury Strategy Posts $8.2 Billion Loss

Strategy Skips Bitcoin Buy, Establishes New Dollar Reserve

by Moussa
August 25, 2026
0

Bitcoin treasury Strategy has established a new cash reserve that it will use to buy Bitcoin, according to a Monday...

Load More

youssufi.com

sephina.com

[vc_row full_width="stretch_row" parallax="content-moving" vc_row_background="" background_repeat="no-repeat" background_position="center center" footer_scheme="dark" css=".vc_custom_1517813231908{padding-top: 60px !important;padding-bottom: 30px !important;background-color: #191818 !important;background-position: center;background-repeat: no-repeat !important;background-size: cover !important;}" footer_widget_title_color="#fcbf46" footer_button_bg="#fcb11e"][vc_column width="1/4"]

We bring you the latest in Crypto News

[/vc_column][vc_column width="1/4"][vc_wp_categories]
[/vc_column][vc_column width="1/4"][vc_wp_tagcloud taxonomy="post_tag"][/vc_column][vc_column width="1/4"]

Newsletter

[vc_raw_html]JTNDcCUzRSUzQ2RpdiU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wdXQlMjB0eXBlJTNEJTIyY2hlY2tib3glMjIlMjBuYW1lJTNEJTIybnklMjIlMjByZXF1aXJlZCUyMGNsYXNzJTNEJTIydG5wLXByaXZhY3klMjIlM0UlQzIlQTBCeSUyMGNvbnRpbnVpbmclMkMlMjB5b3UlMjBhY2NlcHQlMjB0aGUlMjBwcml2YWN5JTIwcG9saWN5JTNDJTJGbGFiZWwlM0UlM0MlMkZkaXYlM0UlM0NkaXYlMjBjbGFzcyUzRCUyMnRucC1maWVsZCUyMHRucC1maWVsZC1idXR0b24lMjIlM0UlM0NpbnB1dCUyMGNsYXNzJTNEJTIydG5wLXN1Ym1pdCUyMiUyMHR5cGUlM0QlMjJzdWJtaXQlMjIlMjB2YWx1ZSUzRCUyMlN1YnNjcmliZSUyMiUyMCUzRSUwQSUzQyUyRmRpdiUzRSUwQSUzQyUyRmZvcm0lM0UlMEElM0MlMkZkaXYlM0UlM0NiciUyRiUzRSUzQyUyRnAlM0U=[/vc_raw_html][/vc_column][/vc_row]
No Result
View All Result
  • Contact Us
  • Homepages
  • Business
  • Guide

© 2024 APPROX FOUNDATION - The Crypto Currency News