Last active
August 22, 2019 18:57
-
-
Save Varunram/34e92107cb00f9679d97c02acb784a07 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import ( | |
"encoding/hex" | |
"log" | |
// "github.com/btcsuite/btcd/txscript" | |
"github.com/btcsuite/btcd/chaincfg/chainhash" | |
"github.com/btcsuite/btcd/wire" | |
) | |
func main() { | |
tx := wire.NewMsgTx(2) | |
opBytes, err := hex.DecodeString("525fc8fea737c827d600b09fcbb002e518d5b9498230c0f596ea1ba60358cc20") | |
if err != nil { | |
log.Fatal(err) | |
} | |
var opHash chainhash.Hash | |
opHash.SetBytes(opBytes) | |
op := wire.OutPoint{ | |
Hash: opHash, | |
Index: 0, | |
} | |
witness1, err := hex.DecodeString("3044022009ee2956dfe779c8120db092c86d8fc8d95741a193231151a203ed246444fbcd02203bec6d837a7d11e69375a4130bd56251fccbbdd262ed6ba4bb693310209bc33401") | |
if err != nil { | |
log.Fatal(err) | |
} | |
witness2, err := hex.DecodeString("039ff0c4745bf9b5b3b85ddacff408b7d6288f832a53bc016267d5f5b6a52f92c4") | |
if err != nil { | |
log.Fatal(err) | |
} | |
scriptSig, err := hex.DecodeString("1600143e33e3c857f5e4374eb16c65149eb9eeeb5bd7ce") | |
if err != nil { | |
log.Fatal(err) | |
} | |
witness := [][]byte{witness1, witness2} | |
txIn := wire.TxIn{ | |
PreviousOutPoint: op, | |
Witness: witness, | |
Sequence: 0xffffffff, | |
SignatureScript: scriptSig, | |
} | |
scriptPubKey1, err := hex.DecodeString("a91402edb870b533709fc15643eb24e94b7d31bea22787") | |
if err != nil { | |
log.Fatal(err) | |
} | |
txOut1 := wire.NewTxOut(int64(250250), scriptPubKey1) | |
scriptPubKey2, err := hex.DecodeString("76a914d268b87b79af4c5ab430464df058ece832b98a4988ac") | |
if err != nil { | |
log.Fatal(err) | |
} | |
txOut2 := wire.NewTxOut(int64(2750), scriptPubKey2) | |
tx.AddTxIn(&txIn) | |
tx.AddTxOut(txOut1) | |
tx.AddTxOut(txOut2) | |
tx.LockTime = 0 | |
log.Println(tx.WitnessHash()) | |
log.Println(tx.TxHash()) | |
log.Println(tx.SerializeSize()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment