Bitcoin

transaction – help with serializing dictionary digest for txid calculation

I tried serializing the transaction for txid calculation and got this predigest:

 01000000      // version
 01            // input count
 a6026e772ab727c8619986490fceaa5a072344ebe2b9d666deb1d8de72083cb3 // outpoint.txid
 01000000      // outpoint.index
 00            // scriptSig length
 fdffffff     // sequence
 02           // output count
 b49cac0000000000   // output.value
 16          // scriptPubKey length
 00146158eebd1aec7512fc33e9cfb95f388fd3a62617   // scriptPubKey
 b01f480600000000   // output.value
 16          // scriptPubKey length
 0014373f3051c8c409bf1e12ddb2bd4165c7c0ef9310 // scriptPubKey
 00000000    // locktime

Raw: 0100000001a6026e772ab727c8619986490fceaa5a072344ebe2b9d666deb1d8de72083cb30100000000fdffffff02b49cac00000000001600146158eebd1aec7512fc33e9cfb95f388fd3a62617b01f480600000000160014373f3051c8c409bf1e12ddb2bd4165c7c0ef931000000000

This is the deal.


  "version": 1,
  "locktime": 0,
  "vin": (
    
      "txid": "b33c0872ded8b1de66d6b9e2eb4423075aaace0f49869961c827b72a776e02a6",
      "vout": 1,
      "prevout": 
        "scriptpubkey": "0014833861497915c51c113d32010aec8640eae74a1b",
        "scriptpubkey_asm": "OP_0 OP_PUSHBYTES_20 833861497915c51c113d32010aec8640eae74a1b",
        "scriptpubkey_type": "v0_p2wpkh",
        "scriptpubkey_address": "bc1qsvuxzjtezhz3cyfaxgqs4myxgr4wwjsm4cfzxt",
        "value": 116704000
      ,
      "scriptsig": "",
      "scriptsig_asm": "",
      "witness": (
        "3045022100a02e43fcb331314b21df61b18a051a69c83ba01ea51e811ea525ca73fc2fa3ab02203ffbbd97984b3ad59f9e19ff17141ce2edee46921db86bb8a8fb0bddfa9e85ee01",
        "031af9d9a891b3b7dfd7a03a6470dc2a530edf28f30903656cce75f42e0eb4ac4a"
      ),
      "is_coinbase": false,
      "sequence": 4294967293
    
  ),
  "vout": (
    
      "scriptpubkey": "00146158eebd1aec7512fc33e9cfb95f388fd3a62617",
      "scriptpubkey_asm": "OP_0 OP_PUSHBYTES_20 6158eebd1aec7512fc33e9cfb95f388fd3a62617",
      "scriptpubkey_type": "v0_p2wpkh",
      "scriptpubkey_address": "bc1qv9vwa0g6a3639lpna88mjhec3lf6vfshwfljge",
      "value": 11312308
    ,
    
      "scriptpubkey": "0014373f3051c8c409bf1e12ddb2bd4165c7c0ef9310",
      "scriptpubkey_asm": "OP_0 OP_PUSHBYTES_20 373f3051c8c409bf1e12ddb2bd4165c7c0ef9310",
      "scriptpubkey_type": "v0_p2wpkh",
      "scriptpubkey_address": "bc1qxulnq5wgcsym78sjmket6st9clqwlycsz8q6dh",
      "value": 105390000
    
  )

I tried to explain the change in endianness and got this txid (how it shows up in cli):

698675daa46546737422856fe2eb81fcb4740eb19d1f4cf7837c27603c9f9ce7

But the correct txid is:

fff53b0fda0ab690ddaa23c84536e0d364a736bb93137a76ebf5d78f57cdd32f

Related Articles

Back to top button