The court shall determine the validity of all liens filed, the amount due upon each, the amount due to the contractor, and if the amount due to the contractor be sufficient, shall order the public body to pay the amounts of all liens adjudged valid to the persons entitled to the same and the costs of the action and the residue, if any, to the contractor.
SDCL 5-22-5