errors.go 936 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package vm
  2. import (
  3. "fmt"
  4. "github.com/ethereum/go-ethereum/params"
  5. "math/big"
  6. )
  7. type OutOfGasError struct {
  8. req, has *big.Int
  9. }
  10. func OOG(req, has *big.Int) OutOfGasError {
  11. return OutOfGasError{req, has}
  12. }
  13. func (self OutOfGasError) Error() string {
  14. return fmt.Sprintf("out of gas! require %v, have %v", self.req, self.has)
  15. }
  16. func IsOOGErr(err error) bool {
  17. _, ok := err.(OutOfGasError)
  18. return ok
  19. }
  20. type StackError struct {
  21. req, has int
  22. }
  23. func StackErr(req, has int) StackError {
  24. return StackError{req, has}
  25. }
  26. func (self StackError) Error() string {
  27. return fmt.Sprintf("stack error! require %v, have %v", self.req, self.has)
  28. }
  29. func IsStack(err error) bool {
  30. _, ok := err.(StackError)
  31. return ok
  32. }
  33. type DepthError struct{}
  34. func (self DepthError) Error() string {
  35. return fmt.Sprintf("Max call depth exceeded (%d)", params.CallCreateDepth)
  36. }
  37. func IsDepthErr(err error) bool {
  38. _, ok := err.(DepthError)
  39. return ok
  40. }