aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-04-13 17:07:27 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-15 22:09:55 +0800
commitc0442fcd0a65acbe6e7b32316e8531863838a365 (patch)
tree74d394ee5ca17362b61c3ac59aebc6b75d3442cf /cmd
parent4ad9119a92ea63b0568f1100729a8cf377adfe2a (diff)
downloadgo-tangerine-c0442fcd0a65acbe6e7b32316e8531863838a365.tar.gz
go-tangerine-c0442fcd0a65acbe6e7b32316e8531863838a365.tar.zst
go-tangerine-c0442fcd0a65acbe6e7b32316e8531863838a365.zip
cmd: add govtool for decoding governance input (#361)
Diffstat (limited to 'cmd')
-rw-r--r--cmd/govtool/main.go145
1 files changed, 145 insertions, 0 deletions
diff --git a/cmd/govtool/main.go b/cmd/govtool/main.go
new file mode 100644
index 000000000..239c95003
--- /dev/null
+++ b/cmd/govtool/main.go
@@ -0,0 +1,145 @@
+package main
+
+import (
+ "encoding/hex"
+ "fmt"
+ "math/big"
+ "os"
+
+ coreTypes "github.com/dexon-foundation/dexon-consensus/core/types"
+ dkgTypes "github.com/dexon-foundation/dexon-consensus/core/types/dkg"
+ "github.com/dexon-foundation/dexon/cmd/utils"
+ "github.com/dexon-foundation/dexon/core/vm"
+ "github.com/dexon-foundation/dexon/rlp"
+ "gopkg.in/urfave/cli.v1"
+)
+
+// Git SHA1 commit hash of the release (set via linker flags)
+var gitCommit = ""
+
+var app *cli.App
+
+func init() {
+ app = utils.NewApp(gitCommit, "DEXON governance tool")
+ app.Commands = []cli.Command{
+ commandDecodeInput,
+ }
+}
+
+func decodeInput(ctx *cli.Context) error {
+ inputHex := ctx.Args().First()
+ if inputHex == "" {
+ utils.Fatalf("no input specified")
+ }
+
+ if inputHex[:2] == "0x" {
+ inputHex = inputHex[2:]
+ }
+
+ input, err := hex.DecodeString(inputHex)
+ if err != nil {
+ utils.Fatalf("failed to decode input")
+ }
+
+ // Parse input.
+ method, exists := vm.GovernanceABI.Sig2Method[string(input[:4])]
+ if !exists {
+ utils.Fatalf("invalid method")
+ }
+
+ arguments := input[4:]
+
+ switch method.Name {
+ case "addDKGComplaint":
+ var Complaint []byte
+ if err := method.Inputs.Unpack(&Complaint, arguments); err != nil {
+ utils.Fatalf("%s", err)
+ }
+ var comp dkgTypes.Complaint
+ if err := rlp.DecodeBytes(Complaint, &comp); err != nil {
+ utils.Fatalf("%s", err)
+ }
+ fmt.Printf("Complaint: %+v\n", comp)
+ case "addDKGMasterPublicKey":
+ var PublicKey []byte
+ if err := method.Inputs.Unpack(&PublicKey, arguments); err != nil {
+ utils.Fatalf("%s", err)
+ }
+ var mpk dkgTypes.MasterPublicKey
+ if err := rlp.DecodeBytes(PublicKey, &mpk); err != nil {
+ utils.Fatalf("%s", err)
+ }
+ fmt.Printf("MasterPublicKey: %+v\n", mpk)
+ case "addDKGMPKReady":
+ var MPKReady []byte
+ if err := method.Inputs.Unpack(&MPKReady, arguments); err != nil {
+ utils.Fatalf("%s", err)
+ }
+ var ready dkgTypes.MPKReady
+ if err := rlp.DecodeBytes(MPKReady, &ready); err != nil {
+ utils.Fatalf("%s", err)
+ }
+ fmt.Printf("MPKReady: %+v\n", ready)
+ case "addDKGFinalize":
+ var Finalize []byte
+ if err := method.Inputs.Unpack(&Finalize, arguments); err != nil {
+ utils.Fatalf("%s", err)
+ }
+ var finalize dkgTypes.Finalize
+ if err := rlp.DecodeBytes(Finalize, &finalize); err != nil {
+ utils.Fatalf("%s", err)
+ }
+ fmt.Println(finalize)
+ case "report":
+ args := struct {
+ Type *big.Int
+ Arg1 []byte
+ Arg2 []byte
+ }{}
+ if err := method.Inputs.Unpack(&args, arguments); err != nil {
+ utils.Fatalf("%s", err)
+ }
+ switch args.Type.Uint64() {
+ case vm.FineTypeForkVote:
+ vote1 := new(coreTypes.Vote)
+ if err := rlp.DecodeBytes(args.Arg1, vote1); err != nil {
+ utils.Fatalf("%s", err)
+ }
+ vote2 := new(coreTypes.Vote)
+ if err := rlp.DecodeBytes(args.Arg2, vote2); err != nil {
+ utils.Fatalf("%s", err)
+ }
+ fmt.Printf("Vote1: %+v\n", vote1)
+ fmt.Printf("Vote2: %+v\n", vote2)
+ case vm.FineTypeForkBlock:
+ block1 := new(coreTypes.Block)
+ if err := rlp.DecodeBytes(args.Arg1, block1); err != nil {
+ utils.Fatalf("%s", err)
+ }
+ block2 := new(coreTypes.Block)
+ if err := rlp.DecodeBytes(args.Arg2, block2); err != nil {
+ utils.Fatalf("%s", err)
+ }
+ fmt.Printf("Block1: %+v\n", block1)
+ fmt.Printf("Block2: %+v\n", block2)
+ }
+ default:
+ fmt.Printf("Unsupported method: %s\n", method.Name)
+ }
+ return nil
+}
+
+var commandDecodeInput = cli.Command{
+ Name: "decode-input",
+ Usage: "decode governance input",
+ ArgsUsage: "[ <hex-data> ]",
+ Description: `decode governance tx input`,
+ Action: decodeInput,
+}
+
+func main() {
+ if err := app.Run(os.Args); err != nil {
+ fmt.Fprintln(os.Stderr, err)
+ os.Exit(1)
+ }
+}