cosmos-sdk/docs/examples/democoin/x/pow/handler.go
gamarin2 addcfbf5cb Documentation Structure Change and Cleanup (#2808)
* Update docs/sdk/clients.md
* organize ADR directory like tendermint
* docs: move spec-proposals into spec/
* remove lotion, moved to website repo
* move getting-started to cosmos-hub, and voyager to website
* docs: move lite/ into clients/lite/
* move introduction/ content to website repo
* move resources/ content to website repo
* mv sdk/clients.md to clients/clients.md
* mv validators to cosmos-hub/validators
* move deprecated sdk/ content to _attic
* sdk/modules.md is duplicate with modules/README.md
* consolidate remianing sdk/ files into a single sdk.md
* move examples/ to docs/examples/
* mv docs/cosmos-hub to docs/gaia
* Add keys/accounts section to localnet docs
2018-11-14 11:44:17 -08:00

34 lines
710 B
Go

package pow
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// POW handler
func (pk Keeper) Handler(ctx sdk.Context, msg sdk.Msg) sdk.Result {
switch msg := msg.(type) {
case MsgMine:
return handleMsgMine(ctx, pk, msg)
default:
errMsg := "Unrecognized pow Msg type: " + msg.Type()
return sdk.ErrUnknownRequest(errMsg).Result()
}
}
func handleMsgMine(ctx sdk.Context, pk Keeper, msg MsgMine) sdk.Result {
// precondition: msg has passed ValidateBasic
newDiff, newCount, err := pk.CheckValid(ctx, msg.Difficulty, msg.Count)
if err != nil {
return err.Result()
}
err = pk.ApplyValid(ctx, msg.Sender, newDiff, newCount)
if err != nil {
return err.Result()
}
return sdk.Result{}
}