github.com/cosmos/cosmos-sdk@v0.50.10/x/bank/migrations/v1/types.go (about)

     1  package v1
     2  
     3  import (
     4  	"github.com/golang/protobuf/proto"
     5  
     6  	codectypes "github.com/cosmos/cosmos-sdk/codec/types"
     7  	sdk "github.com/cosmos/cosmos-sdk/types"
     8  	"github.com/cosmos/cosmos-sdk/types/kv"
     9  	v1auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v1"
    10  	"github.com/cosmos/cosmos-sdk/x/bank/types"
    11  )
    12  
    13  const (
    14  	// ModuleName defines the module name
    15  	ModuleName = "bank"
    16  
    17  	// StoreKey defines the primary module store key
    18  	StoreKey = ModuleName
    19  
    20  	// RouterKey defines the module's message routing key
    21  	RouterKey = ModuleName
    22  
    23  	// QuerierRoute defines the module's query routing key
    24  	QuerierRoute = ModuleName
    25  )
    26  
    27  // KVStore keys
    28  var (
    29  	BalancesPrefix      = []byte("balances")
    30  	SupplyKey           = []byte{0x00}
    31  	DenomMetadataPrefix = []byte{0x1}
    32  )
    33  
    34  // DenomMetadataKey returns the denomination metadata key.
    35  func DenomMetadataKey(denom string) []byte {
    36  	d := []byte(denom)
    37  	return append(DenomMetadataPrefix, d...)
    38  }
    39  
    40  // AddressFromBalancesStore returns an account address from a balances prefix
    41  // store. The key must not contain the perfix BalancesPrefix as the prefix store
    42  // iterator discards the actual prefix.
    43  func AddressFromBalancesStore(key []byte) sdk.AccAddress {
    44  	kv.AssertKeyAtLeastLength(key, 1+v1auth.AddrLen)
    45  	addr := key[:v1auth.AddrLen]
    46  	kv.AssertKeyLength(addr, v1auth.AddrLen)
    47  	return sdk.AccAddress(addr)
    48  }
    49  
    50  // SupplyI defines an inflationary supply interface for modules that handle
    51  // token supply.
    52  // It is copy-pasted from:
    53  // https://github.com/cosmos/cosmos-sdk/blob/v0.42.3/x/bank/exported/exported.go
    54  // where we stripped off the unnecessary methods.
    55  //
    56  // It is used in the migration script, because we save this interface as an Any
    57  // in the supply state.
    58  //
    59  // Deprecated.
    60  type SupplyI interface {
    61  	proto.Message
    62  }
    63  
    64  // RegisterInterfaces registers interfaces required for the v1 migrations.
    65  func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
    66  	registry.RegisterInterface(
    67  		"cosmos.bank.v1beta1.SupplyI",
    68  		(*SupplyI)(nil),
    69  		&types.Supply{},
    70  	)
    71  }