Skip to content

Commit 0846cc5

Browse files
rigelrozanskialexanderbez
authored andcommitted
Merge PR #31: Update to SDK Client and Module Modularization
1 parent 1b33618 commit 0846cc5

File tree

9 files changed

+47
-142
lines changed

9 files changed

+47
-142
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Bank and Auth module commands are now mounted under their respective module:
2+
* `sign` and `multisign` are under `gaiacli tx auth`
3+
* `send` is under `gaiacli tx bank`

app/app.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,29 @@ import (
44
"io"
55
"os"
66

7+
abci "github.com/tendermint/tendermint/abci/types"
8+
cmn "github.com/tendermint/tendermint/libs/common"
9+
dbm "github.com/tendermint/tendermint/libs/db"
10+
"github.com/tendermint/tendermint/libs/log"
11+
712
bam "github.com/cosmos/cosmos-sdk/baseapp"
813
"github.com/cosmos/cosmos-sdk/codec"
914
sdk "github.com/cosmos/cosmos-sdk/types"
15+
"github.com/cosmos/cosmos-sdk/types/module"
1016
"github.com/cosmos/cosmos-sdk/version"
1117
"github.com/cosmos/cosmos-sdk/x/auth"
1218
"github.com/cosmos/cosmos-sdk/x/auth/genaccounts"
1319
"github.com/cosmos/cosmos-sdk/x/bank"
1420
"github.com/cosmos/cosmos-sdk/x/crisis"
1521
distr "github.com/cosmos/cosmos-sdk/x/distribution"
22+
distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client"
1623
"github.com/cosmos/cosmos-sdk/x/genutil"
1724
"github.com/cosmos/cosmos-sdk/x/gov"
1825
"github.com/cosmos/cosmos-sdk/x/mint"
1926
"github.com/cosmos/cosmos-sdk/x/params"
27+
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
2028
"github.com/cosmos/cosmos-sdk/x/slashing"
2129
"github.com/cosmos/cosmos-sdk/x/staking"
22-
23-
abci "github.com/tendermint/tendermint/abci/types"
24-
cmn "github.com/tendermint/tendermint/libs/common"
25-
dbm "github.com/tendermint/tendermint/libs/db"
26-
"github.com/tendermint/tendermint/libs/log"
2730
)
2831

2932
const appName = "GaiaApp"
@@ -38,19 +41,19 @@ var (
3841
// The ModuleBasicManager is in charge of setting up basic,
3942
// non-dependant module elements, such as codec registration
4043
// and genesis verification.
41-
ModuleBasics sdk.ModuleBasicManager
44+
ModuleBasics module.BasicManager
4245
)
4346

4447
func init() {
45-
ModuleBasics = sdk.NewModuleBasicManager(
48+
ModuleBasics = module.NewBasicManager(
4649
genaccounts.AppModuleBasic{},
4750
genutil.AppModuleBasic{},
4851
auth.AppModuleBasic{},
4952
bank.AppModuleBasic{},
5053
staking.AppModuleBasic{},
5154
mint.AppModuleBasic{},
5255
distr.AppModuleBasic{},
53-
gov.AppModuleBasic{},
56+
gov.NewAppModuleBasic(paramsclient.ProposalHandler, distrclient.ProposalHandler),
5457
params.AppModuleBasic{},
5558
crisis.AppModuleBasic{},
5659
slashing.AppModuleBasic{},
@@ -100,7 +103,7 @@ type GaiaApp struct {
100103
paramsKeeper params.Keeper
101104

102105
// the module manager
103-
mm *sdk.ModuleManager
106+
mm *module.Manager
104107
}
105108

106109
// NewGaiaApp returns a reference to an initialized GaiaApp.
@@ -169,7 +172,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
169172
app.stakingKeeper = *stakingKeeper.SetHooks(
170173
staking.NewMultiStakingHooks(app.distrKeeper.Hooks(), app.slashingKeeper.Hooks()))
171174

172-
app.mm = sdk.NewModuleManager(
175+
app.mm = module.NewManager(
173176
genaccounts.NewAppModule(app.accountKeeper),
174177
genutil.NewAppModule(app.accountKeeper, app.stakingKeeper, app.BaseApp.DeliverTx),
175178
auth.NewAppModule(app.accountKeeper, app.feeCollectionKeeper),

app/export.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
sdk "github.com/cosmos/cosmos-sdk/types"
1212
"github.com/cosmos/cosmos-sdk/x/slashing"
1313
"github.com/cosmos/cosmos-sdk/x/staking"
14-
"github.com/cosmos/cosmos-sdk/x/staking/expected"
1514
)
1615

1716
// export the state of gaia for a genesis file
@@ -61,7 +60,7 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []st
6160
/* Handle fee distribution state. */
6261

6362
// withdraw all validator commission
64-
app.stakingKeeper.IterateValidators(ctx, func(_ int64, val expected.ValidatorI) (stop bool) {
63+
app.stakingKeeper.IterateValidators(ctx, func(_ int64, val staking.ValidatorI) (stop bool) {
6564
_, _ = app.distrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
6665
return false
6766
})
@@ -83,7 +82,7 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []st
8382
ctx = ctx.WithBlockHeight(0)
8483

8584
// reinitialize all validators
86-
app.stakingKeeper.IterateValidators(ctx, func(_ int64, val expected.ValidatorI) (stop bool) {
85+
app.stakingKeeper.IterateValidators(ctx, func(_ int64, val staking.ValidatorI) (stop bool) {
8786

8887
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
8988
scraps := app.distrKeeper.GetValidatorOutstandingRewards(ctx, val.GetOperator())

cli_test/test_helpers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,21 +309,21 @@ func (f *Fixtures) CLIConfig(key, value string, flags ...string) {
309309

310310
// TxSend is gaiacli tx send
311311
func (f *Fixtures) TxSend(from string, to sdk.AccAddress, amount sdk.Coin, flags ...string) (bool, string, string) {
312-
cmd := fmt.Sprintf("%s tx send %s %s %s %v", f.GaiacliBinary, from, to, amount, f.Flags())
312+
cmd := fmt.Sprintf("%s tx bank send %s %s %s %v", f.GaiacliBinary, from, to, amount, f.Flags())
313313
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), client.DefaultKeyPass)
314314
}
315315

316316
func (f *Fixtures) txSendWithConfirm(
317317
from string, to sdk.AccAddress, amount sdk.Coin, confirm string, flags ...string,
318318
) (bool, string, string) {
319319

320-
cmd := fmt.Sprintf("%s tx send %s %s %s %v", f.GaiacliBinary, from, to, amount, f.Flags())
320+
cmd := fmt.Sprintf("%s tx bank send %s %s %s %v", f.GaiacliBinary, from, to, amount, f.Flags())
321321
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), confirm, client.DefaultKeyPass)
322322
}
323323

324324
// TxSign is gaiacli tx sign
325325
func (f *Fixtures) TxSign(signer, fileName string, flags ...string) (bool, string, string) {
326-
cmd := fmt.Sprintf("%s tx sign %v --from=%s %v", f.GaiacliBinary, f.Flags(), signer, fileName)
326+
cmd := fmt.Sprintf("%s tx auth sign %v --from=%s %v", f.GaiacliBinary, f.Flags(), signer, fileName)
327327
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), client.DefaultKeyPass)
328328
}
329329

@@ -343,7 +343,7 @@ func (f *Fixtures) TxEncode(fileName string, flags ...string) (bool, string, str
343343
func (f *Fixtures) TxMultisign(fileName, name string, signaturesFiles []string,
344344
flags ...string) (bool, string, string) {
345345

346-
cmd := fmt.Sprintf("%s tx multisign %v %s %s %s", f.GaiacliBinary, f.Flags(),
346+
cmd := fmt.Sprintf("%s tx auth multisign %v %s %s %s", f.GaiacliBinary, f.Flags(),
347347
fileName, name, strings.Join(signaturesFiles, " "),
348348
)
349349
return executeWriteRetStdStreams(f.T, cmd)

cmd/gaiacli/main.go

Lines changed: 13 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,11 @@ import (
1414
"github.com/cosmos/cosmos-sdk/client/tx"
1515
sdk "github.com/cosmos/cosmos-sdk/types"
1616
"github.com/cosmos/cosmos-sdk/version"
17-
at "github.com/cosmos/cosmos-sdk/x/auth"
1817
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
19-
auth "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
20-
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
21-
bank "github.com/cosmos/cosmos-sdk/x/bank/client/rest"
22-
crisisclient "github.com/cosmos/cosmos-sdk/x/crisis/client"
23-
distcmd "github.com/cosmos/cosmos-sdk/x/distribution"
24-
distClient "github.com/cosmos/cosmos-sdk/x/distribution/client"
25-
distrcli "github.com/cosmos/cosmos-sdk/x/distribution/client/cli"
26-
dist "github.com/cosmos/cosmos-sdk/x/distribution/client/rest"
27-
gv "github.com/cosmos/cosmos-sdk/x/gov"
28-
govClient "github.com/cosmos/cosmos-sdk/x/gov/client"
29-
gov "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
30-
"github.com/cosmos/cosmos-sdk/x/mint"
31-
mintclient "github.com/cosmos/cosmos-sdk/x/mint/client"
32-
mintrest "github.com/cosmos/cosmos-sdk/x/mint/client/rest"
33-
paramcli "github.com/cosmos/cosmos-sdk/x/params/client/cli"
34-
paramsrest "github.com/cosmos/cosmos-sdk/x/params/client/rest"
35-
sl "github.com/cosmos/cosmos-sdk/x/slashing"
36-
slashingclient "github.com/cosmos/cosmos-sdk/x/slashing/client"
37-
slashing "github.com/cosmos/cosmos-sdk/x/slashing/client/rest"
38-
st "github.com/cosmos/cosmos-sdk/x/staking"
39-
stakingclient "github.com/cosmos/cosmos-sdk/x/staking/client"
40-
staking "github.com/cosmos/cosmos-sdk/x/staking/client/rest"
41-
4218
"github.com/spf13/cobra"
4319
"github.com/spf13/viper"
4420

45-
amino "github.com/tendermint/go-amino"
21+
"github.com/tendermint/go-amino"
4622
"github.com/tendermint/tendermint/libs/cli"
4723
)
4824

@@ -64,17 +40,6 @@ func main() {
6440
// the below functions and eliminate global vars, like we do
6541
// with the cdc
6642

67-
// Module clients hold cli commnads (tx,query) and lcd routes
68-
// TODO: Make the lcd command take a list of ModuleClient
69-
mc := []sdk.ModuleClient{
70-
govClient.NewModuleClient(gv.StoreKey, cdc, paramcli.GetCmdSubmitProposal(cdc), distrcli.GetCmdSubmitProposal(cdc)),
71-
distClient.NewModuleClient(distcmd.StoreKey, cdc),
72-
stakingclient.NewModuleClient(st.StoreKey, cdc),
73-
mintclient.NewModuleClient(mint.StoreKey, cdc),
74-
slashingclient.NewModuleClient(sl.StoreKey, cdc),
75-
crisisclient.NewModuleClient(sl.StoreKey, cdc),
76-
}
77-
7843
rootCmd := &cobra.Command{
7944
Use: "gaiacli",
8045
Short: "Command line interface for interacting with gaiad",
@@ -90,8 +55,8 @@ func main() {
9055
rootCmd.AddCommand(
9156
rpc.StatusCommand(),
9257
client.ConfigCmd(app.DefaultCLIHome),
93-
queryCmd(cdc, mc),
94-
txCmd(cdc, mc),
58+
queryCmd(cdc),
59+
txCmd(cdc),
9560
client.LineBreak,
9661
lcd.ServeCommand(cdc, registerRoutes),
9762
client.LineBreak,
@@ -111,51 +76,43 @@ func main() {
11176
}
11277
}
11378

114-
func queryCmd(cdc *amino.Codec, mc []sdk.ModuleClient) *cobra.Command {
79+
func queryCmd(cdc *amino.Codec) *cobra.Command {
11580
queryCmd := &cobra.Command{
11681
Use: "query",
11782
Aliases: []string{"q"},
11883
Short: "Querying subcommands",
11984
}
12085

12186
queryCmd.AddCommand(
87+
authcmd.GetAccountCmd(cdc),
88+
client.LineBreak,
12289
rpc.ValidatorCommand(cdc),
12390
rpc.BlockCommand(),
12491
tx.SearchTxCmd(cdc),
12592
tx.QueryTxCmd(cdc),
12693
client.LineBreak,
127-
authcmd.GetAccountCmd(at.StoreKey, cdc),
12894
)
12995

130-
for _, m := range mc {
131-
mQueryCmd := m.GetQueryCmd()
132-
if mQueryCmd != nil {
133-
queryCmd.AddCommand(mQueryCmd)
134-
}
135-
}
96+
// add modules' query commands
97+
app.ModuleBasics.AddQueryCommands(queryCmd, cdc)
13698

13799
return queryCmd
138100
}
139101

140-
func txCmd(cdc *amino.Codec, mc []sdk.ModuleClient) *cobra.Command {
102+
func txCmd(cdc *amino.Codec) *cobra.Command {
141103
txCmd := &cobra.Command{
142104
Use: "tx",
143105
Short: "Transactions subcommands",
144106
}
145107

146108
txCmd.AddCommand(
147-
bankcmd.SendTxCmd(cdc),
148-
client.LineBreak,
149-
authcmd.GetSignCommand(cdc),
150-
authcmd.GetMultiSignCommand(cdc),
151109
tx.GetBroadcastCommand(cdc),
152110
tx.GetEncodeCommand(cdc),
153111
client.LineBreak,
154112
)
155113

156-
for _, m := range mc {
157-
txCmd.AddCommand(m.GetTxCmd())
158-
}
114+
// add modules' tx commands
115+
app.ModuleBasics.AddTxCommands(txCmd, cdc)
159116

160117
return txCmd
161118
}
@@ -164,15 +121,8 @@ func txCmd(cdc *amino.Codec, mc []sdk.ModuleClient) *cobra.Command {
164121
// NOTE: details on the routes added for each module are in the module documentation
165122
// NOTE: If making updates here you also need to update the test helper in client/lcd/test_helper.go
166123
func registerRoutes(rs *lcd.RestServer) {
167-
rpc.RegisterRPCRoutes(rs.CliCtx, rs.Mux)
168-
tx.RegisterTxRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
169-
auth.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, at.StoreKey)
170-
bank.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
171-
dist.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, distcmd.StoreKey)
172-
staking.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
173-
slashing.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
174-
gov.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, paramsrest.ProposalRESTHandler(rs.CliCtx, rs.Cdc), dist.ProposalRESTHandler(rs.CliCtx, rs.Cdc))
175-
mintrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
124+
client.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
125+
app.ModuleBasics.RegisterRESTRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
176126
}
177127

178128
func initConfig(cmd *cobra.Command) error {

cmd/gaiad/testnet.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"github.com/cosmos/cosmos-sdk/server"
2424
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
2525
sdk "github.com/cosmos/cosmos-sdk/types"
26+
"github.com/cosmos/cosmos-sdk/types/module"
2627
"github.com/cosmos/cosmos-sdk/x/auth"
27-
authtx "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
2828
"github.com/cosmos/cosmos-sdk/x/auth/genaccounts"
2929
"github.com/cosmos/cosmos-sdk/x/genutil"
3030
"github.com/cosmos/cosmos-sdk/x/staking"
@@ -41,7 +41,7 @@ var (
4141

4242
// get cmd to initialize all files for tendermint testnet and application
4343
func testnetCmd(ctx *server.Context, cdc *codec.Codec,
44-
mbm sdk.ModuleBasicManager, genAccIterator genutil.GenesisAccountsIterator) *cobra.Command {
44+
mbm module.BasicManager, genAccIterator genutil.GenesisAccountsIterator) *cobra.Command {
4545

4646
cmd := &cobra.Command{
4747
Use: "testnet",
@@ -94,7 +94,7 @@ Example:
9494
const nodeDirPerm = 0755
9595

9696
// Initialize the testnet
97-
func InitTestnet(config *tmconfig.Config, cdc *codec.Codec, mbm sdk.ModuleBasicManager,
97+
func InitTestnet(config *tmconfig.Config, cdc *codec.Codec, mbm module.BasicManager,
9898
genAccIterator genutil.GenesisAccountsIterator,
9999
outputDir, chainID, minGasPrices, nodeDirPrefix, nodeDaemonHome,
100100
nodeCLIHome, startingIPAddress string, numValidators int) error {
@@ -214,7 +214,7 @@ func InitTestnet(config *tmconfig.Config, cdc *codec.Codec, mbm sdk.ModuleBasicM
214214
return err
215215
}
216216
tx := auth.NewStdTx([]sdk.Msg{msg}, auth.StdFee{}, []auth.StdSignature{}, memo)
217-
txBldr := authtx.NewTxBuilderFromCLI().WithChainID(chainID).WithMemo(memo).WithKeybase(kb)
217+
txBldr := auth.NewTxBuilderFromCLI().WithChainID(chainID).WithMemo(memo).WithKeybase(kb)
218218

219219
signedTx, err := txBldr.SignStdTx(nodeDirName, client.DefaultKeyPass, tx, false)
220220
if err != nil {
@@ -257,7 +257,7 @@ func InitTestnet(config *tmconfig.Config, cdc *codec.Codec, mbm sdk.ModuleBasicM
257257
return nil
258258
}
259259

260-
func initGenFiles(cdc *codec.Codec, mbm sdk.ModuleBasicManager, chainID string,
260+
func initGenFiles(cdc *codec.Codec, mbm module.BasicManager, chainID string,
261261
accs []genaccounts.GenesisAccount, genFiles []string, numValidators int) error {
262262

263263
appGenState := mbm.DefaultGenesis()

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.12
44

55
require (
66
github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c // indirect
7-
github.com/cosmos/cosmos-sdk v0.28.2-0.20190604220658-d322e234253a
7+
github.com/cosmos/cosmos-sdk v0.28.2-0.20190605232616-5f9c3fdf8895
88
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d // indirect
99
github.com/google/gofuzz v1.0.0 // indirect
1010
github.com/gorilla/mux v1.7.2 // indirect

0 commit comments

Comments
 (0)