tx := btcutil.NewTx(&wire.MsgTx{ Version: 1, TxIn: []*wire.TxIn{{ PreviousOutPoint: wire.OutPoint{ Hash: btcutil.TxHash(prevTx), Index: 0, }, SignatureScript: []byte{}, Sequence: 0, }}, TxOut: []*wire.TxOut{{ Value: 1000, PkScript: []byte{}, }}, LockTime: 0, })
msgTx := &wire.MsgTx{ Version: 1, TxIn: []*wire.TxIn{{ PreviousOutPoint: wire.OutPoint{ Hash: btcutil.TxHash(prevTx), Index: 0, }, SignatureScript: []byte{}, Sequence: 0, }}, TxOut: []*wire.TxOut{{ Value: 1000, PkScript: []byte{}, }}, LockTime: 0, } hash, err := msgTx.TxSha() if err != nil { log.Fatal(err) } msgTxHash := btcutil.NewTxShaHash(hash[:])In summary, the `Tx` and `MsgTx` types in the `github.com/conformal/btcutil` package provide a convenient way to work with Bitcoin transactions in Go.