Merge pull request #686 from cosmos/bucky/staking-fixes
x/staking: check for empty stake and pubkey
This commit is contained in:
commit
946b764d7b
|
@ -53,19 +53,30 @@ func (co commander) bondTxCmd(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
stake, err := sdk.ParseCoin(viper.GetString(flagStake))
|
||||
stakeString := viper.GetString(flagStake)
|
||||
if len(stakeString) == 0 {
|
||||
return fmt.Errorf("specify coins to bond with --stake")
|
||||
}
|
||||
|
||||
valString := viper.GetString(flagValidator)
|
||||
if len(valString) == 0 {
|
||||
return fmt.Errorf("specify pubkey to bond to with --validator")
|
||||
}
|
||||
|
||||
stake, err := sdk.ParseCoin(stakeString)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rawPubKey, err := hex.DecodeString(viper.GetString(flagValidator))
|
||||
// TODO: bech32 ...
|
||||
rawPubKey, err := hex.DecodeString(valString)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var pubKey crypto.PubKeyEd25519
|
||||
copy(pubKey[:], rawPubKey)
|
||||
var pubKeyEd crypto.PubKeyEd25519
|
||||
copy(pubKeyEd[:], rawPubKey)
|
||||
|
||||
msg := staking.NewBondMsg(from, stake, pubKey.Wrap())
|
||||
msg := staking.NewBondMsg(from, stake, pubKeyEd.Wrap())
|
||||
|
||||
return co.sendMsg(msg)
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ func (sm StakingMapper) deleteBondInfo(ctx sdk.Context, addr sdk.Address) {
|
|||
}
|
||||
|
||||
func (sm StakingMapper) Bond(ctx sdk.Context, addr sdk.Address, pubKey crypto.PubKey, power int64) (int64, sdk.Error) {
|
||||
|
||||
bi := sm.getBondInfo(ctx, addr)
|
||||
if bi.isEmpty() {
|
||||
bi = bondInfo{
|
||||
|
|
|
@ -34,6 +34,10 @@ func (msg BondMsg) ValidateBasic() sdk.Error {
|
|||
return ErrEmptyStake()
|
||||
}
|
||||
|
||||
if msg.PubKey.Empty() {
|
||||
return sdk.ErrInvalidPubKey("BondMsg.PubKey must not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue