cool module renames

This commit is contained in:
rigelrozanski 2018-03-13 01:37:50 +01:00
parent b9691f1086
commit e7777cc7ca
7 changed files with 54 additions and 54 deletions

View File

@ -81,14 +81,14 @@ func MakeCodec() *wire.Codec {
const msgTypeSend = 0x1 const msgTypeSend = 0x1
const msgTypeIssue = 0x2 const msgTypeIssue = 0x2
const msgTypeCool = 0x3 const msgTypeQuiz = 0x3
const msgTypeSetCool = 0x4 const msgTypeSetTrend = 0x4
var _ = oldwire.RegisterInterface( var _ = oldwire.RegisterInterface(
struct{ sdk.Msg }{}, struct{ sdk.Msg }{},
oldwire.ConcreteType{bank.SendMsg{}, msgTypeSend}, oldwire.ConcreteType{bank.SendMsg{}, msgTypeSend},
oldwire.ConcreteType{bank.IssueMsg{}, msgTypeIssue}, oldwire.ConcreteType{bank.IssueMsg{}, msgTypeIssue},
oldwire.ConcreteType{cool.CoolMsg{}, msgTypeCool}, oldwire.ConcreteType{cool.QuizMsg{}, msgTypeQuiz},
oldwire.ConcreteType{cool.SetCoolMsg{}, msgTypeSetCool}, oldwire.ConcreteType{cool.SetTrendMsg{}, msgTypeSetTrend},
) )
const accTypeApp = 0x1 const accTypeApp = 0x1

View File

@ -33,17 +33,17 @@ var (
Outputs: []bank.Output{bank.NewOutput(addr2, coins)}, Outputs: []bank.Output{bank.NewOutput(addr2, coins)},
} }
coolMsg1 = cool.CoolMsg{ coolMsg1 = cool.QuizMsg{
Sender: addr1, Sender: addr1,
CoolerThanCool: "icecold", CoolAnswer: "icecold",
} }
coolMsg2 = cool.CoolMsg{ coolMsg2 = cool.QuizMsg{
Sender: addr1, Sender: addr1,
CoolerThanCool: "icecold", CoolAnswer: "icecold",
} }
setCoolMsg = cool.SetCoolMsg{ setTrendMsg = cool.SetTrendMsg{
Sender: addr1, Sender: addr1,
Cool: "goodbye", Cool: "goodbye",
} }
@ -65,7 +65,7 @@ func TestMsgs(t *testing.T) {
}{ }{
{sendMsg}, {sendMsg},
{coolMsg1}, {coolMsg1},
{setCoolMsg}, {setTrendMsg},
} }
chainID := "" chainID := ""

View File

@ -62,7 +62,7 @@ func main() {
)...) )...)
basecliCmd.AddCommand( basecliCmd.AddCommand(
client.PostCommands( client.PostCommands(
coolcmd.SetCoolTxCmd(cdc), coolcmd.SetTrendTxCmd(cdc),
)...) )...)
// add proxy, version and key info // add proxy, version and key info

View File

@ -29,7 +29,7 @@ func CoolTxCmd(cdc *wire.Codec) *cobra.Command {
} }
// create the message // create the message
msg := cool.NewCoolMsg(from, args[0]) msg := cool.NewQuizMsg(from, args[0])
// build and sign the transaction, then broadcast to Tendermint // build and sign the transaction, then broadcast to Tendermint
res, err := builder.SignBuildBroadcast(msg, cdc) res, err := builder.SignBuildBroadcast(msg, cdc)
@ -44,7 +44,7 @@ func CoolTxCmd(cdc *wire.Codec) *cobra.Command {
} }
// set what cool transaction // set what cool transaction
func SetCoolTxCmd(cdc *wire.Codec) *cobra.Command { func SetTrendTxCmd(cdc *wire.Codec) *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: "setcool [answer]", Use: "setcool [answer]",
Short: "You're so cool, tell us what is cool!", Short: "You're so cool, tell us what is cool!",
@ -60,7 +60,7 @@ func SetCoolTxCmd(cdc *wire.Codec) *cobra.Command {
} }
// create the message // create the message
msg := cool.NewSetCoolMsg(from, args[0]) msg := cool.NewSetTrendMsg(from, args[0])
// build and sign the transaction, then broadcast to Tendermint // build and sign the transaction, then broadcast to Tendermint
res, err := builder.SignBuildBroadcast(msg, cdc) res, err := builder.SignBuildBroadcast(msg, cdc)

View File

@ -22,10 +22,10 @@ import (
func NewHandler(ck bank.CoinKeeper, cm Mapper) sdk.Handler { func NewHandler(ck bank.CoinKeeper, cm Mapper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result { return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
switch msg := msg.(type) { switch msg := msg.(type) {
case SetCoolMsg: case SetTrendMsg:
return handleSetCoolMsg(ctx, cm, msg) return handleSetTrendMsg(ctx, cm, msg)
case CoolMsg: case QuizMsg:
return handleCoolMsg(ctx, ck, cm, msg) return handleQuizMsg(ctx, ck, cm, msg)
default: default:
errMsg := fmt.Sprintf("Unrecognized cool Msg type: %v", reflect.TypeOf(msg).Name()) errMsg := fmt.Sprintf("Unrecognized cool Msg type: %v", reflect.TypeOf(msg).Name())
return sdk.ErrUnknownRequest(errMsg).Result() return sdk.ErrUnknownRequest(errMsg).Result()
@ -34,22 +34,22 @@ func NewHandler(ck bank.CoinKeeper, cm Mapper) sdk.Handler {
} }
// Handle CoolMsg This is the engine of your module // Handle CoolMsg This is the engine of your module
func handleSetCoolMsg(ctx sdk.Context, cm Mapper, msg SetCoolMsg) sdk.Result { func handleSetTrendMsg(ctx sdk.Context, cm Mapper, msg SetTrendMsg) sdk.Result {
cm.SetCool(ctx, msg.Cool) cm.SetTrend(ctx, msg.Cool)
return sdk.Result{} return sdk.Result{}
} }
// Handle CoolMsg This is the engine of your module // Handle CoolMsg This is the engine of your module
func handleCoolMsg(ctx sdk.Context, ck bank.CoinKeeper, cm Mapper, msg CoolMsg) sdk.Result { func handleQuizMsg(ctx sdk.Context, ck bank.CoinKeeper, cm Mapper, msg QuizMsg) sdk.Result {
whatsCool := cm.GetCool(ctx) whatsCool := cm.GetCool(ctx)
// set default if nothing is set // set default if nothing is set
//if whatsCool == "" { //if whatsCool == "" {
//cm.SetCool(ctx, "icecold") //cm.SetTrend(ctx, "icecold")
//} //}
if msg.CoolerThanCool == whatsCool { if msg.CoolAnswer == whatsCool {
bonusCoins := sdk.Coins{{whatsCool, 69}} bonusCoins := sdk.Coins{{whatsCool, 69}}
_, err := ck.AddCoins(ctx, msg.Sender, bonusCoins) _, err := ck.AddCoins(ctx, msg.Sender, bonusCoins)

View File

@ -24,7 +24,7 @@ func (am Mapper) GetCool(ctx sdk.Context) string {
} }
// Implements sdk.AccountMapper. // Implements sdk.AccountMapper.
func (am Mapper) SetCool(ctx sdk.Context, whatscool string) { func (am Mapper) SetTrend(ctx sdk.Context, whatscool string) {
store := ctx.KVStore(am.key) store := ctx.KVStore(am.key)
store.Set(coolKey, []byte(whatscool)) store.Set(coolKey, []byte(whatscool))
} }

View File

@ -10,32 +10,32 @@ import (
// A really cool msg type, these fields are can be entirely arbitrary and // A really cool msg type, these fields are can be entirely arbitrary and
// custom to your message // custom to your message
type SetCoolMsg struct { type SetTrendMsg struct {
Sender sdk.Address Sender sdk.Address
Cool string Cool string
} }
// New cool message // New cool message
func NewSetCoolMsg(sender sdk.Address, cool string) SetCoolMsg { func NewSetTrendMsg(sender sdk.Address, cool string) SetTrendMsg {
return SetCoolMsg{ return SetTrendMsg{
Sender: sender, Sender: sender,
Cool: cool, Cool: cool,
} }
} }
// enforce the msg type at compile time // enforce the msg type at compile time
var _ sdk.Msg = SetCoolMsg{} var _ sdk.Msg = SetTrendMsg{}
// nolint // nolint
func (msg SetCoolMsg) Type() string { return "cool" } func (msg SetTrendMsg) Type() string { return "cool" }
func (msg SetCoolMsg) Get(key interface{}) (value interface{}) { return nil } func (msg SetTrendMsg) Get(key interface{}) (value interface{}) { return nil }
func (msg SetCoolMsg) GetSigners() []sdk.Address { return []sdk.Address{msg.Sender} } func (msg SetTrendMsg) GetSigners() []sdk.Address { return []sdk.Address{msg.Sender} }
func (msg SetCoolMsg) String() string { func (msg SetTrendMsg) String() string {
return fmt.Sprintf("SetCoolMsg{Sender: %v, Cool: %v}", msg.Sender, msg.Cool) return fmt.Sprintf("SetTrendMsg{Sender: %v, Cool: %v}", msg.Sender, msg.Cool)
} }
// Validate Basic is used to quickly disqualify obviously invalid messages quickly // Validate Basic is used to quickly disqualify obviously invalid messages quickly
func (msg SetCoolMsg) ValidateBasic() sdk.Error { func (msg SetTrendMsg) ValidateBasic() sdk.Error {
if len(msg.Sender) == 0 { if len(msg.Sender) == 0 {
return sdk.ErrUnrecognizedAddress(msg.Sender).Trace("") return sdk.ErrUnrecognizedAddress(msg.Sender).Trace("")
} }
@ -49,7 +49,7 @@ func (msg SetCoolMsg) ValidateBasic() sdk.Error {
} }
// Get the bytes for the message signer to sign on // Get the bytes for the message signer to sign on
func (msg SetCoolMsg) GetSignBytes() []byte { func (msg SetTrendMsg) GetSignBytes() []byte {
b, err := json.Marshal(msg) b, err := json.Marshal(msg)
if err != nil { if err != nil {
panic(err) panic(err)
@ -59,34 +59,34 @@ func (msg SetCoolMsg) GetSignBytes() []byte {
//_______________________________________________________________________ //_______________________________________________________________________
// A really cool msg type, these fields are can be entirely arbitrary and // A message type to quiz how cool you are. these fields are can be entirely
// custom to your message // arbitrary and custom to your message
type TestYourCoolnessMsg struct { type QuizMsg struct {
Sender sdk.Address Sender sdk.Address
CoolerThanCool string CoolAnswer string
} }
// New cool message // New cool message
func NewTestYourCoolnessMsg(sender sdk.Address, coolerthancool string) TestYourCoolnessMsg { func NewQuizMsg(sender sdk.Address, coolerthancool string) QuizMsg {
return TestYourCoolnessMsg{ return QuizMsg{
Sender: sender, Sender: sender,
CoolerThanCool: coolerthancool, CoolAnswer: coolerthancool,
} }
} }
// enforce the msg type at compile time // enforce the msg type at compile time
var _ sdk.Msg = TestYourCoolnessMsg{} var _ sdk.Msg = QuizMsg{}
// nolint // nolint
func (msg TestYourCoolnessMsg) Type() string { return "cool" } func (msg QuizMsg) Type() string { return "cool" }
func (msg TestYourCoolnessMsg) Get(key interface{}) (value interface{}) { return nil } func (msg QuizMsg) Get(key interface{}) (value interface{}) { return nil }
func (msg TestYourCoolnessMsg) GetSigners() []sdk.Address { return []sdk.Address{msg.Sender} } func (msg QuizMsg) GetSigners() []sdk.Address { return []sdk.Address{msg.Sender} }
func (msg TestYourCoolnessMsg) String() string { func (msg QuizMsg) String() string {
return fmt.Sprintf("TestYourCoolnessMsg{Sender: %v, CoolerThanCool: %v}", msg.Sender, msg.CoolerThanCool) return fmt.Sprintf("QuizMsg{Sender: %v, CoolAnswer: %v}", msg.Sender, msg.CoolAnswer)
} }
// Validate Basic is used to quickly disqualify obviously invalid messages quickly // Validate Basic is used to quickly disqualify obviously invalid messages quickly
func (msg TestYourCoolnessMsg) ValidateBasic() sdk.Error { func (msg QuizMsg) ValidateBasic() sdk.Error {
if len(msg.Sender) == 0 { if len(msg.Sender) == 0 {
return sdk.ErrUnrecognizedAddress(msg.Sender).Trace("") return sdk.ErrUnrecognizedAddress(msg.Sender).Trace("")
} }
@ -94,7 +94,7 @@ func (msg TestYourCoolnessMsg) ValidateBasic() sdk.Error {
} }
// Get the bytes for the message signer to sign on // Get the bytes for the message signer to sign on
func (msg TestYourCoolnessMsg) GetSignBytes() []byte { func (msg QuizMsg) GetSignBytes() []byte {
b, err := json.Marshal(msg) b, err := json.Marshal(msg)
if err != nil { if err != nil {
panic(err) panic(err)