Collecting the History of Assets (continued)
Let’s now look into how the world state key modification impacts the blockchain data structure in Hyperledger Fabric.
Let’s perform the following sequence of chaincode executions:
Create a key-value pair: put("history", "key", "initial_value")
Update the value: put("history", "key", "updated_value")
Delete the key-value pair: del("history", "key")
Reuse the key once again after deletion: put("history", "key", "new_value")
Get the history of the key modifications: getHistory("history", "key")
You will receive a JSON containing an array of all historical records associated with our key. Of all the records, we are interested in the values and deletion flags, the examples of which are shown below.
{
"objectType": "history",
"key": "key",
"values" [{
"tx_id": "a632beac6289795e31f1507054c9f0936b125aa74ebcbd10446379dbd77bc69f",
"value": "new_value",
"isDelete": false
}, {
"tx_id": "9be4d02a9c0b1df3d9e3b8f7042f5a52d333fdb6a5825716e4ce9d14680e2d0a",
"value": "",
"isDelete": true
}, {
"tx_id": "c8c4c5bc049c0839aa097a0476d5444c3800ea9489667c5c55e8a8cd7f942aa3",
"value": "updated_value",
"isDelete": false
}, {
"tx_id": "4654547499ae3b1110c0371e073d077aad67322fc866a40dd3a4148053135b7b",
"value": "initial_value",
"isDelete": false
}]
}
From this sample, we can see that once the key is committed to the ledger, it has both a value and a deletion flag bound to it. Thus, when we want to remove the key from the world state, its value is simply changed to null in the blockchain, with the history remaining traceable. We cannot retrieve this key from the world state, because the deletion flag is set to true, preventing the key from being fetched into the world state. However, we can still use the same key further without any restrictions.
Last updated
Was this helpful?