-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx.go
95 lines (75 loc) · 2.41 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
package cli
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"
"github.com/incubus-network/fanfury-sdk/v2/x/oracle/types"
)
// GetTxCmd returns the CLI transaction commands for the x/oracle module.
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Transaction commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(
GetCmdDelegateFeedConsent(),
AddFundsToRewardPool(),
)
return cmd
}
// GetCmdDelegateFeedConsent returns a CLI command handler to generate or
// broadcast a transaction with a MsgDelegateFeedConsent message.
func GetCmdDelegateFeedConsent() *cobra.Command {
cmd := &cobra.Command{
Use: "delegate-feed-consent [operator] [feeder]",
Args: cobra.ExactArgs(2),
Short: "Delegate oracle feed consent from an operator to another feeder address",
RunE: func(cmd *cobra.Command, args []string) error {
if err := cmd.Flags().Set(flags.FlagFrom, args[0]); err != nil {
return err
}
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
feederAddr, err := sdk.AccAddressFromBech32(args[1])
if err != nil {
return err
}
msg := types.NewMsgDelegateFeedConsent(sdk.ValAddress(clientCtx.GetFromAddress()), feederAddr)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
func AddFundsToRewardPool() *cobra.Command {
cmd := &cobra.Command{
Use: "fund-reward-pool [operator] [amount]",
Args: cobra.ExactArgs(2),
Short: "Send the funds to the oracle reward pool from operator account",
RunE: func(cmd *cobra.Command, args []string) error {
if err := cmd.Flags().Set(flags.FlagFrom, args[0]); err != nil {
return err
}
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
funds, err := sdk.ParseCoinsNormalized(args[1])
if err != nil {
return err
}
msg := types.NewMsgAddFundsToRewardPool(clientCtx.GetFromAddress(), funds)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}