Skip to content

Commit

Permalink
Add gasfree params querying, general cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianBorst committed Mar 13, 2024
1 parent eaffc52 commit 784a083
Show file tree
Hide file tree
Showing 10 changed files with 815 additions and 20 deletions.
7 changes: 6 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ import (
"github.com/althea-net/althea-L1/app/ante"
altheaappparams "github.com/althea-net/althea-L1/app/params"
altheacfg "github.com/althea-net/althea-L1/config"
"github.com/althea-net/althea-L1/x/gasfree"
gasfreekeeper "github.com/althea-net/althea-L1/x/gasfree/keeper"
gasfreetypes "github.com/althea-net/althea-L1/x/gasfree/types"
lockup "github.com/althea-net/althea-L1/x/lockup"
Expand Down Expand Up @@ -756,8 +757,9 @@ func NewAltheaApp(
ibc.NewAppModule(&ibcKeeper),
params.NewAppModule(paramsKeeper),
ibcTransferAppModule,
gasfree.NewAppModule(gasfreeKeeper),
lockup.NewAppModule(lockupKeeper, bankKeeper),
microtx.NewAppModule(microtxKeeper, accountKeeper, bankKeeper),
microtx.NewAppModule(microtxKeeper, accountKeeper),
evm.NewAppModule(&evmKeeper, accountKeeper),
erc20.NewAppModule(erc20Keeper, accountKeeper),
feemarket.NewAppModule(feemarketKeeper),
Expand Down Expand Up @@ -791,6 +793,7 @@ func NewAltheaApp(
authz.ModuleName,
govtypes.ModuleName,
paramstypes.ModuleName,
gasfreetypes.ModuleName,
lockuptypes.ModuleName,
microtxtypes.ModuleName,
erc20types.ModuleName,
Expand Down Expand Up @@ -819,6 +822,7 @@ func NewAltheaApp(
genutiltypes.ModuleName,
authz.ModuleName,
paramstypes.ModuleName,
gasfreetypes.ModuleName,
lockuptypes.ModuleName,
microtxtypes.ModuleName,
erc20types.ModuleName,
Expand All @@ -844,6 +848,7 @@ func NewAltheaApp(
ibctransfertypes.ModuleName,
authz.ModuleName,
paramstypes.ModuleName,
gasfreetypes.ModuleName,
lockuptypes.ModuleName,
microtxtypes.ModuleName,
erc20types.ModuleName,
Expand Down
2 changes: 1 addition & 1 deletion proto/althea/gasfree/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ option go_package = "github.com/althea-net/althea-L1/x/gasfree/types";
message Params {
// Messages with one of these types will not be charged gas fees in the
// AnteHandler, but will later be charged some form of fee in the Msg handler
repeated string gas_free_message_types = 3;
repeated string gas_free_message_types = 1;
}

message GenesisState {
Expand Down
25 changes: 25 additions & 0 deletions proto/althea/gasfree/v1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto3";
package althea.gasfree.v1;

import "google/api/annotations.proto";
import "gogoproto/gogo.proto";
import "althea/gasfree/v1/genesis.proto";

option go_package = "github.com/althea-net/althea-L1/x/gasfree/types";

// Query defines the gRPC querier service.
service Query {
// Params retrieves the total set of onboarding parameters.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/althea/gasfree/v1/params";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];
}
53 changes: 53 additions & 0 deletions x/gasfree/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cli

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"

"github.com/althea-net/althea-L1/x/gasfree/types"
)

// GetQueryCmd bundles all the query subcmds together so they appear under the `query` or `q` subcommand
func GetQueryCmd() *cobra.Command {
// nolint: exhaustruct
gasfreeQueryCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the gasfree module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
gasfreeQueryCmd.AddCommand([]*cobra.Command{
CmdQueryParams(),
}...)

return gasfreeQueryCmd
}

// CmdQueryParams fetches the current microtx params
func CmdQueryParams() *cobra.Command {
// nolint: exhaustruct
cmd := &cobra.Command{
Use: "params",
Args: cobra.NoArgs,
Short: "Query gasfree params",
RunE: func(cmd *cobra.Command, _ []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
}
22 changes: 22 additions & 0 deletions x/gasfree/keeper/grpc_query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/althea-net/althea-L1/x/gasfree/types"
)

// nolint: exhaustruct
// Enforce via type assertion that the Keeper functions as a query server
var _ types.QueryServer = Keeper{}

// Params queries the params of the microtx module
func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
p, err := k.GetParamsIfSet(sdk.UnwrapSDKContext(c))
if err != nil {
return nil, err // Force an empty response on error
}
return &types.QueryParamsResponse{Params: p}, nil
}
23 changes: 14 additions & 9 deletions x/gasfree/module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gasfree

import (
"context"
"encoding/json"
"fmt"
"math/rand"
Expand All @@ -15,11 +16,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
abci "github.com/tendermint/tendermint/abci/types"

"github.com/althea-net/althea-L1/x/gasfree/keeper"
"github.com/althea-net/althea-L1/x/gasfree/types"
"github.com/althea-net/althea-L1/x/microtx/client/cli"
)

// type check to ensure the interface is properly implemented
Expand All @@ -40,6 +41,7 @@ func (AppModuleBasic) Name() string {

// RegisterLegacyAminoCodec implements app module basic
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
// types.RegisterCodec(cdc)
}

// DefaultGenesis implements app module basic
Expand All @@ -63,8 +65,8 @@ func (AppModuleBasic) RegisterRESTRoutes(ctx client.Context, rtr *mux.Router) {

// GetQueryCmd implements app module basic
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
// nolint: exhaustruct
return &cobra.Command{}
return cli.GetQueryCmd()

}

// GetTxCmd implements app module basic
Expand All @@ -74,29 +76,32 @@ func (AppModuleBasic) GetTxCmd() *cobra.Command {
}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the distribution module.
// also implements app modeul basic
// also implements app module basic
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err != nil {
panic("Failed to register query handler")
}
}

// RegisterInterfaces implements app bmodule basic
// RegisterInterfaces implements app module basic
func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
// types.RegisterInterfaces(registry)
}

//____________________________________________________________________________

// AppModule object for module implementation
type AppModule struct {
AppModuleBasic
keeper keeper.Keeper
bankKeeper bankkeeper.Keeper
keeper keeper.Keeper
}

// NewAppModule creates a new AppModule Object
func NewAppModule(k keeper.Keeper, bankKeeper bankkeeper.Keeper) AppModule {
func NewAppModule(k keeper.Keeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
keeper: k,
bankKeeper: bankKeeper,
}
}

Expand Down
10 changes: 5 additions & 5 deletions x/gasfree/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 784a083

Please sign in to comment.