-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from iov-one/burner-module
Adds a burner module
- Loading branch information
Showing
10 changed files
with
226 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package burner | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/iov-one/starnamed/x/burner/types" | ||
) | ||
|
||
//TODO: we could add a test for this function | ||
|
||
//EndBlocker burns all the coins owned by the burner module | ||
func EndBlocker(ctx sdk.Context, supplyKeeper types.SupplyKeeper, accountKeeper types.AccountKeeper) { | ||
moduleAcc := accountKeeper.GetModuleAccount(ctx, types.ModuleName) | ||
if balance := supplyKeeper.GetAllBalances(ctx, moduleAcc.GetAddress()); !balance.IsZero() { | ||
if err := supplyKeeper.BurnCoins(ctx, types.ModuleName, balance); err != nil { | ||
panic(fmt.Sprintf("Error while burning tokens of the burner module account: %s", err.Error())) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Package burner contains the burner module, that burns all tokens sent | ||
// to its address (star1v7uw4xhrcv0vk7qp8jf9lu3hm5d8uu5ywlkzeg) | ||
package burner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package burner | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
cdctypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
"github.com/gorilla/mux" | ||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
"github.com/spf13/cobra" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
|
||
"github.com/iov-one/starnamed/x/burner/types" | ||
) | ||
|
||
var ( | ||
_ module.AppModule = AppModule{} | ||
_ module.AppModuleBasic = AppModuleBasic{} | ||
) | ||
|
||
// AppModuleBasic defines the basic application module used by the burner module. | ||
type AppModuleBasic struct { | ||
cdc codec.Marshaler | ||
} | ||
|
||
// RegisterLegacyAminoCodec registers the amino codec. | ||
func (b AppModuleBasic) RegisterLegacyAminoCodec(*codec.LegacyAmino) { | ||
} | ||
|
||
// RegisterGRPCGatewayRoutes registers the query handler client. | ||
func (b AppModuleBasic) RegisterGRPCGatewayRoutes(client.Context, *runtime.ServeMux) { | ||
} | ||
|
||
// Name returns the burner module's name. | ||
func (AppModuleBasic) Name() string { return types.ModuleName } | ||
|
||
// DefaultGenesis returns default genesis state as raw bytes for the burner module. | ||
func (AppModuleBasic) DefaultGenesis(codec.JSONMarshaler) json.RawMessage { | ||
return nil | ||
} | ||
|
||
// ValidateGenesis performs genesis state validation for the burner module. | ||
func (b AppModuleBasic) ValidateGenesis(_ codec.JSONMarshaler, _ client.TxEncodingConfig, genesisData json.RawMessage) error { | ||
if len(genesisData) > 0 { | ||
return fmt.Errorf("invalid genesis data for module burner: should be empty") | ||
} | ||
return nil | ||
} | ||
|
||
// RegisterRESTRoutes registers the REST routes for this module. | ||
func (AppModuleBasic) RegisterRESTRoutes(client.Context, *mux.Router) { | ||
} | ||
|
||
// GetQueryCmd returns no root query command for this module. | ||
func (AppModuleBasic) GetQueryCmd() *cobra.Command { | ||
return nil | ||
} | ||
|
||
// GetTxCmd returns the root tx command for this module. | ||
func (AppModuleBasic) GetTxCmd() *cobra.Command { | ||
return nil | ||
} | ||
|
||
// RegisterInterfaces implements InterfaceModule | ||
func (b AppModuleBasic) RegisterInterfaces(cdctypes.InterfaceRegistry) { | ||
} | ||
|
||
// AppModule implements an application module for the burner module. | ||
type AppModule struct { | ||
AppModuleBasic | ||
supplyKeeper types.SupplyKeeper | ||
accountKeeper types.AccountKeeper | ||
} | ||
|
||
// NewAppModule creates a new AppModule object. | ||
func NewAppModule(supplyKeeper types.SupplyKeeper, accountKeeper types.AccountKeeper) AppModule { | ||
return AppModule{ | ||
AppModuleBasic: AppModuleBasic{}, | ||
supplyKeeper: supplyKeeper, | ||
accountKeeper: accountKeeper, | ||
} | ||
} | ||
|
||
// Name returns the burner module's name. | ||
func (am AppModule) Name() string { return am.AppModuleBasic.Name() } | ||
|
||
// RegisterServices allows a module to register services | ||
func (am AppModule) RegisterServices(module.Configurator) { | ||
} | ||
|
||
// LegacyQuerierHandler provides an sdk.Querier object that uses the legacy amino codec. | ||
func (AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { | ||
return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { | ||
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "%s", path[0]) | ||
} | ||
} | ||
|
||
// RegisterInvariants registers the burner module invariants. | ||
func (AppModule) RegisterInvariants(sdk.InvariantRegistry) {} | ||
|
||
// Route returns the message routing key for the burner module. | ||
func (am AppModule) Route() sdk.Route { | ||
return sdk.NewRoute(types.ModuleName, func(sdk.Context, sdk.Msg) (*sdk.Result, error) { | ||
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "unknown request") | ||
}) | ||
} | ||
|
||
// QuerierRoute returns the burner module's querier route name. | ||
func (AppModule) QuerierRoute() string { return types.ModuleName } | ||
|
||
// BeginBlock returns the begin blocker for the burner module. | ||
func (AppModule) BeginBlock(sdk.Context, abci.RequestBeginBlock) {} | ||
|
||
// EndBlock returns the end blocker for the burner module. It returns no validator updates. | ||
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { | ||
EndBlocker(ctx, am.supplyKeeper, am.accountKeeper) | ||
return []abci.ValidatorUpdate{} | ||
} | ||
|
||
// InitGenesis performs genesis initialization for the burner module. It returns no validator updates. | ||
func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONMarshaler, _ json.RawMessage) []abci.ValidatorUpdate { | ||
return []abci.ValidatorUpdate{} | ||
} | ||
|
||
// ExportGenesis returns the exported genesis state as raw bytes for the burner module. | ||
func (am AppModule) ExportGenesis(sdk.Context, codec.JSONMarshaler) json.RawMessage { | ||
return am.DefaultGenesis(nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package types | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth/types" | ||
) | ||
|
||
type SupplyKeeper interface { | ||
GetAllBalances(sdk.Context, sdk.AccAddress) sdk.Coins | ||
BurnCoins(sdk.Context, string, sdk.Coins) error | ||
} | ||
|
||
type AccountKeeper interface { | ||
GetModuleAddress(string) sdk.AccAddress | ||
GetModuleAccount(sdk.Context, string) types.ModuleAccountI | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package types | ||
|
||
// Module names | ||
const ( | ||
// ModuleName is the name of the module | ||
// the corresponding bech32 address is star1v7uw4xhrcv0vk7qp8jf9lu3hm5d8uu5ywlkzeg | ||
ModuleName = "burner" | ||
) |