 ;; disconnect
 ;; get-peer-address
 ;; connected?
-;; register-block-event
-;; register-chaincode-event
-;; register-tx-event
 ;; set-peer-address
 ;; unregister-block-event
 ;; unregister-chaincode-event

           :illegal-writeset
           :invalid-other-reason]))

;; Block event is proto/Block
(defrecord TxEvent [tx-id status])

(defn tx-id->channel [tx-id]
  :fixme)

(defn deliver-block-events-to-channels
  [^Common$Block proto-block]
  (let [clj-block (proto/proto->clj proto-block (proto/parse-trees :block))]
    ;; 1. Block Event on all channels
    (async/put! block-channel clj-block)
    (doseq [[data code] (map list
                             (:data clj-block)
                             (-> (:metadata clj-block)
                                 (:metadata)
                                 (nth (block-metadata-index-map :transactions-filter))
                                 (.toByteArray)))]
      (let [payload (get data :payload)
            channel-header (get-in payload [:header :channel-header])]
        ;; 2. Transaction Event with tx-id
        (when-let [ch (tx-id->channel tx-id)]
          (async/put! ch (make-TxEvent (:tx-id channel-header) code)))
        ;; 3. Chaincode event
        (when (= (:type channel-header) (proto/header-types :endorser-transaction))
          (let [chaincode-event (get-in payload [:data :actions 0 :payload :action
                                                 :proposal-response-payload :extension :events])]
            (when-let [ch (chaincode-id->channel (:chaincode-id chaincode-event))]
              (async/put! ch chaincode-event))))))))

(defn transaction-observer

(ns clojure-fabric.event-hub
  (:require [clojure-fabric.proto :as proto]
            [clojure-fabric.crypto-suite :as crypto]
            [clojure-fabric.utils :as utils]
            [clojure.core.async :as async]
            [clojure-fabric.core :as core])
  (:import io.grpc.stub.StreamObserver
           [clojure_fabric.proto Block ChaincodeEvent]
           [com.google.protobuf ByteString]
           io.grpc.ManagedChannel
           org.hyperledger.fabric.protos.msp.Identities$SerializedIdentity
