mirror of
https://github.com/tendermint/tendermint.git
synced 2026-04-29 03:46:57 +00:00
consensus: proto migration (#4984)
## Description migrate consensus to protobuf Closes: #XXX
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
)
|
||||
|
||||
var ErrOverflowInt32 = errors.New("int32 overflow")
|
||||
var ErrOverflowUint8 = errors.New("uint8 overflow")
|
||||
|
||||
// SafeAddInt32 adds two int32 integers
|
||||
// If there is an overflow this will panic
|
||||
@@ -39,3 +40,14 @@ func SafeConvertInt32(a int64) int32 {
|
||||
}
|
||||
return int32(a)
|
||||
}
|
||||
|
||||
// SafeConvertUint8 takes an int64 and checks if it overflows
|
||||
// If there is an overflow it returns an error
|
||||
func SafeConvertUint8(a int64) (uint8, error) {
|
||||
if a > math.MaxUint8 {
|
||||
return 0, ErrOverflowUint8
|
||||
} else if a < 0 {
|
||||
return 0, ErrOverflowUint8
|
||||
}
|
||||
return uint8(a), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user