Merge PR #3119: Move all store keys into constants
* Move all store keys into constants * Fix lint issue * Add Pending.md * QuerierKey -> QuerierRoute
This commit is contained in:
committed by
Christopher Goes
parent
5241c3c7c1
commit
14ebc65daf
@@ -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
|
||||
|
||||
@@ -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)
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
@@ -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,
|
||||
@@ -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:
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# Modules
|
||||
|
||||
In the previous app, we introduced a new `Msg` type and used Amino to encode
|
||||
transactions. We also introduced additional data to the `Tx`, and used a simple
|
||||
`AnteHandler` to validate it.
|
||||
transactions. We also introduced additional data to the `Tx`, and used a simple
|
||||
`AnteHandler` to validate it.
|
||||
|
||||
Here, in `App3`, we introduce two built-in SDK modules to
|
||||
replace the `Msg`, `Tx`, `Handler`, and `AnteHandler` implementations we've seen
|
||||
@@ -16,11 +16,11 @@ The `x/bank` module implements `Msg` and `Handler` - it has everything we need
|
||||
to transfer coins between accounts.
|
||||
|
||||
Here, we'll introduce the important types from `x/auth` and `x/bank`, and use
|
||||
them to build `App3`, our shortest app yet. The complete code can be found in
|
||||
them to build `App3`, our shortest app yet. The complete code can be found in
|
||||
[app3.go](examples/app3.go), and at the end of this section.
|
||||
|
||||
For more details, see the
|
||||
[x/auth](https://godoc.org/github.com/cosmos/cosmos-sdk/x/auth) and
|
||||
[x/auth](https://godoc.org/github.com/cosmos/cosmos-sdk/x/auth) and
|
||||
[x/bank](https://godoc.org/github.com/cosmos/cosmos-sdk/x/bank) API documentation.
|
||||
|
||||
## Accounts
|
||||
@@ -102,7 +102,7 @@ the `BaseAccount` to store additional data without requiring another lookup from
|
||||
the store.
|
||||
|
||||
Creating an AccountKeeper is easy - we just need to specify a codec, a
|
||||
capability key, and a prototype of the object being encoded
|
||||
capability key, and a prototype of the object being encoded
|
||||
|
||||
```go
|
||||
accountKeeper := auth.NewAccountKeeper(cdc, keyAccount, auth.ProtoBaseAccount)
|
||||
@@ -145,7 +145,7 @@ type StdTx struct {
|
||||
This is the standard form for a transaction in the SDK. Besides the Msgs, it
|
||||
includes:
|
||||
|
||||
- a fee to be paid by the first signer
|
||||
- a fee to be paid by the first signer
|
||||
- replay protecting nonces in the signature
|
||||
- a memo of prunable additional data
|
||||
|
||||
@@ -166,8 +166,8 @@ type StdSignature struct {
|
||||
}
|
||||
```
|
||||
|
||||
The signature includes both an `AccountNumber` and a `Sequence`.
|
||||
The `Sequence` must match the one in the
|
||||
The signature includes both an `AccountNumber` and a `Sequence`.
|
||||
The `Sequence` must match the one in the
|
||||
corresponding account when the transaction is processed, and will increment by
|
||||
one with every transaction. This prevents the same
|
||||
transaction from being replayed multiple times, resolving the insecurity that
|
||||
@@ -200,10 +200,10 @@ transaction fee can be paid, and reject the transaction if not.
|
||||
The `StdTx` supports multiple messages and multiple signers.
|
||||
To sign the transaction, each signer must collect the following information:
|
||||
|
||||
- the ChainID
|
||||
- the ChainID
|
||||
- the AccountNumber and Sequence for the given signer's account (from the
|
||||
blockchain)
|
||||
- the transaction fee
|
||||
- the transaction fee
|
||||
- the list of transaction messages
|
||||
- an optional memo
|
||||
|
||||
@@ -244,7 +244,7 @@ Note that validating
|
||||
signatures requires checking that the correct account number and sequence was
|
||||
used by each signer, as this information is required in the `StdSignBytes`.
|
||||
|
||||
If any of the above are not satisfied, the AnteHandelr returns an error.
|
||||
If any of the above are not satisfied, the AnteHandelr returns an error.
|
||||
|
||||
If all of the above verifications pass, the AnteHandler makes the following
|
||||
changes to the state:
|
||||
@@ -254,7 +254,7 @@ changes to the state:
|
||||
- deduct the fee from the first signer's account
|
||||
|
||||
Recall that incrementing the `Sequence` prevents "replay attacks" where
|
||||
the same message could be executed over and over again.
|
||||
the same message could be executed over and over again.
|
||||
|
||||
The PubKey is required for signature verification, but it is only required in
|
||||
the StdSignature once. From that point on, it will be stored in the account.
|
||||
@@ -267,13 +267,13 @@ Now that we've seen the `auth.AccountKeeper` and how its used to build a
|
||||
complete AnteHandler, it's time to look at how to build higher-level
|
||||
abstractions for taking action on accounts.
|
||||
|
||||
Earlier, we noted that `Mappers` are abstactions over KVStores that handle
|
||||
marshalling and unmarshalling data types to and from underlying stores.
|
||||
We can build another abstraction on top of `Mappers` that we call `Keepers`,
|
||||
Earlier, we noted that `Mappers` are abstactions over KVStores that handle
|
||||
marshalling and unmarshalling data types to and from underlying stores.
|
||||
We can build another abstraction on top of `Mappers` that we call `Keepers`,
|
||||
which expose only limitted functionality on the underlying types stored by the `Mapper`.
|
||||
|
||||
For instance, the `x/bank` module defines the canonical versions of `MsgSend`
|
||||
and `MsgIssue` for the SDK, as well as a `Handler` for processing them. However,
|
||||
and `MsgIssue` for the SDK, as well as a `Handler` for processing them. However,
|
||||
rather than passing a `KVStore` or even an `AccountKeeper` directly to the handler,
|
||||
we introduce a `bank.Keeper`, which can only be used to transfer coins in and out of accounts.
|
||||
This allows us to determine up front that the only effect the bank module's
|
||||
@@ -302,21 +302,21 @@ docs](https://godoc.org/github.com/cosmos/cosmos-sdk/x/bank#Keeper) for the full
|
||||
|
||||
Note we can refine the `bank.Keeper` by restricting it's method set. For
|
||||
instance, the
|
||||
[bank.ViewKeeper](https://godoc.org/github.com/cosmos/cosmos-sdk/x/bank#ViewKeeper)
|
||||
[bank.ViewKeeper](https://godoc.org/github.com/cosmos/cosmos-sdk/x/bank#ViewKeeper)
|
||||
is a read-only version, while the
|
||||
[bank.SendKeeper](https://godoc.org/github.com/cosmos/cosmos-sdk/x/bank#SendKeeper)
|
||||
[bank.SendKeeper](https://godoc.org/github.com/cosmos/cosmos-sdk/x/bank#SendKeeper)
|
||||
only executes transfers of coins from input accounts to output
|
||||
accounts.
|
||||
|
||||
We use this `Keeper` paradigm extensively in the SDK as the way to define what
|
||||
kind of functionality each module gets access to. In particular, we try to
|
||||
follow the *principle of least authority*.
|
||||
Rather than providing full blown access to the `KVStore` or the `AccountKeeper`,
|
||||
Rather than providing full blown access to the `KVStore` or the `AccountKeeper`,
|
||||
we restrict access to a small number of functions that do very specific things.
|
||||
|
||||
## App3
|
||||
|
||||
With the `auth.AccountKeeper` and `bank.Keeper` in hand,
|
||||
With the `auth.AccountKeeper` and `bank.Keeper` in hand,
|
||||
we're now ready to build `App3`.
|
||||
The `x/auth` and `x/bank` modules do all the heavy lifting:
|
||||
|
||||
@@ -330,8 +330,8 @@ func NewApp3(logger log.Logger, db dbm.DB) *bapp.BaseApp {
|
||||
app := bapp.NewBaseApp(app3Name, logger, db, auth.DefaultTxDecoder(cdc))
|
||||
|
||||
// Create a key for accessing the account store.
|
||||
keyAccount := sdk.NewKVStoreKey("acc")
|
||||
keyFees := sdk.NewKVStoreKey("fee") // TODO
|
||||
keyAccount := sdk.NewKVStoreKey(auth.StoreKey)
|
||||
keyFees := sdk.NewKVStoreKey(auth.FeeStoreKey) // TODO
|
||||
|
||||
// Set various mappers/keepers to interact easily with underlying stores
|
||||
accountKeeper := auth.NewAccountKeeper(cdc, keyAccount, auth.ProtoBaseAccount)
|
||||
@@ -355,8 +355,8 @@ func NewApp3(logger log.Logger, db dbm.DB) *bapp.BaseApp {
|
||||
}
|
||||
```
|
||||
|
||||
Note we use `bank.NewHandler`, which handles only `bank.MsgSend`,
|
||||
and receives only the `bank.Keeper`. See the
|
||||
Note we use `bank.NewHandler`, which handles only `bank.MsgSend`,
|
||||
and receives only the `bank.Keeper`. See the
|
||||
[x/bank API docs](https://godoc.org/github.com/cosmos/cosmos-sdk/x/bank)
|
||||
for more details.
|
||||
|
||||
@@ -366,7 +366,7 @@ We also use the default txDecoder in `x/auth`, which decodes amino-encoded
|
||||
## Conclusion
|
||||
|
||||
Armed with native modules for authentication and coin transfer,
|
||||
emboldened by the paradigm of mappers and keepers,
|
||||
and ever invigorated by the desire to build secure state-machines,
|
||||
emboldened by the paradigm of mappers and keepers,
|
||||
and ever invigorated by the desire to build secure state-machines,
|
||||
we find ourselves here with a full-blown, all-checks-in-place, multi-asset
|
||||
cryptocurrency - the beating heart of the Cosmos-SDK.
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
bapp "github.com/cosmos/cosmos-sdk/baseapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -22,7 +23,7 @@ func NewApp1(logger log.Logger, db dbm.DB) *bapp.BaseApp {
|
||||
app := bapp.NewBaseApp(app1Name, logger, db, tx1Decoder)
|
||||
|
||||
// Create a key for accessing the account store.
|
||||
keyAccount := sdk.NewKVStoreKey("acc")
|
||||
keyAccount := sdk.NewKVStoreKey(auth.StoreKey)
|
||||
|
||||
// Register message routes.
|
||||
// Note the handler gets access to the account store.
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
bapp "github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -42,7 +43,7 @@ func NewApp2(logger log.Logger, db dbm.DB) *bapp.BaseApp {
|
||||
app := bapp.NewBaseApp(app2Name, logger, db, tx2Decoder(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")
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ func NewApp3(logger log.Logger, db dbm.DB) *bapp.BaseApp {
|
||||
app := bapp.NewBaseApp(app3Name, logger, db, auth.DefaultTxDecoder(cdc))
|
||||
|
||||
// Create a key for accessing the account store.
|
||||
keyAccount := sdk.NewKVStoreKey("acc")
|
||||
keyFees := sdk.NewKVStoreKey("fee") // TODO
|
||||
keyAccount := sdk.NewKVStoreKey(auth.StoreKey)
|
||||
keyFees := sdk.NewKVStoreKey(auth.FeeStoreKey) // TODO
|
||||
|
||||
// Set various mappers/keepers to interact easily with underlying stores
|
||||
accountKeeper := auth.NewAccountKeeper(cdc, keyAccount, auth.ProtoBaseAccount)
|
||||
|
||||
@@ -25,14 +25,14 @@ func NewApp4(logger log.Logger, db dbm.DB) *bapp.BaseApp {
|
||||
app := bapp.NewBaseApp(app4Name, logger, db, auth.DefaultTxDecoder(cdc))
|
||||
|
||||
// Create a key for accessing the account store.
|
||||
keyAccount := sdk.NewKVStoreKey("acc")
|
||||
keyAccount := sdk.NewKVStoreKey(auth.StoreKey)
|
||||
|
||||
// Set various mappers/keepers to interact easily with underlying stores
|
||||
accountKeeper := auth.NewAccountKeeper(cdc, keyAccount, auth.ProtoBaseAccount)
|
||||
bankKeeper := bank.NewBaseKeeper(accountKeeper)
|
||||
|
||||
// TODO
|
||||
keyFees := sdk.NewKVStoreKey("fee")
|
||||
keyFees := sdk.NewKVStoreKey(auth.FeeStoreKey)
|
||||
feeKeeper := auth.NewFeeCollectionKeeper(cdc, keyFees)
|
||||
|
||||
app.SetAnteHandler(auth.NewAnteHandler(accountKeeper, feeKeeper))
|
||||
|
||||
@@ -56,7 +56,7 @@ type SimpleGovApp struct {
|
||||
|
||||
Let us do a quick reminder so that it is clear why we need these stores and keepers. Our application is primarily based on the `simple_governance` module. However, we have established in section [Keepers for our app](module-keeper.md) that our module needs access to two other modules: the `bank` module and the `stake` module. We also need the `auth` module for basic account functionalities. Finally, we need access to the main multistore to declare the stores of each of the module we use.
|
||||
|
||||
## CLI and Rest server
|
||||
## CLI and Rest server
|
||||
|
||||
We will need to add the newly created commands to our application. To do so, go to the `cmd` folder inside your root directory:
|
||||
|
||||
@@ -66,7 +66,7 @@ cd cmd
|
||||
```
|
||||
`simplegovd` is the folder that stores the command for running the server daemon, whereas `simplegovcli` defines the commands of your application.
|
||||
|
||||
### Application CLI
|
||||
### Application CLI
|
||||
|
||||
**File: [`cmd/simplegovcli/maing.go`](https://github.com/cosmos/cosmos-sdk/blob/fedekunze/module_tutorial/examples/simpleGov/cmd/simplegovcli/main.go)**
|
||||
|
||||
@@ -191,9 +191,9 @@ var cdc = MakeCodec()
|
||||
var app = &SimpleGovApp{
|
||||
BaseApp: bam.NewBaseApp(appName, cdc, logger, db),
|
||||
cdc: cdc,
|
||||
capKeyMainStore: sdk.NewKVStoreKey("main"),
|
||||
capKeyAccountStore: sdk.NewKVStoreKey("acc"),
|
||||
capKeyStakingStore: sdk.NewKVStoreKey("stake"),
|
||||
capKeyMainStore: sdk.NewKVStoreKey(bam.MainStoreKey),
|
||||
capKeyAccountStore: sdk.NewKVStoreKey(auth.StoreKey),
|
||||
capKeyStakingStore: sdk.NewKVStoreKey(stake.StoreKey),
|
||||
capKeySimpleGovStore: sdk.NewKVStoreKey("simpleGov"),
|
||||
}
|
||||
```
|
||||
@@ -248,4 +248,4 @@ func MakeCodec() *codec.Codec {
|
||||
cdc.RegisterConcrete(&types.AppAccount{}, "simpleGov/Account", nil)
|
||||
return cdc
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
@@ -13,7 +13,7 @@ commitment, only the `DeliverTx` is persisted.
|
||||
The BaseApp requires stores to be mounted via capabilities keys - handlers can
|
||||
only access stores they're given the key to. The `baseApp` ensures all stores are
|
||||
properly loaded, cached, and committed. One mounted store is considered the
|
||||
"main" - it holds the latest block header, from which we can find and load the
|
||||
"main" (`baseApp.MainStoreKey`) - it holds the latest block header, from which we can find and load the
|
||||
most recent state.
|
||||
|
||||
The BaseApp distinguishes between two handler types - the `AnteHandler` and the
|
||||
@@ -116,9 +116,9 @@ otherwise a gas meter with `ConsensusParam.BlockSize.MaxGas` is initialized.
|
||||
|
||||
Before the transaction logic is run, the `BlockGasMeter` is first checked to
|
||||
see if any gas remains. If no gas remains, then `DeliverTx` immediately returns
|
||||
an error.
|
||||
an error.
|
||||
|
||||
After the transaction has been processed, the used gas (up to the transaction
|
||||
gas limit) is deducted from the BlockGasMeter. If the remaining gas exceeds the
|
||||
meter's limits, then DeliverTx returns an error and the transaction is not
|
||||
committed.
|
||||
committed.
|
||||
|
||||
@@ -62,8 +62,8 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba
|
||||
var app = &BasecoinApp{
|
||||
cdc: cdc,
|
||||
BaseApp: bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...),
|
||||
keyMain: sdk.NewKVStoreKey("main"),
|
||||
keyAccount: sdk.NewKVStoreKey("acc"),
|
||||
keyMain: sdk.NewKVStoreKey(bam.MainStoreKey),
|
||||
keyAccount: sdk.NewKVStoreKey(auth.StoreKey),
|
||||
keyIBC: sdk.NewKVStoreKey("ibc"),
|
||||
}
|
||||
|
||||
|
||||
@@ -14,23 +14,20 @@ import (
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
at "github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
auth "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
|
||||
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||
bank "github.com/cosmos/cosmos-sdk/x/bank/client/rest"
|
||||
ibccmd "github.com/cosmos/cosmos-sdk/x/ibc/client/cli"
|
||||
sl "github.com/cosmos/cosmos-sdk/x/slashing"
|
||||
slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
|
||||
slashing "github.com/cosmos/cosmos-sdk/x/slashing/client/rest"
|
||||
st "github.com/cosmos/cosmos-sdk/x/stake"
|
||||
stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli"
|
||||
stake "github.com/cosmos/cosmos-sdk/x/stake/client/rest"
|
||||
)
|
||||
|
||||
const (
|
||||
storeAcc = "acc"
|
||||
storeSlashing = "slashing"
|
||||
storeStake = "stake"
|
||||
)
|
||||
|
||||
// rootCmd is the entry point for this binary
|
||||
var (
|
||||
rootCmd = &cobra.Command{
|
||||
@@ -68,21 +65,21 @@ func main() {
|
||||
|
||||
// add query/post commands (custom to binary)
|
||||
rootCmd.AddCommand(
|
||||
stakecmd.GetCmdQueryValidator(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryValidators(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryValidatorUnbondingDelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryValidatorRedelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryDelegation(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryDelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryPool(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryParams(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryUnbondingDelegation(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryUnbondingDelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryRedelegation(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryRedelegations(storeStake, cdc),
|
||||
slashingcmd.GetCmdQuerySigningInfo(storeSlashing, cdc),
|
||||
stakecmd.GetCmdQueryValidatorDelegations(storeStake, cdc),
|
||||
authcmd.GetAccountCmd(storeAcc, cdc),
|
||||
stakecmd.GetCmdQueryValidator(st.StoreKey, cdc),
|
||||
stakecmd.GetCmdQueryValidators(st.StoreKey, cdc),
|
||||
stakecmd.GetCmdQueryValidatorUnbondingDelegations(st.StoreKey, cdc),
|
||||
stakecmd.GetCmdQueryValidatorRedelegations(st.StoreKey, cdc),
|
||||
stakecmd.GetCmdQueryDelegation(st.StoreKey, cdc),
|
||||
stakecmd.GetCmdQueryDelegations(st.StoreKey, cdc),
|
||||
stakecmd.GetCmdQueryPool(st.StoreKey, cdc),
|
||||
stakecmd.GetCmdQueryParams(st.StoreKey, cdc),
|
||||
stakecmd.GetCmdQueryUnbondingDelegation(st.StoreKey, cdc),
|
||||
stakecmd.GetCmdQueryUnbondingDelegations(st.StoreKey, cdc),
|
||||
stakecmd.GetCmdQueryRedelegation(st.StoreKey, cdc),
|
||||
stakecmd.GetCmdQueryRedelegations(st.StoreKey, cdc),
|
||||
slashingcmd.GetCmdQuerySigningInfo(sl.StoreKey, cdc),
|
||||
stakecmd.GetCmdQueryValidatorDelegations(st.StoreKey, cdc),
|
||||
authcmd.GetAccountCmd(at.StoreKey, cdc),
|
||||
)
|
||||
|
||||
rootCmd.AddCommand(
|
||||
@@ -92,8 +89,8 @@ func main() {
|
||||
stakecmd.GetCmdCreateValidator(cdc),
|
||||
stakecmd.GetCmdEditValidator(cdc),
|
||||
stakecmd.GetCmdDelegate(cdc),
|
||||
stakecmd.GetCmdUnbond(storeStake, cdc),
|
||||
stakecmd.GetCmdRedelegate(storeStake, cdc),
|
||||
stakecmd.GetCmdUnbond(st.StoreKey, cdc),
|
||||
stakecmd.GetCmdRedelegate(st.StoreKey, cdc),
|
||||
slashingcmd.GetCmdUnjail(cdc),
|
||||
)
|
||||
|
||||
@@ -119,7 +116,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)
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/docs/examples/democoin/types"
|
||||
"github.com/cosmos/cosmos-sdk/docs/examples/democoin/x/cool"
|
||||
@@ -67,11 +68,11 @@ func NewDemocoinApp(logger log.Logger, db dbm.DB) *DemocoinApp {
|
||||
var app = &DemocoinApp{
|
||||
BaseApp: bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc)),
|
||||
cdc: cdc,
|
||||
capKeyMainStore: sdk.NewKVStoreKey("main"),
|
||||
capKeyAccountStore: sdk.NewKVStoreKey("acc"),
|
||||
capKeyMainStore: sdk.NewKVStoreKey(bam.MainStoreKey),
|
||||
capKeyAccountStore: sdk.NewKVStoreKey(auth.StoreKey),
|
||||
capKeyPowStore: sdk.NewKVStoreKey("pow"),
|
||||
capKeyIBCStore: sdk.NewKVStoreKey("ibc"),
|
||||
capKeyStakingStore: sdk.NewKVStoreKey("stake"),
|
||||
capKeyStakingStore: sdk.NewKVStoreKey(stake.StoreKey),
|
||||
}
|
||||
|
||||
// Define the accountKeeper.
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
at "github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
auth "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
|
||||
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||
@@ -31,7 +32,6 @@ var (
|
||||
Use: "democli",
|
||||
Short: "Democoin light-client",
|
||||
}
|
||||
storeAcc = "acc"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -65,7 +65,7 @@ func main() {
|
||||
// add query/post commands (custom to binary)
|
||||
// start with commands common to basecoin
|
||||
rootCmd.AddCommand(
|
||||
authcmd.GetAccountCmd(storeAcc, cdc),
|
||||
authcmd.GetAccountCmd(at.StoreKey, cdc),
|
||||
)
|
||||
rootCmd.AddCommand(
|
||||
bankcmd.SendTxCmd(cdc),
|
||||
@@ -108,6 +108,6 @@ 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)
|
||||
}
|
||||
|
||||
@@ -6,10 +6,9 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
)
|
||||
|
||||
const stakingToken = "stake"
|
||||
|
||||
const moduleName = "simplestake"
|
||||
|
||||
// simple stake keeper
|
||||
@@ -62,7 +61,7 @@ func (k Keeper) deleteBondInfo(ctx sdk.Context, addr sdk.AccAddress) {
|
||||
|
||||
// register a bond with the keeper
|
||||
func (k Keeper) Bond(ctx sdk.Context, addr sdk.AccAddress, pubKey crypto.PubKey, stake sdk.Coin) (int64, sdk.Error) {
|
||||
if stake.Denom != stakingToken {
|
||||
if stake.Denom != stakeTypes.DefaultBondDenom {
|
||||
return 0, ErrIncorrectStakingToken(k.codespace)
|
||||
}
|
||||
|
||||
@@ -93,7 +92,7 @@ func (k Keeper) Unbond(ctx sdk.Context, addr sdk.AccAddress) (crypto.PubKey, int
|
||||
}
|
||||
k.deleteBondInfo(ctx, addr)
|
||||
|
||||
returnedBond := sdk.NewInt64Coin(stakingToken, bi.Power)
|
||||
returnedBond := sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, bi.Power)
|
||||
|
||||
_, _, err := k.ck.AddCoins(ctx, addr, []sdk.Coin{returnedBond})
|
||||
if err != nil {
|
||||
@@ -106,7 +105,7 @@ func (k Keeper) Unbond(ctx sdk.Context, addr sdk.AccAddress) (crypto.PubKey, int
|
||||
// FOR TESTING PURPOSES -------------------------------------------------
|
||||
|
||||
func (k Keeper) bondWithoutCoins(ctx sdk.Context, addr sdk.AccAddress, pubKey crypto.PubKey, stake sdk.Coin) (int64, sdk.Error) {
|
||||
if stake.Denom != stakingToken {
|
||||
if stake.Denom != stakeTypes.DefaultBondDenom {
|
||||
return 0, ErrIncorrectStakingToken(k.codespace)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
)
|
||||
|
||||
func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey, *sdk.KVStoreKey) {
|
||||
@@ -75,10 +76,10 @@ func TestBonding(t *testing.T) {
|
||||
_, _, err := stakeKeeper.unbondWithoutCoins(ctx, addr)
|
||||
require.Equal(t, err, ErrInvalidUnbond(DefaultCodespace))
|
||||
|
||||
_, err = stakeKeeper.bondWithoutCoins(ctx, addr, pubKey, sdk.NewInt64Coin("stake", 10))
|
||||
_, err = stakeKeeper.bondWithoutCoins(ctx, addr, pubKey, sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 10))
|
||||
require.Nil(t, err)
|
||||
|
||||
power, err := stakeKeeper.bondWithoutCoins(ctx, addr, pubKey, sdk.NewInt64Coin("stake", 10))
|
||||
power, err := stakeKeeper.bondWithoutCoins(ctx, addr, pubKey, sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 10))
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, int64(20), power)
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
|
||||
func main() {
|
||||
|
||||
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "main")
|
||||
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", bam.MainStoreKey)
|
||||
|
||||
rootDir := viper.GetString(cli.HomeFlag)
|
||||
db, err := dbm.NewGoLevelDB("basecoind", filepath.Join(rootDir, "data"))
|
||||
@@ -29,7 +29,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Capabilities key to access the main KVStore.
|
||||
var capKeyMainStore = sdk.NewKVStoreKey("main")
|
||||
var capKeyMainStore = sdk.NewKVStoreKey(bam.MainStoreKey)
|
||||
|
||||
// Create BaseApp.
|
||||
var baseApp = bam.NewBaseApp("kvstore", logger, db, decodeTx)
|
||||
|
||||
Reference in New Issue
Block a user