|
@ -3,6 +3,7 @@ package dummy |
|
|
import ( |
|
|
import ( |
|
|
"bytes" |
|
|
"bytes" |
|
|
"encoding/hex" |
|
|
"encoding/hex" |
|
|
|
|
|
"fmt" |
|
|
"strconv" |
|
|
"strconv" |
|
|
"strings" |
|
|
"strings" |
|
|
|
|
|
|
|
@ -135,7 +136,7 @@ func LoadLastBlock(db dbm.DB) (lastBlock LastBlockInfo) { |
|
|
wire.ReadBinaryPtr(&lastBlock, r, 0, n, err) |
|
|
wire.ReadBinaryPtr(&lastBlock, r, 0, n, err) |
|
|
if *err != nil { |
|
|
if *err != nil { |
|
|
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
|
|
|
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
|
|
|
common.Exit(common.Fmt("Data has been corrupted or its spec has changed: %v\n", *err)) |
|
|
|
|
|
|
|
|
common.Exit(fmt.Sprintf("Data has been corrupted or its spec has changed: %v\n", *err)) |
|
|
} |
|
|
} |
|
|
// TODO: ensure that buf is completely read.
|
|
|
// TODO: ensure that buf is completely read.
|
|
|
} |
|
|
} |
|
@ -173,7 +174,7 @@ func (app *PersistentDummyApplication) Validators() (validators []*types.Validat |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func MakeValSetChangeTx(pubkey []byte, power uint64) []byte { |
|
|
func MakeValSetChangeTx(pubkey []byte, power uint64) []byte { |
|
|
return []byte(common.Fmt("val:%X/%d", pubkey, power)) |
|
|
|
|
|
|
|
|
return []byte(fmt.Sprintf("val:%X/%d", pubkey, power)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func isValidatorTx(tx []byte) bool { |
|
|
func isValidatorTx(tx []byte) bool { |
|
@ -188,16 +189,16 @@ func (app *PersistentDummyApplication) execValidatorTx(tx []byte) types.Result { |
|
|
tx = tx[len(ValidatorSetChangePrefix):] |
|
|
tx = tx[len(ValidatorSetChangePrefix):] |
|
|
pubKeyAndPower := strings.Split(string(tx), "/") |
|
|
pubKeyAndPower := strings.Split(string(tx), "/") |
|
|
if len(pubKeyAndPower) != 2 { |
|
|
if len(pubKeyAndPower) != 2 { |
|
|
return types.ErrEncodingError.SetLog(common.Fmt("Expected 'pubkey/power'. Got %v", pubKeyAndPower)) |
|
|
|
|
|
|
|
|
return types.ErrEncodingError.SetLog(fmt.Sprintf("Expected 'pubkey/power'. Got %v", pubKeyAndPower)) |
|
|
} |
|
|
} |
|
|
pubkeyS, powerS := pubKeyAndPower[0], pubKeyAndPower[1] |
|
|
pubkeyS, powerS := pubKeyAndPower[0], pubKeyAndPower[1] |
|
|
pubkey, err := hex.DecodeString(pubkeyS) |
|
|
pubkey, err := hex.DecodeString(pubkeyS) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return types.ErrEncodingError.SetLog(common.Fmt("Pubkey (%s) is invalid hex", pubkeyS)) |
|
|
|
|
|
|
|
|
return types.ErrEncodingError.SetLog(fmt.Sprintf("Pubkey (%s) is invalid hex", pubkeyS)) |
|
|
} |
|
|
} |
|
|
power, err := strconv.Atoi(powerS) |
|
|
power, err := strconv.Atoi(powerS) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return types.ErrEncodingError.SetLog(common.Fmt("Power (%s) is not an int", powerS)) |
|
|
|
|
|
|
|
|
return types.ErrEncodingError.SetLog(fmt.Sprintf("Power (%s) is not an int", powerS)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// update
|
|
|
// update
|
|
@ -210,14 +211,14 @@ func (app *PersistentDummyApplication) updateValidator(v *types.Validator) types |
|
|
if v.Power == 0 { |
|
|
if v.Power == 0 { |
|
|
// remove validator
|
|
|
// remove validator
|
|
|
if !app.app.state.Has(key) { |
|
|
if !app.app.state.Has(key) { |
|
|
return types.ErrUnauthorized.SetLog(common.Fmt("Cannot remove non-existent validator %X", key)) |
|
|
|
|
|
|
|
|
return types.ErrUnauthorized.SetLog(fmt.Sprintf("Cannot remove non-existent validator %X", key)) |
|
|
} |
|
|
} |
|
|
app.app.state.Remove(key) |
|
|
app.app.state.Remove(key) |
|
|
} else { |
|
|
} else { |
|
|
// add or update validator
|
|
|
// add or update validator
|
|
|
value := bytes.NewBuffer(make([]byte, 0)) |
|
|
value := bytes.NewBuffer(make([]byte, 0)) |
|
|
if err := types.WriteMessage(v, value); err != nil { |
|
|
if err := types.WriteMessage(v, value); err != nil { |
|
|
return types.ErrInternalError.SetLog(common.Fmt("Error encoding validator: %v", err)) |
|
|
|
|
|
|
|
|
return types.ErrInternalError.SetLog(fmt.Sprintf("Error encoding validator: %v", err)) |
|
|
} |
|
|
} |
|
|
app.app.state.Set(key, value.Bytes()) |
|
|
app.app.state.Set(key, value.Bytes()) |
|
|
} |
|
|
} |
|
|