-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rollapp): refactor rollapp cli to be more useful (#842)
- Loading branch information
Showing
10 changed files
with
829 additions
and
864 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/dymensionxyz/dymension/v3/x/rollapp/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func CmdShowLatestHeight() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "latest-height [rollapp-id]", | ||
Short: "Query the last height of the last UpdateState associated with the specified rollapp-id.", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
clientCtx := client.GetClientContextFromCmd(cmd) | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
argRollappId := args[0] | ||
|
||
argFinalized, err := cmd.Flags().GetBool(FlagFinalized) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
req := &types.QueryGetLatestHeightRequest{ | ||
RollappId: argRollappId, | ||
Finalized: argFinalized, | ||
} | ||
|
||
res, err := queryClient.LatestHeight(context.Background(), req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
cmd.Flags().Bool(FlagFinalized, false, "Indicates whether to return the latest finalized state index") | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/dymensionxyz/dymension/v3/x/rollapp/types" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func (k Keeper) LatestHeight(c context.Context, req *types.QueryGetLatestHeightRequest) (*types.QueryGetLatestHeightResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid request") | ||
} | ||
ctx := sdk.UnwrapSDKContext(c) | ||
|
||
var val types.StateInfoIndex | ||
var found bool | ||
if req.Finalized { | ||
val, found = k.GetLatestFinalizedStateIndex( | ||
ctx, | ||
req.RollappId, | ||
) | ||
} else { | ||
val, found = k.GetLatestStateInfoIndex( | ||
ctx, | ||
req.RollappId, | ||
) | ||
} | ||
if !found { | ||
return nil, status.Error(codes.NotFound, "not found") | ||
} | ||
|
||
state := k.MustGetStateInfo(ctx, req.RollappId, val.Index) | ||
|
||
return &types.QueryGetLatestHeightResponse{ | ||
Height: state.GetLatestHeight(), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.