Skip to content

Commit

Permalink
add opchild querys & output index to propose output
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-cha committed Jul 16, 2024
1 parent e4dc6f9 commit dff654a
Show file tree
Hide file tree
Showing 12 changed files with 583 additions and 772 deletions.
691 changes: 346 additions & 345 deletions api/opinit/ophost/v1/tx.pulsar.go

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions proto/opinit/ophost/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,14 @@ message MsgProposeOutput {

string proposer = 1 [(gogoproto.moretags) = "yaml:\"proposer\"", (cosmos_proto.scalar) = "cosmos.AddressString"];
uint64 bridge_id = 2 [(gogoproto.moretags) = "yaml:\"bridge_id\""];
uint64 l2_block_number = 3 [(gogoproto.moretags) = "yaml:\"l2_block_number\""];
bytes output_root = 4 [(gogoproto.moretags) = "yaml:\"output_root\""];
uint64 output_index = 3 [(gogoproto.moretags) = "yaml:\"output_index\""];
uint64 l2_block_number = 4 [(gogoproto.moretags) = "yaml:\"l2_block_number\""];
bytes output_root = 5 [(gogoproto.moretags) = "yaml:\"output_root\""];
}

// MsgProposeOutputResponse returns deposit result data
message MsgProposeOutputResponse {
uint64 output_index = 1;

}

////////////////////////////
Expand Down
46 changes: 46 additions & 0 deletions x/opchild/autocli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package opchild

import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
opchildv1 "github.com/initia-labs/OPinit/api/opinit/opchild/v1"
)

// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface.
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
return &autocliv1.ModuleOptions{
Query: &autocliv1.ServiceCommandDescriptor{
Service: opchildv1.Query_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "Validator",
Use: "validator [validator-addr]",
Short: "Query a validator",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "validator_addr"},
},
},
{
RpcMethod: "Validators",
Use: "validators",
Short: "Query for all validators",
},
{
RpcMethod: "Params",
Use: "params",
Short: "Query the current opchild parameters information",
},
{
RpcMethod: "NextL1Sequence",
Use: "next-l1-sequence",
Short: "Query the next l1 sequence",
},
{
RpcMethod: "NextL2Sequence",
Use: "next-l2-sequence",
Short: "Query the next l2 sequence",
},
},
EnhanceCustomCommand: true, // We still have manual commands in gov that we want to keep
},
}
}
137 changes: 1 addition & 136 deletions x/opchild/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package cli

import (
"fmt"
"strings"

"cosmossdk.io/core/address"
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/initia-labs/OPinit/x/opchild/types"
)

Expand All @@ -24,135 +18,6 @@ func GetQueryCmd(vc address.Codec) *cobra.Command {
RunE: client.ValidateCmd,
}

opchildQueryCmd.AddCommand(
GetCmdQueryValidator(vc),
GetCmdQueryValidators(),
GetCmdQueryParams(),
)

opchildQueryCmd.AddCommand()
return opchildQueryCmd
}

// GetCmdQueryValidator implements the validator query command.
func GetCmdQueryValidator(vc address.Codec) *cobra.Command {
bech32PrefixValAddr := sdk.GetConfig().GetBech32ValidatorAddrPrefix()

cmd := &cobra.Command{
Use: "validator [validator-addr]",
Short: "Query a validator",
Long: strings.TrimSpace(
fmt.Sprintf(`Query details about an individual validator.
Example:
$ %s query opchild validator %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
`,
version.AppName, bech32PrefixValAddr,
),
),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

_, err = vc.StringToBytes(args[0])
if err != nil {
return err
}

params := &types.QueryValidatorRequest{ValidatorAddr: args[0]}
res, err := queryClient.Validator(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(&res.Validator)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQueryValidators implements the query all validators command.
func GetCmdQueryValidators() *cobra.Command {
cmd := &cobra.Command{
Use: "validators",
Short: "Query for all validators",
Args: cobra.NoArgs,
Long: strings.TrimSpace(
fmt.Sprintf(`Query details about all validators on a network.
Example:
$ %s query opchild validators
`,
version.AppName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

result, err := queryClient.Validators(cmd.Context(), &types.QueryValidatorsRequest{
// Leaving status empty on purpose to query all validators.
Pagination: pageReq,
})
if err != nil {
return err
}

return clientCtx.PrintProto(result)
},
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "validators")

return cmd
}

// GetCmdQueryParams implements the params query command.
func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Args: cobra.NoArgs,
Short: "Query the current opchild parameters information",
Long: strings.TrimSpace(
fmt.Sprintf(`Query values set as opchild parameters.
Example:
$ %s query opchild params
`,
version.AppName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(&res.Params)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
85 changes: 0 additions & 85 deletions x/opchild/client/cli/query_test.go

This file was deleted.

Loading

0 comments on commit dff654a

Please sign in to comment.