forked from eoscanada/eosc
/
txId.go
40 lines (30 loc) · 841 Bytes
/
txId.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
// Copyright © 2018 EOS Canada <info@eoscanada.com>
package cmd
import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
eos "github.com/sebastianmontero/eos-go"
"github.com/spf13/cobra"
)
var txIDCmd = &cobra.Command{
Use: "id [transaction.json]",
Short: "Print the transaction ID for a given transaction file.",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
filename := args[0]
cnt, err := ioutil.ReadFile(filename)
errorCheck("reading file", err)
var stx *eos.SignedTransaction
errorCheck("parsing JSON content", json.Unmarshal(cnt, &stx))
ptx, err := stx.Pack(eos.CompressionNone)
errorCheck("packing transaction", err)
ptxID, err := ptx.ID()
errorCheck("transaction ID", err)
fmt.Println(hex.EncodeToString(ptxID))
},
}
func init() {
txCmd.AddCommand(txIDCmd)
}