Skip to content

Commit

Permalink
common module added
Browse files Browse the repository at this point in the history
  • Loading branch information
cgsingh33 committed Dec 14, 2023
1 parent 5b75679 commit 2d96f73
Show file tree
Hide file tree
Showing 40 changed files with 5,372 additions and 2 deletions.
24 changes: 23 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ import (
"github.com/comdex-official/comdex/x/collector"
collectorkeeper "github.com/comdex-official/comdex/x/collector/keeper"
collectortypes "github.com/comdex-official/comdex/x/collector/types"

"github.com/comdex-official/comdex/x/common"
commonkeeper "github.com/comdex-official/comdex/x/common/keeper"
commontypes "github.com/comdex-official/comdex/x/common/types"

"github.com/comdex-official/comdex/x/esm"
esmkeeper "github.com/comdex-official/comdex/x/esm/keeper"
esmtypes "github.com/comdex-official/comdex/x/esm/types"
Expand Down Expand Up @@ -306,6 +311,7 @@ var (
ibcfee.AppModuleBasic{},
liquidationsV2.AppModuleBasic{},
auctionsV2.AppModuleBasic{},
common.AppModuleBasic{},
icq.AppModuleBasic{},
ibchooks.AppModuleBasic{},
packetforward.AppModuleBasic{},
Expand Down Expand Up @@ -388,6 +394,7 @@ type App struct {
Rewardskeeper rewardskeeper.Keeper
NewliqKeeper liquidationsV2keeper.Keeper
NewaucKeeper auctionsV2keeper.Keeper
CommonKeeper commonkeeper.Keeper

// IBC modules
// transfer module
Expand Down Expand Up @@ -434,7 +441,7 @@ func New(
markettypes.StoreKey, bandoraclemoduletypes.StoreKey, lockertypes.StoreKey,
wasm.StoreKey, authzkeeper.StoreKey, auctiontypes.StoreKey, tokenminttypes.StoreKey,
rewardstypes.StoreKey, feegrant.StoreKey, liquiditytypes.StoreKey, esmtypes.ModuleName, lendtypes.StoreKey,
liquidationsV2types.StoreKey, auctionsV2types.StoreKey, ibchookstypes.StoreKey, packetforwardtypes.StoreKey, icqtypes.StoreKey, consensusparamtypes.StoreKey, crisistypes.StoreKey,
liquidationsV2types.StoreKey, auctionsV2types.StoreKey, commontypes.StoreKey, ibchookstypes.StoreKey, packetforwardtypes.StoreKey, icqtypes.StoreKey, consensusparamtypes.StoreKey, crisistypes.StoreKey,
)
)

Expand Down Expand Up @@ -489,6 +496,7 @@ func New(
app.ParamsKeeper.Subspace(rewardstypes.ModuleName)
app.ParamsKeeper.Subspace(liquidationsV2types.ModuleName)
app.ParamsKeeper.Subspace(auctionsV2types.ModuleName)
app.ParamsKeeper.Subspace(commontypes.ModuleName)
app.ParamsKeeper.Subspace(icqtypes.ModuleName)
app.ParamsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())

Expand Down Expand Up @@ -881,6 +889,15 @@ func New(
&app.TokenmintKeeper,
)

app.CommonKeeper = commonkeeper.NewKeeper(
app.cdc,
app.keys[commontypes.StoreKey],
app.keys[commontypes.MemStoreKey],
app.GetSubspace(commontypes.ModuleName),
&app.WasmKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// ICQ Keeper
icqKeeper := icqkeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -1051,6 +1068,7 @@ func New(
liquidity.NewAppModule(app.cdc, app.LiquidityKeeper, app.AccountKeeper, app.BankKeeper, app.AssetKeeper),
rewards.NewAppModule(app.cdc, app.Rewardskeeper, app.AccountKeeper, app.BankKeeper),
liquidationsV2.NewAppModule(app.cdc, app.NewliqKeeper, app.AccountKeeper, app.BankKeeper),
common.NewAppModule(app.cdc, app.CommonKeeper, app.AccountKeeper, app.BankKeeper, app.WasmKeeper),
auctionsV2.NewAppModule(app.cdc, app.NewaucKeeper, app.BankKeeper),
ibchooks.NewAppModule(app.AccountKeeper),
icq.NewAppModule(*app.ICQKeeper),
Expand Down Expand Up @@ -1097,6 +1115,7 @@ func New(
esmtypes.ModuleName,
liquidationsV2types.ModuleName,
auctionsV2types.ModuleName,
commontypes.ModuleName,
ibchookstypes.ModuleName,
icqtypes.ModuleName,
packetforwardtypes.ModuleName,
Expand Down Expand Up @@ -1140,6 +1159,7 @@ func New(
esmtypes.ModuleName,
liquidationsV2types.ModuleName,
auctionsV2types.ModuleName,
commontypes.ModuleName,
ibchookstypes.ModuleName,
icqtypes.ModuleName,
packetforwardtypes.ModuleName,
Expand Down Expand Up @@ -1187,6 +1207,7 @@ func New(
crisistypes.ModuleName,
liquidationsV2types.ModuleName,
auctionsV2types.ModuleName,
commontypes.ModuleName,
ibchookstypes.ModuleName,
icqtypes.ModuleName,
packetforwardtypes.ModuleName,
Expand Down Expand Up @@ -1447,6 +1468,7 @@ func (a *App) ModuleAccountsPermissions() map[string][]string {
rewardstypes.ModuleName: {authtypes.Minter, authtypes.Burner},
liquidationsV2types.ModuleName: {authtypes.Minter, authtypes.Burner},
auctionsV2types.ModuleName: {authtypes.Minter, authtypes.Burner},
commontypes.ModuleName: nil,
icatypes.ModuleName: nil,
ibcfeetypes.ModuleName: nil,
assettypes.ModuleName: nil,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/bandprotocol/bandchain-packet v0.0.3
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-apps/modules/async-icq/v7 v7.0.0
Expand Down Expand Up @@ -92,7 +93,6 @@ require (
github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v0.20.0 // indirect
Expand Down
14 changes: 14 additions & 0 deletions proto/comdex/common/v1beta1/common.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";
package comdex.common.v1beta1;

import "gogoproto/gogo.proto";

option go_package = "github.com/comdex-official/comdex/x/common/types";

message WhitelistedContract {
uint64 game_id = 1;
string security_address = 2;
string contract_admin = 3;
string game_name = 4;
string contract_address = 5;
}
14 changes: 14 additions & 0 deletions proto/comdex/common/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";
package comdex.common.v1beta1;

import "gogoproto/gogo.proto";
import "comdex/common/v1beta1/params.proto";
import "comdex/common/v1beta1/common.proto";

option go_package = "github.com/comdex-official/comdex/x/common/types";

// GenesisState defines the common module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated WhitelistedContract whitelisted_contracts = 2 [ (gogoproto.moretags) = "yaml:\"whitelisted_contracts\"" ];
}
20 changes: 20 additions & 0 deletions proto/comdex/common/v1beta1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";
package comdex.common.v1beta1;

import "gogoproto/gogo.proto";

option go_package = "github.com/comdex-official/comdex/x/common/types";

// Params defines the set of module parameters.
message Params {
// Security address that can whitelist/delist contract
repeated string security_address = 1 [
(gogoproto.jsontag) = "security_address,omitempty",
(gogoproto.moretags) = "yaml:\"security_address\""
];

uint64 contract_gas_limit = 2 [
(gogoproto.jsontag) = "contract_gas_limit,omitempty",
(gogoproto.moretags) = "yaml:\"contract_gas_limit\""
];
}
42 changes: 42 additions & 0 deletions proto/comdex/common/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
syntax = "proto3";
package comdex.common.v1beta1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "comdex/common/v1beta1/params.proto";
import "comdex/common/v1beta1/common.proto";

option go_package = "github.com/comdex-official/comdex/x/common/types";

// Query defines the gRPC querier service.
service Query {
// Parameters queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/comdex/common/v1beta1/params";
}
rpc QueryWhitelistedContracts(QueryWhitelistedContractsRequest) returns (QueryWhitelistedContractsResponse) {
option (google.api.http).get = "/comdex/common/v1beta1/whitelisted_contracts";
}
}

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

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false];
}

message QueryWhitelistedContractsRequest{
cosmos.base.query.v1beta1.PageRequest pagination = 1
[(gogoproto.moretags) = "yaml:\"pagination\""];
}

message QueryWhitelistedContractsResponse {
repeated WhitelistedContract whilisted_contracts = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2
[(gogoproto.moretags) = "yaml:\"pagination\""];
}

54 changes: 54 additions & 0 deletions proto/comdex/common/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
syntax = "proto3";
package comdex.common.v1beta1;
import "gogoproto/gogo.proto";

import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "comdex/common/v1beta1/params.proto";


option go_package = "github.com/comdex-official/comdex/x/common/types";

// Msg defines the Msg service.
service Msg {
rpc RegisterContract(MsgRegisterContract) returns(MsgRegisterContractResponse);
rpc DeRegisterContract(MsgDeRegisterContract) returns(MsgDeRegisterContractResponse);
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

message MsgRegisterContract {
string security_address = 1;
string game_name = 2;
string contract_address = 3;
}

message MsgRegisterContractResponse {}

message MsgDeRegisterContract {
string security_address = 1;
uint64 game_id = 2;
}

message MsgDeRegisterContractResponse {}


// MsgUpdateParams is the MsgUpdateParams request type.
//
// Since: 0.47
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/auth parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
//
// Since: 0.47
message MsgUpdateParamsResponse {}
30 changes: 30 additions & 0 deletions proto/cosmos/msg/v1/msg.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
syntax = "proto3";

package cosmos.msg.v1;

import "google/protobuf/descriptor.proto";

// TODO(fdymylja): once we fully migrate to protov2 the go_package needs to be updated.
// We need this right now because gogoproto codegen needs to import the extension.
option go_package = "github.com/cosmos/cosmos-sdk/types/msgservice";

extend google.protobuf.ServiceOptions {
// service indicates that the service is a Msg service and that requests
// must be transported via blockchain transactions rather than gRPC.
// Tooling can use this annotation to distinguish between Msg services and
// other types of services via reflection.
bool service = 11110000;
}

extend google.protobuf.MessageOptions {
// signer must be used in cosmos messages in order
// to signal to external clients which fields in a
// given cosmos message must be filled with signer
// information (address).
// The field must be the protobuf name of the message
// field extended with this MessageOption.
// The field must either be of string kind, or of message
// kind in case the signer information is contained within
// a message inside the cosmos message.
repeated string signer = 11110000;
}
24 changes: 24 additions & 0 deletions x/common/abci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package common

import (
"fmt"
"github.com/comdex-official/comdex/x/common/keeper"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {

Msg := []byte(`{"resolve_bet":{}}`)

allContracts := k.GetAllContract(ctx)
logger := k.Logger(ctx)

for _, data := range allContracts {
err := k.SudoContractCall(ctx, data.ContractAddress, Msg)
if err != nil {
logger.Error(fmt.Sprintf("Game Id %d contract call error", data.GameId))
}
logger.Info(fmt.Sprintf("Game Id %d contract call", data.GameId))
}

}
65 changes: 65 additions & 0 deletions x/common/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package cli

import (
"fmt"
// "strings"

"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/comdex-official/comdex/x/common/types"
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
// Group common queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(CmdQueryParams(),
QueryWhitelistedContracts())
// this line is used by starport scaffolding # 1

return cmd
}

func QueryWhitelistedContracts() *cobra.Command {
cmd := &cobra.Command{
Use: "whitelisted-contracts",
Short: "Query all whitelisted contracts",
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
pagination, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

queryClient := types.NewQueryClient(ctx)

res, err := queryClient.QueryWhitelistedContracts(cmd.Context(), &types.QueryWhitelistedContractsRequest{
Pagination: pagination,
})
if err != nil {
return err
}
return ctx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "whitelisted-contracts")

return cmd
}
Loading

0 comments on commit 2d96f73

Please sign in to comment.