Friday, December 13, 2024
HomeBitcoinsegregated witness - Segwit transaction in golang

segregated witness – Segwit transaction in golang


  • from wif I derived compressed pub key: “035476e55521c97cf0489e6c57893a99d67e84d306a69e6b6904f324c11b3cef8d”.

  • created witness program: “813798fcae182d1a36c6b4bb5f69e03bb9ec4124”.

  • created script: “0014813798fcae182d1a36c6b4bb5f69e03bb9ec4124” and sigscript from script which must be specified to spend this ouput: “160014813798fcae182d1a36c6b4bb5f69e03bb9ec4124”.

  • added tx enter: {hash: “863fea23ba1c176bda5e360b0be25cacc405877aa3e46a3e1c60196c3b6cd7b6”, vout: 0, signatureScript: scriptSig, witeness: nil}

  • created pkscript for deal with “14s9ocrbTX3ZCybtcN1jmtdxxJwKuyM3Em” (p2sh-p2wpkh): “a914809800f62119afdcf2317882eda5efd7a9a2163487”.

  • added txout {quantity: 11000, scriptPubKey: pkscript}

  • calculated txSigHashes := txscript.NewTxSigHashes(tx)

  • decoded utxo subscript into bytes: “a914bb4d332112bde9787ac2da5954ee5a2c5fbada6987”.

  • derived witness signature: wit := txscript.WitnessSignature(tx, txSigHashes, 0, quantity, subscript, txscript.SigHashAll, wif.PrivKey, true)
    outcome: “3045022100bae83fd9e87751350a09bc4c120b29decadb13fb389541c3025a8982906602d5022005dc688901fd27b749cfd4ce14a62587f267a070984654271454e88cc3f9ed4e01 035476e55521c97cf0489e6c57893a99d67e84d306a69e6b6904f324c11b3cef8d”.

  • added witness signature to tx.TxIn[0].Witness

  • Serializied signed tx: “01000000000101b6d76c3b6c19601c3e6ae4a37a8705c4ac5ce20b0b365eda6b171cba23ea3f860000000017160014813798fcae182d1a36c6b4bb5f69e03bb9ec4124ffffffff01f82a000000000000434104b2534d287f2d9fa908319557298591143fecbd3f6497d6d11f283b80c3248c35f580ff376805418c3610256bc102c0beb3e9f745d493aed81127f5d4a4921bebac02483045022100bae83fd9e87751350a09bc4c120b29decadb13fb389541c3025a8982906602d5022005dc688901fd27b749cfd4ce14a62587f267a070984654271454e88cc3f9ed4e0121035476e55521c97cf0489e6c57893a99d67e84d306a69e6b6904f324c11b3cef8d00000000”

  • Even when I adopted all the foundations to create this transaction any attempt to push it into mainnet (through Blockcypher and different providers) failed due to this error: “Error validating transaction: Error operating script for enter 0 referencing 863fea23ba1c176bda5e360b0be25cacc405877aa3e46a3e1c60196c3b6cd7b6 at 0: Script was NOT verified efficiently”

    So my query is the place have I unsuitable completed? Which step is unsuitable and learn how to do it in a proper manner?

    RELATED ARTICLES

    Most Popular

    Recent Comments