   (:require [clojure.core.async :as casync]
             [clojure.tools.logging :as log]
             [cognitect.transit :as transit]
+            [datascript.core]
             [dato.db.utils :as dsu]
             [dato.lib.datomic :as datod]
             [dato.lib.incoming :as incoming]
+            [dato.lib.outgoing :as outgoing]
             [dato.lib.incoming-tx :as incoming-tx]
             [datomic.api :as d]
             [immutant.codecs :as cdc]

  (let [dato-server (:server config)
        tal-state (tal/init :transit-reader-opts {:handlers {"r"                (transit/read-handler (fn [s] (URI. s)))
                                                             "datascript/Datom" (transit/read-handler datascript-datom->datom)}}
                            :transit-writer-opts {:handlers {dato.lib.server.Datom (transit/write-handler (constantly "datascript/Datom")
                                                                                                          transit-rep)}})
        session-store all-sessions]
    (set-dato-route-heirarchy! (get-routing-table config))
    (def -tal-state tal-state)

(defmethod handle-websocket-msg :web-peer/transact
  [tal-state dato-config session-store msg]
  (let [reply (incoming-tx/handle-txes (get-dato-conn dato-config)
                                       {:tx/session-id (:tal/ch-id msg)}
                                       (-> msg :data :txes)
                                       (-> msg :data :guids)
                                       (get-dato-db dato-config)
                                       nil)]
    (tal/queue-reply! tal-state msg reply)))


