Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
krhubert committed Feb 10, 2020
1 parent 16ee943 commit 84c0a48
Show file tree
Hide file tree
Showing 129 changed files with 4,742 additions and 0 deletions.
13 changes: 13 additions & 0 deletions modules/execution/abci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package execution

import (
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
)

// BeginBlocker check for infraction evidence or downtime of validators
// on every begin block
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k Keeper) {}

// EndBlocker called every block, process inflation, update validator set.
func EndBlocker(ctx sdk.Context, k Keeper) {}
35 changes: 35 additions & 0 deletions modules/execution/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package execution

import (
"github.com/mesg-foundation/engine/modules/execution/internal/keeper"
"github.com/mesg-foundation/engine/modules/execution/internal/types"
)

const (
ModuleName = types.ModuleName
RouterKey = types.RouterKey
StoreKey = types.StoreKey
DefaultParamspace = types.DefaultParamspace
QueryParams = types.QueryParams
QuerierRoute = types.QuerierRoute
)

var (
// functions aliases
NewKeeper = keeper.NewKeeper
NewQuerier = keeper.NewQuerier
RegisterCodec = types.RegisterCodec
NewGenesisState = types.NewGenesisState
DefaultGenesisState = types.DefaultGenesisState
ValidateGenesis = types.ValidateGenesis

// variable aliases
ModuleCdc = types.ModuleCdc
)

type (
// module types
Keeper = keeper.Keeper
GenesisState = types.GenesisState
Params = types.Params
)
39 changes: 39 additions & 0 deletions modules/execution/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cli

import (
"fmt"
"strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/mesg-foundation/engine/modules/execution/internal/types"
)

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

executionQueryCmd.AddCommand(
flags.GetCommands(
// TODO: Add query Cmds
)...,
)

return executionQueryCmd

}

// TODO: Add Query Commands
59 changes: 59 additions & 0 deletions modules/execution/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cli

import (
"fmt"
"bufio"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/mesg-foundation/engine/modules/execution/internal/types"
)

// GetTxCmd returns the transaction commands for this module
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
executionTxCmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%S transactions subcommands", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

executionTxCmd.AddCommand(flags.PostCommands(
// TODO: Add tx based commands
// GetCmd<Action>(cdc)
)...)

return executionTxCmd
}

// Example:
//
// GetCmd<Action> is the CLI command for doing <Action>
// func GetCmd<Action>(cdc *codec.Codec) *cobra.Command {
// return &cobra.Command{
// Use: "/* Describe your action cmd */",
// Short: "/* Provide a short description on the cmd */",
// Args: cobra.ExactArgs(2), // Does your request require arguments
// RunE: func(cmd *cobra.Command, args []string) error {
// cliCtx := context.NewCLIContext().WithCodec(cdc)
// inBuf := bufio.NewReader(cmd.InOrStdin())
// txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))

// msg := types.NewMsg<Action>(/* Action params */)
// err = msg.ValidateBasic()
// if err != nil {
// return err
// }

// return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
// },
// }
// }
39 changes: 39 additions & 0 deletions modules/execution/client/rest/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package rest

import (
"fmt"
"net/http"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/gorilla/mux"
"github.com/mesg-foundation/engine/modules/execution/internal/types"
)

func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
// TODO: Define your GET REST endpoints
r.HandleFunc(
"/execution/parameters",
queryParamsHandlerFn(cliCtx),
).Methods("GET")
}

func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}

route := fmt.Sprintf("custom/%s/parameters", types.QuerierRoute)

res, height, err := cliCtx.QueryWithData(route, nil)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res)
}
}
13 changes: 13 additions & 0 deletions modules/execution/client/rest/rest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package rest

import (
"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/client/context"
)

// RegisterRoutes registers execution-related REST handlers to a router
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
registerQueryRoutes(cliCtx, r)
registerTxRoutes(cliCtx, r)
}
45 changes: 45 additions & 0 deletions modules/execution/client/rest/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package rest

import (
"bytes"
"net/http"

"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/mesg-foundation/engine/modules/execution/internal/types"
)

func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) {
// r.HandleFunc(
// TODO: Define the Rest route ,
// Call the function which should be executed for this route),
// ).Methods("POST")
}

/*
// Action TX body
type <Action>Req struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
// TODO: Define more types if needed
}
func <Action>RequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req <Action>Req
vars := mux.Vars(r)
baseReq := req.BaseReq.Sanitize()
if !baseReq.ValidateBasic(w) {
return
}
// TODO: Define the module tx logic for this action
utils.WriteGenerateStdTxResponse(w, cliCtx, BaseReq, []sdk.Msg{msg})
}
}
*/
18 changes: 18 additions & 0 deletions modules/execution/genesis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package execution

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/mesg-foundation/engine/modules/execution/internal/types"
abci "github.com/tendermint/tendermint/abci/types"
)

// InitGenesis initialize default parameters and the keeper's address to pubkey map.
func InitGenesis(ctx sdk.Context, k Keeper, data types.GenesisState) []abci.ValidatorUpdate {
return []abci.ValidatorUpdate{}
}

// ExportGenesis writes the current store values // to a genesis file,
// which can be imported again with InitGenesis.
func ExportGenesis(ctx sdk.Context, k Keeper) types.GenesisState {
return types.NewGenesisState()
}
40 changes: 40 additions & 0 deletions modules/execution/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package execution

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/mesg-foundation/engine/modules/execution/internal/types"
)

// NewHandler creates an sdk.Handler for all the execution type messages
func NewHandler(k Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
ctx = ctx.WithEventManager(sdk.NewEventManager())
switch msg := msg.(type) {
case types.MsgCreateExecution:
case types.MsgUpdateExecution:
default:
errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg)
return sdk.ErrUnknownRequest(errMsg).Result()
}
}
}

func handleMsgCreateExecution(ctx sdk.Context, msg MsgType, k Keeper) sdk.Result {
err := k.Create(ctx, msg.Signer)
if err != nil {
return err.Result()
}

// TODO: Define your msg events
ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.ValidatorAddr.String()),
),
)

return sdk.Result{Events: ctx.EventManager().Events()}
}
56 changes: 56 additions & 0 deletions modules/execution/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package keeper

import (
"fmt"

"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/mesg-foundation/engine/modules/execution/internal/types"
)

// Keeper of the execution store
type Keeper struct {
storeKey sdk.StoreKey
cdc *codec.Codec
paramspace types.ParamSubspace
}

// NewKeeper creates a execution keeper
func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, paramspace types.ParamSubspace) Keeper {
keeper := Keeper{
storeKey: key,
cdc: cdc,
paramspace: paramspace.WithKeyTable(types.ParamKeyTable()),
}
return keeper
}

// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}

// Get returns the pubkey from the adddress-pubkey relation
func (k Keeper) Get(ctx sdk.Context, key string) (/* TODO: Fill out this type */, error) {
store := ctx.KVStore(k.storeKey)
var item /* TODO: Fill out this type */
byteKey := []byte(key)
err := k.cdc.UnmarshalBinaryLengthPrefixed(store.Get(byteKey), &item)
if err != nil {
return nil, err
}
return item, nil
}

func (k Keeper) set(ctx sdk.Context, key string, value /* TODO: fill out this type */ ) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshalBinaryLengthPrefixed(value)
store.Set([]byte(key), bz)
}

func (k Keeper) delete(ctx sdk.Context, key string) {
store := ctx.KVStore(k.storeKey)
store.Delete([]byte(key))
}
22 changes: 22 additions & 0 deletions modules/execution/internal/keeper/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package keeper
/*
// TODO: Define if your module needs Parameters, if not this can be deleted
import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/mesg-foundation/engine/modules/execution/internal/types"
)
// GetParams returns the total set of execution parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
k.paramspace.GetParamSet(ctx, &params)
return params
}
// SetParams sets the execution parameters to the param space.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramspace.SetParamSet(ctx, &params)
}
*/
Loading

0 comments on commit 84c0a48

Please sign in to comment.