github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/examples/events/block-listener/README.md (about)

     1  # What is block-listener
     2  block-listener.go will connect to a peer and receive blocks events, transaction rejection events and chaincode events (if a chaincode emits events).
     3  
     4  # To Run
     5  ```sh
     6  1. go build
     7  
     8  2. ./block-listener -events-address=< event address > -listen-to-rejections=< true | false > -events-from-chaincode=< chaincode ID >
     9  ```
    10  
    11  # Example with PBFT
    12  
    13  ## Run 4 docker peers with PBFT
    14  ```sh
    15  docker run --rm -it -e CORE_VM_ENDPOINT=http://172.17.0.1:2375 -e CORE_PEER_ID=vp0 -e CORE_PEER_ADDRESSAUTODETECT=true -e CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft hyperledger/fabric-peer peer node start
    16  
    17  docker run --rm -it -e CORE_VM_ENDPOINT=http://172.17.0.1:2375 -e CORE_PEER_ID=vp1 -e CORE_PEER_ADDRESSAUTODETECT=true -e CORE_PEER_DISCOVERY_ROOTNODE=172.17.0.2:7051 -e CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft hyperledger/fabric-peer peer node start
    18  
    19  docker run --rm -it -e CORE_VM_ENDPOINT=http://172.17.0.1:2375 -e CORE_PEER_ID=vp2 -e CORE_PEER_ADDRESSAUTODETECT=true -e CORE_PEER_DISCOVERY_ROOTNODE=172.17.0.2:7051 -e CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft hyperledger/fabric-peer peer node start
    20  
    21  docker run --rm -it -e CORE_VM_ENDPOINT=http://172.17.0.1:2375 -e CORE_PEER_ID=vp3 -e CORE_PEER_ADDRESSAUTODETECT=true -e CORE_PEER_DISCOVERY_ROOTNODE=172.17.0.2:7051 -e CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft hyperledger/fabric-peer peer node start
    22  
    23  ## Attach event client to a Peer
    24  ```sh
    25  ./block-listener -events-address=172.17.0.2:7053 -listen-to-rejections=true
    26  ```
    27  
    28  Event client should output "Event Address: 172.17.0.2:7053" and wait for events.
    29  
    30  ## Create a deploy transaction
    31  Submit a transaction to deploy chaincode_example02.
    32  
    33  ```sh
    34  CORE_PEER_ADDRESS=172.17.0.2:7051 peer chaincode deploy -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Function":"init", "Args": ["a","100", "b", "200"]}'
    35  ```
    36  
    37  Notice success transaction in the events client.
    38  
    39  ## Create an invoke transaction - good
    40  Send a valid invoke transaction to chaincode_example02.
    41  
    42  ```sh
    43  CORE_PEER_ADDRESS=172.17.0.2:7051 peer chaincode invoke -n 1edd7021ab71b766f4928a9ef91182c018dffb86fef7a4b5a5516ac590a87957e21a62d939df817f5105f524abddcddfc7b1a60d780f02d8235bd7af9db81b66 -c '{"Function":"invoke", "Args": ["a","b","10"]}'
    44  ```
    45  Notice success transaction in events client.
    46  
    47  ## Create an invoke transaction - bad
    48  Send an invoke transaction with invalid parameters to chaincode_example02.
    49  
    50  ```sh
    51  CORE_PEER_ADDRESS=172.17.0.2:7051 peer chaincode invoke -n 1edd7021ab71b766f4928a9ef91182c018dffb86fef7a4b5a5516ac590a87957e21a62d939df817f5105f524abddcddfc7b1a60d780f02d8235bd7af9db81b66 -c '{"Function":"invoke", "Args": ["a","b"]}'
    52  ```
    53  
    54  Notice error transaction in events client.
    55  
    56  # Tesing chaincode events
    57  Chaincode github.com/hyperledger/fabric/examples/chaincode/go/eventsender can be used to test event sender.
    58  ## Deploy eventsender chaincode
    59  Stop the event listener and restart it as follows
    60  
    61  ```
    62  CORE_PEER_ADDRESS=172.17.0.2:7051 ./peer chaincode deploy -p github.com/hyperledger/fabric/examples/chaincode/go/eventsender -c '{"Function":"init", "Args":[]}'
    63  ```
    64  
    65  ```
    66  Note the chaincode ID of the eventsender chaincode. This will be used in the commands below.
    67  ```
    68  ## Restart event listener
    69  Stop the event listener if running and restart it with `-events-from-chaincode` option
    70  
    71  ```sh
    72  ./block-listener -events-address=172.17.0.2:7053 -listen-to-rejections=true -events-from-chaincode=< event sender chaincode ID>
    73  ```
    74  
    75  
    76  ##Send an invoke request to event sender
    77  
    78  ```sh
    79  CORE_PEER_ADDRESS=172.17.0.2:7051 ./peer chaincode invoke -n < eventsender chaincode ID > -c '{"Function":"greet", "Args":["hello","world"]}'
    80  ```
    81  
    82  Note the output from the event listener terminal showing a chaincode event from the event sender chaincode in addition to the block event generated by the transaction.