Multi-line commands in the ensure constraint

I am using an ensure constraint to check whether the original owner of the Wallet is the only one who can create an UpgradeWallet template for their wallet. This is what I have:

template UpgradeWallet
        owner : Party
        public : [Party]
        oldWalletId : ContractId Wallet
        signatory owner
        observer public
            (let walletTest = (
                        oldWallet <- fetch @Wallet oldWalletId
                        if oldWallet.owner == owner then pure True else pure False)

However, I am getting the parse error on input error in the closing bracket. I understand that this is because the let command doesn’t returns anything and just assigns the value to the walletTest variable. Can I somehow make the ensure constraint check the value of walletTest variable for it’s boolean check?

This is not a kind of constraint you can use ensure for. ensure is a pure expression (i.e. no fetch allowed) that can only validate the self-consistency of the contract being created.

In other words, the ensure expression can be thought of as a function of type (in this case) UpgradeWallet -> Bool.

This kind of constraint must be enforced through choices and their signatories. In effect, you cannot say “this invalid contract cannot exist on the ledger”, but you have to instead say “each user can choose the set of parties they trust to have verified the validity of these contracts”.