package validation import ( "errors" "math/big" "github.com/ethereum/go-ethereum/common" ) var ( // ErrZeroAddress is returned when a zero address is provided ErrZeroAddress = errors.New("zero address not allowed") // ErrNilAddress is returned when a nil address pointer is provided ErrNilAddress = errors.New("nil address pointer") // ErrZeroAmount is returned when a zero amount is provided ErrZeroAmount = errors.New("zero amount not allowed") // ErrNilAmount is returned when a nil amount pointer is provided ErrNilAmount = errors.New("nil amount pointer") // ErrNegativeAmount is returned when a negative amount is provided ErrNegativeAmount = errors.New("negative amount not allowed") ) // ValidateAddress validates that an address is not zero func ValidateAddress(addr common.Address) error { if addr == (common.Address{}) { return ErrZeroAddress } return nil } // ValidateAddressPtr validates that an address pointer is not nil and not zero func ValidateAddressPtr(addr *common.Address) error { if addr == nil { return ErrNilAddress } if *addr == (common.Address{}) { return ErrZeroAddress } return nil } // ValidateAmount validates that an amount is not nil, not zero, and not negative func ValidateAmount(amount *big.Int) error { if amount == nil { return ErrNilAmount } if amount.Sign() == 0 { return ErrZeroAmount } if amount.Sign() < 0 { return ErrNegativeAmount } return nil } // ValidateAmountAllowZero validates that an amount is not nil and not negative // (allows zero amounts for optional parameters) func ValidateAmountAllowZero(amount *big.Int) error { if amount == nil { return ErrNilAmount } if amount.Sign() < 0 { return ErrNegativeAmount } return nil } // IsZeroAddress checks if an address is zero without returning an error func IsZeroAddress(addr common.Address) bool { return addr == (common.Address{}) } // IsZeroAmount checks if an amount is zero or nil without returning an error func IsZeroAmount(amount *big.Int) bool { return amount == nil || amount.Sign() == 0 }