Merge remote-tracking branch 'origin/develop' into rigel/fee-distribution
This commit is contained in:
+3
-3
@@ -3,8 +3,8 @@ package auth
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
)
|
||||
|
||||
@@ -119,8 +119,8 @@ func (acc *BaseAccount) SetSequence(seq int64) error {
|
||||
// Wire
|
||||
|
||||
// Most users shouldn't use this, but this comes handy for tests.
|
||||
func RegisterBaseAccount(cdc *wire.Codec) {
|
||||
func RegisterBaseAccount(cdc *codec.Codec) {
|
||||
cdc.RegisterInterface((*Account)(nil), nil)
|
||||
cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/BaseAccount", nil)
|
||||
wire.RegisterCrypto(cdc)
|
||||
codec.RegisterCrypto(cdc)
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
wire "github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) {
|
||||
@@ -90,20 +90,19 @@ func TestBaseAccountMarshal(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// need a codec for marshaling
|
||||
codec := wire.NewCodec()
|
||||
wire.RegisterCrypto(codec)
|
||||
cdc := codec.New()
|
||||
codec.RegisterCrypto(cdc)
|
||||
|
||||
b, err := codec.MarshalBinary(acc)
|
||||
b, err := cdc.MarshalBinary(acc)
|
||||
require.Nil(t, err)
|
||||
|
||||
acc2 := BaseAccount{}
|
||||
err = codec.UnmarshalBinary(b, &acc2)
|
||||
err = cdc.UnmarshalBinary(b, &acc2)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, acc, acc2)
|
||||
|
||||
// error on bad bytes
|
||||
acc2 = BaseAccount{}
|
||||
err = codec.UnmarshalBinary(b[:len(b)/2], &acc2)
|
||||
err = cdc.UnmarshalBinary(b[:len(b)/2], &acc2)
|
||||
require.NotNil(t, err)
|
||||
|
||||
}
|
||||
|
||||
+10
-10
@@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
wire "github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
@@ -110,7 +110,7 @@ func newTestTxWithSignBytes(msgs []sdk.Msg, privs []crypto.PrivKey, accNums []in
|
||||
func TestAnteHandlerSigErrors(t *testing.T) {
|
||||
// setup
|
||||
ms, capKey, capKey2 := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
RegisterBaseAccount(cdc)
|
||||
mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount)
|
||||
feeCollector := NewFeeCollectionKeeper(cdc, capKey2)
|
||||
@@ -163,7 +163,7 @@ func TestAnteHandlerSigErrors(t *testing.T) {
|
||||
func TestAnteHandlerAccountNumbers(t *testing.T) {
|
||||
// setup
|
||||
ms, capKey, capKey2 := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
RegisterBaseAccount(cdc)
|
||||
mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount)
|
||||
feeCollector := NewFeeCollectionKeeper(cdc, capKey2)
|
||||
@@ -222,7 +222,7 @@ func TestAnteHandlerAccountNumbers(t *testing.T) {
|
||||
func TestAnteHandlerSequences(t *testing.T) {
|
||||
// setup
|
||||
ms, capKey, capKey2 := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
RegisterBaseAccount(cdc)
|
||||
mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount)
|
||||
feeCollector := NewFeeCollectionKeeper(cdc, capKey2)
|
||||
@@ -300,7 +300,7 @@ func TestAnteHandlerSequences(t *testing.T) {
|
||||
func TestAnteHandlerFees(t *testing.T) {
|
||||
// setup
|
||||
ms, capKey, capKey2 := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
RegisterBaseAccount(cdc)
|
||||
mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount)
|
||||
feeCollector := NewFeeCollectionKeeper(cdc, capKey2)
|
||||
@@ -342,7 +342,7 @@ func TestAnteHandlerFees(t *testing.T) {
|
||||
func TestAnteHandlerMemoGas(t *testing.T) {
|
||||
// setup
|
||||
ms, capKey, capKey2 := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
RegisterBaseAccount(cdc)
|
||||
mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount)
|
||||
feeCollector := NewFeeCollectionKeeper(cdc, capKey2)
|
||||
@@ -385,7 +385,7 @@ func TestAnteHandlerMemoGas(t *testing.T) {
|
||||
func TestAnteHandlerMultiSigner(t *testing.T) {
|
||||
// setup
|
||||
ms, capKey, capKey2 := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
RegisterBaseAccount(cdc)
|
||||
mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount)
|
||||
feeCollector := NewFeeCollectionKeeper(cdc, capKey2)
|
||||
@@ -436,7 +436,7 @@ func TestAnteHandlerMultiSigner(t *testing.T) {
|
||||
func TestAnteHandlerBadSignBytes(t *testing.T) {
|
||||
// setup
|
||||
ms, capKey, capKey2 := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
RegisterBaseAccount(cdc)
|
||||
mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount)
|
||||
feeCollector := NewFeeCollectionKeeper(cdc, capKey2)
|
||||
@@ -517,7 +517,7 @@ func TestAnteHandlerBadSignBytes(t *testing.T) {
|
||||
func TestAnteHandlerSetPubKey(t *testing.T) {
|
||||
// setup
|
||||
ms, capKey, capKey2 := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
RegisterBaseAccount(cdc)
|
||||
mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount)
|
||||
feeCollector := NewFeeCollectionKeeper(cdc, capKey2)
|
||||
@@ -570,7 +570,7 @@ func TestAnteHandlerSetPubKey(t *testing.T) {
|
||||
|
||||
func TestProcessPubKey(t *testing.T) {
|
||||
ms, capKey, _ := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
RegisterBaseAccount(cdc)
|
||||
mapper := NewAccountMapper(cdc, capKey, ProtoBaseAccount)
|
||||
ctx := sdk.NewContext(ms, abci.Header{ChainID: "mychainid"}, false, log.NewNopLogger())
|
||||
|
||||
@@ -6,18 +6,18 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"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/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
)
|
||||
|
||||
// GetAccountCmdDefault invokes the GetAccountCmd for the auth.BaseAccount type.
|
||||
func GetAccountCmdDefault(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetAccountCmdDefault(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
return GetAccountCmd(storeName, cdc, GetAccountDecoder(cdc))
|
||||
}
|
||||
|
||||
// GetAccountDecoder gets the account decoder for auth.DefaultAccount.
|
||||
func GetAccountDecoder(cdc *wire.Codec) auth.AccountDecoder {
|
||||
func GetAccountDecoder(cdc *codec.Codec) auth.AccountDecoder {
|
||||
return func(accBytes []byte) (acct auth.Account, err error) {
|
||||
err = cdc.UnmarshalBinaryBare(accBytes, &acct)
|
||||
if err != nil {
|
||||
@@ -31,7 +31,7 @@ func GetAccountDecoder(cdc *wire.Codec) auth.AccountDecoder {
|
||||
// GetAccountCmd returns a query account that will display the state of the
|
||||
// account at a given address.
|
||||
// nolint: unparam
|
||||
func GetAccountCmd(storeName string, cdc *wire.Codec, decoder auth.AccountDecoder) *cobra.Command {
|
||||
func GetAccountCmd(storeName string, cdc *codec.Codec, decoder auth.AccountDecoder) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "account [address]",
|
||||
Short: "Query account balance",
|
||||
@@ -58,7 +58,7 @@ func GetAccountCmd(storeName string, cdc *wire.Codec, decoder auth.AccountDecode
|
||||
return err
|
||||
}
|
||||
|
||||
output, err := wire.MarshalJSONIndent(cdc, acc)
|
||||
output, err := codec.MarshalJSONIndent(cdc, acc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
"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/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
// register REST routes
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, storeName string) {
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, storeName string) {
|
||||
r.HandleFunc(
|
||||
"/accounts/{address}",
|
||||
QueryAccountRequestHandlerFn(storeName, cdc, authcmd.GetAccountDecoder(cdc), cliCtx),
|
||||
@@ -28,7 +28,7 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, s
|
||||
|
||||
// query accountREST Handler
|
||||
func QueryAccountRequestHandlerFn(
|
||||
storeName string, cdc *wire.Codec,
|
||||
storeName string, cdc *codec.Codec,
|
||||
decoder auth.AccountDecoder, cliCtx context.CLIContext,
|
||||
) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
)
|
||||
@@ -22,8 +22,9 @@ type SignBody struct {
|
||||
AppendSig bool `json:"append_sig"`
|
||||
}
|
||||
|
||||
// nolint: unparam
|
||||
// sign tx REST handler
|
||||
func SignTxRequestHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
func SignTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var m SignBody
|
||||
@@ -51,7 +52,7 @@ func SignTxRequestHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.Han
|
||||
return
|
||||
}
|
||||
|
||||
output, err := wire.MarshalJSONIndent(cdc, signedTx)
|
||||
output, err := codec.MarshalJSONIndent(cdc, signedTx)
|
||||
if err != nil {
|
||||
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
||||
@@ -3,8 +3,8 @@ package context
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"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/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
// TxBuilder implements a transaction context created in SDK modules.
|
||||
type TxBuilder struct {
|
||||
Codec *wire.Codec
|
||||
Codec *codec.Codec
|
||||
AccountNumber int64
|
||||
Sequence int64
|
||||
Gas int64 // TODO: should this turn into uint64? requires further discussion - see #2173
|
||||
@@ -49,7 +49,7 @@ func NewTxBuilderFromCLI() TxBuilder {
|
||||
}
|
||||
|
||||
// WithCodec returns a copy of the context with an updated codec.
|
||||
func (bldr TxBuilder) WithCodec(cdc *wire.Codec) TxBuilder {
|
||||
func (bldr TxBuilder) WithCodec(cdc *codec.Codec) TxBuilder {
|
||||
bldr.Codec = cdc
|
||||
return bldr
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
)
|
||||
|
||||
// Register concrete types on codec codec for default AppAccount
|
||||
func RegisterCodec(cdc *codec.Codec) {
|
||||
cdc.RegisterInterface((*Account)(nil), nil)
|
||||
cdc.RegisterConcrete(&BaseAccount{}, "auth/Account", nil)
|
||||
cdc.RegisterConcrete(StdTx{}, "auth/StdTx", nil)
|
||||
}
|
||||
|
||||
var msgCdc = codec.New()
|
||||
|
||||
func init() {
|
||||
RegisterCodec(msgCdc)
|
||||
codec.RegisterCrypto(msgCdc)
|
||||
}
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
wire "github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -16,11 +16,11 @@ type FeeCollectionKeeper struct {
|
||||
// The (unexposed) key used to access the fee store from the Context.
|
||||
key sdk.StoreKey
|
||||
|
||||
// The wire codec for binary encoding/decoding of accounts.
|
||||
cdc *wire.Codec
|
||||
// The codec codec for binary encoding/decoding of accounts.
|
||||
cdc *codec.Codec
|
||||
}
|
||||
|
||||
func NewFeeCollectionKeeper(cdc *wire.Codec, key sdk.StoreKey) FeeCollectionKeeper {
|
||||
func NewFeeCollectionKeeper(cdc *codec.Codec, key sdk.StoreKey) FeeCollectionKeeper {
|
||||
return FeeCollectionKeeper{
|
||||
key: key,
|
||||
cdc: cdc,
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
wire "github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -20,7 +20,7 @@ var (
|
||||
|
||||
func TestFeeCollectionKeeperGetSet(t *testing.T) {
|
||||
ms, _, capKey2 := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
|
||||
// make context and keeper
|
||||
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger())
|
||||
@@ -39,7 +39,7 @@ func TestFeeCollectionKeeperGetSet(t *testing.T) {
|
||||
|
||||
func TestFeeCollectionKeeperAdd(t *testing.T) {
|
||||
ms, _, capKey2 := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
|
||||
// make context and keeper
|
||||
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger())
|
||||
@@ -59,7 +59,7 @@ func TestFeeCollectionKeeperAdd(t *testing.T) {
|
||||
|
||||
func TestFeeCollectionKeeperClear(t *testing.T) {
|
||||
ms, _, capKey2 := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
|
||||
// make context and keeper
|
||||
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger())
|
||||
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
wire "github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
)
|
||||
|
||||
@@ -18,14 +18,14 @@ type AccountMapper struct {
|
||||
// The prototypical Account constructor.
|
||||
proto func() Account
|
||||
|
||||
// The wire codec for binary encoding/decoding of accounts.
|
||||
cdc *wire.Codec
|
||||
// The codec codec for binary encoding/decoding of accounts.
|
||||
cdc *codec.Codec
|
||||
}
|
||||
|
||||
// NewAccountMapper returns a new sdk.AccountMapper that
|
||||
// uses go-amino to (binary) encode and decode concrete sdk.Accounts.
|
||||
// nolint
|
||||
func NewAccountMapper(cdc *wire.Codec, key sdk.StoreKey, proto func() Account) AccountMapper {
|
||||
func NewAccountMapper(cdc *codec.Codec, key sdk.StoreKey, proto func() Account) AccountMapper {
|
||||
return AccountMapper{
|
||||
key: key,
|
||||
proto: proto,
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
dbm "github.com/tendermint/tendermint/libs/db"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
wire "github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey, *sdk.KVStoreKey) {
|
||||
@@ -27,7 +27,7 @@ func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey, *sdk.KVStoreKey) {
|
||||
|
||||
func TestAccountMapperGetSet(t *testing.T) {
|
||||
ms, capKey, _ := setupMultiStore()
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
RegisterBaseAccount(cdc)
|
||||
|
||||
// make context and mapper
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@ package auth
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
)
|
||||
|
||||
@@ -165,7 +165,7 @@ type StdSignature struct {
|
||||
}
|
||||
|
||||
// logic for standard transaction decoding
|
||||
func DefaultTxDecoder(cdc *wire.Codec) sdk.TxDecoder {
|
||||
func DefaultTxDecoder(cdc *codec.Codec) sdk.TxDecoder {
|
||||
return func(txBytes []byte) (sdk.Tx, sdk.Error) {
|
||||
var tx = StdTx{}
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
// Register concrete types on wire codec for default AppAccount
|
||||
func RegisterWire(cdc *wire.Codec) {
|
||||
cdc.RegisterInterface((*Account)(nil), nil)
|
||||
cdc.RegisterConcrete(&BaseAccount{}, "auth/Account", nil)
|
||||
cdc.RegisterConcrete(StdTx{}, "auth/StdTx", nil)
|
||||
}
|
||||
|
||||
var msgCdc = wire.NewCodec()
|
||||
|
||||
func init() {
|
||||
RegisterWire(msgCdc)
|
||||
wire.RegisterCrypto(msgCdc)
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
func getBenchmarkMockApp() (*mock.App, error) {
|
||||
mapp := mock.NewApp()
|
||||
|
||||
RegisterWire(mapp.Cdc)
|
||||
RegisterCodec(mapp.Cdc)
|
||||
bankKeeper := NewBaseKeeper(mapp.AccountMapper)
|
||||
mapp.Router().AddRoute("bank", NewHandler(bankKeeper))
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"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/wire"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/client"
|
||||
@@ -22,7 +22,7 @@ const (
|
||||
)
|
||||
|
||||
// SendTxCmd will create a send tx and sign it with the given key.
|
||||
func SendTxCmd(cdc *wire.Codec) *cobra.Command {
|
||||
func SendTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "send",
|
||||
Short: "Create and sign a send tx",
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
)
|
||||
|
||||
@@ -15,7 +15,7 @@ type broadcastBody struct {
|
||||
}
|
||||
|
||||
// BroadcastTxRequestHandlerFn returns the broadcast tx REST handler
|
||||
func BroadcastTxRequestHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
func BroadcastTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var m broadcastBody
|
||||
if ok := unmarshalBodyOrReturnBadRequest(cliCtx, w, r, &m); !ok {
|
||||
@@ -33,7 +33,7 @@ func BroadcastTxRequestHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) htt
|
||||
return
|
||||
}
|
||||
|
||||
output, err := wire.MarshalJSONIndent(cdc, res)
|
||||
output, err := codec.MarshalJSONIndent(cdc, res)
|
||||
if err != nil {
|
||||
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
cliclient "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"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/client"
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
// RegisterRoutes - Central function to define routes that get registered by the main application
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) {
|
||||
r.HandleFunc("/accounts/{address}/send", SendRequestHandlerFn(cdc, kb, cliCtx)).Methods("POST")
|
||||
r.HandleFunc("/tx/broadcast", BroadcastTxRequestHandlerFn(cdc, cliCtx)).Methods("POST")
|
||||
}
|
||||
@@ -36,15 +36,15 @@ type sendBody struct {
|
||||
GasAdjustment string `json:"gas_adjustment"`
|
||||
}
|
||||
|
||||
var msgCdc = wire.NewCodec()
|
||||
var msgCdc = codec.New()
|
||||
|
||||
func init() {
|
||||
bank.RegisterWire(msgCdc)
|
||||
bank.RegisterCodec(msgCdc)
|
||||
}
|
||||
|
||||
// SendRequestHandlerFn - http request handler to send coins to a address
|
||||
// nolint: gocyclo
|
||||
func SendRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
func SendRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// collect data
|
||||
vars := mux.Vars(r)
|
||||
@@ -131,7 +131,7 @@ func SendRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLICo
|
||||
return
|
||||
}
|
||||
|
||||
output, err := wire.MarshalJSONIndent(cdc, res)
|
||||
output, err := codec.MarshalJSONIndent(cdc, res)
|
||||
if err != nil {
|
||||
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package bank
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
)
|
||||
|
||||
// Register concrete types on codec codec
|
||||
func RegisterCodec(cdc *codec.Codec) {
|
||||
cdc.RegisterConcrete(MsgSend{}, "cosmos-sdk/Send", nil)
|
||||
cdc.RegisterConcrete(MsgIssue{}, "cosmos-sdk/Issue", nil)
|
||||
}
|
||||
|
||||
var msgCdc = codec.New()
|
||||
|
||||
func init() {
|
||||
RegisterCodec(msgCdc)
|
||||
}
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
dbm "github.com/tendermint/tendermint/libs/db"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/store"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
wire "github.com/cosmos/cosmos-sdk/wire"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
)
|
||||
@@ -29,7 +29,7 @@ func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey) {
|
||||
func TestKeeper(t *testing.T) {
|
||||
ms, authKey := setupMultiStore()
|
||||
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
auth.RegisterBaseAccount(cdc)
|
||||
|
||||
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger())
|
||||
@@ -114,7 +114,7 @@ func TestKeeper(t *testing.T) {
|
||||
func TestSendKeeper(t *testing.T) {
|
||||
ms, authKey := setupMultiStore()
|
||||
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
auth.RegisterBaseAccount(cdc)
|
||||
|
||||
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger())
|
||||
@@ -183,7 +183,7 @@ func TestSendKeeper(t *testing.T) {
|
||||
func TestViewKeeper(t *testing.T) {
|
||||
ms, authKey := setupMultiStore()
|
||||
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
auth.RegisterBaseAccount(cdc)
|
||||
|
||||
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger())
|
||||
|
||||
@@ -20,7 +20,9 @@ func NewMsgSend(in []Input, out []Output) MsgSend {
|
||||
}
|
||||
|
||||
// Implements Msg.
|
||||
// nolint
|
||||
func (msg MsgSend) Type() string { return "bank" } // TODO: "bank/send"
|
||||
func (msg MsgSend) Name() string { return "send" }
|
||||
|
||||
// Implements Msg.
|
||||
func (msg MsgSend) ValidateBasic() sdk.Error {
|
||||
@@ -101,7 +103,9 @@ func NewMsgIssue(banker sdk.AccAddress, out []Output) MsgIssue {
|
||||
}
|
||||
|
||||
// Implements Msg.
|
||||
// nolint
|
||||
func (msg MsgIssue) Type() string { return "bank" } // TODO: "bank/issue"
|
||||
func (msg MsgIssue) Name() string { return "issue" }
|
||||
|
||||
// Implements Msg.
|
||||
func (msg MsgIssue) ValidateBasic() sdk.Error {
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
func TestBankWithRandomMessages(t *testing.T) {
|
||||
mapp := mock.NewApp()
|
||||
|
||||
bank.RegisterWire(mapp.Cdc)
|
||||
bank.RegisterCodec(mapp.Cdc)
|
||||
mapper := mapp.AccountMapper
|
||||
bankKeeper := bank.NewBaseKeeper(mapper)
|
||||
mapp.Router().AddRoute("bank", bank.NewHandler(bankKeeper))
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package bank
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
// Register concrete types on wire codec
|
||||
func RegisterWire(cdc *wire.Codec) {
|
||||
cdc.RegisterConcrete(MsgSend{}, "cosmos-sdk/Send", nil)
|
||||
cdc.RegisterConcrete(MsgIssue{}, "cosmos-sdk/Issue", nil)
|
||||
}
|
||||
|
||||
var msgCdc = wire.NewCodec()
|
||||
|
||||
func init() {
|
||||
RegisterWire(msgCdc)
|
||||
}
|
||||
@@ -3,14 +3,14 @@ package stake
|
||||
//// keeper of the staking store
|
||||
//type Keeper struct {
|
||||
//storeKey sdk.StoreKey
|
||||
//cdc *wire.Codec
|
||||
//cdc *codec.Codec
|
||||
//bankKeeper bank.Keeper
|
||||
|
||||
//// codespace
|
||||
//codespace sdk.CodespaceType
|
||||
//}
|
||||
|
||||
//func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ck bank.Keeper, codespace sdk.CodespaceType) Keeper {
|
||||
//func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, ck bank.Keeper, codespace sdk.CodespaceType) Keeper {
|
||||
//keeper := Keeper{
|
||||
//storeKey: key,
|
||||
//cdc: cdc,
|
||||
|
||||
+11
-11
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
"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/wire"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||
@@ -49,7 +49,7 @@ var proposalFlags = []string{
|
||||
}
|
||||
|
||||
// GetCmdSubmitProposal implements submitting a proposal transaction command.
|
||||
func GetCmdSubmitProposal(cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdSubmitProposal(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "submit-proposal",
|
||||
Short: "Submit a proposal along with an initial deposit",
|
||||
@@ -156,7 +156,7 @@ func parseSubmitProposalFlags() (*proposal, error) {
|
||||
}
|
||||
|
||||
// GetCmdDeposit implements depositing tokens for an active proposal.
|
||||
func GetCmdDeposit(cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdDeposit(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "deposit",
|
||||
Short: "deposit tokens for activing proposal",
|
||||
@@ -202,7 +202,7 @@ func GetCmdDeposit(cdc *wire.Codec) *cobra.Command {
|
||||
}
|
||||
|
||||
// GetCmdVote implements creating a new vote command.
|
||||
func GetCmdVote(cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdVote(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "vote",
|
||||
Short: "vote for an active proposal, options: Yes/No/NoWithVeto/Abstain",
|
||||
@@ -253,7 +253,7 @@ func GetCmdVote(cdc *wire.Codec) *cobra.Command {
|
||||
}
|
||||
|
||||
// GetCmdQueryProposal implements the query proposal command.
|
||||
func GetCmdQueryProposal(queryRoute string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "query-proposal",
|
||||
Short: "query proposal details",
|
||||
@@ -287,7 +287,7 @@ func GetCmdQueryProposal(queryRoute string, cdc *wire.Codec) *cobra.Command {
|
||||
|
||||
// nolint: gocyclo
|
||||
// GetCmdQueryProposals implements a query proposals command.
|
||||
func GetCmdQueryProposals(queryRoute string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "query-proposals",
|
||||
Short: "query proposals with optional filters",
|
||||
@@ -366,7 +366,7 @@ func GetCmdQueryProposals(queryRoute string, cdc *wire.Codec) *cobra.Command {
|
||||
|
||||
// Command to Get a Proposal Information
|
||||
// GetCmdQueryVote implements the query proposal vote command.
|
||||
func GetCmdQueryVote(queryRoute string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryVote(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "query-vote",
|
||||
Short: "query vote",
|
||||
@@ -405,7 +405,7 @@ func GetCmdQueryVote(queryRoute string, cdc *wire.Codec) *cobra.Command {
|
||||
}
|
||||
|
||||
// GetCmdQueryVotes implements the command to query for proposal votes.
|
||||
func GetCmdQueryVotes(queryRoute string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "query-votes",
|
||||
Short: "query votes on a proposal",
|
||||
@@ -438,7 +438,7 @@ func GetCmdQueryVotes(queryRoute string, cdc *wire.Codec) *cobra.Command {
|
||||
|
||||
// Command to Get a specific Deposit Information
|
||||
// GetCmdQueryDeposit implements the query proposal deposit command.
|
||||
func GetCmdQueryDeposit(queryRoute string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "query-deposit",
|
||||
Short: "query deposit",
|
||||
@@ -477,7 +477,7 @@ func GetCmdQueryDeposit(queryRoute string, cdc *wire.Codec) *cobra.Command {
|
||||
}
|
||||
|
||||
// GetCmdQueryDeposits implements the command to query for proposal deposits.
|
||||
func GetCmdQueryDeposits(queryRoute string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryDeposits(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "query-deposits",
|
||||
Short: "query deposits on a proposal",
|
||||
@@ -509,7 +509,7 @@ func GetCmdQueryDeposits(queryRoute string, cdc *wire.Codec) *cobra.Command {
|
||||
}
|
||||
|
||||
// GetCmdQueryDeposits implements the command to query for proposal deposits.
|
||||
func GetCmdQueryTally(queryRoute string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryTally(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "query-tally",
|
||||
Short: "get the tally of a proposal vote",
|
||||
|
||||
+11
-11
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
"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/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
@@ -26,7 +26,7 @@ const (
|
||||
)
|
||||
|
||||
// RegisterRoutes - Central function to define routes that get registered by the main application
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec) {
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
|
||||
r.HandleFunc("/gov/proposals", postProposalHandlerFn(cdc, cliCtx)).Methods("POST")
|
||||
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), depositHandlerFn(cdc, cliCtx)).Methods("POST")
|
||||
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), voteHandlerFn(cdc, cliCtx)).Methods("POST")
|
||||
@@ -61,7 +61,7 @@ type voteReq struct {
|
||||
Option gov.VoteOption `json:"option"` // option from OptionSet chosen by the voter
|
||||
}
|
||||
|
||||
func postProposalHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
func postProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req postProposalReq
|
||||
err := buildReq(w, r, cdc, &req)
|
||||
@@ -85,7 +85,7 @@ func postProposalHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.Hand
|
||||
}
|
||||
}
|
||||
|
||||
func depositHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
func depositHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
strProposalID := vars[RestProposalID]
|
||||
@@ -122,7 +122,7 @@ func depositHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFu
|
||||
}
|
||||
}
|
||||
|
||||
func voteHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
func voteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
strProposalID := vars[RestProposalID]
|
||||
@@ -159,7 +159,7 @@ func voteHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc
|
||||
}
|
||||
}
|
||||
|
||||
func queryProposalHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||
func queryProposalHandlerFn(cdc *codec.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
strProposalID := vars[RestProposalID]
|
||||
@@ -197,7 +197,7 @@ func queryProposalHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func queryDepositHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||
func queryDepositHandlerFn(cdc *codec.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
strProposalID := vars[RestProposalID]
|
||||
@@ -264,7 +264,7 @@ func queryDepositHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func queryVoteHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||
func queryVoteHandlerFn(cdc *codec.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
strProposalID := vars[RestProposalID]
|
||||
@@ -336,7 +336,7 @@ func queryVoteHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||
|
||||
// nolint: gocyclo
|
||||
// todo: Split this functionality into helper functions to remove the above
|
||||
func queryVotesOnProposalHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||
func queryVotesOnProposalHandlerFn(cdc *codec.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
strProposalID := vars[RestProposalID]
|
||||
@@ -375,7 +375,7 @@ func queryVotesOnProposalHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||
|
||||
// nolint: gocyclo
|
||||
// todo: Split this functionality into helper functions to remove the above
|
||||
func queryProposalsWithParameterFn(cdc *wire.Codec) http.HandlerFunc {
|
||||
func queryProposalsWithParameterFn(cdc *codec.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
bechVoterAddr := r.URL.Query().Get(RestVoter)
|
||||
bechDepositerAddr := r.URL.Query().Get(RestDepositer)
|
||||
@@ -441,7 +441,7 @@ func queryProposalsWithParameterFn(cdc *wire.Codec) http.HandlerFunc {
|
||||
|
||||
// nolint: gocyclo
|
||||
// todo: Split this functionality into helper functions to remove the above
|
||||
func queryTallyOnProposalHandlerFn(cdc *wire.Codec) http.HandlerFunc {
|
||||
func queryTallyOnProposalHandlerFn(cdc *codec.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
strProposalID := vars[RestProposalID]
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"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/wire"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@ type baseReq struct {
|
||||
GasAdjustment string `json:"gas_adjustment"`
|
||||
}
|
||||
|
||||
func buildReq(w http.ResponseWriter, r *http.Request, cdc *wire.Codec, req interface{}) error {
|
||||
func buildReq(w http.ResponseWriter, r *http.Request, cdc *codec.Codec, req interface{}) error {
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||
@@ -68,7 +68,7 @@ func (req baseReq) baseReqValidate(w http.ResponseWriter) bool {
|
||||
|
||||
// TODO: Build this function out into a more generic base-request
|
||||
// (probably should live in client/lcd).
|
||||
func signAndBuild(w http.ResponseWriter, r *http.Request, cliCtx context.CLIContext, baseReq baseReq, msg sdk.Msg, cdc *wire.Codec) {
|
||||
func signAndBuild(w http.ResponseWriter, r *http.Request, cliCtx context.CLIContext, baseReq baseReq, msg sdk.Msg, cdc *codec.Codec) {
|
||||
simulateGas, gas, err := client.ReadGasFlag(baseReq.Gas)
|
||||
if err != nil {
|
||||
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||
@@ -119,7 +119,7 @@ func signAndBuild(w http.ResponseWriter, r *http.Request, cliCtx context.CLICont
|
||||
return
|
||||
}
|
||||
|
||||
output, err := wire.MarshalJSONIndent(cdc, res)
|
||||
output, err := codec.MarshalJSONIndent(cdc, res)
|
||||
if err != nil {
|
||||
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package gov
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
)
|
||||
|
||||
// Register concrete types on wire codec
|
||||
func RegisterWire(cdc *wire.Codec) {
|
||||
// Register concrete types on codec codec
|
||||
func RegisterCodec(cdc *codec.Codec) {
|
||||
|
||||
cdc.RegisterConcrete(MsgSubmitProposal{}, "cosmos-sdk/MsgSubmitProposal", nil)
|
||||
cdc.RegisterConcrete(MsgDeposit{}, "cosmos-sdk/MsgDeposit", nil)
|
||||
@@ -15,4 +15,4 @@ func RegisterWire(cdc *wire.Codec) {
|
||||
cdc.RegisterConcrete(&TextProposal{}, "gov/TextProposal", nil)
|
||||
}
|
||||
|
||||
var msgCdc = wire.NewCodec()
|
||||
var msgCdc = codec.New()
|
||||
+7
-7
@@ -1,8 +1,8 @@
|
||||
package gov
|
||||
|
||||
import (
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
wire "github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
"github.com/cosmos/cosmos-sdk/x/params"
|
||||
)
|
||||
@@ -31,15 +31,15 @@ type Keeper struct {
|
||||
// The (unexposed) keys used to access the stores from the Context.
|
||||
storeKey sdk.StoreKey
|
||||
|
||||
// The wire codec for binary encoding/decoding.
|
||||
cdc *wire.Codec
|
||||
// The codec codec for binary encoding/decoding.
|
||||
cdc *codec.Codec
|
||||
|
||||
// Reserved codespace
|
||||
codespace sdk.CodespaceType
|
||||
}
|
||||
|
||||
// NewGovernanceMapper returns a mapper that uses go-wire to (binary) encode and decode gov types.
|
||||
func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ps params.Setter, ck bank.Keeper, ds sdk.DelegationSet, codespace sdk.CodespaceType) Keeper {
|
||||
// NewGovernanceMapper returns a mapper that uses go-codec to (binary) encode and decode gov types.
|
||||
func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, ps params.Setter, ck bank.Keeper, ds sdk.DelegationSet, codespace sdk.CodespaceType) Keeper {
|
||||
return Keeper{
|
||||
storeKey: key,
|
||||
ps: ps,
|
||||
@@ -51,8 +51,8 @@ func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ps params.Setter, ck bank.Keep
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the go-wire codec.
|
||||
func (keeper Keeper) WireCodec() *wire.Codec {
|
||||
// Returns the go-codec codec.
|
||||
func (keeper Keeper) WireCodec() *codec.Codec {
|
||||
return keeper.cdc
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
// name to idetify transaction types
|
||||
const MsgType = "gov"
|
||||
|
||||
var _, _, _ sdk.Msg = MsgSubmitProposal{}, MsgDeposit{}, MsgVote{}
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// MsgSubmitProposal
|
||||
type MsgSubmitProposal struct {
|
||||
@@ -31,6 +33,7 @@ func NewMsgSubmitProposal(title string, description string, proposalType Proposa
|
||||
|
||||
// Implements Msg.
|
||||
func (msg MsgSubmitProposal) Type() string { return MsgType }
|
||||
func (msg MsgSubmitProposal) Name() string { return "submit_proposal" }
|
||||
|
||||
// Implements Msg.
|
||||
func (msg MsgSubmitProposal) ValidateBasic() sdk.Error {
|
||||
@@ -95,7 +98,9 @@ func NewMsgDeposit(depositer sdk.AccAddress, proposalID int64, amount sdk.Coins)
|
||||
}
|
||||
|
||||
// Implements Msg.
|
||||
// nolint
|
||||
func (msg MsgDeposit) Type() string { return MsgType }
|
||||
func (msg MsgDeposit) Name() string { return "deposit" }
|
||||
|
||||
// Implements Msg.
|
||||
func (msg MsgDeposit) ValidateBasic() sdk.Error {
|
||||
@@ -154,7 +159,9 @@ func NewMsgVote(voter sdk.AccAddress, proposalID int64, option VoteOption) MsgVo
|
||||
}
|
||||
|
||||
// Implements Msg.
|
||||
// nolint
|
||||
func (msg MsgVote) Type() string { return MsgType }
|
||||
func (msg MsgVote) Name() string { return "vote" }
|
||||
|
||||
// Implements Msg.
|
||||
func (msg MsgVote) ValidateBasic() sdk.Error {
|
||||
|
||||
+8
-8
@@ -3,8 +3,8 @@ package gov
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
@@ -60,7 +60,7 @@ func queryProposal(ctx sdk.Context, path []string, req abci.RequestQuery, keeper
|
||||
return []byte{}, ErrUnknownProposal(DefaultCodespace, params.ProposalID)
|
||||
}
|
||||
|
||||
bz, err2 := wire.MarshalJSONIndent(keeper.cdc, proposal)
|
||||
bz, err2 := codec.MarshalJSONIndent(keeper.cdc, proposal)
|
||||
if err2 != nil {
|
||||
panic("could not marshal result to JSON")
|
||||
}
|
||||
@@ -82,7 +82,7 @@ func queryDeposit(ctx sdk.Context, path []string, req abci.RequestQuery, keeper
|
||||
}
|
||||
|
||||
deposit, _ := keeper.GetDeposit(ctx, params.ProposalID, params.Depositer)
|
||||
bz, err2 := wire.MarshalJSONIndent(keeper.cdc, deposit)
|
||||
bz, err2 := codec.MarshalJSONIndent(keeper.cdc, deposit)
|
||||
if err2 != nil {
|
||||
panic("could not marshal result to JSON")
|
||||
}
|
||||
@@ -104,7 +104,7 @@ func queryVote(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Kee
|
||||
}
|
||||
|
||||
vote, _ := keeper.GetVote(ctx, params.ProposalID, params.Voter)
|
||||
bz, err2 := wire.MarshalJSONIndent(keeper.cdc, vote)
|
||||
bz, err2 := codec.MarshalJSONIndent(keeper.cdc, vote)
|
||||
if err2 != nil {
|
||||
panic("could not marshal result to JSON")
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func queryDeposits(ctx sdk.Context, path []string, req abci.RequestQuery, keeper
|
||||
deposits = append(deposits, deposit)
|
||||
}
|
||||
|
||||
bz, err2 := wire.MarshalJSONIndent(keeper.cdc, deposits)
|
||||
bz, err2 := codec.MarshalJSONIndent(keeper.cdc, deposits)
|
||||
if err2 != nil {
|
||||
panic("could not marshal result to JSON")
|
||||
}
|
||||
@@ -161,7 +161,7 @@ func queryVotes(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Ke
|
||||
votes = append(votes, vote)
|
||||
}
|
||||
|
||||
bz, err2 := wire.MarshalJSONIndent(keeper.cdc, votes)
|
||||
bz, err2 := codec.MarshalJSONIndent(keeper.cdc, votes)
|
||||
if err2 != nil {
|
||||
panic("could not marshal result to JSON")
|
||||
}
|
||||
@@ -186,7 +186,7 @@ func queryProposals(ctx sdk.Context, path []string, req abci.RequestQuery, keepe
|
||||
|
||||
proposals := keeper.GetProposalsFiltered(ctx, params.Voter, params.Depositer, params.ProposalStatus, params.NumLatestProposals)
|
||||
|
||||
bz, err2 := wire.MarshalJSONIndent(keeper.cdc, proposals)
|
||||
bz, err2 := codec.MarshalJSONIndent(keeper.cdc, proposals)
|
||||
if err2 != nil {
|
||||
panic("could not marshal result to JSON")
|
||||
}
|
||||
@@ -223,7 +223,7 @@ func queryTally(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Ke
|
||||
_, tallyResult, _ = tally(ctx, keeper, proposal)
|
||||
}
|
||||
|
||||
bz, err2 := wire.MarshalJSONIndent(keeper.cdc, tallyResult)
|
||||
bz, err2 := codec.MarshalJSONIndent(keeper.cdc, tallyResult)
|
||||
if err2 != nil {
|
||||
panic("could not marshal result to JSON")
|
||||
}
|
||||
|
||||
@@ -51,7 +51,11 @@ func SimulateSubmittingVotingAndSlashingForProposal(k gov.Keeper, sk stake.Keepe
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
action = simulateHandleMsgSubmitProposal(msg, sk, handler, ctx, event)
|
||||
action, ok := simulateHandleMsgSubmitProposal(msg, sk, handler, ctx, event)
|
||||
// don't schedule votes if proposal failed
|
||||
if !ok {
|
||||
return action, nil, nil
|
||||
}
|
||||
proposalID := k.GetLastProposalID(ctx)
|
||||
// 2) Schedule operations for votes
|
||||
// 2.1) first pick a number of people to vote.
|
||||
@@ -85,24 +89,25 @@ func SimulateMsgSubmitProposal(k gov.Keeper, sk stake.Keeper) simulation.Operati
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
action = simulateHandleMsgSubmitProposal(msg, sk, handler, ctx, event)
|
||||
action, _ = simulateHandleMsgSubmitProposal(msg, sk, handler, ctx, event)
|
||||
return action, nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
func simulateHandleMsgSubmitProposal(msg gov.MsgSubmitProposal, sk stake.Keeper, handler sdk.Handler, ctx sdk.Context, event func(string)) (action string) {
|
||||
func simulateHandleMsgSubmitProposal(msg gov.MsgSubmitProposal, sk stake.Keeper, handler sdk.Handler, ctx sdk.Context, event func(string)) (action string, ok bool) {
|
||||
ctx, write := ctx.CacheContext()
|
||||
result := handler(ctx, msg)
|
||||
if result.IsOK() {
|
||||
ok = result.IsOK()
|
||||
if ok {
|
||||
// Update pool to keep invariants
|
||||
pool := sk.GetPool(ctx)
|
||||
pool.LooseTokens = pool.LooseTokens.Sub(sdk.NewDecFromInt(msg.InitialDeposit.AmountOf(denom)))
|
||||
sk.SetPool(ctx, pool)
|
||||
write()
|
||||
}
|
||||
event(fmt.Sprintf("gov/MsgSubmitProposal/%v", result.IsOK()))
|
||||
action = fmt.Sprintf("TestMsgSubmitProposal: ok %v, msg %s", result.IsOK(), msg.GetSignBytes())
|
||||
return action
|
||||
event(fmt.Sprintf("gov/MsgSubmitProposal/%v", ok))
|
||||
action = fmt.Sprintf("TestMsgSubmitProposal: ok %v, msg %s", ok, msg.GetSignBytes())
|
||||
return
|
||||
}
|
||||
|
||||
func simulationCreateMsgSubmitProposal(r *rand.Rand, sender crypto.PrivKey) (msg gov.MsgSubmitProposal, err error) {
|
||||
@@ -156,7 +161,6 @@ func SimulateMsgVote(k gov.Keeper, sk stake.Keeper) simulation.Operation {
|
||||
return operationSimulateMsgVote(k, sk, nil, -1)
|
||||
}
|
||||
|
||||
|
||||
// nolint: unparam
|
||||
func operationSimulateMsgVote(k gov.Keeper, sk stake.Keeper, key crypto.PrivKey, proposalID int64) simulation.Operation {
|
||||
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, event func(string)) (action string, fOp []simulation.FutureOperation, err error) {
|
||||
|
||||
@@ -21,8 +21,8 @@ import (
|
||||
func TestGovWithRandomMessages(t *testing.T) {
|
||||
mapp := mock.NewApp()
|
||||
|
||||
bank.RegisterWire(mapp.Cdc)
|
||||
gov.RegisterWire(mapp.Cdc)
|
||||
bank.RegisterCodec(mapp.Cdc)
|
||||
gov.RegisterCodec(mapp.Cdc)
|
||||
mapper := mapp.AccountMapper
|
||||
bankKeeper := bank.NewBaseKeeper(mapper)
|
||||
stakeKey := sdk.NewKVStoreKey("stake")
|
||||
|
||||
@@ -23,8 +23,8 @@ import (
|
||||
func getMockApp(t *testing.T, numGenAccs int) (*mock.App, Keeper, stake.Keeper, []sdk.AccAddress, []crypto.PubKey, []crypto.PrivKey) {
|
||||
mapp := mock.NewApp()
|
||||
|
||||
stake.RegisterWire(mapp.Cdc)
|
||||
RegisterWire(mapp.Cdc)
|
||||
stake.RegisterCodec(mapp.Cdc)
|
||||
RegisterCodec(mapp.Cdc)
|
||||
|
||||
keyGlobalParams := sdk.NewKVStoreKey("params")
|
||||
keyStake := sdk.NewKVStoreKey("stake")
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ import (
|
||||
func getMockApp(t *testing.T) *mock.App {
|
||||
mapp := mock.NewApp()
|
||||
|
||||
RegisterWire(mapp.Cdc)
|
||||
RegisterCodec(mapp.Cdc)
|
||||
keyIBC := sdk.NewKVStoreKey("ibc")
|
||||
ibcMapper := NewMapper(mapp.Cdc, keyIBC, mapp.RegisterCodespace(DefaultCodespace))
|
||||
bankKeeper := bank.NewBaseKeeper(mapp.AccountMapper)
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
wire "github.com/cosmos/cosmos-sdk/wire"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc"
|
||||
@@ -24,7 +24,7 @@ const (
|
||||
)
|
||||
|
||||
// IBCTransferCmd implements the IBC transfer command.
|
||||
func IBCTransferCmd(cdc *wire.Codec) *cobra.Command {
|
||||
func IBCTransferCmd(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "transfer",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
wire "github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
@@ -28,7 +28,7 @@ const (
|
||||
)
|
||||
|
||||
type relayCommander struct {
|
||||
cdc *wire.Codec
|
||||
cdc *codec.Codec
|
||||
address sdk.AccAddress
|
||||
decoder auth.AccountDecoder
|
||||
mainStore string
|
||||
@@ -39,7 +39,7 @@ type relayCommander struct {
|
||||
}
|
||||
|
||||
// IBCRelayCmd implements the IBC relay command.
|
||||
func IBCRelayCmd(cdc *wire.Codec) *cobra.Command {
|
||||
func IBCRelayCmd(cdc *codec.Codec) *cobra.Command {
|
||||
cmdr := relayCommander{
|
||||
cdc: cdc,
|
||||
decoder: authcmd.GetAccountDecoder(cdc),
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
"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"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc"
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
// RegisterRoutes - Central function to define routes that get registered by the main application
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) {
|
||||
r.HandleFunc("/ibc/{destchain}/{address}/send", TransferRequestHandlerFn(cdc, kb, cliCtx)).Methods("POST")
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ type transferBody struct {
|
||||
// TransferRequestHandler - http request handler to transfer coins to a address
|
||||
// on a different chain via IBC
|
||||
// nolint: gocyclo
|
||||
func TransferRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
func TransferRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
destChainID := vars["destchain"]
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package ibc
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
)
|
||||
|
||||
// Register concrete types on wire codec
|
||||
func RegisterWire(cdc *wire.Codec) {
|
||||
// Register concrete types on codec codec
|
||||
func RegisterCodec(cdc *codec.Codec) {
|
||||
cdc.RegisterConcrete(IBCTransferMsg{}, "cosmos-sdk/IBCTransferMsg", nil)
|
||||
cdc.RegisterConcrete(IBCReceiveMsg{}, "cosmos-sdk/IBCReceiveMsg", nil)
|
||||
}
|
||||
+4
-4
@@ -10,9 +10,9 @@ import (
|
||||
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/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
)
|
||||
@@ -38,8 +38,8 @@ func getCoins(ck bank.Keeper, ctx sdk.Context, addr sdk.AccAddress) (sdk.Coins,
|
||||
return coins, err
|
||||
}
|
||||
|
||||
func makeCodec() *wire.Codec {
|
||||
var cdc = wire.NewCodec()
|
||||
func makeCodec() *codec.Codec {
|
||||
var cdc = codec.New()
|
||||
|
||||
// Register Msgs
|
||||
cdc.RegisterInterface((*sdk.Msg)(nil), nil)
|
||||
@@ -51,7 +51,7 @@ func makeCodec() *wire.Codec {
|
||||
// Register AppAccount
|
||||
cdc.RegisterInterface((*auth.Account)(nil), nil)
|
||||
cdc.RegisterConcrete(&auth.BaseAccount{}, "test/ibc/Account", nil)
|
||||
wire.RegisterCrypto(cdc)
|
||||
codec.RegisterCrypto(cdc)
|
||||
|
||||
cdc.Seal()
|
||||
|
||||
|
||||
+5
-5
@@ -3,20 +3,20 @@ package ibc
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
wire "github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
// IBC Mapper
|
||||
type Mapper struct {
|
||||
key sdk.StoreKey
|
||||
cdc *wire.Codec
|
||||
cdc *codec.Codec
|
||||
codespace sdk.CodespaceType
|
||||
}
|
||||
|
||||
// XXX: The Mapper should not take a CoinKeeper. Rather have the CoinKeeper
|
||||
// take an Mapper.
|
||||
func NewMapper(cdc *wire.Codec, key sdk.StoreKey, codespace sdk.CodespaceType) Mapper {
|
||||
func NewMapper(cdc *codec.Codec, key sdk.StoreKey, codespace sdk.CodespaceType) Mapper {
|
||||
// XXX: How are these codecs supposed to work?
|
||||
return Mapper{
|
||||
key: key,
|
||||
@@ -60,7 +60,7 @@ func (ibcm Mapper) ReceiveIBCPacket(ctx sdk.Context, packet IBCPacket) sdk.Error
|
||||
// --------------------------
|
||||
// Functions for accessing the underlying KVStore.
|
||||
|
||||
func marshalBinaryPanic(cdc *wire.Codec, value interface{}) []byte {
|
||||
func marshalBinaryPanic(cdc *codec.Codec, value interface{}) []byte {
|
||||
res, err := cdc.MarshalBinary(value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -68,7 +68,7 @@ func marshalBinaryPanic(cdc *wire.Codec, value interface{}) []byte {
|
||||
return res
|
||||
}
|
||||
|
||||
func unmarshalBinaryPanic(cdc *wire.Codec, bz []byte, ptr interface{}) {
|
||||
func unmarshalBinaryPanic(cdc *codec.Codec, bz []byte, ptr interface{}) {
|
||||
err := cdc.UnmarshalBinary(bz, ptr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
+5
-3
@@ -3,16 +3,16 @@ package ibc
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
wire "github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
var (
|
||||
msgCdc *wire.Codec
|
||||
msgCdc *codec.Codec
|
||||
)
|
||||
|
||||
func init() {
|
||||
msgCdc = wire.NewCodec()
|
||||
msgCdc = codec.New()
|
||||
}
|
||||
|
||||
// ------------------------------
|
||||
@@ -72,6 +72,7 @@ type IBCTransferMsg struct {
|
||||
|
||||
// nolint
|
||||
func (msg IBCTransferMsg) Type() string { return "ibc" }
|
||||
func (msg IBCTransferMsg) Name() string { return "transfer" }
|
||||
|
||||
// x/bank/tx.go MsgSend.GetSigners()
|
||||
func (msg IBCTransferMsg) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.SrcAddr} }
|
||||
@@ -100,6 +101,7 @@ type IBCReceiveMsg struct {
|
||||
|
||||
// nolint
|
||||
func (msg IBCReceiveMsg) Type() string { return "ibc" }
|
||||
func (msg IBCReceiveMsg) Name() string { return "receive" }
|
||||
func (msg IBCReceiveMsg) ValidateBasic() sdk.Error { return msg.IBCPacket.ValidateBasic() }
|
||||
|
||||
// x/bank/tx.go MsgSend.GetSigners()
|
||||
|
||||
+6
-6
@@ -6,8 +6,8 @@ import (
|
||||
"os"
|
||||
|
||||
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/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
@@ -24,7 +24,7 @@ const chainID = ""
|
||||
// capabilities aren't needed for testing.
|
||||
type App struct {
|
||||
*bam.BaseApp
|
||||
Cdc *wire.Codec // Cdc is public since the codec is passed into the module anyways
|
||||
Cdc *codec.Codec // Cdc is public since the codec is passed into the module anyways
|
||||
KeyMain *sdk.KVStoreKey
|
||||
KeyAccount *sdk.KVStoreKey
|
||||
|
||||
@@ -43,10 +43,10 @@ func NewApp() *App {
|
||||
db := dbm.NewMemDB()
|
||||
|
||||
// Create the cdc with some standard codecs
|
||||
cdc := wire.NewCodec()
|
||||
sdk.RegisterWire(cdc)
|
||||
wire.RegisterCrypto(cdc)
|
||||
auth.RegisterWire(cdc)
|
||||
cdc := codec.New()
|
||||
sdk.RegisterCodec(cdc)
|
||||
codec.RegisterCrypto(cdc)
|
||||
auth.RegisterCodec(cdc)
|
||||
|
||||
// Create your application object
|
||||
app := &App{
|
||||
|
||||
@@ -24,6 +24,7 @@ type testMsg struct {
|
||||
}
|
||||
|
||||
func (tx testMsg) Type() string { return msgType }
|
||||
func (tx testMsg) Name() string { return "test" }
|
||||
func (tx testMsg) GetMsg() sdk.Msg { return tx }
|
||||
func (tx testMsg) GetMemo() string { return "" }
|
||||
func (tx testMsg) GetSignBytes() []byte { return nil }
|
||||
|
||||
+1
-12
@@ -1,15 +1,4 @@
|
||||
/*
|
||||
Package mock provides functions for creating applications for testing.
|
||||
|
||||
This module also features randomized testing, so that various modules can test
|
||||
that their operations are interoperable.
|
||||
|
||||
The intended method of using this randomized testing framework is that every
|
||||
module provides TestAndRunTx methods for each of its desired methods of fuzzing
|
||||
its own txs, and it also provides the invariants that it assumes to be true.
|
||||
You then pick and choose from these tx types and invariants. To pick and choose
|
||||
these, you first build a mock app with the correct keepers. Then you call the
|
||||
app.RandomizedTesting method with the set of desired txs, invariants, along
|
||||
with the setups each module requires.
|
||||
Package mock provides utility methods to ease writing tests.
|
||||
*/
|
||||
package mock
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Package simulation implements a simulation framework for any state machine
|
||||
built on the SDK which utilizes auth.
|
||||
|
||||
It is primarily intended for fuzz testing the integration of modules.
|
||||
It will test that the provided operations are interoperable,
|
||||
and that the desired invariants hold.
|
||||
It can additionally be used to detect what the performance benchmarks in the
|
||||
system are, by using benchmarking mode and cpu / mem profiling.
|
||||
If it detects a failure, it provides the entire log of what was ran,
|
||||
|
||||
The simulator takes as input: a random seed, the set of operations to run,
|
||||
the invariants to test, and additional parameters to configure how long to run,
|
||||
and misc. parameters that affect simulation speed.
|
||||
|
||||
It is intended that every module provides a list of Operations which will randomly
|
||||
create and run a message / tx in a manner that is interesting to fuzz, and verify that
|
||||
the state transition was executed as expected.
|
||||
Each module should additionally provide methods to assert that the desired invariants hold.
|
||||
|
||||
Then to perform a randomized simulation, select the set of desired operations,
|
||||
the weightings for each, the invariants you want to test, and how long to run it for.
|
||||
Then run simulation.Simulate!
|
||||
The simulator will handle things like ensuring that validators periodically double signing,
|
||||
or go offline.
|
||||
*/
|
||||
package simulation
|
||||
+4
-4
@@ -4,18 +4,18 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
// Keeper manages global parameter store
|
||||
type Keeper struct {
|
||||
cdc *wire.Codec
|
||||
cdc *codec.Codec
|
||||
key sdk.StoreKey
|
||||
}
|
||||
|
||||
// NewKeeper constructs a new Keeper
|
||||
func NewKeeper(cdc *wire.Codec, key sdk.StoreKey) Keeper {
|
||||
func NewKeeper(cdc *codec.Codec, key sdk.StoreKey) Keeper {
|
||||
return Keeper{
|
||||
cdc: cdc,
|
||||
key: key,
|
||||
@@ -24,7 +24,7 @@ func NewKeeper(cdc *wire.Codec, key sdk.StoreKey) Keeper {
|
||||
|
||||
// InitKeeper constructs a new Keeper with initial parameters
|
||||
// nolint: errcheck
|
||||
func InitKeeper(ctx sdk.Context, cdc *wire.Codec, key sdk.StoreKey, params ...interface{}) Keeper {
|
||||
func InitKeeper(ctx sdk.Context, cdc *codec.Codec, key sdk.StoreKey, params ...interface{}) Keeper {
|
||||
if len(params)%2 != 0 {
|
||||
panic("Odd params list length for InitKeeper")
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
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/wire"
|
||||
)
|
||||
|
||||
func defaultContext(key sdk.StoreKey) sdk.Context {
|
||||
@@ -37,7 +37,7 @@ func TestKeeper(t *testing.T) {
|
||||
|
||||
skey := sdk.NewKVStoreKey("test")
|
||||
ctx := defaultContext(skey)
|
||||
setter := NewKeeper(wire.NewCodec(), skey).Setter()
|
||||
setter := NewKeeper(codec.New(), skey).Setter()
|
||||
|
||||
for _, kv := range kvs {
|
||||
err := setter.Set(ctx, kv.key, kv.param)
|
||||
@@ -51,7 +51,7 @@ func TestKeeper(t *testing.T) {
|
||||
assert.Equal(t, kv.param, param)
|
||||
}
|
||||
|
||||
cdc := wire.NewCodec()
|
||||
cdc := codec.New()
|
||||
for _, kv := range kvs {
|
||||
var param int64
|
||||
bz := setter.GetRaw(ctx, kv.key)
|
||||
@@ -75,7 +75,7 @@ func TestKeeper(t *testing.T) {
|
||||
func TestGetter(t *testing.T) {
|
||||
key := sdk.NewKVStoreKey("test")
|
||||
ctx := defaultContext(key)
|
||||
keeper := NewKeeper(wire.NewCodec(), key)
|
||||
keeper := NewKeeper(codec.New(), key)
|
||||
|
||||
g := keeper.Getter()
|
||||
s := keeper.Setter()
|
||||
|
||||
@@ -24,7 +24,7 @@ var (
|
||||
func getMockApp(t *testing.T) (*mock.App, stake.Keeper, Keeper) {
|
||||
mapp := mock.NewApp()
|
||||
|
||||
RegisterWire(mapp.Cdc)
|
||||
RegisterCodec(mapp.Cdc)
|
||||
keyStake := sdk.NewKVStoreKey("stake")
|
||||
tkeyStake := sdk.NewTransientStoreKey("transient_stake")
|
||||
keySlashing := sdk.NewKVStoreKey("slashing")
|
||||
|
||||
@@ -8,13 +8,13 @@ import (
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/codec" // XXX fix
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire" // XXX fix
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||
)
|
||||
|
||||
// GetCmdQuerySigningInfo implements the command to query signing info.
|
||||
func GetCmdQuerySigningInfo(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQuerySigningInfo(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "signing-info [validator-pubkey]",
|
||||
Short: "Query a validator's signing information",
|
||||
@@ -44,7 +44,7 @@ func GetCmdQuerySigningInfo(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
|
||||
case "json":
|
||||
// parse out the signing info
|
||||
output, err := wire.MarshalJSONIndent(cdc, signingInfo)
|
||||
output, err := codec.MarshalJSONIndent(cdc, signingInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"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/wire"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
// GetCmdUnjail implements the create unjail validator command.
|
||||
func GetCmdUnjail(cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdUnjail(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "unjail",
|
||||
Args: cobra.NoArgs,
|
||||
|
||||
@@ -5,13 +5,13 @@ import (
|
||||
"net/http"
|
||||
|
||||
"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/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec) {
|
||||
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
|
||||
r.HandleFunc(
|
||||
"/slashing/signing_info/{validator}",
|
||||
signingInfoHandlerFn(cliCtx, "slashing", cdc),
|
||||
@@ -20,7 +20,7 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Cod
|
||||
|
||||
// http request handler to query signing info
|
||||
// nolint: unparam
|
||||
func signingInfoHandlerFn(cliCtx context.CLIContext, storeName string, cdc *wire.Codec) http.HandlerFunc {
|
||||
func signingInfoHandlerFn(cliCtx context.CLIContext, storeName string, cdc *codec.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@ package rest
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// RegisterRoutes registers staking-related REST handlers to a router
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) {
|
||||
registerQueryRoutes(cliCtx, r, cdc)
|
||||
registerTxRoutes(cliCtx, r, cdc, kb)
|
||||
}
|
||||
|
||||
@@ -10,16 +10,16 @@ import (
|
||||
"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"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
|
||||
func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) {
|
||||
r.HandleFunc(
|
||||
"/slashing/unjail",
|
||||
unjailRequestHandlerFn(cdc, kb, cliCtx),
|
||||
@@ -39,7 +39,7 @@ type UnjailBody struct {
|
||||
}
|
||||
|
||||
// nolint: gocyclo
|
||||
func unjailRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
func unjailRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var m UnjailBody
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package slashing
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
)
|
||||
|
||||
// Register concrete types on codec codec
|
||||
func RegisterCodec(cdc *codec.Codec) {
|
||||
cdc.RegisterConcrete(MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil)
|
||||
}
|
||||
|
||||
var cdcEmpty = codec.New()
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/params"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
// Keeper of the slashing store
|
||||
type Keeper struct {
|
||||
storeKey sdk.StoreKey
|
||||
cdc *wire.Codec
|
||||
cdc *codec.Codec
|
||||
validatorSet sdk.ValidatorSet
|
||||
params params.Getter
|
||||
// codespace
|
||||
@@ -24,7 +24,7 @@ type Keeper struct {
|
||||
}
|
||||
|
||||
// NewKeeper creates a slashing keeper
|
||||
func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, vs sdk.ValidatorSet, params params.Getter, codespace sdk.CodespaceType) Keeper {
|
||||
func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, vs sdk.ValidatorSet, params params.Getter, codespace sdk.CodespaceType) Keeper {
|
||||
keeper := Keeper{
|
||||
storeKey: key,
|
||||
cdc: cdc,
|
||||
|
||||
+3
-2
@@ -1,11 +1,11 @@
|
||||
package slashing
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
var cdc = wire.NewCodec()
|
||||
var cdc = codec.New()
|
||||
|
||||
// name to identify transaction types
|
||||
const MsgType = "slashing"
|
||||
@@ -26,6 +26,7 @@ func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail {
|
||||
|
||||
//nolint
|
||||
func (msg MsgUnjail) Type() string { return MsgType }
|
||||
func (msg MsgUnjail) Name() string { return "unjail" }
|
||||
func (msg MsgUnjail) GetSigners() []sdk.AccAddress {
|
||||
return []sdk.AccAddress{sdk.AccAddress(msg.ValidatorAddr)}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
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/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
"github.com/cosmos/cosmos-sdk/x/params"
|
||||
@@ -39,13 +39,13 @@ var (
|
||||
initCoins = sdk.NewInt(200)
|
||||
)
|
||||
|
||||
func createTestCodec() *wire.Codec {
|
||||
cdc := wire.NewCodec()
|
||||
sdk.RegisterWire(cdc)
|
||||
auth.RegisterWire(cdc)
|
||||
bank.RegisterWire(cdc)
|
||||
stake.RegisterWire(cdc)
|
||||
wire.RegisterCrypto(cdc)
|
||||
func createTestCodec() *codec.Codec {
|
||||
cdc := codec.New()
|
||||
sdk.RegisterCodec(cdc)
|
||||
auth.RegisterCodec(cdc)
|
||||
bank.RegisterCodec(cdc)
|
||||
stake.RegisterCodec(cdc)
|
||||
codec.RegisterCrypto(cdc)
|
||||
return cdc
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package slashing
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
// Register concrete types on wire codec
|
||||
func RegisterWire(cdc *wire.Codec) {
|
||||
cdc.RegisterConcrete(MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil)
|
||||
}
|
||||
|
||||
var cdcEmpty = wire.NewCodec()
|
||||
+3
-3
@@ -20,9 +20,9 @@ var (
|
||||
addr3 = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
|
||||
priv4 = ed25519.GenPrivKey()
|
||||
addr4 = sdk.AccAddress(priv4.PubKey().Address())
|
||||
coins = sdk.Coins{{"foocoin", sdk.NewInt(10)}}
|
||||
coins = sdk.Coins{sdk.NewCoin("foocoin", sdk.NewInt(10))}
|
||||
fee = auth.StdFee{
|
||||
sdk.Coins{{"foocoin", sdk.NewInt(0)}},
|
||||
sdk.Coins{sdk.NewCoin("foocoin", sdk.NewInt(0))},
|
||||
100000,
|
||||
}
|
||||
)
|
||||
@@ -31,7 +31,7 @@ var (
|
||||
func getMockApp(t *testing.T) (*mock.App, Keeper) {
|
||||
mApp := mock.NewApp()
|
||||
|
||||
RegisterWire(mApp.Cdc)
|
||||
RegisterCodec(mApp.Cdc)
|
||||
|
||||
keyStake := sdk.NewKVStoreKey("stake")
|
||||
tkeyStake := sdk.NewTransientStoreKey("transient_stake")
|
||||
|
||||
+21
-21
@@ -8,14 +8,14 @@ import (
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"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/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
)
|
||||
|
||||
// GetCmdQueryValidator implements the validator query command.
|
||||
func GetCmdQueryValidator(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryValidator(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "validator [operator-addr]",
|
||||
Short: "Query a validator",
|
||||
@@ -48,7 +48,7 @@ func GetCmdQueryValidator(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
|
||||
case "json":
|
||||
// parse out the validator
|
||||
output, err := wire.MarshalJSONIndent(cdc, validator)
|
||||
output, err := codec.MarshalJSONIndent(cdc, validator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func GetCmdQueryValidator(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
}
|
||||
|
||||
// GetCmdQueryValidators implements the query all validators command.
|
||||
func GetCmdQueryValidators(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryValidators(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "validators",
|
||||
Short: "Query for all validators",
|
||||
@@ -97,7 +97,7 @@ func GetCmdQueryValidators(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
fmt.Println(resp)
|
||||
}
|
||||
case "json":
|
||||
output, err := wire.MarshalJSONIndent(cdc, validators)
|
||||
output, err := codec.MarshalJSONIndent(cdc, validators)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func GetCmdQueryValidators(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
}
|
||||
|
||||
// GetCmdQueryDelegation the query delegation command.
|
||||
func GetCmdQueryDelegation(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryDelegation(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "delegation",
|
||||
Short: "Query a delegation based on address and validator address",
|
||||
@@ -153,7 +153,7 @@ func GetCmdQueryDelegation(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
|
||||
fmt.Println(resp)
|
||||
case "json":
|
||||
output, err := wire.MarshalJSONIndent(cdc, delegation)
|
||||
output, err := codec.MarshalJSONIndent(cdc, delegation)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -174,7 +174,7 @@ func GetCmdQueryDelegation(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
|
||||
// GetCmdQueryDelegations implements the command to query all the delegations
|
||||
// made from one delegator.
|
||||
func GetCmdQueryDelegations(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryDelegations(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "delegations [delegator-addr]",
|
||||
Short: "Query all delegations made from one delegator",
|
||||
@@ -200,7 +200,7 @@ func GetCmdQueryDelegations(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
delegations = append(delegations, delegation)
|
||||
}
|
||||
|
||||
output, err := wire.MarshalJSONIndent(cdc, delegations)
|
||||
output, err := codec.MarshalJSONIndent(cdc, delegations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -217,7 +217,7 @@ func GetCmdQueryDelegations(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
|
||||
// GetCmdQueryUnbondingDelegation implements the command to query a single
|
||||
// unbonding-delegation record.
|
||||
func GetCmdQueryUnbondingDelegation(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryUnbondingDelegation(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "unbonding-delegation",
|
||||
Short: "Query an unbonding-delegation record based on delegator and validator address",
|
||||
@@ -252,7 +252,7 @@ func GetCmdQueryUnbondingDelegation(storeName string, cdc *wire.Codec) *cobra.Co
|
||||
|
||||
fmt.Println(resp)
|
||||
case "json":
|
||||
output, err := wire.MarshalJSONIndent(cdc, ubd)
|
||||
output, err := codec.MarshalJSONIndent(cdc, ubd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -273,7 +273,7 @@ func GetCmdQueryUnbondingDelegation(storeName string, cdc *wire.Codec) *cobra.Co
|
||||
|
||||
// GetCmdQueryUnbondingDelegations implements the command to query all the
|
||||
// unbonding-delegation records for a delegator.
|
||||
func GetCmdQueryUnbondingDelegations(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryUnbondingDelegations(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "unbonding-delegations [delegator-addr]",
|
||||
Short: "Query all unbonding-delegations records for one delegator",
|
||||
@@ -299,7 +299,7 @@ func GetCmdQueryUnbondingDelegations(storeName string, cdc *wire.Codec) *cobra.C
|
||||
ubds = append(ubds, ubd)
|
||||
}
|
||||
|
||||
output, err := wire.MarshalJSONIndent(cdc, ubds)
|
||||
output, err := codec.MarshalJSONIndent(cdc, ubds)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -316,7 +316,7 @@ func GetCmdQueryUnbondingDelegations(storeName string, cdc *wire.Codec) *cobra.C
|
||||
|
||||
// GetCmdQueryRedelegation implements the command to query a single
|
||||
// redelegation record.
|
||||
func GetCmdQueryRedelegation(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryRedelegation(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "redelegation",
|
||||
Short: "Query a redelegation record based on delegator and a source and destination validator address",
|
||||
@@ -356,7 +356,7 @@ func GetCmdQueryRedelegation(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
|
||||
fmt.Println(resp)
|
||||
case "json":
|
||||
output, err := wire.MarshalJSONIndent(cdc, red)
|
||||
output, err := codec.MarshalJSONIndent(cdc, red)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -377,7 +377,7 @@ func GetCmdQueryRedelegation(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
|
||||
// GetCmdQueryRedelegations implements the command to query all the
|
||||
// redelegation records for a delegator.
|
||||
func GetCmdQueryRedelegations(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryRedelegations(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "redelegations [delegator-addr]",
|
||||
Short: "Query all redelegations records for one delegator",
|
||||
@@ -403,7 +403,7 @@ func GetCmdQueryRedelegations(storeName string, cdc *wire.Codec) *cobra.Command
|
||||
reds = append(reds, red)
|
||||
}
|
||||
|
||||
output, err := wire.MarshalJSONIndent(cdc, reds)
|
||||
output, err := codec.MarshalJSONIndent(cdc, reds)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -419,7 +419,7 @@ func GetCmdQueryRedelegations(storeName string, cdc *wire.Codec) *cobra.Command
|
||||
}
|
||||
|
||||
// GetCmdQueryPool implements the pool query command.
|
||||
func GetCmdQueryPool(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryPool(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "pool",
|
||||
Short: "Query the current staking pool values",
|
||||
@@ -443,7 +443,7 @@ func GetCmdQueryPool(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
|
||||
case "json":
|
||||
// parse out the pool
|
||||
output, err := wire.MarshalJSONIndent(cdc, pool)
|
||||
output, err := codec.MarshalJSONIndent(cdc, pool)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -458,7 +458,7 @@ func GetCmdQueryPool(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
}
|
||||
|
||||
// GetCmdQueryPool implements the params query command.
|
||||
func GetCmdQueryParams(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdQueryParams(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "parameters",
|
||||
Short: "Query the current staking parameters information",
|
||||
@@ -482,7 +482,7 @@ func GetCmdQueryParams(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
|
||||
case "json":
|
||||
// parse out the params
|
||||
output, err := wire.MarshalJSONIndent(cdc, params)
|
||||
output, err := codec.MarshalJSONIndent(cdc, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+11
-11
@@ -7,8 +7,8 @@ import (
|
||||
"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/wire"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
)
|
||||
|
||||
// GetCmdCreateValidator implements the create validator command handler.
|
||||
func GetCmdCreateValidator(cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdCreateValidator(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "create-validator",
|
||||
Short: "create new validator initialized with a self-delegation to it",
|
||||
@@ -94,7 +94,7 @@ func GetCmdCreateValidator(cdc *wire.Codec) *cobra.Command {
|
||||
}
|
||||
|
||||
// GetCmdEditValidator implements the create edit validator command.
|
||||
func GetCmdEditValidator(cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "edit-validator",
|
||||
Short: "edit and existing validator account",
|
||||
@@ -133,7 +133,7 @@ func GetCmdEditValidator(cdc *wire.Codec) *cobra.Command {
|
||||
}
|
||||
|
||||
// GetCmdDelegate implements the delegate command.
|
||||
func GetCmdDelegate(cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdDelegate(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "delegate",
|
||||
Short: "delegate liquid tokens to an validator",
|
||||
@@ -176,7 +176,7 @@ func GetCmdDelegate(cdc *wire.Codec) *cobra.Command {
|
||||
}
|
||||
|
||||
// GetCmdRedelegate implements the redelegate validator command.
|
||||
func GetCmdRedelegate(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdRedelegate(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "redelegate",
|
||||
Short: "redelegate illiquid tokens from one validator to another",
|
||||
@@ -192,7 +192,7 @@ func GetCmdRedelegate(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
}
|
||||
|
||||
// GetCmdBeginRedelegate the begin redelegation command.
|
||||
func GetCmdBeginRedelegate(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdBeginRedelegate(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "begin",
|
||||
Short: "begin redelegation",
|
||||
@@ -250,7 +250,7 @@ func GetCmdBeginRedelegate(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
// nolint: gocyclo
|
||||
// TODO: Make this pass gocyclo linting
|
||||
func getShares(
|
||||
storeName string, cdc *wire.Codec, sharesAmountStr,
|
||||
storeName string, cdc *codec.Codec, sharesAmountStr,
|
||||
sharesPercentStr string, delAddr sdk.AccAddress, valAddr sdk.ValAddress,
|
||||
) (sharesAmount sdk.Dec, err error) {
|
||||
switch {
|
||||
@@ -296,7 +296,7 @@ func getShares(
|
||||
}
|
||||
|
||||
// GetCmdCompleteRedelegate implements the complete redelegation command.
|
||||
func GetCmdCompleteRedelegate(cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdCompleteRedelegate(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "complete",
|
||||
Short: "complete redelegation",
|
||||
@@ -338,7 +338,7 @@ func GetCmdCompleteRedelegate(cdc *wire.Codec) *cobra.Command {
|
||||
}
|
||||
|
||||
// GetCmdUnbond implements the unbond validator command.
|
||||
func GetCmdUnbond(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdUnbond(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "unbond",
|
||||
Short: "begin or complete unbonding shares from a validator",
|
||||
@@ -354,7 +354,7 @@ func GetCmdUnbond(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
}
|
||||
|
||||
// GetCmdBeginUnbonding implements the begin unbonding validator command.
|
||||
func GetCmdBeginUnbonding(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdBeginUnbonding(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "begin",
|
||||
Short: "begin unbonding",
|
||||
@@ -403,7 +403,7 @@ func GetCmdBeginUnbonding(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||
}
|
||||
|
||||
// GetCmdCompleteUnbonding implements the complete unbonding validator command.
|
||||
func GetCmdCompleteUnbonding(cdc *wire.Codec) *cobra.Command {
|
||||
func GetCmdCompleteUnbonding(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "complete",
|
||||
Short: "complete unbonding",
|
||||
|
||||
+205
-355
@@ -7,18 +7,17 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/tags"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
const storeName = "stake"
|
||||
|
||||
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec) {
|
||||
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
|
||||
|
||||
// Get all delegations (delegation, undelegation and redelegation) from a delegator
|
||||
r.HandleFunc(
|
||||
@@ -50,16 +49,16 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Cod
|
||||
delegationHandlerFn(cliCtx, cdc),
|
||||
).Methods("GET")
|
||||
|
||||
// Query all unbonding_delegations between a delegator and a validator
|
||||
// Query all unbonding delegations between a delegator and a validator
|
||||
r.HandleFunc(
|
||||
"/stake/delegators/{delegatorAddr}/unbonding_delegations/{validatorAddr}",
|
||||
unbondingDelegationsHandlerFn(cliCtx, cdc),
|
||||
unbondingDelegationHandlerFn(cliCtx, cdc),
|
||||
).Methods("GET")
|
||||
|
||||
// Get all validators
|
||||
r.HandleFunc(
|
||||
"/stake/validators",
|
||||
validatorsHandlerFn(cliCtx, cdc),
|
||||
validatorsHandlerFn(cliCtx),
|
||||
).Methods("GET")
|
||||
|
||||
// Get a single validator info
|
||||
@@ -71,119 +70,67 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Cod
|
||||
// Get the current state of the staking pool
|
||||
r.HandleFunc(
|
||||
"/stake/pool",
|
||||
poolHandlerFn(cliCtx, cdc),
|
||||
poolHandlerFn(cliCtx),
|
||||
).Methods("GET")
|
||||
|
||||
// Get the current staking parameter values
|
||||
r.HandleFunc(
|
||||
"/stake/parameters",
|
||||
paramsHandlerFn(cliCtx, cdc),
|
||||
paramsHandlerFn(cliCtx),
|
||||
).Methods("GET")
|
||||
|
||||
}
|
||||
|
||||
// already resolve the rational shares to not handle this in the client
|
||||
|
||||
// defines a delegation without type Rat for shares
|
||||
type DelegationWithoutRat struct {
|
||||
DelegatorAddr sdk.AccAddress `json:"delegator_addr"`
|
||||
ValidatorAddr sdk.ValAddress `json:"validator_addr"`
|
||||
Shares string `json:"shares"`
|
||||
Height int64 `json:"height"`
|
||||
}
|
||||
|
||||
// aggregation of all delegations, unbondings and redelegations
|
||||
type DelegationSummary struct {
|
||||
Delegations []DelegationWithoutRat `json:"delegations"`
|
||||
UnbondingDelegations []stake.UnbondingDelegation `json:"unbonding_delegations"`
|
||||
Redelegations []stake.Redelegation `json:"redelegations"`
|
||||
}
|
||||
|
||||
// HTTP request handler to query a delegator delegations
|
||||
func delegatorHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc {
|
||||
func delegatorHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var valAddr sdk.ValAddress
|
||||
var delegationSummary = DelegationSummary{}
|
||||
|
||||
// read parameters
|
||||
vars := mux.Vars(r)
|
||||
bech32delegator := vars["delegatorAddr"]
|
||||
|
||||
delAddr, err := sdk.AccAddressFromBech32(bech32delegator)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// Get all validators using key
|
||||
validators, statusCode, errMsg, err := getBech32Validators(storeName, cliCtx, cdc)
|
||||
if err != nil {
|
||||
w.WriteHeader(statusCode)
|
||||
w.Write([]byte(fmt.Sprintf("%s%s", errMsg, err.Error())))
|
||||
return
|
||||
params := stake.QueryDelegatorParams{
|
||||
DelegatorAddr: delegatorAddr,
|
||||
}
|
||||
|
||||
for _, validator := range validators {
|
||||
valAddr = validator.OperatorAddr
|
||||
|
||||
// Delegations
|
||||
delegations, statusCode, errMsg, err := getDelegatorDelegations(cliCtx, cdc, delAddr, valAddr)
|
||||
if err != nil {
|
||||
w.WriteHeader(statusCode)
|
||||
w.Write([]byte(fmt.Sprintf("%s%s", errMsg, err.Error())))
|
||||
return
|
||||
}
|
||||
if statusCode != http.StatusNoContent {
|
||||
delegationSummary.Delegations = append(delegationSummary.Delegations, delegations)
|
||||
}
|
||||
|
||||
// Undelegations
|
||||
unbondingDelegation, statusCode, errMsg, err := getDelegatorUndelegations(cliCtx, cdc, delAddr, valAddr)
|
||||
if err != nil {
|
||||
w.WriteHeader(statusCode)
|
||||
w.Write([]byte(fmt.Sprintf("%s%s", errMsg, err.Error())))
|
||||
return
|
||||
}
|
||||
if statusCode != http.StatusNoContent {
|
||||
delegationSummary.UnbondingDelegations = append(delegationSummary.UnbondingDelegations, unbondingDelegation)
|
||||
}
|
||||
|
||||
// Redelegations
|
||||
// only querying redelegations to a validator as this should give us already all relegations
|
||||
// if we also would put in redelegations from, we would have every redelegation double
|
||||
redelegations, statusCode, errMsg, err := getDelegatorRedelegations(cliCtx, cdc, delAddr, valAddr)
|
||||
if err != nil {
|
||||
w.WriteHeader(statusCode)
|
||||
w.Write([]byte(fmt.Sprintf("%s%s", errMsg, err.Error())))
|
||||
return
|
||||
}
|
||||
if statusCode != http.StatusNoContent {
|
||||
delegationSummary.Redelegations = append(delegationSummary.Redelegations, redelegations)
|
||||
}
|
||||
}
|
||||
|
||||
output, err := cdc.MarshalJSON(delegationSummary)
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(output)
|
||||
res, err := cliCtx.QueryWithData("custom/stake/delegator", bz)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(res)
|
||||
}
|
||||
}
|
||||
|
||||
// nolint gocyclo
|
||||
// HTTP request handler to query all staking txs (msgs) from a delegator
|
||||
func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc {
|
||||
func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var output []byte
|
||||
var typesQuerySlice []string
|
||||
vars := mux.Vars(r)
|
||||
delegatorAddr := vars["delegatorAddr"]
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
_, err := sdk.AccAddressFromBech32(delegatorAddr)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
@@ -234,10 +181,10 @@ func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.Hand
|
||||
}
|
||||
|
||||
for _, action := range actions {
|
||||
foundTxs, errQuery := queryTxs(node, cdc, action, delegatorAddr)
|
||||
foundTxs, errQuery := queryTxs(node, cliCtx, cdc, action, delegatorAddr)
|
||||
if errQuery != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(fmt.Sprintf("error querying transactions. Error: %s", errQuery.Error())))
|
||||
w.Write([]byte(errQuery.Error()))
|
||||
}
|
||||
txs = append(txs, foundTxs...)
|
||||
}
|
||||
@@ -253,134 +200,13 @@ func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.Hand
|
||||
}
|
||||
|
||||
// HTTP request handler to query an unbonding-delegation
|
||||
func unbondingDelegationsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc {
|
||||
func unbondingDelegationHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
bech32delegator := vars["delegatorAddr"]
|
||||
bech32validator := vars["validatorAddr"]
|
||||
|
||||
delAddr, err := sdk.AccAddressFromBech32(bech32delegator)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
valAddr, err := sdk.ValAddressFromBech32(bech32validator)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
key := stake.GetUBDKey(delAddr, valAddr)
|
||||
|
||||
res, err := cliCtx.QueryStore(key, storeName)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(fmt.Sprintf("couldn't query unbonding-delegation. Error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
// the query will return empty if there is no data for this record
|
||||
if len(res) == 0 {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
ubd, err := types.UnmarshalUBD(cdc, key, res)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(fmt.Sprintf("couldn't unmarshall unbonding-delegation. Error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
// unbondings will be a list in the future but is not yet, but we want to keep the API consistent
|
||||
ubdArray := []stake.UnbondingDelegation{ubd}
|
||||
|
||||
output, err := cdc.MarshalJSON(ubdArray)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(fmt.Sprintf("couldn't marshall unbonding-delegation. Error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(output)
|
||||
}
|
||||
}
|
||||
|
||||
// HTTP request handler to query a bonded validator
|
||||
func delegationHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// read parameters
|
||||
vars := mux.Vars(r)
|
||||
bech32delegator := vars["delegatorAddr"]
|
||||
bech32validator := vars["validatorAddr"]
|
||||
|
||||
delAddr, err := sdk.AccAddressFromBech32(bech32delegator)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
valAddr, err := sdk.ValAddressFromBech32(bech32validator)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
key := stake.GetDelegationKey(delAddr, valAddr)
|
||||
|
||||
res, err := cliCtx.QueryStore(key, storeName)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(fmt.Sprintf("couldn't query delegation. Error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
// the query will return empty if there is no data for this record
|
||||
if len(res) == 0 {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
delegation, err := types.UnmarshalDelegation(cdc, key, res)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
outputDelegation := DelegationWithoutRat{
|
||||
DelegatorAddr: delegation.DelegatorAddr,
|
||||
ValidatorAddr: delegation.ValidatorAddr,
|
||||
Height: delegation.Height,
|
||||
Shares: delegation.Shares.String(),
|
||||
}
|
||||
|
||||
output, err := cdc.MarshalJSON(outputDelegation)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(output)
|
||||
}
|
||||
}
|
||||
|
||||
// HTTP request handler to query all delegator bonded validators
|
||||
func delegatorValidatorsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var valAddr sdk.ValAddress
|
||||
var bondedValidators []types.Validator
|
||||
|
||||
// read parameters
|
||||
vars := mux.Vars(r)
|
||||
bech32delegator := vars["delegatorAddr"]
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator)
|
||||
if err != nil {
|
||||
@@ -389,232 +215,256 @@ func delegatorValidatorsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) ht
|
||||
return
|
||||
}
|
||||
|
||||
// Get all validators using key
|
||||
kvs, err := cliCtx.QuerySubspace(stake.ValidatorsKey, storeName)
|
||||
validatorAddr, err := sdk.ValAddressFromBech32(bech32validator)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(fmt.Sprintf("couldn't query validators. Error: %s", err.Error())))
|
||||
return
|
||||
} else if len(kvs) == 0 {
|
||||
// the query will return empty if there are no validators
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
validators, err := getValidators(kvs, cdc)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(fmt.Sprintf("Error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
for _, validator := range validators {
|
||||
// get all transactions from the delegator to val and append
|
||||
valAddr = validator.OperatorAddr
|
||||
|
||||
validator, statusCode, errMsg, errRes := getDelegatorValidator(cliCtx, cdc, delegatorAddr, valAddr)
|
||||
if errRes != nil {
|
||||
w.WriteHeader(statusCode)
|
||||
w.Write([]byte(fmt.Sprintf("%s%s", errMsg, errRes.Error())))
|
||||
return
|
||||
} else if statusCode == http.StatusNoContent {
|
||||
continue
|
||||
}
|
||||
|
||||
bondedValidators = append(bondedValidators, validator)
|
||||
}
|
||||
output, err := cdc.MarshalJSON(bondedValidators)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
w.Write(output)
|
||||
|
||||
params := stake.QueryBondsParams{
|
||||
DelegatorAddr: delegatorAddr,
|
||||
ValidatorAddr: validatorAddr,
|
||||
}
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData("custom/stake/unbondingDelegation", bz)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(res)
|
||||
}
|
||||
}
|
||||
|
||||
// HTTP request handler to get information from a currently bonded validator
|
||||
func delegatorValidatorHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc {
|
||||
// HTTP request handler to query a bonded validator
|
||||
func delegationHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// read parameters
|
||||
var output []byte
|
||||
vars := mux.Vars(r)
|
||||
bech32delegator := vars["delegatorAddr"]
|
||||
bech32validator := vars["validatorAddr"]
|
||||
|
||||
delAddr, err := sdk.AccAddressFromBech32(bech32delegator)
|
||||
valAddr, err := sdk.ValAddressFromBech32(bech32validator)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(fmt.Sprintf("Error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
// Check if there if the delegator is bonded or redelegated to the validator
|
||||
|
||||
validator, statusCode, errMsg, err := getDelegatorValidator(cliCtx, cdc, delAddr, valAddr)
|
||||
if err != nil {
|
||||
w.WriteHeader(statusCode)
|
||||
w.Write([]byte(fmt.Sprintf("%s%s", errMsg, err.Error())))
|
||||
return
|
||||
} else if statusCode == http.StatusNoContent {
|
||||
w.WriteHeader(statusCode)
|
||||
return
|
||||
}
|
||||
output, err = cdc.MarshalJSON(validator)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
w.Write(output)
|
||||
|
||||
validatorAddr, err := sdk.ValAddressFromBech32(bech32validator)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
params := stake.QueryBondsParams{
|
||||
DelegatorAddr: delegatorAddr,
|
||||
ValidatorAddr: validatorAddr,
|
||||
}
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData("custom/stake/delegation", bz)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(res)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO bech32
|
||||
// http request handler to query list of validators
|
||||
func validatorsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc {
|
||||
// HTTP request handler to query all delegator bonded validators
|
||||
func delegatorValidatorsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
kvs, err := cliCtx.QuerySubspace(stake.ValidatorsKey, storeName)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(fmt.Sprintf("couldn't query validators. Error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
// read parameters
|
||||
vars := mux.Vars(r)
|
||||
bech32delegator := vars["delegatorAddr"]
|
||||
|
||||
// the query will return empty if there are no validators
|
||||
if len(kvs) == 0 {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
validators, err := getValidators(kvs, cdc)
|
||||
delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(fmt.Sprintf("Error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
output, err := cdc.MarshalJSON(validators)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(output)
|
||||
params := stake.QueryDelegatorParams{
|
||||
DelegatorAddr: delegatorAddr,
|
||||
}
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData("custom/stake/delegatorValidators", bz)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(res)
|
||||
}
|
||||
}
|
||||
|
||||
// HTTP request handler to get information from a currently bonded validator
|
||||
func delegatorValidatorHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
vars := mux.Vars(r)
|
||||
bech32delegator := vars["delegatorAddr"]
|
||||
bech32validator := vars["validatorAddr"]
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator)
|
||||
validatorAddr, err := sdk.ValAddressFromBech32(bech32validator)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
params := stake.QueryBondsParams{
|
||||
DelegatorAddr: delegatorAddr,
|
||||
ValidatorAddr: validatorAddr,
|
||||
}
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData("custom/stake/delegatorValidator", bz)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(res)
|
||||
}
|
||||
}
|
||||
|
||||
// HTTP request handler to query list of validators
|
||||
func validatorsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
res, err := cliCtx.QueryWithData("custom/stake/validators", nil)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(res)
|
||||
}
|
||||
}
|
||||
|
||||
// HTTP request handler to query the validator information from a given validator address
|
||||
func validatorHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc {
|
||||
func validatorHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var output []byte
|
||||
// read parameters
|
||||
vars := mux.Vars(r)
|
||||
bech32validatorAddr := vars["addr"]
|
||||
|
||||
valAddr, err := sdk.ValAddressFromBech32(bech32validatorAddr)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(fmt.Sprintf("error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
key := stake.GetValidatorKey(valAddr)
|
||||
|
||||
res, err := cliCtx.QueryStore(key, storeName)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(fmt.Sprintf("couldn't query validator, error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
// the query will return empty if there is no data for this record
|
||||
if len(res) == 0 {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
validator, err := types.UnmarshalValidator(cdc, valAddr, res)
|
||||
validatorAddr, err := sdk.ValAddressFromBech32(bech32validatorAddr)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
output, err = cdc.MarshalJSON(validator)
|
||||
params := stake.QueryValidatorParams{
|
||||
ValidatorAddr: validatorAddr,
|
||||
}
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(fmt.Sprintf("Error: %s", err.Error())))
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if output == nil {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
res, err := cliCtx.QueryWithData("custom/stake/validator", bz)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
|
||||
return
|
||||
}
|
||||
w.Write(output)
|
||||
|
||||
w.Write(res)
|
||||
}
|
||||
}
|
||||
|
||||
// HTTP request handler to query the pool information
|
||||
func poolHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc {
|
||||
func poolHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
key := stake.PoolKey
|
||||
|
||||
res, err := cliCtx.QueryStore(key, storeName)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(fmt.Sprintf("couldn't query pool. Error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
pool, err := types.UnmarshalPool(cdc, res)
|
||||
res, err := cliCtx.QueryWithData("custom/stake/pool", nil)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
output, err := cdc.MarshalJSON(pool)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(output)
|
||||
w.Write(res)
|
||||
}
|
||||
}
|
||||
|
||||
// HTTP request handler to query the staking params values
|
||||
func paramsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.HandlerFunc {
|
||||
func paramsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
key := stake.ParamKey
|
||||
|
||||
res, err := cliCtx.QueryStore(key, storeName)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(fmt.Sprintf("couldn't query parameters. Error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
params, err := types.UnmarshalParams(cdc, res)
|
||||
res, err := cliCtx.QueryWithData("custom/stake/parameters", nil)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
output, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(output)
|
||||
w.Write(res)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ package rest
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// RegisterRoutes registers staking-related REST handlers to a router
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) {
|
||||
registerQueryRoutes(cliCtx, r, cdc)
|
||||
registerTxRoutes(cliCtx, r, cdc, kb)
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"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"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
)
|
||||
|
||||
func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
|
||||
func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) {
|
||||
r.HandleFunc(
|
||||
"/stake/delegators/{delegatorAddr}/delegations",
|
||||
delegationsRequestHandlerFn(cdc, kb, cliCtx),
|
||||
@@ -72,7 +72,7 @@ type EditDelegationsBody struct {
|
||||
// nolint: gocyclo
|
||||
// TODO: Split this up into several smaller functions, and remove the above nolint
|
||||
// TODO: use sdk.ValAddress instead of sdk.AccAddress for validators in messages
|
||||
func delegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
func delegationsRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var m EditDelegationsBody
|
||||
|
||||
@@ -329,7 +329,7 @@ func delegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx contex
|
||||
results[i] = res
|
||||
}
|
||||
|
||||
output, err := wire.MarshalJSONIndent(cdc, results[:])
|
||||
output, err := codec.MarshalJSONIndent(cdc, results[:])
|
||||
if err != nil {
|
||||
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
||||
+13
-147
@@ -2,16 +2,12 @@ package rest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/tags"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
)
|
||||
|
||||
// contains checks if the a given query contains one of the tx types
|
||||
@@ -24,155 +20,25 @@ func contains(stringSlice []string, txType string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func getDelegatorValidator(cliCtx context.CLIContext, cdc *wire.Codec, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (
|
||||
validator types.Validator, httpStatusCode int, errMsg string, err error) {
|
||||
|
||||
key := stake.GetDelegationKey(delAddr, valAddr)
|
||||
res, err := cliCtx.QueryStore(key, storeName)
|
||||
if err != nil {
|
||||
return types.Validator{}, http.StatusInternalServerError, "couldn't query delegation. Error: ", err
|
||||
}
|
||||
if len(res) == 0 {
|
||||
return types.Validator{}, http.StatusNoContent, "", nil
|
||||
}
|
||||
|
||||
key = stake.GetValidatorKey(valAddr)
|
||||
res, err = cliCtx.QueryStore(key, storeName)
|
||||
if err != nil {
|
||||
return types.Validator{}, http.StatusInternalServerError, "couldn't query validator. Error: ", err
|
||||
}
|
||||
if len(res) == 0 {
|
||||
return types.Validator{}, http.StatusNoContent, "", nil
|
||||
}
|
||||
validator, err = types.UnmarshalValidator(cdc, valAddr, res)
|
||||
if err != nil {
|
||||
return types.Validator{}, http.StatusBadRequest, "", err
|
||||
}
|
||||
|
||||
return validator, http.StatusOK, "", nil
|
||||
}
|
||||
|
||||
func getDelegatorDelegations(
|
||||
cliCtx context.CLIContext, cdc *wire.Codec, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (
|
||||
outputDelegation DelegationWithoutRat, httpStatusCode int, errMsg string, err error) {
|
||||
|
||||
delegationKey := stake.GetDelegationKey(delAddr, valAddr)
|
||||
marshalledDelegation, err := cliCtx.QueryStore(delegationKey, storeName)
|
||||
if err != nil {
|
||||
return DelegationWithoutRat{}, http.StatusInternalServerError, "couldn't query delegation. Error: ", err
|
||||
}
|
||||
|
||||
if len(marshalledDelegation) == 0 {
|
||||
return DelegationWithoutRat{}, http.StatusNoContent, "", nil
|
||||
}
|
||||
|
||||
delegation, err := types.UnmarshalDelegation(cdc, delegationKey, marshalledDelegation)
|
||||
if err != nil {
|
||||
return DelegationWithoutRat{}, http.StatusInternalServerError, "couldn't unmarshall delegation. Error: ", err
|
||||
}
|
||||
|
||||
outputDelegation = DelegationWithoutRat{
|
||||
DelegatorAddr: delegation.DelegatorAddr,
|
||||
ValidatorAddr: delegation.ValidatorAddr,
|
||||
Height: delegation.Height,
|
||||
Shares: delegation.Shares.String(),
|
||||
}
|
||||
|
||||
return outputDelegation, http.StatusOK, "", nil
|
||||
}
|
||||
|
||||
func getDelegatorUndelegations(
|
||||
cliCtx context.CLIContext, cdc *wire.Codec, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (
|
||||
unbonds types.UnbondingDelegation, httpStatusCode int, errMsg string, err error) {
|
||||
|
||||
undelegationKey := stake.GetUBDKey(delAddr, valAddr)
|
||||
marshalledUnbondingDelegation, err := cliCtx.QueryStore(undelegationKey, storeName)
|
||||
if err != nil {
|
||||
return types.UnbondingDelegation{}, http.StatusInternalServerError, "couldn't query unbonding-delegation. Error: ", err
|
||||
}
|
||||
|
||||
if len(marshalledUnbondingDelegation) == 0 {
|
||||
return types.UnbondingDelegation{}, http.StatusNoContent, "", nil
|
||||
}
|
||||
|
||||
unbondingDelegation, err := types.UnmarshalUBD(cdc, undelegationKey, marshalledUnbondingDelegation)
|
||||
if err != nil {
|
||||
return types.UnbondingDelegation{}, http.StatusInternalServerError, "couldn't unmarshall unbonding-delegation. Error: ", err
|
||||
}
|
||||
return unbondingDelegation, http.StatusOK, "", nil
|
||||
}
|
||||
|
||||
func getDelegatorRedelegations(
|
||||
cliCtx context.CLIContext, cdc *wire.Codec, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (
|
||||
regelegations types.Redelegation, httpStatusCode int, errMsg string, err error) {
|
||||
|
||||
key := stake.GetREDsByDelToValDstIndexKey(delAddr, valAddr)
|
||||
marshalledRedelegations, err := cliCtx.QueryStore(key, storeName)
|
||||
if err != nil {
|
||||
return types.Redelegation{}, http.StatusInternalServerError, "couldn't query redelegation. Error: ", err
|
||||
}
|
||||
|
||||
if len(marshalledRedelegations) == 0 {
|
||||
return types.Redelegation{}, http.StatusNoContent, "", nil
|
||||
}
|
||||
|
||||
redelegations, err := types.UnmarshalRED(cdc, key, marshalledRedelegations)
|
||||
if err != nil {
|
||||
return types.Redelegation{}, http.StatusInternalServerError, "couldn't unmarshall redelegations. Error: ", err
|
||||
}
|
||||
|
||||
return redelegations, http.StatusOK, "", nil
|
||||
}
|
||||
|
||||
// queries staking txs
|
||||
func queryTxs(node rpcclient.Client, cdc *wire.Codec, tag string, delegatorAddr string) ([]tx.Info, error) {
|
||||
func queryTxs(node rpcclient.Client, cliCtx context.CLIContext, cdc *codec.Codec, tag string, delegatorAddr string) ([]tx.Info, error) {
|
||||
page := 0
|
||||
perPage := 100
|
||||
prove := false
|
||||
prove := !cliCtx.TrustNode
|
||||
query := fmt.Sprintf("%s='%s' AND %s='%s'", tags.Action, tag, tags.Delegator, delegatorAddr)
|
||||
res, err := node.TxSearch(query, prove, page, perPage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if prove {
|
||||
for _, txData := range res.Txs {
|
||||
err := tx.ValidateTxResult(cliCtx, txData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tx.FormatTxResults(cdc, res.Txs)
|
||||
}
|
||||
|
||||
// gets all validators
|
||||
func getValidators(validatorKVs []sdk.KVPair, cdc *wire.Codec) ([]types.Validator, error) {
|
||||
validators := make([]types.Validator, len(validatorKVs))
|
||||
for i, kv := range validatorKVs {
|
||||
|
||||
addr := kv.Key[1:]
|
||||
validator, err := types.UnmarshalValidator(cdc, addr, kv.Value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
validators[i] = validator
|
||||
}
|
||||
return validators, nil
|
||||
}
|
||||
|
||||
// gets all Bech32 validators from a key
|
||||
// nolint: unparam
|
||||
func getBech32Validators(storeName string, cliCtx context.CLIContext, cdc *wire.Codec) (
|
||||
validators []types.Validator, httpStatusCode int, errMsg string, err error) {
|
||||
|
||||
// Get all validators using key
|
||||
kvs, err := cliCtx.QuerySubspace(stake.ValidatorsKey, storeName)
|
||||
if err != nil {
|
||||
return nil, http.StatusInternalServerError, "couldn't query validators. Error: ", err
|
||||
}
|
||||
|
||||
// the query will return empty if there are no validators
|
||||
if len(kvs) == 0 {
|
||||
return nil, http.StatusNoContent, "", nil
|
||||
}
|
||||
|
||||
validators, err = getValidators(kvs, cdc)
|
||||
if err != nil {
|
||||
return nil, http.StatusInternalServerError, "Error: ", err
|
||||
}
|
||||
return validators, http.StatusOK, "", nil
|
||||
}
|
||||
|
||||
@@ -42,6 +42,12 @@ func TestInitGenesis(t *testing.T) {
|
||||
vals, err := InitGenesis(ctx, keeper, genesisState)
|
||||
require.NoError(t, err)
|
||||
|
||||
actualGenesis := WriteGenesis(ctx, keeper)
|
||||
require.Equal(t, genesisState.Pool, actualGenesis.Pool)
|
||||
require.Equal(t, genesisState.Params, actualGenesis.Params)
|
||||
require.Equal(t, genesisState.Bonds, actualGenesis.Bonds)
|
||||
require.EqualValues(t, keeper.GetAllValidators(ctx), actualGenesis.Validators)
|
||||
|
||||
// now make sure the validators are bonded and intra-tx counters are correct
|
||||
resVal, found := keeper.GetValidator(ctx, sdk.ValAddress(keep.Addrs[0]))
|
||||
require.True(t, found)
|
||||
|
||||
@@ -17,14 +17,14 @@ import (
|
||||
//______________________________________________________________________
|
||||
|
||||
func newTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt int64) MsgCreateValidator {
|
||||
return types.NewMsgCreateValidator(address, pubKey, sdk.Coin{"steak", sdk.NewInt(amt)}, Description{})
|
||||
return types.NewMsgCreateValidator(address, pubKey, sdk.NewCoin("steak", sdk.NewInt(amt)), Description{})
|
||||
}
|
||||
|
||||
func newTestMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt int64) MsgDelegate {
|
||||
return MsgDelegate{
|
||||
DelegatorAddr: delAddr,
|
||||
ValidatorAddr: valAddr,
|
||||
Delegation: sdk.Coin{"steak", sdk.NewInt(amt)},
|
||||
Delegation: sdk.NewCoin("steak", sdk.NewInt(amt)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func newTestMsgCreateValidatorOnBehalfOf(delAddr sdk.AccAddress, valAddr sdk.Val
|
||||
DelegatorAddr: delAddr,
|
||||
ValidatorAddr: valAddr,
|
||||
PubKey: valPubKey,
|
||||
Delegation: sdk.Coin{"steak", sdk.NewInt(amt)},
|
||||
Delegation: sdk.NewCoin("steak", sdk.NewInt(amt)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
)
|
||||
|
||||
// load a delegation
|
||||
// return a specific delegation
|
||||
func (k Keeper) GetDelegation(ctx sdk.Context,
|
||||
delAddr sdk.AccAddress, valAddr sdk.ValAddress) (
|
||||
delegation types.Delegation, found bool) {
|
||||
@@ -24,44 +24,37 @@ func (k Keeper) GetDelegation(ctx sdk.Context,
|
||||
return delegation, true
|
||||
}
|
||||
|
||||
// load all delegations used during genesis dump
|
||||
// return all delegations used during genesis dump
|
||||
func (k Keeper) GetAllDelegations(ctx sdk.Context) (delegations []types.Delegation) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
iterator := sdk.KVStorePrefixIterator(store, DelegationKey)
|
||||
defer iterator.Close()
|
||||
|
||||
i := 0
|
||||
for ; ; i++ {
|
||||
if !iterator.Valid() {
|
||||
break
|
||||
}
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
delegation := types.MustUnmarshalDelegation(k.cdc, iterator.Key(), iterator.Value())
|
||||
delegations = append(delegations, delegation)
|
||||
iterator.Next()
|
||||
}
|
||||
iterator.Close()
|
||||
return delegations
|
||||
}
|
||||
|
||||
// load all delegations for a delegator
|
||||
func (k Keeper) GetDelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
||||
maxRetrieve int16) (delegations []types.Delegation) {
|
||||
// return a given amount of all the delegations from a delegator
|
||||
func (k Keeper) GetDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
||||
maxRetrieve uint16) (delegations []types.Delegation) {
|
||||
|
||||
delegations = make([]types.Delegation, maxRetrieve)
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
delegatorPrefixKey := GetDelegationsKey(delegator)
|
||||
iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) //smallest to largest
|
||||
iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey)
|
||||
defer iterator.Close()
|
||||
|
||||
delegations = make([]types.Delegation, maxRetrieve)
|
||||
i := 0
|
||||
for ; ; i++ {
|
||||
if !iterator.Valid() || i > int(maxRetrieve-1) {
|
||||
break
|
||||
}
|
||||
for ; iterator.Valid() && i < int(maxRetrieve); iterator.Next() {
|
||||
delegation := types.MustUnmarshalDelegation(k.cdc, iterator.Key(), iterator.Value())
|
||||
delegations[i] = delegation
|
||||
iterator.Next()
|
||||
i++
|
||||
}
|
||||
iterator.Close()
|
||||
return delegations[:i] // trim
|
||||
return delegations[:i] // trim if the array length < maxRetrieve
|
||||
}
|
||||
|
||||
// iterate through all of the delegations from a delegator
|
||||
@@ -89,7 +82,7 @@ func (k Keeper) SetDelegation(ctx sdk.Context, delegation types.Delegation) {
|
||||
store.Set(GetDelegationKey(delegation.DelegatorAddr, delegation.ValidatorAddr), b)
|
||||
}
|
||||
|
||||
// remove the delegation
|
||||
// remove a delegation from store
|
||||
func (k Keeper) RemoveDelegation(ctx sdk.Context, delegation types.Delegation) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
store.Delete(GetDelegationKey(delegation.DelegatorAddr, delegation.ValidatorAddr))
|
||||
@@ -97,7 +90,27 @@ func (k Keeper) RemoveDelegation(ctx sdk.Context, delegation types.Delegation) {
|
||||
|
||||
//_____________________________________________________________________________________
|
||||
|
||||
// load a unbonding delegation
|
||||
// return a given amount of all the delegator unbonding-delegations
|
||||
func (k Keeper) GetUnbondingDelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
||||
maxRetrieve uint16) (unbondingDelegations []types.UnbondingDelegation) {
|
||||
|
||||
unbondingDelegations = make([]types.UnbondingDelegation, maxRetrieve)
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
delegatorPrefixKey := GetUBDsKey(delegator)
|
||||
iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey)
|
||||
defer iterator.Close()
|
||||
|
||||
i := 0
|
||||
for ; iterator.Valid() && i < int(maxRetrieve); iterator.Next() {
|
||||
unbondingDelegation := types.MustUnmarshalUBD(k.cdc, iterator.Key(), iterator.Value())
|
||||
unbondingDelegations[i] = unbondingDelegation
|
||||
i++
|
||||
}
|
||||
return unbondingDelegations[:i] // trim if the array length < maxRetrieve
|
||||
}
|
||||
|
||||
// return a unbonding delegation
|
||||
func (k Keeper) GetUnbondingDelegation(ctx sdk.Context,
|
||||
delAddr sdk.AccAddress, valAddr sdk.ValAddress) (ubd types.UnbondingDelegation, found bool) {
|
||||
|
||||
@@ -112,21 +125,18 @@ func (k Keeper) GetUnbondingDelegation(ctx sdk.Context,
|
||||
return ubd, true
|
||||
}
|
||||
|
||||
// load all unbonding delegations from a particular validator
|
||||
// return all unbonding delegations from a particular validator
|
||||
func (k Keeper) GetUnbondingDelegationsFromValidator(ctx sdk.Context, valAddr sdk.ValAddress) (ubds []types.UnbondingDelegation) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
iterator := sdk.KVStorePrefixIterator(store, GetUBDsByValIndexKey(valAddr))
|
||||
for {
|
||||
if !iterator.Valid() {
|
||||
break
|
||||
}
|
||||
defer iterator.Close()
|
||||
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
key := GetUBDKeyFromValIndexKey(iterator.Key())
|
||||
value := store.Get(key)
|
||||
ubd := types.MustUnmarshalUBD(k.cdc, key, value)
|
||||
ubds = append(ubds, ubd)
|
||||
iterator.Next()
|
||||
}
|
||||
iterator.Close()
|
||||
return ubds
|
||||
}
|
||||
|
||||
@@ -134,16 +144,15 @@ func (k Keeper) GetUnbondingDelegationsFromValidator(ctx sdk.Context, valAddr sd
|
||||
func (k Keeper) IterateUnbondingDelegations(ctx sdk.Context, fn func(index int64, ubd types.UnbondingDelegation) (stop bool)) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
iterator := sdk.KVStorePrefixIterator(store, UnbondingDelegationKey)
|
||||
i := int64(0)
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
defer iterator.Close()
|
||||
|
||||
for i := int64(0); iterator.Valid(); iterator.Next() {
|
||||
ubd := types.MustUnmarshalUBD(k.cdc, iterator.Key(), iterator.Value())
|
||||
stop := fn(i, ubd)
|
||||
if stop {
|
||||
if stop := fn(i, ubd); stop {
|
||||
break
|
||||
}
|
||||
i++
|
||||
}
|
||||
iterator.Close()
|
||||
}
|
||||
|
||||
// set the unbonding delegation and associated index
|
||||
@@ -165,7 +174,26 @@ func (k Keeper) RemoveUnbondingDelegation(ctx sdk.Context, ubd types.UnbondingDe
|
||||
|
||||
//_____________________________________________________________________________________
|
||||
|
||||
// load a redelegation
|
||||
// return a given amount of all the delegator redelegations
|
||||
func (k Keeper) GetRedelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
||||
maxRetrieve uint16) (redelegations []types.Redelegation) {
|
||||
redelegations = make([]types.Redelegation, maxRetrieve)
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
delegatorPrefixKey := GetREDsKey(delegator)
|
||||
iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey)
|
||||
defer iterator.Close()
|
||||
|
||||
i := 0
|
||||
for ; iterator.Valid() && i < int(maxRetrieve); iterator.Next() {
|
||||
redelegation := types.MustUnmarshalRED(k.cdc, iterator.Key(), iterator.Value())
|
||||
redelegations[i] = redelegation
|
||||
i++
|
||||
}
|
||||
return redelegations[:i] // trim if the array length < maxRetrieve
|
||||
}
|
||||
|
||||
// return a redelegation
|
||||
func (k Keeper) GetRedelegation(ctx sdk.Context,
|
||||
delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress) (red types.Redelegation, found bool) {
|
||||
|
||||
@@ -180,38 +208,34 @@ func (k Keeper) GetRedelegation(ctx sdk.Context,
|
||||
return red, true
|
||||
}
|
||||
|
||||
// load all redelegations from a particular validator
|
||||
// return all redelegations from a particular validator
|
||||
func (k Keeper) GetRedelegationsFromValidator(ctx sdk.Context, valAddr sdk.ValAddress) (reds []types.Redelegation) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
iterator := sdk.KVStorePrefixIterator(store, GetREDsFromValSrcIndexKey(valAddr))
|
||||
for {
|
||||
if !iterator.Valid() {
|
||||
break
|
||||
}
|
||||
defer iterator.Close()
|
||||
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
key := GetREDKeyFromValSrcIndexKey(iterator.Key())
|
||||
value := store.Get(key)
|
||||
red := types.MustUnmarshalRED(k.cdc, key, value)
|
||||
reds = append(reds, red)
|
||||
iterator.Next()
|
||||
}
|
||||
iterator.Close()
|
||||
return reds
|
||||
}
|
||||
|
||||
// has a redelegation
|
||||
// check if validator is receiving a redelegation
|
||||
func (k Keeper) HasReceivingRedelegation(ctx sdk.Context,
|
||||
delAddr sdk.AccAddress, valDstAddr sdk.ValAddress) bool {
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
prefix := GetREDsByDelToValDstIndexKey(delAddr, valDstAddr)
|
||||
iterator := sdk.KVStorePrefixIterator(store, prefix) //smallest to largest
|
||||
iterator := sdk.KVStorePrefixIterator(store, prefix)
|
||||
defer iterator.Close()
|
||||
|
||||
found := false
|
||||
if iterator.Valid() {
|
||||
//record found
|
||||
found = true
|
||||
}
|
||||
iterator.Close()
|
||||
return found
|
||||
}
|
||||
|
||||
@@ -376,7 +400,7 @@ func (k Keeper) BeginUnbonding(ctx sdk.Context,
|
||||
// create the unbonding delegation
|
||||
params := k.GetParams(ctx)
|
||||
minTime, height, completeNow := k.getBeginInfo(ctx, params, valAddr)
|
||||
balance := sdk.Coin{params.BondDenom, returnAmount.RoundInt()}
|
||||
balance := sdk.NewCoin(params.BondDenom, returnAmount.RoundInt())
|
||||
|
||||
// no need to create the ubd object just complete now
|
||||
if completeNow {
|
||||
@@ -436,7 +460,7 @@ func (k Keeper) BeginRedelegation(ctx sdk.Context, delAddr sdk.AccAddress,
|
||||
}
|
||||
|
||||
params := k.GetParams(ctx)
|
||||
returnCoin := sdk.Coin{params.BondDenom, returnAmount.RoundInt()}
|
||||
returnCoin := sdk.NewCoin(params.BondDenom, returnAmount.RoundInt())
|
||||
dstValidator, found := k.GetValidator(ctx, valDstAddr)
|
||||
if !found {
|
||||
return types.ErrBadRedelegationDst(k.Codespace())
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// tests GetDelegation, GetDelegations, SetDelegation, RemoveDelegation, GetDelegations
|
||||
// tests GetDelegation, GetDelegatorDelegations, SetDelegation, RemoveDelegation, GetDelegatorDelegations
|
||||
func TestDelegation(t *testing.T) {
|
||||
ctx, _, keeper := CreateTestInput(t, false, 10)
|
||||
pool := keeper.GetPool(ctx)
|
||||
@@ -30,6 +30,7 @@ func TestDelegation(t *testing.T) {
|
||||
validators[2] = keeper.UpdateValidator(ctx, validators[2])
|
||||
|
||||
// first add a validators[0] to delegate too
|
||||
|
||||
bond1to1 := types.Delegation{
|
||||
DelegatorAddr: addrDels[0],
|
||||
ValidatorAddr: addrVals[0],
|
||||
@@ -66,16 +67,16 @@ func TestDelegation(t *testing.T) {
|
||||
keeper.SetDelegation(ctx, bond2to3)
|
||||
|
||||
// test all bond retrieve capabilities
|
||||
resBonds := keeper.GetDelegations(ctx, addrDels[0], 5)
|
||||
resBonds := keeper.GetDelegatorDelegations(ctx, addrDels[0], 5)
|
||||
require.Equal(t, 3, len(resBonds))
|
||||
require.True(t, bond1to1.Equal(resBonds[0]))
|
||||
require.True(t, bond1to2.Equal(resBonds[1]))
|
||||
require.True(t, bond1to3.Equal(resBonds[2]))
|
||||
resBonds = keeper.GetDelegations(ctx, addrDels[0], 3)
|
||||
resBonds = keeper.GetAllDelegatorDelegations(ctx, addrDels[0])
|
||||
require.Equal(t, 3, len(resBonds))
|
||||
resBonds = keeper.GetDelegations(ctx, addrDels[0], 2)
|
||||
resBonds = keeper.GetDelegatorDelegations(ctx, addrDels[0], 2)
|
||||
require.Equal(t, 2, len(resBonds))
|
||||
resBonds = keeper.GetDelegations(ctx, addrDels[1], 5)
|
||||
resBonds = keeper.GetDelegatorDelegations(ctx, addrDels[1], 5)
|
||||
require.Equal(t, 3, len(resBonds))
|
||||
require.True(t, bond2to1.Equal(resBonds[0]))
|
||||
require.True(t, bond2to2.Equal(resBonds[1]))
|
||||
@@ -89,15 +90,34 @@ func TestDelegation(t *testing.T) {
|
||||
require.True(t, bond2to2.Equal(allBonds[4]))
|
||||
require.True(t, bond2to3.Equal(allBonds[5]))
|
||||
|
||||
resVals := keeper.GetDelegatorValidators(ctx, addrDels[0], 3)
|
||||
require.Equal(t, 3, len(resVals))
|
||||
resVals = keeper.GetDelegatorValidators(ctx, addrDels[1], 4)
|
||||
require.Equal(t, 3, len(resVals))
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
|
||||
resVal, err := keeper.GetDelegatorValidator(ctx, addrDels[0], addrVals[i])
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, addrVals[i], resVal.GetOperator())
|
||||
|
||||
resVal, err = keeper.GetDelegatorValidator(ctx, addrDels[1], addrVals[i])
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, addrVals[i], resVal.GetOperator())
|
||||
}
|
||||
|
||||
// delete a record
|
||||
keeper.RemoveDelegation(ctx, bond2to3)
|
||||
_, found = keeper.GetDelegation(ctx, addrDels[1], addrVals[2])
|
||||
require.False(t, found)
|
||||
resBonds = keeper.GetDelegations(ctx, addrDels[1], 5)
|
||||
resBonds = keeper.GetDelegatorDelegations(ctx, addrDels[1], 5)
|
||||
require.Equal(t, 2, len(resBonds))
|
||||
require.True(t, bond2to1.Equal(resBonds[0]))
|
||||
require.True(t, bond2to2.Equal(resBonds[1]))
|
||||
|
||||
resBonds = keeper.GetAllDelegatorDelegations(ctx, addrDels[1])
|
||||
require.Equal(t, 2, len(resBonds))
|
||||
|
||||
// delete all the records from delegator 2
|
||||
keeper.RemoveDelegation(ctx, bond2to1)
|
||||
keeper.RemoveDelegation(ctx, bond2to2)
|
||||
@@ -105,7 +125,7 @@ func TestDelegation(t *testing.T) {
|
||||
require.False(t, found)
|
||||
_, found = keeper.GetDelegation(ctx, addrDels[1], addrVals[1])
|
||||
require.False(t, found)
|
||||
resBonds = keeper.GetDelegations(ctx, addrDels[1], 5)
|
||||
resBonds = keeper.GetDelegatorDelegations(ctx, addrDels[1], 5)
|
||||
require.Equal(t, 0, len(resBonds))
|
||||
}
|
||||
|
||||
@@ -123,21 +143,35 @@ func TestUnbondingDelegation(t *testing.T) {
|
||||
|
||||
// set and retrieve a record
|
||||
keeper.SetUnbondingDelegation(ctx, ubd)
|
||||
resBond, found := keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
|
||||
resUnbond, found := keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
|
||||
require.True(t, found)
|
||||
require.True(t, ubd.Equal(resBond))
|
||||
require.True(t, ubd.Equal(resUnbond))
|
||||
|
||||
// modify a records, save, and retrieve
|
||||
ubd.Balance = sdk.NewInt64Coin("steak", 21)
|
||||
keeper.SetUnbondingDelegation(ctx, ubd)
|
||||
resBond, found = keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
|
||||
|
||||
resUnbonds := keeper.GetUnbondingDelegations(ctx, addrDels[0], 5)
|
||||
require.Equal(t, 1, len(resUnbonds))
|
||||
|
||||
resUnbonds = keeper.GetAllUnbondingDelegations(ctx, addrDels[0])
|
||||
require.Equal(t, 1, len(resUnbonds))
|
||||
|
||||
resUnbond, found = keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
|
||||
require.True(t, found)
|
||||
require.True(t, ubd.Equal(resBond))
|
||||
require.True(t, ubd.Equal(resUnbond))
|
||||
|
||||
// delete a record
|
||||
keeper.RemoveUnbondingDelegation(ctx, ubd)
|
||||
_, found = keeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
|
||||
require.False(t, found)
|
||||
|
||||
resUnbonds = keeper.GetUnbondingDelegations(ctx, addrDels[0], 5)
|
||||
require.Equal(t, 0, len(resUnbonds))
|
||||
|
||||
resUnbonds = keeper.GetAllUnbondingDelegations(ctx, addrDels[0])
|
||||
require.Equal(t, 0, len(resUnbonds))
|
||||
|
||||
}
|
||||
|
||||
func TestUnbondDelegation(t *testing.T) {
|
||||
@@ -413,12 +447,20 @@ func TestRedelegation(t *testing.T) {
|
||||
|
||||
// set and retrieve a record
|
||||
keeper.SetRedelegation(ctx, rd)
|
||||
resBond, found := keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
|
||||
resRed, found := keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
|
||||
require.True(t, found)
|
||||
|
||||
redelegations := keeper.GetRedelegationsFromValidator(ctx, addrVals[0])
|
||||
require.Equal(t, 1, len(redelegations))
|
||||
require.True(t, redelegations[0].Equal(resBond))
|
||||
require.True(t, redelegations[0].Equal(resRed))
|
||||
|
||||
redelegations = keeper.GetRedelegations(ctx, addrDels[0], 5)
|
||||
require.Equal(t, 1, len(redelegations))
|
||||
require.True(t, redelegations[0].Equal(resRed))
|
||||
|
||||
redelegations = keeper.GetAllRedelegations(ctx, addrDels[0])
|
||||
require.Equal(t, 1, len(redelegations))
|
||||
require.True(t, redelegations[0].Equal(resRed))
|
||||
|
||||
// check if has the redelegation
|
||||
has = keeper.HasReceivingRedelegation(ctx, addrDels[0], addrVals[1])
|
||||
@@ -429,18 +471,28 @@ func TestRedelegation(t *testing.T) {
|
||||
rd.SharesDst = sdk.NewDec(21)
|
||||
keeper.SetRedelegation(ctx, rd)
|
||||
|
||||
resBond, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
|
||||
resRed, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
|
||||
require.True(t, found)
|
||||
require.True(t, rd.Equal(resBond))
|
||||
require.True(t, rd.Equal(resRed))
|
||||
|
||||
redelegations = keeper.GetRedelegationsFromValidator(ctx, addrVals[0])
|
||||
require.Equal(t, 1, len(redelegations))
|
||||
require.True(t, redelegations[0].Equal(resBond))
|
||||
require.True(t, redelegations[0].Equal(resRed))
|
||||
|
||||
redelegations = keeper.GetRedelegations(ctx, addrDels[0], 5)
|
||||
require.Equal(t, 1, len(redelegations))
|
||||
require.True(t, redelegations[0].Equal(resRed))
|
||||
|
||||
// delete a record
|
||||
keeper.RemoveRedelegation(ctx, rd)
|
||||
_, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
|
||||
require.False(t, found)
|
||||
|
||||
redelegations = keeper.GetRedelegations(ctx, addrDels[0], 5)
|
||||
require.Equal(t, 0, len(redelegations))
|
||||
|
||||
redelegations = keeper.GetAllRedelegations(ctx, addrDels[0])
|
||||
require.Equal(t, 0, len(redelegations))
|
||||
}
|
||||
|
||||
func TestRedelegateSelfDelegation(t *testing.T) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
type Keeper struct {
|
||||
storeKey sdk.StoreKey
|
||||
storeTKey sdk.StoreKey
|
||||
cdc *wire.Codec
|
||||
cdc *codec.Codec
|
||||
bankKeeper bank.Keeper
|
||||
validatorHooks sdk.ValidatorHooks
|
||||
|
||||
@@ -20,7 +20,7 @@ type Keeper struct {
|
||||
codespace sdk.CodespaceType
|
||||
}
|
||||
|
||||
func NewKeeper(cdc *wire.Codec, key, tkey sdk.StoreKey, ck bank.Keeper, codespace sdk.CodespaceType) Keeper {
|
||||
func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey, ck bank.Keeper, codespace sdk.CodespaceType) Keeper {
|
||||
keeper := Keeper{
|
||||
storeKey: key,
|
||||
storeTKey: tkey,
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
)
|
||||
|
||||
// Return all validators that a delegator is bonded to. If maxRetrieve is supplied, the respective amount will be returned.
|
||||
func (k Keeper) GetDelegatorValidators(ctx sdk.Context, delegatorAddr sdk.AccAddress,
|
||||
maxRetrieve uint16) (validators []types.Validator) {
|
||||
validators = make([]types.Validator, maxRetrieve)
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
delegatorPrefixKey := GetDelegationsKey(delegatorAddr)
|
||||
iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) //smallest to largest
|
||||
defer iterator.Close()
|
||||
|
||||
i := 0
|
||||
for ; iterator.Valid() && i < int(maxRetrieve); iterator.Next() {
|
||||
addr := iterator.Key()
|
||||
delegation := types.MustUnmarshalDelegation(k.cdc, addr, iterator.Value())
|
||||
|
||||
validator, found := k.GetValidator(ctx, delegation.ValidatorAddr)
|
||||
if !found {
|
||||
panic(types.ErrNoValidatorFound(types.DefaultCodespace))
|
||||
}
|
||||
validators[i] = validator
|
||||
i++
|
||||
}
|
||||
return validators[:i] // trim
|
||||
}
|
||||
|
||||
// return a validator that a delegator is bonded to
|
||||
func (k Keeper) GetDelegatorValidator(ctx sdk.Context, delegatorAddr sdk.AccAddress,
|
||||
validatorAddr sdk.ValAddress) (validator types.Validator, err sdk.Error) {
|
||||
|
||||
delegation, found := k.GetDelegation(ctx, delegatorAddr, validatorAddr)
|
||||
if !found {
|
||||
return validator, types.ErrNoDelegation(types.DefaultCodespace)
|
||||
}
|
||||
|
||||
validator, found = k.GetValidator(ctx, delegation.ValidatorAddr)
|
||||
if !found {
|
||||
panic(types.ErrNoValidatorFound(types.DefaultCodespace))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________________
|
||||
|
||||
// return all delegations for a delegator
|
||||
func (k Keeper) GetAllDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddress) (
|
||||
delegations []types.Delegation) {
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
delegatorPrefixKey := GetDelegationsKey(delegator)
|
||||
iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) //smallest to largest
|
||||
defer iterator.Close()
|
||||
|
||||
i := 0
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
delegation := types.MustUnmarshalDelegation(k.cdc, iterator.Key(), iterator.Value())
|
||||
delegations = append(delegations, delegation)
|
||||
i++
|
||||
}
|
||||
return delegations
|
||||
}
|
||||
|
||||
// return all unbonding-delegations for a delegator
|
||||
func (k Keeper) GetAllUnbondingDelegations(ctx sdk.Context, delegator sdk.AccAddress) (
|
||||
unbondingDelegations []types.UnbondingDelegation) {
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
delegatorPrefixKey := GetUBDsKey(delegator)
|
||||
iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) //smallest to largest
|
||||
defer iterator.Close()
|
||||
|
||||
i := 0
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
unbondingDelegation := types.MustUnmarshalUBD(k.cdc, iterator.Key(), iterator.Value())
|
||||
unbondingDelegations = append(unbondingDelegations, unbondingDelegation)
|
||||
i++
|
||||
}
|
||||
return unbondingDelegations
|
||||
}
|
||||
|
||||
// return all redelegations for a delegator
|
||||
func (k Keeper) GetAllRedelegations(ctx sdk.Context, delegator sdk.AccAddress) (redelegations []types.Redelegation) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
delegatorPrefixKey := GetREDsKey(delegator)
|
||||
iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) //smallest to largest
|
||||
defer iterator.Close()
|
||||
|
||||
i := 0
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
redelegation := types.MustUnmarshalRED(k.cdc, iterator.Key(), iterator.Value())
|
||||
redelegations = append(redelegations, redelegation)
|
||||
i++
|
||||
}
|
||||
return redelegations
|
||||
}
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
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/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
@@ -52,8 +52,8 @@ func ValEq(t *testing.T, exp, got types.Validator) (*testing.T, bool, string, ty
|
||||
//_______________________________________________________________________________________
|
||||
|
||||
// create a codec used only for testing
|
||||
func MakeTestCodec() *wire.Codec {
|
||||
var cdc = wire.NewCodec()
|
||||
func MakeTestCodec() *codec.Codec {
|
||||
var cdc = codec.New()
|
||||
|
||||
// Register Msgs
|
||||
cdc.RegisterInterface((*sdk.Msg)(nil), nil)
|
||||
@@ -69,7 +69,7 @@ func MakeTestCodec() *wire.Codec {
|
||||
// Register AppAccount
|
||||
cdc.RegisterInterface((*auth.Account)(nil), nil)
|
||||
cdc.RegisterConcrete(&auth.BaseAccount{}, "test/stake/Account", nil)
|
||||
wire.RegisterCrypto(cdc)
|
||||
codec.RegisterCrypto(cdc)
|
||||
|
||||
return cdc
|
||||
}
|
||||
|
||||
+22
-40
@@ -104,39 +104,32 @@ func (k Keeper) validatorByPowerIndexExists(ctx sdk.Context, power []byte) bool
|
||||
func (k Keeper) GetAllValidators(ctx sdk.Context) (validators []types.Validator) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
iterator := sdk.KVStorePrefixIterator(store, ValidatorsKey)
|
||||
defer iterator.Close()
|
||||
|
||||
i := 0
|
||||
for ; ; i++ {
|
||||
if !iterator.Valid() {
|
||||
break
|
||||
}
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
addr := iterator.Key()[1:]
|
||||
validator := types.MustUnmarshalValidator(k.cdc, addr, iterator.Value())
|
||||
validators = append(validators, validator)
|
||||
iterator.Next()
|
||||
}
|
||||
iterator.Close()
|
||||
return validators
|
||||
}
|
||||
|
||||
// Get the set of all validators, retrieve a maxRetrieve number of records
|
||||
func (k Keeper) GetValidators(ctx sdk.Context, maxRetrieve int16) (validators []types.Validator) {
|
||||
// return a given amount of all the validators
|
||||
func (k Keeper) GetValidators(ctx sdk.Context, maxRetrieve uint16) (validators []types.Validator) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
iterator := sdk.KVStorePrefixIterator(store, ValidatorsKey)
|
||||
|
||||
validators = make([]types.Validator, maxRetrieve)
|
||||
|
||||
iterator := sdk.KVStorePrefixIterator(store, ValidatorsKey)
|
||||
defer iterator.Close()
|
||||
|
||||
i := 0
|
||||
for ; ; i++ {
|
||||
if !iterator.Valid() || i > int(maxRetrieve-1) {
|
||||
break
|
||||
}
|
||||
for ; iterator.Valid() && i < int(maxRetrieve); iterator.Next() {
|
||||
addr := iterator.Key()[1:]
|
||||
validator := types.MustUnmarshalValidator(k.cdc, addr, iterator.Value())
|
||||
validators[i] = validator
|
||||
iterator.Next()
|
||||
i++
|
||||
}
|
||||
iterator.Close()
|
||||
return validators[:i] // trim
|
||||
return validators[:i] // trim if the array length < maxRetrieve
|
||||
}
|
||||
|
||||
//___________________________________________________________________________
|
||||
@@ -150,6 +143,8 @@ func (k Keeper) GetValidatorsBonded(ctx sdk.Context) (validators []types.Validat
|
||||
validators = make([]types.Validator, maxValidators)
|
||||
|
||||
iterator := sdk.KVStorePrefixIterator(store, ValidatorsBondedIndexKey)
|
||||
defer iterator.Close()
|
||||
|
||||
i := 0
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
|
||||
@@ -164,7 +159,6 @@ func (k Keeper) GetValidatorsBonded(ctx sdk.Context) (validators []types.Validat
|
||||
validators[i] = validator
|
||||
i++
|
||||
}
|
||||
iterator.Close()
|
||||
return validators[:i] // trim
|
||||
}
|
||||
|
||||
@@ -175,12 +169,12 @@ func (k Keeper) GetValidatorsByPower(ctx sdk.Context) []types.Validator {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
maxValidators := k.GetParams(ctx).MaxValidators
|
||||
validators := make([]types.Validator, maxValidators)
|
||||
iterator := sdk.KVStoreReversePrefixIterator(store, ValidatorsByPowerIndexKey) // largest to smallest
|
||||
|
||||
iterator := sdk.KVStoreReversePrefixIterator(store, ValidatorsByPowerIndexKey)
|
||||
defer iterator.Close()
|
||||
|
||||
i := 0
|
||||
for {
|
||||
if !iterator.Valid() || i > int(maxValidators-1) {
|
||||
break
|
||||
}
|
||||
for ; iterator.Valid() && i < int(maxValidators); iterator.Next() {
|
||||
address := iterator.Value()
|
||||
validator, found := k.GetValidator(ctx, address)
|
||||
ensureValidatorFound(found, address)
|
||||
@@ -189,9 +183,7 @@ func (k Keeper) GetValidatorsByPower(ctx sdk.Context) []types.Validator {
|
||||
validators[i] = validator
|
||||
i++
|
||||
}
|
||||
iterator.Next()
|
||||
}
|
||||
iterator.Close()
|
||||
return validators[:i] // trim
|
||||
}
|
||||
|
||||
@@ -207,6 +199,8 @@ func (k Keeper) GetValidTendermintUpdates(ctx sdk.Context) (updates []abci.Valid
|
||||
tstore := ctx.TransientStore(k.storeTKey)
|
||||
|
||||
iterator := sdk.KVStorePrefixIterator(tstore, TendermintUpdatesTKey)
|
||||
defer iterator.Close()
|
||||
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
var abciVal abci.Validator
|
||||
|
||||
@@ -229,8 +223,6 @@ func (k Keeper) GetValidTendermintUpdates(ctx sdk.Context) (updates []abci.Valid
|
||||
updates = append(updates, abciVal)
|
||||
}
|
||||
}
|
||||
|
||||
iterator.Close()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -448,10 +440,7 @@ func (k Keeper) UpdateBondedValidators(
|
||||
|
||||
// create a validator iterator ranging from largest to smallest by power
|
||||
iterator := sdk.KVStoreReversePrefixIterator(store, ValidatorsByPowerIndexKey)
|
||||
for {
|
||||
if !iterator.Valid() || bondedValidatorsCount > int(maxValidators-1) {
|
||||
break
|
||||
}
|
||||
for ; iterator.Valid() && bondedValidatorsCount < int(maxValidators); iterator.Next() {
|
||||
|
||||
// either retrieve the original validator from the store, or under the
|
||||
// situation that this is the "affected validator" just use the
|
||||
@@ -485,7 +474,6 @@ func (k Keeper) UpdateBondedValidators(
|
||||
}
|
||||
|
||||
bondedValidatorsCount++
|
||||
iterator.Next()
|
||||
}
|
||||
|
||||
iterator.Close()
|
||||
@@ -552,11 +540,7 @@ func (k Keeper) UpdateBondedValidatorsFull(ctx sdk.Context) {
|
||||
bondedValidatorsCount := 0
|
||||
|
||||
iterator = sdk.KVStoreReversePrefixIterator(store, ValidatorsByPowerIndexKey)
|
||||
for {
|
||||
if !iterator.Valid() || bondedValidatorsCount > int(maxValidators-1) {
|
||||
break
|
||||
}
|
||||
|
||||
for ; iterator.Valid() && bondedValidatorsCount < int(maxValidators); iterator.Next() {
|
||||
var found bool
|
||||
|
||||
ownerAddr := iterator.Value()
|
||||
@@ -579,12 +563,10 @@ func (k Keeper) UpdateBondedValidatorsFull(ctx sdk.Context) {
|
||||
if validator.Status == sdk.Bonded {
|
||||
panic(fmt.Sprintf("jailed validator cannot be bonded for address: %s\n", ownerAddr))
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
bondedValidatorsCount++
|
||||
iterator.Next()
|
||||
}
|
||||
|
||||
iterator.Close()
|
||||
|
||||
@@ -59,11 +59,22 @@ func TestSetValidator(t *testing.T) {
|
||||
|
||||
resVals = keeper.GetValidatorsByPower(ctx)
|
||||
require.Equal(t, 1, len(resVals))
|
||||
assert.True(ValEq(t, validator, resVals[0]))
|
||||
require.True(ValEq(t, validator, resVals[0]))
|
||||
|
||||
resVals = keeper.GetValidators(ctx, 1)
|
||||
require.Equal(t, 1, len(resVals))
|
||||
require.True(ValEq(t, validator, resVals[0]))
|
||||
|
||||
resVals = keeper.GetValidators(ctx, 10)
|
||||
require.Equal(t, 1, len(resVals))
|
||||
require.True(ValEq(t, validator, resVals[0]))
|
||||
|
||||
updates := keeper.GetValidTendermintUpdates(ctx)
|
||||
require.Equal(t, 1, len(updates))
|
||||
require.Equal(t, validator.ABCIValidator(), updates[0])
|
||||
|
||||
allVals := keeper.GetAllValidators(ctx)
|
||||
require.Equal(t, 1, len(allVals))
|
||||
}
|
||||
|
||||
func TestUpdateValidatorByPowerIndex(t *testing.T) {
|
||||
@@ -283,7 +294,10 @@ func TestValidatorBasics(t *testing.T) {
|
||||
_, found := keeper.GetValidator(ctx, addrVals[0])
|
||||
require.False(t, found)
|
||||
resVals := keeper.GetValidatorsBonded(ctx)
|
||||
assert.Zero(t, len(resVals))
|
||||
require.Zero(t, len(resVals))
|
||||
|
||||
resVals = keeper.GetValidators(ctx, 2)
|
||||
require.Zero(t, len(resVals))
|
||||
|
||||
pool = keeper.GetPool(ctx)
|
||||
assert.True(sdk.DecEq(t, sdk.ZeroDec(), pool.BondedTokens))
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
package querier
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
keep "github.com/cosmos/cosmos-sdk/x/stake/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
// query endpoints supported by the staking Querier
|
||||
const (
|
||||
QueryValidators = "validators"
|
||||
QueryValidator = "validator"
|
||||
QueryDelegator = "delegator"
|
||||
QueryDelegation = "delegation"
|
||||
QueryUnbondingDelegation = "unbondingDelegation"
|
||||
QueryDelegatorValidators = "delegatorValidators"
|
||||
QueryDelegatorValidator = "delegatorValidator"
|
||||
QueryPool = "pool"
|
||||
QueryParameters = "parameters"
|
||||
)
|
||||
|
||||
// creates a querier for staking REST endpoints
|
||||
func NewQuerier(k keep.Keeper, cdc *codec.Codec) sdk.Querier {
|
||||
return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err sdk.Error) {
|
||||
switch path[0] {
|
||||
case QueryValidators:
|
||||
return queryValidators(ctx, cdc, k)
|
||||
case QueryValidator:
|
||||
return queryValidator(ctx, cdc, req, k)
|
||||
case QueryDelegator:
|
||||
return queryDelegator(ctx, cdc, req, k)
|
||||
case QueryDelegation:
|
||||
return queryDelegation(ctx, cdc, req, k)
|
||||
case QueryUnbondingDelegation:
|
||||
return queryUnbondingDelegation(ctx, cdc, req, k)
|
||||
case QueryDelegatorValidators:
|
||||
return queryDelegatorValidators(ctx, cdc, req, k)
|
||||
case QueryDelegatorValidator:
|
||||
return queryDelegatorValidator(ctx, cdc, req, k)
|
||||
case QueryPool:
|
||||
return queryPool(ctx, cdc, k)
|
||||
case QueryParameters:
|
||||
return queryParameters(ctx, cdc, k)
|
||||
default:
|
||||
return nil, sdk.ErrUnknownRequest("unknown stake query endpoint")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// defines the params for the following queries:
|
||||
// - 'custom/stake/delegator'
|
||||
// - 'custom/stake/delegatorValidators'
|
||||
type QueryDelegatorParams struct {
|
||||
DelegatorAddr sdk.AccAddress
|
||||
}
|
||||
|
||||
// defines the params for the following queries:
|
||||
// - 'custom/stake/validator'
|
||||
type QueryValidatorParams struct {
|
||||
ValidatorAddr sdk.ValAddress
|
||||
}
|
||||
|
||||
// defines the params for the following queries:
|
||||
// - 'custom/stake/delegation'
|
||||
// - 'custom/stake/unbondingDelegation'
|
||||
// - 'custom/stake/delegatorValidator'
|
||||
type QueryBondsParams struct {
|
||||
DelegatorAddr sdk.AccAddress
|
||||
ValidatorAddr sdk.ValAddress
|
||||
}
|
||||
|
||||
func queryValidators(ctx sdk.Context, cdc *codec.Codec, k keep.Keeper) (res []byte, err sdk.Error) {
|
||||
stakeParams := k.GetParams(ctx)
|
||||
validators := k.GetValidators(ctx, stakeParams.MaxValidators)
|
||||
|
||||
res, errRes := codec.MarshalJSONIndent(cdc, validators)
|
||||
if err != nil {
|
||||
return nil, sdk.ErrInternal(fmt.Sprintf("could not marshal result to JSON: %s", errRes.Error()))
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func queryValidator(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k keep.Keeper) (res []byte, err sdk.Error) {
|
||||
var params QueryValidatorParams
|
||||
|
||||
errRes := cdc.UnmarshalJSON(req.Data, ¶ms)
|
||||
if errRes != nil {
|
||||
return []byte{}, sdk.ErrUnknownAddress(fmt.Sprintf("incorrectly formatted request address: %s", err.Error()))
|
||||
}
|
||||
|
||||
validator, found := k.GetValidator(ctx, params.ValidatorAddr)
|
||||
if !found {
|
||||
return []byte{}, types.ErrNoValidatorFound(types.DefaultCodespace)
|
||||
}
|
||||
|
||||
res, errRes = codec.MarshalJSONIndent(cdc, validator)
|
||||
if errRes != nil {
|
||||
return nil, sdk.ErrInternal(fmt.Sprintf("could not marshal result to JSON: %s", errRes.Error()))
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func queryDelegator(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k keep.Keeper) (res []byte, err sdk.Error) {
|
||||
var params QueryDelegatorParams
|
||||
errRes := cdc.UnmarshalJSON(req.Data, ¶ms)
|
||||
if errRes != nil {
|
||||
return []byte{}, sdk.ErrUnknownAddress(fmt.Sprintf("incorrectly formatted request address: %s", errRes.Error()))
|
||||
}
|
||||
delegations := k.GetAllDelegatorDelegations(ctx, params.DelegatorAddr)
|
||||
unbondingDelegations := k.GetAllUnbondingDelegations(ctx, params.DelegatorAddr)
|
||||
redelegations := k.GetAllRedelegations(ctx, params.DelegatorAddr)
|
||||
|
||||
summary := types.DelegationSummary{
|
||||
Delegations: delegations,
|
||||
UnbondingDelegations: unbondingDelegations,
|
||||
Redelegations: redelegations,
|
||||
}
|
||||
|
||||
res, errRes = codec.MarshalJSONIndent(cdc, summary)
|
||||
if errRes != nil {
|
||||
return nil, sdk.ErrInternal(fmt.Sprintf("could not marshal result to JSON: %s", errRes.Error()))
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func queryDelegatorValidators(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k keep.Keeper) (res []byte, err sdk.Error) {
|
||||
var params QueryDelegatorParams
|
||||
|
||||
stakeParams := k.GetParams(ctx)
|
||||
|
||||
errRes := cdc.UnmarshalJSON(req.Data, ¶ms)
|
||||
if errRes != nil {
|
||||
return []byte{}, sdk.ErrUnknownAddress(fmt.Sprintf("incorrectly formatted request address: %s", errRes.Error()))
|
||||
}
|
||||
|
||||
validators := k.GetDelegatorValidators(ctx, params.DelegatorAddr, stakeParams.MaxValidators)
|
||||
|
||||
res, errRes = codec.MarshalJSONIndent(cdc, validators)
|
||||
if errRes != nil {
|
||||
return nil, sdk.ErrInternal(fmt.Sprintf("could not marshal result to JSON: %s", errRes.Error()))
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func queryDelegatorValidator(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k keep.Keeper) (res []byte, err sdk.Error) {
|
||||
var params QueryBondsParams
|
||||
|
||||
errRes := cdc.UnmarshalJSON(req.Data, ¶ms)
|
||||
if errRes != nil {
|
||||
return []byte{}, sdk.ErrUnknownRequest(fmt.Sprintf("incorrectly formatted request address: %s", errRes.Error()))
|
||||
}
|
||||
|
||||
validator, err := k.GetDelegatorValidator(ctx, params.DelegatorAddr, params.ValidatorAddr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
res, errRes = codec.MarshalJSONIndent(cdc, validator)
|
||||
if errRes != nil {
|
||||
return nil, sdk.ErrInternal(fmt.Sprintf("could not marshal result to JSON: %s", errRes.Error()))
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func queryDelegation(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k keep.Keeper) (res []byte, err sdk.Error) {
|
||||
var params QueryBondsParams
|
||||
|
||||
errRes := cdc.UnmarshalJSON(req.Data, ¶ms)
|
||||
if errRes != nil {
|
||||
return []byte{}, sdk.ErrUnknownRequest(fmt.Sprintf("incorrectly formatted request address: %s", errRes.Error()))
|
||||
}
|
||||
|
||||
delegation, found := k.GetDelegation(ctx, params.DelegatorAddr, params.ValidatorAddr)
|
||||
if !found {
|
||||
return []byte{}, types.ErrNoDelegation(types.DefaultCodespace)
|
||||
}
|
||||
|
||||
res, errRes = codec.MarshalJSONIndent(cdc, delegation)
|
||||
if errRes != nil {
|
||||
return nil, sdk.ErrInternal(fmt.Sprintf("could not marshal result to JSON: %s", errRes.Error()))
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func queryUnbondingDelegation(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k keep.Keeper) (res []byte, err sdk.Error) {
|
||||
var params QueryBondsParams
|
||||
|
||||
errRes := cdc.UnmarshalJSON(req.Data, ¶ms)
|
||||
if errRes != nil {
|
||||
return []byte{}, sdk.ErrUnknownRequest(fmt.Sprintf("incorrectly formatted request address: %s", errRes.Error()))
|
||||
}
|
||||
|
||||
unbond, found := k.GetUnbondingDelegation(ctx, params.DelegatorAddr, params.ValidatorAddr)
|
||||
if !found {
|
||||
return []byte{}, types.ErrNoUnbondingDelegation(types.DefaultCodespace)
|
||||
}
|
||||
|
||||
res, errRes = codec.MarshalJSONIndent(cdc, unbond)
|
||||
if errRes != nil {
|
||||
return nil, sdk.ErrInternal(fmt.Sprintf("could not marshal result to JSON: %s", errRes.Error()))
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func queryPool(ctx sdk.Context, cdc *codec.Codec, k keep.Keeper) (res []byte, err sdk.Error) {
|
||||
pool := k.GetPool(ctx)
|
||||
|
||||
res, errRes := codec.MarshalJSONIndent(cdc, pool)
|
||||
if errRes != nil {
|
||||
return nil, sdk.ErrInternal(fmt.Sprintf("could not marshal result to JSON: %s", errRes.Error()))
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func queryParameters(ctx sdk.Context, cdc *codec.Codec, k keep.Keeper) (res []byte, err sdk.Error) {
|
||||
params := k.GetParams(ctx)
|
||||
|
||||
res, errRes := codec.MarshalJSONIndent(cdc, params)
|
||||
if errRes != nil {
|
||||
return nil, sdk.ErrInternal(fmt.Sprintf("could not marshal result to JSON: %s", errRes.Error()))
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
package querier
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
keep "github.com/cosmos/cosmos-sdk/x/stake/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
var (
|
||||
addrAcc1, addrAcc2 = keep.Addrs[0], keep.Addrs[1]
|
||||
addrVal1, addrVal2 = sdk.ValAddress(keep.Addrs[0]), sdk.ValAddress(keep.Addrs[1])
|
||||
pk1, pk2 = keep.PKs[0], keep.PKs[1]
|
||||
)
|
||||
|
||||
func newTestDelegatorQuery(delegatorAddr sdk.AccAddress) QueryDelegatorParams {
|
||||
return QueryDelegatorParams{
|
||||
DelegatorAddr: delegatorAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func newTestValidatorQuery(validatorAddr sdk.ValAddress) QueryValidatorParams {
|
||||
return QueryValidatorParams{
|
||||
ValidatorAddr: validatorAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func newTestBondQuery(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) QueryBondsParams {
|
||||
return QueryBondsParams{
|
||||
DelegatorAddr: delegatorAddr,
|
||||
ValidatorAddr: validatorAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryParametersPool(t *testing.T) {
|
||||
cdc := codec.New()
|
||||
ctx, _, keeper := keep.CreateTestInput(t, false, 1000)
|
||||
|
||||
res, err := queryParameters(ctx, cdc, keeper)
|
||||
require.Nil(t, err)
|
||||
|
||||
var params types.Params
|
||||
errRes := cdc.UnmarshalJSON(res, ¶ms)
|
||||
require.Nil(t, errRes)
|
||||
require.Equal(t, keeper.GetParams(ctx), params)
|
||||
|
||||
res, err = queryPool(ctx, cdc, keeper)
|
||||
require.Nil(t, err)
|
||||
|
||||
var pool types.Pool
|
||||
errRes = cdc.UnmarshalJSON(res, &pool)
|
||||
require.Nil(t, errRes)
|
||||
require.Equal(t, keeper.GetPool(ctx), pool)
|
||||
}
|
||||
|
||||
func TestQueryValidators(t *testing.T) {
|
||||
cdc := codec.New()
|
||||
ctx, _, keeper := keep.CreateTestInput(t, false, 10000)
|
||||
pool := keeper.GetPool(ctx)
|
||||
params := keeper.GetParams(ctx)
|
||||
|
||||
// Create Validators
|
||||
amts := []sdk.Int{sdk.NewInt(9), sdk.NewInt(8)}
|
||||
var validators [2]types.Validator
|
||||
for i, amt := range amts {
|
||||
validators[i] = types.NewValidator(sdk.ValAddress(keep.Addrs[i]), keep.PKs[i], types.Description{})
|
||||
validators[i], pool, _ = validators[i].AddTokensFromDel(pool, amt)
|
||||
}
|
||||
keeper.SetPool(ctx, pool)
|
||||
validators[0] = keeper.UpdateValidator(ctx, validators[0])
|
||||
validators[1] = keeper.UpdateValidator(ctx, validators[1])
|
||||
|
||||
// Query Validators
|
||||
queriedValidators := keeper.GetValidators(ctx, params.MaxValidators)
|
||||
|
||||
res, err := queryValidators(ctx, cdc, keeper)
|
||||
require.Nil(t, err)
|
||||
|
||||
var validatorsResp []types.Validator
|
||||
errRes := cdc.UnmarshalJSON(res, &validatorsResp)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
require.Equal(t, len(queriedValidators), len(validatorsResp))
|
||||
require.ElementsMatch(t, queriedValidators, validatorsResp)
|
||||
|
||||
// Query each validator
|
||||
queryParams := newTestValidatorQuery(addrVal1)
|
||||
bz, errRes := cdc.MarshalJSON(queryParams)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
query := abci.RequestQuery{
|
||||
Path: "/custom/stake/validator",
|
||||
Data: bz,
|
||||
}
|
||||
res, err = queryValidator(ctx, cdc, query, keeper)
|
||||
require.Nil(t, err)
|
||||
|
||||
var validator types.Validator
|
||||
errRes = cdc.UnmarshalJSON(res, &validator)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
require.Equal(t, queriedValidators[0], validator)
|
||||
}
|
||||
|
||||
func TestQueryDelegation(t *testing.T) {
|
||||
cdc := codec.New()
|
||||
ctx, _, keeper := keep.CreateTestInput(t, false, 10000)
|
||||
params := keeper.GetParams(ctx)
|
||||
|
||||
// Create Validators and Delegation
|
||||
val1 := types.NewValidator(addrVal1, pk1, types.Description{})
|
||||
keeper.SetValidator(ctx, val1)
|
||||
|
||||
keeper.Delegate(ctx, addrAcc2, sdk.NewCoin("steak", sdk.NewInt(20)), val1, true)
|
||||
|
||||
// Query Delegator bonded validators
|
||||
queryParams := newTestDelegatorQuery(addrAcc2)
|
||||
bz, errRes := cdc.MarshalJSON(queryParams)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
query := abci.RequestQuery{
|
||||
Path: "/custom/stake/delegatorValidators",
|
||||
Data: bz,
|
||||
}
|
||||
|
||||
delValidators := keeper.GetDelegatorValidators(ctx, addrAcc2, params.MaxValidators)
|
||||
|
||||
res, err := queryDelegatorValidators(ctx, cdc, query, keeper)
|
||||
require.Nil(t, err)
|
||||
|
||||
var validatorsResp []types.Validator
|
||||
errRes = cdc.UnmarshalJSON(res, &validatorsResp)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
require.Equal(t, len(delValidators), len(validatorsResp))
|
||||
require.ElementsMatch(t, delValidators, validatorsResp)
|
||||
|
||||
// Query bonded validator
|
||||
queryBondParams := newTestBondQuery(addrAcc2, addrVal1)
|
||||
bz, errRes = cdc.MarshalJSON(queryBondParams)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
query = abci.RequestQuery{
|
||||
Path: "/custom/stake/delegatorValidator",
|
||||
Data: bz,
|
||||
}
|
||||
|
||||
res, err = queryDelegatorValidator(ctx, cdc, query, keeper)
|
||||
require.Nil(t, err)
|
||||
|
||||
var validator types.Validator
|
||||
errRes = cdc.UnmarshalJSON(res, &validator)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
require.Equal(t, delValidators[0], validator)
|
||||
|
||||
// Query delegation
|
||||
|
||||
query = abci.RequestQuery{
|
||||
Path: "/custom/stake/delegation",
|
||||
Data: bz,
|
||||
}
|
||||
|
||||
delegation, found := keeper.GetDelegation(ctx, addrAcc2, addrVal1)
|
||||
require.True(t, found)
|
||||
|
||||
res, err = queryDelegation(ctx, cdc, query, keeper)
|
||||
require.Nil(t, err)
|
||||
|
||||
var delegationRes types.Delegation
|
||||
errRes = cdc.UnmarshalJSON(res, &delegationRes)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
require.Equal(t, delegation, delegationRes)
|
||||
|
||||
// Query unbonging delegation
|
||||
keeper.BeginUnbonding(ctx, addrAcc2, val1.OperatorAddr, sdk.NewDec(10))
|
||||
|
||||
query = abci.RequestQuery{
|
||||
Path: "/custom/stake/unbondingDelegation",
|
||||
Data: bz,
|
||||
}
|
||||
|
||||
unbond, found := keeper.GetUnbondingDelegation(ctx, addrAcc2, addrVal1)
|
||||
require.True(t, found)
|
||||
|
||||
res, err = queryUnbondingDelegation(ctx, cdc, query, keeper)
|
||||
require.Nil(t, err)
|
||||
|
||||
var unbondRes types.UnbondingDelegation
|
||||
errRes = cdc.UnmarshalJSON(res, &unbondRes)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
require.Equal(t, unbond, unbondRes)
|
||||
|
||||
// Query Delegator Summary
|
||||
|
||||
query = abci.RequestQuery{
|
||||
Path: "/custom/stake/delegator",
|
||||
Data: bz,
|
||||
}
|
||||
|
||||
res, err = queryDelegator(ctx, cdc, query, keeper)
|
||||
require.Nil(t, err)
|
||||
|
||||
var summary types.DelegationSummary
|
||||
errRes = cdc.UnmarshalJSON(res, &summary)
|
||||
require.Nil(t, errRes)
|
||||
|
||||
require.Equal(t, unbond, summary.UnbondingDelegations[0])
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
func TestStakeWithRandomMessages(t *testing.T) {
|
||||
mapp := mock.NewApp()
|
||||
|
||||
bank.RegisterWire(mapp.Cdc)
|
||||
bank.RegisterCodec(mapp.Cdc)
|
||||
mapper := mapp.AccountMapper
|
||||
bankKeeper := bank.NewBaseKeeper(mapper)
|
||||
stakeKey := sdk.NewKVStoreKey("stake")
|
||||
|
||||
+8
-1
@@ -3,6 +3,7 @@ package stake
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/querier"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/tags"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
)
|
||||
@@ -12,6 +13,7 @@ type (
|
||||
Validator = types.Validator
|
||||
Description = types.Description
|
||||
Delegation = types.Delegation
|
||||
DelegationSummary = types.DelegationSummary
|
||||
UnbondingDelegation = types.UnbondingDelegation
|
||||
Redelegation = types.Redelegation
|
||||
Params = types.Params
|
||||
@@ -24,6 +26,9 @@ type (
|
||||
MsgBeginRedelegate = types.MsgBeginRedelegate
|
||||
MsgCompleteRedelegate = types.MsgCompleteRedelegate
|
||||
GenesisState = types.GenesisState
|
||||
QueryDelegatorParams = querier.QueryDelegatorParams
|
||||
QueryValidatorParams = querier.QueryValidatorParams
|
||||
QueryBondsParams = querier.QueryBondsParams
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -65,7 +70,7 @@ var (
|
||||
NewDescription = types.NewDescription
|
||||
NewGenesisState = types.NewGenesisState
|
||||
DefaultGenesisState = types.DefaultGenesisState
|
||||
RegisterWire = types.RegisterWire
|
||||
RegisterCodec = types.RegisterCodec
|
||||
|
||||
NewMsgCreateValidator = types.NewMsgCreateValidator
|
||||
NewMsgCreateValidatorOnBehalfOf = types.NewMsgCreateValidatorOnBehalfOf
|
||||
@@ -75,6 +80,8 @@ var (
|
||||
NewMsgCompleteUnbonding = types.NewMsgCompleteUnbonding
|
||||
NewMsgBeginRedelegate = types.NewMsgBeginRedelegate
|
||||
NewMsgCompleteRedelegate = types.NewMsgCompleteRedelegate
|
||||
|
||||
NewQuerier = querier.NewQuerier
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
)
|
||||
|
||||
// Register concrete types on wire codec
|
||||
func RegisterWire(cdc *wire.Codec) {
|
||||
// Register concrete types on codec codec
|
||||
func RegisterCodec(cdc *codec.Codec) {
|
||||
cdc.RegisterConcrete(MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator", nil)
|
||||
cdc.RegisterConcrete(MsgEditValidator{}, "cosmos-sdk/MsgEditValidator", nil)
|
||||
cdc.RegisterConcrete(MsgDelegate{}, "cosmos-sdk/MsgDelegate", nil)
|
||||
@@ -16,12 +16,12 @@ func RegisterWire(cdc *wire.Codec) {
|
||||
}
|
||||
|
||||
// generic sealed codec to be used throughout sdk
|
||||
var MsgCdc *wire.Codec
|
||||
var MsgCdc *codec.Codec
|
||||
|
||||
func init() {
|
||||
cdc := wire.NewCodec()
|
||||
RegisterWire(cdc)
|
||||
wire.RegisterCrypto(cdc)
|
||||
cdc := codec.New()
|
||||
RegisterCodec(cdc)
|
||||
codec.RegisterCrypto(cdc)
|
||||
MsgCdc = cdc
|
||||
//MsgCdc = cdc.Seal() //TODO use when upgraded to go-amino 0.9.10
|
||||
}
|
||||
+17
-10
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
// Delegation represents the bond with tokens held by an account. It is
|
||||
@@ -24,8 +24,15 @@ type delegationValue struct {
|
||||
Height int64
|
||||
}
|
||||
|
||||
// aggregates of all delegations, unbondings and redelegations
|
||||
type DelegationSummary struct {
|
||||
Delegations []Delegation `json:"delegations"`
|
||||
UnbondingDelegations []UnbondingDelegation `json:"unbonding_delegations"`
|
||||
Redelegations []Redelegation `json:"redelegations"`
|
||||
}
|
||||
|
||||
// return the delegation without fields contained within the key for the store
|
||||
func MustMarshalDelegation(cdc *wire.Codec, delegation Delegation) []byte {
|
||||
func MustMarshalDelegation(cdc *codec.Codec, delegation Delegation) []byte {
|
||||
val := delegationValue{
|
||||
delegation.Shares,
|
||||
delegation.Height,
|
||||
@@ -34,7 +41,7 @@ func MustMarshalDelegation(cdc *wire.Codec, delegation Delegation) []byte {
|
||||
}
|
||||
|
||||
// return the delegation without fields contained within the key for the store
|
||||
func MustUnmarshalDelegation(cdc *wire.Codec, key, value []byte) Delegation {
|
||||
func MustUnmarshalDelegation(cdc *codec.Codec, key, value []byte) Delegation {
|
||||
delegation, err := UnmarshalDelegation(cdc, key, value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -43,7 +50,7 @@ func MustUnmarshalDelegation(cdc *wire.Codec, key, value []byte) Delegation {
|
||||
}
|
||||
|
||||
// return the delegation without fields contained within the key for the store
|
||||
func UnmarshalDelegation(cdc *wire.Codec, key, value []byte) (delegation Delegation, err error) {
|
||||
func UnmarshalDelegation(cdc *codec.Codec, key, value []byte) (delegation Delegation, err error) {
|
||||
var storeValue delegationValue
|
||||
err = cdc.UnmarshalBinary(value, &storeValue)
|
||||
if err != nil {
|
||||
@@ -115,7 +122,7 @@ type ubdValue struct {
|
||||
}
|
||||
|
||||
// return the unbonding delegation without fields contained within the key for the store
|
||||
func MustMarshalUBD(cdc *wire.Codec, ubd UnbondingDelegation) []byte {
|
||||
func MustMarshalUBD(cdc *codec.Codec, ubd UnbondingDelegation) []byte {
|
||||
val := ubdValue{
|
||||
ubd.CreationHeight,
|
||||
ubd.MinTime,
|
||||
@@ -126,7 +133,7 @@ func MustMarshalUBD(cdc *wire.Codec, ubd UnbondingDelegation) []byte {
|
||||
}
|
||||
|
||||
// unmarshal a unbonding delegation from a store key and value
|
||||
func MustUnmarshalUBD(cdc *wire.Codec, key, value []byte) UnbondingDelegation {
|
||||
func MustUnmarshalUBD(cdc *codec.Codec, key, value []byte) UnbondingDelegation {
|
||||
ubd, err := UnmarshalUBD(cdc, key, value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -135,7 +142,7 @@ func MustUnmarshalUBD(cdc *wire.Codec, key, value []byte) UnbondingDelegation {
|
||||
}
|
||||
|
||||
// unmarshal a unbonding delegation from a store key and value
|
||||
func UnmarshalUBD(cdc *wire.Codec, key, value []byte) (ubd UnbondingDelegation, err error) {
|
||||
func UnmarshalUBD(cdc *codec.Codec, key, value []byte) (ubd UnbondingDelegation, err error) {
|
||||
var storeValue ubdValue
|
||||
err = cdc.UnmarshalBinary(value, &storeValue)
|
||||
if err != nil {
|
||||
@@ -205,7 +212,7 @@ type redValue struct {
|
||||
}
|
||||
|
||||
// return the redelegation without fields contained within the key for the store
|
||||
func MustMarshalRED(cdc *wire.Codec, red Redelegation) []byte {
|
||||
func MustMarshalRED(cdc *codec.Codec, red Redelegation) []byte {
|
||||
val := redValue{
|
||||
red.CreationHeight,
|
||||
red.MinTime,
|
||||
@@ -218,7 +225,7 @@ func MustMarshalRED(cdc *wire.Codec, red Redelegation) []byte {
|
||||
}
|
||||
|
||||
// unmarshal a redelegation from a store key and value
|
||||
func MustUnmarshalRED(cdc *wire.Codec, key, value []byte) Redelegation {
|
||||
func MustUnmarshalRED(cdc *codec.Codec, key, value []byte) Redelegation {
|
||||
red, err := UnmarshalRED(cdc, key, value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -227,7 +234,7 @@ func MustUnmarshalRED(cdc *wire.Codec, key, value []byte) Redelegation {
|
||||
}
|
||||
|
||||
// unmarshal a redelegation from a store key and value
|
||||
func UnmarshalRED(cdc *wire.Codec, key, value []byte) (red Redelegation, err error) {
|
||||
func UnmarshalRED(cdc *codec.Codec, key, value []byte) (red Redelegation, err error) {
|
||||
var storeValue redValue
|
||||
err = cdc.UnmarshalBinary(value, &storeValue)
|
||||
if err != nil {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
)
|
||||
|
||||
// name to idetify transaction types
|
||||
// name to identify transaction types
|
||||
const MsgType = "stake"
|
||||
|
||||
// Verify interface at compile time
|
||||
@@ -49,6 +49,7 @@ func NewMsgCreateValidatorOnBehalfOf(delAddr sdk.AccAddress, valAddr sdk.ValAddr
|
||||
|
||||
//nolint
|
||||
func (msg MsgCreateValidator) Type() string { return MsgType }
|
||||
func (msg MsgCreateValidator) Name() string { return "create_validator" }
|
||||
|
||||
// Return address(es) that must sign over msg.GetSignBytes()
|
||||
func (msg MsgCreateValidator) GetSigners() []sdk.AccAddress {
|
||||
@@ -118,6 +119,7 @@ func NewMsgEditValidator(valAddr sdk.ValAddress, description Description) MsgEdi
|
||||
|
||||
//nolint
|
||||
func (msg MsgEditValidator) Type() string { return MsgType }
|
||||
func (msg MsgEditValidator) Name() string { return "edit_validator" }
|
||||
func (msg MsgEditValidator) GetSigners() []sdk.AccAddress {
|
||||
return []sdk.AccAddress{sdk.AccAddress(msg.ValidatorAddr)}
|
||||
}
|
||||
@@ -168,6 +170,7 @@ func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, delegation s
|
||||
|
||||
//nolint
|
||||
func (msg MsgDelegate) Type() string { return MsgType }
|
||||
func (msg MsgDelegate) Name() string { return "delegate" }
|
||||
func (msg MsgDelegate) GetSigners() []sdk.AccAddress {
|
||||
return []sdk.AccAddress{msg.DelegatorAddr}
|
||||
}
|
||||
@@ -218,6 +221,7 @@ func NewMsgBeginRedelegate(delAddr sdk.AccAddress, valSrcAddr,
|
||||
|
||||
//nolint
|
||||
func (msg MsgBeginRedelegate) Type() string { return MsgType }
|
||||
func (msg MsgBeginRedelegate) Name() string { return "begin_redelegate" }
|
||||
func (msg MsgBeginRedelegate) GetSigners() []sdk.AccAddress {
|
||||
return []sdk.AccAddress{msg.DelegatorAddr}
|
||||
}
|
||||
@@ -275,6 +279,7 @@ func NewMsgCompleteRedelegate(delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk
|
||||
|
||||
//nolint
|
||||
func (msg MsgCompleteRedelegate) Type() string { return MsgType }
|
||||
func (msg MsgCompleteRedelegate) Name() string { return "complete_redelegate" }
|
||||
func (msg MsgCompleteRedelegate) GetSigners() []sdk.AccAddress {
|
||||
return []sdk.AccAddress{msg.DelegatorAddr}
|
||||
}
|
||||
@@ -321,6 +326,7 @@ func NewMsgBeginUnbonding(delAddr sdk.AccAddress, valAddr sdk.ValAddress, shares
|
||||
|
||||
//nolint
|
||||
func (msg MsgBeginUnbonding) Type() string { return MsgType }
|
||||
func (msg MsgBeginUnbonding) Name() string { return "begin_unbonding" }
|
||||
func (msg MsgBeginUnbonding) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.DelegatorAddr} }
|
||||
|
||||
// get the bytes for the message signer to sign on
|
||||
@@ -369,6 +375,7 @@ func NewMsgCompleteUnbonding(delAddr sdk.AccAddress, valAddr sdk.ValAddress) Msg
|
||||
|
||||
//nolint
|
||||
func (msg MsgCompleteUnbonding) Type() string { return MsgType }
|
||||
func (msg MsgCompleteUnbonding) Name() string { return "complete_unbonding" }
|
||||
func (msg MsgCompleteUnbonding) GetSigners() []sdk.AccAddress {
|
||||
return []sdk.AccAddress{msg.DelegatorAddr}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
// defaultUnbondingTime reflects three weeks in seconds as the default
|
||||
@@ -62,7 +62,7 @@ func (p Params) HumanReadableString() string {
|
||||
}
|
||||
|
||||
// unmarshal the current staking params value from store key or panic
|
||||
func MustUnmarshalParams(cdc *wire.Codec, value []byte) Params {
|
||||
func MustUnmarshalParams(cdc *codec.Codec, value []byte) Params {
|
||||
params, err := UnmarshalParams(cdc, value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -71,7 +71,7 @@ func MustUnmarshalParams(cdc *wire.Codec, value []byte) Params {
|
||||
}
|
||||
|
||||
// unmarshal the current staking params value from store key
|
||||
func UnmarshalParams(cdc *wire.Codec, value []byte) (params Params, err error) {
|
||||
func UnmarshalParams(cdc *codec.Codec, value []byte) (params Params, err error) {
|
||||
err = cdc.UnmarshalBinary(value, ¶ms)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
// Pool - dynamic parameters of the current state
|
||||
@@ -142,7 +142,7 @@ func (p Pool) HumanReadableString() string {
|
||||
}
|
||||
|
||||
// unmarshal the current pool value from store key or panics
|
||||
func MustUnmarshalPool(cdc *wire.Codec, value []byte) Pool {
|
||||
func MustUnmarshalPool(cdc *codec.Codec, value []byte) Pool {
|
||||
pool, err := UnmarshalPool(cdc, value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -151,7 +151,7 @@ func MustUnmarshalPool(cdc *wire.Codec, value []byte) Pool {
|
||||
}
|
||||
|
||||
// unmarshal the current pool value from store key
|
||||
func UnmarshalPool(cdc *wire.Codec, value []byte) (pool Pool, err error) {
|
||||
func UnmarshalPool(cdc *codec.Codec, value []byte) (pool Pool, err error) {
|
||||
err = cdc.UnmarshalBinary(value, &pool)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
)
|
||||
|
||||
// Validator defines the total amount of bond shares and their exchange rate to
|
||||
@@ -82,7 +82,7 @@ type validatorValue struct {
|
||||
}
|
||||
|
||||
// return the redelegation without fields contained within the key for the store
|
||||
func MustMarshalValidator(cdc *wire.Codec, validator Validator) []byte {
|
||||
func MustMarshalValidator(cdc *codec.Codec, validator Validator) []byte {
|
||||
val := validatorValue{
|
||||
ConsPubKey: validator.ConsPubKey,
|
||||
Jailed: validator.Jailed,
|
||||
@@ -103,7 +103,7 @@ func MustMarshalValidator(cdc *wire.Codec, validator Validator) []byte {
|
||||
}
|
||||
|
||||
// unmarshal a redelegation from a store key and value
|
||||
func MustUnmarshalValidator(cdc *wire.Codec, operatorAddr, value []byte) Validator {
|
||||
func MustUnmarshalValidator(cdc *codec.Codec, operatorAddr, value []byte) Validator {
|
||||
validator, err := UnmarshalValidator(cdc, operatorAddr, value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -112,7 +112,7 @@ func MustUnmarshalValidator(cdc *wire.Codec, operatorAddr, value []byte) Validat
|
||||
}
|
||||
|
||||
// unmarshal a redelegation from a store key and value
|
||||
func UnmarshalValidator(cdc *wire.Codec, operatorAddr, value []byte) (validator Validator, err error) {
|
||||
func UnmarshalValidator(cdc *codec.Codec, operatorAddr, value []byte) (validator Validator, err error) {
|
||||
if len(operatorAddr) != sdk.AddrLen {
|
||||
err = fmt.Errorf("%v", ErrBadValidatorAddr(DefaultCodespace).Data())
|
||||
return
|
||||
@@ -202,7 +202,7 @@ func (v Validator) MarshalJSON() ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return wire.Cdc.MarshalJSON(bechValidator{
|
||||
return codec.Cdc.MarshalJSON(bechValidator{
|
||||
OperatorAddr: v.OperatorAddr,
|
||||
ConsPubKey: bechConsPubKey,
|
||||
Jailed: v.Jailed,
|
||||
@@ -224,7 +224,7 @@ func (v Validator) MarshalJSON() ([]byte, error) {
|
||||
// UnmarshalJSON unmarshals the validator from JSON using Bech32
|
||||
func (v *Validator) UnmarshalJSON(data []byte) error {
|
||||
bv := &bechValidator{}
|
||||
if err := wire.Cdc.UnmarshalJSON(data, bv); err != nil {
|
||||
if err := codec.Cdc.UnmarshalJSON(data, bv); err != nil {
|
||||
return err
|
||||
}
|
||||
consPubKey, err := sdk.GetConsPubKeyBech32(bv.ConsPubKey)
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -265,12 +265,12 @@ func TestHumanReadableString(t *testing.T) {
|
||||
|
||||
func TestValidatorMarshalUnmarshalJSON(t *testing.T) {
|
||||
validator := NewValidator(addr1, pk1, Description{})
|
||||
js, err := wire.Cdc.MarshalJSON(validator)
|
||||
js, err := codec.Cdc.MarshalJSON(validator)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, js)
|
||||
require.Contains(t, string(js), "\"consensus_pubkey\":\"cosmosvalconspu")
|
||||
got := &Validator{}
|
||||
err = wire.Cdc.UnmarshalJSON(js, got)
|
||||
err = codec.Cdc.UnmarshalJSON(js, got)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, validator, *got)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user