hyperledger-fabrichyperledger-chaincode

Hypeledger fabric chaincode, strange behavior while making a transaction


I have a really weird behavior, so basically I make a transaction, the transaction is visible in explorer, the asset is added only once. But can be updated just like the asset-transfer-basic chain code, so I checked the transaction if it is there.

I got no result, added the asset again, but nothing, I see the transaction on explorer, but I can't add, and the AssetExist return false, meaning the asset has not been created?

Any similar behavior you guys have?

thanks in advance.

peer chaincode query -C assets -n basicasset -c '{"Args":["AddAsset","112233","asset01","123","asset01@email.test","+32323232323","adress 54","24","male","0","yes"]}'

peer chaincode query -C assets -n basicasset -c '{"Args":["GetAllAssets"]}'

And i have the log with completed transaction

2022-05-03T16:43:23.249Z info [c-api:lib/handler.js]                              [users-1c1d1d2f] Calling chaincode Invoke() succeeded. Sending COMPLETED message back to peer
2022-05-03T16:43:32.914Z info [c-api:lib/handler.js]                              [users-03399546] Calling chaincode Invoke() succeeded. Sending COMPLETED message back to peer
2022-05-03T16:45:17.563Z info [c-api:lib/handler.js]                              [users-da06502d] Calling chaincode Invoke() succeeded. Sending COMPLETED message back to peer

Solution

  • You are executing a query (or "evaluating" a transaction). Here your client is sending a transaction proposal, which is executed by the smart contract, and a proposal response is returned. Amongst other things, this proposal response contains the return value from the transaction, so you can see the result of executing the transaction but nothing has been written to the ledger.

    To update the ledger you need to invoke the transaction (or "submit" the transaction). This sends proposals to peers and obtains (endorsed) proposal responses, similar to when you evaluate a transaction. However, this endorsed transaction is then sent to the orderers to be committed into a block, which is then distributed to peers, and they (assuming the transaction passes validation) apply the transaction updates to the ledger.

    In summary, you are not seeing any ledger updates because you are not updating the ledger. You are only querying ledger state.