Smart Contract Templates: Legal semantics and code validation