Reputation: 6092
I would like to get some data from a chaincode transaction (too complex for a query), but, as I see from the code, transactions return promises that don't resolve to values. In addition, chaincode has access to the current user's identity, and I don't know how to implement this in a query.
The Util
class contains both invokeChainCode
and queryChainCode
methods, but the BusinessNetworkConnection
class has only the submitTransaction
transaction method that uses invokeChainCode
and doesn't return any value.
What is the correct way of getting data from the chaincode, apart from copying and modifying the code for submitTransaction
?
Upvotes: 1
Views: 2209
Reputation: 1644
As far as I can understand your question, you wish to return some values from a transaction.
Assuming that the transaction is of Invoke Type (not query) then whatever you are returning from the chain code (for example shim.Success(someData);
, it will be part of your transaction payload.)
So, in order to get that transaction payload from the transaction, you have to make sure its committed to the peer's ledger.
To be sure, just before you submit the transaction, you can subscribe to the transaction event using the given transaction id)
Once you receive this event you can be sure that your transaction is successfully committed in the peer.
You can use the same transaction ID you can query a peer for the transaction block.
Once you get the transaction payload in JSON you can dig into the JSON and find the return value in proposal response part of the JSON payload.
[P.S. Assuming you are using Node JS SDK]
EDIT 1:
Hyperledger Fabric supports only 2 types of transactions on a broader level.
So, in case you have read only transaction then you could just submit the transaction and get the proposal response payload from the peer(s). The proposal response itself is the result of your query invocation.
Upvotes: 2