         #_(mw-logger/wrap-with-logger))))
 
 ;; launching and halting the app
-(defonce app-state {})
+(defonce app-state (atom {}))
 
 (defn connect-db [app-state]
   (if (:db app-state)


;; For running from the repl
(defn start []
  (alter-var-root #'app-state (comp launch connect-db)))

(defn stop []
  (alter-var-root #'app-state (comp disconnect-db halt)))

;; For running using lein-ring server
(defonce lein-ring-handler nil)

(defn lein-ring-init []
  (prn "lein-ring-init")
  (alter-var-root #'app-state connect-db)
  (alter-var-root #'lein-ring-handler
                  (fn [_] (let [config-m (config/create-config)
                                db (:db app-state)
                                stores-m (storage/create-mongo-stores db)

                            (create-app config-m stores-m blockchain)))))

(defn lein-ring-stop []
  (swap! app-state disconnect-db))
