stackitem: change Bool() to TryBool(), prepare for its failures

This commit is contained in:
Roman Khimov 2020-08-21 20:55:20 +03:00
parent 790693fc6d
commit a7670303e8
7 changed files with 65 additions and 45 deletions

View file

@ -80,9 +80,14 @@ func (e *Element) BigInt() *big.Int {
return val
}
// Bool converts an underlying value of the element to a boolean.
// Bool converts an underlying value of the element to a boolean if it's
// possible to do so, it will panic otherwise.
func (e *Element) Bool() bool {
return e.value.Bool()
b, err := e.value.TryBool()
if err != nil {
panic(err)
}
return b
}
// Bytes attempts to get the underlying value of the element as a byte array.