Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R Client Generalization (+ associated module refactor) #4451

Merged
merged 28 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c5b89c3
porting changes from first branch
rigelrozanski May 30, 2019
f4e2f93
fix import cycles
rigelrozanski May 30, 2019
ca8f4cd
circle dep cont.
rigelrozanski May 30, 2019
8206f89
working on compile errors
rigelrozanski May 30, 2019
32e14a5
simapp addition
rigelrozanski May 30, 2019
93d6e60
...
rigelrozanski May 30, 2019
bf09851
working through compile errors
rigelrozanski May 31, 2019
f6decfb
resolve all compile errors
rigelrozanski May 31, 2019
abfbe47
fix bugs
rigelrozanski May 31, 2019
0ed158d
Merge remote-tracking branch 'origin/master' into rigel/client-genera…
rigelrozanski May 31, 2019
5c62e49
gov proposal handler type
rigelrozanski May 31, 2019
d010ed7
client routes
rigelrozanski May 31, 2019
f7246b6
cl
rigelrozanski May 31, 2019
27a52d4
@jleni comments
rigelrozanski Jun 3, 2019
71bf692
@fedekunze pr comments
rigelrozanski Jun 3, 2019
9013c97
Merge remote-tracking branch 'origin/master' into rigel/client-genera…
rigelrozanski Jun 3, 2019
8cc66cc
@jackzampolin comments
rigelrozanski Jun 3, 2019
e5d0b71
Update x/auth/keeper.go
alexanderbez Jun 4, 2019
3b82dc5
Update x/auth/keeper.go
alexanderbez Jun 4, 2019
0e650ae
add auth and bank tx/query subcommands
rigelrozanski Jun 4, 2019
f2ee34c
Merge branch 'rigel/client-generalization2' of https://github.com/cos…
rigelrozanski Jun 4, 2019
bc64c7e
resolve cli issues, global cdc for commands
rigelrozanski Jun 4, 2019
ac9fdc7
Merge remote-tracking branch 'origin/master' into rigel/client-genera…
rigelrozanski Jun 4, 2019
b646cfa
update alias
rigelrozanski Jun 4, 2019
9d81db8
@fedekunze PR comments (round 2)
rigelrozanski Jun 5, 2019
394ecd3
@alexanderbez PR comments (and marko comment on queryRoute)
rigelrozanski Jun 5, 2019
4740a8c
Merge remote-tracking branch 'origin/master' into rigel/client-genera…
rigelrozanski Jun 5, 2019
02ab8f6
Fix pending file
alexanderbez Jun 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ func (config *Config) SetAddressVerifier(addressVerifier func([]byte) error) {
config.addressVerifier = addressVerifier
}

// TODO
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
func (config *Config) SetCoinType(coinType uint32) {
config.assertNotSealed()
config.coinType = coinType
}

// TODO
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
func (config *Config) SetFullFundraiserPath(fullFundraiserPath string) {
config.assertNotSealed()
config.fullFundraiserPath = fullFundraiserPath
Expand Down Expand Up @@ -144,10 +146,12 @@ func (config *Config) GetAddressVerifier() func([]byte) error {
return config.addressVerifier
}

// TODO
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
func (config *Config) GetCoinType() uint32 {
return config.coinType
}

// TODO
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
func (config *Config) GetFullFundraiserPath() string {
return config.fullFundraiserPath
}
41 changes: 35 additions & 6 deletions types/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,28 @@ ModuleBasicManager.
package types

import (
"context"
"encoding/json"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"
)

// ModuleClient helps modules provide a standard interface for exporting client functionality
type ModuleClient interface {
GetQueryCmd() *cobra.Command
GetTxCmd() *cobra.Command
}

//__________________________________________________________________________________________
// AppModuleBasic is the standard form for basic non-dependant elements of an application module.
type AppModuleBasic interface {
Name() string
RegisterCodec(*codec.Codec)

// genesis
DefaultGenesis() json.RawMessage
ValidateGenesis(json.RawMessage) error

// client functionality
RegisterRESTRoutes(context.CLIContext, *mux.Router, *codec.Codec)
GetTxCmd() *cobra.Command
GetQueryCmd() *cobra.Command
}

// collections of AppModuleBasic
Expand Down Expand Up @@ -77,6 +79,33 @@ func (mbm ModuleBasicManager) ValidateGenesis(genesis map[string]json.RawMessage
return nil
}

// RegisterRestRoutes registers all module rest routes
func (mbm ModuleBasicManager) RegisterRESTRoutes(
ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {

for _, mb := range mbm {
mb.RegisterRESTRoutes(ctx, rtr, cdc)
}
}

// add all tx commands to the rootTxCmd
func (mbm ModuleBasicManager) AddTxCommands(rootTxCmd *cobra.Command) {
for _, mb := range mbm {
if cmd := mb.GetTxCmd(); cmd != nil {
rootTxCmd.AddCommand(cmd)
}
}
}

// add all query commands to the rootQueryCmd
func (mbm ModuleBasicManager) AddQueryCommands(rootQueryCmd *cobra.Command) {
for _, mb := range mbm {
if cmd := mb.GetQueryCmd(); cmd != nil {
rootQueryCmd.AddCommand(cmd)
}
}
}

//_________________________________________________________
// AppModuleGenesis is the standard form for an application module genesis functions
type AppModuleGenesis interface {
Expand Down
15 changes: 14 additions & 1 deletion x/auth/genaccounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package genaccounts
import (
"encoding/json"

"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"

"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"
abci "github.com/tendermint/tendermint/abci/types"
)

var (
Expand Down Expand Up @@ -43,6 +46,16 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
return ValidateGenesis(data)
}

// register rest routes
func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router, _ *codec.Codec) {
}

// get the root tx command of this module
func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil }

// get the root query command of this module
func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil }

// extra function from sdk.AppModuleBasic
// iterate the genesis accounts and perform an operation at each of them
// - to used by other modules
Expand Down
20 changes: 19 additions & 1 deletion x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ package auth
import (
"encoding/json"

"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/x/auth/client/rest"
)

var (
Expand Down Expand Up @@ -44,6 +48,20 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
return ValidateGenesis(data)
}

// XXX
// register rest routes
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {
rest.RegisterRoutes(ctx, rtr, cdc, StoreKey)
}

// TODO
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
// get the root tx command of this module
func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil }

// TODO
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
// get the root query command of this module
func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil }

//___________________________
// app module object
type AppModule struct {
Expand Down
19 changes: 18 additions & 1 deletion x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ package bank
import (
"encoding/json"

"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"

"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"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/x/bank/client/rest"
)

var (
Expand Down Expand Up @@ -47,6 +51,19 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
return ValidateGenesis(data)
}

// register rest routes
func RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {
rest.RegisterRoutes(ctx, rtr, cdc, StoreKey)
}

// TODO
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
// get the root tx command of this module
func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil }

// TODO
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
// get the root query command of this module
func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil }

//___________________________
// app module
type AppModule struct {
Expand Down
14 changes: 14 additions & 0 deletions x/crisis/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package cli
import (
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -31,3 +32,16 @@ func GetCmdInvariantBroken(cdc *codec.Codec) *cobra.Command {
}
return cmd
}

// GetTxCmd returns the transaction commands for this module
func GetTxCmd(cdc *amino.Codec) *cobra.Command {
txCmd := &cobra.Command{
Use: crisis.ModuleName,
Short: "crisis transactions subcommands",
}

txCmd.AddCommand(client.PostCommands(
GetCmdInvariantBroken(cdc),
)...)
return txCmd
}
42 changes: 0 additions & 42 deletions x/crisis/client/module_client.go

This file was deleted.

19 changes: 18 additions & 1 deletion x/crisis/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package crisis
import (
"encoding/json"

"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/x/crisis/client/cli"
)

var (
Expand Down Expand Up @@ -48,6 +51,20 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
return ValidateGenesis(data)
}

// register rest routes
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {
}

// get the root tx command of this module
func (AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.GetTxCmd(moduleCdc)
}

// get the root query command of this module
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return nil
}

//___________________________
// app module for bank
type AppModule struct {
Expand Down
21 changes: 21 additions & 0 deletions x/distribution/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"strings"

"github.com/spf13/cobra"
amino "github.com/tendermint/go-amino"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -16,6 +18,25 @@ import (
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(storeKey string, cdc *amino.Codec) *cobra.Command {
distQueryCmd := &cobra.Command{
Use: "distr",
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
Short: "Querying commands for the distribution module",
}

distQueryCmd.AddCommand(client.GetCommands(
GetCmdQueryParams(storeKey, cdc),
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
GetCmdQueryValidatorOutstandingRewards(storeKey, cdc),
GetCmdQueryValidatorCommission(storeKey, cdc),
GetCmdQueryValidatorSlashes(storeKey, cdc),
GetCmdQueryDelegatorRewards(storeKey, cdc),
GetCmdQueryCommunityPool(storeKey, cdc),
)...)

return distQueryCmd
}

// GetCmdQueryParams implements the query params command.
func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Expand Down
3 changes: 2 additions & 1 deletion x/distribution/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ const (
// GetTxCmd returns the transaction commands for this module
func GetTxCmd(storeKey string, cdc *amino.Codec) *cobra.Command {
distTxCmd := &cobra.Command{
Use: "dist",
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
Use: "distr",
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
Short: "Distribution transactions subcommands",
}

distTxCmd.AddCommand(client.PostCommands(
GetCmdWithdrawRewards(cdc),
GetCmdSetWithdrawAddr(cdc),
distCmds.GetCmdWithdrawAllRewards(cdc, storeKey),
)...)

return distTxCmd
Expand Down
5 changes: 3 additions & 2 deletions x/distribution/client/cli/tx_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package cli

import (
"testing"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
"github.com/stretchr/testify/assert"
"github.com/tendermint/tendermint/crypto/secp256k1"
"testing"
)

func createFakeTxBuilder() authtxb.TxBuilder {
Expand Down Expand Up @@ -56,7 +57,7 @@ func Test_splitAndCall_Splitting(t *testing.T) {
callCount := 0
err := splitAndApply(
func(ctx context.CLIContext, txBldr authtxb.TxBuilder, msgs []sdk.Msg) error {
callCount += 1
callCount++

assert.NotNil(t, ctx)
assert.NotNil(t, txBldr)
Expand Down
Loading