问题
I am trying to get the operation which is responsible for the new state. In simple words, I want to get the function name passed to the invoke method. When I am looking into the historical states I am able to fetch its value, timestamp, transaction ID, etc. but not the parameters which are responsible for that transaction.
I know we can get the parameters from the block history, but I need it for the states.
Is there any way to achieve this from the chaincode side?
回答1:
Yes, from the chaincode you can create an Invoke endpoint and do like:
func (s *SmartContract) Invoke(APIstub shim.ChaincodeStubInterface) sc.Response {
function, args := APIstub.GetFunctionAndParameters()
}
Here you got everything you want. For example if you print function you will see the name of the function you invoked.
回答2:
I would like to know about your approach as well. However this would be my take on this,we can probably register an event listener in our sdk (using registerChaincodeEvent method) and create an Event (using setEvent method) in our chaincode ,wherein our payload would be the result from getFunctionAndParameters method. And you can probably keep storing these results into a datastore to later fetch them all.
Alternatively: You can simply send back the result of getFunctionAndParameters as a key in the response object via shim.success.
来源:https://stackoverflow.com/questions/59194606/how-to-get-the-parameters-passed-to-the-transaction-for-the-historical-states