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: Move all store keys into constants #3119

Merged
merged 5 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ BREAKING CHANGES
* Gaia CLI (`gaiacli`)

* Gaia
* https://github.com/cosmos/cosmos-sdk/issues/2838 - Move store keys to constants

* SDK

Expand Down
3 changes: 3 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const (
runTxModeSimulate runTxMode = iota
// Deliver a transaction
runTxModeDeliver runTxMode = iota

// MainStoreKey is the string representation of the main store
MainStoreKey = "main"
)

// BaseApp reflects the ABCI application implementation.
Expand Down
6 changes: 3 additions & 3 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestLoadVersion(t *testing.T) {
app := NewBaseApp(name, logger, db, nil)

// make a cap key and mount the store
capKey := sdk.NewKVStoreKey("main")
capKey := sdk.NewKVStoreKey(MainStoreKey)
app.MountStores(capKey)
err := app.LoadLatestVersion(capKey) // needed to make stores non-nil
require.Nil(t, err)
Expand Down Expand Up @@ -160,7 +160,7 @@ func testChangeNameHelper(name string) func(*BaseApp) {
app := newBaseApp(t.Name())

// make a cap key and mount the store
capKey := sdk.NewKVStoreKey("main")
capKey := sdk.NewKVStoreKey(MainStoreKey)
app.MountStores(capKey)
err := app.LoadLatestVersion(capKey) // needed to make stores non-nil
require.Nil(t, err)
Expand Down Expand Up @@ -217,7 +217,7 @@ func TestInitChainer(t *testing.T) {
db := dbm.NewMemDB()
logger := defaultLogger()
app := NewBaseApp(name, logger, db, nil)
capKey := sdk.NewKVStoreKey("main")
capKey := sdk.NewKVStoreKey(MainStoreKey)
capKey2 := sdk.NewKVStoreKey("key2")
app.MountStores(capKey, capKey2)

Expand Down
4 changes: 1 addition & 3 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"github.com/cosmos/cosmos-sdk/types"
)

const ctxAccStoreName = "acc"

var (
verifier tmlite.Verifier
)
Expand Down Expand Up @@ -76,7 +74,7 @@ func NewCLIContext() CLIContext {
Client: rpc,
Output: os.Stdout,
NodeURI: nodeURI,
AccountStore: ctxAccStoreName,
AccountStore: auth.StoreKey,
From: viper.GetString(client.FlagFrom),
Height: viper.GetInt64(client.FlagHeight),
TrustNode: viper.GetBool(client.FlagTrustNode),
Expand Down
2 changes: 1 addition & 1 deletion client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func registerRoutes(rs *RestServer) {
keys.RegisterRoutes(rs.Mux, rs.CliCtx.Indent)
rpc.RegisterRoutes(rs.CliCtx, rs.Mux)
tx.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
authRest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, "acc")
authRest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, auth.StoreKey)
bankRest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
stakeRest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
slashingRest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
Expand Down
40 changes: 20 additions & 20 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
var app = &GaiaApp{
BaseApp: bApp,
cdc: cdc,
keyMain: sdk.NewKVStoreKey("main"),
keyAccount: sdk.NewKVStoreKey("acc"),
keyStake: sdk.NewKVStoreKey("stake"),
tkeyStake: sdk.NewTransientStoreKey("transient_stake"),
keyMint: sdk.NewKVStoreKey("mint"),
keyDistr: sdk.NewKVStoreKey("distr"),
tkeyDistr: sdk.NewTransientStoreKey("transient_distr"),
keySlashing: sdk.NewKVStoreKey("slashing"),
keyGov: sdk.NewKVStoreKey("gov"),
keyFeeCollection: sdk.NewKVStoreKey("fee"),
keyParams: sdk.NewKVStoreKey("params"),
tkeyParams: sdk.NewTransientStoreKey("transient_params"),
keyMain: sdk.NewKVStoreKey(bam.MainStoreKey),
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
keyAccount: sdk.NewKVStoreKey(auth.StoreKey),
keyStake: sdk.NewKVStoreKey(stake.StoreKey),
tkeyStake: sdk.NewTransientStoreKey(stake.TStoreKey),
keyMint: sdk.NewKVStoreKey(mint.StoreKey),
keyDistr: sdk.NewKVStoreKey(distr.StoreKey),
tkeyDistr: sdk.NewTransientStoreKey(distr.TStoreKey),
keySlashing: sdk.NewKVStoreKey(slashing.StoreKey),
keyGov: sdk.NewKVStoreKey(gov.StoreKey),
keyFeeCollection: sdk.NewKVStoreKey(auth.FeeStoreKey),
keyParams: sdk.NewKVStoreKey(params.StoreKey),
tkeyParams: sdk.NewTransientStoreKey(params.TStoreKey),
}

// define the accountKeeper
Expand Down Expand Up @@ -147,16 +147,16 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio

// register message routes
app.Router().
AddRoute("bank", bank.NewHandler(app.bankKeeper)).
AddRoute("stake", stake.NewHandler(app.stakeKeeper)).
AddRoute("distr", distr.NewHandler(app.distrKeeper)).
AddRoute("slashing", slashing.NewHandler(app.slashingKeeper)).
AddRoute("gov", gov.NewHandler(app.govKeeper))
AddRoute(bank.RouterKey, bank.NewHandler(app.bankKeeper)).
AddRoute(stake.RouterKey, stake.NewHandler(app.stakeKeeper)).
AddRoute(distr.RouterKey, distr.NewHandler(app.distrKeeper)).
AddRoute(slashing.RouterKey, slashing.NewHandler(app.slashingKeeper)).
AddRoute(gov.RouterKey, gov.NewHandler(app.govKeeper))

app.QueryRouter().
AddRoute("gov", gov.NewQuerier(app.govKeeper)).
AddRoute(slashing.QuerierRoute, slashing.NewQuerier(app.slashingKeeper, app.cdc)).
AddRoute("stake", stake.NewQuerier(app.stakeKeeper, app.cdc))
AddRoute(gov.QuerierRoute, gov.NewQuerier(app.govKeeper)).
AddRoute(slashing.QuerierRoute, slashing.NewQuerier(app.slashingKeeper, app.cdc)).
AddRoute(stake.QuerierRoute, stake.NewQuerier(app.stakeKeeper, app.cdc))

// initialize BaseApp
app.MountStores(app.keyMain, app.keyAccount, app.keyStake, app.keyMint, app.keyDistr,
Expand Down
25 changes: 11 additions & 14 deletions cmd/gaia/cmd/gaiacli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"

at "github.com/cosmos/cosmos-sdk/x/auth"
auth "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
bank "github.com/cosmos/cosmos-sdk/x/bank/client/rest"
dist "github.com/cosmos/cosmos-sdk/x/distribution"
gv "github.com/cosmos/cosmos-sdk/x/gov"
gov "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
sl "github.com/cosmos/cosmos-sdk/x/slashing"
slashing "github.com/cosmos/cosmos-sdk/x/slashing/client/rest"
st "github.com/cosmos/cosmos-sdk/x/stake"
stake "github.com/cosmos/cosmos-sdk/x/stake/client/rest"

authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
Expand All @@ -38,14 +43,6 @@ import (
_ "github.com/cosmos/cosmos-sdk/client/lcd/statik"
)

const (
storeAcc = "acc"
storeGov = "gov"
storeSlashing = "slashing"
storeStake = "stake"
storeDist = "distr"
)

func main() {
// Configure cobra to sort commands
cobra.EnableCommandSorting = false
Expand All @@ -67,10 +64,10 @@ func main() {
// Module clients hold cli commnads (tx,query) and lcd routes
// TODO: Make the lcd command take a list of ModuleClient
mc := []sdk.ModuleClients{
govClient.NewModuleClient(storeGov, cdc),
distClient.NewModuleClient(storeDist, cdc),
stakeClient.NewModuleClient(storeStake, cdc),
slashingClient.NewModuleClient(storeSlashing, cdc),
govClient.NewModuleClient(gv.StoreKey, cdc),
distClient.NewModuleClient(dist.StoreKey, cdc),
stakeClient.NewModuleClient(st.StoreKey, cdc),
slashingClient.NewModuleClient(sl.StoreKey, cdc),
}

rootCmd := &cobra.Command{
Expand Down Expand Up @@ -120,7 +117,7 @@ func queryCmd(cdc *amino.Codec, mc []sdk.ModuleClients) *cobra.Command {
tx.SearchTxCmd(cdc),
tx.QueryTxCmd(cdc),
client.LineBreak,
authcmd.GetAccountCmd(storeAcc, cdc),
authcmd.GetAccountCmd(at.StoreKey, cdc),
)

for _, m := range mc {
Expand Down Expand Up @@ -159,7 +156,7 @@ func registerRoutes(rs *lcd.RestServer) {
keys.RegisterRoutes(rs.Mux, rs.CliCtx.Indent)
rpc.RegisterRoutes(rs.CliCtx, rs.Mux)
tx.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
auth.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, storeAcc)
auth.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, at.StoreKey)
bank.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
stake.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
slashing.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
Expand Down
16 changes: 8 additions & 8 deletions cmd/gaia/cmd/gaiadebug/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp
var app = &GaiaApp{
BaseApp: bApp,
cdc: cdc,
keyMain: sdk.NewKVStoreKey("main"),
keyAccount: sdk.NewKVStoreKey("acc"),
keyStake: sdk.NewKVStoreKey("stake"),
tkeyStake: sdk.NewTransientStoreKey("transient_stake"),
keySlashing: sdk.NewKVStoreKey("slashing"),
keyParams: sdk.NewKVStoreKey("params"),
tkeyParams: sdk.NewTransientStoreKey("transient_params"),
keyMain: sdk.NewKVStoreKey(bam.MainStoreKey),
keyAccount: sdk.NewKVStoreKey(auth.StoreKey),
keyStake: sdk.NewKVStoreKey(stake.StoreKey),
tkeyStake: sdk.NewTransientStoreKey(stake.TStoreKey),
keySlashing: sdk.NewKVStoreKey(slashing.StoreKey),
keyParams: sdk.NewKVStoreKey(params.StoreKey),
tkeyParams: sdk.NewTransientStoreKey(params.TStoreKey),
}

// define the accountKeeper
Expand All @@ -181,7 +181,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp
// register message routes
app.Router().
AddRoute("bank", bank.NewHandler(app.bankKeeper)).
AddRoute("stake", stake.NewHandler(app.stakeKeeper))
AddRoute(stake.RouterKey, stake.NewHandler(app.stakeKeeper))

// initialize BaseApp
app.SetInitChainer(app.initChainer)
Expand Down
2 changes: 1 addition & 1 deletion docs/_attic/sdk/core/app1.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func NewApp1(logger log.Logger, db dbm.DB) *bapp.BaseApp {
app := bapp.NewBaseApp(app1Name, logger, db, tx1Decoder)

// Create a capability key for accessing the account store.
keyAccount := sdk.NewKVStoreKey("acc")
keyAccount := sdk.NewKVStoreKey(auth.StoreKey)

// Register message routes.
// Note the handler receives the keyAccount and thus
Expand Down
20 changes: 10 additions & 10 deletions docs/_attic/sdk/core/app2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

In the previous app we built a simple bank with one message type `send` for sending
coins and one store for storing accounts.
Here we build `App2`, which expands on `App1` by introducing
Here we build `App2`, which expands on `App1` by introducing

- a new message type for issuing new coins
- a new store for coin metadata (like who can issue coins)
Expand Down Expand Up @@ -38,7 +38,7 @@ methods for `MsgIssue` are similar to `MsgSend`.
## Handler

We'll need a new handler to support the new message type. It just checks if the
sender of the `MsgIssue` is the correct issuer for the given coin type, as per the information
sender of the `MsgIssue` is the correct issuer for the given coin type, as per the information
in the issuer store:

```go
Expand Down Expand Up @@ -107,11 +107,11 @@ but that's left as an excercise for the reader :).

## Amino

Now that we have two implementations of `Msg`, we won't know before hand
Now that we have two implementations of `Msg`, we won't know before hand
which type is contained in a serialized `Tx`. Ideally, we would use the
`Msg` interface inside our `Tx` implementation, but the JSON decoder can't
decode into interface types. In fact, there's no standard way to unmarshal
into interfaces in Go. This is one of the primary reasons we built
decode into interface types. In fact, there's no standard way to unmarshal
into interfaces in Go. This is one of the primary reasons we built
[Amino](https://github.com/tendermint/go-amino) :).

While SDK developers can encode transactions and state objects however they
Expand All @@ -121,7 +121,7 @@ excludes the `oneof` keyword.

While `oneof` provides union types, Amino aims to provide interfaces.
The main difference being that with union types, you have to know all the types
up front. But anyone can implement an interface type whenever and however
up front. But anyone can implement an interface type whenever and however
they like.

To implement interface types, Amino allows any concrete implementation of an
Expand Down Expand Up @@ -164,7 +164,7 @@ Now that we're using Amino, we can embed the `Msg` interface directly in our
// Simple tx to wrap the Msg.
type app2Tx struct {
sdk.Msg

PubKey crypto.PubKey
Signature []byte
}
Expand All @@ -189,7 +189,7 @@ func tx2Decoder(cdc *codec.Codec) sdk.TxDecoder {

## AnteHandler

Now that we have an implementation of `Tx` that includes more than just the Msg,
Now that we have an implementation of `Tx` that includes more than just the Msg,
we need to specify how that extra information is validated and processed. This
is the role of the `AnteHandler`. The word `ante` here denotes "before", as the
`AnteHandler` is run before a `Handler`. While an app can have many Handlers,
Expand All @@ -209,7 +209,7 @@ according to whatever capability keys it was granted. Instead of a `Msg`,
however, it takes a `Tx`.

Like Handler, AnteHandler returns a `Result` type, but it also returns a new
`Context` and an `abort bool`.
`Context` and an `abort bool`.

For `App2`, we simply check if the PubKey matches the Address, and the Signature validates with the PubKey:

Expand Down Expand Up @@ -259,7 +259,7 @@ func NewApp2(logger log.Logger, db dbm.DB) *bapp.BaseApp {
app := bapp.NewBaseApp(app2Name, logger, db, txDecoder(cdc))

// Create a key for accessing the account store.
keyAccount := sdk.NewKVStoreKey("acc")
keyAccount := sdk.NewKVStoreKey(auth.StoreKey)
// Create a key for accessing the issue store.
keyIssue := sdk.NewKVStoreKey("issue")

Expand Down
Loading