Merge PR #4451: Client and Module Modularization
This commit is contained in:
parent
d80a980c30
commit
5f9c3fdf88
|
@ -0,0 +1,5 @@
|
|||
#4451 Improve modularization of clients and modules:
|
||||
* Module directory structure improved and standardized
|
||||
* Aliases autogenerated
|
||||
* Auth and bank related commands are now mounted under the respective moduels
|
||||
* Client initialization and mounting standardized
|
|
@ -8,15 +8,8 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptokeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"gopkg.in/yaml.v2"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
@ -24,7 +17,12 @@ import (
|
|||
tmliteProxy "github.com/tendermint/tendermint/lite/proxy"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptokeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -36,7 +34,7 @@ var (
|
|||
// transaction handling and queries.
|
||||
type CLIContext struct {
|
||||
Codec *codec.Codec
|
||||
AccDecoder auth.AccountDecoder
|
||||
AccDecoder authtypes.AccountDecoder
|
||||
Client rpcclient.Client
|
||||
Keybase cryptokeys.Keybase
|
||||
Output io.Writer
|
||||
|
@ -90,7 +88,7 @@ func NewCLIContextWithFrom(from string) CLIContext {
|
|||
Client: rpc,
|
||||
Output: os.Stdout,
|
||||
NodeURI: nodeURI,
|
||||
AccountStore: auth.StoreKey,
|
||||
AccountStore: authtypes.StoreKey,
|
||||
From: viper.GetString(flags.FlagFrom),
|
||||
OutputFormat: viper.GetString(cli.OutputFlag),
|
||||
Height: viper.GetInt64(flags.FlagHeight),
|
||||
|
@ -165,8 +163,8 @@ func (ctx CLIContext) WithCodec(cdc *codec.Codec) CLIContext {
|
|||
}
|
||||
|
||||
// GetAccountDecoder gets the account decoder for auth.DefaultAccount.
|
||||
func GetAccountDecoder(cdc *codec.Codec) auth.AccountDecoder {
|
||||
return func(accBytes []byte) (acct auth.Account, err error) {
|
||||
func GetAccountDecoder(cdc *codec.Codec) authtypes.AccountDecoder {
|
||||
return func(accBytes []byte) (acct authtypes.Account, err error) {
|
||||
err = cdc.UnmarshalBinaryBare(accBytes, &acct)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
|
||||
"github.com/cosmos/cosmos-sdk/store/rootmulti"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
// GetNode returns an RPC client. If the context's client is not defined, an
|
||||
|
@ -59,7 +59,7 @@ func (ctx CLIContext) QuerySubspace(subspace []byte, storeName string) (res []sd
|
|||
|
||||
// GetAccount queries for an account given an address and a block height. An
|
||||
// error is returned if the query or decoding fails.
|
||||
func (ctx CLIContext) GetAccount(address []byte) (auth.Account, error) {
|
||||
func (ctx CLIContext) GetAccount(address []byte) (authtypes.Account, error) {
|
||||
if ctx.AccDecoder == nil {
|
||||
return nil, errors.New("account decoder required but not provided")
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ func (ctx CLIContext) GetAccount(address []byte) (auth.Account, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var account auth.Account
|
||||
var account authtypes.Account
|
||||
if err := ctx.Codec.UnmarshalJSON(res, &account); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -127,12 +127,12 @@ func (ctx CLIContext) EnsureAccountExistsFromAddr(addr sdk.AccAddress) error {
|
|||
// queryAccount queries an account using custom query endpoint of auth module
|
||||
// returns an error if result is `null` otherwise account data
|
||||
func (ctx CLIContext) queryAccount(addr sdk.AccAddress) ([]byte, error) {
|
||||
bz, err := ctx.Codec.MarshalJSON(auth.NewQueryAccountParams(addr))
|
||||
bz, err := ctx.Codec.MarshalJSON(authtypes.NewQueryAccountParams(addr))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", ctx.AccountStore, auth.QueryAccount)
|
||||
route := fmt.Sprintf("custom/%s/%s", ctx.AccountStore, authtypes.QueryAccount)
|
||||
|
||||
res, err := ctx.QueryWithData(route, bz)
|
||||
if err != nil {
|
||||
|
|
|
@ -9,6 +9,7 @@ var cdc *codec.Codec
|
|||
func init() {
|
||||
cdc = codec.New()
|
||||
codec.RegisterCrypto(cdc)
|
||||
cdc.Seal()
|
||||
}
|
||||
|
||||
// marshal keys
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -32,7 +31,7 @@ func WriteGenerateStdTxResponse(w http.ResponseWriter, cdc *codec.Codec,
|
|||
return
|
||||
}
|
||||
|
||||
txBldr := authtxb.NewTxBuilder(
|
||||
txBldr := auth.NewTxBuilder(
|
||||
utils.GetTxEncoder(cdc), br.AccountNumber, br.Sequence, gas, gasAdj,
|
||||
br.Simulate, br.ChainID, br.Memo, br.Fees, br.GasPrices,
|
||||
)
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
)
|
||||
|
||||
// Register routes
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
|
||||
RegisterRPCRoutes(cliCtx, r)
|
||||
RegisterTxRoutes(cliCtx, r, cdc)
|
||||
}
|
|
@ -5,7 +5,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
|
@ -62,7 +61,7 @@ func BroadcastTxRequest(cliCtx context.CLIContext, cdc *codec.Codec) http.Handle
|
|||
}
|
||||
|
||||
// GetBroadcastCommand returns the tx broadcast command.
|
||||
func GetBroadcastCommand(codec *amino.Codec) *cobra.Command {
|
||||
func GetBroadcastCommand(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "broadcast [file_path]",
|
||||
Short: "Broadcast transactions generated offline",
|
||||
|
@ -75,7 +74,7 @@ $ <appcli> tx broadcast ./mytxn.json
|
|||
`),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
cliCtx := context.NewCLIContext().WithCodec(codec)
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
stdTx, err := utils.ReadStdTxFromFile(cliCtx.Codec, args[0])
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
|
@ -69,7 +68,7 @@ func (txr txEncodeRespStr) String() string {
|
|||
|
||||
// GetEncodeCommand returns the encode command to take a JSONified transaction and turn it into
|
||||
// Amino-serialized bytes
|
||||
func GetEncodeCommand(codec *amino.Codec) *cobra.Command {
|
||||
func GetEncodeCommand(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "encode [file]",
|
||||
Short: "Encode transactions generated offline",
|
||||
|
@ -78,7 +77,7 @@ Read a transaction from <file>, serialize it to the Amino wire protocol, and out
|
|||
If you supply a dash (-) argument in place of an input filename, the command reads from standard input.`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
cliCtx := context.NewCLIContext().WithCodec(codec)
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
|
||||
stdTx, err := utils.ReadStdTxFromFile(cliCtx.Codec, args[0])
|
||||
if err != nil {
|
||||
|
|
|
@ -18,8 +18,7 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
// GasEstimateResponse defines a response definition for tx gas estimation.
|
||||
|
@ -35,7 +34,7 @@ func (gr GasEstimateResponse) String() string {
|
|||
// the provided context has generate-only enabled, the tx will only be printed
|
||||
// to STDOUT in a fully offline manner. Otherwise, the tx will be signed and
|
||||
// broadcasted.
|
||||
func GenerateOrBroadcastMsgs(cliCtx context.CLIContext, txBldr authtxb.TxBuilder, msgs []sdk.Msg) error {
|
||||
func GenerateOrBroadcastMsgs(cliCtx context.CLIContext, txBldr authtypes.TxBuilder, msgs []sdk.Msg) error {
|
||||
if cliCtx.GenerateOnly {
|
||||
return PrintUnsignedStdTx(txBldr, cliCtx, msgs)
|
||||
}
|
||||
|
@ -48,7 +47,7 @@ func GenerateOrBroadcastMsgs(cliCtx context.CLIContext, txBldr authtxb.TxBuilder
|
|||
// QueryContext. It ensures that the account exists, has a proper number and
|
||||
// sequence set. In addition, it builds and signs a transaction with the
|
||||
// supplied messages. Finally, it broadcasts the signed transaction to a node.
|
||||
func CompleteAndBroadcastTxCLI(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) error {
|
||||
func CompleteAndBroadcastTxCLI(txBldr authtypes.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) error {
|
||||
txBldr, err := PrepareTxBuilder(txBldr, cliCtx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -118,7 +117,7 @@ func CompleteAndBroadcastTxCLI(txBldr authtxb.TxBuilder, cliCtx context.CLIConte
|
|||
|
||||
// EnrichWithGas calculates the gas estimate that would be consumed by the
|
||||
// transaction and set the transaction's respective value accordingly.
|
||||
func EnrichWithGas(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (authtxb.TxBuilder, error) {
|
||||
func EnrichWithGas(txBldr authtypes.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (authtypes.TxBuilder, error) {
|
||||
_, adjusted, err := simulateMsgs(txBldr, cliCtx, msgs)
|
||||
if err != nil {
|
||||
return txBldr, err
|
||||
|
@ -146,7 +145,7 @@ func CalculateGas(queryFunc func(string, common.HexBytes) ([]byte, error),
|
|||
}
|
||||
|
||||
// PrintUnsignedStdTx builds an unsigned StdTx and prints it to os.Stdout.
|
||||
func PrintUnsignedStdTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) error {
|
||||
func PrintUnsignedStdTx(txBldr authtypes.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) error {
|
||||
stdTx, err := buildUnsignedStdTxOffline(txBldr, cliCtx, msgs)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -165,11 +164,11 @@ func PrintUnsignedStdTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msg
|
|||
// is false, it replaces the signatures already attached with the new signature.
|
||||
// Don't perform online validation or lookups if offline is true.
|
||||
func SignStdTx(
|
||||
txBldr authtxb.TxBuilder, cliCtx context.CLIContext, name string,
|
||||
stdTx auth.StdTx, appendSig bool, offline bool,
|
||||
) (auth.StdTx, error) {
|
||||
txBldr authtypes.TxBuilder, cliCtx context.CLIContext, name string,
|
||||
stdTx authtypes.StdTx, appendSig bool, offline bool,
|
||||
) (authtypes.StdTx, error) {
|
||||
|
||||
var signedStdTx auth.StdTx
|
||||
var signedStdTx authtypes.StdTx
|
||||
|
||||
info, err := txBldr.Keybase().Get(name)
|
||||
if err != nil {
|
||||
|
@ -201,9 +200,9 @@ func SignStdTx(
|
|||
// SignStdTxWithSignerAddress attaches a signature to a StdTx and returns a copy of a it.
|
||||
// Don't perform online validation or lookups if offline is true, else
|
||||
// populate account and sequence numbers from a foreign account.
|
||||
func SignStdTxWithSignerAddress(txBldr authtxb.TxBuilder, cliCtx context.CLIContext,
|
||||
addr sdk.AccAddress, name string, stdTx auth.StdTx,
|
||||
offline bool) (signedStdTx auth.StdTx, err error) {
|
||||
func SignStdTxWithSignerAddress(txBldr authtypes.TxBuilder, cliCtx context.CLIContext,
|
||||
addr sdk.AccAddress, name string, stdTx authtypes.StdTx,
|
||||
offline bool) (signedStdTx authtypes.StdTx, err error) {
|
||||
|
||||
// check whether the address is a signer
|
||||
if !isTxSigner(addr, stdTx.GetSigners()) {
|
||||
|
@ -226,7 +225,7 @@ func SignStdTxWithSignerAddress(txBldr authtxb.TxBuilder, cliCtx context.CLICont
|
|||
}
|
||||
|
||||
// Read and decode a StdTx from the given filename. Can pass "-" to read from stdin.
|
||||
func ReadStdTxFromFile(cdc *codec.Codec, filename string) (stdTx auth.StdTx, err error) {
|
||||
func ReadStdTxFromFile(cdc *codec.Codec, filename string) (stdTx authtypes.StdTx, err error) {
|
||||
var bytes []byte
|
||||
if filename == "-" {
|
||||
bytes, err = ioutil.ReadAll(os.Stdin)
|
||||
|
@ -243,8 +242,8 @@ func ReadStdTxFromFile(cdc *codec.Codec, filename string) (stdTx auth.StdTx, err
|
|||
}
|
||||
|
||||
func populateAccountFromState(
|
||||
txBldr authtxb.TxBuilder, cliCtx context.CLIContext, addr sdk.AccAddress,
|
||||
) (authtxb.TxBuilder, error) {
|
||||
txBldr authtypes.TxBuilder, cliCtx context.CLIContext, addr sdk.AccAddress,
|
||||
) (authtypes.TxBuilder, error) {
|
||||
|
||||
accNum, err := cliCtx.GetAccountNumber(addr)
|
||||
if err != nil {
|
||||
|
@ -264,14 +263,14 @@ func populateAccountFromState(
|
|||
func GetTxEncoder(cdc *codec.Codec) (encoder sdk.TxEncoder) {
|
||||
encoder = sdk.GetConfig().GetTxEncoder()
|
||||
if encoder == nil {
|
||||
encoder = auth.DefaultTxEncoder(cdc)
|
||||
encoder = authtypes.DefaultTxEncoder(cdc)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// nolint
|
||||
// SimulateMsgs simulates the transaction and returns the gas estimate and the adjusted value.
|
||||
func simulateMsgs(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (estimated, adjusted uint64, err error) {
|
||||
func simulateMsgs(txBldr authtypes.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (estimated, adjusted uint64, err error) {
|
||||
txBytes, err := txBldr.BuildTxForSim(msgs)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -293,7 +292,7 @@ func parseQueryResponse(cdc *codec.Codec, rawRes []byte) (uint64, error) {
|
|||
}
|
||||
|
||||
// PrepareTxBuilder populates a TxBuilder in preparation for the build of a Tx.
|
||||
func PrepareTxBuilder(txBldr authtxb.TxBuilder, cliCtx context.CLIContext) (authtxb.TxBuilder, error) {
|
||||
func PrepareTxBuilder(txBldr authtypes.TxBuilder, cliCtx context.CLIContext) (authtypes.TxBuilder, error) {
|
||||
if err := cliCtx.EnsureAccountExists(); err != nil {
|
||||
return txBldr, err
|
||||
}
|
||||
|
@ -322,7 +321,7 @@ func PrepareTxBuilder(txBldr authtxb.TxBuilder, cliCtx context.CLIContext) (auth
|
|||
return txBldr, nil
|
||||
}
|
||||
|
||||
func buildUnsignedStdTxOffline(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (stdTx auth.StdTx, err error) {
|
||||
func buildUnsignedStdTxOffline(txBldr authtypes.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (stdTx authtypes.StdTx, err error) {
|
||||
if txBldr.SimulateAndExecute() {
|
||||
if cliCtx.GenerateOnly {
|
||||
return stdTx, errors.New("cannot estimate gas with generate-only")
|
||||
|
@ -341,7 +340,7 @@ func buildUnsignedStdTxOffline(txBldr authtxb.TxBuilder, cliCtx context.CLIConte
|
|||
return stdTx, nil
|
||||
}
|
||||
|
||||
return auth.NewStdTx(stdSignMsg.Msgs, stdSignMsg.Fee, nil, stdSignMsg.Memo), nil
|
||||
return authtypes.NewStdTx(stdSignMsg.Msgs, stdSignMsg.Fee, nil, stdSignMsg.Memo), nil
|
||||
}
|
||||
|
||||
func isTxSigner(user sdk.AccAddress, signers []sdk.AccAddress) bool {
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -73,7 +73,7 @@ func TestCalculateGas(t *testing.T) {
|
|||
func TestDefaultTxEncoder(t *testing.T) {
|
||||
cdc := makeCodec()
|
||||
|
||||
defaultEncoder := auth.DefaultTxEncoder(cdc)
|
||||
defaultEncoder := authtypes.DefaultTxEncoder(cdc)
|
||||
encoder := GetTxEncoder(cdc)
|
||||
|
||||
compareEncoders(t, defaultEncoder, encoder)
|
||||
|
@ -99,8 +99,8 @@ func TestReadStdTxFromFile(t *testing.T) {
|
|||
sdk.RegisterCodec(cdc)
|
||||
|
||||
// Build a test transaction
|
||||
fee := auth.NewStdFee(50000, sdk.Coins{sdk.NewInt64Coin("atom", 150)})
|
||||
stdTx := auth.NewStdTx([]sdk.Msg{}, fee, []auth.StdSignature{}, "foomemo")
|
||||
fee := authtypes.NewStdFee(50000, sdk.Coins{sdk.NewInt64Coin("atom", 150)})
|
||||
stdTx := authtypes.NewStdTx([]sdk.Msg{}, fee, []authtypes.StdSignature{}, "foomemo")
|
||||
|
||||
// Write it to the file
|
||||
encodedTx, _ := cdc.MarshalJSON(stdTx)
|
||||
|
@ -158,7 +158,7 @@ func TestValidateCmd(t *testing.T) {
|
|||
|
||||
func compareEncoders(t *testing.T, expected sdk.TxEncoder, actual sdk.TxEncoder) {
|
||||
msgs := []sdk.Msg{sdk.NewTestMsg(addr)}
|
||||
tx := auth.NewStdTx(msgs, auth.StdFee{}, []auth.StdSignature{}, "")
|
||||
tx := authtypes.NewStdTx(msgs, authtypes.StdFee{}, []authtypes.StdSignature{}, "")
|
||||
|
||||
defaultEncoderBytes, err := expected(tx)
|
||||
require.NoError(t, err)
|
||||
|
@ -181,7 +181,7 @@ func makeCodec() *codec.Codec {
|
|||
var cdc = codec.New()
|
||||
sdk.RegisterCodec(cdc)
|
||||
codec.RegisterCrypto(cdc)
|
||||
auth.RegisterCodec(cdc)
|
||||
authtypes.RegisterCodec(cdc)
|
||||
cdc.RegisterConcrete(sdk.TestMsg{}, "cosmos-sdk/Test", nil)
|
||||
return cdc
|
||||
}
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
package keys
|
||||
|
||||
import (
|
||||
amino "github.com/tendermint/go-amino"
|
||||
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/hd"
|
||||
)
|
||||
|
||||
var cdc = amino.NewCodec()
|
||||
var cdc *codec.Codec
|
||||
|
||||
func init() {
|
||||
cdc = codec.New()
|
||||
cryptoAmino.RegisterAmino(cdc)
|
||||
cdc.RegisterInterface((*Info)(nil), nil)
|
||||
cdc.RegisterConcrete(hd.BIP44Params{}, "crypto/keys/hd/BIP44Params", nil)
|
||||
|
@ -17,4 +18,5 @@ func init() {
|
|||
cdc.RegisterConcrete(ledgerInfo{}, "crypto/keys/ledgerInfo", nil)
|
||||
cdc.RegisterConcrete(offlineInfo{}, "crypto/keys/offlineInfo", nil)
|
||||
cdc.RegisterConcrete(multiInfo{}, "crypto/keys/multiInfo", nil)
|
||||
cdc.Seal()
|
||||
}
|
||||
|
|
|
@ -8,15 +8,15 @@ import (
|
|||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
secp256k1 "github.com/tendermint/btcd/btcec"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
tmsecp256k1 "github.com/tendermint/tendermint/crypto/secp256k1"
|
||||
|
||||
bip39 "github.com/cosmos/go-bip39"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/hd"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
secp256k1 "github.com/tendermint/btcd/btcec"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
tmsecp256k1 "github.com/tendermint/tendermint/crypto/secp256k1"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// If ledger support (build tag) has been enabled, which implies a CGO dependency,
|
||||
|
@ -41,7 +41,7 @@ func (mock LedgerSECP256K1Mock) GetPublicKeySECP256K1(derivationPath []uint32) (
|
|||
if derivationPath[0] != 44 {
|
||||
return nil, errors.New("Invalid derivation path")
|
||||
}
|
||||
if derivationPath[1] != types.CoinType {
|
||||
if derivationPath[1] != sdk.CoinType {
|
||||
return nil, errors.New("Invalid derivation path")
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ func (mock LedgerSECP256K1Mock) GetAddressPubKeySECP256K1(derivationPath []uint3
|
|||
copy(compressedPublicKey[:], cmp.SerializeCompressed())
|
||||
|
||||
// Generate the bech32 addr using existing tmcrypto/etc.
|
||||
addr := types.AccAddress(compressedPublicKey.Address()).String()
|
||||
addr := sdk.AccAddress(compressedPublicKey.Address()).String()
|
||||
return pk, addr, err
|
||||
}
|
||||
|
||||
|
|
|
@ -7,12 +7,12 @@ import (
|
|||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/hd"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
tmbtcec "github.com/tendermint/btcd/btcec"
|
||||
tmcrypto "github.com/tendermint/tendermint/crypto"
|
||||
tmsecp256k1 "github.com/tendermint/tendermint/crypto/secp256k1"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/hd"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -119,7 +119,7 @@ func LedgerShowAddress(path hd.BIP44Params, expectedPubKey tmcrypto.PubKey) erro
|
|||
return fmt.Errorf("the key's pubkey does not match with the one retrieved from Ledger. Check that the HD path and device are the correct ones")
|
||||
}
|
||||
|
||||
pubKey2, _, err := getPubKeyAddrSafe(device, path, types.Bech32PrefixAccAddr)
|
||||
pubKey2, _, err := getPubKeyAddrSafe(device, path, sdk.Bech32PrefixAccAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -4,14 +4,13 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
tmcrypto "github.com/tendermint/tendermint/crypto"
|
||||
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/hd"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
|
|
2
go.mod
2
go.mod
|
@ -19,9 +19,7 @@ require (
|
|||
github.com/jmhodges/levigo v1.0.0 // indirect
|
||||
github.com/magiconair/properties v1.8.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.6
|
||||
github.com/mattn/go-runewidth v0.0.4 // indirect
|
||||
github.com/mitchellh/mapstructure v1.1.2 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.1
|
||||
github.com/pelletier/go-toml v1.2.0
|
||||
github.com/pkg/errors v0.8.1
|
||||
github.com/prometheus/client_golang v0.9.2 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -82,15 +82,11 @@ github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDe
|
|||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/mattn/go-isatty v0.0.6 h1:SrwhHcpV4nWrMGdNcC2kXpMfcBVYGDuTArqyhocJgvA=
|
||||
github.com/mattn/go-isatty v0.0.6/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
|
||||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88=
|
||||
github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
|
|
|
@ -4,26 +4,29 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
dbm "github.com/tendermint/tendermint/libs/db"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
bam "github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/genaccounts"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis"
|
||||
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
||||
distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint"
|
||||
"github.com/cosmos/cosmos-sdk/x/params"
|
||||
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
dbm "github.com/tendermint/tendermint/libs/db"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
)
|
||||
|
||||
const appName = "SimApp"
|
||||
|
@ -35,14 +38,10 @@ var (
|
|||
// default home directories for the application daemon
|
||||
DefaultNodeHome = os.ExpandEnv("$HOME/.simapp")
|
||||
|
||||
// The ModuleBasicManager is in charge of setting up basic,
|
||||
// The module BasicManager is in charge of setting up basic,
|
||||
// non-dependant module elements, such as codec registration
|
||||
// and genesis verification.
|
||||
ModuleBasics sdk.ModuleBasicManager
|
||||
)
|
||||
|
||||
func init() {
|
||||
ModuleBasics = sdk.NewModuleBasicManager(
|
||||
ModuleBasics = module.NewBasicManager(
|
||||
genaccounts.AppModuleBasic{},
|
||||
genutil.AppModuleBasic{},
|
||||
auth.AppModuleBasic{},
|
||||
|
@ -50,12 +49,12 @@ func init() {
|
|||
staking.AppModuleBasic{},
|
||||
mint.AppModuleBasic{},
|
||||
distr.AppModuleBasic{},
|
||||
gov.AppModuleBasic{},
|
||||
gov.NewAppModuleBasic(paramsclient.ProposalHandler, distrclient.ProposalHandler),
|
||||
params.AppModuleBasic{},
|
||||
crisis.AppModuleBasic{},
|
||||
slashing.AppModuleBasic{},
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
// custom tx codec
|
||||
func MakeCodec() *codec.Codec {
|
||||
|
@ -100,7 +99,7 @@ type SimApp struct {
|
|||
paramsKeeper params.Keeper
|
||||
|
||||
// the module manager
|
||||
mm *sdk.ModuleManager
|
||||
mm *module.Manager
|
||||
}
|
||||
|
||||
// NewSimApp returns a reference to an initialized SimApp.
|
||||
|
@ -169,7 +168,7 @@ func NewSimApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bo
|
|||
app.stakingKeeper = *stakingKeeper.SetHooks(
|
||||
staking.NewMultiStakingHooks(app.distrKeeper.Hooks(), app.slashingKeeper.Hooks()))
|
||||
|
||||
app.mm = sdk.NewModuleManager(
|
||||
app.mm = module.NewManager(
|
||||
genaccounts.NewAppModule(app.accountKeeper),
|
||||
genutil.NewAppModule(app.accountKeeper, app.stakingKeeper, app.BaseApp.DeliverTx),
|
||||
auth.NewAppModule(app.accountKeeper, app.feeCollectionKeeper),
|
||||
|
|
|
@ -16,20 +16,10 @@ import (
|
|||
func TestSimAppExport(t *testing.T) {
|
||||
db := db.NewMemDB()
|
||||
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0)
|
||||
setGenesis(app)
|
||||
|
||||
// Making a new app object with the db, so that initchain hasn't been called
|
||||
app2 := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0)
|
||||
_, _, err := app2.ExportAppStateAndValidators(false, []string{})
|
||||
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
|
||||
}
|
||||
|
||||
func setGenesis(app *SimApp) error {
|
||||
genesisState := NewDefaultGenesisState()
|
||||
stateBytes, err := codec.MarshalJSONIndent(app.cdc, genesisState)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
// Initialize the chain
|
||||
app.InitChain(
|
||||
|
@ -38,7 +28,10 @@ func setGenesis(app *SimApp) error {
|
|||
AppStateBytes: stateBytes,
|
||||
},
|
||||
)
|
||||
|
||||
app.Commit()
|
||||
return nil
|
||||
|
||||
// Making a new app object with the db, so that initchain hasn't been called
|
||||
app2 := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0)
|
||||
_, _, err = app2.ExportAppStateAndValidators(false, []string{})
|
||||
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
|
||||
}
|
||||
|
|
|
@ -5,17 +5,17 @@ import (
|
|||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"strings"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
tmclient "github.com/tendermint/tendermint/rpc/client"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
)
|
||||
|
||||
// Wait for the next tendermint block from the Tendermint RPC
|
||||
|
@ -209,7 +209,7 @@ func NewTestCaseDir(t *testing.T) (string, func()) {
|
|||
return dir, func() { os.RemoveAll(dir) }
|
||||
}
|
||||
|
||||
var cdc = amino.NewCodec()
|
||||
var cdc = codec.New()
|
||||
|
||||
func init() {
|
||||
ctypes.RegisterAmino(cdc)
|
||||
|
|
|
@ -85,11 +85,13 @@ func (config *Config) SetAddressVerifier(addressVerifier func([]byte) error) {
|
|||
config.addressVerifier = addressVerifier
|
||||
}
|
||||
|
||||
// Set the BIP-0044 CoinType code on the config
|
||||
func (config *Config) SetCoinType(coinType uint32) {
|
||||
config.assertNotSealed()
|
||||
config.coinType = coinType
|
||||
}
|
||||
|
||||
// Set the FullFundraiserPath (BIP44Prefix) on the config
|
||||
func (config *Config) SetFullFundraiserPath(fullFundraiserPath string) {
|
||||
config.assertNotSealed()
|
||||
config.fullFundraiserPath = fullFundraiserPath
|
||||
|
@ -144,10 +146,12 @@ func (config *Config) GetAddressVerifier() func([]byte) error {
|
|||
return config.addressVerifier
|
||||
}
|
||||
|
||||
// Get the BIP-0044 CoinType code on the config
|
||||
func (config *Config) GetCoinType() uint32 {
|
||||
return config.coinType
|
||||
}
|
||||
|
||||
// Get the FullFundraiserPath (BIP44Prefix) on the config
|
||||
func (config *Config) GetFullFundraiserPath() string {
|
||||
return config.fullFundraiserPath
|
||||
}
|
||||
|
|
|
@ -257,7 +257,7 @@ type cloner interface {
|
|||
Clone() interface{} // deep copy
|
||||
}
|
||||
|
||||
// XXX add description
|
||||
// TODO add description
|
||||
type Op struct {
|
||||
// type is always 'with'
|
||||
gen int
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
/*
|
||||
Package types contains application module patterns and associated "manager" functionality.
|
||||
Package module contains application module patterns and associated "manager" functionality.
|
||||
The module pattern has been broken down by:
|
||||
- independent module functionality (AppModuleBasic)
|
||||
- inter-dependent module functionality (AppModule)
|
||||
- inter-dependent module genesis functionality (AppModuleGenesis)
|
||||
- inter-dependent module full functionality (AppModule)
|
||||
|
||||
inter-dependent module functionality is module functionality which somehow
|
||||
depends on other modules, typically through the module keeper. Many of the
|
||||
|
@ -17,72 +18,114 @@ process. This separation is necessary, however we still want to allow for a
|
|||
high level pattern for modules to follow - for instance, such that we don't
|
||||
have to manually register all of the codecs for all the modules. This basic
|
||||
procedure as well as other basic patterns are handled through the use of
|
||||
ModuleBasicManager.
|
||||
BasicManager.
|
||||
|
||||
Lastly the interface for genesis functionality (AppModuleGenesis) has been
|
||||
separated out from full module functionality (AppModule) so that modules which
|
||||
are only used for genesis can take advantage of the Module patterns without
|
||||
needlessly defining many placeholder functions
|
||||
*/
|
||||
package types
|
||||
package module
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/gorilla/mux"
|
||||
"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
|
||||
}
|
||||
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"
|
||||
)
|
||||
|
||||
//__________________________________________________________________________________________
|
||||
// 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(*codec.Codec) *cobra.Command
|
||||
GetQueryCmd(*codec.Codec) *cobra.Command
|
||||
}
|
||||
|
||||
// collections of AppModuleBasic
|
||||
type ModuleBasicManager []AppModuleBasic
|
||||
type BasicManager map[string]AppModuleBasic
|
||||
|
||||
func NewModuleBasicManager(modules ...AppModuleBasic) ModuleBasicManager {
|
||||
return modules
|
||||
func NewBasicManager(modules ...AppModuleBasic) BasicManager {
|
||||
moduleMap := make(map[string]AppModuleBasic)
|
||||
for _, module := range modules {
|
||||
moduleMap[module.Name()] = module
|
||||
}
|
||||
return moduleMap
|
||||
}
|
||||
|
||||
// RegisterCodecs registers all module codecs
|
||||
func (mbm ModuleBasicManager) RegisterCodec(cdc *codec.Codec) {
|
||||
for _, mb := range mbm {
|
||||
mb.RegisterCodec(cdc)
|
||||
func (bm BasicManager) RegisterCodec(cdc *codec.Codec) {
|
||||
for _, b := range bm {
|
||||
b.RegisterCodec(cdc)
|
||||
}
|
||||
}
|
||||
|
||||
// Provided default genesis information for all modules
|
||||
func (mbm ModuleBasicManager) DefaultGenesis() map[string]json.RawMessage {
|
||||
func (bm BasicManager) DefaultGenesis() map[string]json.RawMessage {
|
||||
genesis := make(map[string]json.RawMessage)
|
||||
for _, mb := range mbm {
|
||||
genesis[mb.Name()] = mb.DefaultGenesis()
|
||||
for _, b := range bm {
|
||||
genesis[b.Name()] = b.DefaultGenesis()
|
||||
}
|
||||
return genesis
|
||||
}
|
||||
|
||||
// Provided default genesis information for all modules
|
||||
func (mbm ModuleBasicManager) ValidateGenesis(genesis map[string]json.RawMessage) error {
|
||||
for _, mb := range mbm {
|
||||
if err := mb.ValidateGenesis(genesis[mb.Name()]); err != nil {
|
||||
func (bm BasicManager) ValidateGenesis(genesis map[string]json.RawMessage) error {
|
||||
for _, b := range bm {
|
||||
if err := b.ValidateGenesis(genesis[b.Name()]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterRestRoutes registers all module rest routes
|
||||
func (bm BasicManager) RegisterRESTRoutes(
|
||||
ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {
|
||||
|
||||
for _, b := range bm {
|
||||
b.RegisterRESTRoutes(ctx, rtr, cdc)
|
||||
}
|
||||
}
|
||||
|
||||
// add all tx commands to the rootTxCmd
|
||||
func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command, cdc *codec.Codec) {
|
||||
for _, b := range bm {
|
||||
if cmd := b.GetTxCmd(cdc); cmd != nil {
|
||||
rootTxCmd.AddCommand(cmd)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add all query commands to the rootQueryCmd
|
||||
func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command, cdc *codec.Codec) {
|
||||
for _, b := range bm {
|
||||
if cmd := b.GetQueryCmd(cdc); cmd != nil {
|
||||
rootQueryCmd.AddCommand(cmd)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_________________________________________________________
|
||||
// AppModuleGenesis is the standard form for an application module genesis functions
|
||||
type AppModuleGenesis interface {
|
||||
AppModuleBasic
|
||||
InitGenesis(Context, json.RawMessage) []abci.ValidatorUpdate
|
||||
ExportGenesis(Context) json.RawMessage
|
||||
InitGenesis(sdk.Context, json.RawMessage) []abci.ValidatorUpdate
|
||||
ExportGenesis(sdk.Context) json.RawMessage
|
||||
}
|
||||
|
||||
// AppModule is the standard form for an application module
|
||||
|
@ -90,16 +133,16 @@ type AppModule interface {
|
|||
AppModuleGenesis
|
||||
|
||||
// registers
|
||||
RegisterInvariants(InvariantRouter)
|
||||
RegisterInvariants(sdk.InvariantRouter)
|
||||
|
||||
// routes
|
||||
Route() string
|
||||
NewHandler() Handler
|
||||
NewHandler() sdk.Handler
|
||||
QuerierRoute() string
|
||||
NewQuerierHandler() Querier
|
||||
NewQuerierHandler() sdk.Querier
|
||||
|
||||
BeginBlock(Context, abci.RequestBeginBlock) Tags
|
||||
EndBlock(Context, abci.RequestEndBlock) ([]abci.ValidatorUpdate, Tags)
|
||||
BeginBlock(sdk.Context, abci.RequestBeginBlock) sdk.Tags
|
||||
EndBlock(sdk.Context, abci.RequestEndBlock) ([]abci.ValidatorUpdate, sdk.Tags)
|
||||
}
|
||||
|
||||
//___________________________
|
||||
|
@ -116,34 +159,34 @@ func NewGenesisOnlyAppModule(amg AppModuleGenesis) AppModule {
|
|||
}
|
||||
|
||||
// register invariants
|
||||
func (GenesisOnlyAppModule) RegisterInvariants(_ InvariantRouter) {}
|
||||
func (GenesisOnlyAppModule) RegisterInvariants(_ sdk.InvariantRouter) {}
|
||||
|
||||
// module message route ngame
|
||||
func (GenesisOnlyAppModule) Route() string { return "" }
|
||||
|
||||
// module handler
|
||||
func (GenesisOnlyAppModule) NewHandler() Handler { return nil }
|
||||
func (GenesisOnlyAppModule) NewHandler() sdk.Handler { return nil }
|
||||
|
||||
// module querier route ngame
|
||||
func (GenesisOnlyAppModule) QuerierRoute() string { return "" }
|
||||
|
||||
// module querier
|
||||
func (gam GenesisOnlyAppModule) NewQuerierHandler() Querier { return nil }
|
||||
func (gam GenesisOnlyAppModule) NewQuerierHandler() sdk.Querier { return nil }
|
||||
|
||||
// module begin-block
|
||||
func (gam GenesisOnlyAppModule) BeginBlock(ctx Context, req abci.RequestBeginBlock) Tags {
|
||||
return EmptyTags()
|
||||
func (gam GenesisOnlyAppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) sdk.Tags {
|
||||
return sdk.EmptyTags()
|
||||
}
|
||||
|
||||
// module end-block
|
||||
func (GenesisOnlyAppModule) EndBlock(_ Context, _ abci.RequestEndBlock) ([]abci.ValidatorUpdate, Tags) {
|
||||
return []abci.ValidatorUpdate{}, EmptyTags()
|
||||
func (GenesisOnlyAppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) ([]abci.ValidatorUpdate, sdk.Tags) {
|
||||
return []abci.ValidatorUpdate{}, sdk.EmptyTags()
|
||||
}
|
||||
|
||||
//____________________________________________________________________________
|
||||
// module manager provides the high level utility for managing and executing
|
||||
// operations for a group of modules
|
||||
type ModuleManager struct {
|
||||
type Manager struct {
|
||||
Modules map[string]AppModule
|
||||
OrderInitGenesis []string
|
||||
OrderExportGenesis []string
|
||||
|
@ -151,8 +194,8 @@ type ModuleManager struct {
|
|||
OrderEndBlockers []string
|
||||
}
|
||||
|
||||
// NewModuleManager creates a new ModuleManager object
|
||||
func NewModuleManager(modules ...AppModule) *ModuleManager {
|
||||
// NewModuleManager creates a new Manager object
|
||||
func NewManager(modules ...AppModule) *Manager {
|
||||
|
||||
moduleMap := make(map[string]AppModule)
|
||||
var modulesStr []string
|
||||
|
@ -161,7 +204,7 @@ func NewModuleManager(modules ...AppModule) *ModuleManager {
|
|||
modulesStr = append(modulesStr, module.Name())
|
||||
}
|
||||
|
||||
return &ModuleManager{
|
||||
return &Manager{
|
||||
Modules: moduleMap,
|
||||
OrderInitGenesis: modulesStr,
|
||||
OrderExportGenesis: modulesStr,
|
||||
|
@ -171,35 +214,35 @@ func NewModuleManager(modules ...AppModule) *ModuleManager {
|
|||
}
|
||||
|
||||
// set the order of init genesis calls
|
||||
func (mm *ModuleManager) SetOrderInitGenesis(moduleNames ...string) {
|
||||
mm.OrderInitGenesis = moduleNames
|
||||
func (m *Manager) SetOrderInitGenesis(moduleNames ...string) {
|
||||
m.OrderInitGenesis = moduleNames
|
||||
}
|
||||
|
||||
// set the order of export genesis calls
|
||||
func (mm *ModuleManager) SetOrderExportGenesis(moduleNames ...string) {
|
||||
mm.OrderExportGenesis = moduleNames
|
||||
func (m *Manager) SetOrderExportGenesis(moduleNames ...string) {
|
||||
m.OrderExportGenesis = moduleNames
|
||||
}
|
||||
|
||||
// set the order of set begin-blocker calls
|
||||
func (mm *ModuleManager) SetOrderBeginBlockers(moduleNames ...string) {
|
||||
mm.OrderBeginBlockers = moduleNames
|
||||
func (m *Manager) SetOrderBeginBlockers(moduleNames ...string) {
|
||||
m.OrderBeginBlockers = moduleNames
|
||||
}
|
||||
|
||||
// set the order of set end-blocker calls
|
||||
func (mm *ModuleManager) SetOrderEndBlockers(moduleNames ...string) {
|
||||
mm.OrderEndBlockers = moduleNames
|
||||
func (m *Manager) SetOrderEndBlockers(moduleNames ...string) {
|
||||
m.OrderEndBlockers = moduleNames
|
||||
}
|
||||
|
||||
// register all module routes and module querier routes
|
||||
func (mm *ModuleManager) RegisterInvariants(invarRouter InvariantRouter) {
|
||||
for _, module := range mm.Modules {
|
||||
func (m *Manager) RegisterInvariants(invarRouter sdk.InvariantRouter) {
|
||||
for _, module := range m.Modules {
|
||||
module.RegisterInvariants(invarRouter)
|
||||
}
|
||||
}
|
||||
|
||||
// register all module routes and module querier routes
|
||||
func (mm *ModuleManager) RegisterRoutes(router Router, queryRouter QueryRouter) {
|
||||
for _, module := range mm.Modules {
|
||||
func (m *Manager) RegisterRoutes(router sdk.Router, queryRouter sdk.QueryRouter) {
|
||||
for _, module := range m.Modules {
|
||||
if module.Route() != "" {
|
||||
router.AddRoute(module.Route(), module.NewHandler())
|
||||
}
|
||||
|
@ -210,13 +253,13 @@ func (mm *ModuleManager) RegisterRoutes(router Router, queryRouter QueryRouter)
|
|||
}
|
||||
|
||||
// perform init genesis functionality for modules
|
||||
func (mm *ModuleManager) InitGenesis(ctx Context, genesisData map[string]json.RawMessage) abci.ResponseInitChain {
|
||||
func (m *Manager) InitGenesis(ctx sdk.Context, genesisData map[string]json.RawMessage) abci.ResponseInitChain {
|
||||
var validatorUpdates []abci.ValidatorUpdate
|
||||
for _, moduleName := range mm.OrderInitGenesis {
|
||||
for _, moduleName := range m.OrderInitGenesis {
|
||||
if genesisData[moduleName] == nil {
|
||||
continue
|
||||
}
|
||||
moduleValUpdates := mm.Modules[moduleName].InitGenesis(ctx, genesisData[moduleName])
|
||||
moduleValUpdates := m.Modules[moduleName].InitGenesis(ctx, genesisData[moduleName])
|
||||
|
||||
// use these validator updates if provided, the module manager assumes
|
||||
// only one module will update the validator set
|
||||
|
@ -233,19 +276,19 @@ func (mm *ModuleManager) InitGenesis(ctx Context, genesisData map[string]json.Ra
|
|||
}
|
||||
|
||||
// perform export genesis functionality for modules
|
||||
func (mm *ModuleManager) ExportGenesis(ctx Context) map[string]json.RawMessage {
|
||||
func (m *Manager) ExportGenesis(ctx sdk.Context) map[string]json.RawMessage {
|
||||
genesisData := make(map[string]json.RawMessage)
|
||||
for _, moduleName := range mm.OrderExportGenesis {
|
||||
genesisData[moduleName] = mm.Modules[moduleName].ExportGenesis(ctx)
|
||||
for _, moduleName := range m.OrderExportGenesis {
|
||||
genesisData[moduleName] = m.Modules[moduleName].ExportGenesis(ctx)
|
||||
}
|
||||
return genesisData
|
||||
}
|
||||
|
||||
// perform begin block functionality for modules
|
||||
func (mm *ModuleManager) BeginBlock(ctx Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
|
||||
tags := EmptyTags()
|
||||
for _, moduleName := range mm.OrderBeginBlockers {
|
||||
moduleTags := mm.Modules[moduleName].BeginBlock(ctx, req)
|
||||
func (m *Manager) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
|
||||
tags := sdk.EmptyTags()
|
||||
for _, moduleName := range m.OrderBeginBlockers {
|
||||
moduleTags := m.Modules[moduleName].BeginBlock(ctx, req)
|
||||
tags = tags.AppendTags(moduleTags)
|
||||
}
|
||||
|
||||
|
@ -255,11 +298,11 @@ func (mm *ModuleManager) BeginBlock(ctx Context, req abci.RequestBeginBlock) abc
|
|||
}
|
||||
|
||||
// perform end block functionality for modules
|
||||
func (mm *ModuleManager) EndBlock(ctx Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
|
||||
func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
|
||||
validatorUpdates := []abci.ValidatorUpdate{}
|
||||
tags := EmptyTags()
|
||||
for _, moduleName := range mm.OrderEndBlockers {
|
||||
moduleValUpdates, moduleTags := mm.Modules[moduleName].EndBlock(ctx, req)
|
||||
tags := sdk.EmptyTags()
|
||||
for _, moduleName := range m.OrderEndBlockers {
|
||||
moduleValUpdates, moduleTags := m.Modules[moduleName].EndBlock(ctx, req)
|
||||
tags = tags.AppendTags(moduleTags)
|
||||
|
||||
// use these validator updates if provided, the module manager assumes
|
|
@ -1,4 +1,4 @@
|
|||
package types
|
||||
package module
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
func TestSetOrderBeginBlockers(t *testing.T) {
|
||||
mm := NewModuleManager()
|
||||
mm := NewManager()
|
||||
mm.SetOrderBeginBlockers("a", "b", "c")
|
||||
obb := mm.OrderBeginBlockers
|
||||
require.Equal(t, 3, len(obb))
|
|
@ -0,0 +1,92 @@
|
|||
// nolint
|
||||
// autogenerated code using github.com/rigelrozanski/multitool
|
||||
// aliases generated for the following subdirectories:
|
||||
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/auth/types
|
||||
package auth
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
const (
|
||||
ModuleName = types.ModuleName
|
||||
StoreKey = types.StoreKey
|
||||
FeeStoreKey = types.FeeStoreKey
|
||||
QuerierRoute = types.QuerierRoute
|
||||
DefaultParamspace = types.DefaultParamspace
|
||||
DefaultMaxMemoCharacters = types.DefaultMaxMemoCharacters
|
||||
DefaultTxSigLimit = types.DefaultTxSigLimit
|
||||
DefaultTxSizeCostPerByte = types.DefaultTxSizeCostPerByte
|
||||
DefaultSigVerifyCostED25519 = types.DefaultSigVerifyCostED25519
|
||||
DefaultSigVerifyCostSecp256k1 = types.DefaultSigVerifyCostSecp256k1
|
||||
QueryAccount = types.QueryAccount
|
||||
)
|
||||
|
||||
var (
|
||||
// functions aliases
|
||||
NewBaseAccount = types.NewBaseAccount
|
||||
ProtoBaseAccount = types.ProtoBaseAccount
|
||||
NewBaseAccountWithAddress = types.NewBaseAccountWithAddress
|
||||
NewBaseVestingAccount = types.NewBaseVestingAccount
|
||||
NewContinuousVestingAccountRaw = types.NewContinuousVestingAccountRaw
|
||||
NewContinuousVestingAccount = types.NewContinuousVestingAccount
|
||||
NewDelayedVestingAccountRaw = types.NewDelayedVestingAccountRaw
|
||||
NewDelayedVestingAccount = types.NewDelayedVestingAccount
|
||||
RegisterCodec = types.RegisterCodec
|
||||
RegisterBaseAccount = types.RegisterBaseAccount
|
||||
NewFeeCollectionKeeper = types.NewFeeCollectionKeeper
|
||||
NewGenesisState = types.NewGenesisState
|
||||
DefaultGenesisState = types.DefaultGenesisState
|
||||
ValidateGenesis = types.ValidateGenesis
|
||||
AddressStoreKey = types.AddressStoreKey
|
||||
NewParams = types.NewParams
|
||||
ParamKeyTable = types.ParamKeyTable
|
||||
DefaultParams = types.DefaultParams
|
||||
NewQueryAccountParams = types.NewQueryAccountParams
|
||||
NewStdTx = types.NewStdTx
|
||||
CountSubKeys = types.CountSubKeys
|
||||
NewStdFee = types.NewStdFee
|
||||
StdSignBytes = types.StdSignBytes
|
||||
DefaultTxDecoder = types.DefaultTxDecoder
|
||||
DefaultTxEncoder = types.DefaultTxEncoder
|
||||
NewTestMsg = types.NewTestMsg
|
||||
NewTestStdFee = types.NewTestStdFee
|
||||
NewTestCoins = types.NewTestCoins
|
||||
KeyTestPubAddr = types.KeyTestPubAddr
|
||||
NewTestTx = types.NewTestTx
|
||||
NewTestTxWithMemo = types.NewTestTxWithMemo
|
||||
NewTestTxWithSignBytes = types.NewTestTxWithSignBytes
|
||||
NewTxBuilder = types.NewTxBuilder
|
||||
NewTxBuilderFromCLI = types.NewTxBuilderFromCLI
|
||||
MakeSignature = types.MakeSignature
|
||||
|
||||
// variable aliases
|
||||
ModuleCdc = types.ModuleCdc
|
||||
AddressStoreKeyPrefix = types.AddressStoreKeyPrefix
|
||||
GlobalAccountNumberKey = types.GlobalAccountNumberKey
|
||||
KeyMaxMemoCharacters = types.KeyMaxMemoCharacters
|
||||
KeyTxSigLimit = types.KeyTxSigLimit
|
||||
KeyTxSizeCostPerByte = types.KeyTxSizeCostPerByte
|
||||
KeySigVerifyCostED25519 = types.KeySigVerifyCostED25519
|
||||
KeySigVerifyCostSecp256k1 = types.KeySigVerifyCostSecp256k1
|
||||
)
|
||||
|
||||
type (
|
||||
Account = types.Account
|
||||
VestingAccount = types.VestingAccount
|
||||
AccountDecoder = types.AccountDecoder
|
||||
BaseAccount = types.BaseAccount
|
||||
BaseVestingAccount = types.BaseVestingAccount
|
||||
ContinuousVestingAccount = types.ContinuousVestingAccount
|
||||
DelayedVestingAccount = types.DelayedVestingAccount
|
||||
FeeCollectionKeeper = types.FeeCollectionKeeper
|
||||
GenesisState = types.GenesisState
|
||||
Params = types.Params
|
||||
QueryAccountParams = types.QueryAccountParams
|
||||
StdSignMsg = types.StdSignMsg
|
||||
StdTx = types.StdTx
|
||||
StdFee = types.StdFee
|
||||
StdSignDoc = types.StdSignDoc
|
||||
StdSignature = types.StdSignature
|
||||
TxBuilder = types.TxBuilder
|
||||
)
|
|
@ -29,7 +29,7 @@ func init() {
|
|||
}
|
||||
|
||||
// SignatureVerificationGasConsumer is the type of function that is used to both consume gas when verifying signatures
|
||||
// and also to accept or reject different types of PubKey's. This is where apps can define their own PubKey types.
|
||||
// and also to accept or reject different types of PubKey's. This is where apps can define their own PubKey
|
||||
type SignatureVerificationGasConsumer = func(meter sdk.GasMeter, sig []byte, pubkey crypto.PubKey, params Params) sdk.Result
|
||||
|
||||
// NewAnteHandler returns an AnteHandler that checks and increments sequence
|
||||
|
@ -165,7 +165,7 @@ func ValidateSigCount(stdTx StdTx, params Params) sdk.Result {
|
|||
|
||||
sigCount := 0
|
||||
for i := 0; i < len(stdSigs); i++ {
|
||||
sigCount += countSubKeys(stdSigs[i].PubKey)
|
||||
sigCount += CountSubKeys(stdSigs[i].PubKey)
|
||||
if uint64(sigCount) > params.TxSigLimit {
|
||||
return sdk.ErrTooManySignatures(
|
||||
fmt.Sprintf("signatures: %d, limit: %d", sigCount, params.TxSigLimit),
|
||||
|
@ -237,7 +237,7 @@ func consumeSimSigGas(gasmeter sdk.GasMeter, pubkey crypto.PubKey, sig StdSignat
|
|||
simSig.Signature = simSecp256k1Sig[:]
|
||||
}
|
||||
|
||||
sigBz := moduleCdc.MustMarshalBinaryLengthPrefixed(simSig)
|
||||
sigBz := ModuleCdc.MustMarshalBinaryLengthPrefixed(simSig)
|
||||
cost := sdk.Gas(len(sigBz) + 6)
|
||||
|
||||
// If the pubkey is a multi-signature pubkey, then we estimate for the maximum
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
// run the tx through the anteHandler and ensure its valid
|
||||
|
@ -32,8 +33,8 @@ func checkInvalidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context,
|
|||
require.Equal(t, sdk.CodespaceRoot, result.Codespace)
|
||||
|
||||
if code == sdk.CodeOutOfGas {
|
||||
stdTx, ok := tx.(StdTx)
|
||||
require.True(t, ok, "tx must be in form auth.StdTx")
|
||||
stdTx, ok := tx.(types.StdTx)
|
||||
require.True(t, ok, "tx must be in form auth.types.StdTx")
|
||||
// GasWanted set correctly
|
||||
require.Equal(t, stdTx.Fee.Gas, result.GasWanted, "Gas wanted not set correctly")
|
||||
require.True(t, result.GasUsed > result.GasWanted, "GasUsed not greated than GasWanted")
|
||||
|
@ -50,25 +51,25 @@ func TestAnteHandlerSigErrors(t *testing.T) {
|
|||
anteHandler := NewAnteHandler(input.ak, input.fck, DefaultSigVerificationGasConsumer)
|
||||
|
||||
// keys and addresses
|
||||
priv1, _, addr1 := keyPubAddr()
|
||||
priv2, _, addr2 := keyPubAddr()
|
||||
priv3, _, addr3 := keyPubAddr()
|
||||
priv1, _, addr1 := KeyTestPubAddr()
|
||||
priv2, _, addr2 := KeyTestPubAddr()
|
||||
priv3, _, addr3 := KeyTestPubAddr()
|
||||
|
||||
// msg and signatures
|
||||
var tx sdk.Tx
|
||||
msg1 := newTestMsg(addr1, addr2)
|
||||
msg2 := newTestMsg(addr1, addr3)
|
||||
fee := newStdFee()
|
||||
msg1 := NewTestMsg(addr1, addr2)
|
||||
msg2 := NewTestMsg(addr1, addr3)
|
||||
fee := NewTestStdFee()
|
||||
|
||||
msgs := []sdk.Msg{msg1, msg2}
|
||||
|
||||
// test no signatures
|
||||
privs, accNums, seqs := []crypto.PrivKey{}, []uint64{}, []uint64{}
|
||||
tx = newTestTx(ctx, msgs, privs, accNums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accNums, seqs, fee)
|
||||
|
||||
// tx.GetSigners returns addresses in correct order: addr1, addr2, addr3
|
||||
expectedSigners := []sdk.AccAddress{addr1, addr2, addr3}
|
||||
stdTx := tx.(StdTx)
|
||||
stdTx := tx.(types.StdTx)
|
||||
require.Equal(t, expectedSigners, stdTx.GetSigners())
|
||||
|
||||
// Check no signatures fails
|
||||
|
@ -76,12 +77,12 @@ func TestAnteHandlerSigErrors(t *testing.T) {
|
|||
|
||||
// test num sigs dont match GetSigners
|
||||
privs, accNums, seqs = []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
|
||||
tx = newTestTx(ctx, msgs, privs, accNums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accNums, seqs, fee)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeUnauthorized)
|
||||
|
||||
// test an unrecognized account
|
||||
privs, accNums, seqs = []crypto.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{0, 0, 0}
|
||||
tx = newTestTx(ctx, msgs, privs, accNums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accNums, seqs, fee)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeUnknownAddress)
|
||||
|
||||
// save the first account, but second is still unrecognized
|
||||
|
@ -99,50 +100,50 @@ func TestAnteHandlerAccountNumbers(t *testing.T) {
|
|||
ctx := input.ctx.WithBlockHeight(1)
|
||||
|
||||
// keys and addresses
|
||||
priv1, _, addr1 := keyPubAddr()
|
||||
priv2, _, addr2 := keyPubAddr()
|
||||
priv1, _, addr1 := KeyTestPubAddr()
|
||||
priv2, _, addr2 := KeyTestPubAddr()
|
||||
|
||||
// set the accounts
|
||||
acc1 := input.ak.NewAccountWithAddress(ctx, addr1)
|
||||
acc1.SetCoins(newCoins())
|
||||
acc1.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc1)
|
||||
acc2 := input.ak.NewAccountWithAddress(ctx, addr2)
|
||||
acc2.SetCoins(newCoins())
|
||||
acc2.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc2)
|
||||
|
||||
// msg and signatures
|
||||
var tx sdk.Tx
|
||||
msg := newTestMsg(addr1)
|
||||
fee := newStdFee()
|
||||
msg := NewTestMsg(addr1)
|
||||
fee := NewTestStdFee()
|
||||
|
||||
msgs := []sdk.Msg{msg}
|
||||
|
||||
// test good tx from one signer
|
||||
privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
|
||||
// new tx from wrong account number
|
||||
seqs = []uint64{1}
|
||||
tx = newTestTx(ctx, msgs, privs, []uint64{1}, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, []uint64{1}, seqs, fee)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeUnauthorized)
|
||||
|
||||
// from correct account number
|
||||
seqs = []uint64{1}
|
||||
tx = newTestTx(ctx, msgs, privs, []uint64{0}, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, []uint64{0}, seqs, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
|
||||
// new tx with another signer and incorrect account numbers
|
||||
msg1 := newTestMsg(addr1, addr2)
|
||||
msg2 := newTestMsg(addr2, addr1)
|
||||
msg1 := NewTestMsg(addr1, addr2)
|
||||
msg2 := NewTestMsg(addr2, addr1)
|
||||
msgs = []sdk.Msg{msg1, msg2}
|
||||
privs, accnums, seqs = []crypto.PrivKey{priv1, priv2}, []uint64{1, 0}, []uint64{2, 0}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeUnauthorized)
|
||||
|
||||
// correct account numbers
|
||||
privs, accnums, seqs = []crypto.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{2, 0}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
}
|
||||
|
||||
|
@ -154,50 +155,50 @@ func TestAnteHandlerAccountNumbersAtBlockHeightZero(t *testing.T) {
|
|||
ctx := input.ctx.WithBlockHeight(0)
|
||||
|
||||
// keys and addresses
|
||||
priv1, _, addr1 := keyPubAddr()
|
||||
priv2, _, addr2 := keyPubAddr()
|
||||
priv1, _, addr1 := KeyTestPubAddr()
|
||||
priv2, _, addr2 := KeyTestPubAddr()
|
||||
|
||||
// set the accounts
|
||||
acc1 := input.ak.NewAccountWithAddress(ctx, addr1)
|
||||
acc1.SetCoins(newCoins())
|
||||
acc1.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc1)
|
||||
acc2 := input.ak.NewAccountWithAddress(ctx, addr2)
|
||||
acc2.SetCoins(newCoins())
|
||||
acc2.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc2)
|
||||
|
||||
// msg and signatures
|
||||
var tx sdk.Tx
|
||||
msg := newTestMsg(addr1)
|
||||
fee := newStdFee()
|
||||
msg := NewTestMsg(addr1)
|
||||
fee := NewTestStdFee()
|
||||
|
||||
msgs := []sdk.Msg{msg}
|
||||
|
||||
// test good tx from one signer
|
||||
privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
|
||||
// new tx from wrong account number
|
||||
seqs = []uint64{1}
|
||||
tx = newTestTx(ctx, msgs, privs, []uint64{1}, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, []uint64{1}, seqs, fee)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeUnauthorized)
|
||||
|
||||
// from correct account number
|
||||
seqs = []uint64{1}
|
||||
tx = newTestTx(ctx, msgs, privs, []uint64{0}, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, []uint64{0}, seqs, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
|
||||
// new tx with another signer and incorrect account numbers
|
||||
msg1 := newTestMsg(addr1, addr2)
|
||||
msg2 := newTestMsg(addr2, addr1)
|
||||
msg1 := NewTestMsg(addr1, addr2)
|
||||
msg2 := NewTestMsg(addr2, addr1)
|
||||
msgs = []sdk.Msg{msg1, msg2}
|
||||
privs, accnums, seqs = []crypto.PrivKey{priv1, priv2}, []uint64{1, 0}, []uint64{2, 0}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeUnauthorized)
|
||||
|
||||
// correct account numbers
|
||||
privs, accnums, seqs = []crypto.PrivKey{priv1, priv2}, []uint64{0, 0}, []uint64{2, 0}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
}
|
||||
|
||||
|
@ -209,31 +210,31 @@ func TestAnteHandlerSequences(t *testing.T) {
|
|||
ctx := input.ctx.WithBlockHeight(1)
|
||||
|
||||
// keys and addresses
|
||||
priv1, _, addr1 := keyPubAddr()
|
||||
priv2, _, addr2 := keyPubAddr()
|
||||
priv3, _, addr3 := keyPubAddr()
|
||||
priv1, _, addr1 := KeyTestPubAddr()
|
||||
priv2, _, addr2 := KeyTestPubAddr()
|
||||
priv3, _, addr3 := KeyTestPubAddr()
|
||||
|
||||
// set the accounts
|
||||
acc1 := input.ak.NewAccountWithAddress(ctx, addr1)
|
||||
acc1.SetCoins(newCoins())
|
||||
acc1.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc1)
|
||||
acc2 := input.ak.NewAccountWithAddress(ctx, addr2)
|
||||
acc2.SetCoins(newCoins())
|
||||
acc2.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc2)
|
||||
acc3 := input.ak.NewAccountWithAddress(ctx, addr3)
|
||||
acc3.SetCoins(newCoins())
|
||||
acc3.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc3)
|
||||
|
||||
// msg and signatures
|
||||
var tx sdk.Tx
|
||||
msg := newTestMsg(addr1)
|
||||
fee := newStdFee()
|
||||
msg := NewTestMsg(addr1)
|
||||
fee := NewTestStdFee()
|
||||
|
||||
msgs := []sdk.Msg{msg}
|
||||
|
||||
// test good tx from one signer
|
||||
privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
|
||||
// test sending it again fails (replay protection)
|
||||
|
@ -241,37 +242,37 @@ func TestAnteHandlerSequences(t *testing.T) {
|
|||
|
||||
// fix sequence, should pass
|
||||
seqs = []uint64{1}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
|
||||
// new tx with another signer and correct sequences
|
||||
msg1 := newTestMsg(addr1, addr2)
|
||||
msg2 := newTestMsg(addr3, addr1)
|
||||
msg1 := NewTestMsg(addr1, addr2)
|
||||
msg2 := NewTestMsg(addr3, addr1)
|
||||
msgs = []sdk.Msg{msg1, msg2}
|
||||
|
||||
privs, accnums, seqs = []crypto.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{2, 0, 0}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
|
||||
// replay fails
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeUnauthorized)
|
||||
|
||||
// tx from just second signer with incorrect sequence fails
|
||||
msg = newTestMsg(addr2)
|
||||
msg = NewTestMsg(addr2)
|
||||
msgs = []sdk.Msg{msg}
|
||||
privs, accnums, seqs = []crypto.PrivKey{priv2}, []uint64{1}, []uint64{0}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeUnauthorized)
|
||||
|
||||
// fix the sequence and it passes
|
||||
tx = newTestTx(ctx, msgs, []crypto.PrivKey{priv2}, []uint64{1}, []uint64{1}, fee)
|
||||
tx = NewTestTx(ctx, msgs, []crypto.PrivKey{priv2}, []uint64{1}, []uint64{1}, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
|
||||
// another tx from both of them that passes
|
||||
msg = newTestMsg(addr1, addr2)
|
||||
msg = NewTestMsg(addr1, addr2)
|
||||
msgs = []sdk.Msg{msg}
|
||||
privs, accnums, seqs = []crypto.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{3, 2}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
}
|
||||
|
||||
|
@ -283,7 +284,7 @@ func TestAnteHandlerFees(t *testing.T) {
|
|||
anteHandler := NewAnteHandler(input.ak, input.fck, DefaultSigVerificationGasConsumer)
|
||||
|
||||
// keys and addresses
|
||||
priv1, _, addr1 := keyPubAddr()
|
||||
priv1, _, addr1 := KeyTestPubAddr()
|
||||
|
||||
// set the accounts
|
||||
acc1 := input.ak.NewAccountWithAddress(ctx, addr1)
|
||||
|
@ -291,19 +292,20 @@ func TestAnteHandlerFees(t *testing.T) {
|
|||
|
||||
// msg and signatures
|
||||
var tx sdk.Tx
|
||||
msg := newTestMsg(addr1)
|
||||
msg := NewTestMsg(addr1)
|
||||
privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
|
||||
fee := newStdFee()
|
||||
fee := NewTestStdFee()
|
||||
msgs := []sdk.Msg{msg}
|
||||
|
||||
// signer does not have enough funds to pay the fee
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeInsufficientFunds)
|
||||
|
||||
acc1.SetCoins(sdk.NewCoins(sdk.NewInt64Coin("atom", 149)))
|
||||
input.ak.SetAccount(ctx, acc1)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeInsufficientFunds)
|
||||
|
||||
emptyCoins := sdk.NewCoins()
|
||||
require.True(t, input.fck.GetCollectedFees(ctx).IsEqual(emptyCoins))
|
||||
require.True(t, input.ak.GetAccount(ctx, addr1).GetCoins().AmountOf("atom").Equal(sdk.NewInt(149)))
|
||||
|
||||
|
@ -323,7 +325,7 @@ func TestAnteHandlerMemoGas(t *testing.T) {
|
|||
ctx := input.ctx.WithBlockHeight(1)
|
||||
|
||||
// keys and addresses
|
||||
priv1, _, addr1 := keyPubAddr()
|
||||
priv1, _, addr1 := KeyTestPubAddr()
|
||||
|
||||
// set the accounts
|
||||
acc1 := input.ak.NewAccountWithAddress(ctx, addr1)
|
||||
|
@ -331,27 +333,27 @@ func TestAnteHandlerMemoGas(t *testing.T) {
|
|||
|
||||
// msg and signatures
|
||||
var tx sdk.Tx
|
||||
msg := newTestMsg(addr1)
|
||||
msg := NewTestMsg(addr1)
|
||||
privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
|
||||
fee := NewStdFee(0, sdk.NewCoins(sdk.NewInt64Coin("atom", 0)))
|
||||
|
||||
// tx does not have enough gas
|
||||
tx = newTestTx(ctx, []sdk.Msg{msg}, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, []sdk.Msg{msg}, privs, accnums, seqs, fee)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeOutOfGas)
|
||||
|
||||
// tx with memo doesn't have enough gas
|
||||
fee = NewStdFee(801, sdk.NewCoins(sdk.NewInt64Coin("atom", 0)))
|
||||
tx = newTestTxWithMemo(ctx, []sdk.Msg{msg}, privs, accnums, seqs, fee, "abcininasidniandsinasindiansdiansdinaisndiasndiadninsd")
|
||||
tx = NewTestTxWithMemo(ctx, []sdk.Msg{msg}, privs, accnums, seqs, fee, "abcininasidniandsinasindiansdiansdinaisndiasndiadninsd")
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeOutOfGas)
|
||||
|
||||
// memo too large
|
||||
fee = NewStdFee(9000, sdk.NewCoins(sdk.NewInt64Coin("atom", 0)))
|
||||
tx = newTestTxWithMemo(ctx, []sdk.Msg{msg}, privs, accnums, seqs, fee, strings.Repeat("01234567890", 500))
|
||||
tx = NewTestTxWithMemo(ctx, []sdk.Msg{msg}, privs, accnums, seqs, fee, strings.Repeat("01234567890", 500))
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeMemoTooLarge)
|
||||
|
||||
// tx with memo has enough gas
|
||||
fee = NewStdFee(9000, sdk.NewCoins(sdk.NewInt64Coin("atom", 0)))
|
||||
tx = newTestTxWithMemo(ctx, []sdk.Msg{msg}, privs, accnums, seqs, fee, strings.Repeat("0123456789", 10))
|
||||
tx = NewTestTxWithMemo(ctx, []sdk.Msg{msg}, privs, accnums, seqs, fee, strings.Repeat("0123456789", 10))
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
}
|
||||
|
||||
|
@ -362,43 +364,43 @@ func TestAnteHandlerMultiSigner(t *testing.T) {
|
|||
ctx := input.ctx.WithBlockHeight(1)
|
||||
|
||||
// keys and addresses
|
||||
priv1, _, addr1 := keyPubAddr()
|
||||
priv2, _, addr2 := keyPubAddr()
|
||||
priv3, _, addr3 := keyPubAddr()
|
||||
priv1, _, addr1 := KeyTestPubAddr()
|
||||
priv2, _, addr2 := KeyTestPubAddr()
|
||||
priv3, _, addr3 := KeyTestPubAddr()
|
||||
|
||||
// set the accounts
|
||||
acc1 := input.ak.NewAccountWithAddress(ctx, addr1)
|
||||
acc1.SetCoins(newCoins())
|
||||
acc1.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc1)
|
||||
acc2 := input.ak.NewAccountWithAddress(ctx, addr2)
|
||||
acc2.SetCoins(newCoins())
|
||||
acc2.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc2)
|
||||
acc3 := input.ak.NewAccountWithAddress(ctx, addr3)
|
||||
acc3.SetCoins(newCoins())
|
||||
acc3.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc3)
|
||||
|
||||
// set up msgs and fee
|
||||
var tx sdk.Tx
|
||||
msg1 := newTestMsg(addr1, addr2)
|
||||
msg2 := newTestMsg(addr3, addr1)
|
||||
msg3 := newTestMsg(addr2, addr3)
|
||||
msg1 := NewTestMsg(addr1, addr2)
|
||||
msg2 := NewTestMsg(addr3, addr1)
|
||||
msg3 := NewTestMsg(addr2, addr3)
|
||||
msgs := []sdk.Msg{msg1, msg2, msg3}
|
||||
fee := newStdFee()
|
||||
fee := NewTestStdFee()
|
||||
|
||||
// signers in order
|
||||
privs, accnums, seqs := []crypto.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{0, 0, 0}
|
||||
tx = newTestTxWithMemo(ctx, msgs, privs, accnums, seqs, fee, "Check signers are in expected order and different account numbers works")
|
||||
tx = NewTestTxWithMemo(ctx, msgs, privs, accnums, seqs, fee, "Check signers are in expected order and different account numbers works")
|
||||
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
|
||||
// change sequence numbers
|
||||
tx = newTestTx(ctx, []sdk.Msg{msg1}, []crypto.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{1, 1}, fee)
|
||||
tx = NewTestTx(ctx, []sdk.Msg{msg1}, []crypto.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{1, 1}, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
tx = newTestTx(ctx, []sdk.Msg{msg2}, []crypto.PrivKey{priv3, priv1}, []uint64{2, 0}, []uint64{1, 2}, fee)
|
||||
tx = NewTestTx(ctx, []sdk.Msg{msg2}, []crypto.PrivKey{priv3, priv1}, []uint64{2, 0}, []uint64{1, 2}, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
|
||||
// expected seqs = [3, 2, 2]
|
||||
tx = newTestTxWithMemo(ctx, msgs, privs, accnums, []uint64{3, 2, 2}, fee, "Check signers are in expected order and different account numbers and sequence numbers works")
|
||||
tx = NewTestTxWithMemo(ctx, msgs, privs, accnums, []uint64{3, 2, 2}, fee, "Check signers are in expected order and different account numbers and sequence numbers works")
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
}
|
||||
|
||||
|
@ -409,29 +411,29 @@ func TestAnteHandlerBadSignBytes(t *testing.T) {
|
|||
ctx := input.ctx.WithBlockHeight(1)
|
||||
|
||||
// keys and addresses
|
||||
priv1, _, addr1 := keyPubAddr()
|
||||
priv2, _, addr2 := keyPubAddr()
|
||||
priv1, _, addr1 := KeyTestPubAddr()
|
||||
priv2, _, addr2 := KeyTestPubAddr()
|
||||
|
||||
// set the accounts
|
||||
acc1 := input.ak.NewAccountWithAddress(ctx, addr1)
|
||||
acc1.SetCoins(newCoins())
|
||||
acc1.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc1)
|
||||
acc2 := input.ak.NewAccountWithAddress(ctx, addr2)
|
||||
acc2.SetCoins(newCoins())
|
||||
acc2.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc2)
|
||||
|
||||
var tx sdk.Tx
|
||||
msg := newTestMsg(addr1)
|
||||
msg := NewTestMsg(addr1)
|
||||
msgs := []sdk.Msg{msg}
|
||||
fee := newStdFee()
|
||||
fee2 := newStdFee()
|
||||
fee := NewTestStdFee()
|
||||
fee2 := NewTestStdFee()
|
||||
fee2.Gas += 100
|
||||
fee3 := newStdFee()
|
||||
fee3 := NewTestStdFee()
|
||||
fee3.Amount[0].Amount = fee3.Amount[0].Amount.AddRaw(100)
|
||||
|
||||
// test good tx and signBytes
|
||||
privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
|
||||
chainID := ctx.ChainID()
|
||||
|
@ -449,14 +451,14 @@ func TestAnteHandlerBadSignBytes(t *testing.T) {
|
|||
{chainID2, 0, 1, fee, msgs, codeUnauth}, // test wrong chain_id
|
||||
{chainID, 0, 2, fee, msgs, codeUnauth}, // test wrong seqs
|
||||
{chainID, 1, 1, fee, msgs, codeUnauth}, // test wrong accnum
|
||||
{chainID, 0, 1, fee, []sdk.Msg{newTestMsg(addr2)}, codeUnauth}, // test wrong msg
|
||||
{chainID, 0, 1, fee, []sdk.Msg{NewTestMsg(addr2)}, codeUnauth}, // test wrong msg
|
||||
{chainID, 0, 1, fee2, msgs, codeUnauth}, // test wrong fee
|
||||
{chainID, 0, 1, fee3, msgs, codeUnauth}, // test wrong fee
|
||||
}
|
||||
|
||||
privs, seqs = []crypto.PrivKey{priv1}, []uint64{1}
|
||||
for _, cs := range cases {
|
||||
tx := newTestTxWithSignBytes(
|
||||
tx := NewTestTxWithSignBytes(
|
||||
msgs, privs, accnums, seqs, fee,
|
||||
StdSignBytes(cs.chainID, cs.accnum, cs.seq, cs.fee, cs.msgs, ""),
|
||||
"",
|
||||
|
@ -466,14 +468,14 @@ func TestAnteHandlerBadSignBytes(t *testing.T) {
|
|||
|
||||
// test wrong signer if public key exist
|
||||
privs, accnums, seqs = []crypto.PrivKey{priv2}, []uint64{0}, []uint64{1}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeUnauthorized)
|
||||
|
||||
// test wrong signer if public doesn't exist
|
||||
msg = newTestMsg(addr2)
|
||||
msg = NewTestMsg(addr2)
|
||||
msgs = []sdk.Msg{msg}
|
||||
privs, accnums, seqs = []crypto.PrivKey{priv1}, []uint64{1}, []uint64{0}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeInvalidPubKey)
|
||||
}
|
||||
|
||||
|
@ -484,35 +486,35 @@ func TestAnteHandlerSetPubKey(t *testing.T) {
|
|||
ctx := input.ctx.WithBlockHeight(1)
|
||||
|
||||
// keys and addresses
|
||||
priv1, _, addr1 := keyPubAddr()
|
||||
_, _, addr2 := keyPubAddr()
|
||||
priv1, _, addr1 := KeyTestPubAddr()
|
||||
_, _, addr2 := KeyTestPubAddr()
|
||||
|
||||
// set the accounts
|
||||
acc1 := input.ak.NewAccountWithAddress(ctx, addr1)
|
||||
acc1.SetCoins(newCoins())
|
||||
acc1.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc1)
|
||||
acc2 := input.ak.NewAccountWithAddress(ctx, addr2)
|
||||
acc2.SetCoins(newCoins())
|
||||
acc2.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc2)
|
||||
|
||||
var tx sdk.Tx
|
||||
|
||||
// test good tx and set public key
|
||||
msg := newTestMsg(addr1)
|
||||
msg := NewTestMsg(addr1)
|
||||
msgs := []sdk.Msg{msg}
|
||||
privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
|
||||
fee := newStdFee()
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
fee := NewTestStdFee()
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
|
||||
acc1 = input.ak.GetAccount(ctx, addr1)
|
||||
require.Equal(t, acc1.GetPubKey(), priv1.PubKey())
|
||||
|
||||
// test public key not found
|
||||
msg = newTestMsg(addr2)
|
||||
msg = NewTestMsg(addr2)
|
||||
msgs = []sdk.Msg{msg}
|
||||
tx = newTestTx(ctx, msgs, privs, []uint64{1}, seqs, fee)
|
||||
sigs := tx.(StdTx).GetSignatures()
|
||||
tx = NewTestTx(ctx, msgs, privs, []uint64{1}, seqs, fee)
|
||||
sigs := tx.(types.StdTx).GetSignatures()
|
||||
sigs[0].PubKey = nil
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeInvalidPubKey)
|
||||
|
||||
|
@ -520,7 +522,7 @@ func TestAnteHandlerSetPubKey(t *testing.T) {
|
|||
require.Nil(t, acc2.GetPubKey())
|
||||
|
||||
// test invalid signature and public key
|
||||
tx = newTestTx(ctx, msgs, privs, []uint64{1}, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, []uint64{1}, seqs, fee)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeInvalidPubKey)
|
||||
|
||||
acc2 = input.ak.GetAccount(ctx, addr2)
|
||||
|
@ -532,8 +534,8 @@ func TestProcessPubKey(t *testing.T) {
|
|||
ctx := input.ctx
|
||||
|
||||
// keys
|
||||
_, _, addr1 := keyPubAddr()
|
||||
priv2, _, addr2 := keyPubAddr()
|
||||
_, _, addr1 := KeyTestPubAddr()
|
||||
priv2, _, addr2 := KeyTestPubAddr()
|
||||
acc1 := input.ak.NewAccountWithAddress(ctx, addr1)
|
||||
acc2 := input.ak.NewAccountWithAddress(ctx, addr2)
|
||||
|
||||
|
@ -666,7 +668,7 @@ func TestCountSubkeys(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(T *testing.T) {
|
||||
require.Equal(t, tt.want, countSubKeys(tt.args.pub))
|
||||
require.Equal(t, tt.want, CountSubKeys(tt.args.pub))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -678,32 +680,32 @@ func TestAnteHandlerSigLimitExceeded(t *testing.T) {
|
|||
ctx := input.ctx.WithBlockHeight(1)
|
||||
|
||||
// keys and addresses
|
||||
priv1, _, addr1 := keyPubAddr()
|
||||
priv2, _, addr2 := keyPubAddr()
|
||||
priv3, _, addr3 := keyPubAddr()
|
||||
priv4, _, addr4 := keyPubAddr()
|
||||
priv5, _, addr5 := keyPubAddr()
|
||||
priv6, _, addr6 := keyPubAddr()
|
||||
priv7, _, addr7 := keyPubAddr()
|
||||
priv8, _, addr8 := keyPubAddr()
|
||||
priv1, _, addr1 := KeyTestPubAddr()
|
||||
priv2, _, addr2 := KeyTestPubAddr()
|
||||
priv3, _, addr3 := KeyTestPubAddr()
|
||||
priv4, _, addr4 := KeyTestPubAddr()
|
||||
priv5, _, addr5 := KeyTestPubAddr()
|
||||
priv6, _, addr6 := KeyTestPubAddr()
|
||||
priv7, _, addr7 := KeyTestPubAddr()
|
||||
priv8, _, addr8 := KeyTestPubAddr()
|
||||
|
||||
// set the accounts
|
||||
acc1 := input.ak.NewAccountWithAddress(ctx, addr1)
|
||||
acc1.SetCoins(newCoins())
|
||||
acc1.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc1)
|
||||
acc2 := input.ak.NewAccountWithAddress(ctx, addr2)
|
||||
acc2.SetCoins(newCoins())
|
||||
acc2.SetCoins(NewTestCoins())
|
||||
input.ak.SetAccount(ctx, acc2)
|
||||
|
||||
var tx sdk.Tx
|
||||
msg := newTestMsg(addr1, addr2, addr3, addr4, addr5, addr6, addr7, addr8)
|
||||
msg := NewTestMsg(addr1, addr2, addr3, addr4, addr5, addr6, addr7, addr8)
|
||||
msgs := []sdk.Msg{msg}
|
||||
fee := newStdFee()
|
||||
fee := NewTestStdFee()
|
||||
|
||||
// test rejection logic
|
||||
privs, accnums, seqs := []crypto.PrivKey{priv1, priv2, priv3, priv4, priv5, priv6, priv7, priv8},
|
||||
[]uint64{0, 0, 0, 0, 0, 0, 0, 0}, []uint64{0, 0, 0, 0, 0, 0, 0, 0}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeTooManySignatures)
|
||||
}
|
||||
|
||||
|
@ -774,16 +776,16 @@ func TestCustomSignatureVerificationGasConsumer(t *testing.T) {
|
|||
ctx := input.ctx.WithBlockHeight(1)
|
||||
|
||||
// verify that an secp256k1 account gets rejected
|
||||
priv1, _, addr1 := keyPubAddr()
|
||||
priv1, _, addr1 := KeyTestPubAddr()
|
||||
acc1 := input.ak.NewAccountWithAddress(ctx, addr1)
|
||||
_ = acc1.SetCoins(sdk.NewCoins(sdk.NewInt64Coin("atom", 150)))
|
||||
input.ak.SetAccount(ctx, acc1)
|
||||
var tx sdk.Tx
|
||||
msg := newTestMsg(addr1)
|
||||
msg := NewTestMsg(addr1)
|
||||
privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
|
||||
fee := newStdFee()
|
||||
fee := NewTestStdFee()
|
||||
msgs := []sdk.Msg{msg}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeInvalidPubKey)
|
||||
|
||||
// verify that an ed25519 account gets accepted
|
||||
|
@ -793,10 +795,10 @@ func TestCustomSignatureVerificationGasConsumer(t *testing.T) {
|
|||
acc2 := input.ak.NewAccountWithAddress(ctx, addr2)
|
||||
_ = acc2.SetCoins(sdk.NewCoins(sdk.NewInt64Coin("atom", 150)))
|
||||
input.ak.SetAccount(ctx, acc2)
|
||||
msg = newTestMsg(addr2)
|
||||
msg = NewTestMsg(addr2)
|
||||
privs, accnums, seqs = []crypto.PrivKey{priv2}, []uint64{1}, []uint64{0}
|
||||
fee = newStdFee()
|
||||
fee = NewTestStdFee()
|
||||
msgs = []sdk.Msg{msg}
|
||||
tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accnums, seqs, fee)
|
||||
checkValidTx(t, anteHandler, ctx, tx, false)
|
||||
}
|
||||
|
|
|
@ -3,16 +3,31 @@ 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/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
// GetTxCmd returns the transaction commands for this module
|
||||
func GetQueryCmd(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "Querying commands for the auth module",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: utils.ValidateCmd,
|
||||
}
|
||||
cmd.AddCommand(GetAccountCmd(cdc))
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetAccountCmd returns a query account that will display the state of the
|
||||
// account at a given address.
|
||||
// nolint: unparam
|
||||
func GetAccountCmd(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
func GetAccountCmd(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "account [address]",
|
||||
Short: "Query account balance",
|
||||
|
@ -38,5 +53,5 @@ func GetAccountCmd(storeName string, cdc *codec.Codec) *cobra.Command {
|
|||
return cliCtx.PrintOutput(acc)
|
||||
},
|
||||
}
|
||||
return client.GetCommands(cmd)[0]
|
||||
return flags.GetCommands(cmd)[0]
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
// GetTxCmd returns the transaction commands for this module
|
||||
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||
txCmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "Auth transaction subcommands",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: utils.ValidateCmd,
|
||||
}
|
||||
txCmd.AddCommand(
|
||||
GetMultiSignCommand(cdc),
|
||||
GetSignCommand(cdc),
|
||||
)
|
||||
return txCmd
|
||||
}
|
|
@ -8,22 +8,22 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/multisig"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
crkeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
// GetSignCommand returns the sign command
|
||||
func GetMultiSignCommand(codec *amino.Codec) *cobra.Command {
|
||||
func GetMultiSignCommand(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "multisign [file] [name] [[signature]...]",
|
||||
Short: "Generate multisig signatures for transactions generated offline",
|
||||
|
@ -46,7 +46,7 @@ recommended to set such parameters manually.
|
|||
version.ClientName,
|
||||
),
|
||||
),
|
||||
RunE: makeMultiSignCmd(codec),
|
||||
RunE: makeMultiSignCmd(cdc),
|
||||
Args: cobra.MinimumNArgs(3),
|
||||
}
|
||||
|
||||
|
@ -55,10 +55,10 @@ recommended to set such parameters manually.
|
|||
cmd.Flags().String(flagOutfile, "", "The document will be written to the given file instead of STDOUT")
|
||||
|
||||
// Add the flags here and return the command
|
||||
return client.PostCommands(cmd)[0]
|
||||
return flags.PostCommands(cmd)[0]
|
||||
}
|
||||
|
||||
func makeMultiSignCmd(cdc *amino.Codec) func(cmd *cobra.Command, args []string) error {
|
||||
func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error {
|
||||
return func(cmd *cobra.Command, args []string) (err error) {
|
||||
stdTx, err := utils.ReadStdTxFromFile(cdc, args[0])
|
||||
if err != nil {
|
||||
|
@ -81,7 +81,7 @@ func makeMultiSignCmd(cdc *amino.Codec) func(cmd *cobra.Command, args []string)
|
|||
multisigPub := multisigInfo.GetPubKey().(multisig.PubKeyMultisigThreshold)
|
||||
multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys))
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)
|
||||
txBldr := authtxb.NewTxBuilderFromCLI()
|
||||
txBldr := types.NewTxBuilderFromCLI()
|
||||
|
||||
if !viper.GetBool(flagOffline) {
|
||||
addr := multisigInfo.GetAddress()
|
||||
|
@ -106,7 +106,7 @@ func makeMultiSignCmd(cdc *amino.Codec) func(cmd *cobra.Command, args []string)
|
|||
}
|
||||
|
||||
// Validate each signature
|
||||
sigBytes := auth.StdSignBytes(
|
||||
sigBytes := types.StdSignBytes(
|
||||
txBldr.ChainID(), txBldr.AccountNumber(), txBldr.Sequence(),
|
||||
stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(),
|
||||
)
|
||||
|
@ -118,8 +118,8 @@ func makeMultiSignCmd(cdc *amino.Codec) func(cmd *cobra.Command, args []string)
|
|||
}
|
||||
}
|
||||
|
||||
newStdSig := auth.StdSignature{Signature: cdc.MustMarshalBinaryBare(multisigSig), PubKey: multisigPub}
|
||||
newTx := auth.NewStdTx(stdTx.GetMsgs(), stdTx.Fee, []auth.StdSignature{newStdSig}, stdTx.GetMemo())
|
||||
newStdSig := types.StdSignature{Signature: cdc.MustMarshalBinaryBare(multisigSig), PubKey: multisigPub}
|
||||
newTx := types.NewStdTx(stdTx.GetMsgs(), stdTx.Fee, []types.StdSignature{newStdSig}, stdTx.GetMemo())
|
||||
|
||||
sigOnly := viper.GetBool(flagSigOnly)
|
||||
var json []byte
|
||||
|
@ -156,7 +156,7 @@ func makeMultiSignCmd(cdc *amino.Codec) func(cmd *cobra.Command, args []string)
|
|||
}
|
||||
}
|
||||
|
||||
func readAndUnmarshalStdSignature(cdc *amino.Codec, filename string) (stdSig auth.StdSignature, err error) {
|
||||
func readAndUnmarshalStdSignature(cdc *codec.Codec, filename string) (stdSig types.StdSignature, err error) {
|
||||
var bytes []byte
|
||||
if bytes, err = ioutil.ReadFile(filename); err != nil {
|
||||
return
|
|
@ -9,13 +9,12 @@ import (
|
|||
"github.com/spf13/viper"
|
||||
"github.com/tendermint/tendermint/crypto/multisig"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -77,8 +76,8 @@ be generated via the 'multisign' command.
|
|||
)
|
||||
cmd.Flags().String(flagOutfile, "", "The document will be written to the given file instead of STDOUT")
|
||||
|
||||
cmd = client.PostCommands(cmd)[0]
|
||||
cmd.MarkFlagRequired(client.FlagFrom)
|
||||
cmd = flags.PostCommands(cmd)[0]
|
||||
cmd.MarkFlagRequired(flags.FlagFrom)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
@ -87,8 +86,8 @@ func preSignCmd(cmd *cobra.Command, _ []string) {
|
|||
// Conditionally mark the account and sequence numbers required as no RPC
|
||||
// query will be done.
|
||||
if viper.GetBool(flagOffline) {
|
||||
cmd.MarkFlagRequired(client.FlagAccountNumber)
|
||||
cmd.MarkFlagRequired(client.FlagSequence)
|
||||
cmd.MarkFlagRequired(flags.FlagAccountNumber)
|
||||
cmd.MarkFlagRequired(flags.FlagSequence)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +100,7 @@ func makeSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error
|
|||
|
||||
offline := viper.GetBool(flagOffline)
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)
|
||||
txBldr := authtxb.NewTxBuilderFromCLI()
|
||||
txBldr := types.NewTxBuilderFromCLI()
|
||||
|
||||
if viper.GetBool(flagValidateSigs) {
|
||||
if !printAndValidateSigs(cliCtx, txBldr.ChainID(), stdTx, offline) {
|
||||
|
@ -112,7 +111,7 @@ func makeSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error
|
|||
}
|
||||
|
||||
// if --signature-only is on, then override --append
|
||||
var newTx auth.StdTx
|
||||
var newTx types.StdTx
|
||||
generateSignatureOnly := viper.GetBool(flagSigOnly)
|
||||
multisigAddrStr := viper.GetString(flagMultisig)
|
||||
|
||||
|
@ -161,7 +160,7 @@ func makeSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error
|
|||
}
|
||||
}
|
||||
|
||||
func getSignatureJSON(cdc *codec.Codec, newTx auth.StdTx, indent, generateSignatureOnly bool) ([]byte, error) {
|
||||
func getSignatureJSON(cdc *codec.Codec, newTx types.StdTx, indent, generateSignatureOnly bool) ([]byte, error) {
|
||||
switch generateSignatureOnly {
|
||||
case true:
|
||||
switch indent {
|
||||
|
@ -186,7 +185,7 @@ func getSignatureJSON(cdc *codec.Codec, newTx auth.StdTx, indent, generateSignat
|
|||
// its expected signers. In addition, if offline has not been supplied, the
|
||||
// signature is verified over the transaction sign bytes.
|
||||
func printAndValidateSigs(
|
||||
cliCtx context.CLIContext, chainID string, stdTx auth.StdTx, offline bool,
|
||||
cliCtx context.CLIContext, chainID string, stdTx types.StdTx, offline bool,
|
||||
) bool {
|
||||
|
||||
fmt.Println("Signers:")
|
||||
|
@ -229,7 +228,7 @@ func printAndValidateSigs(
|
|||
return false
|
||||
}
|
||||
|
||||
sigBytes := auth.StdSignBytes(
|
||||
sigBytes := types.StdSignBytes(
|
||||
chainID, acc.GetAccountNumber(), acc.GetSequence(),
|
||||
stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(),
|
||||
)
|
|
@ -10,7 +10,7 @@ import (
|
|||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
// register REST routes
|
||||
|
@ -29,7 +29,7 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec,
|
|||
// query accountREST Handler
|
||||
func QueryAccountRequestHandlerFn(
|
||||
storeName string, cdc *codec.Codec,
|
||||
decoder auth.AccountDecoder, cliCtx context.CLIContext,
|
||||
decoder types.AccountDecoder, cliCtx context.CLIContext,
|
||||
) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
|
@ -41,7 +41,7 @@ func QueryAccountRequestHandlerFn(
|
|||
return
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryStore(auth.AddressStoreKey(addr), storeName)
|
||||
res, err := cliCtx.QueryStore(types.AddressStoreKey(addr), storeName)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
@ -49,7 +49,7 @@ func QueryAccountRequestHandlerFn(
|
|||
|
||||
// the query will return empty account if there is no data
|
||||
if len(res) == 0 {
|
||||
rest.PostProcessResponse(w, cdc, auth.BaseAccount{}, cliCtx.Indent)
|
||||
rest.PostProcessResponse(w, cdc, types.BaseAccount{}, cliCtx.Indent)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ func QueryAccountRequestHandlerFn(
|
|||
// query accountREST Handler
|
||||
func QueryBalancesRequestHandlerFn(
|
||||
storeName string, cdc *codec.Codec,
|
||||
decoder auth.AccountDecoder, cliCtx context.CLIContext,
|
||||
decoder types.AccountDecoder, cliCtx context.CLIContext,
|
||||
) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
@ -80,7 +80,7 @@ func QueryBalancesRequestHandlerFn(
|
|||
return
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryStore(auth.AddressStoreKey(addr), storeName)
|
||||
res, err := cliCtx.QueryStore(types.AddressStoreKey(addr), storeName)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package context
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
)
|
||||
|
||||
// StdSignMsg is a convenience structure for passing along
|
||||
// a Msg with the other requirements for a StdSignDoc before
|
||||
// it is signed. For use in the CLI.
|
||||
type StdSignMsg struct {
|
||||
ChainID string `json:"chain_id"`
|
||||
AccountNumber uint64 `json:"account_number"`
|
||||
Sequence uint64 `json:"sequence"`
|
||||
Fee auth.StdFee `json:"fee"`
|
||||
Msgs []sdk.Msg `json:"msgs"`
|
||||
Memo string `json:"memo"`
|
||||
}
|
||||
|
||||
// get message bytes
|
||||
func (msg StdSignMsg) Bytes() []byte {
|
||||
return auth.StdSignBytes(msg.ChainID, msg.AccountNumber, msg.Sequence, msg.Fee, msg.Msgs, msg.Memo)
|
||||
}
|
|
@ -8,7 +8,7 @@ import (
|
|||
var moduleCdc *codec.Codec
|
||||
|
||||
func init() {
|
||||
cdc := codec.New()
|
||||
codec.RegisterCrypto(cdc)
|
||||
moduleCdc = cdc.Seal()
|
||||
moduleCdc = codec.New()
|
||||
codec.RegisterCrypto(moduleCdc)
|
||||
moduleCdc.Seal()
|
||||
}
|
||||
|
|
|
@ -3,15 +3,21 @@ package genaccounts
|
|||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"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/types/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
var (
|
||||
_ sdk.AppModuleGenesis = AppModule{}
|
||||
_ sdk.AppModuleBasic = AppModuleBasic{}
|
||||
_ module.AppModuleGenesis = AppModule{}
|
||||
_ module.AppModuleBasic = AppModuleBasic{}
|
||||
)
|
||||
|
||||
// module name
|
||||
|
@ -43,6 +49,15 @@ 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(_ *codec.Codec) *cobra.Command { return nil }
|
||||
|
||||
// get the root query command of this module
|
||||
func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *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
|
||||
|
@ -66,9 +81,9 @@ type AppModule struct {
|
|||
}
|
||||
|
||||
// NewAppModule creates a new AppModule object
|
||||
func NewAppModule(accountKeeper AccountKeeper) sdk.AppModule {
|
||||
func NewAppModule(accountKeeper AccountKeeper) module.AppModule {
|
||||
|
||||
return sdk.NewGenesisOnlyAppModule(AppModule{
|
||||
return module.NewGenesisOnlyAppModule(AppModule{
|
||||
AppModuleBasic: AppModuleBasic{},
|
||||
accountKeeper: accountKeeper,
|
||||
})
|
||||
|
|
|
@ -1,61 +1,20 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
// GenesisState - all auth state that must be provided at genesis
|
||||
type GenesisState struct {
|
||||
CollectedFees sdk.Coins `json:"collected_fees"`
|
||||
Params Params `json:"params"`
|
||||
}
|
||||
|
||||
// NewGenesisState - Create a new genesis state
|
||||
func NewGenesisState(collectedFees sdk.Coins, params Params) GenesisState {
|
||||
return GenesisState{
|
||||
CollectedFees: collectedFees,
|
||||
Params: params,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultGenesisState - Return a default genesis state
|
||||
func DefaultGenesisState() GenesisState {
|
||||
return NewGenesisState(sdk.NewCoins(), DefaultParams())
|
||||
}
|
||||
|
||||
// InitGenesis - Init store state from genesis data
|
||||
func InitGenesis(ctx sdk.Context, ak AccountKeeper, fck FeeCollectionKeeper, data GenesisState) {
|
||||
func InitGenesis(ctx sdk.Context, ak AccountKeeper, fck types.FeeCollectionKeeper, data types.GenesisState) {
|
||||
ak.SetParams(ctx, data.Params)
|
||||
fck.setCollectedFees(ctx, data.CollectedFees)
|
||||
fck.AddCollectedFees(ctx, data.CollectedFees)
|
||||
}
|
||||
|
||||
// ExportGenesis returns a GenesisState for a given context and keeper
|
||||
func ExportGenesis(ctx sdk.Context, ak AccountKeeper, fck FeeCollectionKeeper) GenesisState {
|
||||
func ExportGenesis(ctx sdk.Context, ak AccountKeeper, fck types.FeeCollectionKeeper) types.GenesisState {
|
||||
collectedFees := fck.GetCollectedFees(ctx)
|
||||
params := ak.GetParams(ctx)
|
||||
|
||||
return NewGenesisState(collectedFees, params)
|
||||
}
|
||||
|
||||
// ValidateGenesis performs basic validation of auth genesis data returning an
|
||||
// error for any failed validation criteria.
|
||||
func ValidateGenesis(data GenesisState) error {
|
||||
if data.Params.TxSigLimit == 0 {
|
||||
return fmt.Errorf("invalid tx signature limit: %d", data.Params.TxSigLimit)
|
||||
}
|
||||
if data.Params.SigVerifyCostED25519 == 0 {
|
||||
return fmt.Errorf("invalid ED25519 signature verification cost: %d", data.Params.SigVerifyCostED25519)
|
||||
}
|
||||
if data.Params.SigVerifyCostSecp256k1 == 0 {
|
||||
return fmt.Errorf("invalid SECK256k1 signature verification cost: %d", data.Params.SigVerifyCostSecp256k1)
|
||||
}
|
||||
if data.Params.MaxMemoCharacters == 0 {
|
||||
return fmt.Errorf("invalid max memo characters: %d", data.Params.MaxMemoCharacters)
|
||||
}
|
||||
if data.Params.TxSizeCostPerByte == 0 {
|
||||
return fmt.Errorf("invalid tx size cost per byte: %d", data.Params.TxSizeCostPerByte)
|
||||
}
|
||||
return nil
|
||||
return types.NewGenesisState(collectedFees, params)
|
||||
}
|
||||
|
|
|
@ -7,27 +7,10 @@ import (
|
|||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/params/subspace"
|
||||
)
|
||||
|
||||
const (
|
||||
// StoreKey is string representation of the store key for auth
|
||||
StoreKey = "acc"
|
||||
|
||||
// FeeStoreKey is a string representation of the store key for fees
|
||||
FeeStoreKey = "fee"
|
||||
|
||||
// QuerierRoute is the querier route for acc
|
||||
QuerierRoute = StoreKey
|
||||
)
|
||||
|
||||
var (
|
||||
// AddressStoreKeyPrefix prefix for account-by-address store
|
||||
AddressStoreKeyPrefix = []byte{0x01}
|
||||
|
||||
globalAccountNumberKey = []byte("globalAccountNumber")
|
||||
)
|
||||
|
||||
// AccountKeeper encodes/decodes accounts using the go-amino (binary)
|
||||
// encoding/decoding library.
|
||||
type AccountKeeper struct {
|
||||
|
@ -35,7 +18,7 @@ type AccountKeeper struct {
|
|||
key sdk.StoreKey
|
||||
|
||||
// The prototypical Account constructor.
|
||||
proto func() Account
|
||||
proto func() types.Account
|
||||
|
||||
// The codec codec for binary encoding/decoding of accounts.
|
||||
cdc *codec.Codec
|
||||
|
@ -47,19 +30,19 @@ type AccountKeeper struct {
|
|||
// (binary) encode and decode concrete sdk.Accounts.
|
||||
// nolint
|
||||
func NewAccountKeeper(
|
||||
cdc *codec.Codec, key sdk.StoreKey, paramstore subspace.Subspace, proto func() Account,
|
||||
cdc *codec.Codec, key sdk.StoreKey, paramstore subspace.Subspace, proto func() types.Account,
|
||||
) AccountKeeper {
|
||||
|
||||
return AccountKeeper{
|
||||
key: key,
|
||||
proto: proto,
|
||||
cdc: cdc,
|
||||
paramSubspace: paramstore.WithKeyTable(ParamKeyTable()),
|
||||
paramSubspace: paramstore.WithKeyTable(types.ParamKeyTable()),
|
||||
}
|
||||
}
|
||||
|
||||
// NewAccountWithAddress implements sdk.AccountKeeper.
|
||||
func (ak AccountKeeper) NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) Account {
|
||||
func (ak AccountKeeper) NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) types.Account {
|
||||
acc := ak.proto()
|
||||
err := acc.SetAddress(addr)
|
||||
if err != nil {
|
||||
|
@ -75,22 +58,17 @@ func (ak AccountKeeper) NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddre
|
|||
}
|
||||
|
||||
// NewAccount creates a new account
|
||||
func (ak AccountKeeper) NewAccount(ctx sdk.Context, acc Account) Account {
|
||||
func (ak AccountKeeper) NewAccount(ctx sdk.Context, acc types.Account) types.Account {
|
||||
if err := acc.SetAccountNumber(ak.GetNextAccountNumber(ctx)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return acc
|
||||
}
|
||||
|
||||
// AddressStoreKey turn an address to key used to get it from the account store
|
||||
func AddressStoreKey(addr sdk.AccAddress) []byte {
|
||||
return append(AddressStoreKeyPrefix, addr.Bytes()...)
|
||||
}
|
||||
|
||||
// GetAccount implements sdk.AccountKeeper.
|
||||
func (ak AccountKeeper) GetAccount(ctx sdk.Context, addr sdk.AccAddress) Account {
|
||||
func (ak AccountKeeper) GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.Account {
|
||||
store := ctx.KVStore(ak.key)
|
||||
bz := store.Get(AddressStoreKey(addr))
|
||||
bz := store.Get(types.AddressStoreKey(addr))
|
||||
if bz == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -99,9 +77,9 @@ func (ak AccountKeeper) GetAccount(ctx sdk.Context, addr sdk.AccAddress) Account
|
|||
}
|
||||
|
||||
// GetAllAccounts returns all accounts in the accountKeeper.
|
||||
func (ak AccountKeeper) GetAllAccounts(ctx sdk.Context) []Account {
|
||||
accounts := []Account{}
|
||||
appendAccount := func(acc Account) (stop bool) {
|
||||
func (ak AccountKeeper) GetAllAccounts(ctx sdk.Context) []types.Account {
|
||||
accounts := []types.Account{}
|
||||
appendAccount := func(acc types.Account) (stop bool) {
|
||||
accounts = append(accounts, acc)
|
||||
return false
|
||||
}
|
||||
|
@ -110,28 +88,28 @@ func (ak AccountKeeper) GetAllAccounts(ctx sdk.Context) []Account {
|
|||
}
|
||||
|
||||
// SetAccount implements sdk.AccountKeeper.
|
||||
func (ak AccountKeeper) SetAccount(ctx sdk.Context, acc Account) {
|
||||
func (ak AccountKeeper) SetAccount(ctx sdk.Context, acc types.Account) {
|
||||
addr := acc.GetAddress()
|
||||
store := ctx.KVStore(ak.key)
|
||||
bz, err := ak.cdc.MarshalBinaryBare(acc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
store.Set(AddressStoreKey(addr), bz)
|
||||
store.Set(types.AddressStoreKey(addr), bz)
|
||||
}
|
||||
|
||||
// RemoveAccount removes an account for the account mapper store.
|
||||
// NOTE: this will cause supply invariant violation if called
|
||||
func (ak AccountKeeper) RemoveAccount(ctx sdk.Context, acc Account) {
|
||||
func (ak AccountKeeper) RemoveAccount(ctx sdk.Context, acc types.Account) {
|
||||
addr := acc.GetAddress()
|
||||
store := ctx.KVStore(ak.key)
|
||||
store.Delete(AddressStoreKey(addr))
|
||||
store.Delete(types.AddressStoreKey(addr))
|
||||
}
|
||||
|
||||
// IterateAccounts implements sdk.AccountKeeper.
|
||||
func (ak AccountKeeper) IterateAccounts(ctx sdk.Context, process func(Account) (stop bool)) {
|
||||
func (ak AccountKeeper) IterateAccounts(ctx sdk.Context, process func(types.Account) (stop bool)) {
|
||||
store := ctx.KVStore(ak.key)
|
||||
iter := sdk.KVStorePrefixIterator(store, AddressStoreKeyPrefix)
|
||||
iter := sdk.KVStorePrefixIterator(store, types.AddressStoreKeyPrefix)
|
||||
defer iter.Close()
|
||||
for {
|
||||
if !iter.Valid() {
|
||||
|
@ -182,7 +160,7 @@ func (ak AccountKeeper) setSequence(ctx sdk.Context, addr sdk.AccAddress, newSeq
|
|||
func (ak AccountKeeper) GetNextAccountNumber(ctx sdk.Context) uint64 {
|
||||
var accNumber uint64
|
||||
store := ctx.KVStore(ak.key)
|
||||
bz := store.Get(globalAccountNumberKey)
|
||||
bz := store.Get(types.GlobalAccountNumberKey)
|
||||
if bz == nil {
|
||||
accNumber = 0
|
||||
} else {
|
||||
|
@ -193,7 +171,7 @@ func (ak AccountKeeper) GetNextAccountNumber(ctx sdk.Context) uint64 {
|
|||
}
|
||||
|
||||
bz = ak.cdc.MustMarshalBinaryLengthPrefixed(accNumber + 1)
|
||||
store.Set(globalAccountNumberKey, bz)
|
||||
store.Set(types.GlobalAccountNumberKey, bz)
|
||||
|
||||
return accNumber
|
||||
}
|
||||
|
@ -202,12 +180,12 @@ func (ak AccountKeeper) GetNextAccountNumber(ctx sdk.Context) uint64 {
|
|||
// Params
|
||||
|
||||
// SetParams sets the auth module's parameters.
|
||||
func (ak AccountKeeper) SetParams(ctx sdk.Context, params Params) {
|
||||
func (ak AccountKeeper) SetParams(ctx sdk.Context, params types.Params) {
|
||||
ak.paramSubspace.SetParamSet(ctx, ¶ms)
|
||||
}
|
||||
|
||||
// GetParams gets the auth module's parameters.
|
||||
func (ak AccountKeeper) GetParams(ctx sdk.Context) (params Params) {
|
||||
func (ak AccountKeeper) GetParams(ctx sdk.Context) (params types.Params) {
|
||||
ak.paramSubspace.GetParamSet(ctx, ¶ms)
|
||||
return
|
||||
}
|
||||
|
@ -215,7 +193,7 @@ func (ak AccountKeeper) GetParams(ctx sdk.Context) (params Params) {
|
|||
// -----------------------------------------------------------------------------
|
||||
// Misc.
|
||||
|
||||
func (ak AccountKeeper) decodeAccount(bz []byte) (acc Account) {
|
||||
func (ak AccountKeeper) decodeAccount(bz []byte) (acc types.Account) {
|
||||
err := ak.cdc.UnmarshalBinaryBare(bz, &acc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -3,45 +3,65 @@ package auth
|
|||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"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/types/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/client/rest"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
var (
|
||||
_ sdk.AppModule = AppModule{}
|
||||
_ sdk.AppModuleBasic = AppModuleBasic{}
|
||||
_ module.AppModule = AppModule{}
|
||||
_ module.AppModuleBasic = AppModuleBasic{}
|
||||
)
|
||||
|
||||
// name of this module
|
||||
const ModuleName = "auth"
|
||||
|
||||
// app module basics object
|
||||
type AppModuleBasic struct{}
|
||||
|
||||
// module name
|
||||
func (AppModuleBasic) Name() string {
|
||||
return ModuleName
|
||||
return types.ModuleName
|
||||
}
|
||||
|
||||
// register module codec
|
||||
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
|
||||
RegisterCodec(cdc)
|
||||
types.RegisterCodec(cdc)
|
||||
}
|
||||
|
||||
// default genesis state
|
||||
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
|
||||
return moduleCdc.MustMarshalJSON(DefaultGenesisState())
|
||||
return types.ModuleCdc.MustMarshalJSON(types.DefaultGenesisState())
|
||||
}
|
||||
|
||||
// module validate genesis
|
||||
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
|
||||
var data GenesisState
|
||||
err := moduleCdc.UnmarshalJSON(bz, &data)
|
||||
var data types.GenesisState
|
||||
err := types.ModuleCdc.UnmarshalJSON(bz, &data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ValidateGenesis(data)
|
||||
return types.ValidateGenesis(data)
|
||||
}
|
||||
|
||||
// register rest routes
|
||||
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {
|
||||
rest.RegisterRoutes(ctx, rtr, cdc, types.StoreKey)
|
||||
}
|
||||
|
||||
// get the root tx command of this module
|
||||
func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||
return cli.GetTxCmd(cdc)
|
||||
}
|
||||
|
||||
// get the root query command of this module
|
||||
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
|
||||
return cli.GetQueryCmd(cdc)
|
||||
}
|
||||
|
||||
//___________________________
|
||||
|
@ -49,12 +69,12 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
|
|||
type AppModule struct {
|
||||
AppModuleBasic
|
||||
accountKeeper AccountKeeper
|
||||
feeCollectionKeeper FeeCollectionKeeper
|
||||
feeCollectionKeeper types.FeeCollectionKeeper
|
||||
}
|
||||
|
||||
// NewAppModule creates a new AppModule object
|
||||
func NewAppModule(accountKeeper AccountKeeper,
|
||||
feeCollectionKeeper FeeCollectionKeeper) AppModule {
|
||||
feeCollectionKeeper types.FeeCollectionKeeper) AppModule {
|
||||
return AppModule{
|
||||
AppModuleBasic: AppModuleBasic{},
|
||||
accountKeeper: accountKeeper,
|
||||
|
@ -64,7 +84,7 @@ func NewAppModule(accountKeeper AccountKeeper,
|
|||
|
||||
// module name
|
||||
func (AppModule) Name() string {
|
||||
return ModuleName
|
||||
return types.ModuleName
|
||||
}
|
||||
|
||||
// register invariants
|
||||
|
@ -78,7 +98,7 @@ func (AppModule) NewHandler() sdk.Handler { return nil }
|
|||
|
||||
// module querier route name
|
||||
func (AppModule) QuerierRoute() string {
|
||||
return QuerierRoute
|
||||
return types.QuerierRoute
|
||||
}
|
||||
|
||||
// module querier
|
||||
|
@ -88,8 +108,8 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
|
|||
|
||||
// module init-genesis
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
|
||||
var genesisState GenesisState
|
||||
moduleCdc.MustUnmarshalJSON(data, &genesisState)
|
||||
var genesisState types.GenesisState
|
||||
types.ModuleCdc.MustUnmarshalJSON(data, &genesisState)
|
||||
InitGenesis(ctx, am.accountKeeper, am.feeCollectionKeeper, genesisState)
|
||||
return []abci.ValidatorUpdate{}
|
||||
}
|
||||
|
@ -97,7 +117,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.Va
|
|||
// module export genesis
|
||||
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
|
||||
gs := ExportGenesis(ctx, am.accountKeeper, am.feeCollectionKeeper)
|
||||
return moduleCdc.MustMarshalJSON(gs)
|
||||
return types.ModuleCdc.MustMarshalJSON(gs)
|
||||
}
|
||||
|
||||
// module begin-block
|
||||
|
|
|
@ -7,18 +7,14 @@ import (
|
|||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// query endpoints supported by the auth Querier
|
||||
const (
|
||||
QueryAccount = "account"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
// creates a querier for auth REST endpoints
|
||||
func NewQuerier(keeper AccountKeeper) sdk.Querier {
|
||||
return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, sdk.Error) {
|
||||
switch path[0] {
|
||||
case QueryAccount:
|
||||
case types.QueryAccount:
|
||||
return queryAccount(ctx, req, keeper)
|
||||
default:
|
||||
return nil, sdk.ErrUnknownRequest("unknown auth query endpoint")
|
||||
|
@ -26,19 +22,8 @@ func NewQuerier(keeper AccountKeeper) sdk.Querier {
|
|||
}
|
||||
}
|
||||
|
||||
// defines the params for query: "custom/acc/account"
|
||||
type QueryAccountParams struct {
|
||||
Address sdk.AccAddress
|
||||
}
|
||||
|
||||
func NewQueryAccountParams(addr sdk.AccAddress) QueryAccountParams {
|
||||
return QueryAccountParams{
|
||||
Address: addr,
|
||||
}
|
||||
}
|
||||
|
||||
func queryAccount(ctx sdk.Context, req abci.RequestQuery, keeper AccountKeeper) ([]byte, sdk.Error) {
|
||||
var params QueryAccountParams
|
||||
var params types.QueryAccountParams
|
||||
if err := keeper.cdc.UnmarshalJSON(req.Data, ¶ms); err != nil {
|
||||
return nil, sdk.ErrInternal(fmt.Sprintf("failed to parse params: %s", err))
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ func Test_queryAccount(t *testing.T) {
|
|||
require.NotNil(t, err)
|
||||
require.Nil(t, res)
|
||||
|
||||
_, _, addr := keyPubAddr()
|
||||
_, _, addr := KeyTestPubAddr()
|
||||
req.Data = input.cdc.MustMarshalJSON(NewQueryAccountParams(addr))
|
||||
res, err = queryAccount(input.ctx, req, input.ak)
|
||||
require.NotNil(t, err)
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
// nolint
|
||||
package auth
|
||||
|
||||
import (
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
dbm "github.com/tendermint/tendermint/libs/db"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/params/subspace"
|
||||
)
|
||||
|
||||
type testInput struct {
|
||||
cdc *codec.Codec
|
||||
ctx sdk.Context
|
||||
ak AccountKeeper
|
||||
fck types.FeeCollectionKeeper
|
||||
}
|
||||
|
||||
func setupTestInput() testInput {
|
||||
db := dbm.NewMemDB()
|
||||
|
||||
cdc := codec.New()
|
||||
types.RegisterBaseAccount(cdc)
|
||||
|
||||
authCapKey := sdk.NewKVStoreKey("authCapKey")
|
||||
fckCapKey := sdk.NewKVStoreKey("fckCapKey")
|
||||
keyParams := sdk.NewKVStoreKey("subspace")
|
||||
tkeyParams := sdk.NewTransientStoreKey("transient_subspace")
|
||||
|
||||
ms := store.NewCommitMultiStore(db)
|
||||
ms.MountStoreWithDB(authCapKey, sdk.StoreTypeIAVL, db)
|
||||
ms.MountStoreWithDB(fckCapKey, sdk.StoreTypeIAVL, db)
|
||||
ms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db)
|
||||
ms.MountStoreWithDB(tkeyParams, sdk.StoreTypeTransient, db)
|
||||
ms.LoadLatestVersion()
|
||||
|
||||
ps := subspace.NewSubspace(cdc, keyParams, tkeyParams, types.DefaultParamspace)
|
||||
ak := NewAccountKeeper(cdc, authCapKey, ps, types.ProtoBaseAccount)
|
||||
fck := types.NewFeeCollectionKeeper(cdc, fckCapKey)
|
||||
ctx := sdk.NewContext(ms, abci.Header{ChainID: "test-chain-id"}, false, log.NewNopLogger())
|
||||
|
||||
ak.SetParams(ctx, types.DefaultParams())
|
||||
|
||||
return testInput{cdc: cdc, ctx: ctx, ak: ak, fck: fck}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package auth
|
||||
package types
|
||||
|
||||
import (
|
||||
"errors"
|
|
@ -1,4 +1,4 @@
|
|||
package auth
|
||||
package types
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
@ -18,8 +18,8 @@ var (
|
|||
)
|
||||
|
||||
func TestBaseAddressPubKey(t *testing.T) {
|
||||
_, pub1, addr1 := keyPubAddr()
|
||||
_, pub2, addr2 := keyPubAddr()
|
||||
_, pub1, addr1 := KeyTestPubAddr()
|
||||
_, pub2, addr2 := KeyTestPubAddr()
|
||||
acc := NewBaseAccountWithAddress(addr1)
|
||||
|
||||
// check the address (set) and pubkey (not set)
|
||||
|
@ -51,7 +51,7 @@ func TestBaseAddressPubKey(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBaseAccountCoins(t *testing.T) {
|
||||
_, _, addr := keyPubAddr()
|
||||
_, _, addr := KeyTestPubAddr()
|
||||
acc := NewBaseAccountWithAddress(addr)
|
||||
|
||||
someCoins := sdk.Coins{sdk.NewInt64Coin("atom", 123), sdk.NewInt64Coin("eth", 246)}
|
||||
|
@ -62,7 +62,7 @@ func TestBaseAccountCoins(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBaseAccountSequence(t *testing.T) {
|
||||
_, _, addr := keyPubAddr()
|
||||
_, _, addr := KeyTestPubAddr()
|
||||
acc := NewBaseAccountWithAddress(addr)
|
||||
|
||||
seq := uint64(7)
|
||||
|
@ -73,7 +73,7 @@ func TestBaseAccountSequence(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBaseAccountMarshal(t *testing.T) {
|
||||
_, pub, addr := keyPubAddr()
|
||||
_, pub, addr := KeyTestPubAddr()
|
||||
acc := NewBaseAccountWithAddress(addr)
|
||||
|
||||
someCoins := sdk.Coins{sdk.NewInt64Coin("atom", 123), sdk.NewInt64Coin("eth", 246)}
|
||||
|
@ -109,7 +109,7 @@ func TestGetVestedCoinsContVestingAcc(t *testing.T) {
|
|||
now := tmtime.Now()
|
||||
endTime := now.Add(24 * time.Hour)
|
||||
|
||||
_, _, addr := keyPubAddr()
|
||||
_, _, addr := KeyTestPubAddr()
|
||||
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
|
||||
bacc := NewBaseAccountWithAddress(addr)
|
||||
bacc.SetCoins(origCoins)
|
||||
|
@ -136,7 +136,7 @@ func TestGetVestingCoinsContVestingAcc(t *testing.T) {
|
|||
now := tmtime.Now()
|
||||
endTime := now.Add(24 * time.Hour)
|
||||
|
||||
_, _, addr := keyPubAddr()
|
||||
_, _, addr := KeyTestPubAddr()
|
||||
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
|
||||
bacc := NewBaseAccountWithAddress(addr)
|
||||
bacc.SetCoins(origCoins)
|
||||
|
@ -159,7 +159,7 @@ func TestSpendableCoinsContVestingAcc(t *testing.T) {
|
|||
now := tmtime.Now()
|
||||
endTime := now.Add(24 * time.Hour)
|
||||
|
||||
_, _, addr := keyPubAddr()
|
||||
_, _, addr := KeyTestPubAddr()
|
||||
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
|
||||
bacc := NewBaseAccountWithAddress(addr)
|
||||
bacc.SetCoins(origCoins)
|
||||
|
@ -199,7 +199,7 @@ func TestTrackDelegationContVestingAcc(t *testing.T) {
|
|||
now := tmtime.Now()
|
||||
endTime := now.Add(24 * time.Hour)
|
||||
|
||||
_, _, addr := keyPubAddr()
|
||||
_, _, addr := KeyTestPubAddr()
|
||||
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
|
||||
bacc := NewBaseAccountWithAddress(addr)
|
||||
bacc.SetCoins(origCoins)
|
||||
|
@ -246,7 +246,7 @@ func TestTrackUndelegationContVestingAcc(t *testing.T) {
|
|||
now := tmtime.Now()
|
||||
endTime := now.Add(24 * time.Hour)
|
||||
|
||||
_, _, addr := keyPubAddr()
|
||||
_, _, addr := KeyTestPubAddr()
|
||||
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
|
||||
bacc := NewBaseAccountWithAddress(addr)
|
||||
bacc.SetCoins(origCoins)
|
||||
|
@ -302,7 +302,7 @@ func TestGetVestedCoinsDelVestingAcc(t *testing.T) {
|
|||
now := tmtime.Now()
|
||||
endTime := now.Add(24 * time.Hour)
|
||||
|
||||
_, _, addr := keyPubAddr()
|
||||
_, _, addr := KeyTestPubAddr()
|
||||
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
|
||||
bacc := NewBaseAccountWithAddress(addr)
|
||||
bacc.SetCoins(origCoins)
|
||||
|
@ -321,7 +321,7 @@ func TestGetVestingCoinsDelVestingAcc(t *testing.T) {
|
|||
now := tmtime.Now()
|
||||
endTime := now.Add(24 * time.Hour)
|
||||
|
||||
_, _, addr := keyPubAddr()
|
||||
_, _, addr := KeyTestPubAddr()
|
||||
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
|
||||
bacc := NewBaseAccountWithAddress(addr)
|
||||
bacc.SetCoins(origCoins)
|
||||
|
@ -340,7 +340,7 @@ func TestSpendableCoinsDelVestingAcc(t *testing.T) {
|
|||
now := tmtime.Now()
|
||||
endTime := now.Add(24 * time.Hour)
|
||||
|
||||
_, _, addr := keyPubAddr()
|
||||
_, _, addr := KeyTestPubAddr()
|
||||
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
|
||||
bacc := NewBaseAccountWithAddress(addr)
|
||||
bacc.SetCoins(origCoins)
|
||||
|
@ -381,7 +381,7 @@ func TestTrackDelegationDelVestingAcc(t *testing.T) {
|
|||
now := tmtime.Now()
|
||||
endTime := now.Add(24 * time.Hour)
|
||||
|
||||
_, _, addr := keyPubAddr()
|
||||
_, _, addr := KeyTestPubAddr()
|
||||
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
|
||||
bacc := NewBaseAccountWithAddress(addr)
|
||||
bacc.SetCoins(origCoins)
|
||||
|
@ -427,7 +427,7 @@ func TestTrackUndelegationDelVestingAcc(t *testing.T) {
|
|||
now := tmtime.Now()
|
||||
endTime := now.Add(24 * time.Hour)
|
||||
|
||||
_, _, addr := keyPubAddr()
|
||||
_, _, addr := KeyTestPubAddr()
|
||||
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
|
||||
bacc := NewBaseAccountWithAddress(addr)
|
||||
bacc.SetCoins(origCoins)
|
|
@ -1,4 +1,4 @@
|
|||
package auth
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
|
@ -26,9 +26,12 @@ func RegisterBaseAccount(cdc *codec.Codec) {
|
|||
codec.RegisterCrypto(cdc)
|
||||
}
|
||||
|
||||
var moduleCdc = codec.New()
|
||||
// module wide codec
|
||||
var ModuleCdc *codec.Codec
|
||||
|
||||
func init() {
|
||||
RegisterCodec(moduleCdc)
|
||||
codec.RegisterCrypto(moduleCdc)
|
||||
ModuleCdc = codec.New()
|
||||
RegisterCodec(ModuleCdc)
|
||||
codec.RegisterCrypto(ModuleCdc)
|
||||
ModuleCdc.Seal()
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package auth
|
||||
package types
|
||||
|
||||
import (
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
|
@ -1,4 +1,4 @@
|
|||
package auth
|
||||
package types
|
||||
|
||||
import (
|
||||
"testing"
|
|
@ -0,0 +1,47 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// GenesisState - all auth state that must be provided at genesis
|
||||
type GenesisState struct {
|
||||
CollectedFees sdk.Coins `json:"collected_fees"`
|
||||
Params Params `json:"params"`
|
||||
}
|
||||
|
||||
// NewGenesisState - Create a new genesis state
|
||||
func NewGenesisState(collectedFees sdk.Coins, params Params) GenesisState {
|
||||
return GenesisState{
|
||||
CollectedFees: collectedFees,
|
||||
Params: params,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultGenesisState - Return a default genesis state
|
||||
func DefaultGenesisState() GenesisState {
|
||||
return NewGenesisState(sdk.NewCoins(), DefaultParams())
|
||||
}
|
||||
|
||||
// ValidateGenesis performs basic validation of auth genesis data returning an
|
||||
// error for any failed validation criteria.
|
||||
func ValidateGenesis(data GenesisState) error {
|
||||
if data.Params.TxSigLimit == 0 {
|
||||
return fmt.Errorf("invalid tx signature limit: %d", data.Params.TxSigLimit)
|
||||
}
|
||||
if data.Params.SigVerifyCostED25519 == 0 {
|
||||
return fmt.Errorf("invalid ED25519 signature verification cost: %d", data.Params.SigVerifyCostED25519)
|
||||
}
|
||||
if data.Params.SigVerifyCostSecp256k1 == 0 {
|
||||
return fmt.Errorf("invalid SECK256k1 signature verification cost: %d", data.Params.SigVerifyCostSecp256k1)
|
||||
}
|
||||
if data.Params.MaxMemoCharacters == 0 {
|
||||
return fmt.Errorf("invalid max memo characters: %d", data.Params.MaxMemoCharacters)
|
||||
}
|
||||
if data.Params.TxSizeCostPerByte == 0 {
|
||||
return fmt.Errorf("invalid tx size cost per byte: %d", data.Params.TxSizeCostPerByte)
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package types
|
||||
|
||||
import sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
const (
|
||||
// module name
|
||||
ModuleName = "auth"
|
||||
|
||||
// StoreKey is string representation of the store key for auth
|
||||
StoreKey = "acc"
|
||||
|
||||
// FeeStoreKey is a string representation of the store key for fees
|
||||
FeeStoreKey = "fee"
|
||||
|
||||
// QuerierRoute is the querier route for acc
|
||||
QuerierRoute = StoreKey
|
||||
)
|
||||
|
||||
var (
|
||||
// AddressStoreKeyPrefix prefix for account-by-address store
|
||||
AddressStoreKeyPrefix = []byte{0x01}
|
||||
|
||||
// param key for global account number
|
||||
GlobalAccountNumberKey = []byte("globalAccountNumber")
|
||||
)
|
||||
|
||||
// AddressStoreKey turn an address to key used to get it from the account store
|
||||
func AddressStoreKey(addr sdk.AccAddress) []byte {
|
||||
return append(AddressStoreKeyPrefix, addr.Bytes()...)
|
||||
}
|
|
@ -1,11 +1,10 @@
|
|||
package auth
|
||||
package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/params"
|
||||
"github.com/cosmos/cosmos-sdk/x/params/subspace"
|
||||
)
|
||||
|
||||
|
@ -55,8 +54,8 @@ func NewParams(maxMemoCharacters, txSigLimit, txSizeCostPerByte,
|
|||
}
|
||||
|
||||
// ParamKeyTable for auth module
|
||||
func ParamKeyTable() params.KeyTable {
|
||||
return params.NewKeyTable().RegisterParamSet(&Params{})
|
||||
func ParamKeyTable() subspace.KeyTable {
|
||||
return subspace.NewKeyTable().RegisterParamSet(&Params{})
|
||||
}
|
||||
|
||||
// ParamSetPairs implements the ParamSet interface and returns all the key/value pairs
|
||||
|
@ -74,8 +73,8 @@ func (p *Params) ParamSetPairs() subspace.ParamSetPairs {
|
|||
|
||||
// Equal returns a boolean determining if two Params types are identical.
|
||||
func (p Params) Equal(p2 Params) bool {
|
||||
bz1 := moduleCdc.MustMarshalBinaryLengthPrefixed(&p)
|
||||
bz2 := moduleCdc.MustMarshalBinaryLengthPrefixed(&p2)
|
||||
bz1 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&p)
|
||||
bz2 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&p2)
|
||||
return bytes.Equal(bz1, bz2)
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package auth
|
||||
package types
|
||||
|
||||
import (
|
||||
"testing"
|
|
@ -0,0 +1,21 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// query endpoints supported by the auth Querier
|
||||
const (
|
||||
QueryAccount = "account"
|
||||
)
|
||||
|
||||
// defines the params for query: "custom/acc/account"
|
||||
type QueryAccountParams struct {
|
||||
Address sdk.AccAddress
|
||||
}
|
||||
|
||||
func NewQueryAccountParams(addr sdk.AccAddress) QueryAccountParams {
|
||||
return QueryAccountParams{
|
||||
Address: addr,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// StdSignMsg is a convenience structure for passing along
|
||||
// a Msg with the other requirements for a StdSignDoc before
|
||||
// it is signed. For use in the CLI.
|
||||
type StdSignMsg struct {
|
||||
ChainID string `json:"chain_id"`
|
||||
AccountNumber uint64 `json:"account_number"`
|
||||
Sequence uint64 `json:"sequence"`
|
||||
Fee StdFee `json:"fee"`
|
||||
Msgs []sdk.Msg `json:"msgs"`
|
||||
Memo string `json:"memo"`
|
||||
}
|
||||
|
||||
// get message bytes
|
||||
func (msg StdSignMsg) Bytes() []byte {
|
||||
return StdSignBytes(msg.ChainID, msg.AccountNumber, msg.Sequence, msg.Fee, msg.Msgs, msg.Memo)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package auth
|
||||
package types
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
@ -59,8 +59,8 @@ func (tx StdTx) ValidateBasic() sdk.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// countSubKeys counts the total number of keys for a multi-sig public key.
|
||||
func countSubKeys(pub crypto.PubKey) int {
|
||||
// CountSubKeys counts the total number of keys for a multi-sig public key.
|
||||
func CountSubKeys(pub crypto.PubKey) int {
|
||||
v, ok := pub.(multisig.PubKeyMultisigThreshold)
|
||||
if !ok {
|
||||
return 1
|
||||
|
@ -68,7 +68,7 @@ func countSubKeys(pub crypto.PubKey) int {
|
|||
|
||||
numKeys := 0
|
||||
for _, subkey := range v.PubKeys {
|
||||
numKeys += countSubKeys(subkey)
|
||||
numKeys += CountSubKeys(subkey)
|
||||
}
|
||||
|
||||
return numKeys
|
||||
|
@ -133,7 +133,7 @@ func (fee StdFee) Bytes() []byte {
|
|||
if len(fee.Amount) == 0 {
|
||||
fee.Amount = sdk.NewCoins()
|
||||
}
|
||||
bz, err := moduleCdc.MarshalJSON(fee) // TODO
|
||||
bz, err := ModuleCdc.MarshalJSON(fee) // TODO
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, ms
|
|||
for _, msg := range msgs {
|
||||
msgsBytes = append(msgsBytes, json.RawMessage(msg.GetSignBytes()))
|
||||
}
|
||||
bz, err := moduleCdc.MarshalJSON(StdSignDoc{
|
||||
bz, err := ModuleCdc.MarshalJSON(StdSignDoc{
|
||||
AccountNumber: accnum,
|
||||
ChainID: chainID,
|
||||
Fee: json.RawMessage(fee.Bytes()),
|
|
@ -1,4 +1,4 @@
|
|||
package auth
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -21,7 +21,7 @@ var (
|
|||
|
||||
func TestStdTx(t *testing.T) {
|
||||
msgs := []sdk.Msg{sdk.NewTestMsg(addr)}
|
||||
fee := newStdFee()
|
||||
fee := NewTestStdFee()
|
||||
sigs := []StdSignature{}
|
||||
|
||||
tx := NewStdTx(msgs, fee, sigs, "")
|
||||
|
@ -41,7 +41,7 @@ func TestStdSignBytes(t *testing.T) {
|
|||
msgs []sdk.Msg
|
||||
memo string
|
||||
}
|
||||
defaultFee := newStdFee()
|
||||
defaultFee := NewTestStdFee()
|
||||
tests := []struct {
|
||||
args args
|
||||
want string
|
||||
|
@ -61,19 +61,19 @@ func TestTxValidateBasic(t *testing.T) {
|
|||
ctx := sdk.NewContext(nil, abci.Header{ChainID: "mychainid"}, false, log.NewNopLogger())
|
||||
|
||||
// keys and addresses
|
||||
priv1, _, addr1 := keyPubAddr()
|
||||
priv2, _, addr2 := keyPubAddr()
|
||||
priv1, _, addr1 := KeyTestPubAddr()
|
||||
priv2, _, addr2 := KeyTestPubAddr()
|
||||
|
||||
// msg and signatures
|
||||
msg1 := newTestMsg(addr1, addr2)
|
||||
fee := newStdFee()
|
||||
msg1 := NewTestMsg(addr1, addr2)
|
||||
fee := NewTestStdFee()
|
||||
|
||||
msgs := []sdk.Msg{msg1}
|
||||
|
||||
// require to fail validation upon invalid fee
|
||||
badFee := newStdFee()
|
||||
badFee := NewTestStdFee()
|
||||
badFee.Amount[0].Amount = sdk.NewInt(-5)
|
||||
tx := newTestTx(ctx, nil, nil, nil, nil, badFee)
|
||||
tx := NewTestTx(ctx, nil, nil, nil, nil, badFee)
|
||||
|
||||
err := tx.ValidateBasic()
|
||||
require.Error(t, err)
|
||||
|
@ -81,7 +81,7 @@ func TestTxValidateBasic(t *testing.T) {
|
|||
|
||||
// require to fail validation when no signatures exist
|
||||
privs, accNums, seqs := []crypto.PrivKey{}, []uint64{}, []uint64{}
|
||||
tx = newTestTx(ctx, msgs, privs, accNums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accNums, seqs, fee)
|
||||
|
||||
err = tx.ValidateBasic()
|
||||
require.Error(t, err)
|
||||
|
@ -89,16 +89,16 @@ func TestTxValidateBasic(t *testing.T) {
|
|||
|
||||
// require to fail validation when signatures do not match expected signers
|
||||
privs, accNums, seqs = []crypto.PrivKey{priv1}, []uint64{0, 1}, []uint64{0, 0}
|
||||
tx = newTestTx(ctx, msgs, privs, accNums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accNums, seqs, fee)
|
||||
|
||||
err = tx.ValidateBasic()
|
||||
require.Error(t, err)
|
||||
require.Equal(t, sdk.CodeUnauthorized, err.Result().Code)
|
||||
|
||||
// require to fail with invalid gas supplied
|
||||
badFee = newStdFee()
|
||||
badFee = NewTestStdFee()
|
||||
badFee.Gas = 9223372036854775808
|
||||
tx = newTestTx(ctx, nil, nil, nil, nil, badFee)
|
||||
tx = NewTestTx(ctx, nil, nil, nil, nil, badFee)
|
||||
|
||||
err = tx.ValidateBasic()
|
||||
require.Error(t, err)
|
||||
|
@ -106,7 +106,7 @@ func TestTxValidateBasic(t *testing.T) {
|
|||
|
||||
// require to pass when above criteria are matched
|
||||
privs, accNums, seqs = []crypto.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{0, 0}
|
||||
tx = newTestTx(ctx, msgs, privs, accNums, seqs, fee)
|
||||
tx = NewTestTx(ctx, msgs, privs, accNums, seqs, fee)
|
||||
|
||||
err = tx.ValidateBasic()
|
||||
require.NoError(t, err)
|
||||
|
@ -120,7 +120,7 @@ func TestDefaultTxEncoder(t *testing.T) {
|
|||
encoder := DefaultTxEncoder(cdc)
|
||||
|
||||
msgs := []sdk.Msg{sdk.NewTestMsg(addr)}
|
||||
fee := newStdFee()
|
||||
fee := NewTestStdFee()
|
||||
sigs := []StdSignature{}
|
||||
|
||||
tx := NewStdTx(msgs, fee, sigs, "")
|
|
@ -1,5 +1,5 @@
|
|||
// nolint
|
||||
package auth
|
||||
//nolint
|
||||
package types
|
||||
|
||||
import (
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
@ -11,13 +11,13 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/params/subspace"
|
||||
)
|
||||
|
||||
//DONTCOVER
|
||||
|
||||
type testInput struct {
|
||||
cdc *codec.Codec
|
||||
ctx sdk.Context
|
||||
ak AccountKeeper
|
||||
fck FeeCollectionKeeper
|
||||
}
|
||||
|
||||
|
@ -39,41 +39,37 @@ func setupTestInput() testInput {
|
|||
ms.MountStoreWithDB(tkeyParams, sdk.StoreTypeTransient, db)
|
||||
ms.LoadLatestVersion()
|
||||
|
||||
ps := subspace.NewSubspace(cdc, keyParams, tkeyParams, DefaultParamspace)
|
||||
ak := NewAccountKeeper(cdc, authCapKey, ps, ProtoBaseAccount)
|
||||
fck := NewFeeCollectionKeeper(cdc, fckCapKey)
|
||||
ctx := sdk.NewContext(ms, abci.Header{ChainID: "test-chain-id"}, false, log.NewNopLogger())
|
||||
|
||||
ak.SetParams(ctx, DefaultParams())
|
||||
|
||||
return testInput{cdc: cdc, ctx: ctx, ak: ak, fck: fck}
|
||||
return testInput{cdc: cdc, ctx: ctx, fck: fck}
|
||||
}
|
||||
|
||||
func newTestMsg(addrs ...sdk.AccAddress) *sdk.TestMsg {
|
||||
func NewTestMsg(addrs ...sdk.AccAddress) *sdk.TestMsg {
|
||||
return sdk.NewTestMsg(addrs...)
|
||||
}
|
||||
|
||||
func newStdFee() StdFee {
|
||||
func NewTestStdFee() StdFee {
|
||||
return NewStdFee(50000,
|
||||
sdk.NewCoins(sdk.NewInt64Coin("atom", 150)),
|
||||
)
|
||||
}
|
||||
|
||||
// coins to more than cover the fee
|
||||
func newCoins() sdk.Coins {
|
||||
func NewTestCoins() sdk.Coins {
|
||||
return sdk.Coins{
|
||||
sdk.NewInt64Coin("atom", 10000000),
|
||||
}
|
||||
}
|
||||
|
||||
func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) {
|
||||
func KeyTestPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) {
|
||||
key := secp256k1.GenPrivKey()
|
||||
pub := key.PubKey()
|
||||
addr := sdk.AccAddress(pub.Address())
|
||||
return key, pub, addr
|
||||
}
|
||||
|
||||
func newTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee) sdk.Tx {
|
||||
func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee) sdk.Tx {
|
||||
sigs := make([]StdSignature, len(privs))
|
||||
for i, priv := range privs {
|
||||
signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, "")
|
||||
|
@ -90,7 +86,7 @@ func newTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums
|
|||
return tx
|
||||
}
|
||||
|
||||
func newTestTxWithMemo(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, memo string) sdk.Tx {
|
||||
func NewTestTxWithMemo(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, memo string) sdk.Tx {
|
||||
sigs := make([]StdSignature, len(privs))
|
||||
for i, priv := range privs {
|
||||
signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, memo)
|
||||
|
@ -107,7 +103,7 @@ func newTestTxWithMemo(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey,
|
|||
return tx
|
||||
}
|
||||
|
||||
func newTestTxWithSignBytes(msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, signBytes []byte, memo string) sdk.Tx {
|
||||
func NewTestTxWithSignBytes(msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, signBytes []byte, memo string) sdk.Tx {
|
||||
sigs := make([]StdSignature, len(privs))
|
||||
for i, priv := range privs {
|
||||
sig, err := priv.Sign(signBytes)
|
|
@ -1,4 +1,4 @@
|
|||
package context
|
||||
package types
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@ -11,7 +11,6 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
crkeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
)
|
||||
|
||||
// TxBuilder implements a transaction context created in SDK modules.
|
||||
|
@ -203,7 +202,7 @@ func (bldr TxBuilder) BuildSignMsg(msgs []sdk.Msg) (StdSignMsg, error) {
|
|||
Sequence: bldr.sequence,
|
||||
Memo: bldr.memo,
|
||||
Msgs: msgs,
|
||||
Fee: auth.NewStdFee(bldr.gas, fees),
|
||||
Fee: NewStdFee(bldr.gas, fees),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -215,7 +214,7 @@ func (bldr TxBuilder) Sign(name, passphrase string, msg StdSignMsg) ([]byte, err
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return bldr.txEncoder(auth.NewStdTx(msg.Msgs, msg.Fee, []auth.StdSignature{sig}, msg.Memo))
|
||||
return bldr.txEncoder(NewStdTx(msg.Msgs, msg.Fee, []StdSignature{sig}, msg.Memo))
|
||||
}
|
||||
|
||||
// BuildAndSign builds a single message to be signed, and signs a transaction
|
||||
|
@ -238,15 +237,15 @@ func (bldr TxBuilder) BuildTxForSim(msgs []sdk.Msg) ([]byte, error) {
|
|||
}
|
||||
|
||||
// the ante handler will populate with a sentinel pubkey
|
||||
sigs := []auth.StdSignature{{}}
|
||||
return bldr.txEncoder(auth.NewStdTx(signMsg.Msgs, signMsg.Fee, sigs, signMsg.Memo))
|
||||
sigs := []StdSignature{{}}
|
||||
return bldr.txEncoder(NewStdTx(signMsg.Msgs, signMsg.Fee, sigs, signMsg.Memo))
|
||||
}
|
||||
|
||||
// SignStdTx appends a signature to a StdTx and returns a copy of it. If append
|
||||
// is false, it replaces the signatures already attached with the new signature.
|
||||
func (bldr TxBuilder) SignStdTx(name, passphrase string, stdTx auth.StdTx, appendSig bool) (signedStdTx auth.StdTx, err error) {
|
||||
func (bldr TxBuilder) SignStdTx(name, passphrase string, stdTx StdTx, appendSig bool) (signedStdTx StdTx, err error) {
|
||||
if bldr.chainID == "" {
|
||||
return auth.StdTx{}, fmt.Errorf("chain ID required but not specified")
|
||||
return StdTx{}, fmt.Errorf("chain ID required but not specified")
|
||||
}
|
||||
|
||||
stdSignature, err := MakeSignature(bldr.keybase, name, passphrase, StdSignMsg{
|
||||
|
@ -263,17 +262,17 @@ func (bldr TxBuilder) SignStdTx(name, passphrase string, stdTx auth.StdTx, appen
|
|||
|
||||
sigs := stdTx.GetSignatures()
|
||||
if len(sigs) == 0 || !appendSig {
|
||||
sigs = []auth.StdSignature{stdSignature}
|
||||
sigs = []StdSignature{stdSignature}
|
||||
} else {
|
||||
sigs = append(sigs, stdSignature)
|
||||
}
|
||||
signedStdTx = auth.NewStdTx(stdTx.GetMsgs(), stdTx.Fee, sigs, stdTx.GetMemo())
|
||||
signedStdTx = NewStdTx(stdTx.GetMsgs(), stdTx.Fee, sigs, stdTx.GetMemo())
|
||||
return
|
||||
}
|
||||
|
||||
// MakeSignature builds a StdSignature given keybase, key name, passphrase, and a StdSignMsg.
|
||||
func MakeSignature(keybase crkeys.Keybase, name, passphrase string,
|
||||
msg StdSignMsg) (sig auth.StdSignature, err error) {
|
||||
msg StdSignMsg) (sig StdSignature, err error) {
|
||||
if keybase == nil {
|
||||
keybase, err = keys.NewKeyBaseFromHomeFlag()
|
||||
if err != nil {
|
||||
|
@ -285,7 +284,7 @@ func MakeSignature(keybase crkeys.Keybase, name, passphrase string,
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
return auth.StdSignature{
|
||||
return StdSignature{
|
||||
PubKey: pubkey,
|
||||
Signature: sigBytes,
|
||||
}, nil
|
|
@ -1,4 +1,4 @@
|
|||
package context
|
||||
package types
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
@ -6,16 +6,8 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
)
|
||||
|
||||
var (
|
||||
priv = ed25519.GenPrivKey()
|
||||
addr = sdk.AccAddress(priv.PubKey().Address())
|
||||
)
|
||||
|
||||
func TestTxBuilderBuild(t *testing.T) {
|
||||
|
@ -42,7 +34,7 @@ func TestTxBuilderBuild(t *testing.T) {
|
|||
{
|
||||
"builder with fees",
|
||||
fields{
|
||||
TxEncoder: auth.DefaultTxEncoder(codec.New()),
|
||||
TxEncoder: DefaultTxEncoder(codec.New()),
|
||||
AccountNumber: 1,
|
||||
Sequence: 1,
|
||||
Gas: 200000,
|
||||
|
@ -59,14 +51,14 @@ func TestTxBuilderBuild(t *testing.T) {
|
|||
Sequence: 1,
|
||||
Memo: "hello from Voyager 1!",
|
||||
Msgs: defaultMsg,
|
||||
Fee: auth.NewStdFee(200000, sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1))}),
|
||||
Fee: NewStdFee(200000, sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1))}),
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"builder with gas prices",
|
||||
fields{
|
||||
TxEncoder: auth.DefaultTxEncoder(codec.New()),
|
||||
TxEncoder: DefaultTxEncoder(codec.New()),
|
||||
AccountNumber: 1,
|
||||
Sequence: 1,
|
||||
Gas: 200000,
|
||||
|
@ -83,14 +75,14 @@ func TestTxBuilderBuild(t *testing.T) {
|
|||
Sequence: 1,
|
||||
Memo: "hello from Voyager 2!",
|
||||
Msgs: defaultMsg,
|
||||
Fee: auth.NewStdFee(200000, sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1))}),
|
||||
Fee: NewStdFee(200000, sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1))}),
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"no chain-id supplied",
|
||||
fields{
|
||||
TxEncoder: auth.DefaultTxEncoder(codec.New()),
|
||||
TxEncoder: DefaultTxEncoder(codec.New()),
|
||||
AccountNumber: 1,
|
||||
Sequence: 1,
|
||||
Gas: 200000,
|
||||
|
@ -107,14 +99,14 @@ func TestTxBuilderBuild(t *testing.T) {
|
|||
Sequence: 1,
|
||||
Memo: "hello from Voyager 1!",
|
||||
Msgs: defaultMsg,
|
||||
Fee: auth.NewStdFee(200000, sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1))}),
|
||||
Fee: NewStdFee(200000, sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1))}),
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"builder w/ fees and gas prices",
|
||||
fields{
|
||||
TxEncoder: auth.DefaultTxEncoder(codec.New()),
|
||||
TxEncoder: DefaultTxEncoder(codec.New()),
|
||||
AccountNumber: 1,
|
||||
Sequence: 1,
|
||||
Gas: 200000,
|
||||
|
@ -132,7 +124,7 @@ func TestTxBuilderBuild(t *testing.T) {
|
|||
Sequence: 1,
|
||||
Memo: "hello from Voyager 1!",
|
||||
Msgs: defaultMsg,
|
||||
Fee: auth.NewStdFee(200000, sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1))}),
|
||||
Fee: NewStdFee(200000, sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1))}),
|
||||
},
|
||||
true,
|
||||
},
|
|
@ -0,0 +1,45 @@
|
|||
// nolint
|
||||
// autogenerated code using github.com/rigelrozanski/multitool
|
||||
// aliases generated for the following subdirectories:
|
||||
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/bank/types
|
||||
package bank
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultCodespace = types.DefaultCodespace
|
||||
CodeSendDisabled = types.CodeSendDisabled
|
||||
CodeInvalidInputsOutputs = types.CodeInvalidInputsOutputs
|
||||
ModuleName = types.ModuleName
|
||||
RouterKey = types.RouterKey
|
||||
DefaultParamspace = types.DefaultParamspace
|
||||
DefaultSendEnabled = types.DefaultSendEnabled
|
||||
)
|
||||
|
||||
var (
|
||||
// functions aliases
|
||||
RegisterCodec = types.RegisterCodec
|
||||
ErrNoInputs = types.ErrNoInputs
|
||||
ErrNoOutputs = types.ErrNoOutputs
|
||||
ErrInputOutputMismatch = types.ErrInputOutputMismatch
|
||||
ErrSendDisabled = types.ErrSendDisabled
|
||||
NewMsgSend = types.NewMsgSend
|
||||
NewMsgMultiSend = types.NewMsgMultiSend
|
||||
NewInput = types.NewInput
|
||||
NewOutput = types.NewOutput
|
||||
ValidateInputsOutputs = types.ValidateInputsOutputs
|
||||
ParamKeyTable = types.ParamKeyTable
|
||||
|
||||
// variable aliases
|
||||
ModuleCdc = types.ModuleCdc
|
||||
ParamStoreKeySendEnabled = types.ParamStoreKeySendEnabled
|
||||
)
|
||||
|
||||
type (
|
||||
MsgSend = types.MsgSend
|
||||
MsgMultiSend = types.MsgMultiSend
|
||||
Input = types.Input
|
||||
Output = types.Output
|
||||
)
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/mock"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -45,43 +46,43 @@ var (
|
|||
manyCoins = sdk.Coins{sdk.NewInt64Coin("foocoin", 1), sdk.NewInt64Coin("barcoin", 1)}
|
||||
freeFee = auth.NewStdFee(100000, sdk.Coins{sdk.NewInt64Coin("foocoin", 0)})
|
||||
|
||||
sendMsg1 = NewMsgSend(addr1, addr2, coins)
|
||||
sendMsg1 = types.NewMsgSend(addr1, addr2, coins)
|
||||
|
||||
multiSendMsg1 = MsgMultiSend{
|
||||
Inputs: []Input{NewInput(addr1, coins)},
|
||||
Outputs: []Output{NewOutput(addr2, coins)},
|
||||
multiSendMsg1 = types.MsgMultiSend{
|
||||
Inputs: []types.Input{types.NewInput(addr1, coins)},
|
||||
Outputs: []types.Output{types.NewOutput(addr2, coins)},
|
||||
}
|
||||
multiSendMsg2 = MsgMultiSend{
|
||||
Inputs: []Input{NewInput(addr1, coins)},
|
||||
Outputs: []Output{
|
||||
NewOutput(addr2, halfCoins),
|
||||
NewOutput(addr3, halfCoins),
|
||||
multiSendMsg2 = types.MsgMultiSend{
|
||||
Inputs: []types.Input{types.NewInput(addr1, coins)},
|
||||
Outputs: []types.Output{
|
||||
types.NewOutput(addr2, halfCoins),
|
||||
types.NewOutput(addr3, halfCoins),
|
||||
},
|
||||
}
|
||||
multiSendMsg3 = MsgMultiSend{
|
||||
Inputs: []Input{
|
||||
NewInput(addr1, coins),
|
||||
NewInput(addr4, coins),
|
||||
multiSendMsg3 = types.MsgMultiSend{
|
||||
Inputs: []types.Input{
|
||||
types.NewInput(addr1, coins),
|
||||
types.NewInput(addr4, coins),
|
||||
},
|
||||
Outputs: []Output{
|
||||
NewOutput(addr2, coins),
|
||||
NewOutput(addr3, coins),
|
||||
Outputs: []types.Output{
|
||||
types.NewOutput(addr2, coins),
|
||||
types.NewOutput(addr3, coins),
|
||||
},
|
||||
}
|
||||
multiSendMsg4 = MsgMultiSend{
|
||||
Inputs: []Input{
|
||||
NewInput(addr2, coins),
|
||||
multiSendMsg4 = types.MsgMultiSend{
|
||||
Inputs: []types.Input{
|
||||
types.NewInput(addr2, coins),
|
||||
},
|
||||
Outputs: []Output{
|
||||
NewOutput(addr1, coins),
|
||||
Outputs: []types.Output{
|
||||
types.NewOutput(addr1, coins),
|
||||
},
|
||||
}
|
||||
multiSendMsg5 = MsgMultiSend{
|
||||
Inputs: []Input{
|
||||
NewInput(addr1, manyCoins),
|
||||
multiSendMsg5 = types.MsgMultiSend{
|
||||
Inputs: []types.Input{
|
||||
types.NewInput(addr1, manyCoins),
|
||||
},
|
||||
Outputs: []Output{
|
||||
NewOutput(addr2, manyCoins),
|
||||
Outputs: []types.Output{
|
||||
types.NewOutput(addr2, manyCoins),
|
||||
},
|
||||
}
|
||||
)
|
||||
|
@ -122,7 +123,7 @@ func TestSendNotEnoughBalance(t *testing.T) {
|
|||
origAccNum := res1.GetAccountNumber()
|
||||
origSeq := res1.GetSequence()
|
||||
|
||||
sendMsg := NewMsgSend(addr1, addr2, sdk.Coins{sdk.NewInt64Coin("foocoin", 100)})
|
||||
sendMsg := types.NewMsgSend(addr1, addr2, sdk.Coins{sdk.NewInt64Coin("foocoin", 100)})
|
||||
header := abci.Header{Height: mapp.LastBlockHeight() + 1}
|
||||
mock.SignCheckDeliver(t, mapp.Cdc, mapp.BaseApp, header, []sdk.Msg{sendMsg}, []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1)
|
||||
|
||||
|
|
|
@ -3,11 +3,12 @@ package bank
|
|||
import (
|
||||
"testing"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/mock"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
// getBenchmarkMockApp initializes a mock application for this module, for purposes of benchmarking
|
||||
|
@ -15,13 +16,13 @@ import (
|
|||
func getBenchmarkMockApp() (*mock.App, error) {
|
||||
mapp := mock.NewApp()
|
||||
|
||||
RegisterCodec(mapp.Cdc)
|
||||
types.RegisterCodec(mapp.Cdc)
|
||||
bankKeeper := NewBaseKeeper(
|
||||
mapp.AccountKeeper,
|
||||
mapp.ParamsKeeper.Subspace(DefaultParamspace),
|
||||
DefaultCodespace,
|
||||
mapp.ParamsKeeper.Subspace(types.DefaultParamspace),
|
||||
types.DefaultCodespace,
|
||||
)
|
||||
mapp.Router().AddRoute(RouterKey, NewHandler(bankKeeper))
|
||||
mapp.Router().AddRoute(types.RouterKey, NewHandler(bankKeeper))
|
||||
mapp.SetInitChainer(getInitChainer(mapp, bankKeeper))
|
||||
|
||||
err := mapp.CompleteSetup()
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
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"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
auth "github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -17,6 +17,21 @@ const (
|
|||
flagAmount = "amount"
|
||||
)
|
||||
|
||||
// GetTxCmd returns the transaction commands for this module
|
||||
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||
txCmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "Bank transaction subcommands",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: utils.ValidateCmd,
|
||||
}
|
||||
txCmd.AddCommand(
|
||||
SendTxCmd(cdc),
|
||||
)
|
||||
return txCmd
|
||||
}
|
||||
|
||||
// SendTxCmd will create a send tx and sign it with the given key.
|
||||
func SendTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
|
@ -24,7 +39,7 @@ func SendTxCmd(cdc *codec.Codec) *cobra.Command {
|
|||
Short: "Create and sign a send tx",
|
||||
Args: cobra.ExactArgs(3),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
||||
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
||||
cliCtx := context.NewCLIContextWithFrom(args[0]).
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(cdc)
|
||||
|
@ -41,7 +56,7 @@ func SendTxCmd(cdc *codec.Codec) *cobra.Command {
|
|||
}
|
||||
|
||||
// build and sign the transaction, then broadcast to Tendermint
|
||||
msg := bank.NewMsgSend(cliCtx.GetFromAddress(), to, coins)
|
||||
msg := types.NewMsgSend(cliCtx.GetFromAddress(), to, coins)
|
||||
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
||||
},
|
||||
}
|
|
@ -8,16 +8,15 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
|
||||
// RegisterRoutes - Central function to define routes that get registered by the main application
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) {
|
||||
r.HandleFunc("/bank/accounts/{address}/transfers", SendRequestHandlerFn(cdc, kb, cliCtx)).Methods("POST")
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
|
||||
r.HandleFunc("/bank/accounts/{address}/transfers", SendRequestHandlerFn(cdc, cliCtx)).Methods("POST")
|
||||
}
|
||||
|
||||
// SendReq defines the properties of a send request's body.
|
||||
|
@ -29,11 +28,11 @@ type SendReq struct {
|
|||
var moduleCdc = codec.New()
|
||||
|
||||
func init() {
|
||||
bank.RegisterCodec(moduleCdc)
|
||||
types.RegisterCodec(moduleCdc)
|
||||
}
|
||||
|
||||
// SendRequestHandlerFn - http request handler to send coins to a address.
|
||||
func SendRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
func SendRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
bech32Addr := vars["address"]
|
||||
|
@ -60,7 +59,7 @@ func SendRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIC
|
|||
return
|
||||
}
|
||||
|
||||
msg := bank.NewMsgSend(fromAddr, toAddr, req.Amount)
|
||||
msg := types.NewMsgSend(fromAddr, toAddr, req.Amount)
|
||||
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
|
||||
}
|
||||
}
|
|
@ -5,16 +5,17 @@ import (
|
|||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/tags"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
|
||||
// NewHandler returns a handler for "bank" type messages.
|
||||
func NewHandler(k Keeper) sdk.Handler {
|
||||
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
|
||||
switch msg := msg.(type) {
|
||||
case MsgSend:
|
||||
case types.MsgSend:
|
||||
return handleMsgSend(ctx, k, msg)
|
||||
|
||||
case MsgMultiSend:
|
||||
case types.MsgMultiSend:
|
||||
return handleMsgMultiSend(ctx, k, msg)
|
||||
|
||||
default:
|
||||
|
@ -25,9 +26,9 @@ func NewHandler(k Keeper) sdk.Handler {
|
|||
}
|
||||
|
||||
// Handle MsgSend.
|
||||
func handleMsgSend(ctx sdk.Context, k Keeper, msg MsgSend) sdk.Result {
|
||||
func handleMsgSend(ctx sdk.Context, k Keeper, msg types.MsgSend) sdk.Result {
|
||||
if !k.GetSendEnabled(ctx) {
|
||||
return ErrSendDisabled(k.Codespace()).Result()
|
||||
return types.ErrSendDisabled(k.Codespace()).Result()
|
||||
}
|
||||
err := k.SendCoins(ctx, msg.FromAddress, msg.ToAddress, msg.Amount)
|
||||
if err != nil {
|
||||
|
@ -46,10 +47,10 @@ func handleMsgSend(ctx sdk.Context, k Keeper, msg MsgSend) sdk.Result {
|
|||
}
|
||||
|
||||
// Handle MsgMultiSend.
|
||||
func handleMsgMultiSend(ctx sdk.Context, k Keeper, msg MsgMultiSend) sdk.Result {
|
||||
func handleMsgMultiSend(ctx sdk.Context, k Keeper, msg types.MsgMultiSend) sdk.Result {
|
||||
// NOTE: totalIn == totalOut should already have been checked
|
||||
if !k.GetSendEnabled(ctx) {
|
||||
return ErrSendDisabled(k.Codespace()).Result()
|
||||
return types.ErrSendDisabled(k.Codespace()).Result()
|
||||
}
|
||||
resTags, err := k.InputOutputCoins(ctx, msg.Inputs, msg.Outputs)
|
||||
if err != nil {
|
||||
|
|
|
@ -6,11 +6,12 @@ import (
|
|||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
|
||||
// register bank invariants
|
||||
func RegisterInvariants(ir sdk.InvariantRouter, ak auth.AccountKeeper) {
|
||||
ir.RegisterRoute(RouterKey, "nonnegative-outstanding",
|
||||
ir.RegisterRoute(types.ModuleName, "nonnegative-outstanding",
|
||||
NonnegativeBalanceInvariant(ak))
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/tags"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/params"
|
||||
)
|
||||
|
||||
|
@ -20,7 +21,7 @@ type Keeper interface {
|
|||
SetCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) sdk.Error
|
||||
SubtractCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, sdk.Error)
|
||||
AddCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, sdk.Error)
|
||||
InputOutputCoins(ctx sdk.Context, inputs []Input, outputs []Output) (sdk.Tags, sdk.Error)
|
||||
InputOutputCoins(ctx sdk.Context, inputs []types.Input, outputs []types.Output) (sdk.Tags, sdk.Error)
|
||||
|
||||
DelegateCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Tags, sdk.Error)
|
||||
UndelegateCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Tags, sdk.Error)
|
||||
|
@ -39,7 +40,7 @@ func NewBaseKeeper(ak auth.AccountKeeper,
|
|||
paramSpace params.Subspace,
|
||||
codespace sdk.CodespaceType) BaseKeeper {
|
||||
|
||||
ps := paramSpace.WithKeyTable(ParamKeyTable())
|
||||
ps := paramSpace.WithKeyTable(types.ParamKeyTable())
|
||||
return BaseKeeper{
|
||||
BaseSendKeeper: NewBaseSendKeeper(ak, ps, codespace),
|
||||
ak: ak,
|
||||
|
@ -82,7 +83,7 @@ func (keeper BaseKeeper) AddCoins(
|
|||
|
||||
// InputOutputCoins handles a list of inputs and outputs
|
||||
func (keeper BaseKeeper) InputOutputCoins(
|
||||
ctx sdk.Context, inputs []Input, outputs []Output,
|
||||
ctx sdk.Context, inputs []types.Input, outputs []types.Output,
|
||||
) (sdk.Tags, sdk.Error) {
|
||||
|
||||
return inputOutputCoins(ctx, keeper.ak, inputs, outputs)
|
||||
|
@ -163,13 +164,13 @@ func (keeper BaseSendKeeper) SendCoins(
|
|||
// nolint: errcheck
|
||||
func (keeper BaseSendKeeper) GetSendEnabled(ctx sdk.Context) bool {
|
||||
var enabled bool
|
||||
keeper.paramSpace.Get(ctx, ParamStoreKeySendEnabled, &enabled)
|
||||
keeper.paramSpace.Get(ctx, types.ParamStoreKeySendEnabled, &enabled)
|
||||
return enabled
|
||||
}
|
||||
|
||||
// SetSendEnabled sets the send enabled
|
||||
func (keeper BaseSendKeeper) SetSendEnabled(ctx sdk.Context, enabled bool) {
|
||||
keeper.paramSpace.Set(ctx, ParamStoreKeySendEnabled, &enabled)
|
||||
keeper.paramSpace.Set(ctx, types.ParamStoreKeySendEnabled, &enabled)
|
||||
}
|
||||
|
||||
var _ ViewKeeper = (*BaseViewKeeper)(nil)
|
||||
|
@ -323,10 +324,10 @@ func sendCoins(ctx sdk.Context, am auth.AccountKeeper, fromAddr sdk.AccAddress,
|
|||
|
||||
// InputOutputCoins handles a list of inputs and outputs
|
||||
// NOTE: Make sure to revert state changes from tx on error
|
||||
func inputOutputCoins(ctx sdk.Context, am auth.AccountKeeper, inputs []Input, outputs []Output) (sdk.Tags, sdk.Error) {
|
||||
func inputOutputCoins(ctx sdk.Context, am auth.AccountKeeper, inputs []types.Input, outputs []types.Output) (sdk.Tags, sdk.Error) {
|
||||
// Safety check ensuring that when sending coins the keeper must maintain the
|
||||
// Check supply invariant and validity of Coins.
|
||||
if err := ValidateInputsOutputs(inputs, outputs); err != nil {
|
||||
if err := types.ValidateInputsOutputs(inputs, outputs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/store"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/params"
|
||||
)
|
||||
|
||||
|
@ -56,7 +57,7 @@ func setupTestInput() testInput {
|
|||
func TestKeeper(t *testing.T) {
|
||||
input := setupTestInput()
|
||||
ctx := input.ctx
|
||||
bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(DefaultParamspace), DefaultCodespace)
|
||||
bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(types.DefaultParamspace), types.DefaultCodespace)
|
||||
bankKeeper.SetSendEnabled(ctx, true)
|
||||
|
||||
addr := sdk.AccAddress([]byte("addr1"))
|
||||
|
@ -112,18 +113,18 @@ func TestKeeper(t *testing.T) {
|
|||
require.True(t, bankKeeper.GetCoins(ctx, addr2).IsEqual(sdk.NewCoins(sdk.NewInt64Coin("barcoin", 10), sdk.NewInt64Coin("foocoin", 10))))
|
||||
|
||||
// Test InputOutputCoins
|
||||
input1 := NewInput(addr2, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 2)))
|
||||
output1 := NewOutput(addr, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 2)))
|
||||
bankKeeper.InputOutputCoins(ctx, []Input{input1}, []Output{output1})
|
||||
input1 := types.NewInput(addr2, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 2)))
|
||||
output1 := types.NewOutput(addr, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 2)))
|
||||
bankKeeper.InputOutputCoins(ctx, []types.Input{input1}, []types.Output{output1})
|
||||
require.True(t, bankKeeper.GetCoins(ctx, addr).IsEqual(sdk.NewCoins(sdk.NewInt64Coin("barcoin", 20), sdk.NewInt64Coin("foocoin", 7))))
|
||||
require.True(t, bankKeeper.GetCoins(ctx, addr2).IsEqual(sdk.NewCoins(sdk.NewInt64Coin("barcoin", 10), sdk.NewInt64Coin("foocoin", 8))))
|
||||
|
||||
inputs := []Input{
|
||||
inputs := []types.Input{
|
||||
NewInput(addr, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 3))),
|
||||
NewInput(addr2, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 3), sdk.NewInt64Coin("foocoin", 2))),
|
||||
types.NewInput(addr2, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 3), sdk.NewInt64Coin("foocoin", 2))),
|
||||
}
|
||||
|
||||
outputs := []Output{
|
||||
outputs := []types.Output{
|
||||
NewOutput(addr, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 1))),
|
||||
NewOutput(addr3, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 2), sdk.NewInt64Coin("foocoin", 5))),
|
||||
}
|
||||
|
@ -136,8 +137,8 @@ func TestKeeper(t *testing.T) {
|
|||
func TestSendKeeper(t *testing.T) {
|
||||
input := setupTestInput()
|
||||
ctx := input.ctx
|
||||
paramSpace := input.pk.Subspace(DefaultParamspace)
|
||||
bankKeeper := NewBaseKeeper(input.ak, paramSpace, DefaultCodespace)
|
||||
paramSpace := input.pk.Subspace(types.DefaultParamspace)
|
||||
bankKeeper := NewBaseKeeper(input.ak, paramSpace, types.DefaultCodespace)
|
||||
sendKeeper := NewBaseSendKeeper(input.ak, paramSpace, DefaultCodespace)
|
||||
bankKeeper.SetSendEnabled(ctx, true)
|
||||
|
||||
|
|
|
@ -3,50 +3,69 @@ package bank
|
|||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"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/types/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/client/rest"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
|
||||
var (
|
||||
_ sdk.AppModule = AppModule{}
|
||||
_ sdk.AppModuleBasic = AppModuleBasic{}
|
||||
_ module.AppModule = AppModule{}
|
||||
_ module.AppModuleBasic = AppModuleBasic{}
|
||||
)
|
||||
|
||||
// name of this module
|
||||
const ModuleName = "bank"
|
||||
|
||||
// app module basics object
|
||||
type AppModuleBasic struct{}
|
||||
|
||||
var _ sdk.AppModuleBasic = AppModuleBasic{}
|
||||
var _ module.AppModuleBasic = AppModuleBasic{}
|
||||
|
||||
// module name
|
||||
func (AppModuleBasic) Name() string {
|
||||
return ModuleName
|
||||
return types.ModuleName
|
||||
}
|
||||
|
||||
// register module codec
|
||||
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
|
||||
RegisterCodec(cdc)
|
||||
types.RegisterCodec(cdc)
|
||||
}
|
||||
|
||||
// default genesis state
|
||||
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
|
||||
return moduleCdc.MustMarshalJSON(DefaultGenesisState())
|
||||
return types.ModuleCdc.MustMarshalJSON(DefaultGenesisState())
|
||||
}
|
||||
|
||||
// module validate genesis
|
||||
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
|
||||
var data GenesisState
|
||||
err := moduleCdc.UnmarshalJSON(bz, &data)
|
||||
err := types.ModuleCdc.UnmarshalJSON(bz, &data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ValidateGenesis(data)
|
||||
}
|
||||
|
||||
// register rest routes
|
||||
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {
|
||||
rest.RegisterRoutes(ctx, rtr, cdc)
|
||||
}
|
||||
|
||||
// get the root tx command of this module
|
||||
func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||
return cli.GetTxCmd(cdc)
|
||||
}
|
||||
|
||||
// get the root query command of this module
|
||||
func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil }
|
||||
|
||||
//___________________________
|
||||
// app module
|
||||
type AppModule struct {
|
||||
|
@ -66,7 +85,7 @@ func NewAppModule(keeper Keeper, accountKeeper auth.AccountKeeper) AppModule {
|
|||
|
||||
// module name
|
||||
func (AppModule) Name() string {
|
||||
return ModuleName
|
||||
return types.ModuleName
|
||||
}
|
||||
|
||||
// register invariants
|
||||
|
@ -76,7 +95,7 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRouter) {
|
|||
|
||||
// module message route name
|
||||
func (AppModule) Route() string {
|
||||
return RouterKey
|
||||
return types.RouterKey
|
||||
}
|
||||
|
||||
// module handler
|
||||
|
@ -93,7 +112,7 @@ func (AppModule) NewQuerierHandler() sdk.Querier { return nil }
|
|||
// module init-genesis
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
|
||||
var genesisState GenesisState
|
||||
moduleCdc.MustUnmarshalJSON(data, &genesisState)
|
||||
types.ModuleCdc.MustUnmarshalJSON(data, &genesisState)
|
||||
InitGenesis(ctx, am.keeper, genesisState)
|
||||
return []abci.ValidatorUpdate{}
|
||||
}
|
||||
|
@ -101,7 +120,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.Va
|
|||
// module export genesis
|
||||
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
|
||||
gs := ExportGenesis(ctx, am.keeper)
|
||||
return moduleCdc.MustMarshalJSON(gs)
|
||||
return types.ModuleCdc.MustMarshalJSON(gs)
|
||||
}
|
||||
|
||||
// module begin-block
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package bank
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
|
@ -10,8 +10,11 @@ func RegisterCodec(cdc *codec.Codec) {
|
|||
cdc.RegisterConcrete(MsgMultiSend{}, "cosmos-sdk/MsgMultiSend", nil)
|
||||
}
|
||||
|
||||
var moduleCdc = codec.New()
|
||||
// module codec
|
||||
var ModuleCdc *codec.Codec
|
||||
|
||||
func init() {
|
||||
RegisterCodec(moduleCdc)
|
||||
ModuleCdc = codec.New()
|
||||
RegisterCodec(ModuleCdc)
|
||||
ModuleCdc.Seal()
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package bank
|
||||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
@ -0,0 +1,6 @@
|
|||
package types
|
||||
|
||||
const (
|
||||
// module name
|
||||
ModuleName = "bank"
|
||||
)
|
|
@ -1,4 +1,4 @@
|
|||
package bank
|
||||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
@ -46,7 +46,7 @@ func (msg MsgSend) ValidateBasic() sdk.Error {
|
|||
|
||||
// GetSignBytes Implements Msg.
|
||||
func (msg MsgSend) GetSignBytes() []byte {
|
||||
return sdk.MustSortJSON(moduleCdc.MustMarshalJSON(msg))
|
||||
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
|
||||
}
|
||||
|
||||
// GetSigners Implements Msg.
|
||||
|
@ -89,7 +89,7 @@ func (msg MsgMultiSend) ValidateBasic() sdk.Error {
|
|||
|
||||
// GetSignBytes Implements Msg.
|
||||
func (msg MsgMultiSend) GetSignBytes() []byte {
|
||||
return sdk.MustSortJSON(moduleCdc.MustMarshalJSON(msg))
|
||||
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
|
||||
}
|
||||
|
||||
// GetSigners Implements Msg.
|
|
@ -1,4 +1,4 @@
|
|||
package bank
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package bank
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/x/params"
|
|
@ -0,0 +1,38 @@
|
|||
// nolint
|
||||
// autogenerated code using github.com/rigelrozanski/multitool
|
||||
// aliases generated for the following subdirectories:
|
||||
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/crisis/types
|
||||
package crisis
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis/types"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultCodespace = types.DefaultCodespace
|
||||
CodeInvalidInput = types.CodeInvalidInput
|
||||
ModuleName = types.ModuleName
|
||||
DefaultParamspace = types.DefaultParamspace
|
||||
)
|
||||
|
||||
var (
|
||||
// functions aliases
|
||||
RegisterCodec = types.RegisterCodec
|
||||
ErrNilSender = types.ErrNilSender
|
||||
ErrUnknownInvariant = types.ErrUnknownInvariant
|
||||
NewGenesisState = types.NewGenesisState
|
||||
DefaultGenesisState = types.DefaultGenesisState
|
||||
NewMsgVerifyInvariant = types.NewMsgVerifyInvariant
|
||||
ParamKeyTable = types.ParamKeyTable
|
||||
NewInvarRoute = types.NewInvarRoute
|
||||
|
||||
// variable aliases
|
||||
ModuleCdc = types.ModuleCdc
|
||||
ParamStoreKeyConstantFee = types.ParamStoreKeyConstantFee
|
||||
)
|
||||
|
||||
type (
|
||||
GenesisState = types.GenesisState
|
||||
MsgVerifyInvariant = types.MsgVerifyInvariant
|
||||
InvarRoute = types.InvarRoute
|
||||
)
|
|
@ -4,12 +4,13 @@ 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"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis"
|
||||
auth "github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis/types"
|
||||
)
|
||||
|
||||
// command to replace a delegator's withdrawal address
|
||||
|
@ -20,14 +21,30 @@ func GetCmdInvariantBroken(cdc *codec.Codec) *cobra.Command {
|
|||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
||||
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)
|
||||
|
||||
senderAddr := cliCtx.GetFromAddress()
|
||||
moduleName, route := args[0], args[1]
|
||||
msg := crisis.NewMsgVerifyInvariant(senderAddr, moduleName, route)
|
||||
msg := types.NewMsgVerifyInvariant(senderAddr, moduleName, route)
|
||||
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetTxCmd returns the transaction commands for this module
|
||||
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||
txCmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "Crisis transactions subcommands",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: utils.ValidateCmd,
|
||||
}
|
||||
|
||||
txCmd.AddCommand(client.PostCommands(
|
||||
GetCmdInvariantBroken(cdc),
|
||||
)...)
|
||||
return txCmd
|
||||
}
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis/client/cli"
|
||||
)
|
||||
|
||||
// ModuleClient exports all client functionality from this module
|
||||
type ModuleClient struct {
|
||||
storeKey string
|
||||
cdc *amino.Codec
|
||||
}
|
||||
|
||||
// NewModuleClient creates a new ModuleClient object
|
||||
func NewModuleClient(storeKey string, cdc *amino.Codec) ModuleClient {
|
||||
return ModuleClient{
|
||||
storeKey: storeKey,
|
||||
cdc: cdc,
|
||||
}
|
||||
}
|
||||
|
||||
// GetQueryCmd returns the cli query commands for this module
|
||||
func (ModuleClient) GetQueryCmd() *cobra.Command {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTxCmd returns the transaction commands for this module
|
||||
func (mc ModuleClient) GetTxCmd() *cobra.Command {
|
||||
txCmd := &cobra.Command{
|
||||
Use: crisis.ModuleName,
|
||||
Short: "crisis transactions subcommands",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: utils.ValidateCmd,
|
||||
}
|
||||
|
||||
txCmd.AddCommand(client.PostCommands(
|
||||
cli.GetCmdInvariantBroken(mc.cdc),
|
||||
)...)
|
||||
return txCmd
|
||||
}
|
|
@ -2,39 +2,16 @@ package crisis
|
|||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis/types"
|
||||
)
|
||||
|
||||
// GenesisState - crisis genesis state
|
||||
type GenesisState struct {
|
||||
ConstantFee sdk.Coin `json:"constant_fee"`
|
||||
}
|
||||
|
||||
// NewGenesisState creates a new GenesisState object
|
||||
func NewGenesisState(constantFee sdk.Coin) GenesisState {
|
||||
return GenesisState{
|
||||
ConstantFee: constantFee,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultGenesisState creates a default GenesisState object
|
||||
func DefaultGenesisState() GenesisState {
|
||||
return GenesisState{
|
||||
ConstantFee: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000)),
|
||||
}
|
||||
}
|
||||
|
||||
// new crisis genesis
|
||||
func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState) {
|
||||
func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) {
|
||||
keeper.SetConstantFee(ctx, data.ConstantFee)
|
||||
}
|
||||
|
||||
// ExportGenesis returns a GenesisState for a given context and keeper.
|
||||
func ExportGenesis(ctx sdk.Context, keeper Keeper) GenesisState {
|
||||
func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
|
||||
constantFee := keeper.GetConstantFee(ctx)
|
||||
return NewGenesisState(constantFee)
|
||||
}
|
||||
|
||||
// ValidateGenesis - placeholder function
|
||||
func ValidateGenesis(data GenesisState) error {
|
||||
return nil
|
||||
return types.NewGenesisState(constantFee)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis/tags"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis/types"
|
||||
)
|
||||
|
||||
// RouterKey
|
||||
|
@ -13,7 +14,7 @@ const RouterKey = ModuleName
|
|||
func NewHandler(k Keeper) sdk.Handler {
|
||||
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
|
||||
switch msg := msg.(type) {
|
||||
case MsgVerifyInvariant:
|
||||
case types.MsgVerifyInvariant:
|
||||
return handleMsgVerifyInvariant(ctx, msg, k)
|
||||
|
||||
default:
|
||||
|
@ -23,7 +24,7 @@ func NewHandler(k Keeper) sdk.Handler {
|
|||
}
|
||||
}
|
||||
|
||||
func handleMsgVerifyInvariant(ctx sdk.Context, msg MsgVerifyInvariant, k Keeper) sdk.Result {
|
||||
func handleMsgVerifyInvariant(ctx sdk.Context, msg types.MsgVerifyInvariant, k Keeper) sdk.Result {
|
||||
|
||||
// remove the constant fee
|
||||
constantFee := sdk.NewCoins(k.GetConstantFee(ctx))
|
||||
|
@ -47,7 +48,7 @@ func handleMsgVerifyInvariant(ctx sdk.Context, msg MsgVerifyInvariant, k Keeper)
|
|||
}
|
||||
}
|
||||
if !found {
|
||||
return ErrUnknownInvariant(DefaultCodespace).Result()
|
||||
return types.ErrUnknownInvariant(types.DefaultCodespace).Result()
|
||||
}
|
||||
|
||||
if invarianceErr != nil {
|
||||
|
|
|
@ -7,12 +7,13 @@ import (
|
|||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/params"
|
||||
)
|
||||
|
||||
// Keeper - crisis keeper
|
||||
type Keeper struct {
|
||||
routes []InvarRoute
|
||||
routes []types.InvarRoute
|
||||
paramSpace params.Subspace
|
||||
invCheckPeriod uint
|
||||
|
||||
|
@ -27,8 +28,8 @@ func NewKeeper(paramSpace params.Subspace, invCheckPeriod uint,
|
|||
feeCollectionKeeper FeeCollectionKeeper) Keeper {
|
||||
|
||||
return Keeper{
|
||||
routes: []InvarRoute{},
|
||||
paramSpace: paramSpace.WithKeyTable(ParamKeyTable()),
|
||||
routes: []types.InvarRoute{},
|
||||
paramSpace: paramSpace.WithKeyTable(types.ParamKeyTable()),
|
||||
invCheckPeriod: invCheckPeriod,
|
||||
distrKeeper: distrKeeper,
|
||||
bankKeeper: bankKeeper,
|
||||
|
@ -38,12 +39,12 @@ func NewKeeper(paramSpace params.Subspace, invCheckPeriod uint,
|
|||
|
||||
// register routes for the
|
||||
func (k *Keeper) RegisterRoute(moduleName, route string, invar sdk.Invariant) {
|
||||
invarRoute := NewInvarRoute(moduleName, route, invar)
|
||||
invarRoute := types.NewInvarRoute(moduleName, route, invar)
|
||||
k.routes = append(k.routes, invarRoute)
|
||||
}
|
||||
|
||||
// Routes - return the keeper's invariant routes
|
||||
func (k Keeper) Routes() []InvarRoute {
|
||||
func (k Keeper) Routes() []types.InvarRoute {
|
||||
return k.routes
|
||||
}
|
||||
|
||||
|
|
|
@ -3,25 +3,28 @@ package crisis
|
|||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"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/types/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis/client/cli"
|
||||
)
|
||||
|
||||
var (
|
||||
_ sdk.AppModule = AppModule{}
|
||||
_ sdk.AppModuleBasic = AppModuleBasic{}
|
||||
_ module.AppModule = AppModule{}
|
||||
_ module.AppModuleBasic = AppModuleBasic{}
|
||||
)
|
||||
|
||||
// name of this module
|
||||
const ModuleName = "crisis"
|
||||
|
||||
// app module basics object
|
||||
type AppModuleBasic struct{}
|
||||
|
||||
var _ sdk.AppModuleBasic = AppModuleBasic{}
|
||||
var _ module.AppModuleBasic = AppModuleBasic{}
|
||||
|
||||
// module name
|
||||
func (AppModuleBasic) Name() string {
|
||||
|
@ -35,19 +38,27 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
|
|||
|
||||
// default genesis state
|
||||
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
|
||||
return moduleCdc.MustMarshalJSON(DefaultGenesisState())
|
||||
return ModuleCdc.MustMarshalJSON(DefaultGenesisState())
|
||||
}
|
||||
|
||||
// module validate genesis
|
||||
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
|
||||
var data GenesisState
|
||||
err := moduleCdc.UnmarshalJSON(bz, &data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ValidateGenesis(data)
|
||||
//TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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(cdc *codec.Codec) *cobra.Command {
|
||||
return cli.GetTxCmd(cdc)
|
||||
}
|
||||
|
||||
// get the root query command of this module
|
||||
func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil }
|
||||
|
||||
//___________________________
|
||||
// app module for bank
|
||||
type AppModule struct {
|
||||
|
@ -92,7 +103,7 @@ func (AppModule) NewQuerierHandler() sdk.Querier { return nil }
|
|||
// module init-genesis
|
||||
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
|
||||
var genesisState GenesisState
|
||||
moduleCdc.MustUnmarshalJSON(data, &genesisState)
|
||||
ModuleCdc.MustUnmarshalJSON(data, &genesisState)
|
||||
InitGenesis(ctx, am.keeper, genesisState)
|
||||
|
||||
am.keeper.AssertInvariants(ctx, am.logger)
|
||||
|
@ -102,7 +113,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.Va
|
|||
// module export genesis
|
||||
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
|
||||
gs := ExportGenesis(ctx, am.keeper)
|
||||
return moduleCdc.MustMarshalJSON(gs)
|
||||
return ModuleCdc.MustMarshalJSON(gs)
|
||||
}
|
||||
|
||||
// module begin-block
|
||||
|
|
|
@ -2,33 +2,16 @@ package crisis
|
|||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/params"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis/types"
|
||||
)
|
||||
|
||||
// Default parameter namespace
|
||||
const (
|
||||
DefaultParamspace = ModuleName
|
||||
)
|
||||
|
||||
var (
|
||||
// key for constant fee parameter
|
||||
ParamStoreKeyConstantFee = []byte("ConstantFee")
|
||||
)
|
||||
|
||||
// type declaration for parameters
|
||||
func ParamKeyTable() params.KeyTable {
|
||||
return params.NewKeyTable(
|
||||
ParamStoreKeyConstantFee, sdk.Coin{},
|
||||
)
|
||||
}
|
||||
|
||||
// GetConstantFee get's the constant fee from the paramSpace
|
||||
func (k Keeper) GetConstantFee(ctx sdk.Context) (constantFee sdk.Coin) {
|
||||
k.paramSpace.Get(ctx, ParamStoreKeyConstantFee, &constantFee)
|
||||
k.paramSpace.Get(ctx, types.ParamStoreKeyConstantFee, &constantFee)
|
||||
return
|
||||
}
|
||||
|
||||
// GetConstantFee set's the constant fee in the paramSpace
|
||||
func (k Keeper) SetConstantFee(ctx sdk.Context, constantFee sdk.Coin) {
|
||||
k.paramSpace.Set(ctx, ParamStoreKeyConstantFee, constantFee)
|
||||
k.paramSpace.Set(ctx, types.ParamStoreKeyConstantFee, constantFee)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package crisis
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
|
@ -10,11 +10,11 @@ func RegisterCodec(cdc *codec.Codec) {
|
|||
}
|
||||
|
||||
// generic sealed codec to be used throughout module
|
||||
var moduleCdc *codec.Codec
|
||||
var ModuleCdc *codec.Codec
|
||||
|
||||
func init() {
|
||||
cdc := codec.New()
|
||||
RegisterCodec(cdc)
|
||||
codec.RegisterCrypto(cdc)
|
||||
moduleCdc = cdc.Seal()
|
||||
ModuleCdc = codec.New()
|
||||
RegisterCodec(ModuleCdc)
|
||||
codec.RegisterCrypto(ModuleCdc)
|
||||
ModuleCdc.Seal()
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package crisis
|
||||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
@ -0,0 +1,24 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// GenesisState - crisis genesis state
|
||||
type GenesisState struct {
|
||||
ConstantFee sdk.Coin `json:"constant_fee"`
|
||||
}
|
||||
|
||||
// NewGenesisState creates a new GenesisState object
|
||||
func NewGenesisState(constantFee sdk.Coin) GenesisState {
|
||||
return GenesisState{
|
||||
ConstantFee: constantFee,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultGenesisState creates a default GenesisState object
|
||||
func DefaultGenesisState() GenesisState {
|
||||
return GenesisState{
|
||||
ConstantFee: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000)),
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package types
|
||||
|
||||
const (
|
||||
// module name
|
||||
ModuleName = "crisis"
|
||||
)
|
|
@ -1,4 +1,4 @@
|
|||
package crisis
|
||||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
@ -34,7 +34,7 @@ func (msg MsgVerifyInvariant) GetSigners() []sdk.AccAddress { return []sdk.AccAd
|
|||
|
||||
// GetSignBytes gets the sign bytes for the msg MsgVerifyInvariant
|
||||
func (msg MsgVerifyInvariant) GetSignBytes() []byte {
|
||||
bz := moduleCdc.MustMarshalJSON(msg)
|
||||
bz := ModuleCdc.MustMarshalJSON(msg)
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/params"
|
||||
)
|
||||
|
||||
// Default parameter namespace
|
||||
const (
|
||||
DefaultParamspace = ModuleName
|
||||
)
|
||||
|
||||
var (
|
||||
// key for constant fee parameter
|
||||
ParamStoreKeyConstantFee = []byte("ConstantFee")
|
||||
)
|
||||
|
||||
// type declaration for parameters
|
||||
func ParamKeyTable() params.KeyTable {
|
||||
return params.NewKeyTable(
|
||||
ParamStoreKeyConstantFee, sdk.Coin{},
|
||||
)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package crisis
|
||||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
@ -14,19 +14,6 @@ import (
|
|||
|
||||
const (
|
||||
DefaultParamspace = keeper.DefaultParamspace
|
||||
QueryParams = keeper.QueryParams
|
||||
QueryValidatorOutstandingRewards = keeper.QueryValidatorOutstandingRewards
|
||||
QueryValidatorCommission = keeper.QueryValidatorCommission
|
||||
QueryValidatorSlashes = keeper.QueryValidatorSlashes
|
||||
QueryDelegationRewards = keeper.QueryDelegationRewards
|
||||
QueryDelegatorTotalRewards = keeper.QueryDelegatorTotalRewards
|
||||
QueryDelegatorValidators = keeper.QueryDelegatorValidators
|
||||
QueryWithdrawAddr = keeper.QueryWithdrawAddr
|
||||
QueryCommunityPool = keeper.QueryCommunityPool
|
||||
ParamCommunityTax = keeper.ParamCommunityTax
|
||||
ParamBaseProposerReward = keeper.ParamBaseProposerReward
|
||||
ParamBonusProposerReward = keeper.ParamBonusProposerReward
|
||||
ParamWithdrawAddrEnabled = keeper.ParamWithdrawAddrEnabled
|
||||
DefaultCodespace = types.DefaultCodespace
|
||||
CodeInvalidInput = types.CodeInvalidInput
|
||||
CodeNoDistributionInfo = types.CodeNoDistributionInfo
|
||||
|
@ -37,6 +24,20 @@ const (
|
|||
TStoreKey = types.TStoreKey
|
||||
RouterKey = types.RouterKey
|
||||
QuerierRoute = types.QuerierRoute
|
||||
ProposalTypeCommunityPoolSpend = types.ProposalTypeCommunityPoolSpend
|
||||
QueryParams = types.QueryParams
|
||||
QueryValidatorOutstandingRewards = types.QueryValidatorOutstandingRewards
|
||||
QueryValidatorCommission = types.QueryValidatorCommission
|
||||
QueryValidatorSlashes = types.QueryValidatorSlashes
|
||||
QueryDelegationRewards = types.QueryDelegationRewards
|
||||
QueryDelegatorTotalRewards = types.QueryDelegatorTotalRewards
|
||||
QueryDelegatorValidators = types.QueryDelegatorValidators
|
||||
QueryWithdrawAddr = types.QueryWithdrawAddr
|
||||
QueryCommunityPool = types.QueryCommunityPool
|
||||
ParamCommunityTax = types.ParamCommunityTax
|
||||
ParamBaseProposerReward = types.ParamBaseProposerReward
|
||||
ParamBonusProposerReward = types.ParamBonusProposerReward
|
||||
ParamWithdrawAddrEnabled = types.ParamWithdrawAddrEnabled
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -64,13 +65,8 @@ var (
|
|||
GetValidatorSlashEventPrefix = keeper.GetValidatorSlashEventPrefix
|
||||
GetValidatorSlashEventKey = keeper.GetValidatorSlashEventKey
|
||||
ParamKeyTable = keeper.ParamKeyTable
|
||||
HandleCommunityPoolSpendProposal = keeper.HandleCommunityPoolSpendProposal
|
||||
NewQuerier = keeper.NewQuerier
|
||||
NewQueryValidatorOutstandingRewardsParams = keeper.NewQueryValidatorOutstandingRewardsParams
|
||||
NewQueryValidatorCommissionParams = keeper.NewQueryValidatorCommissionParams
|
||||
NewQueryValidatorSlashesParams = keeper.NewQueryValidatorSlashesParams
|
||||
NewQueryDelegationRewardsParams = keeper.NewQueryDelegationRewardsParams
|
||||
NewQueryDelegatorParams = keeper.NewQueryDelegatorParams
|
||||
NewQueryDelegatorWithdrawAddrParams = keeper.NewQueryDelegatorWithdrawAddrParams
|
||||
MakeTestCodec = keeper.MakeTestCodec
|
||||
CreateTestInputDefault = keeper.CreateTestInputDefault
|
||||
CreateTestInputAdvanced = keeper.CreateTestInputAdvanced
|
||||
|
@ -84,6 +80,8 @@ var (
|
|||
ErrNoValidatorCommission = types.ErrNoValidatorCommission
|
||||
ErrSetWithdrawAddrDisabled = types.ErrSetWithdrawAddrDisabled
|
||||
ErrBadDistribution = types.ErrBadDistribution
|
||||
ErrInvalidProposalAmount = types.ErrInvalidProposalAmount
|
||||
ErrEmptyProposalRecipient = types.ErrEmptyProposalRecipient
|
||||
InitialFeePool = types.InitialFeePool
|
||||
NewGenesisState = types.NewGenesisState
|
||||
DefaultGenesisState = types.DefaultGenesisState
|
||||
|
@ -91,13 +89,19 @@ var (
|
|||
NewMsgSetWithdrawAddress = types.NewMsgSetWithdrawAddress
|
||||
NewMsgWithdrawDelegatorReward = types.NewMsgWithdrawDelegatorReward
|
||||
NewMsgWithdrawValidatorCommission = types.NewMsgWithdrawValidatorCommission
|
||||
NewCommunityPoolSpendProposal = types.NewCommunityPoolSpendProposal
|
||||
NewQueryValidatorOutstandingRewardsParams = types.NewQueryValidatorOutstandingRewardsParams
|
||||
NewQueryValidatorCommissionParams = types.NewQueryValidatorCommissionParams
|
||||
NewQueryValidatorSlashesParams = types.NewQueryValidatorSlashesParams
|
||||
NewQueryDelegationRewardsParams = types.NewQueryDelegationRewardsParams
|
||||
NewQueryDelegatorParams = types.NewQueryDelegatorParams
|
||||
NewQueryDelegatorWithdrawAddrParams = types.NewQueryDelegatorWithdrawAddrParams
|
||||
NewQueryDelegatorTotalRewardsResponse = types.NewQueryDelegatorTotalRewardsResponse
|
||||
NewDelegationDelegatorReward = types.NewDelegationDelegatorReward
|
||||
NewValidatorHistoricalRewards = types.NewValidatorHistoricalRewards
|
||||
NewValidatorCurrentRewards = types.NewValidatorCurrentRewards
|
||||
InitialValidatorAccumulatedCommission = types.InitialValidatorAccumulatedCommission
|
||||
NewValidatorSlashEvent = types.NewValidatorSlashEvent
|
||||
NewCommunityPoolSpendProposal = types.NewCommunityPoolSpendProposal
|
||||
|
||||
// variable aliases
|
||||
FeePoolKey = keeper.FeePoolKey
|
||||
|
@ -126,12 +130,6 @@ var (
|
|||
type (
|
||||
Hooks = keeper.Hooks
|
||||
Keeper = keeper.Keeper
|
||||
QueryValidatorOutstandingRewardsParams = keeper.QueryValidatorOutstandingRewardsParams
|
||||
QueryValidatorCommissionParams = keeper.QueryValidatorCommissionParams
|
||||
QueryValidatorSlashesParams = keeper.QueryValidatorSlashesParams
|
||||
QueryDelegationRewardsParams = keeper.QueryDelegationRewardsParams
|
||||
QueryDelegatorParams = keeper.QueryDelegatorParams
|
||||
QueryDelegatorWithdrawAddrParams = keeper.QueryDelegatorWithdrawAddrParams
|
||||
DummyFeeCollectionKeeper = keeper.DummyFeeCollectionKeeper
|
||||
DelegatorStartingInfo = types.DelegatorStartingInfo
|
||||
CodeType = types.CodeType
|
||||
|
@ -146,11 +144,17 @@ type (
|
|||
ValidatorCurrentRewardsRecord = types.ValidatorCurrentRewardsRecord
|
||||
DelegatorStartingInfoRecord = types.DelegatorStartingInfoRecord
|
||||
ValidatorSlashEventRecord = types.ValidatorSlashEventRecord
|
||||
CommunityPoolSpendProposal = types.CommunityPoolSpendProposal
|
||||
GenesisState = types.GenesisState
|
||||
MsgSetWithdrawAddress = types.MsgSetWithdrawAddress
|
||||
MsgWithdrawDelegatorReward = types.MsgWithdrawDelegatorReward
|
||||
MsgWithdrawValidatorCommission = types.MsgWithdrawValidatorCommission
|
||||
CommunityPoolSpendProposal = types.CommunityPoolSpendProposal
|
||||
QueryValidatorOutstandingRewardsParams = types.QueryValidatorOutstandingRewardsParams
|
||||
QueryValidatorCommissionParams = types.QueryValidatorCommissionParams
|
||||
QueryValidatorSlashesParams = types.QueryValidatorSlashesParams
|
||||
QueryDelegationRewardsParams = types.QueryDelegationRewardsParams
|
||||
QueryDelegatorParams = types.QueryDelegatorParams
|
||||
QueryDelegatorWithdrawAddrParams = types.QueryDelegatorWithdrawAddrParams
|
||||
QueryDelegatorTotalRewardsResponse = types.QueryDelegatorTotalRewardsResponse
|
||||
DelegationDelegatorReward = types.DelegationDelegatorReward
|
||||
ValidatorHistoricalRewards = types.ValidatorHistoricalRewards
|
||||
|
|
|
@ -7,15 +7,38 @@ 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"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/client/common"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
)
|
||||
|
||||
// GetQueryCmd returns the cli query commands for this module
|
||||
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
distQueryCmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "Querying commands for the distribution module",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: utils.ValidateCmd,
|
||||
}
|
||||
|
||||
distQueryCmd.AddCommand(client.GetCommands(
|
||||
GetCmdQueryParams(queryRoute, cdc),
|
||||
GetCmdQueryValidatorOutstandingRewards(queryRoute, cdc),
|
||||
GetCmdQueryValidatorCommission(queryRoute, cdc),
|
||||
GetCmdQueryValidatorSlashes(queryRoute, cdc),
|
||||
GetCmdQueryDelegatorRewards(queryRoute, cdc),
|
||||
GetCmdQueryCommunityPool(queryRoute, cdc),
|
||||
)...)
|
||||
|
||||
return distQueryCmd
|
||||
}
|
||||
|
||||
// GetCmdQueryParams implements the query params command.
|
||||
func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
|
@ -123,7 +146,7 @@ $ %s query distr slashes cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 0
|
|||
return fmt.Errorf("end-height %s not a valid uint, please input a valid end-height", args[2])
|
||||
}
|
||||
|
||||
params := distr.NewQueryValidatorSlashesParams(validatorAddr, startHeight, endHeight)
|
||||
params := types.NewQueryValidatorSlashesParams(validatorAddr, startHeight, endHeight)
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -178,7 +201,7 @@ $ %s query distr rewards cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosval
|
|||
return err
|
||||
}
|
||||
|
||||
var result distr.QueryDelegatorTotalRewardsResponse
|
||||
var result types.QueryDelegatorTotalRewardsResponse
|
||||
cdc.MustUnmarshalJSON(resp, &result)
|
||||
return cliCtx.PrintOutput(result)
|
||||
},
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
|
@ -15,8 +14,8 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||
auth "github.com/cosmos/cosmos-sdk/x/auth"
|
||||
gov "github.com/cosmos/cosmos-sdk/x/gov"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/client/common"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
|
@ -34,26 +33,30 @@ const (
|
|||
)
|
||||
|
||||
// GetTxCmd returns the transaction commands for this module
|
||||
func GetTxCmd(storeKey string, cdc *amino.Codec) *cobra.Command {
|
||||
func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
|
||||
distTxCmd := &cobra.Command{
|
||||
Use: "dist",
|
||||
Short: "Distribution transactions subcommands",
|
||||
Use: types.ModuleName,
|
||||
Short: "Distribution transactions subcommands",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: utils.ValidateCmd,
|
||||
}
|
||||
|
||||
distTxCmd.AddCommand(client.PostCommands(
|
||||
GetCmdWithdrawRewards(cdc),
|
||||
GetCmdSetWithdrawAddr(cdc),
|
||||
GetCmdWithdrawAllRewards(cdc, storeKey),
|
||||
)...)
|
||||
|
||||
return distTxCmd
|
||||
}
|
||||
|
||||
type generateOrBroadcastFunc func(context.CLIContext, authtxb.TxBuilder, []sdk.Msg) error
|
||||
type generateOrBroadcastFunc func(context.CLIContext, auth.TxBuilder, []sdk.Msg) error
|
||||
|
||||
func splitAndApply(
|
||||
generateOrBroadcast generateOrBroadcastFunc,
|
||||
cliCtx context.CLIContext,
|
||||
txBldr authtxb.TxBuilder,
|
||||
txBldr auth.TxBuilder,
|
||||
msgs []sdk.Msg,
|
||||
chunkSize int,
|
||||
) error {
|
||||
|
@ -98,7 +101,7 @@ $ %s tx distr withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqh
|
|||
),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
||||
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(cdc)
|
||||
|
@ -138,7 +141,7 @@ $ %s tx distr withdraw-all-rewards --from mykey
|
|||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
||||
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(cdc)
|
||||
|
@ -174,7 +177,7 @@ $ %s tx set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p --from m
|
|||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
||||
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(cdc)
|
||||
|
@ -228,7 +231,7 @@ Where proposal.json contains:
|
|||
),
|
||||
),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
||||
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(cdc)
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||
|
||||
"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"
|
||||
auth "github.com/cosmos/cosmos-sdk/x/auth"
|
||||
)
|
||||
|
||||
func createFakeTxBuilder() authtxb.TxBuilder {
|
||||
func createFakeTxBuilder() auth.TxBuilder {
|
||||
cdc := codec.New()
|
||||
return authtxb.NewTxBuilder(
|
||||
return auth.NewTxBuilder(
|
||||
utils.GetTxEncoder(cdc),
|
||||
123,
|
||||
9876,
|
||||
|
@ -55,8 +57,8 @@ func Test_splitAndCall_Splitting(t *testing.T) {
|
|||
|
||||
callCount := 0
|
||||
err := splitAndApply(
|
||||
func(ctx context.CLIContext, txBldr authtxb.TxBuilder, msgs []sdk.Msg) error {
|
||||
callCount += 1
|
||||
func(ctx context.CLIContext, txBldr auth.TxBuilder, msgs []sdk.Msg) error {
|
||||
callCount++
|
||||
|
||||
assert.NotNil(t, ctx)
|
||||
assert.NotNil(t, txBldr)
|
||||
|
|
|
@ -6,31 +6,31 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
)
|
||||
|
||||
// QueryParams actually queries distribution params.
|
||||
func QueryParams(cliCtx context.CLIContext, queryRoute string) (PrettyParams, error) {
|
||||
route := fmt.Sprintf("custom/%s/params/%s", queryRoute, distr.ParamCommunityTax)
|
||||
route := fmt.Sprintf("custom/%s/params/%s", queryRoute, types.ParamCommunityTax)
|
||||
|
||||
retCommunityTax, err := cliCtx.QueryWithData(route, []byte{})
|
||||
if err != nil {
|
||||
return PrettyParams{}, err
|
||||
}
|
||||
|
||||
route = fmt.Sprintf("custom/%s/params/%s", queryRoute, distr.ParamBaseProposerReward)
|
||||
route = fmt.Sprintf("custom/%s/params/%s", queryRoute, types.ParamBaseProposerReward)
|
||||
retBaseProposerReward, err := cliCtx.QueryWithData(route, []byte{})
|
||||
if err != nil {
|
||||
return PrettyParams{}, err
|
||||
}
|
||||
|
||||
route = fmt.Sprintf("custom/%s/params/%s", queryRoute, distr.ParamBonusProposerReward)
|
||||
route = fmt.Sprintf("custom/%s/params/%s", queryRoute, types.ParamBonusProposerReward)
|
||||
retBonusProposerReward, err := cliCtx.QueryWithData(route, []byte{})
|
||||
if err != nil {
|
||||
return PrettyParams{}, err
|
||||
}
|
||||
|
||||
route = fmt.Sprintf("custom/%s/params/%s", queryRoute, distr.ParamWithdrawAddrEnabled)
|
||||
route = fmt.Sprintf("custom/%s/params/%s", queryRoute, types.ParamWithdrawAddrEnabled)
|
||||
retWithdrawAddrEnabled, err := cliCtx.QueryWithData(route, []byte{})
|
||||
if err != nil {
|
||||
return PrettyParams{}, err
|
||||
|
@ -50,8 +50,8 @@ func QueryDelegatorTotalRewards(cliCtx context.CLIContext, cdc *codec.Codec,
|
|||
}
|
||||
|
||||
return cliCtx.QueryWithData(
|
||||
fmt.Sprintf("custom/%s/%s", queryRoute, distr.QueryDelegatorTotalRewards),
|
||||
cdc.MustMarshalJSON(distr.NewQueryDelegatorParams(delegatorAddr)),
|
||||
fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegatorTotalRewards),
|
||||
cdc.MustMarshalJSON(types.NewQueryDelegatorParams(delegatorAddr)),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -69,8 +69,8 @@ func QueryDelegationRewards(cliCtx context.CLIContext, cdc *codec.Codec,
|
|||
}
|
||||
|
||||
return cliCtx.QueryWithData(
|
||||
fmt.Sprintf("custom/%s/%s", queryRoute, distr.QueryDelegationRewards),
|
||||
cdc.MustMarshalJSON(distr.NewQueryDelegationRewardsParams(delegatorAddr, validatorAddr)),
|
||||
fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegationRewards),
|
||||
cdc.MustMarshalJSON(types.NewQueryDelegationRewardsParams(delegatorAddr, validatorAddr)),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -80,8 +80,8 @@ func QueryDelegatorValidators(cliCtx context.CLIContext, cdc *codec.Codec,
|
|||
queryRoute string, delegatorAddr sdk.AccAddress) ([]byte, error) {
|
||||
|
||||
return cliCtx.QueryWithData(
|
||||
fmt.Sprintf("custom/%s/%s", queryRoute, distr.QueryDelegatorValidators),
|
||||
cdc.MustMarshalJSON(distr.NewQueryDelegatorParams(delegatorAddr)),
|
||||
fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegatorValidators),
|
||||
cdc.MustMarshalJSON(types.NewQueryDelegatorParams(delegatorAddr)),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -90,8 +90,8 @@ func QueryValidatorCommission(cliCtx context.CLIContext, cdc *codec.Codec,
|
|||
queryRoute string, validatorAddr sdk.ValAddress) ([]byte, error) {
|
||||
|
||||
return cliCtx.QueryWithData(
|
||||
fmt.Sprintf("custom/%s/%s", queryRoute, distr.QueryValidatorCommission),
|
||||
cdc.MustMarshalJSON(distr.NewQueryValidatorCommissionParams(validatorAddr)),
|
||||
fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryValidatorCommission),
|
||||
cdc.MustMarshalJSON(types.NewQueryValidatorCommissionParams(validatorAddr)),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ func WithdrawAllDelegatorRewards(cliCtx context.CLIContext, cdc *codec.Codec,
|
|||
// build multi-message transaction
|
||||
var msgs []sdk.Msg
|
||||
for _, valAddr := range validators {
|
||||
msg := distr.NewMsgWithdrawDelegatorReward(delegatorAddr, valAddr)
|
||||
msg := types.NewMsgWithdrawDelegatorReward(delegatorAddr, valAddr)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -129,13 +129,13 @@ func WithdrawAllDelegatorRewards(cliCtx context.CLIContext, cdc *codec.Codec,
|
|||
// used to withdraw both validation's commission and self-delegation reward.
|
||||
func WithdrawValidatorRewardsAndCommission(validatorAddr sdk.ValAddress) ([]sdk.Msg, error) {
|
||||
|
||||
commissionMsg := distr.NewMsgWithdrawValidatorCommission(validatorAddr)
|
||||
commissionMsg := types.NewMsgWithdrawValidatorCommission(validatorAddr)
|
||||
if err := commissionMsg.ValidateBasic(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// build and validate MsgWithdrawDelegatorReward
|
||||
rewardMsg := distr.NewMsgWithdrawDelegatorReward(
|
||||
rewardMsg := types.NewMsgWithdrawDelegatorReward(
|
||||
sdk.AccAddress(validatorAddr.Bytes()), validatorAddr)
|
||||
if err := rewardMsg.ValidateBasic(); err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
dist "github.com/cosmos/cosmos-sdk/x/distribution"
|
||||
distCmds "github.com/cosmos/cosmos-sdk/x/distribution/client/cli"
|
||||
)
|
||||
|
||||
// ModuleClient exports all client functionality from this module
|
||||
type ModuleClient struct {
|
||||
storeKey string
|
||||
cdc *amino.Codec
|
||||
}
|
||||
|
||||
func NewModuleClient(storeKey string, cdc *amino.Codec) ModuleClient {
|
||||
return ModuleClient{storeKey, cdc}
|
||||
}
|
||||
|
||||
// GetQueryCmd returns the cli query commands for this module
|
||||
func (mc ModuleClient) GetQueryCmd() *cobra.Command {
|
||||
distQueryCmd := &cobra.Command{
|
||||
Use: dist.ModuleName,
|
||||
Short: "Querying commands for the distribution module",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: utils.ValidateCmd,
|
||||
}
|
||||
|
||||
distQueryCmd.AddCommand(client.GetCommands(
|
||||
distCmds.GetCmdQueryParams(mc.storeKey, mc.cdc),
|
||||
distCmds.GetCmdQueryValidatorOutstandingRewards(mc.storeKey, mc.cdc),
|
||||
distCmds.GetCmdQueryValidatorCommission(mc.storeKey, mc.cdc),
|
||||
distCmds.GetCmdQueryValidatorSlashes(mc.storeKey, mc.cdc),
|
||||
distCmds.GetCmdQueryDelegatorRewards(mc.storeKey, mc.cdc),
|
||||
distCmds.GetCmdQueryCommunityPool(mc.storeKey, mc.cdc),
|
||||
)...)
|
||||
|
||||
return distQueryCmd
|
||||
}
|
||||
|
||||
// GetTxCmd returns the transaction commands for this module
|
||||
func (mc ModuleClient) GetTxCmd() *cobra.Command {
|
||||
distTxCmd := &cobra.Command{
|
||||
Use: dist.ModuleName,
|
||||
Short: "Distribution transactions subcommands",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: utils.ValidateCmd,
|
||||
}
|
||||
|
||||
distTxCmd.AddCommand(client.PostCommands(
|
||||
distCmds.GetCmdWithdrawRewards(mc.cdc),
|
||||
distCmds.GetCmdSetWithdrawAddr(mc.cdc),
|
||||
distCmds.GetCmdWithdrawAllRewards(mc.cdc, mc.storeKey),
|
||||
)...)
|
||||
|
||||
return distTxCmd
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/client/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/client/rest"
|
||||
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
|
||||
)
|
||||
|
||||
// param change proposal handler
|
||||
var ProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitProposal, rest.ProposalRESTHandler)
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/client/common"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
|
||||
|
@ -111,7 +110,7 @@ func delegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext, cdc *codec.Code
|
|||
return
|
||||
}
|
||||
|
||||
bz := cdc.MustMarshalJSON(distribution.NewQueryDelegatorWithdrawAddrParams(delegatorAddr))
|
||||
bz := cdc.MustMarshalJSON(types.NewQueryDelegatorWithdrawAddrParams(delegatorAddr))
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/withdraw_addr", queryRoute), bz)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
|
@ -243,7 +242,7 @@ func outstandingRewardsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec,
|
|||
return
|
||||
}
|
||||
|
||||
bin := cdc.MustMarshalJSON(distribution.NewQueryValidatorOutstandingRewardsParams(validatorAddr))
|
||||
bin := cdc.MustMarshalJSON(types.NewQueryValidatorOutstandingRewardsParams(validatorAddr))
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/validator_outstanding_rewards", queryRoute), bin)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
package rest
|
||||
|
||||
import (
|
||||
"github.com/gorilla/mux"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||
govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
|
||||
)
|
||||
|
@ -40,7 +41,7 @@ func postProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Han
|
|||
return
|
||||
}
|
||||
|
||||
content := distribution.NewCommunityPoolSpendProposal(req.Title, req.Description, req.Recipient, req.Amount)
|
||||
content := types.NewCommunityPoolSpendProposal(req.Title, req.Description, req.Recipient, req.Amount)
|
||||
|
||||
msg := gov.NewMsgSubmitProposal(content, req.Deposit, req.Proposer)
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
)
|
||||
|
||||
// Handler for executing a passed community spend proposal
|
||||
func HandleCommunityPoolSpendProposal(ctx sdk.Context, k Keeper, p types.CommunityPoolSpendProposal) sdk.Error {
|
||||
feePool := k.GetFeePool(ctx)
|
||||
newPool, negative := feePool.CommunityPool.SafeSub(sdk.NewDecCoins(p.Amount))
|
||||
|
|
|
@ -12,52 +12,34 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
)
|
||||
|
||||
// nolint
|
||||
const (
|
||||
QueryParams = "params"
|
||||
QueryValidatorOutstandingRewards = "validator_outstanding_rewards"
|
||||
QueryValidatorCommission = "validator_commission"
|
||||
QueryValidatorSlashes = "validator_slashes"
|
||||
QueryDelegationRewards = "delegation_rewards"
|
||||
QueryDelegatorTotalRewards = "delegator_total_rewards"
|
||||
QueryDelegatorValidators = "delegator_validators"
|
||||
QueryWithdrawAddr = "withdraw_addr"
|
||||
QueryCommunityPool = "community_pool"
|
||||
|
||||
ParamCommunityTax = "community_tax"
|
||||
ParamBaseProposerReward = "base_proposer_reward"
|
||||
ParamBonusProposerReward = "bonus_proposer_reward"
|
||||
ParamWithdrawAddrEnabled = "withdraw_addr_enabled"
|
||||
)
|
||||
|
||||
func NewQuerier(k Keeper) sdk.Querier {
|
||||
return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, sdk.Error) {
|
||||
switch path[0] {
|
||||
case QueryParams:
|
||||
case types.QueryParams:
|
||||
return queryParams(ctx, path[1:], req, k)
|
||||
|
||||
case QueryValidatorOutstandingRewards:
|
||||
case types.QueryValidatorOutstandingRewards:
|
||||
return queryValidatorOutstandingRewards(ctx, path[1:], req, k)
|
||||
|
||||
case QueryValidatorCommission:
|
||||
case types.QueryValidatorCommission:
|
||||
return queryValidatorCommission(ctx, path[1:], req, k)
|
||||
|
||||
case QueryValidatorSlashes:
|
||||
case types.QueryValidatorSlashes:
|
||||
return queryValidatorSlashes(ctx, path[1:], req, k)
|
||||
|
||||
case QueryDelegationRewards:
|
||||
case types.QueryDelegationRewards:
|
||||
return queryDelegationRewards(ctx, path[1:], req, k)
|
||||
|
||||
case QueryDelegatorTotalRewards:
|
||||
case types.QueryDelegatorTotalRewards:
|
||||
return queryDelegatorTotalRewards(ctx, path[1:], req, k)
|
||||
|
||||
case QueryDelegatorValidators:
|
||||
case types.QueryDelegatorValidators:
|
||||
return queryDelegatorValidators(ctx, path[1:], req, k)
|
||||
|
||||
case QueryWithdrawAddr:
|
||||
case types.QueryWithdrawAddr:
|
||||
return queryDelegatorWithdrawAddress(ctx, path[1:], req, k)
|
||||
|
||||
case QueryCommunityPool:
|
||||
case types.QueryCommunityPool:
|
||||
return queryCommunityPool(ctx, path[1:], req, k)
|
||||
|
||||
default:
|
||||
|
@ -68,25 +50,25 @@ func NewQuerier(k Keeper) sdk.Querier {
|
|||
|
||||
func queryParams(ctx sdk.Context, path []string, req abci.RequestQuery, k Keeper) ([]byte, sdk.Error) {
|
||||
switch path[0] {
|
||||
case ParamCommunityTax:
|
||||
case types.ParamCommunityTax:
|
||||
bz, err := codec.MarshalJSONIndent(k.cdc, k.GetCommunityTax(ctx))
|
||||
if err != nil {
|
||||
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err.Error()))
|
||||
}
|
||||
return bz, nil
|
||||
case ParamBaseProposerReward:
|
||||
case types.ParamBaseProposerReward:
|
||||
bz, err := codec.MarshalJSONIndent(k.cdc, k.GetBaseProposerReward(ctx))
|
||||
if err != nil {
|
||||
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err.Error()))
|
||||
}
|
||||
return bz, nil
|
||||
case ParamBonusProposerReward:
|
||||
case types.ParamBonusProposerReward:
|
||||
bz, err := codec.MarshalJSONIndent(k.cdc, k.GetBonusProposerReward(ctx))
|
||||
if err != nil {
|
||||
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err.Error()))
|
||||
}
|
||||
return bz, nil
|
||||
case ParamWithdrawAddrEnabled:
|
||||
case types.ParamWithdrawAddrEnabled:
|
||||
bz, err := codec.MarshalJSONIndent(k.cdc, k.GetWithdrawAddrEnabled(ctx))
|
||||
if err != nil {
|
||||
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err.Error()))
|
||||
|
@ -97,20 +79,8 @@ func queryParams(ctx sdk.Context, path []string, req abci.RequestQuery, k Keeper
|
|||
}
|
||||
}
|
||||
|
||||
// params for query 'custom/distr/validator_outstanding_rewards'
|
||||
type QueryValidatorOutstandingRewardsParams struct {
|
||||
ValidatorAddress sdk.ValAddress `json:"validator_address"`
|
||||
}
|
||||
|
||||
// creates a new instance of QueryValidatorOutstandingRewardsParams
|
||||
func NewQueryValidatorOutstandingRewardsParams(validatorAddr sdk.ValAddress) QueryValidatorOutstandingRewardsParams {
|
||||
return QueryValidatorOutstandingRewardsParams{
|
||||
ValidatorAddress: validatorAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func queryValidatorOutstandingRewards(ctx sdk.Context, path []string, req abci.RequestQuery, k Keeper) ([]byte, sdk.Error) {
|
||||
var params QueryValidatorOutstandingRewardsParams
|
||||
var params types.QueryValidatorOutstandingRewardsParams
|
||||
err := k.cdc.UnmarshalJSON(req.Data, ¶ms)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrUnknownRequest(sdk.AppendMsgToErr("incorrectly formatted request data", err.Error()))
|
||||
|
@ -122,20 +92,8 @@ func queryValidatorOutstandingRewards(ctx sdk.Context, path []string, req abci.R
|
|||
return bz, nil
|
||||
}
|
||||
|
||||
// params for query 'custom/distr/validator_commission'
|
||||
type QueryValidatorCommissionParams struct {
|
||||
ValidatorAddress sdk.ValAddress `json:"validator_address"`
|
||||
}
|
||||
|
||||
// creates a new instance of QueryValidatorCommissionParams
|
||||
func NewQueryValidatorCommissionParams(validatorAddr sdk.ValAddress) QueryValidatorCommissionParams {
|
||||
return QueryValidatorCommissionParams{
|
||||
ValidatorAddress: validatorAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func queryValidatorCommission(ctx sdk.Context, path []string, req abci.RequestQuery, k Keeper) ([]byte, sdk.Error) {
|
||||
var params QueryValidatorCommissionParams
|
||||
var params types.QueryValidatorCommissionParams
|
||||
err := k.cdc.UnmarshalJSON(req.Data, ¶ms)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrUnknownRequest(sdk.AppendMsgToErr("incorrectly formatted request data", err.Error()))
|
||||
|
@ -148,24 +106,8 @@ func queryValidatorCommission(ctx sdk.Context, path []string, req abci.RequestQu
|
|||
return bz, nil
|
||||
}
|
||||
|
||||
// params for query 'custom/distr/validator_slashes'
|
||||
type QueryValidatorSlashesParams struct {
|
||||
ValidatorAddress sdk.ValAddress `json:"validator_address"`
|
||||
StartingHeight uint64 `json:"starting_height"`
|
||||
EndingHeight uint64 `json:"ending_height"`
|
||||
}
|
||||
|
||||
// creates a new instance of QueryValidatorSlashesParams
|
||||
func NewQueryValidatorSlashesParams(validatorAddr sdk.ValAddress, startingHeight uint64, endingHeight uint64) QueryValidatorSlashesParams {
|
||||
return QueryValidatorSlashesParams{
|
||||
ValidatorAddress: validatorAddr,
|
||||
StartingHeight: startingHeight,
|
||||
EndingHeight: endingHeight,
|
||||
}
|
||||
}
|
||||
|
||||
func queryValidatorSlashes(ctx sdk.Context, path []string, req abci.RequestQuery, k Keeper) ([]byte, sdk.Error) {
|
||||
var params QueryValidatorSlashesParams
|
||||
var params types.QueryValidatorSlashesParams
|
||||
err := k.cdc.UnmarshalJSON(req.Data, ¶ms)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrUnknownRequest(sdk.AppendMsgToErr("incorrectly formatted request data", err.Error()))
|
||||
|
@ -184,22 +126,8 @@ func queryValidatorSlashes(ctx sdk.Context, path []string, req abci.RequestQuery
|
|||
return bz, nil
|
||||
}
|
||||
|
||||
// params for query 'custom/distr/delegation_rewards'
|
||||
type QueryDelegationRewardsParams struct {
|
||||
DelegatorAddress sdk.AccAddress `json:"delegator_address"`
|
||||
ValidatorAddress sdk.ValAddress `json:"validator_address"`
|
||||
}
|
||||
|
||||
// creates a new instance of QueryDelegationRewardsParams
|
||||
func NewQueryDelegationRewardsParams(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) QueryDelegationRewardsParams {
|
||||
return QueryDelegationRewardsParams{
|
||||
DelegatorAddress: delegatorAddr,
|
||||
ValidatorAddress: validatorAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func queryDelegationRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper) ([]byte, sdk.Error) {
|
||||
var params QueryDelegationRewardsParams
|
||||
var params types.QueryDelegationRewardsParams
|
||||
err := k.cdc.UnmarshalJSON(req.Data, ¶ms)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrUnknownRequest(sdk.AppendMsgToErr("incorrectly formatted request data", err.Error()))
|
||||
|
@ -231,20 +159,8 @@ func queryDelegationRewards(ctx sdk.Context, _ []string, req abci.RequestQuery,
|
|||
return bz, nil
|
||||
}
|
||||
|
||||
// params for query 'custom/distr/delegator_total_rewards' and 'custom/distr/delegator_validators'
|
||||
type QueryDelegatorParams struct {
|
||||
DelegatorAddress sdk.AccAddress `json:"delegator_address"`
|
||||
}
|
||||
|
||||
// creates a new instance of QueryDelegationRewardsParams
|
||||
func NewQueryDelegatorParams(delegatorAddr sdk.AccAddress) QueryDelegatorParams {
|
||||
return QueryDelegatorParams{
|
||||
DelegatorAddress: delegatorAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func queryDelegatorTotalRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper) ([]byte, sdk.Error) {
|
||||
var params QueryDelegatorParams
|
||||
var params types.QueryDelegatorParams
|
||||
err := k.cdc.UnmarshalJSON(req.Data, ¶ms)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrUnknownRequest(sdk.AppendMsgToErr("incorrectly formatted request data", err.Error()))
|
||||
|
@ -280,7 +196,7 @@ func queryDelegatorTotalRewards(ctx sdk.Context, _ []string, req abci.RequestQue
|
|||
}
|
||||
|
||||
func queryDelegatorValidators(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper) ([]byte, sdk.Error) {
|
||||
var params QueryDelegatorParams
|
||||
var params types.QueryDelegatorParams
|
||||
err := k.cdc.UnmarshalJSON(req.Data, ¶ms)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrUnknownRequest(sdk.AppendMsgToErr("incorrectly formatted request data", err.Error()))
|
||||
|
@ -306,18 +222,8 @@ func queryDelegatorValidators(ctx sdk.Context, _ []string, req abci.RequestQuery
|
|||
return bz, nil
|
||||
}
|
||||
|
||||
// params for query 'custom/distr/withdraw_addr'
|
||||
type QueryDelegatorWithdrawAddrParams struct {
|
||||
DelegatorAddress sdk.AccAddress `json:"delegator_address"`
|
||||
}
|
||||
|
||||
// NewQueryDelegatorWithdrawAddrParams creates a new instance of QueryDelegatorWithdrawAddrParams.
|
||||
func NewQueryDelegatorWithdrawAddrParams(delegatorAddr sdk.AccAddress) QueryDelegatorWithdrawAddrParams {
|
||||
return QueryDelegatorWithdrawAddrParams{DelegatorAddress: delegatorAddr}
|
||||
}
|
||||
|
||||
func queryDelegatorWithdrawAddress(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper) ([]byte, sdk.Error) {
|
||||
var params QueryDelegatorWithdrawAddrParams
|
||||
var params types.QueryDelegatorWithdrawAddrParams
|
||||
err := k.cdc.UnmarshalJSON(req.Data, ¶ms)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrUnknownRequest(sdk.AppendMsgToErr("incorrectly formatted request data", err.Error()))
|
||||
|
|
|
@ -19,38 +19,38 @@ const custom = "custom"
|
|||
func getQueriedParams(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier) (communityTax sdk.Dec, baseProposerReward sdk.Dec, bonusProposerReward sdk.Dec, withdrawAddrEnabled bool) {
|
||||
|
||||
query := abci.RequestQuery{
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, QueryParams, ParamCommunityTax}, "/"),
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryParams, types.ParamCommunityTax}, "/"),
|
||||
Data: []byte{},
|
||||
}
|
||||
|
||||
bz, err := querier(ctx, []string{QueryParams, ParamCommunityTax}, query)
|
||||
bz, err := querier(ctx, []string{types.QueryParams, types.ParamCommunityTax}, query)
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, cdc.UnmarshalJSON(bz, &communityTax))
|
||||
|
||||
query = abci.RequestQuery{
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, QueryParams, ParamBaseProposerReward}, "/"),
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryParams, types.ParamBaseProposerReward}, "/"),
|
||||
Data: []byte{},
|
||||
}
|
||||
|
||||
bz, err = querier(ctx, []string{QueryParams, ParamBaseProposerReward}, query)
|
||||
bz, err = querier(ctx, []string{types.QueryParams, types.ParamBaseProposerReward}, query)
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, cdc.UnmarshalJSON(bz, &baseProposerReward))
|
||||
|
||||
query = abci.RequestQuery{
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, QueryParams, ParamBonusProposerReward}, "/"),
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryParams, types.ParamBonusProposerReward}, "/"),
|
||||
Data: []byte{},
|
||||
}
|
||||
|
||||
bz, err = querier(ctx, []string{QueryParams, ParamBonusProposerReward}, query)
|
||||
bz, err = querier(ctx, []string{types.QueryParams, types.ParamBonusProposerReward}, query)
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, cdc.UnmarshalJSON(bz, &bonusProposerReward))
|
||||
|
||||
query = abci.RequestQuery{
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, QueryParams, ParamWithdrawAddrEnabled}, "/"),
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryParams, types.ParamWithdrawAddrEnabled}, "/"),
|
||||
Data: []byte{},
|
||||
}
|
||||
|
||||
bz, err = querier(ctx, []string{QueryParams, ParamWithdrawAddrEnabled}, query)
|
||||
bz, err = querier(ctx, []string{types.QueryParams, types.ParamWithdrawAddrEnabled}, query)
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, cdc.UnmarshalJSON(bz, &withdrawAddrEnabled))
|
||||
|
||||
|
@ -59,11 +59,11 @@ func getQueriedParams(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier s
|
|||
|
||||
func getQueriedValidatorOutstandingRewards(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, validatorAddr sdk.ValAddress) (outstandingRewards sdk.DecCoins) {
|
||||
query := abci.RequestQuery{
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, QueryValidatorOutstandingRewards}, "/"),
|
||||
Data: cdc.MustMarshalJSON(NewQueryValidatorOutstandingRewardsParams(validatorAddr)),
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryValidatorOutstandingRewards}, "/"),
|
||||
Data: cdc.MustMarshalJSON(types.NewQueryValidatorOutstandingRewardsParams(validatorAddr)),
|
||||
}
|
||||
|
||||
bz, err := querier(ctx, []string{QueryValidatorOutstandingRewards}, query)
|
||||
bz, err := querier(ctx, []string{types.QueryValidatorOutstandingRewards}, query)
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, cdc.UnmarshalJSON(bz, &outstandingRewards))
|
||||
|
||||
|
@ -72,11 +72,11 @@ func getQueriedValidatorOutstandingRewards(t *testing.T, ctx sdk.Context, cdc *c
|
|||
|
||||
func getQueriedValidatorCommission(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, validatorAddr sdk.ValAddress) (validatorCommission sdk.DecCoins) {
|
||||
query := abci.RequestQuery{
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, QueryValidatorCommission}, "/"),
|
||||
Data: cdc.MustMarshalJSON(NewQueryValidatorCommissionParams(validatorAddr)),
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryValidatorCommission}, "/"),
|
||||
Data: cdc.MustMarshalJSON(types.NewQueryValidatorCommissionParams(validatorAddr)),
|
||||
}
|
||||
|
||||
bz, err := querier(ctx, []string{QueryValidatorCommission}, query)
|
||||
bz, err := querier(ctx, []string{types.QueryValidatorCommission}, query)
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, cdc.UnmarshalJSON(bz, &validatorCommission))
|
||||
|
||||
|
@ -85,11 +85,11 @@ func getQueriedValidatorCommission(t *testing.T, ctx sdk.Context, cdc *codec.Cod
|
|||
|
||||
func getQueriedValidatorSlashes(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, validatorAddr sdk.ValAddress, startHeight uint64, endHeight uint64) (slashes []types.ValidatorSlashEvent) {
|
||||
query := abci.RequestQuery{
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, QueryValidatorSlashes}, "/"),
|
||||
Data: cdc.MustMarshalJSON(NewQueryValidatorSlashesParams(validatorAddr, startHeight, endHeight)),
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryValidatorSlashes}, "/"),
|
||||
Data: cdc.MustMarshalJSON(types.NewQueryValidatorSlashesParams(validatorAddr, startHeight, endHeight)),
|
||||
}
|
||||
|
||||
bz, err := querier(ctx, []string{QueryValidatorSlashes}, query)
|
||||
bz, err := querier(ctx, []string{types.QueryValidatorSlashes}, query)
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, cdc.UnmarshalJSON(bz, &slashes))
|
||||
|
||||
|
@ -98,11 +98,11 @@ func getQueriedValidatorSlashes(t *testing.T, ctx sdk.Context, cdc *codec.Codec,
|
|||
|
||||
func getQueriedDelegationRewards(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) (rewards sdk.DecCoins) {
|
||||
query := abci.RequestQuery{
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, QueryDelegationRewards}, "/"),
|
||||
Data: cdc.MustMarshalJSON(NewQueryDelegationRewardsParams(delegatorAddr, validatorAddr)),
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryDelegationRewards}, "/"),
|
||||
Data: cdc.MustMarshalJSON(types.NewQueryDelegationRewardsParams(delegatorAddr, validatorAddr)),
|
||||
}
|
||||
|
||||
bz, err := querier(ctx, []string{QueryDelegationRewards}, query)
|
||||
bz, err := querier(ctx, []string{types.QueryDelegationRewards}, query)
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, cdc.UnmarshalJSON(bz, &rewards))
|
||||
|
||||
|
@ -111,11 +111,11 @@ func getQueriedDelegationRewards(t *testing.T, ctx sdk.Context, cdc *codec.Codec
|
|||
|
||||
func getQueriedDelegatorTotalRewards(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, delegatorAddr sdk.AccAddress) (response types.QueryDelegatorTotalRewardsResponse) {
|
||||
query := abci.RequestQuery{
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, QueryDelegatorTotalRewards}, "/"),
|
||||
Data: cdc.MustMarshalJSON(NewQueryDelegatorParams(delegatorAddr)),
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryDelegatorTotalRewards}, "/"),
|
||||
Data: cdc.MustMarshalJSON(types.NewQueryDelegatorParams(delegatorAddr)),
|
||||
}
|
||||
|
||||
bz, err := querier(ctx, []string{QueryDelegatorTotalRewards}, query)
|
||||
bz, err := querier(ctx, []string{types.QueryDelegatorTotalRewards}, query)
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, cdc.UnmarshalJSON(bz, &response))
|
||||
|
||||
|
@ -124,11 +124,11 @@ func getQueriedDelegatorTotalRewards(t *testing.T, ctx sdk.Context, cdc *codec.C
|
|||
|
||||
func getQueriedCommunityPool(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier) (ptr []byte) {
|
||||
query := abci.RequestQuery{
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, QueryCommunityPool}, ""),
|
||||
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryCommunityPool}, ""),
|
||||
Data: []byte{},
|
||||
}
|
||||
|
||||
cp, err := querier(ctx, []string{QueryCommunityPool}, query)
|
||||
cp, err := querier(ctx, []string{types.QueryCommunityPool}, query)
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, cdc.UnmarshalJSON(cp, &ptr))
|
||||
|
||||
|
|
|
@ -3,14 +3,22 @@ package distribution
|
|||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"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/types/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/client/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/client/rest"
|
||||
)
|
||||
|
||||
var (
|
||||
_ sdk.AppModule = AppModule{}
|
||||
_ sdk.AppModuleBasic = AppModuleBasic{}
|
||||
_ module.AppModule = AppModule{}
|
||||
_ module.AppModuleBasic = AppModuleBasic{}
|
||||
)
|
||||
|
||||
// app module basics object
|
||||
|
@ -41,6 +49,21 @@ 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) {
|
||||
rest.RegisterRoutes(ctx, rtr, cdc, StoreKey)
|
||||
}
|
||||
|
||||
// get the root tx command of this module
|
||||
func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||
return cli.GetTxCmd(StoreKey, cdc)
|
||||
}
|
||||
|
||||
// get the root query command of this module
|
||||
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
|
||||
return cli.GetQueryCmd(StoreKey, cdc)
|
||||
}
|
||||
|
||||
// app module
|
||||
type AppModule struct {
|
||||
AppModuleBasic
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue