<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_batch_unlock( end_state: NettingChannelEndState, ) -> Optional[MerkleTreeLeaves]: """ Unlock proof for an entire merkle tree of pending locks The unlock proof contains all the merkle tree data, tightly packed, needed by the token network contract to verify the secret expiry and calculate the token amounts to transfer. """


    if len(end_state.merkletree.layers[LEAVES]) == 0:  # pylint: disable=len-as-condition
        return None

    lockhashes_to_locks = dict()
    lockhashes_to_locks.update({
        lock.lockhash: lock
        for secrethash, lock in end_state.secrethashes_to_lockedlocks.items()
    })
    lockhashes_to_locks.update({
        proof.lock.lockhash: proof.lock
        for secrethash, proof in end_state.secrethashes_to_unlockedlocks.items()
    })
    lockhashes_to_locks.update({
        proof.lock.lockhash: proof.lock
        for secrethash, proof in end_state.secrethashes_to_onchain_unlockedlocks.items()
    })

    ordered_locks = [
        lockhashes_to_locks[LockHash(lockhash)]
        for lockhash in end_state.merkletree.layers[LEAVES]
    ]

    # Not sure why the cast is needed here. The error was:
    # Incompatible return value type
    # (got "List[HashTimeLockState]", expected "Optional[MerkleTreeLeaves]")
    return cast(MerkleTreeLeaves, ordered_locks)