Date
1 - 5 of 5
Fabric-sdk-jAVA #fabric-sdk-java
Mark Lewis
The ContractEvent (fabric-gateway-java) and ChaincodeEvent (Fabric Gateway client API) that get delivered to you by contract/chaincode event listening both have getPayload() methods. Similar to the values returned by transaction invocation, these are binary (byte[]) payloads containing whatever data your smart contract put there. If it's string data you might want to turn it back into a string to view it. If it's JSON data, you might want to use a JSON parser.
If you really want to, you can extract the chaincode events from block events yourself. I would suggest looking at the fabric-gateway-java source to see how this is done: https://github.com/hyperledger/fabric-gateway-java/blob/9389ffb2b5ff2f6fb4387687479ff332697ad1ff/src/main/java/org/hyperledger/fabric/gateway/impl/event/Listeners.java#L31-L49 The chaincode event listening provided by the Fabric Gateway client API actually uses a new service to directly retrieve only the chaincode events from the peer, precisely to avoid the overhead of retrieving the large amount of additional data contained in the block event, and the work of parsing that extremely complex data structure to extract the chaincode event at the client end. |
|
jeff.jo95z@...
is it possible to extract this from the blockevent itself?
|
|
jeff.jo95z@...
data appears like this:
\tassetTest\\022\\030\\n\\026\\n\\020\\000\\364\\217\\277\\277initialized\\022\\002\\b\\026\\022\\301\\001\\n\\tassetTest\\022@612b449bdcc554261c663ba2bc67048ca74e3f6944a9f9b5ce6cb557ffaee5e1\\032\\027CreatePrivateAssetEvent\\\"Y{\\\"VCID\\\":\\\"vcp326\\\",\\\"SenderKid\\\":\\\"senId100\\\",\\\"ReceiverKid\\\":\\\"rec100\\\",\\\"IsNotificationMsg\\\":\\\"yes\\\"}\\032!\\b\\310\\001\\032\\034\ this is the event:CreatePrivateAssetEvent I want to extract this |
|
Mark Lewis
You can add a chaincode / contract listener instead of a block listener and receive only the chaincode events. Use addContractListener() method on your Contract object:
https://hyperledger.github.io/fabric-gateway-java/release-2.2/org/hyperledger/fabric/gateway/Contract.html If using Fabric v2.4 (or later) the Fabric Gateway client API provides an equivalent getChaincodeEvents() method on the Network object: https://hyperledger.github.io/fabric-gateway/main/api/java/org/hyperledger/fabric/client/Network.html |
|
jeff.jo95z@...
In the chaincode,an event is emitted.
In the blockdata from the blockevent listener,the event data is visible. Is it possible to extract just the event data from the blockdata? |
|