forked from tanitall/memo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_transaction.go
44 lines (40 loc) · 1.01 KB
/
parse_transaction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cmd
import (
"bytes"
"encoding/hex"
"fmt"
"github.com/jchavannes/btcd/txscript"
"github.com/jchavannes/btcd/wire"
"github.com/jchavannes/jgo/jerr"
"github.com/spf13/cobra"
)
var parseTransactionCmd = &cobra.Command{
Use: "parse-transaction",
RunE: func(c *cobra.Command, args []string) error {
if len(args) < 1 {
return jerr.New("not enough arguments")
}
var txHex = args[0]
rawHex, err := hex.DecodeString(txHex)
if err != nil {
jerr.Get("error decoding hex", err).Print()
return nil
}
msg := wire.NewMsgTx(1)
pr := bytes.NewBuffer(rawHex)
err = msg.BtcDecode(pr, 0)
str, err := txscript.DisasmString(msg.TxOut[1].PkScript)
if err != nil {
jerr.Get("error disassembling data", err).Print()
return nil
}
fmt.Printf("disassembled output: %s\n", str)
pushedData, err := txscript.PushedData(msg.TxOut[1].PkScript)
if err != nil {
jerr.Get("error getting push data", err).Print()
return nil
}
fmt.Printf("pushedData: %#v\n", pushedData)
return nil
},
}