How Smart Contracts Work: The Logic Behind Blockchain Automation