consensus: proto migration (#4984)

## Description

migrate consensus to protobuf

Closes: #XXX
This commit is contained in:
Marko
2020-06-10 14:08:47 +02:00
committed by GitHub
parent 5697e144a7
commit d54de61bf6
20 changed files with 873 additions and 217 deletions

View File

@@ -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
}