                 :accept :json
                 :form-params body})))
 
+;;--------------------------------------------------------------------------------------
+;; invokes a "query" operation on top of (post) and evaluates to a successful response
+;; or throws an exception
+;;--------------------------------------------------------------------------------------
 (defn- query [args]
   (let [{:keys [body]} (post (assoc args :method "query"))
         response (-> body (json/parse-string true) (select-keys [:result :error]))]

      (util/abort -1 (str response)))))

;;--------------------------------------------------------------------------------------
;; make-input-stream - factory function for creating an input-stream for a specific entry
;;
;; We install the necessary decompressor such that the output of this stream represents
;; raw, uncompressed original data
;;--------------------------------------------------------------------------------------
(defn- make-input-stream [data]
  (let [is (.newInput data)]
    (codecs/decompressor "gzip" is)))

(defn- get-interfaces [{:keys [host port] :as options}]
  (let [response (query (assoc options
                               :func "org.hyperledger.chaintool.meta/query/1"
                               :args (fl/protobuf GetInterfacesParams :IncludeContent (some? (:interfaces options)))))]

    (decode Interfaces response)))

(defn- get-facts [{:keys [host port] :as options}]
  (let [response (query (assoc options
                               :func "org.hyperledger.chaintool.meta/query/3"
                               :args (fl/protobuf GetFactsParams)))]

    (decode Facts response)))

(defn run [options]

  (println "Connecting to" (url options))


             (do
               (println "\t-" name)
               (when-let [path (:interfaces options)]
                 (let [is (->> data .newInput (codecs/decompressor "gzip"))
                       file (io/file path (str name ".cci"))]

                   (io/make-parents file)
