Appease linter

This commit is contained in:
Aditya Sripal 2018-06-27 15:05:04 -07:00 committed by Ethan Buchman
parent e3f38b6f6c
commit 4e2eb240f3
3 changed files with 23 additions and 4 deletions

View File

@ -81,9 +81,10 @@ type MsgIssue struct {
Coin sdk.Coin
}
// nolint
// Implements Msg.
func (msg MsgIssue) Type() string { return "issue" }
// Implements Msg. Ensures addresses are valid and Coin is positive
func (msg MsgIssue) ValidateBasic() sdk.Error {
if len(msg.Issuer) == 0 {
return sdk.ErrInvalidAddress("Issuer address cannot be empty")
@ -101,6 +102,7 @@ func (msg MsgIssue) ValidateBasic() sdk.Error {
return nil
}
// Implements Msg. Get canonical sign bytes for MsgIssue
func (msg MsgIssue) GetSignBytes() []byte {
bz, err := json.Marshal(msg)
if err != nil {

View File

@ -135,21 +135,26 @@ func betterHandleMetaData(ctx sdk.Context, metadataMapper MetaDataMapper, issuer
//------------------------------------------------------------------
// Mapper for Coin Metadata
// Example of a very simple user-defined mapper
// Example of a very simple user-defined mapper interface
type MetaDataMapper interface {
GetMetaData(sdk.Context, string) CoinMetadata
SetMetaData(sdk.Context, string, CoinMetadata)
}
// Implements MetaDataMapper
type App3MetaDataMapper struct {
mainKey *sdk.KVStoreKey
}
// Construct new App3MetaDataMapper
func NewApp3MetaDataMapper(key *sdk.KVStoreKey) App3MetaDataMapper {
return App3MetaDataMapper{mainKey: key}
}
// Implements MetaDataMpper. Returns metadata for coin
// If metadata does not exist in store, function creates default metadata and returns it
// without adding it to the store.
func (mdm App3MetaDataMapper) GetMetaData(ctx sdk.Context, denom string) CoinMetadata {
store := ctx.KVStore(mdm.mainKey)
@ -170,6 +175,7 @@ func (mdm App3MetaDataMapper) GetMetaData(ctx sdk.Context, denom string) CoinMet
return metadata
}
// Implements MetaDataMapper. Sets metadata in store with key equal to denom.
func (mdm App3MetaDataMapper) SetMetaData(ctx sdk.Context, denom string, metadata CoinMetadata) {
store := ctx.KVStore(mdm.mainKey)

View File

@ -59,6 +59,7 @@ func NewApp4(logger log.Logger, db dbm.DB) *bapp.BaseApp {
return app
}
// Application state at Genesis has accounts with starting balances and coins with starting metadata
type GenesisState struct {
Accounts []*GenesisAccount `json:"accounts"`
Coins []*GenesisCoin `json:"coins"`
@ -70,6 +71,7 @@ type GenesisAccount struct {
Coins sdk.Coins `json:"coins"`
}
// Converts GenesisAccount to auth.BaseAccount for storage in account store
func (ga *GenesisAccount) ToAccount() (acc *auth.BaseAccount, err error) {
baseAcc := auth.BaseAccount{
Address: ga.Address,
@ -86,6 +88,7 @@ type GenesisCoin struct {
Decimal uint64 `json:"decimals"`
}
// Converts GenesisCoin to its denom and metadata for storage in main store
func (gc *GenesisCoin) ToMetaData() (string, CoinMetadata) {
return gc.Denom, CoinMetadata{
Issuer: gc.Issuer,
@ -129,8 +132,10 @@ func NewInitChainer(cdc *wire.Codec, accountMapper auth.AccountMapper, metadataM
}
//---------------------------------------------------------------------------------------------
// Now that initializing coin metadata is done in InitChainer we can simplifiy handleMsgIssue
// Now that initializing coin metadata is done in InitChainer we can simplify handleMsgIssue
// New MsgIssue handler will no longer generate coin metadata on the fly.
// Allows issuers (permissioned at genesis) to issue coin to receiver.
func evenBetterHandleMsgIssue(metadataMapper MetaDataMapper, accountKeeper bank.Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
issueMsg, ok := msg.(MsgIssue)
@ -156,6 +161,8 @@ func evenBetterHandleMsgIssue(metadataMapper MetaDataMapper, accountKeeper bank.
}
}
// No longer generates metadata on the fly.
// Returns error result when it cannot find coin metadata
func evenBetterHandleMetaData(ctx sdk.Context, metadataMapper MetaDataMapper, issuer sdk.Address, coin sdk.Coin) sdk.Result {
metadata := metadataMapper.GetMetaData(ctx, coin.Denom)
@ -182,16 +189,19 @@ func evenBetterHandleMetaData(ctx sdk.Context, metadataMapper MetaDataMapper, is
}
//---------------------------------------------------------------------------------------------
// Simpler MetaDataMapper no longer able to initalize default CoinMetaData
// Simpler MetaDataMapper no longer able to initialize default CoinMetaData
// Implements MetaDataMapper
type App4MetaDataMapper struct {
mainKey *sdk.KVStoreKey
}
// Constructs new App4MetaDataMapper
func NewApp4MetaDataMapper(key *sdk.KVStoreKey) App4MetaDataMapper {
return App4MetaDataMapper{mainKey: key}
}
// Returns coin Metadata. If metadata not found in store, function returns empty struct.
func (mdm App4MetaDataMapper) GetMetaData(ctx sdk.Context, denom string) CoinMetadata {
store := ctx.KVStore(mdm.mainKey)
@ -210,6 +220,7 @@ func (mdm App4MetaDataMapper) GetMetaData(ctx sdk.Context, denom string) CoinMet
return metadata
}
// Sets metadata in store with key equal to coin denom. Same behavior as App3 implementation.
func (mdm App4MetaDataMapper) SetMetaData(ctx sdk.Context, denom string, metadata CoinMetadata) {
store := ctx.KVStore(mdm.mainKey)