Skip to content

Commit

Permalink
feat(oracle): cli commands for prevoting / voting (#1220)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamewozniak committed Aug 5, 2022
1 parent f42bbfe commit 857c28d
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [1188](https://github.com/umee-network/umee/pull/1188) Add `liquidity`, `maximum_borrow`, `maximum_collateral`, `minimum_liquidity`, `available_withdraw`, `available_collateralize`, and `utoken_supply` fields to market summary.
- [1203](https://github.com/umee-network/umee/pull/1203) Add Swagger docs.
- [1212](https://github.com/umee-network/umee/pull/1212) Add `util/checkers` utility package providing common check / validation functions.
- [1220](https://github.com/umee-network/umee/pull/1220) Submit oracle prevotes / vote txs via the CLI.

### Improvements

Expand Down
86 changes: 86 additions & 0 deletions x/oracle/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func GetTxCmd() *cobra.Command {

cmd.AddCommand(
GetCmdDelegateFeedConsent(),
GetCmdAggregateExchangeRatePrevote(),
GetCmdAggregateExchangeRateVote(),
)

return cmd
Expand Down Expand Up @@ -53,6 +55,90 @@ func GetCmdDelegateFeedConsent() *cobra.Command {

msg := types.NewMsgDelegateFeedConsent(sdk.ValAddress(clientCtx.GetFromAddress()), feederAddr)

if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}

// GetCmdAggregateExchangeRatePrevote creates a Cobra command to generate or
// broadcast a transaction with a MsgAggregateExchangeRatePrevote message.
func GetCmdAggregateExchangeRatePrevote() *cobra.Command {
cmd := &cobra.Command{
Use: "exchange-rate-prevote [hash]",
Args: cobra.ExactArgs(1),
Short: "Submit an exchange rate prevote with a hash",
Long: fmt.Sprintf(`Submit an exchange rate prevote with a hash as a hex string
representation of a byte array.
Ex: umeed tx oracle exchange-rate-prevote %s --from alice`,
"19c30cf9ea8aa0e0b03904162cadec0f2024a76d"),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

hash, err := types.AggregateVoteHashFromHexString(args[0])
if err != nil {
return err
}

msg := types.NewMsgAggregateExchangeRatePrevote(
hash,
clientCtx.GetFromAddress(),
sdk.ValAddress(clientCtx.GetFromAddress()),
)

if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}

// GetCmdAggregateExchangeRateVote creates a Cobra command to generate or
// broadcast a transaction with a NewMsgAggregateExchangeRateVote message.
func GetCmdAggregateExchangeRateVote() *cobra.Command {
cmd := &cobra.Command{
Use: "exchange-rate-vote [salt] [exchange-rates]",
Args: cobra.ExactArgs(2),
Short: "Submit an exchange rate vote with the salt and exchange rate string",
Long: fmt.Sprintf(`Submit an exchange rate vote with the salt of the previous hash, and the
exchange rate string previously used in the hash.
Ex: umeed tx oracle exchange-rate-vote %s %s --from alice`,
"0cf33fb528b388660c3a42c3f3250e983395290b75fef255050fb5bc48a6025f",
"foo:1.0,bar:1232.123",
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgAggregateExchangeRateVote(
args[0],
args[1],
clientCtx.GetFromAddress(),
sdk.ValAddress(clientCtx.GetFromAddress()),
)

if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
Expand Down

0 comments on commit 857c28d

Please sign in to comment.