-
Notifications
You must be signed in to change notification settings - Fork 23
/
getmpt.go
45 lines (39 loc) · 1.06 KB
/
getmpt.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
45
package cmd
import (
"bytes"
"encoding/json"
"fmt"
"log"
"strings"
"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/spf13/cobra"
)
var getMptKeyCommand = &cobra.Command{
Use: "get-mpt",
Short: "Directly view blockchain data",
Long: `Directly view blockchain data from MPT key`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
if cmd.Flags().Changed("key") == false {
log.Fatal("Required Mpt key missing\n")
}
key := cmd.Flag("key").Value.String()
jsonBytes, err := sdk.GetMptData(key)
if err != nil {
log.Fatalf("Failed to get Mpt key: %v\n", err)
}
var indented bytes.Buffer
err = json.Indent(&indented, jsonBytes, "", "\t")
if err != nil {
log.Fatalf("Result %s baddly formated: %v\n", string(jsonBytes), err)
}
noBackSlash := strings.Replace(indented.String(), "\\", "", -1)
fmt.Println(key, ": ", noBackSlash)
return
},
}
func init() {
rootCmd.AddCommand(getMptKeyCommand)
getMptKeyCommand.PersistentFlags().String("key", "", "Key into MPT datastore")
getMptKeyCommand.MarkFlagRequired("key")
}