用户可能注意到,发往网络的请求是异步处理模式,这就意味着客户端无法获知提交的交易是否最终接受。Fabric 在 Peer 节点上提供了事件 gRPC 服务,用户可以通过客户端来监听。
$ cd $GOPATH/src/hyperledger/fabric/examples/events/eventsclient
$ go install && go clean
$ eventsclient \
-server=${PEER_URL} \
-channelID=${APP_CHANNEL} \
-filtered=true \
-tls=true \
-clientKey=${TLS_CLIENT_KEY} \
-clientCert=${TLS_CLIENT_CERT} \
-rootCert=${TLS_CA_CERT}
$ CORE_PEER_LOCALMSPID=Org1MSP \
CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp \
eventsclient \
-server=peer0.org1.example.com:7051 \
-channelID=businesschannel \
-filtered=true \
-tls=true \
-clientKey=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org1.example.com/users/Admin@Org1.example.com/tls/client.key \
-clientCert=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org1.example.com/users/Admin@Org1.example.com/tls/client.crt \
-rootCert=/etc/hyperledger/fabric/crypto-config/peerOrganizations/org1.example.com/users/Admin@Org1.example.com/tls/ca.crt
UTC [eventsclient] readEventsStream -> INFO 001 Received filtered block:
{
"channel_id": "businesschannel",
"filtered_transactions": [
{
"tx_validation_code": "VALID",
"txid": "",
"type": "CONFIG"
}
],
"number": "0"
}
UTC [eventsclient] readEventsStream -> INFO 002 Received filtered block:
{
"channel_id": "businesschannel",
"filtered_transactions": [
{
"tx_validation_code": "VALID",
"txid": "",
"type": "CONFIG"
}
],
"number": "1"
}
UTC [eventsclient] readEventsStream -> INFO 003 Received filtered block:
{
"channel_id": "businesschannel",
"filtered_transactions": [
{
"tx_validation_code": "VALID",
"txid": "",
"type": "CONFIG"
}
],
"number": "2"
}
UTC [eventsclient] readEventsStream -> INFO 004 Received filtered block:
{
"channel_id": "businesschannel",
"filtered_transactions": [
{
"transaction_actions": {
"chaincode_actions": []
},
"tx_validation_code": "VALID",
"txid": "2832892094f612237b06950b77a6afc13ca9226176e99c2a8577cf4be2074c0a",
"type": "ENDORSER_TRANSACTION"
}
],
"number": "3"
}
UTC [eventsclient] readEventsStream -> INFO 005 Received filtered block:
{
"channel_id": "businesschannel",
"filtered_transactions": [
{
"transaction_actions": {
"chaincode_actions": []
},
"tx_validation_code": "VALID",
"txid": "fec547335060bb324e8e4a08067c7fa24092e1295cb62dffb14a93bc77b2fbcf",
"type": "ENDORSER_TRANSACTION"
}
],
"number": "4"
}
...