Skip to content

Commit

Permalink
refactor, staking uses addresses instead of pubkey
Browse files Browse the repository at this point in the history
staking refactoring working

working
  • Loading branch information
rigelrozanski committed Mar 28, 2018
1 parent 292e156 commit dc86363
Show file tree
Hide file tree
Showing 12 changed files with 424 additions and 356 deletions.
2 changes: 1 addition & 1 deletion docs/spec/staking/old/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type Params struct {
ReserveTax rational.Rational // Tax collected on all fees

MaxVals uint16 // maximum number of validators
AllowedBondDenom string // bondable coin denomination
BondDenom string // bondable coin denomination

// gas costs for txs
GasDeclareCandidacy int64
Expand Down
18 changes: 9 additions & 9 deletions examples/basecoin/x/cool/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func (msg SetTrendMsg) String() string {
return fmt.Sprintf("SetTrendMsg{Sender: %v, Cool: %v}", msg.Sender, msg.Cool)
}

// Get the bytes for the message signer to sign on
func (msg SetTrendMsg) GetSignBytes() []byte {
b, err := json.Marshal(msg)
if err != nil {
panic(err)
}
return b
}

// Validate Basic is used to quickly disqualify obviously invalid messages quickly
func (msg SetTrendMsg) ValidateBasic() sdk.Error {
if len(msg.Sender) == 0 {
Expand All @@ -48,15 +57,6 @@ func (msg SetTrendMsg) ValidateBasic() sdk.Error {
return nil
}

// Get the bytes for the message signer to sign on
func (msg SetTrendMsg) GetSignBytes() []byte {
b, err := json.Marshal(msg)
if err != nil {
panic(err)
}
return b
}

//_______________________________________________________________________

// A message type to quiz how cool you are. these fields are can be entirely
Expand Down
15 changes: 7 additions & 8 deletions types/rational.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types

import (
"errors"
"math/big"
"strconv"
"strings"
Expand Down Expand Up @@ -57,7 +56,7 @@ func NewRat(Numerator int64, Denominator ...int64) Rat {
}

//NewFromDecimal - create a rational from decimal string or integer string
func NewRatFromDecimal(decimalStr string) (f Rat, err error) {
func NewRatFromDecimal(decimalStr string) (f Rat, err Error) {

// first extract any negative symbol
neg := false
Expand All @@ -73,23 +72,23 @@ func NewRatFromDecimal(decimalStr string) (f Rat, err error) {
switch len(str) {
case 1:
if len(str[0]) == 0 {
return f, errors.New("not a decimal string")
return f, NewError(CodeUnknownRequest, "not a decimal string")
}
numStr = str[0]
case 2:
if len(str[0]) == 0 || len(str[1]) == 0 {
return f, errors.New("not a decimal string")
return f, NewError(CodeUnknownRequest, "not a decimal string")
}
numStr = str[0] + str[1]
len := int64(len(str[1]))
denom = new(big.Int).Exp(big.NewInt(10), big.NewInt(len), nil).Int64()
default:
return f, errors.New("not a decimal string")
return f, NewError(CodeUnknownRequest, "not a decimal string")
}

num, err := strconv.Atoi(numStr)
if err != nil {
return f, err
num, errConv := strconv.Atoi(numStr)
if errConv != nil {
return f, NewError(CodeUnknownRequest, errConv.Error())
}

if neg {
Expand Down
1 change: 1 addition & 0 deletions types/tx_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ type StdSignMsg struct {
// XXX: Alt
}

// get message bytes
func (msg StdSignMsg) Bytes() []byte {
return StdSignBytes(msg.ChainID, msg.Sequences, msg.Fee, msg.Msg)
}
Expand Down
8 changes: 4 additions & 4 deletions x/stake/commands/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func cmdDeclareCandidacy(cmd *cobra.Command, args []string) error {
Details: viper.GetString(FlagDetails),
}

tx := stake.NewTxDeclareCandidacy(amount, pk, description)
tx := stake.NewMsgDeclareCandidacy(amount, pk, description)
return doTx(tx)
}

Expand All @@ -125,7 +125,7 @@ func cmdEditCandidacy(cmd *cobra.Command, args []string) error {
Details: viper.GetString(FlagDetails),
}

tx := stake.NewTxEditCandidacy(pk, description)
tx := stake.NewMsgEditCandidacy(pk, description)
return doTx(tx)
}

Expand All @@ -140,7 +140,7 @@ func cmdDelegate(cmd *cobra.Command, args []string) error {
return err
}

tx := stake.NewTxDelegate(amount, pk)
tx := stake.NewMsgDelegate(amount, pk)
return doTx(tx)
}

Expand All @@ -167,7 +167,7 @@ func cmdUnbond(cmd *cobra.Command, args []string) error {
return err
}

tx := stake.NewTxUnbond(sharesStr, pk)
tx := stake.NewMsgUnbond(sharesStr, pk)
return doTx(tx)
}

Expand Down
31 changes: 17 additions & 14 deletions x/stake/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,49 @@ func codeToDefaultMsg(code CodeType) string {
//----------------------------------------
// Error constructors

func ErrCandidateEmpty() error {
func ErrCandidateEmpty() sdk.Error {
return newError(CodeInvalidValidator, "Cannot bond to an empty candidate")
}
func ErrBadBondingDenom() error {
func ErrBadBondingDenom() sdk.Error {
return newError(CodeInvalidValidator, "Invalid coin denomination")
}
func ErrBadBondingAmount() error {
func ErrBadBondingAmount() sdk.Error {
return newError(CodeInvalidValidator, "Amount must be > 0")
}
func ErrNoBondingAcct() error {
func ErrNoBondingAcct() sdk.Error {
return newError(CodeInvalidValidator, "No bond account for this (address, validator) pair")
}
func ErrCommissionNegative() error {
func ErrCommissionNegative() sdk.Error {
return newError(CodeInvalidValidator, "Commission must be positive")
}
func ErrCommissionHuge() error {
func ErrCommissionHuge() sdk.Error {
return newError(CodeInvalidValidator, "Commission cannot be more than 100%")
}
func ErrBadValidatorAddr() error {
func ErrBadValidatorAddr() sdk.Error {
return newError(CodeInvalidValidator, "Validator does not exist for that address")
}
func ErrCandidateExistsAddr() error {
func ErrBadCandidateAddr() sdk.Error {
return newError(CodeInvalidValidator, "Candidate does not exist for that address")
}
func ErrCandidateExistsAddr() sdk.Error {
return newError(CodeInvalidValidator, "Candidate already exist, cannot re-declare candidacy")
}
func ErrMissingSignature() error {
func ErrMissingSignature() sdk.Error {
return newError(CodeInvalidValidator, "Missing signature")
}
func ErrBondNotNominated() error {
func ErrBondNotNominated() sdk.Error {
return newError(CodeInvalidValidator, "Cannot bond to non-nominated account")
}
func ErrNoCandidateForAddress() error {
func ErrNoCandidateForAddress() sdk.Error {
return newError(CodeInvalidValidator, "Validator does not exist for that address")
}
func ErrNoDelegatorForAddress() error {
func ErrNoDelegatorForAddress() sdk.Error {
return newError(CodeInvalidValidator, "Delegator does not contain validator bond")
}
func ErrInsufficientFunds() error {
func ErrInsufficientFunds() sdk.Error {
return newError(CodeInvalidValidator, "Insufficient bond shares")
}
func ErrBadRemoveValidator() error {
func ErrBadRemoveValidator() sdk.Error {
return newError(CodeInvalidValidator, "Error removing validator")
}

Expand Down
Loading

0 comments on commit dc86363

Please sign in to comment.