-
Notifications
You must be signed in to change notification settings - Fork 1
/
tx.go
97 lines (77 loc) · 2.58 KB
/
tx.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
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
package cli
import (
"fmt"
"os"
sdk "github.com/cosmos/cosmos-sdk/types"
govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/spf13/cobra"
mintrest "github.com/Timwood0x10/sei-chain/x/mint/client/rest"
"github.com/Timwood0x10/sei-chain/x/mint/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
)
var UpdateMinterHandler = govclient.NewProposalHandler(MsgUpdateMinterProposalCmd, mintrest.UpdateResourceDependencyProposalRESTHandler)
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
updateMinterProposalCmd := MsgUpdateMinterProposalCmd()
flags.AddTxFlagsToCmd(updateMinterProposalCmd)
cmd.AddCommand(updateMinterProposalCmd)
return cmd
}
func MsgUpdateMinterProposalCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "update-minter [proposal-file]",
Args: cobra.ExactArgs(1),
Short: "Submit an UpdateMinter proposal",
Long: "Submit a proposal to update the current minter. \n" +
"E.g. $ seid tx gov submit-proposal update-minter [proposal-file]\n" +
"The proposal file should contain the following:\n" +
"{\n" +
"\t title: [title],\n" +
"\t description: [description],\n" +
"\t minter: [new minter object] \n" +
"}",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
proposal := types.UpdateMinterProposal{}
contents, err := os.ReadFile(args[0])
if err != nil {
return err
}
clientCtx.Codec.MustUnmarshalJSON(contents, &proposal)
from := clientCtx.GetFromAddress()
content := types.UpdateMinterProposal{
Title: proposal.Title,
Description: proposal.Description,
Minter: proposal.Minter,
}
depositInput, err := cmd.Flags().GetString(govcli.FlagDeposit)
if err != nil {
return err
}
deposit, err := sdk.ParseCoinsNormalized(depositInput)
if err != nil {
return err
}
msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, from)
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(govcli.FlagDeposit, "", "The proposal deposit")
return cmd
}