aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/govtool/main.go
blob: 254ffd50b4cdba0a0fe9d4171ab594c48b957262 (plain) (blame)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package main

import (
    "encoding/hex"
    "fmt"
    "math/big"
    "os"

    "github.com/tangerine-network/go-tangerine/cmd/utils"
    "github.com/tangerine-network/go-tangerine/core/vm"
    "github.com/tangerine-network/go-tangerine/rlp"
    coreTypes "github.com/tangerine-network/tangerine-consensus/core/types"
    dkgTypes "github.com/tangerine-network/tangerine-consensus/core/types/dkg"
    "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 "addDKGSuccess":
        var Success []byte
        if err := method.Inputs.Unpack(&Success, arguments); err != nil {
            utils.Fatalf("%s", err)
        }
        var success dkgTypes.Success
        if err := rlp.DecodeBytes(Success, &success); err != nil {
            utils.Fatalf("%s", err)
        }
        fmt.Println(success)
    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)
    }
}