Merge PR #6010: Merge x/supply into x/bank

This commit is contained in:
Alexander Bezobchuk 2020-04-20 11:22:12 -04:00 committed by GitHub
parent 50f81b173b
commit 1083fa948e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
132 changed files with 2441 additions and 3300 deletions

View File

@ -57,6 +57,7 @@ older clients.
### API Breaking Changes
* (x/supply) [\#6010](https://github.com/cosmos/cosmos-sdk/pull/6010) All `x/supply` types and APIs have been moved to `x/bank`.
* (baseapp) [\#5865](https://github.com/cosmos/cosmos-sdk/pull/5865) The `SimulationResponse` returned from tx simulation is now JSON encoded instead of Amino binary.
* [\#5719](https://github.com/cosmos/cosmos-sdk/pull/5719) Bump Go requirement to 1.14+
* (x/params) [\#5619](https://github.com/cosmos/cosmos-sdk/pull/5619) The `x/params` keeper now accepts a `codec.Marshaller` instead of
@ -124,6 +125,7 @@ invalid or incomplete requests.
### State Machine Breaking
* (x/supply) [\#6010](https://github.com/cosmos/cosmos-sdk/pull/6010) Removed the `x/supply` module by merging the existing types and APIs into the `x/bank` module.
* (modules) [\#5572](https://github.com/cosmos/cosmos-sdk/pull/5572) Separate balance from accounts per ADR 004.
* Account balances are now persisted and retrieved via the `x/bank` module.
* Vesting account interface has been modified to account for changes.

View File

@ -7,16 +7,16 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
"github.com/cosmos/cosmos-sdk/x/bank"
bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported"
"github.com/cosmos/cosmos-sdk/x/evidence"
eviexported "github.com/cosmos/cosmos-sdk/x/evidence/exported"
gov "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/supply"
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
)
var (
_ auth.Codec = (*Codec)(nil)
_ supply.Codec = (*Codec)(nil)
_ bank.Codec = (*Codec)(nil)
_ evidence.Codec = (*Codec)(nil)
_ gov.Codec = (*Codec)(nil)
)
@ -77,7 +77,7 @@ func (c *Codec) UnmarshalAccountJSON(bz []byte) (authexported.Account, error) {
// MarshalSupply marshals a SupplyI interface. If the given type implements
// the Marshaler interface, it is treated as a Proto-defined message and
// serialized that way. Otherwise, it falls back on the internal Amino codec.
func (c *Codec) MarshalSupply(supplyI supplyexported.SupplyI) ([]byte, error) {
func (c *Codec) MarshalSupply(supplyI bankexported.SupplyI) ([]byte, error) {
supply := &Supply{}
if err := supply.SetSupplyI(supplyI); err != nil {
return nil, err
@ -88,7 +88,7 @@ func (c *Codec) MarshalSupply(supplyI supplyexported.SupplyI) ([]byte, error) {
// UnmarshalSupply returns a SupplyI interface from raw encoded account bytes
// of a Proto-based SupplyI type. An error is returned upon decoding failure.
func (c *Codec) UnmarshalSupply(bz []byte) (supplyexported.SupplyI, error) {
func (c *Codec) UnmarshalSupply(bz []byte) (bankexported.SupplyI, error) {
supply := &Supply{}
if err := c.Marshaler.UnmarshalBinaryBare(bz, supply); err != nil {
return nil, err
@ -99,12 +99,12 @@ func (c *Codec) UnmarshalSupply(bz []byte) (supplyexported.SupplyI, error) {
// MarshalSupplyJSON JSON encodes a supply object implementing the SupplyI
// interface.
func (c *Codec) MarshalSupplyJSON(supply supplyexported.SupplyI) ([]byte, error) {
func (c *Codec) MarshalSupplyJSON(supply bankexported.SupplyI) ([]byte, error) {
return c.Marshaler.MarshalJSON(supply)
}
// UnmarshalSupplyJSON returns a SupplyI from JSON encoded bytes.
func (c *Codec) UnmarshalSupplyJSON(bz []byte) (supplyexported.SupplyI, error) {
func (c *Codec) UnmarshalSupplyJSON(bz []byte) (bankexported.SupplyI, error) {
supply := &Supply{}
if err := c.Marshaler.UnmarshalJSON(bz, supply); err != nil {
return nil, err

View File

@ -6,22 +6,21 @@ package std
import (
fmt "fmt"
github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types"
types11 "github.com/cosmos/cosmos-sdk/types"
types10 "github.com/cosmos/cosmos-sdk/types"
github_com_cosmos_cosmos_sdk_x_auth_exported "github.com/cosmos/cosmos-sdk/x/auth/exported"
types "github.com/cosmos/cosmos-sdk/x/auth/types"
types1 "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
types7 "github.com/cosmos/cosmos-sdk/x/bank/types"
types8 "github.com/cosmos/cosmos-sdk/x/crisis/types"
github_com_cosmos_cosmos_sdk_x_bank_exported "github.com/cosmos/cosmos-sdk/x/bank/exported"
types2 "github.com/cosmos/cosmos-sdk/x/bank/types"
types7 "github.com/cosmos/cosmos-sdk/x/crisis/types"
types6 "github.com/cosmos/cosmos-sdk/x/distribution/types"
github_com_cosmos_cosmos_sdk_x_evidence_exported "github.com/cosmos/cosmos-sdk/x/evidence/exported"
types3 "github.com/cosmos/cosmos-sdk/x/evidence/types"
github_com_cosmos_cosmos_sdk_x_gov_types "github.com/cosmos/cosmos-sdk/x/gov/types"
types4 "github.com/cosmos/cosmos-sdk/x/gov/types"
proposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
types9 "github.com/cosmos/cosmos-sdk/x/slashing/types"
types10 "github.com/cosmos/cosmos-sdk/x/staking/types"
github_com_cosmos_cosmos_sdk_x_supply_exported "github.com/cosmos/cosmos-sdk/x/supply/exported"
types2 "github.com/cosmos/cosmos-sdk/x/supply/types"
types8 "github.com/cosmos/cosmos-sdk/x/slashing/types"
types9 "github.com/cosmos/cosmos-sdk/x/staking/types"
types5 "github.com/cosmos/cosmos-sdk/x/upgrade/types"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
@ -685,13 +684,13 @@ type isMessage_Sum interface {
}
type Message_MsgSend struct {
MsgSend *types7.MsgSend `protobuf:"bytes,1,opt,name=msg_send,json=msgSend,proto3,oneof" json:"msg_send,omitempty"`
MsgSend *types2.MsgSend `protobuf:"bytes,1,opt,name=msg_send,json=msgSend,proto3,oneof" json:"msg_send,omitempty"`
}
type Message_MsgMultiSend struct {
MsgMultiSend *types7.MsgMultiSend `protobuf:"bytes,2,opt,name=msg_multi_send,json=msgMultiSend,proto3,oneof" json:"msg_multi_send,omitempty"`
MsgMultiSend *types2.MsgMultiSend `protobuf:"bytes,2,opt,name=msg_multi_send,json=msgMultiSend,proto3,oneof" json:"msg_multi_send,omitempty"`
}
type Message_MsgVerifyInvariant struct {
MsgVerifyInvariant *types8.MsgVerifyInvariant `protobuf:"bytes,3,opt,name=msg_verify_invariant,json=msgVerifyInvariant,proto3,oneof" json:"msg_verify_invariant,omitempty"`
MsgVerifyInvariant *types7.MsgVerifyInvariant `protobuf:"bytes,3,opt,name=msg_verify_invariant,json=msgVerifyInvariant,proto3,oneof" json:"msg_verify_invariant,omitempty"`
}
type Message_MsgSetWithdrawAddress struct {
MsgSetWithdrawAddress *types6.MsgSetWithdrawAddress `protobuf:"bytes,4,opt,name=msg_set_withdraw_address,json=msgSetWithdrawAddress,proto3,oneof" json:"msg_set_withdraw_address,omitempty"`
@ -718,22 +717,22 @@ type Message_MsgDeposit struct {
MsgDeposit *types4.MsgDeposit `protobuf:"bytes,11,opt,name=msg_deposit,json=msgDeposit,proto3,oneof" json:"msg_deposit,omitempty"`
}
type Message_MsgUnjail struct {
MsgUnjail *types9.MsgUnjail `protobuf:"bytes,12,opt,name=msg_unjail,json=msgUnjail,proto3,oneof" json:"msg_unjail,omitempty"`
MsgUnjail *types8.MsgUnjail `protobuf:"bytes,12,opt,name=msg_unjail,json=msgUnjail,proto3,oneof" json:"msg_unjail,omitempty"`
}
type Message_MsgCreateValidator struct {
MsgCreateValidator *types10.MsgCreateValidator `protobuf:"bytes,13,opt,name=msg_create_validator,json=msgCreateValidator,proto3,oneof" json:"msg_create_validator,omitempty"`
MsgCreateValidator *types9.MsgCreateValidator `protobuf:"bytes,13,opt,name=msg_create_validator,json=msgCreateValidator,proto3,oneof" json:"msg_create_validator,omitempty"`
}
type Message_MsgEditValidator struct {
MsgEditValidator *types10.MsgEditValidator `protobuf:"bytes,14,opt,name=msg_edit_validator,json=msgEditValidator,proto3,oneof" json:"msg_edit_validator,omitempty"`
MsgEditValidator *types9.MsgEditValidator `protobuf:"bytes,14,opt,name=msg_edit_validator,json=msgEditValidator,proto3,oneof" json:"msg_edit_validator,omitempty"`
}
type Message_MsgDelegate struct {
MsgDelegate *types10.MsgDelegate `protobuf:"bytes,15,opt,name=msg_delegate,json=msgDelegate,proto3,oneof" json:"msg_delegate,omitempty"`
MsgDelegate *types9.MsgDelegate `protobuf:"bytes,15,opt,name=msg_delegate,json=msgDelegate,proto3,oneof" json:"msg_delegate,omitempty"`
}
type Message_MsgBeginRedelegate struct {
MsgBeginRedelegate *types10.MsgBeginRedelegate `protobuf:"bytes,16,opt,name=msg_begin_redelegate,json=msgBeginRedelegate,proto3,oneof" json:"msg_begin_redelegate,omitempty"`
MsgBeginRedelegate *types9.MsgBeginRedelegate `protobuf:"bytes,16,opt,name=msg_begin_redelegate,json=msgBeginRedelegate,proto3,oneof" json:"msg_begin_redelegate,omitempty"`
}
type Message_MsgUndelegate struct {
MsgUndelegate *types10.MsgUndelegate `protobuf:"bytes,17,opt,name=msg_undelegate,json=msgUndelegate,proto3,oneof" json:"msg_undelegate,omitempty"`
MsgUndelegate *types9.MsgUndelegate `protobuf:"bytes,17,opt,name=msg_undelegate,json=msgUndelegate,proto3,oneof" json:"msg_undelegate,omitempty"`
}
func (*Message_MsgSend) isMessage_Sum() {}
@ -761,21 +760,21 @@ func (m *Message) GetSum() isMessage_Sum {
return nil
}
func (m *Message) GetMsgSend() *types7.MsgSend {
func (m *Message) GetMsgSend() *types2.MsgSend {
if x, ok := m.GetSum().(*Message_MsgSend); ok {
return x.MsgSend
}
return nil
}
func (m *Message) GetMsgMultiSend() *types7.MsgMultiSend {
func (m *Message) GetMsgMultiSend() *types2.MsgMultiSend {
if x, ok := m.GetSum().(*Message_MsgMultiSend); ok {
return x.MsgMultiSend
}
return nil
}
func (m *Message) GetMsgVerifyInvariant() *types8.MsgVerifyInvariant {
func (m *Message) GetMsgVerifyInvariant() *types7.MsgVerifyInvariant {
if x, ok := m.GetSum().(*Message_MsgVerifyInvariant); ok {
return x.MsgVerifyInvariant
}
@ -838,42 +837,42 @@ func (m *Message) GetMsgDeposit() *types4.MsgDeposit {
return nil
}
func (m *Message) GetMsgUnjail() *types9.MsgUnjail {
func (m *Message) GetMsgUnjail() *types8.MsgUnjail {
if x, ok := m.GetSum().(*Message_MsgUnjail); ok {
return x.MsgUnjail
}
return nil
}
func (m *Message) GetMsgCreateValidator() *types10.MsgCreateValidator {
func (m *Message) GetMsgCreateValidator() *types9.MsgCreateValidator {
if x, ok := m.GetSum().(*Message_MsgCreateValidator); ok {
return x.MsgCreateValidator
}
return nil
}
func (m *Message) GetMsgEditValidator() *types10.MsgEditValidator {
func (m *Message) GetMsgEditValidator() *types9.MsgEditValidator {
if x, ok := m.GetSum().(*Message_MsgEditValidator); ok {
return x.MsgEditValidator
}
return nil
}
func (m *Message) GetMsgDelegate() *types10.MsgDelegate {
func (m *Message) GetMsgDelegate() *types9.MsgDelegate {
if x, ok := m.GetSum().(*Message_MsgDelegate); ok {
return x.MsgDelegate
}
return nil
}
func (m *Message) GetMsgBeginRedelegate() *types10.MsgBeginRedelegate {
func (m *Message) GetMsgBeginRedelegate() *types9.MsgBeginRedelegate {
if x, ok := m.GetSum().(*Message_MsgBeginRedelegate); ok {
return x.MsgBeginRedelegate
}
return nil
}
func (m *Message) GetMsgUndelegate() *types10.MsgUndelegate {
func (m *Message) GetMsgUndelegate() *types9.MsgUndelegate {
if x, ok := m.GetSum().(*Message_MsgUndelegate); ok {
return x.MsgUndelegate
}
@ -1191,118 +1190,117 @@ func init() {
func init() { proto.RegisterFile("codec/std/codec.proto", fileDescriptor_daf09dc2dfa19bb4) }
var fileDescriptor_daf09dc2dfa19bb4 = []byte{
// 1764 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x58, 0x4d, 0x70, 0x1b, 0x49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2, 0xf6, 0xa6, 0x75,
0xce, 0x4c, 0x7c, 0xac, 0xc6, 0x70, 0x0b, 0x54, 0x38, 0xfe, 0x34, 0x52, 0xed, 0x62, 0x49, 0x1d,
0x6a, 0x32, 0x4e, 0xf4, 0x97, 0x26, 0xfa, 0xe3, 0x9d, 0x3d, 0xfb, 0xba, 0x3b, 0xdb, 0xbd, 0xfd,
0xc5, 0xf3, 0x7a, 0xf1, 0xd9, 0xf3, 0x7a, 0xf1, 0xdf, 0xcf, 0xeb, 0xc5, 0xcf, 0x5e, 0xd4, 0x0b,
0xcf, 0x5e, 0xd4, 0x0b, 0xff, 0x7c, 0x51, 0x2f, 0xfc, 0x74, 0x71, 0xf9, 0x25, 0xff, 0xc8, 0xeb,
0x2f, 0xab, 0x7f, 0xef, 0xdc, 0xf8, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x89, 0xf5, 0x71, 0xb9,
0xdc, 0x13, 0x00, 0x00,
// 1753 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x58, 0x41, 0x93, 0x1b, 0x47,
0x15, 0x9e, 0xf1, 0xca, 0x2b, 0x6d, 0xaf, 0xbc, 0xde, 0xed, 0xd8, 0xac, 0x58, 0x1c, 0xc9, 0x56,
0xc0, 0x04, 0x07, 0x4b, 0x71, 0x0c, 0x09, 0x56, 0x91, 0xc2, 0xd6, 0xae, 0xb7, 0xb4, 0x24, 0x0b,
0xae, 0x59, 0xdb, 0x14, 0x54, 0x60, 0xaa, 0x35, 0xd3, 0x9e, 0x6d, 0x56, 0x3d, 0x3d, 0x99, 0xee,
0xd1, 0x4a, 0x54, 0x71, 0xa2, 0x8a, 0x82, 0x5b, 0xaa, 0x28, 0xee, 0x01, 0x8a, 0x0b, 0x5c, 0x73,
0xe2, 0x07, 0x50, 0xa9, 0x9c, 0x7c, 0xe4, 0xb4, 0x50, 0xeb, 0x0b, 0x95, 0xa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 0x8a, 0xbd, 0xba, 0x13, 0x00, 0x00,
}
func (this *Supply) Equal(that interface{}) bool {
@ -1720,14 +1718,14 @@ func (this *Account) SetAccount(value github_com_cosmos_cosmos_sdk_x_auth_export
return fmt.Errorf("can't encode value of type %T as message Account", value)
}
func (this *Supply) GetSupplyI() github_com_cosmos_cosmos_sdk_x_supply_exported.SupplyI {
func (this *Supply) GetSupplyI() github_com_cosmos_cosmos_sdk_x_bank_exported.SupplyI {
if x := this.GetSupply(); x != nil {
return x
}
return nil
}
func (this *Supply) SetSupplyI(value github_com_cosmos_cosmos_sdk_x_supply_exported.SupplyI) error {
func (this *Supply) SetSupplyI(value github_com_cosmos_cosmos_sdk_x_bank_exported.SupplyI) error {
if value == nil {
this.Sum = nil
return nil
@ -1868,22 +1866,22 @@ func (this *Message) SetMsg(value github_com_cosmos_cosmos_sdk_types.Msg) error
return nil
}
switch vt := value.(type) {
case *types7.MsgSend:
case *types2.MsgSend:
this.Sum = &Message_MsgSend{vt}
return nil
case types7.MsgSend:
case types2.MsgSend:
this.Sum = &Message_MsgSend{&vt}
return nil
case *types7.MsgMultiSend:
case *types2.MsgMultiSend:
this.Sum = &Message_MsgMultiSend{vt}
return nil
case types7.MsgMultiSend:
case types2.MsgMultiSend:
this.Sum = &Message_MsgMultiSend{&vt}
return nil
case *types8.MsgVerifyInvariant:
case *types7.MsgVerifyInvariant:
this.Sum = &Message_MsgVerifyInvariant{vt}
return nil
case types8.MsgVerifyInvariant:
case types7.MsgVerifyInvariant:
this.Sum = &Message_MsgVerifyInvariant{&vt}
return nil
case *types6.MsgSetWithdrawAddress:
@ -1934,40 +1932,40 @@ func (this *Message) SetMsg(value github_com_cosmos_cosmos_sdk_types.Msg) error
case types4.MsgDeposit:
this.Sum = &Message_MsgDeposit{&vt}
return nil
case *types9.MsgUnjail:
case *types8.MsgUnjail:
this.Sum = &Message_MsgUnjail{vt}
return nil
case types9.MsgUnjail:
case types8.MsgUnjail:
this.Sum = &Message_MsgUnjail{&vt}
return nil
case *types10.MsgCreateValidator:
case *types9.MsgCreateValidator:
this.Sum = &Message_MsgCreateValidator{vt}
return nil
case types10.MsgCreateValidator:
case types9.MsgCreateValidator:
this.Sum = &Message_MsgCreateValidator{&vt}
return nil
case *types10.MsgEditValidator:
case *types9.MsgEditValidator:
this.Sum = &Message_MsgEditValidator{vt}
return nil
case types10.MsgEditValidator:
case types9.MsgEditValidator:
this.Sum = &Message_MsgEditValidator{&vt}
return nil
case *types10.MsgDelegate:
case *types9.MsgDelegate:
this.Sum = &Message_MsgDelegate{vt}
return nil
case types10.MsgDelegate:
case types9.MsgDelegate:
this.Sum = &Message_MsgDelegate{&vt}
return nil
case *types10.MsgBeginRedelegate:
case *types9.MsgBeginRedelegate:
this.Sum = &Message_MsgBeginRedelegate{vt}
return nil
case types10.MsgBeginRedelegate:
case types9.MsgBeginRedelegate:
this.Sum = &Message_MsgBeginRedelegate{&vt}
return nil
case *types10.MsgUndelegate:
case *types9.MsgUndelegate:
this.Sum = &Message_MsgUndelegate{vt}
return nil
case types10.MsgUndelegate:
case types9.MsgUndelegate:
this.Sum = &Message_MsgUndelegate{&vt}
return nil
}
@ -4920,7 +4918,7 @@ func (m *Message) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &types7.MsgSend{}
v := &types2.MsgSend{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
@ -4955,7 +4953,7 @@ func (m *Message) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &types7.MsgMultiSend{}
v := &types2.MsgMultiSend{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
@ -4990,7 +4988,7 @@ func (m *Message) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &types8.MsgVerifyInvariant{}
v := &types7.MsgVerifyInvariant{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
@ -5305,7 +5303,7 @@ func (m *Message) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &types9.MsgUnjail{}
v := &types8.MsgUnjail{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
@ -5340,7 +5338,7 @@ func (m *Message) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &types10.MsgCreateValidator{}
v := &types9.MsgCreateValidator{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
@ -5375,7 +5373,7 @@ func (m *Message) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &types10.MsgEditValidator{}
v := &types9.MsgEditValidator{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
@ -5410,7 +5408,7 @@ func (m *Message) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &types10.MsgDelegate{}
v := &types9.MsgDelegate{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
@ -5445,7 +5443,7 @@ func (m *Message) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &types10.MsgBeginRedelegate{}
v := &types9.MsgBeginRedelegate{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
@ -5480,7 +5478,7 @@ func (m *Message) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
v := &types10.MsgUndelegate{}
v := &types9.MsgUndelegate{}
if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
@ -5688,7 +5686,7 @@ func (m *StdFee) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Amount = append(m.Amount, types11.Coin{})
m.Amount = append(m.Amount, types10.Coin{})
if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}

View File

@ -9,7 +9,6 @@ import "x/auth/vesting/types/types.proto";
import "x/bank/types/types.proto";
import "x/crisis/types/types.proto";
import "x/distribution/types/types.proto";
import "x/supply/types/types.proto";
import "x/evidence/types/types.proto";
import "x/gov/types/types.proto";
import "x/slashing/types/types.proto";
@ -29,18 +28,18 @@ message Account {
cosmos_sdk.x.auth.vesting.v1.ContinuousVestingAccount continuous_vesting_account = 2;
cosmos_sdk.x.auth.vesting.v1.DelayedVestingAccount delayed_vesting_account = 3;
cosmos_sdk.x.auth.vesting.v1.PeriodicVestingAccount periodic_vesting_account = 4;
cosmos_sdk.x.supply.v1.ModuleAccount module_account = 5;
cosmos_sdk.x.bank.v1.ModuleAccount module_account = 5;
}
}
// Supply defines the application-level Supply type.
message Supply {
option (gogoproto.equal) = true;
option (cosmos_proto.interface_type) = "*github.com/cosmos/cosmos-sdk/x/supply/exported.SupplyI";
option (cosmos_proto.interface_type) = "*github.com/cosmos/cosmos-sdk/x/bank/exported.SupplyI";
// sum defines a set of all acceptable concrete Supply implementations.
oneof sum {
cosmos_sdk.x.supply.v1.Supply supply = 1;
cosmos_sdk.x.bank.v1.Supply supply = 1;
}
}

View File

@ -35,7 +35,6 @@ import (
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
)
@ -54,7 +53,6 @@ var (
// and genesis verification.
ModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
supply.AppModuleBasic{},
genutil.AppModuleBasic{},
bank.AppModuleBasic{},
capability.AppModuleBasic{},
@ -77,11 +75,11 @@ var (
maccPerms = map[string][]string{
auth.FeeCollectorName: nil,
distr.ModuleName: nil,
mint.ModuleName: {supply.Minter},
staking.BondedPoolName: {supply.Burner, supply.Staking},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
gov.ModuleName: {supply.Burner},
transfer.GetModuleAccountName(): {supply.Minter, supply.Burner},
mint.ModuleName: {bank.Minter},
staking.BondedPoolName: {bank.Burner, bank.Staking},
staking.NotBondedPoolName: {bank.Burner, bank.Staking},
gov.ModuleName: {bank.Burner},
transfer.GetModuleAccountName(): {bank.Minter, bank.Burner},
}
// module accounts that are allowed to receive tokens
@ -113,7 +111,6 @@ type SimApp struct {
AccountKeeper auth.AccountKeeper
BankKeeper bank.Keeper
CapabilityKeeper *capability.Keeper
SupplyKeeper supply.Keeper
StakingKeeper staking.Keeper
SlashingKeeper slashing.Keeper
MintKeeper mint.Keeper
@ -153,7 +150,7 @@ func NewSimApp(
keys := sdk.NewKVStoreKeys(
auth.StoreKey, bank.StoreKey, staking.StoreKey,
supply.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey,
mint.StoreKey, distr.StoreKey, slashing.StoreKey,
gov.StoreKey, params.StoreKey, ibc.StoreKey, upgrade.StoreKey,
evidence.StoreKey, transfer.StoreKey, capability.StoreKey,
)
@ -194,27 +191,24 @@ func NewSimApp(
appCodec, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount,
)
app.BankKeeper = bank.NewBaseKeeper(
appCodec, keys[bank.StoreKey], app.AccountKeeper, app.subspaces[bank.ModuleName], app.BlacklistedAccAddrs(),
)
app.SupplyKeeper = supply.NewKeeper(
appCodec, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms,
appCodec, keys[bank.StoreKey], app.AccountKeeper, app.subspaces[bank.ModuleName], app.BlacklistedAccAddrs(), maccPerms,
)
stakingKeeper := staking.NewKeeper(
appCodec, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName],
appCodec, keys[staking.StoreKey], app.BankKeeper, app.subspaces[staking.ModuleName],
)
app.MintKeeper = mint.NewKeeper(
appCodec, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper,
app.SupplyKeeper, auth.FeeCollectorName,
app.BankKeeper, auth.FeeCollectorName,
)
app.DistrKeeper = distr.NewKeeper(
appCodec, keys[distr.StoreKey], app.subspaces[distr.ModuleName], app.BankKeeper, &stakingKeeper,
app.SupplyKeeper, auth.FeeCollectorName, app.ModuleAccountAddrs(),
auth.FeeCollectorName, app.ModuleAccountAddrs(),
)
app.SlashingKeeper = slashing.NewKeeper(
appCodec, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName],
)
app.CrisisKeeper = crisis.NewKeeper(
app.subspaces[crisis.ModuleName], invCheckPeriod, app.SupplyKeeper, auth.FeeCollectorName,
app.subspaces[crisis.ModuleName], invCheckPeriod, app.BankKeeper, auth.FeeCollectorName,
)
app.UpgradeKeeper = upgrade.NewKeeper(skipUpgradeHeights, keys[upgrade.StoreKey], appCodec, homePath)
@ -225,7 +219,7 @@ func NewSimApp(
AddRoute(distr.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgrade.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper))
app.GovKeeper = gov.NewKeeper(
appCodec, keys[gov.StoreKey], app.subspaces[gov.ModuleName], app.SupplyKeeper,
appCodec, keys[gov.StoreKey], app.subspaces[gov.ModuleName], app.BankKeeper,
&stakingKeeper, govRouter,
)
@ -244,8 +238,7 @@ func NewSimApp(
app.TransferKeeper = transfer.NewKeeper(
app.cdc, keys[transfer.StoreKey],
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.BankKeeper, app.SupplyKeeper,
scopedTransferKeeper,
app.BankKeeper, scopedTransferKeeper,
)
transferModule := transfer.NewAppModule(app.TransferKeeper)
@ -268,16 +261,15 @@ func NewSimApp(
// must be passed by reference here.
app.mm = module.NewManager(
genutil.NewAppModule(app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx),
auth.NewAppModule(app.AccountKeeper, app.SupplyKeeper),
auth.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(*app.CapabilityKeeper),
crisis.NewAppModule(&app.CrisisKeeper),
supply.NewAppModule(app.SupplyKeeper, app.BankKeeper, app.AccountKeeper),
gov.NewAppModule(app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.SupplyKeeper),
mint.NewAppModule(app.MintKeeper, app.SupplyKeeper),
gov.NewAppModule(app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(app.MintKeeper, app.BankKeeper),
slashing.NewAppModule(app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
distr.NewAppModule(app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.SupplyKeeper, app.StakingKeeper),
staking.NewAppModule(app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.SupplyKeeper),
distr.NewAppModule(app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
staking.NewAppModule(app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
@ -298,9 +290,8 @@ func NewSimApp(
// properly initialized with tokens from genesis accounts.
app.mm.SetOrderInitGenesis(
auth.ModuleName, distr.ModuleName, staking.ModuleName, bank.ModuleName,
slashing.ModuleName, gov.ModuleName, mint.ModuleName, supply.ModuleName,
crisis.ModuleName, ibc.ModuleName, genutil.ModuleName, evidence.ModuleName,
transfer.ModuleName,
slashing.ModuleName, gov.ModuleName, mint.ModuleName, crisis.ModuleName,
ibc.ModuleName, genutil.ModuleName, evidence.ModuleName, transfer.ModuleName,
)
app.mm.RegisterInvariants(&app.CrisisKeeper)
@ -311,13 +302,12 @@ func NewSimApp(
// NOTE: this is not required apps that don't use the simulator for fuzz testing
// transactions
app.sm = module.NewSimulationManager(
auth.NewAppModule(app.AccountKeeper, app.SupplyKeeper),
auth.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(app.BankKeeper, app.AccountKeeper),
supply.NewAppModule(app.SupplyKeeper, app.BankKeeper, app.AccountKeeper),
gov.NewAppModule(app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.SupplyKeeper),
mint.NewAppModule(app.MintKeeper, app.SupplyKeeper),
staking.NewAppModule(app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.SupplyKeeper),
distr.NewAppModule(app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.SupplyKeeper, app.StakingKeeper),
gov.NewAppModule(app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(app.MintKeeper, app.BankKeeper),
staking.NewAppModule(app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
distr.NewAppModule(app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
slashing.NewAppModule(app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
params.NewAppModule(app.ParamsKeeper),
)
@ -334,8 +324,7 @@ func NewSimApp(
app.SetBeginBlocker(app.BeginBlocker)
app.SetAnteHandler(
ante.NewAnteHandler(
app.AccountKeeper, app.SupplyKeeper, *app.IBCKeeper,
ante.DefaultSigVerificationGasConsumer,
app.AccountKeeper, app.BankKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer,
),
)
app.SetEndBlocker(app.EndBlocker)
@ -387,7 +376,7 @@ func (app *SimApp) LoadHeight(height int64) error {
func (app *SimApp) ModuleAccountAddrs() map[string]bool {
modAccAddrs := make(map[string]bool)
for acc := range maccPerms {
modAccAddrs[supply.NewModuleAddress(acc).String()] = true
modAccAddrs[bank.NewModuleAddress(acc).String()] = true
}
return modAccAddrs
@ -397,7 +386,7 @@ func (app *SimApp) ModuleAccountAddrs() map[string]bool {
func (app *SimApp) BlacklistedAccAddrs() map[string]bool {
blacklistedAddrs := make(map[string]bool)
for acc := range maccPerms {
blacklistedAddrs[supply.NewModuleAddress(acc).String()] = !allowedReceivingModAcc[acc]
blacklistedAddrs[bank.NewModuleAddress(acc).String()] = !allowedReceivingModAcc[acc]
}
return blacklistedAddrs

View File

@ -42,7 +42,7 @@ func TestBlackListedAddrs(t *testing.T) {
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0)
for acc := range maccPerms {
require.Equal(t, !allowedReceivingModAcc[acc], app.BankKeeper.BlacklistedAddr(app.SupplyKeeper.GetModuleAddress(acc)))
require.Equal(t, !allowedReceivingModAcc[acc], app.BankKeeper.BlacklistedAddr(app.BankKeeper.GetModuleAddress(acc)))
}
}

View File

@ -6,7 +6,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/cosmos/cosmos-sdk/x/bank"
)
var _ authexported.GenesisAccount = (*SimGenesisAccount)(nil)
@ -37,7 +37,7 @@ func (sga SimGenesisAccount) Validate() error {
}
if sga.ModuleName != "" {
ma := supply.ModuleAccount{
ma := bank.ModuleAccount{
BaseAccount: sga.BaseAccount, Name: sga.ModuleName, Permissions: sga.ModulePermissions,
}
if err := ma.Validate(); err != nil {

View File

@ -18,6 +18,7 @@ import (
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/mint"
@ -25,7 +26,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"
)
// Get flags every time the simulator is run
@ -152,7 +152,7 @@ func TestAppImportExport(t *testing.T) {
{app.keys[slashing.StoreKey], newApp.keys[slashing.StoreKey], [][]byte{}},
{app.keys[mint.StoreKey], newApp.keys[mint.StoreKey], [][]byte{}},
{app.keys[distr.StoreKey], newApp.keys[distr.StoreKey], [][]byte{}},
{app.keys[supply.StoreKey], newApp.keys[supply.StoreKey], [][]byte{}},
{app.keys[bank.StoreKey], newApp.keys[bank.StoreKey], [][]byte{bank.BalancesPrefix}},
{app.keys[paramtypes.StoreKey], newApp.keys[paramtypes.StoreKey], [][]byte{}},
{app.keys[gov.StoreKey], newApp.keys[gov.StoreKey], [][]byte{}},
}
@ -164,7 +164,7 @@ func TestAppImportExport(t *testing.T) {
failedKVAs, failedKVBs := sdk.DiffKVStores(storeA, storeB, skp.Prefixes)
require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare")
fmt.Printf("compared %d key/value pairs between %s and %s\n", len(failedKVAs), skp.A, skp.B)
fmt.Printf("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), skp.A, skp.B)
require.Equal(t, len(failedKVAs), 0, GetSimulationLog(skp.A.Name(), app.SimulationManager().StoreDecoders, app.Codec(), failedKVAs, failedKVBs))
}
}

View File

@ -22,7 +22,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/supply"
)
// DefaultConsensusParams defines the default Tendermint consensus params used in
@ -81,7 +80,12 @@ func SetupWithGenesisAccounts(genAccs []authexported.GenesisAccount, balances ..
authGenesis := auth.NewGenesisState(auth.DefaultParams(), genAccs)
genesisState[auth.ModuleName] = app.Codec().MustMarshalJSON(authGenesis)
bankGenesis := bank.NewGenesisState(bank.DefaultGenesisState().SendEnabled, balances)
totalSupply := sdk.NewCoins()
for _, b := range balances {
totalSupply = totalSupply.Add(b.Coins...)
}
bankGenesis := bank.NewGenesisState(bank.DefaultGenesisState().SendEnabled, balances, totalSupply)
genesisState[bank.ModuleName] = app.Codec().MustMarshalJSON(bankGenesis)
stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState)
@ -153,8 +157,8 @@ func AddTestAddrsFromPubKeys(app *SimApp, ctx sdk.Context, pubKeys []crypto.PubK
// setTotalSupply provides the total supply based on accAmt * totalAccounts.
func setTotalSupply(app *SimApp, ctx sdk.Context, accAmt sdk.Int, totalAccounts int) {
totalSupply := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt.MulRaw(int64(totalAccounts))))
prevSupply := app.SupplyKeeper.GetSupply(ctx)
app.SupplyKeeper.SetSupply(ctx, supply.NewSupply(prevSupply.GetTotal().Add(totalSupply...)))
prevSupply := app.BankKeeper.GetSupply(ctx)
app.BankKeeper.SetSupply(ctx, bank.NewSupply(prevSupply.GetTotal().Add(totalSupply...)))
}
// AddTestAddrs constructs and returns accNum amount of accounts with an

View File

@ -12,7 +12,7 @@ import (
// numbers, checks signatures & account numbers, and deducts fees from the first
// signer.
func NewAnteHandler(
ak keeper.AccountKeeper, supplyKeeper types.SupplyKeeper, ibcKeeper ibckeeper.Keeper,
ak keeper.AccountKeeper, bankKeeper types.BankKeeper, ibcKeeper ibckeeper.Keeper,
sigGasConsumer SignatureVerificationGasConsumer,
) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
@ -23,7 +23,7 @@ func NewAnteHandler(
NewConsumeGasForTxSizeDecorator(ak),
NewSetPubKeyDecorator(ak), // SetPubKeyDecorator must be called before all signature verification decorators
NewValidateSigCountDecorator(ak),
NewDeductFeeDecorator(ak, supplyKeeper),
NewDeductFeeDecorator(ak, bankKeeper),
NewSigGasConsumeDecorator(ak, sigGasConsumer),
NewSigVerificationDecorator(ak),
NewIncrementSequenceDecorator(ak),

View File

@ -38,7 +38,7 @@ func TestSimulateGasCost(t *testing.T) {
// setup
app, ctx := createTestApp(true)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.BankKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
@ -92,7 +92,7 @@ func TestSimulateGasCost(t *testing.T) {
func TestAnteHandlerSigErrors(t *testing.T) {
// setup
app, ctx := createTestApp(true)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.BankKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
@ -142,7 +142,7 @@ func TestAnteHandlerAccountNumbers(t *testing.T) {
// setup
app, ctx := createTestApp(false)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.BankKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
@ -201,7 +201,7 @@ func TestAnteHandlerAccountNumbersAtBlockHeightZero(t *testing.T) {
// setup
app, ctx := createTestApp(false)
ctx = ctx.WithBlockHeight(0)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.BankKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
@ -259,7 +259,7 @@ func TestAnteHandlerSequences(t *testing.T) {
// setup
app, ctx := createTestApp(false)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.BankKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
@ -335,7 +335,7 @@ func TestAnteHandlerSequences(t *testing.T) {
func TestAnteHandlerFees(t *testing.T) {
// setup
app, ctx := createTestApp(true)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.BankKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
@ -359,7 +359,7 @@ func TestAnteHandlerFees(t *testing.T) {
app.BankKeeper.SetBalances(ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("atom", 149)))
checkInvalidTx(t, anteHandler, ctx, tx, false, sdkerrors.ErrInsufficientFunds)
modAcc := app.SupplyKeeper.GetModuleAccount(ctx, types.FeeCollectorName)
modAcc := app.BankKeeper.GetModuleAccount(ctx, types.FeeCollectorName)
require.True(t, app.BankKeeper.GetAllBalances(ctx, modAcc.GetAddress()).Empty())
require.True(sdk.IntEq(t, app.BankKeeper.GetAllBalances(ctx, addr1).AmountOf("atom"), sdk.NewInt(149)))
@ -377,7 +377,7 @@ func TestAnteHandlerMemoGas(t *testing.T) {
// setup
app, ctx := createTestApp(true)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.BankKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
@ -417,7 +417,7 @@ func TestAnteHandlerMultiSigner(t *testing.T) {
// setup
app, ctx := createTestApp(false)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.BankKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
@ -467,7 +467,7 @@ func TestAnteHandlerBadSignBytes(t *testing.T) {
// setup
app, ctx := createTestApp(true)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.BankKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
@ -544,7 +544,7 @@ func TestAnteHandlerSetPubKey(t *testing.T) {
// setup
app, ctx := createTestApp(true)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.BankKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
@ -662,7 +662,7 @@ func TestAnteHandlerSigLimitExceeded(t *testing.T) {
// setup
app, ctx := createTestApp(true)
ctx = ctx.WithBlockHeight(1)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.BankKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
// keys and addresses
priv1, _, addr1 := types.KeyTestPubAddr()
@ -703,7 +703,7 @@ func TestCustomSignatureVerificationGasConsumer(t *testing.T) {
app, ctx := createTestApp(true)
ctx = ctx.WithBlockHeight(1)
// setup an ante handler that only accepts PubKeyEd25519
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, *app.IBCKeeper, func(meter sdk.GasMeter, sig []byte, pubkey crypto.PubKey, params types.Params) error {
anteHandler := ante.NewAnteHandler(app.AccountKeeper, app.BankKeeper, *app.IBCKeeper, func(meter sdk.GasMeter, sig []byte, pubkey crypto.PubKey, params types.Params) error {
switch pubkey := pubkey.(type) {
case ed25519.PubKeyEd25519:
meter.ConsumeGas(params.SigVerifyCostED25519, "ante verify: ed25519")
@ -761,7 +761,7 @@ func TestAnteHandlerReCheck(t *testing.T) {
app.AccountKeeper.SetAccount(ctx, acc1)
app.BankKeeper.SetBalances(ctx, addr1, types.NewTestCoins())
antehandler := ante.NewAnteHandler(app.AccountKeeper, app.SupplyKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
antehandler := ante.NewAnteHandler(app.AccountKeeper, app.BankKeeper, *app.IBCKeeper, ante.DefaultSigVerificationGasConsumer)
// test that operations skipped on recheck do not run

View File

@ -4,11 +4,10 @@ import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
var (
@ -73,14 +72,14 @@ func (mfd MempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b
// Call next AnteHandler if fees successfully deducted
// CONTRACT: Tx must implement FeeTx interface to use DeductFeeDecorator
type DeductFeeDecorator struct {
ak keeper.AccountKeeper
supplyKeeper types.SupplyKeeper
ak keeper.AccountKeeper
bankKeeper types.BankKeeper
}
func NewDeductFeeDecorator(ak keeper.AccountKeeper, sk types.SupplyKeeper) DeductFeeDecorator {
func NewDeductFeeDecorator(ak keeper.AccountKeeper, bk types.BankKeeper) DeductFeeDecorator {
return DeductFeeDecorator{
ak: ak,
supplyKeeper: sk,
ak: ak,
bankKeeper: bk,
}
}
@ -90,7 +89,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}
if addr := dfd.supplyKeeper.GetModuleAddress(types.FeeCollectorName); addr == nil {
if addr := dfd.bankKeeper.GetModuleAddress(types.FeeCollectorName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.FeeCollectorName))
}
@ -103,7 +102,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
// deduct the fees
if !feeTx.GetFee().IsZero() {
err = DeductFees(dfd.supplyKeeper, ctx, feePayerAcc, feeTx.GetFee())
err = DeductFees(dfd.bankKeeper, ctx, feePayerAcc, feeTx.GetFee())
if err != nil {
return ctx, err
}
@ -113,12 +112,12 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
}
// DeductFees deducts fees from the given account.
func DeductFees(supplyKeeper types.SupplyKeeper, ctx sdk.Context, acc exported.Account, fees sdk.Coins) error {
func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc exported.Account, fees sdk.Coins) error {
if !fees.IsValid() {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees)
}
err := supplyKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), types.FeeCollectorName, fees)
err := bankKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), types.FeeCollectorName, fees)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
}

View File

@ -81,7 +81,7 @@ func TestDeductFees(t *testing.T) {
app.AccountKeeper.SetAccount(ctx, acc)
app.BankKeeper.SetBalances(ctx, addr1, sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(10))))
dfd := ante.NewDeductFeeDecorator(app.AccountKeeper, app.SupplyKeeper)
dfd := ante.NewDeductFeeDecorator(app.AccountKeeper, app.BankKeeper)
antehandler := sdk.ChainAnteDecorators(dfd)
_, err := antehandler(ctx, tx, false)

View File

@ -10,7 +10,7 @@ import (
//
// CONTRACT: old coins from the FeeCollectionKeeper need to be transferred through
// a genesis port script to the new fee collector account
func InitGenesis(ctx sdk.Context, ak AccountKeeper, sk types.SupplyKeeper, data GenesisState) {
func InitGenesis(ctx sdk.Context, ak AccountKeeper, bk types.BankKeeper, data GenesisState) {
ak.SetParams(ctx, data.Params)
data.Accounts = SanitizeGenesisAccounts(data.Accounts)
@ -19,7 +19,7 @@ func InitGenesis(ctx sdk.Context, ak AccountKeeper, sk types.SupplyKeeper, data
ak.SetAccount(ctx, acc)
}
sk.GetModuleAccount(ctx, FeeCollectorName)
bk.GetModuleAccount(ctx, FeeCollectorName)
}
// ExportGenesis returns a GenesisState for a given context and keeper

View File

@ -77,15 +77,15 @@ type AppModule struct {
AppModuleBasic
accountKeeper AccountKeeper
supplyKeeper types.SupplyKeeper
bankKeeper types.BankKeeper
}
// NewAppModule creates a new AppModule object
func NewAppModule(accountKeeper AccountKeeper, supplyKeeper types.SupplyKeeper) AppModule {
func NewAppModule(accountKeeper AccountKeeper, bankKeeper types.BankKeeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
accountKeeper: accountKeeper,
supplyKeeper: supplyKeeper,
bankKeeper: bankKeeper,
}
}
@ -118,7 +118,7 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
InitGenesis(ctx, am.accountKeeper, am.supplyKeeper, genesisState)
InitGenesis(ctx, am.accountKeeper, am.bankKeeper, genesisState)
return []abci.ValidatorUpdate{}
}

View File

@ -8,7 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/cosmos/cosmos-sdk/x/bank"
)
func TestItCreatesModuleAccountOnInitBlock(t *testing.T) {
@ -22,6 +22,6 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) {
},
)
acc := app.AccountKeeper.GetAccount(ctx, supply.NewModuleAddress(auth.FeeCollectorName))
acc := app.AccountKeeper.GetAccount(ctx, bank.NewModuleAddress(auth.FeeCollectorName))
require.NotNil(t, acc)
}

View File

@ -2,11 +2,11 @@ package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/supply/exported"
"github.com/cosmos/cosmos-sdk/x/bank/exported"
)
// SupplyKeeper defines the expected supply Keeper (noalias)
type SupplyKeeper interface {
// BankKeeper defines the contract needed for supply related APIs (noalias)
type BankKeeper interface {
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
GetModuleAccount(ctx sdk.Context, moduleName string) exported.ModuleAccountI
GetModuleAddress(moduleName string) sdk.AccAddress

View File

@ -10,10 +10,6 @@ import (
const (
QueryBalance = types.QueryBalance
QueryAllBalances = types.QueryAllBalances
ModuleName = types.ModuleName
QuerierRoute = types.QuerierRoute
RouterKey = types.RouterKey
StoreKey = types.StoreKey
DefaultParamspace = types.DefaultParamspace
DefaultSendEnabled = types.DefaultSendEnabled
@ -21,6 +17,14 @@ const (
AttributeKeyRecipient = types.AttributeKeyRecipient
AttributeKeySender = types.AttributeKeySender
AttributeValueCategory = types.AttributeValueCategory
ModuleName = types.ModuleName
StoreKey = types.StoreKey
RouterKey = types.RouterKey
QuerierRoute = types.QuerierRoute
Minter = types.Minter
Burner = types.Burner
Staking = types.Staking
)
var (
@ -37,7 +41,6 @@ var (
ErrSendDisabled = types.ErrSendDisabled
NewGenesisState = types.NewGenesisState
DefaultGenesisState = types.DefaultGenesisState
ValidateGenesis = types.ValidateGenesis
SanitizeGenesisBalances = types.SanitizeGenesisBalances
GetGenesisStateFromAppState = types.GetGenesisStateFromAppState
NewMsgSend = types.NewMsgSend
@ -52,16 +55,21 @@ var (
ParamStoreKeySendEnabled = types.ParamStoreKeySendEnabled
BalancesPrefix = types.BalancesPrefix
AddressFromBalancesStore = types.AddressFromBalancesStore
AllInvariants = keeper.AllInvariants
TotalSupply = keeper.TotalSupply
NewModuleAddress = types.NewModuleAddress
NewEmptyModuleAccount = types.NewEmptyModuleAccount
NewModuleAccount = types.NewModuleAccount
NewSupply = types.NewSupply
DefaultSupply = types.DefaultSupply
)
type (
Keeper = keeper.Keeper
BaseKeeper = keeper.BaseKeeper
SendKeeper = keeper.SendKeeper
BaseSendKeeper = keeper.BaseSendKeeper
ViewKeeper = keeper.ViewKeeper
BaseViewKeeper = keeper.BaseViewKeeper
GenesisState = types.GenesisState
Balance = types.Balance
MsgSend = types.MsgSend
MsgMultiSend = types.MsgMultiSend
@ -70,4 +78,9 @@ type (
QueryBalanceParams = types.QueryBalanceParams
QueryAllBalancesParams = types.QueryAllBalancesParams
GenesisBalancesIterator = types.GenesisBalancesIterator
Keeper = keeper.Keeper
ModuleAccount = types.ModuleAccount
GenesisState = types.GenesisState
Supply = types.Supply
Codec = types.Codec
)

View File

@ -5,8 +5,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/supply"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
@ -147,7 +147,7 @@ func TestSendToModuleAcc(t *testing.T) {
{
name: "Allowed module account can be the recipient of bank sends",
fromBalance: coins,
msg: types.NewMsgSend(addr1, supply.NewModuleAddress(distribution.ModuleName), coins),
msg: types.NewMsgSend(addr1, bank.NewModuleAddress(distribution.ModuleName), coins),
expPass: true,
expSimPass: true,
expFromBalance: sdk.NewCoins(),

View File

@ -10,11 +10,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"
)
var moduleAccAddr = supply.NewModuleAddress(staking.BondedPoolName)
var moduleAccAddr = bank.NewModuleAddress(staking.BondedPoolName)
func BenchmarkOneBankSendTxPerBlock(b *testing.B) {
// Add an account at genesis

View File

@ -2,6 +2,7 @@ package cli
import (
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@ -11,6 +12,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)
@ -18,85 +20,6 @@ const (
flagDenom = "denom"
)
// NewQueryCmd returns a root CLI command handler for all x/bank query commands.
func NewQueryCmd(m codec.Marshaler) *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the bank module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(NewBalancesCmd(m))
return cmd
}
// NewBalancesCmd returns a CLI command handler for querying account balance(s).
func NewBalancesCmd(m codec.Marshaler) *cobra.Command {
cmd := &cobra.Command{
Use: "balances [address]",
Short: "Query for account balance(s) by address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithMarshaler(m)
addr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}
var (
params interface{}
result interface{}
route string
)
denom := viper.GetString(flagDenom)
if denom == "" {
params = types.NewQueryAllBalancesParams(addr)
route = fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAllBalances)
} else {
params = types.NewQueryBalanceParams(addr, denom)
route = fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryBalance)
}
bz, err := m.MarshalJSON(params)
if err != nil {
return fmt.Errorf("failed to marshal params: %w", err)
}
res, _, err := cliCtx.QueryWithData(route, bz)
if err != nil {
return err
}
if denom == "" {
var balances sdk.Coins
if err := m.UnmarshalJSON(res, &balances); err != nil {
return err
}
result = balances
} else {
var balance sdk.Coin
if err := m.UnmarshalJSON(res, &balance); err != nil {
return err
}
result = balance
}
return cliCtx.Println(result)
},
}
cmd.Flags().String(flagDenom, "", "The specific balance denomination to query for")
return flags.GetCommands(cmd)[0]
}
// ---------------------------------------------------------------------------
// Deprecated
//
@ -116,7 +39,10 @@ func GetQueryCmd(cdc *codec.Codec) *cobra.Command {
RunE: client.ValidateCmd,
}
cmd.AddCommand(GetBalancesCmd(cdc))
cmd.AddCommand(
GetBalancesCmd(cdc),
GetCmdQueryTotalSupply(cdc),
)
return cmd
}
@ -188,3 +114,37 @@ func GetBalancesCmd(cdc *codec.Codec) *cobra.Command {
return flags.GetCommands(cmd)[0]
}
// TODO: Remove once client-side Protobuf migration has been completed.
// ref: https://github.com/cosmos/cosmos-sdk/issues/5864
func GetCmdQueryTotalSupply(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "total [denom]",
Args: cobra.MaximumNArgs(1),
Short: "Query the total supply of coins of the chain",
Long: strings.TrimSpace(
fmt.Sprintf(`Query total supply of coins that are held by accounts in the
chain.
Example:
$ %s query %s total
To query for the total supply of a specific coin denomination use:
$ %s query %s total stake
`,
version.ClientName, types.ModuleName, version.ClientName, types.ModuleName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
if len(args) == 0 {
return queryTotalSupply(cliCtx, cdc)
}
return querySupplyOf(cliCtx, cdc, args[0])
},
}
return flags.GetCommands(cmd)[0]
}

52
x/bank/client/cli/util.go Normal file
View File

@ -0,0 +1,52 @@
package cli
import (
"fmt"
"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/x/bank/types"
)
func queryTotalSupply(cliCtx context.CLIContext, cdc *codec.Codec) error {
params := types.NewQueryTotalSupplyParams(1, 0) // no pagination
bz, err := cdc.MarshalJSON(params)
if err != nil {
return err
}
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTotalSupply), bz)
if err != nil {
return err
}
var totalSupply sdk.Coins
err = cdc.UnmarshalJSON(res, &totalSupply)
if err != nil {
return err
}
return cliCtx.PrintOutput(totalSupply)
}
func querySupplyOf(cliCtx context.CLIContext, cdc *codec.Codec, denom string) error {
params := types.NewQuerySupplyOfParams(denom)
bz, err := cdc.MarshalJSON(params)
if err != nil {
return err
}
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QuerySupplyOf), bz)
if err != nil {
return err
}
var supply sdk.Int
err = cdc.UnmarshalJSON(res, &supply)
if err != nil {
return err
}
return cliCtx.PrintOutput(supply)
}

View File

@ -69,3 +69,57 @@ func QueryBalancesRequestHandlerFn(ctx context.CLIContext) http.HandlerFunc {
rest.PostProcessResponse(w, ctx, res)
}
}
// HTTP request handler to query the total supply of coins
func totalSupplyHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
if rest.CheckBadRequestError(w, err) {
return
}
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}
params := types.NewQueryTotalSupplyParams(page, limit)
bz, err := cliCtx.Codec.MarshalJSON(params)
if rest.CheckBadRequestError(w, err) {
return
}
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTotalSupply), bz)
if rest.CheckInternalServerError(w, err) {
return
}
cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res)
}
}
// HTTP request handler to query the supply of a single denom
func supplyOfHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
denom := mux.Vars(r)["denom"]
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}
params := types.NewQuerySupplyOfParams(denom)
bz, err := cliCtx.Codec.MarshalJSON(params)
if rest.CheckBadRequestError(w, err) {
return
}
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QuerySupplyOf), bz)
if rest.CheckInternalServerError(w, err) {
return
}
cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res)
}
}

View File

@ -25,4 +25,6 @@ func RegisterHandlers(ctx context.CLIContext, m codec.Marshaler, txg tx.Generato
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc("/bank/accounts/{address}/transfers", SendRequestHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc("/bank/balances/{address}", QueryBalancesRequestHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/bank/total", totalSupplyHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/bank/total/{denom}", supplyOfHandlerFn(cliCtx)).Methods("GET")
}

View File

@ -2,6 +2,7 @@ package exported
import (
sdk "github.com/cosmos/cosmos-sdk/types"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
)
// GenesisBalance defines a genesis balance interface that allows for account
@ -10,3 +11,26 @@ type GenesisBalance interface {
GetAddress() sdk.AccAddress
GetCoins() sdk.Coins
}
// ModuleAccountI defines an account interface for modules that hold tokens in
// an escrow.
type ModuleAccountI interface {
authexported.Account
GetName() string
GetPermissions() []string
HasPermission(string) bool
}
// SupplyI defines an inflationary supply interface for modules that handle
// token supply.
type SupplyI interface {
GetTotal() sdk.Coins
SetTotal(total sdk.Coins)
Inflate(amount sdk.Coins)
Deflate(amount sdk.Coins)
String() string
ValidateBasic() error
}

View File

@ -4,12 +4,15 @@ import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)
// InitGenesis initializes the bank module's state from a given genesis state.
func InitGenesis(ctx sdk.Context, keeper Keeper, genState GenesisState) {
keeper.SetSendEnabled(ctx, genState.SendEnabled)
var totalSupply sdk.Coins
genState.Balances = SanitizeGenesisBalances(genState.Balances)
for _, balance := range genState.Balances {
if err := keeper.ValidateBalance(ctx, balance.Address); err != nil {
@ -19,7 +22,15 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, genState GenesisState) {
if err := keeper.SetBalances(ctx, balance.Address, balance.Coins); err != nil {
panic(fmt.Errorf("error on setting balances %w", err))
}
totalSupply = totalSupply.Add(balance.Coins...)
}
if genState.Supply.Empty() {
genState.Supply = totalSupply
}
keeper.SetSupply(ctx, NewSupply(genState.Supply))
}
// ExportGenesis returns the bank module's genesis state.
@ -45,5 +56,11 @@ func ExportGenesis(ctx sdk.Context, keeper Keeper) GenesisState {
})
}
return NewGenesisState(keeper.GetSendEnabled(ctx), balances)
return NewGenesisState(keeper.GetSendEnabled(ctx), balances, keeper.GetSupply(ctx).GetTotal())
}
// ValidateGenesis performs basic validation of supply genesis data returning an
// error for any failed validation criteria.
func ValidateGenesis(data GenesisState) error {
return types.NewSupply(data.Supply).ValidateBasic()
}

View File

@ -8,20 +8,27 @@ import (
)
// RegisterInvariants registers the bank module invariants
func RegisterInvariants(ir sdk.InvariantRegistry, bk ViewKeeper) {
ir.RegisterRoute(types.ModuleName, "nonnegative-outstanding",
NonnegativeBalanceInvariant(bk))
func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper) {
ir.RegisterRoute(types.ModuleName, "nonnegative-outstanding", NonnegativeBalanceInvariant(k))
ir.RegisterRoute(types.ModuleName, "total-supply", TotalSupply(k))
}
// AllInvariants runs all invariants of the X/bank module.
func AllInvariants(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
return TotalSupply(k)(ctx)
}
}
// NonnegativeBalanceInvariant checks that all accounts in the application have non-negative balances
func NonnegativeBalanceInvariant(bk ViewKeeper) sdk.Invariant {
func NonnegativeBalanceInvariant(k ViewKeeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
var (
msg string
count int
)
bk.IterateAllBalances(ctx, func(addr sdk.AccAddress, balance sdk.Coin) bool {
k.IterateAllBalances(ctx, func(addr sdk.AccAddress, balance sdk.Coin) bool {
if balance.IsNegative() {
count++
msg += fmt.Sprintf("\t%s has a negative balance of %s\n", addr, balance)
@ -38,3 +45,24 @@ func NonnegativeBalanceInvariant(bk ViewKeeper) sdk.Invariant {
), broken
}
}
// TotalSupply checks that the total supply reflects all the coins held in accounts
func TotalSupply(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
var expectedTotal sdk.Coins
supply := k.GetSupply(ctx)
k.IterateAllBalances(ctx, func(_ sdk.AccAddress, balance sdk.Coin) bool {
expectedTotal = expectedTotal.Add(balance)
return false
})
broken := !expectedTotal.IsEqual(supply.GetTotal())
return sdk.FormatInvariant(types.ModuleName, "total supply",
fmt.Sprintf(
"\tsum of accounts coins: %v\n"+
"\tsupply.Total: %v\n",
expectedTotal, supply.GetTotal())), broken
}
}

View File

@ -4,13 +4,10 @@ import (
"fmt"
"time"
"github.com/tendermint/tendermint/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
"github.com/cosmos/cosmos-sdk/x/bank/exported"
"github.com/cosmos/cosmos-sdk/x/bank/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
@ -22,6 +19,25 @@ var _ Keeper = (*BaseKeeper)(nil)
type Keeper interface {
SendKeeper
GetSupply(ctx sdk.Context) exported.SupplyI
SetSupply(ctx sdk.Context, supply exported.SupplyI)
ValidatePermissions(macc exported.ModuleAccountI) error
GetModuleAddress(moduleName string) sdk.AccAddress
GetModuleAddressAndPermissions(moduleName string) (addr sdk.AccAddress, permissions []string)
GetModuleAccountAndPermissions(ctx sdk.Context, moduleName string) (exported.ModuleAccountI, []string)
GetModuleAccount(ctx sdk.Context, moduleName string) exported.ModuleAccountI
SetModuleAccount(ctx sdk.Context, macc exported.ModuleAccountI)
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
DelegateCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
UndelegateCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
DelegateCoins(ctx sdk.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error
UndelegateCoins(ctx sdk.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error
}
@ -31,11 +47,15 @@ type BaseKeeper struct {
BaseSendKeeper
ak types.AccountKeeper
cdc types.Codec
storeKey sdk.StoreKey
paramSpace paramtypes.Subspace
permAddrs map[string]types.PermissionsForAddress
}
func NewBaseKeeper(
cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blacklistedAddrs map[string]bool,
cdc types.Codec, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace,
blacklistedAddrs map[string]bool, maccPerms map[string][]string,
) BaseKeeper {
// set KeyTable if it has not already been set
@ -43,10 +63,18 @@ func NewBaseKeeper(
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}
permAddrs := make(map[string]types.PermissionsForAddress)
for name, perms := range maccPerms {
permAddrs[name] = types.NewPermissionsForAddress(name, perms)
}
return BaseKeeper{
BaseSendKeeper: NewBaseSendKeeper(cdc, storeKey, ak, paramSpace, blacklistedAddrs),
ak: ak,
cdc: cdc,
storeKey: storeKey,
paramSpace: paramSpace,
permAddrs: permAddrs,
}
}
@ -126,431 +154,242 @@ func (k BaseKeeper) UndelegateCoins(ctx sdk.Context, moduleAccAddr, delegatorAdd
return nil
}
// SendKeeper defines a module interface that facilitates the transfer of coins
// between accounts without the possibility of creating coins.
type SendKeeper interface {
ViewKeeper
InputOutputCoins(ctx sdk.Context, inputs []types.Input, outputs []types.Output) error
SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
SubtractCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, error)
AddCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, error)
SetBalance(ctx sdk.Context, addr sdk.AccAddress, balance sdk.Coin) error
SetBalances(ctx sdk.Context, addr sdk.AccAddress, balances sdk.Coins) error
GetSendEnabled(ctx sdk.Context) bool
SetSendEnabled(ctx sdk.Context, enabled bool)
BlacklistedAddr(addr sdk.AccAddress) bool
}
var _ SendKeeper = (*BaseSendKeeper)(nil)
// BaseSendKeeper only allows transfers between accounts without the possibility of
// creating coins. It implements the SendKeeper interface.
type BaseSendKeeper struct {
BaseViewKeeper
cdc codec.Marshaler
ak types.AccountKeeper
storeKey sdk.StoreKey
paramSpace paramtypes.Subspace
// list of addresses that are restricted from receiving transactions
blacklistedAddrs map[string]bool
}
func NewBaseSendKeeper(
cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blacklistedAddrs map[string]bool,
) BaseSendKeeper {
return BaseSendKeeper{
BaseViewKeeper: NewBaseViewKeeper(cdc, storeKey, ak),
cdc: cdc,
ak: ak,
storeKey: storeKey,
paramSpace: paramSpace,
blacklistedAddrs: blacklistedAddrs,
}
}
// InputOutputCoins performs multi-send functionality. It accepts a series of
// inputs that correspond to a series of outputs. It returns an error if the
// inputs and outputs don't lineup or if any single transfer of tokens fails.
func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, inputs []types.Input, outputs []types.Output) error {
// Safety check ensuring that when sending coins the keeper must maintain the
// Check supply invariant and validity of Coins.
if err := types.ValidateInputsOutputs(inputs, outputs); err != nil {
return err
}
for _, in := range inputs {
_, err := k.SubtractCoins(ctx, in.Address, in.Coins)
if err != nil {
return err
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(types.AttributeKeySender, in.Address.String()),
),
)
}
for _, out := range outputs {
_, err := k.AddCoins(ctx, out.Address, out.Coins)
if err != nil {
return err
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeTransfer,
sdk.NewAttribute(types.AttributeKeyRecipient, out.Address.String()),
sdk.NewAttribute(sdk.AttributeKeyAmount, out.Coins.String()),
),
)
}
return nil
}
// SendCoins transfers amt coins from a sending account to a receiving account.
// An error is returned upon failure.
func (k BaseSendKeeper) SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error {
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeTransfer,
sdk.NewAttribute(types.AttributeKeyRecipient, toAddr.String()),
sdk.NewAttribute(sdk.AttributeKeyAmount, amt.String()),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(types.AttributeKeySender, fromAddr.String()),
),
})
_, err := k.SubtractCoins(ctx, fromAddr, amt)
if err != nil {
return err
}
_, err = k.AddCoins(ctx, toAddr, amt)
if err != nil {
return err
}
// Create account if recipient does not exist.
//
// NOTE: This should ultimately be removed in favor a more flexible approach
// such as delegated fee messages.
acc := k.ak.GetAccount(ctx, toAddr)
if acc == nil {
k.ak.SetAccount(ctx, k.ak.NewAccountWithAddress(ctx, toAddr))
}
return nil
}
// SubtractCoins removes amt coins the account by the given address. An error is
// returned if the resulting balance is negative or the initial amount is invalid.
func (k BaseSendKeeper) SubtractCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, error) {
if !amt.IsValid() {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, amt.String())
}
resultCoins := sdk.NewCoins()
lockedCoins := k.LockedCoins(ctx, addr)
for _, coin := range amt {
balance := k.GetBalance(ctx, addr, coin.Denom)
locked := sdk.NewCoin(coin.Denom, lockedCoins.AmountOf(coin.Denom))
spendable := balance.Sub(locked)
_, hasNeg := sdk.Coins{spendable}.SafeSub(sdk.Coins{coin})
if hasNeg {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "%s is smaller than %s", spendable, coin)
}
newBalance := balance.Sub(coin)
resultCoins = resultCoins.Add(newBalance)
err := k.SetBalance(ctx, addr, newBalance)
if err != nil {
return nil, err
}
}
return resultCoins, nil
}
// AddCoins adds amt to the account balance given by the provided address. An
// error is returned if the initial amount is invalid or if any resulting new
// balance is negative.
func (k BaseSendKeeper) AddCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, error) {
if !amt.IsValid() {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, amt.String())
}
var resultCoins sdk.Coins
for _, coin := range amt {
balance := k.GetBalance(ctx, addr, coin.Denom)
newBalance := balance.Add(coin)
resultCoins = resultCoins.Add(newBalance)
err := k.SetBalance(ctx, addr, newBalance)
if err != nil {
return nil, err
}
}
return resultCoins, nil
}
// ClearBalances removes all balances for a given account by address.
func (k BaseSendKeeper) ClearBalances(ctx sdk.Context, addr sdk.AccAddress) {
keys := [][]byte{}
k.IterateAccountBalances(ctx, addr, func(balance sdk.Coin) bool {
keys = append(keys, []byte(balance.Denom))
return false
})
// GetSupply retrieves the Supply from store
func (k BaseKeeper) GetSupply(ctx sdk.Context) exported.SupplyI {
store := ctx.KVStore(k.storeKey)
balancesStore := prefix.NewStore(store, types.BalancesPrefix)
accountStore := prefix.NewStore(balancesStore, addr.Bytes())
for _, key := range keys {
accountStore.Delete(key)
}
}
// SetBalances sets the balance (multiple coins) for an account by address. It will
// clear out all balances prior to setting the new coins as to set existing balances
// to zero if they don't exist in amt. An error is returned upon failure.
func (k BaseSendKeeper) SetBalances(ctx sdk.Context, addr sdk.AccAddress, balances sdk.Coins) error {
k.ClearBalances(ctx, addr)
for _, balance := range balances {
err := k.SetBalance(ctx, addr, balance)
if err != nil {
return err
}
}
return nil
}
// SetBalance sets the coin balance for an account by address.
func (k BaseSendKeeper) SetBalance(ctx sdk.Context, addr sdk.AccAddress, balance sdk.Coin) error {
if !balance.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, balance.String())
}
store := ctx.KVStore(k.storeKey)
balancesStore := prefix.NewStore(store, types.BalancesPrefix)
accountStore := prefix.NewStore(balancesStore, addr.Bytes())
bz := k.cdc.MustMarshalBinaryBare(&balance)
accountStore.Set([]byte(balance.Denom), bz)
return nil
}
// GetSendEnabled returns the current SendEnabled
func (k BaseSendKeeper) GetSendEnabled(ctx sdk.Context) bool {
var enabled bool
k.paramSpace.Get(ctx, types.ParamStoreKeySendEnabled, &enabled)
return enabled
}
// SetSendEnabled sets the send enabled
func (k BaseSendKeeper) SetSendEnabled(ctx sdk.Context, enabled bool) {
k.paramSpace.Set(ctx, types.ParamStoreKeySendEnabled, &enabled)
}
// BlacklistedAddr checks if a given address is blacklisted (i.e restricted from
// receiving funds)
func (k BaseSendKeeper) BlacklistedAddr(addr sdk.AccAddress) bool {
return k.blacklistedAddrs[addr.String()]
}
var _ ViewKeeper = (*BaseViewKeeper)(nil)
// ViewKeeper defines a module interface that facilitates read only access to
// account balances.
type ViewKeeper interface {
ValidateBalance(ctx sdk.Context, addr sdk.AccAddress) error
HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
IterateAccountBalances(ctx sdk.Context, addr sdk.AccAddress, cb func(coin sdk.Coin) (stop bool))
IterateAllBalances(ctx sdk.Context, cb func(address sdk.AccAddress, coin sdk.Coin) (stop bool))
}
// BaseViewKeeper implements a read only keeper implementation of ViewKeeper.
type BaseViewKeeper struct {
cdc codec.Marshaler
storeKey sdk.StoreKey
ak types.AccountKeeper
}
// NewBaseViewKeeper returns a new BaseViewKeeper.
func NewBaseViewKeeper(cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper) BaseViewKeeper {
return BaseViewKeeper{
cdc: cdc,
storeKey: storeKey,
ak: ak,
}
}
// Logger returns a module-specific logger.
func (k BaseViewKeeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
// HasBalance returns whether or not an account has at least amt balance.
func (k BaseViewKeeper) HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool {
return k.GetBalance(ctx, addr, amt.Denom).IsGTE(amt)
}
// GetAllBalances returns all the account balances for the given account address.
func (k BaseViewKeeper) GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
balances := sdk.NewCoins()
k.IterateAccountBalances(ctx, addr, func(balance sdk.Coin) bool {
balances = balances.Add(balance)
return false
})
return balances.Sort()
}
// GetBalance returns the balance of a specific denomination for a given account
// by address.
func (k BaseViewKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
store := ctx.KVStore(k.storeKey)
balancesStore := prefix.NewStore(store, types.BalancesPrefix)
accountStore := prefix.NewStore(balancesStore, addr.Bytes())
bz := accountStore.Get([]byte(denom))
bz := store.Get(types.SupplyKey)
if bz == nil {
return sdk.NewCoin(denom, sdk.ZeroInt())
panic("stored supply should not have been nil")
}
var balance sdk.Coin
k.cdc.MustUnmarshalBinaryBare(bz, &balance)
supply, err := k.cdc.UnmarshalSupply(bz)
if err != nil {
panic(err)
}
return balance
return supply
}
// IterateAccountBalances iterates over the balances of a single account and
// provides the token balance to a callback. If true is returned from the
// callback, iteration is halted.
func (k BaseViewKeeper) IterateAccountBalances(ctx sdk.Context, addr sdk.AccAddress, cb func(sdk.Coin) bool) {
// SetSupply sets the Supply to store
func (k BaseKeeper) SetSupply(ctx sdk.Context, supply exported.SupplyI) {
store := ctx.KVStore(k.storeKey)
balancesStore := prefix.NewStore(store, types.BalancesPrefix)
accountStore := prefix.NewStore(balancesStore, addr.Bytes())
bz, err := k.cdc.MarshalSupply(supply)
if err != nil {
panic(err)
}
iterator := accountStore.Iterator(nil, nil)
defer iterator.Close()
store.Set(types.SupplyKey, bz)
}
for ; iterator.Valid(); iterator.Next() {
var balance sdk.Coin
k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &balance)
if cb(balance) {
break
// ValidatePermissions validates that the module account has been granted
// permissions within its set of allowed permissions.
func (k BaseKeeper) ValidatePermissions(macc exported.ModuleAccountI) error {
permAddr := k.permAddrs[macc.GetName()]
for _, perm := range macc.GetPermissions() {
if !permAddr.HasPermission(perm) {
return fmt.Errorf("invalid module permission %s", perm)
}
}
return nil
}
// IterateAllBalances iterates over all the balances of all accounts and
// denominations that are provided to a callback. If true is returned from the
// callback, iteration is halted.
func (k BaseViewKeeper) IterateAllBalances(ctx sdk.Context, cb func(sdk.AccAddress, sdk.Coin) bool) {
store := ctx.KVStore(k.storeKey)
balancesStore := prefix.NewStore(store, types.BalancesPrefix)
iterator := balancesStore.Iterator(nil, nil)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
address := types.AddressFromBalancesStore(iterator.Key())
var balance sdk.Coin
k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &balance)
if cb(address, balance) {
break
}
// GetModuleAddress returns an address based on the module name
func (k BaseKeeper) GetModuleAddress(moduleName string) sdk.AccAddress {
permAddr, ok := k.permAddrs[moduleName]
if !ok {
return nil
}
return permAddr.GetAddress()
}
// LockedCoins returns all the coins that are not spendable (i.e. locked) for an
// account by address. For standard accounts, the result will always be no coins.
// For vesting accounts, LockedCoins is delegated to the concrete vesting account
// type.
func (k BaseViewKeeper) LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
// GetModuleAddressAndPermissions returns an address and permissions based on the module name
func (k BaseKeeper) GetModuleAddressAndPermissions(moduleName string) (addr sdk.AccAddress, permissions []string) {
permAddr, ok := k.permAddrs[moduleName]
if !ok {
return addr, permissions
}
return permAddr.GetAddress(), permAddr.GetPermissions()
}
// GetModuleAccountAndPermissions gets the module account from the auth account store and its
// registered permissions
func (k BaseKeeper) GetModuleAccountAndPermissions(ctx sdk.Context, moduleName string) (exported.ModuleAccountI, []string) {
addr, perms := k.GetModuleAddressAndPermissions(moduleName)
if addr == nil {
return nil, []string{}
}
acc := k.ak.GetAccount(ctx, addr)
if acc != nil {
vacc, ok := acc.(vestexported.VestingAccount)
if ok {
return vacc.LockedCoins(ctx.BlockTime())
macc, ok := acc.(exported.ModuleAccountI)
if !ok {
panic("account is not a module account")
}
return macc, perms
}
return sdk.NewCoins()
// create a new module account
macc := types.NewEmptyModuleAccount(moduleName, perms...)
maccI := (k.ak.NewAccount(ctx, macc)).(exported.ModuleAccountI) // set the account number
k.SetModuleAccount(ctx, maccI)
return maccI, perms
}
// SpendableCoins returns the total balances of spendable coins for an account
// by address. If the account has no spendable coins, an empty Coins slice is
// returned.
func (k BaseViewKeeper) SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
balances := k.GetAllBalances(ctx, addr)
locked := k.LockedCoins(ctx, addr)
// GetModuleAccount gets the module account from the auth account store, if the account does not
// exist in the AccountKeeper, then it is created.
func (k BaseKeeper) GetModuleAccount(ctx sdk.Context, moduleName string) exported.ModuleAccountI {
acc, _ := k.GetModuleAccountAndPermissions(ctx, moduleName)
return acc
}
spendable, hasNeg := balances.SafeSub(locked)
if hasNeg {
return sdk.NewCoins()
// SetModuleAccount sets the module account to the auth account store
func (k BaseKeeper) SetModuleAccount(ctx sdk.Context, macc exported.ModuleAccountI) { //nolint:interfacer
k.ak.SetAccount(ctx, macc)
}
// SendCoinsFromModuleToAccount transfers coins from a ModuleAccount to an AccAddress.
// It will panic if the module account does not exist.
func (k BaseKeeper) SendCoinsFromModuleToAccount(
ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins,
) error {
senderAddr := k.GetModuleAddress(senderModule)
if senderAddr == nil {
panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", senderModule))
}
return spendable
return k.SendCoins(ctx, senderAddr, recipientAddr, amt)
}
// ValidateBalance validates all balances for a given account address returning
// an error if any balance is invalid. It will check for vesting account types
// and validate the balances against the original vesting balances.
//
// CONTRACT: ValidateBalance should only be called upon genesis state. In the
// case of vesting accounts, balances may change in a valid manner that would
// otherwise yield an error from this call.
func (k BaseViewKeeper) ValidateBalance(ctx sdk.Context, addr sdk.AccAddress) error {
acc := k.ak.GetAccount(ctx, addr)
// SendCoinsFromModuleToModule transfers coins from a ModuleAccount to another.
// It will panic if either module account does not exist.
func (k BaseKeeper) SendCoinsFromModuleToModule(
ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins,
) error {
senderAddr := k.GetModuleAddress(senderModule)
if senderAddr == nil {
panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", senderModule))
}
recipientAcc := k.GetModuleAccount(ctx, recipientModule)
if recipientAcc == nil {
panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", recipientModule))
}
return k.SendCoins(ctx, senderAddr, recipientAcc.GetAddress(), amt)
}
// SendCoinsFromAccountToModule transfers coins from an AccAddress to a ModuleAccount.
// It will panic if the module account does not exist.
func (k BaseKeeper) SendCoinsFromAccountToModule(
ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins,
) error {
recipientAcc := k.GetModuleAccount(ctx, recipientModule)
if recipientAcc == nil {
panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", recipientModule))
}
return k.SendCoins(ctx, senderAddr, recipientAcc.GetAddress(), amt)
}
// DelegateCoinsFromAccountToModule delegates coins and transfers them from a
// delegator account to a module account. It will panic if the module account
// does not exist or is unauthorized.
func (k BaseKeeper) DelegateCoinsFromAccountToModule(
ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins,
) error {
recipientAcc := k.GetModuleAccount(ctx, recipientModule)
if recipientAcc == nil {
panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", recipientModule))
}
if !recipientAcc.HasPermission(types.Staking) {
panic(sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "module account %s does not have permissions to receive delegated coins", recipientModule))
}
return k.DelegateCoins(ctx, senderAddr, recipientAcc.GetAddress(), amt)
}
// UndelegateCoinsFromModuleToAccount undelegates the unbonding coins and transfers
// them from a module account to the delegator account. It will panic if the
// module account does not exist or is unauthorized.
func (k BaseKeeper) UndelegateCoinsFromModuleToAccount(
ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins,
) error {
acc := k.GetModuleAccount(ctx, senderModule)
if acc == nil {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr)
panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", senderModule))
}
balances := k.GetAllBalances(ctx, addr)
if !balances.IsValid() {
return fmt.Errorf("account balance of %s is invalid", balances)
if !acc.HasPermission(types.Staking) {
panic(sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "module account %s does not have permissions to undelegate coins", senderModule))
}
vacc, ok := acc.(vestexported.VestingAccount)
if ok {
ogv := vacc.GetOriginalVesting()
if ogv.IsAnyGT(balances) {
return fmt.Errorf("vesting amount %s cannot be greater than total amount %s", ogv, balances)
}
return k.UndelegateCoins(ctx, acc.GetAddress(), recipientAddr, amt)
}
// MintCoins creates new coins from thin air and adds it to the module account.
// It will panic if the module account does not exist or is unauthorized.
func (k BaseKeeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error {
acc := k.GetModuleAccount(ctx, moduleName)
if acc == nil {
panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", moduleName))
}
if !acc.HasPermission(types.Minter) {
panic(sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "module account %s does not have permissions to mint tokens", moduleName))
}
_, err := k.AddCoins(ctx, acc.GetAddress(), amt)
if err != nil {
return err
}
// update total supply
supply := k.GetSupply(ctx)
supply.Inflate(amt)
k.SetSupply(ctx, supply)
logger := k.Logger(ctx)
logger.Info(fmt.Sprintf("minted %s from %s module account", amt.String(), moduleName))
return nil
}
// BurnCoins burns coins deletes coins from the balance of the module account.
// It will panic if the module account does not exist or is unauthorized.
func (k BaseKeeper) BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error {
acc := k.GetModuleAccount(ctx, moduleName)
if acc == nil {
panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", moduleName))
}
if !acc.HasPermission(types.Burner) {
panic(sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "module account %s does not have permissions to burn tokens", moduleName))
}
_, err := k.SubtractCoins(ctx, acc.GetAddress(), amt)
if err != nil {
return err
}
// update total supply
supply := k.GetSupply(ctx)
supply.Deflate(amt)
k.SetSupply(ctx, supply)
logger := k.Logger(ctx)
logger.Info(fmt.Sprintf("burned %s from %s module account", amt.String(), moduleName))
return nil
}

View File

@ -9,16 +9,33 @@ import (
tmkv "github.com/tendermint/tendermint/libs/kv"
tmtime "github.com/tendermint/tendermint/types/time"
codecstd "github.com/cosmos/cosmos-sdk/codec/std"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)
const (
fooDenom = "foo"
barDenom = "bar"
fooDenom = "foo"
barDenom = "bar"
initialPower = int64(100)
holder = "holder"
multiPerm = "multiple permissions account"
randomPerm = "random permission"
)
var (
holderAcc = types.NewEmptyModuleAccount(holder)
burnerAcc = types.NewEmptyModuleAccount(types.Burner, types.Burner)
minterAcc = types.NewEmptyModuleAccount(types.Minter, types.Minter)
multiPermAcc = types.NewEmptyModuleAccount(multiPerm, types.Burner, types.Minter, types.Staking)
randomPermAcc = types.NewEmptyModuleAccount(randomPerm, "random")
initTokens = sdk.TokensFromConsensusPower(initialPower)
initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens))
)
func newFooCoin(amt int64) sdk.Coin {
@ -29,6 +46,17 @@ func newBarCoin(amt int64) sdk.Coin {
return sdk.NewInt64Coin(barDenom, amt)
}
// nolint: interfacer
func getCoinsByName(ctx sdk.Context, bk bank.Keeper, ak types.AccountKeeper, moduleName string) sdk.Coins {
moduleAddress := bk.GetModuleAddress(moduleName)
macc := ak.GetAccount(ctx, moduleAddress)
if macc == nil {
return sdk.Coins(nil)
}
return bk.GetAllBalances(ctx, macc.GetAddress())
}
type IntegrationTestSuite struct {
suite.Suite
@ -47,6 +75,208 @@ func (suite *IntegrationTestSuite) SetupTest() {
suite.ctx = ctx
}
func (suite *IntegrationTestSuite) TestSupply_ValidatePermissions() {
app := suite.app
// add module accounts to supply keeper
maccPerms := simapp.GetMaccPerms()
maccPerms[holder] = nil
maccPerms[types.Burner] = []string{types.Burner}
maccPerms[types.Minter] = []string{types.Minter}
maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking}
maccPerms[randomPerm] = []string{"random"}
appCodec := codecstd.NewAppCodec(app.Codec())
keeper := bank.NewBaseKeeper(
appCodec, app.GetKey(types.StoreKey), app.AccountKeeper,
app.GetSubspace(bank.ModuleName), make(map[string]bool), maccPerms,
)
err := keeper.ValidatePermissions(multiPermAcc)
suite.Require().NoError(err)
err = keeper.ValidatePermissions(randomPermAcc)
suite.Require().NoError(err)
// unregistered permissions
otherAcc := types.NewEmptyModuleAccount("other", "other")
err = app.BankKeeper.ValidatePermissions(otherAcc)
suite.Require().Error(err)
}
func (suite *IntegrationTestSuite) TestSupply() {
app, ctx := suite.app, suite.ctx
initialPower := int64(100)
initTokens := sdk.TokensFromConsensusPower(initialPower)
totalSupply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens))
app.BankKeeper.SetSupply(ctx, types.NewSupply(totalSupply))
total := app.BankKeeper.GetSupply(ctx).GetTotal()
suite.Require().Equal(totalSupply, total)
}
func (suite *IntegrationTestSuite) TestSupply_SendCoins() {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1})
appCodec := codecstd.NewAppCodec(app.Codec())
// add module accounts to supply keeper
maccPerms := simapp.GetMaccPerms()
maccPerms[holder] = nil
maccPerms[types.Burner] = []string{types.Burner}
maccPerms[types.Minter] = []string{types.Minter}
maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking}
maccPerms[randomPerm] = []string{"random"}
keeper := bank.NewBaseKeeper(
appCodec, app.GetKey(types.StoreKey), app.AccountKeeper,
app.GetSubspace(bank.ModuleName), make(map[string]bool), maccPerms,
)
baseAcc := app.AccountKeeper.NewAccountWithAddress(ctx, types.NewModuleAddress("baseAcc"))
suite.Require().NoError(keeper.SetBalances(ctx, holderAcc.GetAddress(), initCoins))
keeper.SetSupply(ctx, types.NewSupply(initCoins))
keeper.SetModuleAccount(ctx, holderAcc)
keeper.SetModuleAccount(ctx, burnerAcc)
app.AccountKeeper.SetAccount(ctx, baseAcc)
suite.Require().Panics(func() {
keeper.SendCoinsFromModuleToModule(ctx, "", holderAcc.GetName(), initCoins) // nolint:errcheck
})
suite.Require().Panics(func() {
keeper.SendCoinsFromModuleToModule(ctx, types.Burner, "", initCoins) // nolint:errcheck
})
suite.Require().Panics(func() {
keeper.SendCoinsFromModuleToAccount(ctx, "", baseAcc.GetAddress(), initCoins) // nolint:errcheck
})
suite.Require().Error(
keeper.SendCoinsFromModuleToAccount(ctx, holderAcc.GetName(), baseAcc.GetAddress(), initCoins.Add(initCoins...)),
)
suite.Require().NoError(
keeper.SendCoinsFromModuleToModule(ctx, holderAcc.GetName(), types.Burner, initCoins),
)
suite.Require().Equal(sdk.Coins(nil), getCoinsByName(ctx, keeper, app.AccountKeeper, holderAcc.GetName()))
suite.Require().Equal(initCoins, getCoinsByName(ctx, keeper, app.AccountKeeper, types.Burner))
suite.Require().NoError(
keeper.SendCoinsFromModuleToAccount(ctx, types.Burner, baseAcc.GetAddress(), initCoins),
)
suite.Require().Equal(sdk.Coins(nil), getCoinsByName(ctx, keeper, app.AccountKeeper, types.Burner))
suite.Require().Equal(initCoins, keeper.GetAllBalances(ctx, baseAcc.GetAddress()))
suite.Require().NoError(keeper.SendCoinsFromAccountToModule(ctx, baseAcc.GetAddress(), types.Burner, initCoins))
suite.Require().Equal(sdk.Coins(nil), keeper.GetAllBalances(ctx, baseAcc.GetAddress()))
suite.Require().Equal(initCoins, getCoinsByName(ctx, keeper, app.AccountKeeper, types.Burner))
}
func (suite *IntegrationTestSuite) TestSupply_MintCoins() {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1})
appCodec := codecstd.NewAppCodec(app.Codec())
// add module accounts to supply keeper
maccPerms := simapp.GetMaccPerms()
maccPerms[holder] = nil
maccPerms[types.Burner] = []string{types.Burner}
maccPerms[types.Minter] = []string{types.Minter}
maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking}
maccPerms[randomPerm] = []string{"random"}
keeper := bank.NewBaseKeeper(
appCodec, app.GetKey(types.StoreKey), app.AccountKeeper,
app.GetSubspace(bank.ModuleName), make(map[string]bool), maccPerms,
)
keeper.SetModuleAccount(ctx, burnerAcc)
keeper.SetModuleAccount(ctx, minterAcc)
keeper.SetModuleAccount(ctx, multiPermAcc)
keeper.SetModuleAccount(ctx, randomPermAcc)
initialSupply := keeper.GetSupply(ctx)
suite.Require().Panics(func() { keeper.MintCoins(ctx, "", initCoins) }, "no module account") // nolint:errcheck
suite.Require().Panics(func() { keeper.MintCoins(ctx, types.Burner, initCoins) }, "invalid permission") // nolint:errcheck
err := keeper.MintCoins(ctx, types.Minter, sdk.Coins{sdk.Coin{Denom: "denom", Amount: sdk.NewInt(-10)}})
suite.Require().Error(err, "insufficient coins")
suite.Require().Panics(func() { keeper.MintCoins(ctx, randomPerm, initCoins) }) // nolint:errcheck
err = keeper.MintCoins(ctx, types.Minter, initCoins)
suite.Require().NoError(err)
suite.Require().Equal(initCoins, getCoinsByName(ctx, keeper, app.AccountKeeper, types.Minter))
suite.Require().Equal(initialSupply.GetTotal().Add(initCoins...), keeper.GetSupply(ctx).GetTotal())
// test same functionality on module account with multiple permissions
initialSupply = keeper.GetSupply(ctx)
err = keeper.MintCoins(ctx, multiPermAcc.GetName(), initCoins)
suite.Require().NoError(err)
suite.Require().Equal(initCoins, getCoinsByName(ctx, keeper, app.AccountKeeper, multiPermAcc.GetName()))
suite.Require().Equal(initialSupply.GetTotal().Add(initCoins...), keeper.GetSupply(ctx).GetTotal())
suite.Require().Panics(func() { keeper.MintCoins(ctx, types.Burner, initCoins) }) // nolint:errcheck
}
func (suite *IntegrationTestSuite) TestSupply_BurnCoins() {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, abci.Header{Height: 1})
appCodec := codecstd.NewAppCodec(app.Codec())
// add module accounts to supply keeper
maccPerms := simapp.GetMaccPerms()
maccPerms[holder] = nil
maccPerms[types.Burner] = []string{types.Burner}
maccPerms[types.Minter] = []string{types.Minter}
maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking}
maccPerms[randomPerm] = []string{"random"}
keeper := bank.NewBaseKeeper(
appCodec, app.GetKey(types.StoreKey), app.AccountKeeper,
app.GetSubspace(bank.ModuleName), make(map[string]bool), maccPerms,
)
suite.Require().NoError(keeper.SetBalances(ctx, burnerAcc.GetAddress(), initCoins))
keeper.SetSupply(ctx, types.NewSupply(initCoins))
keeper.SetModuleAccount(ctx, burnerAcc)
initialSupply := keeper.GetSupply(ctx)
initialSupply.Inflate(initCoins)
keeper.SetSupply(ctx, initialSupply)
suite.Require().Panics(func() { keeper.BurnCoins(ctx, "", initCoins) }, "no module account") // nolint:errcheck
suite.Require().Panics(func() { keeper.BurnCoins(ctx, types.Minter, initCoins) }, "invalid permission") // nolint:errcheck
suite.Require().Panics(func() { keeper.BurnCoins(ctx, randomPerm, initialSupply.GetTotal()) }, "random permission") // nolint:errcheck
err := keeper.BurnCoins(ctx, types.Burner, initialSupply.GetTotal())
suite.Require().Error(err, "insufficient coins")
err = keeper.BurnCoins(ctx, types.Burner, initCoins)
suite.Require().NoError(err)
suite.Require().Equal(sdk.Coins(nil), getCoinsByName(ctx, keeper, app.AccountKeeper, types.Burner))
suite.Require().Equal(initialSupply.GetTotal().Sub(initCoins), keeper.GetSupply(ctx).GetTotal())
// test same functionality on module account with multiple permissions
initialSupply = keeper.GetSupply(ctx)
initialSupply.Inflate(initCoins)
keeper.SetSupply(ctx, initialSupply)
suite.Require().NoError(keeper.SetBalances(ctx, multiPermAcc.GetAddress(), initCoins))
keeper.SetModuleAccount(ctx, multiPermAcc)
err = keeper.BurnCoins(ctx, multiPermAcc.GetName(), initCoins)
suite.Require().NoError(err)
suite.Require().Equal(sdk.Coins(nil), getCoinsByName(ctx, keeper, app.AccountKeeper, multiPermAcc.GetName()))
suite.Require().Equal(initialSupply.GetTotal().Sub(initCoins), keeper.GetSupply(ctx).GetTotal())
}
func (suite *IntegrationTestSuite) TestSendCoinsNewAccount() {
app, ctx := suite.app, suite.ctx
balances := sdk.NewCoins(newFooCoin(100), newBarCoin(50))

View File

@ -3,6 +3,7 @@ package keeper
import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@ -19,6 +20,12 @@ func NewQuerier(k Keeper) sdk.Querier {
case types.QueryAllBalances:
return queryAllBalance(ctx, req, k)
case types.QueryTotalSupply:
return queryTotalSupply(ctx, req, k)
case types.QuerySupplyOf:
return querySupplyOf(ctx, req, k)
default:
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0])
}
@ -58,3 +65,46 @@ func queryAllBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte,
return bz, nil
}
func queryTotalSupply(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) {
var params types.QueryTotalSupplyParams
err := types.ModuleCdc.UnmarshalJSON(req.Data, &params)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
}
totalSupply := k.GetSupply(ctx).GetTotal()
start, end := client.Paginate(len(totalSupply), params.Page, params.Limit, 100)
if start < 0 || end < 0 {
totalSupply = sdk.Coins{}
} else {
totalSupply = totalSupply[start:end]
}
res, err := totalSupply.MarshalJSON()
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
}
return res, nil
}
func querySupplyOf(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) {
var params types.QuerySupplyOfParams
err := types.ModuleCdc.UnmarshalJSON(req.Data, &params)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
}
supply := k.GetSupply(ctx).GetTotal().AmountOf(params.Denom)
res, err := supply.MarshalJSON()
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
}
return res, nil
}

View File

@ -7,6 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)
@ -83,6 +84,61 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryAllBalances() {
suite.True(balances.IsEqual(origCoins))
}
func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupply() {
app, ctx := suite.app, suite.ctx
expectedTotalSupply := bank.NewSupply(sdk.NewCoins(sdk.NewInt64Coin("test", 400000000)))
app.BankKeeper.SetSupply(ctx, expectedTotalSupply)
req := abci.RequestQuery{
Path: fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryTotalSupply),
Data: []byte{},
}
querier := keeper.NewQuerier(app.BankKeeper)
res, err := querier(ctx, []string{types.QueryTotalSupply}, req)
suite.Require().NotNil(err)
suite.Require().Nil(res)
req.Data = app.Codec().MustMarshalJSON(types.NewQueryTotalSupplyParams(1, 100))
res, err = querier(ctx, []string{types.QueryTotalSupply}, req)
suite.Require().NoError(err)
suite.Require().NotNil(res)
var resp sdk.Coins
suite.Require().NoError(app.Codec().UnmarshalJSON(res, &resp))
suite.Require().Equal(expectedTotalSupply.Total, resp)
}
func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupplyOf() {
app, ctx := suite.app, suite.ctx
test1Supply := sdk.NewInt64Coin("test1", 4000000)
test2Supply := sdk.NewInt64Coin("test2", 700000000)
expectedTotalSupply := bank.NewSupply(sdk.NewCoins(test1Supply, test2Supply))
app.BankKeeper.SetSupply(ctx, expectedTotalSupply)
req := abci.RequestQuery{
Path: fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QuerySupplyOf),
Data: []byte{},
}
querier := keeper.NewQuerier(app.BankKeeper)
res, err := querier(ctx, []string{types.QuerySupplyOf}, req)
suite.Require().NotNil(err)
suite.Require().Nil(res)
req.Data = app.Codec().MustMarshalJSON(types.NewQuerySupplyOfParams(test1Supply.Denom))
res, err = querier(ctx, []string{types.QuerySupplyOf}, req)
suite.Require().NoError(err)
suite.Require().NotNil(res)
var resp sdk.Int
suite.Require().NoError(app.Codec().UnmarshalJSON(res, &resp))
suite.Require().Equal(test1Supply.Amount, resp)
}
func (suite *IntegrationTestSuite) TestQuerierRouteNotFound() {
app, ctx := suite.app, suite.ctx
req := abci.RequestQuery{

262
x/bank/keeper/send.go Normal file
View File

@ -0,0 +1,262 @@
package keeper
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/bank/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
// SendKeeper defines a module interface that facilitates the transfer of coins
// between accounts without the possibility of creating coins.
type SendKeeper interface {
ViewKeeper
InputOutputCoins(ctx sdk.Context, inputs []types.Input, outputs []types.Output) error
SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
SubtractCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, error)
AddCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, error)
SetBalance(ctx sdk.Context, addr sdk.AccAddress, balance sdk.Coin) error
SetBalances(ctx sdk.Context, addr sdk.AccAddress, balances sdk.Coins) error
GetSendEnabled(ctx sdk.Context) bool
SetSendEnabled(ctx sdk.Context, enabled bool)
BlacklistedAddr(addr sdk.AccAddress) bool
}
var _ SendKeeper = (*BaseSendKeeper)(nil)
// BaseSendKeeper only allows transfers between accounts without the possibility of
// creating coins. It implements the SendKeeper interface.
type BaseSendKeeper struct {
BaseViewKeeper
cdc codec.Marshaler
ak types.AccountKeeper
storeKey sdk.StoreKey
paramSpace paramtypes.Subspace
// list of addresses that are restricted from receiving transactions
blacklistedAddrs map[string]bool
}
func NewBaseSendKeeper(
cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blacklistedAddrs map[string]bool,
) BaseSendKeeper {
return BaseSendKeeper{
BaseViewKeeper: NewBaseViewKeeper(cdc, storeKey, ak),
cdc: cdc,
ak: ak,
storeKey: storeKey,
paramSpace: paramSpace,
blacklistedAddrs: blacklistedAddrs,
}
}
// InputOutputCoins performs multi-send functionality. It accepts a series of
// inputs that correspond to a series of outputs. It returns an error if the
// inputs and outputs don't lineup or if any single transfer of tokens fails.
func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, inputs []types.Input, outputs []types.Output) error {
// Safety check ensuring that when sending coins the keeper must maintain the
// Check supply invariant and validity of Coins.
if err := types.ValidateInputsOutputs(inputs, outputs); err != nil {
return err
}
for _, in := range inputs {
_, err := k.SubtractCoins(ctx, in.Address, in.Coins)
if err != nil {
return err
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(types.AttributeKeySender, in.Address.String()),
),
)
}
for _, out := range outputs {
_, err := k.AddCoins(ctx, out.Address, out.Coins)
if err != nil {
return err
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeTransfer,
sdk.NewAttribute(types.AttributeKeyRecipient, out.Address.String()),
sdk.NewAttribute(sdk.AttributeKeyAmount, out.Coins.String()),
),
)
}
return nil
}
// SendCoins transfers amt coins from a sending account to a receiving account.
// An error is returned upon failure.
func (k BaseSendKeeper) SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error {
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeTransfer,
sdk.NewAttribute(types.AttributeKeyRecipient, toAddr.String()),
sdk.NewAttribute(sdk.AttributeKeyAmount, amt.String()),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(types.AttributeKeySender, fromAddr.String()),
),
})
_, err := k.SubtractCoins(ctx, fromAddr, amt)
if err != nil {
return err
}
_, err = k.AddCoins(ctx, toAddr, amt)
if err != nil {
return err
}
// Create account if recipient does not exist.
//
// NOTE: This should ultimately be removed in favor a more flexible approach
// such as delegated fee messages.
acc := k.ak.GetAccount(ctx, toAddr)
if acc == nil {
k.ak.SetAccount(ctx, k.ak.NewAccountWithAddress(ctx, toAddr))
}
return nil
}
// SubtractCoins removes amt coins the account by the given address. An error is
// returned if the resulting balance is negative or the initial amount is invalid.
func (k BaseSendKeeper) SubtractCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, error) {
if !amt.IsValid() {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, amt.String())
}
resultCoins := sdk.NewCoins()
lockedCoins := k.LockedCoins(ctx, addr)
for _, coin := range amt {
balance := k.GetBalance(ctx, addr, coin.Denom)
locked := sdk.NewCoin(coin.Denom, lockedCoins.AmountOf(coin.Denom))
spendable := balance.Sub(locked)
_, hasNeg := sdk.Coins{spendable}.SafeSub(sdk.Coins{coin})
if hasNeg {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "%s is smaller than %s", spendable, coin)
}
newBalance := balance.Sub(coin)
resultCoins = resultCoins.Add(newBalance)
err := k.SetBalance(ctx, addr, newBalance)
if err != nil {
return nil, err
}
}
return resultCoins, nil
}
// AddCoins adds amt to the account balance given by the provided address. An
// error is returned if the initial amount is invalid or if any resulting new
// balance is negative.
func (k BaseSendKeeper) AddCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, error) {
if !amt.IsValid() {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, amt.String())
}
var resultCoins sdk.Coins
for _, coin := range amt {
balance := k.GetBalance(ctx, addr, coin.Denom)
newBalance := balance.Add(coin)
resultCoins = resultCoins.Add(newBalance)
err := k.SetBalance(ctx, addr, newBalance)
if err != nil {
return nil, err
}
}
return resultCoins, nil
}
// ClearBalances removes all balances for a given account by address.
func (k BaseSendKeeper) ClearBalances(ctx sdk.Context, addr sdk.AccAddress) {
keys := [][]byte{}
k.IterateAccountBalances(ctx, addr, func(balance sdk.Coin) bool {
keys = append(keys, []byte(balance.Denom))
return false
})
store := ctx.KVStore(k.storeKey)
balancesStore := prefix.NewStore(store, types.BalancesPrefix)
accountStore := prefix.NewStore(balancesStore, addr.Bytes())
for _, key := range keys {
accountStore.Delete(key)
}
}
// SetBalances sets the balance (multiple coins) for an account by address. It will
// clear out all balances prior to setting the new coins as to set existing balances
// to zero if they don't exist in amt. An error is returned upon failure.
func (k BaseSendKeeper) SetBalances(ctx sdk.Context, addr sdk.AccAddress, balances sdk.Coins) error {
k.ClearBalances(ctx, addr)
for _, balance := range balances {
err := k.SetBalance(ctx, addr, balance)
if err != nil {
return err
}
}
return nil
}
// SetBalance sets the coin balance for an account by address.
func (k BaseSendKeeper) SetBalance(ctx sdk.Context, addr sdk.AccAddress, balance sdk.Coin) error {
if !balance.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, balance.String())
}
store := ctx.KVStore(k.storeKey)
balancesStore := prefix.NewStore(store, types.BalancesPrefix)
accountStore := prefix.NewStore(balancesStore, addr.Bytes())
bz := k.cdc.MustMarshalBinaryBare(&balance)
accountStore.Set([]byte(balance.Denom), bz)
return nil
}
// GetSendEnabled returns the current SendEnabled
func (k BaseSendKeeper) GetSendEnabled(ctx sdk.Context) bool {
var enabled bool
k.paramSpace.Get(ctx, types.ParamStoreKeySendEnabled, &enabled)
return enabled
}
// SetSendEnabled sets the send enabled
func (k BaseSendKeeper) SetSendEnabled(ctx sdk.Context, enabled bool) {
k.paramSpace.Set(ctx, types.ParamStoreKeySendEnabled, &enabled)
}
// BlacklistedAddr checks if a given address is blacklisted (i.e restricted from
// receiving funds)
func (k BaseSendKeeper) BlacklistedAddr(addr sdk.AccAddress) bool {
return k.blacklistedAddrs[addr.String()]
}

190
x/bank/keeper/view.go Normal file
View File

@ -0,0 +1,190 @@
package keeper
import (
"fmt"
"github.com/tendermint/tendermint/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)
var _ ViewKeeper = (*BaseViewKeeper)(nil)
// ViewKeeper defines a module interface that facilitates read only access to
// account balances.
type ViewKeeper interface {
ValidateBalance(ctx sdk.Context, addr sdk.AccAddress) error
HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
IterateAccountBalances(ctx sdk.Context, addr sdk.AccAddress, cb func(coin sdk.Coin) (stop bool))
IterateAllBalances(ctx sdk.Context, cb func(address sdk.AccAddress, coin sdk.Coin) (stop bool))
}
// BaseViewKeeper implements a read only keeper implementation of ViewKeeper.
type BaseViewKeeper struct {
cdc codec.Marshaler
storeKey sdk.StoreKey
ak types.AccountKeeper
}
// NewBaseViewKeeper returns a new BaseViewKeeper.
func NewBaseViewKeeper(cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper) BaseViewKeeper {
return BaseViewKeeper{
cdc: cdc,
storeKey: storeKey,
ak: ak,
}
}
// Logger returns a module-specific logger.
func (k BaseViewKeeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
// HasBalance returns whether or not an account has at least amt balance.
func (k BaseViewKeeper) HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool {
return k.GetBalance(ctx, addr, amt.Denom).IsGTE(amt)
}
// GetAllBalances returns all the account balances for the given account address.
func (k BaseViewKeeper) GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
balances := sdk.NewCoins()
k.IterateAccountBalances(ctx, addr, func(balance sdk.Coin) bool {
balances = balances.Add(balance)
return false
})
return balances.Sort()
}
// GetBalance returns the balance of a specific denomination for a given account
// by address.
func (k BaseViewKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
store := ctx.KVStore(k.storeKey)
balancesStore := prefix.NewStore(store, types.BalancesPrefix)
accountStore := prefix.NewStore(balancesStore, addr.Bytes())
bz := accountStore.Get([]byte(denom))
if bz == nil {
return sdk.NewCoin(denom, sdk.ZeroInt())
}
var balance sdk.Coin
k.cdc.MustUnmarshalBinaryBare(bz, &balance)
return balance
}
// IterateAccountBalances iterates over the balances of a single account and
// provides the token balance to a callback. If true is returned from the
// callback, iteration is halted.
func (k BaseViewKeeper) IterateAccountBalances(ctx sdk.Context, addr sdk.AccAddress, cb func(sdk.Coin) bool) {
store := ctx.KVStore(k.storeKey)
balancesStore := prefix.NewStore(store, types.BalancesPrefix)
accountStore := prefix.NewStore(balancesStore, addr.Bytes())
iterator := accountStore.Iterator(nil, nil)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
var balance sdk.Coin
k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &balance)
if cb(balance) {
break
}
}
}
// IterateAllBalances iterates over all the balances of all accounts and
// denominations that are provided to a callback. If true is returned from the
// callback, iteration is halted.
func (k BaseViewKeeper) IterateAllBalances(ctx sdk.Context, cb func(sdk.AccAddress, sdk.Coin) bool) {
store := ctx.KVStore(k.storeKey)
balancesStore := prefix.NewStore(store, types.BalancesPrefix)
iterator := balancesStore.Iterator(nil, nil)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
address := types.AddressFromBalancesStore(iterator.Key())
var balance sdk.Coin
k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &balance)
if cb(address, balance) {
break
}
}
}
// LockedCoins returns all the coins that are not spendable (i.e. locked) for an
// account by address. For standard accounts, the result will always be no coins.
// For vesting accounts, LockedCoins is delegated to the concrete vesting account
// type.
func (k BaseViewKeeper) LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
acc := k.ak.GetAccount(ctx, addr)
if acc != nil {
vacc, ok := acc.(vestexported.VestingAccount)
if ok {
return vacc.LockedCoins(ctx.BlockTime())
}
}
return sdk.NewCoins()
}
// SpendableCoins returns the total balances of spendable coins for an account
// by address. If the account has no spendable coins, an empty Coins slice is
// returned.
func (k BaseViewKeeper) SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
balances := k.GetAllBalances(ctx, addr)
locked := k.LockedCoins(ctx, addr)
spendable, hasNeg := balances.SafeSub(locked)
if hasNeg {
return sdk.NewCoins()
}
return spendable
}
// ValidateBalance validates all balances for a given account address returning
// an error if any balance is invalid. It will check for vesting account types
// and validate the balances against the original vesting balances.
//
// CONTRACT: ValidateBalance should only be called upon genesis state. In the
// case of vesting accounts, balances may change in a valid manner that would
// otherwise yield an error from this call.
func (k BaseViewKeeper) ValidateBalance(ctx sdk.Context, addr sdk.AccAddress) error {
acc := k.ak.GetAccount(ctx, addr)
if acc == nil {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr)
}
balances := k.GetAllBalances(ctx, addr)
if !balances.IsValid() {
return fmt.Errorf("account balance of %s is invalid", balances)
}
vacc, ok := acc.(vestexported.VestingAccount)
if ok {
ogv := vacc.GetOriginalVesting()
if ogv.IsAnyGT(balances) {
return fmt.Errorf("vesting amount %s cannot be greater than total amount %s", ogv, balances)
}
}
return nil
}

View File

@ -152,8 +152,10 @@ func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {
return simulation.ParamChanges(r)
}
// RegisterStoreDecoder performs a no-op.
func (AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}
// RegisterStoreDecoder registers a decoder for supply module's types
func (AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
sdr[StoreKey] = simulation.DecodeStore
}
// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {

View File

@ -7,20 +7,19 @@ import (
tmkv "github.com/tendermint/tendermint/libs/kv"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/supply/keeper"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)
// DecodeStore unmarshals the KVPair's Value to the corresponding supply type
// DecodeStore unmarshals the KVPair's values to the corresponding types.
func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string {
switch {
case bytes.Equal(kvA.Key[:1], keeper.SupplyKey):
case bytes.Equal(kvA.Key[:1], types.SupplyKey):
var supplyA, supplyB types.Supply
cdc.MustUnmarshalBinaryBare(kvA.Value, &supplyA)
cdc.MustUnmarshalBinaryBare(kvB.Value, &supplyB)
return fmt.Sprintf("%v\n%v", supplyB, supplyB)
default:
panic(fmt.Sprintf("invalid supply key %X", kvA.Key))
panic(fmt.Sprintf("unknown %s key %X (%s)", types.ModuleName, kvA.Key, kvA.Key))
}
}

View File

@ -5,13 +5,11 @@ import (
"testing"
"github.com/stretchr/testify/require"
tmkv "github.com/tendermint/tendermint/libs/kv"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/supply/keeper"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)
func makeTestCodec() (cdc *codec.Codec) {
@ -27,7 +25,7 @@ func TestDecodeStore(t *testing.T) {
totalSupply := types.NewSupply(sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000)))
kvPairs := tmkv.Pairs{
tmkv.Pair{Key: keeper.SupplyKey, Value: cdc.MustMarshalBinaryBare(totalSupply)},
tmkv.Pair{Key: types.SupplyKey, Value: cdc.MustMarshalBinaryBare(totalSupply)},
tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}},
}

View File

@ -43,7 +43,10 @@ func RandomizedGenState(simState *module.SimulationState) {
func(r *rand.Rand) { sendEnabled = GenSendEnabled(r) },
)
bankGenesis := types.NewGenesisState(sendEnabled, RandomGenesisBalances(simState))
numAccs := int64(len(simState.Accounts))
totalSupply := sdk.NewInt(simState.InitialStake * (numAccs + simState.NumBonded))
supply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, totalSupply))
bankGenesis := types.NewGenesisState(sendEnabled, RandomGenesisBalances(simState), supply)
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(bankGenesis)
}

View File

@ -4,6 +4,8 @@ order: 1
# State
Presently, the bank module has no inherent state — it simply reads and writes accounts using the `AccountKeeper` from the `auth` module.
The `x/bank` module keeps state of two primary objects, account balances and the
total supply of all balances.
This implementation choice is intended to minimize necessary state reads/writes, since we expect most transactions to involve coin amounts (for fees), so storing coin data in the account saves reading it separately.
- Balances: `[]byte("balances") | []byte(address) / []byte(balance.Denom) -> ProtocolBuffer(balance)`
- Supply: `0x0 -> ProtocolBuffer(Supply)`

View File

@ -5,7 +5,7 @@ parent:
title: "bank"
-->
# `bank`
# `x/bank`
## Abstract
@ -17,8 +17,76 @@ with particular kinds of accounts (notably delegating/undelegating for vesting
accounts). It exposes several interfaces with varying capabilities for secure
interaction with other modules which must alter user balances.
In addition, the bank module tracks and provides query support for the total
supply of all assets used in the application.
This module will be used in the Cosmos Hub.
## Supply
The `supply` module:
- passively tracks the total supply of coins within a chain,
- provides a pattern for modules to hold/interact with `Coins`, and
- introduces the invariant check to verify a chain's total supply.
### Total Supply
The total `Supply` of the network is equal to the sum of all coins from the
account. The total supply is updated every time a `Coin` is minted (eg: as part
of the inflation mechanism) or burned (eg: due to slashing or if a governance
proposal is vetoed).
## Module Accounts
The supply module introduces a new type of `auth.Account` which can be used by
modules to allocate tokens and in special cases mint or burn tokens. At a base
level these module accounts are capable of sending/receiving tokens to and from
`auth.Account`s and other module accounts. This design replaces previous
alternative designs where, to hold tokens, modules would burn the incoming
tokens from the sender account, and then track those tokens internally. Later,
in order to send tokens, the module would need to effectively mint tokens
within a destination account. The new design removes duplicate logic between
modules to perform this accounting.
The `ModuleAccount` interface is defined as follows:
```go
type ModuleAccount interface {
auth.Account // same methods as the Account interface
GetName() string // name of the module; used to obtain the address
GetPermissions() []string // permissions of module account
HasPermission(string) bool
}
```
> **WARNING!**
Any module or message handler that allows either direct or indirect sending of funds must explicitly guarantee those funds cannot be sent to module accounts (unless allowed).
The supply `Keeper` also introduces new wrapper functions for the auth `Keeper`
and the bank `Keeper` that are related to `ModuleAccount`s in order to be able
to:
- Get and set `ModuleAccount`s by providing the `Name`.
- Send coins from and to other `ModuleAccount`s or standard `Account`s
(`BaseAccount` or `VestingAccount`) by passing only the `Name`.
- `Mint` or `Burn` coins for a `ModuleAccount` (restricted to its permissions).
### Permissions
Each `ModuleAccount` has a different set of permissions that provide different
object capabilities to perform certain actions. Permissions need to be
registered upon the creation of the supply `Keeper` so that every time a
`ModuleAccount` calls the allowed functions, the `Keeper` can lookup the
permissions to that specific account and perform or not the action.
The available permissions are:
- `Minter`: allows for a module to mint a specific amount of coins.
- `Burner`: allows for a module to burn a specific amount of coins.
- `Staking`: allows for a module to delegate and undelegate a specific amount of coins.
## Contents
1. **[State](01_state.md)**

View File

@ -6,14 +6,13 @@ import (
"fmt"
"strings"
yaml "gopkg.in/yaml.v2"
"github.com/tendermint/tendermint/crypto"
yaml "gopkg.in/yaml.v2"
sdk "github.com/cosmos/cosmos-sdk/types"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/supply/exported"
"github.com/cosmos/cosmos-sdk/x/bank/exported"
)
var (

View File

@ -2,10 +2,28 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/bank/exported"
)
// Register concrete types on codec codec
// Codec defines the interface needed to serialize x/bank state. It must
// be aware of all concrete supply types.
type Codec interface {
codec.Marshaler
MarshalSupply(supply exported.SupplyI) ([]byte, error)
UnmarshalSupply(bz []byte) (exported.SupplyI, error)
MarshalSupplyJSON(supply exported.SupplyI) ([]byte, error)
UnmarshalSupplyJSON(bz []byte) (exported.SupplyI, error)
}
// RegisterCodec registers the necessary x/bank interfaces and concrete types
// on the provided Amino codec. These types are used for Amino JSON serialization.
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterInterface((*exported.ModuleAccountI)(nil), nil)
cdc.RegisterInterface((*exported.SupplyI)(nil), nil)
cdc.RegisterConcrete(&ModuleAccount{}, "cosmos-sdk/ModuleAccount", nil)
cdc.RegisterConcrete(&Supply{}, "cosmos-sdk/Supply", nil)
cdc.RegisterConcrete(MsgSend{}, "cosmos-sdk/MsgSend", nil)
cdc.RegisterConcrete(MsgMultiSend{}, "cosmos-sdk/MsgMultiSend", nil)
}
@ -24,5 +42,6 @@ var (
func init() {
RegisterCodec(amino)
codec.RegisterCrypto(amino)
amino.Seal()
}

View File

@ -8,6 +8,7 @@ import (
// AccountKeeper defines the account contract that must be fulfilled when
// creating a x/bank keeper.
type AccountKeeper interface {
NewAccount(sdk.Context, exported.Account) exported.Account
NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) exported.Account
GetAccount(ctx sdk.Context, addr sdk.AccAddress) exported.Account

View File

@ -16,6 +16,7 @@ var _ exported.GenesisBalance = (*Balance)(nil)
type GenesisState struct {
SendEnabled bool `json:"send_enabled" yaml:"send_enabled"`
Balances []Balance `json:"balances" yaml:"balances"`
Supply sdk.Coins `json:"supply" yaml:"supply"`
}
// Balance defines an account address and balance pair used in the bank module's
@ -49,16 +50,18 @@ func SanitizeGenesisBalances(balances []Balance) []Balance {
}
// NewGenesisState creates a new genesis state.
func NewGenesisState(sendEnabled bool, balances []Balance) GenesisState {
return GenesisState{SendEnabled: sendEnabled, Balances: balances}
func NewGenesisState(sendEnabled bool, balances []Balance, supply sdk.Coins) GenesisState {
return GenesisState{
SendEnabled: sendEnabled,
Balances: balances,
Supply: supply,
}
}
// DefaultGenesisState returns a default bank module genesis state.
func DefaultGenesisState() GenesisState { return NewGenesisState(true, []Balance{}) }
// ValidateGenesis performs basic validation of bank genesis data returning an
// error for any failed validation criteria.
func ValidateGenesis(data GenesisState) error { return nil }
func DefaultGenesisState() GenesisState {
return NewGenesisState(true, []Balance{}, DefaultSupply().GetTotal())
}
// GetGenesisStateFromAppState returns x/bank GenesisState given raw application
// genesis state.

View File

@ -20,9 +20,10 @@ const (
QuerierRoute = ModuleName
)
// KVStore key prefixes
// KVStore keys
var (
BalancesPrefix = []byte("balances")
SupplyKey = []byte{0x00}
)
// AddressFromBalancesStore returns an account address from a balances prefix

View File

@ -8,6 +8,8 @@ import (
const (
QueryBalance = "balance"
QueryAllBalances = "all_balances"
QueryTotalSupply = "total_supply"
QuerySupplyOf = "supply_of"
)
// QueryBalanceParams defines the params for querying an account balance.
@ -30,3 +32,28 @@ type QueryAllBalancesParams struct {
func NewQueryAllBalancesParams(addr sdk.AccAddress) QueryAllBalancesParams {
return QueryAllBalancesParams{Address: addr}
}
// QueryTotalSupply defines the params for the following queries:
//
// - 'custom/bank/totalSupply'
type QueryTotalSupplyParams struct {
Page, Limit int
}
// NewQueryTotalSupplyParams creates a new instance to query the total supply
func NewQueryTotalSupplyParams(page, limit int) QueryTotalSupplyParams {
return QueryTotalSupplyParams{page, limit}
}
// QuerySupplyOfParams defines the params for the following queries:
//
// - 'custom/bank/totalSupplyOf'
type QuerySupplyOfParams struct {
Denom string
}
// NewQuerySupplyOfParams creates a new instance to query the total supply
// of a given denomination
func NewQuerySupplyOfParams(denom string) QuerySupplyOfParams {
return QuerySupplyOfParams{denom}
}

View File

@ -6,7 +6,7 @@ import (
yaml "gopkg.in/yaml.v2"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/supply/exported"
"github.com/cosmos/cosmos-sdk/x/bank/exported"
)
// Implements Delegation interface

View File

@ -4,11 +4,10 @@ import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
yaml "gopkg.in/yaml.v2"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)
func TestSupplyMarshalYAML(t *testing.T) {

View File

@ -8,6 +8,7 @@ import (
fmt "fmt"
github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types"
types "github.com/cosmos/cosmos-sdk/types"
types1 "github.com/cosmos/cosmos-sdk/x/auth/types"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
io "io"
@ -246,43 +247,131 @@ func (m *MsgMultiSend) GetOutputs() []Output {
return nil
}
// ModuleAccount defines an account for modules that holds coins on a pool
type ModuleAccount struct {
*types1.BaseAccount `protobuf:"bytes,1,opt,name=base_account,json=baseAccount,proto3,embedded=base_account" json:"base_account,omitempty" yaml:"base_account"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Permissions []string `protobuf:"bytes,3,rep,name=permissions,proto3" json:"permissions,omitempty"`
}
func (m *ModuleAccount) Reset() { *m = ModuleAccount{} }
func (*ModuleAccount) ProtoMessage() {}
func (*ModuleAccount) Descriptor() ([]byte, []int) {
return fileDescriptor_934ff6b24d3432e2, []int{4}
}
func (m *ModuleAccount) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *ModuleAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_ModuleAccount.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *ModuleAccount) XXX_Merge(src proto.Message) {
xxx_messageInfo_ModuleAccount.Merge(m, src)
}
func (m *ModuleAccount) XXX_Size() int {
return m.Size()
}
func (m *ModuleAccount) XXX_DiscardUnknown() {
xxx_messageInfo_ModuleAccount.DiscardUnknown(m)
}
var xxx_messageInfo_ModuleAccount proto.InternalMessageInfo
// Supply represents a struct that passively keeps track of the total supply
// amounts in the network.
type Supply struct {
Total github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=total,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"total"`
}
func (m *Supply) Reset() { *m = Supply{} }
func (*Supply) ProtoMessage() {}
func (*Supply) Descriptor() ([]byte, []int) {
return fileDescriptor_934ff6b24d3432e2, []int{5}
}
func (m *Supply) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *Supply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_Supply.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *Supply) XXX_Merge(src proto.Message) {
xxx_messageInfo_Supply.Merge(m, src)
}
func (m *Supply) XXX_Size() int {
return m.Size()
}
func (m *Supply) XXX_DiscardUnknown() {
xxx_messageInfo_Supply.DiscardUnknown(m)
}
var xxx_messageInfo_Supply proto.InternalMessageInfo
func init() {
proto.RegisterType((*MsgSend)(nil), "cosmos_sdk.x.bank.v1.MsgSend")
proto.RegisterType((*Input)(nil), "cosmos_sdk.x.bank.v1.Input")
proto.RegisterType((*Output)(nil), "cosmos_sdk.x.bank.v1.Output")
proto.RegisterType((*MsgMultiSend)(nil), "cosmos_sdk.x.bank.v1.MsgMultiSend")
proto.RegisterType((*ModuleAccount)(nil), "cosmos_sdk.x.bank.v1.ModuleAccount")
proto.RegisterType((*Supply)(nil), "cosmos_sdk.x.bank.v1.Supply")
}
func init() { proto.RegisterFile("x/bank/types/types.proto", fileDescriptor_934ff6b24d3432e2) }
var fileDescriptor_934ff6b24d3432e2 = []byte{
// 413 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xa8, 0xd0, 0x4f, 0x4a,
0xcc, 0xcb, 0xd6, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9,
0x42, 0x22, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, 0x20,
0x45, 0x7a, 0x65, 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25,
0x95, 0xfa, 0x60, 0x85, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0x44, 0xb7, 0x94, 0x20, 0x86,
0x81, 0x4a, 0x87, 0x98, 0xb8, 0xd8, 0x7d, 0x8b, 0xd3, 0x83, 0x53, 0xf3, 0x52, 0x84, 0xb2, 0xb9,
0x78, 0xd2, 0x8a, 0xf2, 0x73, 0xe3, 0x13, 0x53, 0x52, 0x8a, 0x52, 0x8b, 0x8b, 0x25, 0x18, 0x15,
0x18, 0x35, 0x78, 0x9c, 0x3c, 0x3e, 0xdd, 0x93, 0x17, 0xae, 0x4c, 0xcc, 0xcd, 0xb1, 0x52, 0x42,
0x96, 0x55, 0xfa, 0x75, 0x4f, 0x5e, 0x37, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f,
0x57, 0x1f, 0xe2, 0x30, 0x28, 0xa5, 0x5b, 0x9c, 0x02, 0x75, 0xbd, 0x9e, 0x63, 0x72, 0xb2, 0x23,
0x44, 0x47, 0x10, 0x37, 0x48, 0x3f, 0x94, 0x23, 0x94, 0xca, 0xc5, 0x55, 0x92, 0x0f, 0xb7, 0x8a,
0x09, 0x6c, 0x95, 0xdb, 0xa7, 0x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0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3,
0xb1, 0x1c, 0x43, 0x94, 0x26, 0x5e, 0x0f, 0x22, 0xe7, 0xf5, 0x24, 0x36, 0x70, 0xae, 0x34, 0x06,
0x04, 0x00, 0x00, 0xff, 0xff, 0x57, 0x42, 0x17, 0x1f, 0x02, 0x04, 0x00, 0x00,
// 549 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x54, 0xbf, 0x6f, 0xd3, 0x4c,
0x18, 0xf6, 0xa5, 0x69, 0xf2, 0xe5, 0x92, 0x6f, 0xe8, 0x95, 0x21, 0x4a, 0x91, 0x1d, 0x3c, 0xa0,
0x30, 0xf4, 0x4c, 0xca, 0x44, 0xc4, 0x12, 0x57, 0x42, 0x20, 0x14, 0x21, 0xb9, 0x1b, 0x08, 0x45,
0x17, 0xdb, 0x24, 0x56, 0x62, 0x9f, 0xe5, 0x3b, 0x57, 0xc9, 0x7f, 0xc0, 0x82, 0xc4, 0xc8, 0x98,
0x99, 0x91, 0x05, 0x66, 0xa6, 0x8e, 0x19, 0x99, 0x0c, 0x4a, 0x16, 0xe6, 0x8e, 0x4c, 0xe8, 0xce,
0x36, 0x71, 0xd5, 0x0a, 0x01, 0xea, 0xc2, 0x62, 0xdf, 0xf9, 0xee, 0xf9, 0xe1, 0xe7, 0xbd, 0xf7,
0x60, 0x73, 0x6e, 0x8c, 0x48, 0x30, 0x35, 0xf8, 0x22, 0x74, 0x59, 0xfa, 0xc4, 0x61, 0x44, 0x39,
0x45, 0x37, 0x6c, 0xca, 0x7c, 0xca, 0x86, 0xcc, 0x99, 0xe2, 0x39, 0x16, 0x9b, 0xf0, 0x69, 0xb7,
0x75, 0x9b, 0x4f, 0xbc, 0xc8, 0x19, 0x86, 0x24, 0xe2, 0x0b, 0x43, 0x6e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xb5, 0x0a, 0xbe, 0xae, 0x55,
0xf0, 0x66, 0xa3, 0x2a, 0xab, 0x8d, 0xaa, 0x7c, 0xde, 0xa8, 0xca, 0xb3, 0x3b, 0xbf, 0x24, 0x2e,
0xde, 0x97, 0xa3, 0x8a, 0xbc, 0xbf, 0xee, 0xfd, 0x08, 0x00, 0x00, 0xff, 0xff, 0x55, 0x55, 0x67,
0x85, 0x46, 0x05, 0x00, 0x00,
}
func (this *MsgSend) Equal(that interface{}) bool {
@ -421,6 +510,35 @@ func (this *MsgMultiSend) Equal(that interface{}) bool {
}
return true
}
func (this *Supply) Equal(that interface{}) bool {
if that == nil {
return this == nil
}
that1, ok := that.(*Supply)
if !ok {
that2, ok := that.(Supply)
if ok {
that1 = &that2
} else {
return false
}
}
if that1 == nil {
return this == nil
} else if this == nil {
return false
}
if len(this.Total) != len(that1.Total) {
return false
}
for i := range this.Total {
if !this.Total[i].Equal(&that1.Total[i]) {
return false
}
}
return true
}
func (m *MsgSend) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
@ -611,6 +729,94 @@ func (m *MsgMultiSend) MarshalToSizedBuffer(dAtA []byte) (int, error) {
return len(dAtA) - i, nil
}
func (m *ModuleAccount) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *ModuleAccount) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *ModuleAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if len(m.Permissions) > 0 {
for iNdEx := len(m.Permissions) - 1; iNdEx >= 0; iNdEx-- {
i -= len(m.Permissions[iNdEx])
copy(dAtA[i:], m.Permissions[iNdEx])
i = encodeVarintTypes(dAtA, i, uint64(len(m.Permissions[iNdEx])))
i--
dAtA[i] = 0x1a
}
}
if len(m.Name) > 0 {
i -= len(m.Name)
copy(dAtA[i:], m.Name)
i = encodeVarintTypes(dAtA, i, uint64(len(m.Name)))
i--
dAtA[i] = 0x12
}
if m.BaseAccount != nil {
{
size, err := m.BaseAccount.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintTypes(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func (m *Supply) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *Supply) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Supply) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if len(m.Total) > 0 {
for iNdEx := len(m.Total) - 1; iNdEx >= 0; iNdEx-- {
{
size, err := m.Total[iNdEx].MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintTypes(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0xa
}
}
return len(dAtA) - i, nil
}
func encodeVarintTypes(dAtA []byte, offset int, v uint64) int {
offset -= sovTypes(v)
base := offset
@ -704,6 +910,44 @@ func (m *MsgMultiSend) Size() (n int) {
return n
}
func (m *ModuleAccount) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.BaseAccount != nil {
l = m.BaseAccount.Size()
n += 1 + l + sovTypes(uint64(l))
}
l = len(m.Name)
if l > 0 {
n += 1 + l + sovTypes(uint64(l))
}
if len(m.Permissions) > 0 {
for _, s := range m.Permissions {
l = len(s)
n += 1 + l + sovTypes(uint64(l))
}
}
return n
}
func (m *Supply) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if len(m.Total) > 0 {
for _, e := range m.Total {
l = e.Size()
n += 1 + l + sovTypes(uint64(l))
}
}
return n
}
func sovTypes(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
@ -1228,6 +1472,246 @@ func (m *MsgMultiSend) Unmarshal(dAtA []byte) error {
}
return nil
}
func (m *ModuleAccount) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTypes
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: ModuleAccount: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: ModuleAccount: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field BaseAccount", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTypes
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthTypes
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthTypes
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.BaseAccount == nil {
m.BaseAccount = &types1.BaseAccount{}
}
if err := m.BaseAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTypes
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthTypes
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthTypes
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Name = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Permissions", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTypes
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthTypes
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthTypes
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Permissions = append(m.Permissions, string(dAtA[iNdEx:postIndex]))
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipTypes(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthTypes
}
if (iNdEx + skippy) < 0 {
return ErrInvalidLengthTypes
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *Supply) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTypes
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: Supply: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: Supply: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Total", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTypes
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthTypes
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthTypes
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Total = append(m.Total, types.Coin{})
if err := m.Total[len(m.Total)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipTypes(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthTypes
}
if (iNdEx + skippy) < 0 {
return ErrInvalidLengthTypes
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipTypes(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0

View File

@ -1,11 +1,11 @@
syntax = "proto3";
package cosmos_sdk.x.bank.v1;
option go_package = "github.com/cosmos/cosmos-sdk/x/bank/types";
import "third_party/proto/gogoproto/gogo.proto";
import "types/types.proto";
import "x/auth/types/types.proto";
option go_package = "github.com/cosmos/cosmos-sdk/x/bank/types";
// MsgSend - high level transaction of the coin module
message MsgSend {
@ -19,32 +19,26 @@ message MsgSend {
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
(gogoproto.moretags) = "yaml:\"to_address\""
];
repeated cosmos_sdk.v1.Coin amount = 3 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
repeated cosmos_sdk.v1.Coin amount = 3
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
}
// Input models transaction input
message Input {
option (gogoproto.equal) = true;
bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
repeated cosmos_sdk.v1.Coin coins = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
repeated cosmos_sdk.v1.Coin coins = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
}
// Output models transaction outputs
message Output {
option (gogoproto.equal) = true;
bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
repeated cosmos_sdk.v1.Coin coins = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
repeated cosmos_sdk.v1.Coin coins = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
}
// MsgMultiSend - high level transaction of the coin module
@ -54,3 +48,25 @@ message MsgMultiSend {
repeated Input inputs = 1 [(gogoproto.nullable) = false];
repeated Output outputs = 2 [(gogoproto.nullable) = false];
}
// ModuleAccount defines an account for modules that holds coins on a pool
message ModuleAccount {
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
cosmos_sdk.x.auth.v1.BaseAccount base_account = 1
[(gogoproto.embed) = true, (gogoproto.moretags) = "yaml:\"base_account\""];
string name = 2;
repeated string permissions = 3;
}
// Supply represents a struct that passively keeps track of the total supply
// amounts in the network.
message Supply {
option (gogoproto.equal) = true;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
repeated cosmos_sdk.v1.Coin total = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
}

View File

@ -11,10 +11,10 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/crisis"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"
)
var (
@ -38,7 +38,7 @@ func createTestApp() (*simapp.SimApp, sdk.Context, []sdk.AccAddress) {
feePool := distr.InitialFeePool()
feePool.CommunityPool = sdk.NewDecCoinsFromCoins(sdk.NewCoins(constantFee)...)
app.DistrKeeper.SetFeePool(ctx, feePool)
app.SupplyKeeper.SetSupply(ctx, supply.NewSupply(sdk.Coins{}))
app.BankKeeper.SetSupply(ctx, bank.NewSupply(sdk.Coins{}))
addrs := simapp.AddTestAddrs(app, ctx, 1, sdk.NewInt(10000))

View File

@ -8,7 +8,7 @@ import (
)
// InitGenesis sets distribution information for genesis
func InitGenesis(ctx sdk.Context, bk types.BankKeeper, supplyKeeper types.SupplyKeeper, keeper Keeper, data types.GenesisState) {
func InitGenesis(ctx sdk.Context, bk types.BankKeeper, keeper Keeper, data types.GenesisState) {
var moduleHoldings sdk.DecCoins
keeper.SetFeePool(ctx, data.FeePool)
@ -52,7 +52,7 @@ func InitGenesis(ctx sdk.Context, bk types.BankKeeper, supplyKeeper types.Supply
panic(err)
}
supplyKeeper.SetModuleAccount(ctx, moduleAcc)
bk.SetModuleAccount(ctx, moduleAcc)
}
}

View File

@ -2,8 +2,8 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/exported"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/supply/exported"
)
// get outstanding rewards
@ -18,5 +18,5 @@ func (k Keeper) GetFeePoolCommunityCoins(ctx sdk.Context) sdk.DecCoins {
// GetDistributionAccount returns the distribution ModuleAccount
func (k Keeper) GetDistributionAccount(ctx sdk.Context) exported.ModuleAccountI {
return k.supplyKeeper.GetModuleAccount(ctx, types.ModuleName)
return k.bankKeeper.GetModuleAccount(ctx, types.ModuleName)
}

View File

@ -21,12 +21,12 @@ func (k Keeper) AllocateTokens(
// fetch and clear the collected fees for distribution, since this is
// called in BeginBlock, collected fees will be from the previous block
// (and distributed to the previous proposer)
feeCollector := k.supplyKeeper.GetModuleAccount(ctx, k.feeCollectorName)
feeCollector := k.bankKeeper.GetModuleAccount(ctx, k.feeCollectorName)
feesCollectedInt := k.bankKeeper.GetAllBalances(ctx, feeCollector.GetAddress())
feesCollected := sdk.NewDecCoinsFromCoins(feesCollectedInt...)
// transfer collected fees to the distribution module account
err := k.supplyKeeper.SendCoinsFromModuleToModule(ctx, k.feeCollectorName, types.ModuleName, feesCollectedInt)
err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, k.feeCollectorName, types.ModuleName, feesCollectedInt)
if err != nil {
panic(err)
}

View File

@ -97,7 +97,7 @@ func TestAllocateTokensToManyValidators(t *testing.T) {
// allocate tokens as if both had voted and second was proposer
fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)))
feeCollector := app.SupplyKeeper.GetModuleAccount(ctx, types.FeeCollectorName)
feeCollector := app.BankKeeper.GetModuleAccount(ctx, types.FeeCollectorName)
require.NotNil(t, feeCollector)
err = app.BankKeeper.SetBalances(ctx, feeCollector.GetAddress(), fees)
@ -189,7 +189,7 @@ func TestAllocateTokensTruncation(t *testing.T) {
// allocate tokens as if both had voted and second was proposer
fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(634195840)))
feeCollector := app.SupplyKeeper.GetModuleAccount(ctx, types.FeeCollectorName)
feeCollector := app.BankKeeper.GetModuleAccount(ctx, types.FeeCollectorName)
require.NotNil(t, feeCollector)
err = app.BankKeeper.SetBalances(ctx, feeCollector.GetAddress(), fees)

View File

@ -3,8 +3,8 @@ package keeper_test
import (
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/supply"
)
var (
@ -17,5 +17,5 @@ var (
valConsAddr1 = sdk.ConsAddress(valConsPk1.Address())
valConsAddr2 = sdk.ConsAddress(valConsPk2.Address())
distrAcc = supply.NewEmptyModuleAccount(types.ModuleName)
distrAcc = bank.NewEmptyModuleAccount(types.ModuleName)
)

View File

@ -163,7 +163,7 @@ func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val exported.Validato
// add coins to user account
if !coins.IsZero() {
withdrawAddr := k.GetDelegatorWithdrawAddr(ctx, del.GetDelegatorAddr())
err := k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, withdrawAddr, coins)
err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, withdrawAddr, coins)
if err != nil {
return nil, err
}

View File

@ -312,7 +312,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) {
// set module account coins
distrAcc := app.DistrKeeper.GetDistributionAccount(ctx)
require.NoError(t, app.BankKeeper.SetBalances(ctx, distrAcc.GetAddress(), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, balanceTokens))))
app.SupplyKeeper.SetModuleAccount(ctx, distrAcc)
app.BankKeeper.SetModuleAccount(ctx, distrAcc)
// create validator with 50% commission
power := int64(100)
@ -555,7 +555,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) {
distrAcc := app.DistrKeeper.GetDistributionAccount(ctx)
err := app.BankKeeper.SetBalances(ctx, distrAcc.GetAddress(), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000))))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, distrAcc)
app.BankKeeper.SetModuleAccount(ctx, distrAcc)
tokens := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.NewDec(initial))}

View File

@ -20,7 +20,7 @@ func (k Keeper) DistributeFromFeePool(ctx sdk.Context, amount sdk.Coins, receive
feePool.CommunityPool = newPool
err := k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiveAddr, amount)
err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiveAddr, amount)
if err != nil {
return err
}

View File

@ -46,7 +46,7 @@ func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, _ sdk.ConsAddress, valAddr
accAddr := sdk.AccAddress(valAddr)
withdrawAddr := h.k.GetDelegatorWithdrawAddr(ctx, accAddr)
err := h.k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, withdrawAddr, coins)
err := h.k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, withdrawAddr, coins)
if err != nil {
panic(err)
}

View File

@ -19,7 +19,6 @@ type Keeper struct {
paramSpace paramtypes.Subspace
bankKeeper types.BankKeeper
stakingKeeper types.StakingKeeper
supplyKeeper types.SupplyKeeper
blacklistedAddrs map[string]bool
@ -29,12 +28,11 @@ type Keeper struct {
// NewKeeper creates a new distribution Keeper instance
func NewKeeper(
cdc codec.Marshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace, bk types.BankKeeper,
sk types.StakingKeeper, supplyKeeper types.SupplyKeeper, feeCollectorName string,
blacklistedAddrs map[string]bool,
sk types.StakingKeeper, feeCollectorName string, blacklistedAddrs map[string]bool,
) Keeper {
// ensure distribution module account is set
if addr := supplyKeeper.GetModuleAddress(types.ModuleName); addr == nil {
if addr := bk.GetModuleAddress(types.ModuleName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}
@ -49,7 +47,6 @@ func NewKeeper(
paramSpace: paramSpace,
bankKeeper: bk,
stakingKeeper: sk,
supplyKeeper: supplyKeeper,
feeCollectorName: feeCollectorName,
blacklistedAddrs: blacklistedAddrs,
}
@ -130,7 +127,7 @@ func (k Keeper) WithdrawValidatorCommission(ctx sdk.Context, valAddr sdk.ValAddr
if !commission.IsZero() {
accAddr := sdk.AccAddress(valAddr)
withdrawAddr := k.GetDelegatorWithdrawAddr(ctx, accAddr)
err := k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, withdrawAddr, commission)
err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, withdrawAddr, commission)
if err != nil {
return nil, err
}
@ -163,7 +160,7 @@ func (k Keeper) GetTotalRewards(ctx sdk.Context) (totalRewards sdk.DecCoins) {
// added to the pool. An error is returned if the amount cannot be sent to the
// module account.
func (k Keeper) FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error {
if err := k.supplyKeeper.SendCoinsFromAccountToModule(ctx, sender, types.ModuleName, amount); err != nil {
if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, types.ModuleName, amount); err != nil {
return err
}

View File

@ -54,7 +54,7 @@ func TestWithdrawValidatorCommission(t *testing.T) {
sdk.NewCoin("stake", sdk.NewInt(2)),
))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, distrAcc)
app.BankKeeper.SetModuleAccount(ctx, distrAcc)
// check initial balance
balance := app.BankKeeper.GetAllBalances(ctx, sdk.AccAddress(valAddrs[0]))

View File

@ -10,10 +10,10 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/distribution/keeper"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"
)
const custom = "custom"
@ -111,7 +111,7 @@ func getQueriedCommunityPool(t *testing.T, ctx sdk.Context, cdc *codec.Codec, qu
func TestQueries(t *testing.T) {
cdc := codec.New()
types.RegisterCodec(cdc)
supply.RegisterCodec(cdc)
bank.RegisterCodec(cdc)
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, abci.Header{})

View File

@ -81,20 +81,18 @@ type AppModule struct {
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
stakingKeeper stakingkeeper.Keeper
supplyKeeper types.SupplyKeeper
}
// NewAppModule creates a new AppModule object
func NewAppModule(
keeper Keeper, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper,
supplyKeeper types.SupplyKeeper, stakingKeeper stakingkeeper.Keeper,
stakingKeeper stakingkeeper.Keeper,
) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
keeper: keeper,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
supplyKeeper: supplyKeeper,
stakingKeeper: stakingKeeper,
}
}
@ -134,7 +132,7 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
InitGenesis(ctx, am.bankKeeper, am.supplyKeeper, am.keeper, genesisState)
InitGenesis(ctx, am.bankKeeper, am.keeper, genesisState)
return []abci.ValidatorUpdate{}
}

View File

@ -3,13 +3,12 @@ package distribution_test
import (
"testing"
"github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/distribution"
)
func TestItCreatesModuleAccountOnInitBlock(t *testing.T) {
@ -23,6 +22,6 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) {
},
)
acc := app.AccountKeeper.GetAccount(ctx, supply.NewModuleAddress(distribution.ModuleName))
acc := app.AccountKeeper.GetAccount(ctx, bank.NewModuleAddress(distribution.ModuleName))
require.NotNil(t, acc)
}

View File

@ -3,17 +3,13 @@ package distribution_test
import (
"testing"
"github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)
@ -40,7 +36,7 @@ func TestProposalHandlerPassed(t *testing.T) {
err := app.BankKeeper.SetBalances(ctx, macc.GetAddress(), balances.Add(amount...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, macc)
app.BankKeeper.SetModuleAccount(ctx, macc)
account := app.AccountKeeper.NewAccountWithAddress(ctx, recipient)
app.AccountKeeper.SetAccount(ctx, account)

View File

@ -3,9 +3,9 @@ package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported"
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
)
// AccountKeeper defines the expected account keeper used for simulations (noalias)
@ -20,6 +20,16 @@ type BankKeeper interface {
SetBalances(ctx sdk.Context, addr sdk.AccAddress, balances sdk.Coins) error
LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetModuleAddress(name string) sdk.AccAddress
GetModuleAccount(ctx sdk.Context, name string) bankexported.ModuleAccountI
// TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862
SetModuleAccount(sdk.Context, bankexported.ModuleAccountI)
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule string, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
}
// StakingKeeper expected staking keeper (noalias)
@ -70,16 +80,3 @@ type StakingHooks interface {
AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress)
BeforeValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress, fraction sdk.Dec)
}
// SupplyKeeper defines the expected supply Keeper (noalias)
type SupplyKeeper interface {
GetModuleAddress(name string) sdk.AccAddress
GetModuleAccount(ctx sdk.Context, name string) supplyexported.ModuleAccountI
// TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862
SetModuleAccount(sdk.Context, supplyexported.ModuleAccountI)
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule string, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
}

View File

@ -10,11 +10,11 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/evidence"
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
"github.com/cosmos/cosmos-sdk/x/evidence/keeper"
"github.com/cosmos/cosmos-sdk/x/evidence/types"
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
@ -125,7 +125,7 @@ func (suite *KeeperTestSuite) populateValidators(ctx sdk.Context) {
// add accounts and set total supply
totalSupplyAmt := initAmt.MulRaw(int64(len(valAddresses)))
totalSupply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, totalSupplyAmt))
suite.app.SupplyKeeper.SetSupply(ctx, supply.NewSupply(totalSupply))
suite.app.BankKeeper.SetSupply(ctx, bank.NewSupply(totalSupply))
for _, addr := range valAddresses {
_, err := suite.app.BankKeeper.AddCoins(ctx, sdk.AccAddress(addr), initCoins)

View File

@ -4,6 +4,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_34"
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_36"
v036bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v0_36"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_34"
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_36"
v034genAccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v0_34"
@ -13,7 +14,6 @@ import (
v036gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v0_36"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_36"
v036supply "github.com/cosmos/cosmos-sdk/x/supply/legacy/v0_36"
)
// Migrate migrates exported state from v0.34 to a v0.36 genesis state.
@ -90,7 +90,7 @@ func Migrate(appState genutil.AppMap) genutil.AppMap {
}
// migrate supply state
appState[v036supply.ModuleName] = v036Codec.MustMarshalJSON(v036supply.EmptyGenesisState())
appState[v036bank.ModuleName] = v036Codec.MustMarshalJSON(v036bank.EmptyGenesisState())
return appState
}

View File

@ -8,7 +8,7 @@ import (
)
// InitGenesis - store genesis parameters
func InitGenesis(ctx sdk.Context, bk types.BankKeeper, supplyKeeper types.SupplyKeeper, k Keeper, data GenesisState) {
func InitGenesis(ctx sdk.Context, bk types.BankKeeper, k Keeper, data GenesisState) {
k.SetProposalID(ctx, data.StartingProposalID)
k.SetDepositParams(ctx, data.DepositParams)
k.SetVotingParams(ctx, data.VotingParams)
@ -45,7 +45,8 @@ func InitGenesis(ctx sdk.Context, bk types.BankKeeper, supplyKeeper types.Supply
if err := bk.SetBalances(ctx, moduleAcc.GetAddress(), totalDeposits); err != nil {
panic(err)
}
supplyKeeper.SetModuleAccount(ctx, moduleAcc)
bk.SetModuleAccount(ctx, moduleAcc)
}
}

View File

@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/gov"
)
@ -48,12 +49,14 @@ func TestImportExportQueues(t *testing.T) {
require.True(t, proposal2.Status == gov.StatusVotingPeriod)
authGenState := auth.ExportGenesis(ctx, app.AccountKeeper)
bankGenState := bank.ExportGenesis(ctx, app.BankKeeper)
// export the state and import it into a new app
govGenState := gov.ExportGenesis(ctx, app.GovKeeper)
genesisState := simapp.NewDefaultGenesisState()
genesisState[auth.ModuleName] = app.Codec().MustMarshalJSON(authGenState)
genesisState[bank.ModuleName] = app.Codec().MustMarshalJSON(bankGenState)
genesisState[gov.ModuleName] = app.Codec().MustMarshalJSON(govGenState)
stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState)

View File

@ -22,7 +22,6 @@ func createValidators(ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sd
appCodec,
app.GetKey(staking.StoreKey),
app.BankKeeper,
app.SupplyKeeper,
app.GetSubspace(staking.ModuleName),
)

View File

@ -50,7 +50,7 @@ func (keeper Keeper) DeleteDeposits(ctx sdk.Context, proposalID uint64) {
store := ctx.KVStore(keeper.storeKey)
keeper.IterateDeposits(ctx, proposalID, func(deposit types.Deposit) bool {
err := keeper.supplyKeeper.BurnCoins(ctx, types.ModuleName, deposit.Amount)
err := keeper.bankKeeper.BurnCoins(ctx, types.ModuleName, deposit.Amount)
if err != nil {
panic(err)
}
@ -107,7 +107,7 @@ func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID uint64, depositorAdd
}
// update the governance module's account coins pool
err := keeper.supplyKeeper.SendCoinsFromAccountToModule(ctx, depositorAddr, types.ModuleName, depositAmount)
err := keeper.bankKeeper.SendCoinsFromAccountToModule(ctx, depositorAddr, types.ModuleName, depositAmount)
if err != nil {
return false, err
}
@ -148,7 +148,7 @@ func (keeper Keeper) RefundDeposits(ctx sdk.Context, proposalID uint64) {
store := ctx.KVStore(keeper.storeKey)
keeper.IterateDeposits(ctx, proposalID, func(deposit types.Deposit) bool {
err := keeper.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, deposit.Depositor, deposit.Amount)
err := keeper.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, deposit.Depositor, deposit.Amount)
if err != nil {
panic(err)
}

View File

@ -4,11 +4,11 @@ import (
"fmt"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/supply/exported"
"github.com/tendermint/tendermint/libs/log"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/exported"
"github.com/cosmos/cosmos-sdk/x/gov/types"
)
// Keeper defines the governance module Keeper
@ -16,8 +16,7 @@ type Keeper struct {
// The reference to the Paramstore to get and set gov specific params
paramSpace types.ParamSubspace
// The SupplyKeeper to reduce the supply of the network
supplyKeeper types.SupplyKeeper
bankKeeper types.BankKeeper
// The reference to the DelegationSet and ValidatorSet to get information about validators and delegators
sk types.StakingKeeper
@ -41,11 +40,11 @@ type Keeper struct {
// CONTRACT: the parameter Subspace must have the param key table already initialized
func NewKeeper(
cdc types.Codec, key sdk.StoreKey, paramSpace types.ParamSubspace,
supplyKeeper types.SupplyKeeper, sk types.StakingKeeper, rtr types.Router,
bankKeeper types.BankKeeper, sk types.StakingKeeper, rtr types.Router,
) Keeper {
// ensure governance module account is set
if addr := supplyKeeper.GetModuleAddress(types.ModuleName); addr == nil {
if addr := bankKeeper.GetModuleAddress(types.ModuleName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}
@ -55,12 +54,12 @@ func NewKeeper(
rtr.Seal()
return Keeper{
storeKey: key,
paramSpace: paramSpace,
supplyKeeper: supplyKeeper,
sk: sk,
cdc: cdc,
router: rtr,
storeKey: key,
paramSpace: paramSpace,
bankKeeper: bankKeeper,
sk: sk,
cdc: cdc,
router: rtr,
}
}
@ -76,7 +75,7 @@ func (keeper Keeper) Router() types.Router {
// GetGovernanceAccount returns the governance ModuleAccount
func (keeper Keeper) GetGovernanceAccount(ctx sdk.Context) exported.ModuleAccountI {
return keeper.supplyKeeper.GetModuleAccount(ctx, types.ModuleName)
return keeper.bankKeeper.GetModuleAccount(ctx, types.ModuleName)
}
// ProposalQueues

View File

@ -103,17 +103,15 @@ type AppModule struct {
keeper Keeper
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
supplyKeeper types.SupplyKeeper
}
// NewAppModule creates a new AppModule object
func NewAppModule(keeper Keeper, ak types.AccountKeeper, bk types.BankKeeper, sk types.SupplyKeeper) AppModule {
func NewAppModule(keeper Keeper, ak types.AccountKeeper, bk types.BankKeeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
keeper: keeper,
accountKeeper: ak,
bankKeeper: bk,
supplyKeeper: sk,
}
}
@ -152,7 +150,7 @@ func (am AppModule) NewQuerierHandler() sdk.Querier {
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
InitGenesis(ctx, am.bankKeeper, am.supplyKeeper, am.keeper, genesisState)
InitGenesis(ctx, am.bankKeeper, am.keeper, genesisState)
return []abci.ValidatorUpdate{}
}

View File

@ -3,14 +3,12 @@ package gov_test
import (
"testing"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/gov"
)
func TestItCreatesModuleAccountOnInitBlock(t *testing.T) {
@ -24,6 +22,6 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) {
},
)
acc := app.AccountKeeper.GetAccount(ctx, supply.NewModuleAddress(gov.ModuleName))
acc := app.AccountKeeper.GetAccount(ctx, bank.NewModuleAddress(gov.ModuleName))
require.NotNil(t, acc)
}

View File

@ -3,8 +3,8 @@ package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported"
stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported"
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
)
// ParamSubspace defines the expected Subspace interface for parameters (noalias)
@ -13,19 +13,6 @@ type ParamSubspace interface {
Set(ctx sdk.Context, key []byte, param interface{})
}
// SupplyKeeper defines the expected supply keeper for module accounts (noalias)
type SupplyKeeper interface {
GetModuleAddress(name string) sdk.AccAddress
GetModuleAccount(ctx sdk.Context, name string) supplyexported.ModuleAccountI
// TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862
SetModuleAccount(sdk.Context, supplyexported.ModuleAccountI)
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error
}
// StakingKeeper expected staking keeper (Validator and Delegator sets) (noalias)
type StakingKeeper interface {
// iterate through bonded validators by operator address, execute func for each validator
@ -52,4 +39,14 @@ type BankKeeper interface {
SetBalances(ctx sdk.Context, addr sdk.AccAddress, balances sdk.Coins) error
LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetModuleAddress(name string) sdk.AccAddress
GetModuleAccount(ctx sdk.Context, name string) bankexported.ModuleAccountI
// TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862
SetModuleAccount(sdk.Context, bankexported.ModuleAccountI)
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error
}

View File

@ -48,7 +48,6 @@ type (
ChannelKeeper = types.ChannelKeeper
ClientKeeper = types.ClientKeeper
ConnectionKeeper = types.ConnectionKeeper
SupplyKeeper = types.SupplyKeeper
FungibleTokenPacketData = types.FungibleTokenPacketData
FungibleTokenPacketAcknowledgement = types.FungibleTokenPacketAcknowledgement
MsgTransfer = types.MsgTransfer

View File

@ -12,6 +12,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
@ -22,7 +23,6 @@ import (
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"
)
// define constants used for testing
@ -111,7 +111,7 @@ func (suite *HandlerTestSuite) TestHandleMsgTransfer() {
suite.Require().Nil(res, "%+v", res) // incorrect denom prefix
msg = transfer.NewMsgTransfer(testPort1, testChannel1, 10, testPrefixedCoins1, testAddr1, testAddr2.String())
suite.chainA.App.SupplyKeeper.SetSupply(ctx, supply.NewSupply(testPrefixedCoins1))
suite.chainA.App.BankKeeper.SetSupply(ctx, bank.NewSupply(testPrefixedCoins1))
_ = suite.chainA.App.BankKeeper.SetBalances(ctx, testAddr1, testPrefixedCoins1)
res, err = handler(ctx, msg)

View File

@ -8,13 +8,13 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported"
"github.com/cosmos/cosmos-sdk/x/capability"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
porttypes "github.com/cosmos/cosmos-sdk/x/ibc/05-port/types"
"github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
)
// DefaultPacketTimeout is the default packet timeout relative to the current block height
@ -30,7 +30,6 @@ type Keeper struct {
channelKeeper types.ChannelKeeper
portKeeper types.PortKeeper
bankKeeper types.BankKeeper
supplyKeeper types.SupplyKeeper
scopedKeeper capability.ScopedKeeper
}
@ -38,12 +37,11 @@ type Keeper struct {
func NewKeeper(
cdc *codec.Codec, key sdk.StoreKey,
channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper,
bankKeeper types.BankKeeper, supplyKeeper types.SupplyKeeper,
scopedKeeper capability.ScopedKeeper,
bankKeeper types.BankKeeper, scopedKeeper capability.ScopedKeeper,
) Keeper {
// ensure ibc transfer module account is set
if addr := supplyKeeper.GetModuleAddress(types.GetModuleAccountName()); addr == nil {
if addr := bankKeeper.GetModuleAddress(types.GetModuleAccountName()); addr == nil {
panic("the IBC transfer module account has not been set")
}
@ -53,7 +51,6 @@ func NewKeeper(
channelKeeper: channelKeeper,
portKeeper: portKeeper,
bankKeeper: bankKeeper,
supplyKeeper: supplyKeeper,
scopedKeeper: scopedKeeper,
}
}
@ -64,8 +61,8 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
}
// GetTransferAccount returns the ICS20 - transfers ModuleAccount
func (k Keeper) GetTransferAccount(ctx sdk.Context) supplyexported.ModuleAccountI {
return k.supplyKeeper.GetModuleAccount(ctx, types.GetModuleAccountName())
func (k Keeper) GetTransferAccount(ctx sdk.Context) bankexported.ModuleAccountI {
return k.bankKeeper.GetModuleAccount(ctx, types.GetModuleAccountName())
}
// PacketExecuted defines a wrapper function for the channel Keeper's function

View File

@ -106,14 +106,14 @@ func (k Keeper) createOutgoingPacket(
}
// transfer the coins to the module account and burn them
if err := k.supplyKeeper.SendCoinsFromAccountToModule(
if err := k.bankKeeper.SendCoinsFromAccountToModule(
ctx, sender, types.GetModuleAccountName(), amount,
); err != nil {
return err
}
// burn vouchers from the sender's balance if the source is from another chain
if err := k.supplyKeeper.BurnCoins(
if err := k.bankKeeper.BurnCoins(
ctx, types.GetModuleAccountName(), amount,
); err != nil {
// NOTE: should not happen as the module account was
@ -159,14 +159,14 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channel.Packet, data types.
if source {
// mint new tokens if the source of the transfer is the same chain
if err := k.supplyKeeper.MintCoins(
if err := k.bankKeeper.MintCoins(
ctx, types.GetModuleAccountName(), data.Amount,
); err != nil {
return err
}
// send to receiver
return k.supplyKeeper.SendCoinsFromModuleToAccount(
return k.bankKeeper.SendCoinsFromModuleToAccount(
ctx, types.GetModuleAccountName(), receiver, data.Amount,
)
}
@ -233,11 +233,11 @@ func (k Keeper) refundPacketAmount(ctx sdk.Context, packet channel.Packet, data
}
// mint vouchers back to sender
if err := k.supplyKeeper.MintCoins(
if err := k.bankKeeper.MintCoins(
ctx, types.GetModuleAccountName(), data.Amount,
); err != nil {
return err
}
return k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.GetModuleAccountName(), sender, data.Amount)
return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.GetModuleAccountName(), sender, data.Amount)
}

View File

@ -4,12 +4,12 @@ import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
"github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
"github.com/cosmos/cosmos-sdk/x/supply"
)
func (suite *KeeperTestSuite) TestSendTransfer() {
@ -33,7 +33,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
}, true, true},
{"successful transfer from external chain", prefixCoins,
func() {
suite.chainA.App.SupplyKeeper.SetSupply(suite.chainA.GetContext(), supply.NewSupply(prefixCoins))
suite.chainA.App.BankKeeper.SetSupply(suite.chainA.GetContext(), bank.NewSupply(prefixCoins))
_, err := suite.chainA.App.BankKeeper.AddCoins(suite.chainA.GetContext(), testAddr1, prefixCoins)
suite.Require().NoError(err)
suite.chainA.CreateClient(suite.chainB)

View File

@ -2,17 +2,24 @@ package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported"
"github.com/cosmos/cosmos-sdk/x/capability"
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
)
// BankKeeper defines the expected bank keeper
type BankKeeper interface {
SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
GetModuleAddress(name string) sdk.AccAddress
GetModuleAccount(ctx sdk.Context, name string) bankexported.ModuleAccountI
MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
}
// ChannelKeeper defines the expected IBC channel keeper
@ -38,13 +45,3 @@ type ConnectionKeeper interface {
type PortKeeper interface {
BindPort(ctx sdk.Context, portID string) *capability.Capability
}
// SupplyKeeper expected supply keeper
type SupplyKeeper interface {
GetModuleAddress(name string) sdk.AccAddress
GetModuleAccount(ctx sdk.Context, name string) supplyexported.ModuleAccountI
MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
}

View File

@ -6,11 +6,10 @@ import (
)
// InitGenesis new mint genesis
func InitGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper types.SupplyKeeper, data GenesisState) {
func InitGenesis(ctx sdk.Context, keeper Keeper, bankKeeper types.BankKeeper, data GenesisState) {
keeper.SetMinter(ctx, data.Minter)
keeper.SetParams(ctx, data.Params)
supplyKeeper.GetModuleAccount(ctx, ModuleName)
bankKeeper.GetModuleAccount(ctx, ModuleName)
}
// ExportGenesis returns a GenesisState for a given context and keeper.

View File

@ -17,18 +17,18 @@ type Keeper struct {
storeKey sdk.StoreKey
paramSpace paramtypes.Subspace
sk types.StakingKeeper
supplyKeeper types.SupplyKeeper
bankKeeper types.BankKeeper
feeCollectorName string
}
// NewKeeper creates a new mint Keeper instance
func NewKeeper(
cdc codec.Marshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace,
sk types.StakingKeeper, supplyKeeper types.SupplyKeeper, feeCollectorName string,
sk types.StakingKeeper, bankKeeper types.BankKeeper, feeCollectorName string,
) Keeper {
// ensure mint module account is set
if addr := supplyKeeper.GetModuleAddress(types.ModuleName); addr == nil {
if addr := bankKeeper.GetModuleAddress(types.ModuleName); addr == nil {
panic("the mint module account has not been set")
}
@ -42,7 +42,7 @@ func NewKeeper(
storeKey: key,
paramSpace: paramSpace,
sk: sk,
supplyKeeper: supplyKeeper,
bankKeeper: bankKeeper,
feeCollectorName: feeCollectorName,
}
}
@ -108,11 +108,11 @@ func (k Keeper) MintCoins(ctx sdk.Context, newCoins sdk.Coins) error {
return nil
}
return k.supplyKeeper.MintCoins(ctx, types.ModuleName, newCoins)
return k.bankKeeper.MintCoins(ctx, types.ModuleName, newCoins)
}
// AddCollectedFees implements an alias call to the underlying supply keeper's
// AddCollectedFees to be used in BeginBlocker.
func (k Keeper) AddCollectedFees(ctx sdk.Context, fees sdk.Coins) error {
return k.supplyKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, k.feeCollectorName, fees)
return k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, k.feeCollectorName, fees)
}

View File

@ -5,11 +5,8 @@ import (
"fmt"
"math/rand"
"github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/gorilla/mux"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/client/context"
@ -20,6 +17,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/mint/client/cli"
"github.com/cosmos/cosmos-sdk/x/mint/client/rest"
"github.com/cosmos/cosmos-sdk/x/mint/simulation"
"github.com/cosmos/cosmos-sdk/x/mint/types"
)
var (
@ -76,16 +74,16 @@ func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
type AppModule struct {
AppModuleBasic
keeper Keeper
supplyKeeper types.SupplyKeeper
keeper Keeper
bankKeeper types.BankKeeper
}
// NewAppModule creates a new AppModule object
func NewAppModule(keeper Keeper, supplyKeeper types.SupplyKeeper) AppModule {
func NewAppModule(keeper Keeper, bankKeeper types.BankKeeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
keeper: keeper,
supplyKeeper: supplyKeeper,
bankKeeper: bankKeeper,
}
}
@ -119,8 +117,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data j
var genesisState GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
InitGenesis(ctx, am.keeper, am.supplyKeeper, genesisState)
InitGenesis(ctx, am.keeper, am.bankKeeper, genesisState)
return []abci.ValidatorUpdate{}
}

View File

@ -4,12 +4,11 @@ import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/supply"
)
func TestItCreatesModuleAccountOnInitBlock(t *testing.T) {
@ -23,6 +22,6 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) {
},
)
acc := app.AccountKeeper.GetAccount(ctx, supply.NewModuleAddress(mint.ModuleName))
acc := app.AccountKeeper.GetAccount(ctx, bank.NewModuleAddress(mint.ModuleName))
require.NotNil(t, acc)
}

View File

@ -2,7 +2,7 @@ package types // noalias
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/supply/exported"
"github.com/cosmos/cosmos-sdk/x/bank/exported"
)
// StakingKeeper defines the expected staking keeper
@ -11,8 +11,9 @@ type StakingKeeper interface {
BondedRatio(ctx sdk.Context) sdk.Dec
}
// SupplyKeeper defines the expected supply keeper
type SupplyKeeper interface {
// BankKeeper defines the contract needed to be fulfilled for banking and supply
// dependencies.
type BankKeeper interface {
GetModuleAddress(name string) sdk.AccAddress
// TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862

View File

@ -49,7 +49,6 @@ func getBaseSimappWithCustomKeeper() (*codec.Codec, *simapp.SimApp, sdk.Context)
appCodec,
app.GetKey(staking.StoreKey),
app.BankKeeper,
app.SupplyKeeper,
app.GetSubspace(staking.ModuleName),
)
app.StakingKeeper.SetParams(ctx, types.DefaultParams())

View File

@ -18,7 +18,7 @@ import (
// Returns final validator set after applying all declaration and delegations
func InitGenesis(
ctx sdk.Context, keeper Keeper, accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper, supplyKeeper types.SupplyKeeper, data types.GenesisState,
bankKeeper types.BankKeeper, data types.GenesisState,
) (res []abci.ValidatorUpdate) {
bondedTokens := sdk.ZeroInt()
@ -105,7 +105,7 @@ func InitGenesis(
panic(err)
}
supplyKeeper.SetModuleAccount(ctx, bondedPool)
bankKeeper.SetModuleAccount(ctx, bondedPool)
}
notBondedPool := keeper.GetNotBondedPool(ctx)
@ -118,7 +118,7 @@ func InitGenesis(
panic(err)
}
supplyKeeper.SetModuleAccount(ctx, notBondedPool)
bankKeeper.SetModuleAccount(ctx, notBondedPool)
}
// don't need to run Tendermint updates if we exported

View File

@ -6,15 +6,14 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/cosmos-sdk/x/supply"
)
func bootstrapGenesisTest(t *testing.T, power int64, numAddrs int) (*simapp.SimApp, sdk.Context, []sdk.AccAddress, []sdk.ValAddress) {
@ -28,9 +27,9 @@ func bootstrapGenesisTest(t *testing.T, power int64, numAddrs int) (*simapp.SimA
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), totalSupply)
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
app.SupplyKeeper.SetSupply(ctx, supply.NewSupply(totalSupply))
app.BankKeeper.SetModuleAccount(ctx, notBondedPool)
app.BankKeeper.SetSupply(ctx, bank.NewSupply(totalSupply))
return app, ctx, addrDels, addrVals
}
@ -65,7 +64,7 @@ func TestInitGenesis(t *testing.T) {
validators[1].DelegatorShares = valTokens.ToDec()
genesisState := types.NewGenesisState(params, validators, delegations)
vals := staking.InitGenesis(ctx, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.SupplyKeeper, genesisState)
vals := staking.InitGenesis(ctx, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, genesisState)
actualGenesis := staking.ExportGenesis(ctx, app.StakingKeeper)
require.Equal(t, genesisState.Params, actualGenesis.Params)
@ -114,7 +113,7 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
}
genesisState := types.NewGenesisState(params, validators, delegations)
vals := staking.InitGenesis(ctx, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.SupplyKeeper, genesisState)
vals := staking.InitGenesis(ctx, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, genesisState)
abcivals := make([]abci.ValidatorUpdate, 100)
for i, val := range validators[:100] {

View File

@ -15,10 +15,10 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/cosmos-sdk/x/supply"
)
func bootstrapHandlerGenesisTest(t *testing.T, power int64, numAddrs int, accAmount int64) (*simapp.SimApp, sdk.Context, []sdk.AccAddress, []sdk.ValAddress) {
@ -32,9 +32,9 @@ func bootstrapHandlerGenesisTest(t *testing.T, power int64, numAddrs int, accAmo
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), totalSupply)
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
app.SupplyKeeper.SetSupply(ctx, supply.NewSupply(totalSupply))
app.BankKeeper.SetModuleAccount(ctx, notBondedPool)
app.BankKeeper.SetSupply(ctx, bank.NewSupply(totalSupply))
return app, ctx, addrDels, addrVals
}

View File

@ -30,7 +30,6 @@ func createTestInput() (*codec.Codec, *simapp.SimApp, sdk.Context) {
appCodec,
app.GetKey(staking.StoreKey),
app.BankKeeper,
app.SupplyKeeper,
app.GetSubspace(staking.ModuleName),
)

View File

@ -512,7 +512,7 @@ func (k Keeper) Delegate(
}
coins := sdk.NewCoins(sdk.NewCoin(k.BondDenom(ctx), bondAmt))
err := k.supplyKeeper.DelegateCoinsFromAccountToModule(ctx, delegation.DelegatorAddress, sendName, coins)
err := k.bankKeeper.DelegateCoinsFromAccountToModule(ctx, delegation.DelegatorAddress, sendName, coins)
if err != nil {
return sdk.Dec{}, err
}
@ -694,7 +694,7 @@ func (k Keeper) CompleteUnbonding(ctx sdk.Context, delAddr sdk.AccAddress, valAd
// track undelegation only when remaining or truncated shares are non-zero
if !entry.Balance.IsZero() {
amt := sdk.NewCoin(bondDenom, entry.Balance)
err := k.supplyKeeper.UndelegateCoinsFromModuleToAccount(
err := k.bankKeeper.UndelegateCoinsFromModuleToAccount(
ctx, types.NotBondedPoolName, ubd.DelegatorAddress, sdk.NewCoins(amt),
)
if err != nil {

View File

@ -192,7 +192,7 @@ func TestUnbondDelegation(t *testing.T) {
sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), startTokens)),
),
)
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
app.BankKeeper.SetModuleAccount(ctx, notBondedPool)
// create a validator and a delegator to that validator
// note this validator starts not-bonded
@ -234,7 +234,7 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens)))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
app.BankKeeper.SetModuleAccount(ctx, notBondedPool)
// create a validator and a delegator to that validator
validator := types.NewValidator(addrVals[0], PKs[0], types.Description{})
@ -324,7 +324,7 @@ func TestUndelegateSelfDelegationBelowMinSelfDelegation(t *testing.T) {
oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress())
err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(delCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
app.BankKeeper.SetModuleAccount(ctx, notBondedPool)
validator = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true)
require.True(t, validator.IsBonded())
@ -337,7 +337,7 @@ func TestUndelegateSelfDelegationBelowMinSelfDelegation(t *testing.T) {
oldBonded := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
err = app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), oldBonded.Add(delCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, bondedPool)
app.BankKeeper.SetModuleAccount(ctx, bondedPool)
// create a second delegation to this validator
app.StakingKeeper.DeleteValidatorByPowerIndex(ctx, validator)
@ -349,7 +349,7 @@ func TestUndelegateSelfDelegationBelowMinSelfDelegation(t *testing.T) {
oldBonded = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
err = app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), oldBonded.Add(delCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, bondedPool)
app.BankKeeper.SetModuleAccount(ctx, bondedPool)
validator = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true)
delegation := types.NewDelegation(addrDels[0], addrVals[0], issuedShares)
@ -389,7 +389,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) {
oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress())
err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(delCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
app.BankKeeper.SetModuleAccount(ctx, notBondedPool)
validator = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true)
require.True(t, validator.IsBonded())
@ -401,7 +401,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) {
oldBonded := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
err = app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), oldBonded.Add(delCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, bondedPool)
app.BankKeeper.SetModuleAccount(ctx, bondedPool)
// create a second delegation to this validator
app.StakingKeeper.DeleteValidatorByPowerIndex(ctx, validator)
@ -412,7 +412,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) {
oldBonded = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
err = app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), oldBonded.Add(delCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, bondedPool)
app.BankKeeper.SetModuleAccount(ctx, bondedPool)
validator = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true)
delegation := types.NewDelegation(addrDels[1], addrVals[0], issuedShares)
@ -421,7 +421,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) {
oldBonded = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
err = app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), oldBonded.Add(delCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, bondedPool)
app.BankKeeper.SetModuleAccount(ctx, bondedPool)
header := ctx.BlockHeader()
blockHeight := int64(10)
@ -476,7 +476,7 @@ func TestUndelegateFromUnbondedValidator(t *testing.T) {
oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress())
err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(delCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
app.BankKeeper.SetModuleAccount(ctx, notBondedPool)
// create a validator with a self-delegation
validator := types.NewValidator(addrVals[0], PKs[0], types.Description{})
@ -495,7 +495,7 @@ func TestUndelegateFromUnbondedValidator(t *testing.T) {
oldBonded := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
err = app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), oldBonded.Add(delCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, bondedPool)
app.BankKeeper.SetModuleAccount(ctx, bondedPool)
// create a second delegation to this validator
app.StakingKeeper.DeleteValidatorByPowerIndex(ctx, validator)
@ -560,7 +560,7 @@ func TestUnbondingAllDelegationFromValidator(t *testing.T) {
oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress())
err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(delCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
app.BankKeeper.SetModuleAccount(ctx, notBondedPool)
//create a validator with a self-delegation
validator := types.NewValidator(addrVals[0], PKs[0], types.Description{})
@ -585,7 +585,7 @@ func TestUnbondingAllDelegationFromValidator(t *testing.T) {
oldBonded := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
err = app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), oldBonded.Add(delCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, bondedPool)
app.BankKeeper.SetModuleAccount(ctx, bondedPool)
validator = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true)
require.True(t, validator.IsBonded())
@ -727,7 +727,7 @@ func TestRedelegateToSameValidator(t *testing.T) {
oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress())
err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(startCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
app.BankKeeper.SetModuleAccount(ctx, notBondedPool)
// create a validator with a self-delegation
validator := types.NewValidator(addrVals[0], PKs[0], types.Description{})
@ -758,7 +758,7 @@ func TestRedelegationMaxEntries(t *testing.T) {
oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress())
err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(startCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
app.BankKeeper.SetModuleAccount(ctx, notBondedPool)
// create a validator with a self-delegation
validator := types.NewValidator(addrVals[0], PKs[0], types.Description{})
@ -816,7 +816,7 @@ func TestRedelegateSelfDelegation(t *testing.T) {
oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress())
err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(startCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
app.BankKeeper.SetModuleAccount(ctx, notBondedPool)
//create a validator with a self-delegation
validator := types.NewValidator(addrVals[0], PKs[0], types.Description{})
@ -873,7 +873,7 @@ func TestRedelegateFromUnbondingValidator(t *testing.T) {
oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress())
err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(startCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
app.BankKeeper.SetModuleAccount(ctx, notBondedPool)
//create a validator with a self-delegation
validator := types.NewValidator(addrVals[0], PKs[0], types.Description{})
@ -957,7 +957,7 @@ func TestRedelegateFromUnbondedValidator(t *testing.T) {
oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress())
err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(startCoins...))
require.NoError(t, err)
app.SupplyKeeper.SetModuleAccount(ctx, notBondedPool)
app.BankKeeper.SetModuleAccount(ctx, notBondedPool)
//create a validator with a self-delegation
validator := types.NewValidator(addrVals[0], PKs[0], types.Description{})

View File

@ -25,7 +25,6 @@ type Keeper struct {
storeKey sdk.StoreKey
cdc codec.Marshaler
bankKeeper types.BankKeeper
supplyKeeper types.SupplyKeeper
hooks types.StakingHooks
paramstore paramtypes.Subspace
validatorCache map[string]cachedValidator
@ -34,7 +33,7 @@ type Keeper struct {
// NewKeeper creates a new staking Keeper instance
func NewKeeper(
cdc codec.Marshaler, key sdk.StoreKey, bk types.BankKeeper, sk types.SupplyKeeper, ps paramtypes.Subspace,
cdc codec.Marshaler, key sdk.StoreKey, bk types.BankKeeper, ps paramtypes.Subspace,
) Keeper {
// set KeyTable if it has not already been set
@ -43,11 +42,11 @@ func NewKeeper(
}
// ensure bonded and not bonded module accounts are set
if addr := sk.GetModuleAddress(types.BondedPoolName); addr == nil {
if addr := bk.GetModuleAddress(types.BondedPoolName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.BondedPoolName))
}
if addr := sk.GetModuleAddress(types.NotBondedPoolName); addr == nil {
if addr := bk.GetModuleAddress(types.NotBondedPoolName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.NotBondedPoolName))
}
@ -55,7 +54,6 @@ func NewKeeper(
storeKey: key,
cdc: cdc,
bankKeeper: bk,
supplyKeeper: sk,
paramstore: ps,
hooks: nil,
validatorCache: make(map[string]cachedValidator, aminoCacheSize),

View File

@ -2,24 +2,24 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/exported"
"github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/cosmos-sdk/x/supply/exported"
)
// GetBondedPool returns the bonded tokens pool's module account
func (k Keeper) GetBondedPool(ctx sdk.Context) (bondedPool exported.ModuleAccountI) {
return k.supplyKeeper.GetModuleAccount(ctx, types.BondedPoolName)
return k.bankKeeper.GetModuleAccount(ctx, types.BondedPoolName)
}
// GetNotBondedPool returns the not bonded tokens pool's module account
func (k Keeper) GetNotBondedPool(ctx sdk.Context) (notBondedPool exported.ModuleAccountI) {
return k.supplyKeeper.GetModuleAccount(ctx, types.NotBondedPoolName)
return k.bankKeeper.GetModuleAccount(ctx, types.NotBondedPoolName)
}
// bondedTokensToNotBonded transfers coins from the bonded to the not bonded pool within staking
func (k Keeper) bondedTokensToNotBonded(ctx sdk.Context, tokens sdk.Int) {
coins := sdk.NewCoins(sdk.NewCoin(k.BondDenom(ctx), tokens))
err := k.supplyKeeper.SendCoinsFromModuleToModule(ctx, types.BondedPoolName, types.NotBondedPoolName, coins)
err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.BondedPoolName, types.NotBondedPoolName, coins)
if err != nil {
panic(err)
}
@ -28,7 +28,7 @@ func (k Keeper) bondedTokensToNotBonded(ctx sdk.Context, tokens sdk.Int) {
// notBondedTokensToBonded transfers coins from the not bonded to the bonded pool within staking
func (k Keeper) notBondedTokensToBonded(ctx sdk.Context, tokens sdk.Int) {
coins := sdk.NewCoins(sdk.NewCoin(k.BondDenom(ctx), tokens))
err := k.supplyKeeper.SendCoinsFromModuleToModule(ctx, types.NotBondedPoolName, types.BondedPoolName, coins)
err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.NotBondedPoolName, types.BondedPoolName, coins)
if err != nil {
panic(err)
}
@ -41,7 +41,7 @@ func (k Keeper) burnBondedTokens(ctx sdk.Context, amt sdk.Int) error {
return nil
}
coins := sdk.NewCoins(sdk.NewCoin(k.BondDenom(ctx), amt))
return k.supplyKeeper.BurnCoins(ctx, types.BondedPoolName, coins)
return k.bankKeeper.BurnCoins(ctx, types.BondedPoolName, coins)
}
// burnNotBondedTokens removes coins from the not bonded pool module account
@ -51,7 +51,7 @@ func (k Keeper) burnNotBondedTokens(ctx sdk.Context, amt sdk.Int) error {
return nil
}
coins := sdk.NewCoins(sdk.NewCoin(k.BondDenom(ctx), amt))
return k.supplyKeeper.BurnCoins(ctx, types.NotBondedPoolName, coins)
return k.bankKeeper.BurnCoins(ctx, types.NotBondedPoolName, coins)
}
// TotalBondedTokens total staking tokens supply which is bonded
@ -62,7 +62,7 @@ func (k Keeper) TotalBondedTokens(ctx sdk.Context) sdk.Int {
// StakingTokenSupply staking tokens from the total supply
func (k Keeper) StakingTokenSupply(ctx sdk.Context) sdk.Int {
return k.supplyKeeper.GetSupply(ctx).GetTotal().AmountOf(k.BondDenom(ctx))
return k.bankKeeper.GetSupply(ctx).GetTotal().AmountOf(k.BondDenom(ctx))
}
// BondedRatio the fraction of the staking tokens which are currently bonded

Some files were not shown because too many files have changed in this diff Show More