1

on tzkt, the bigmap diffs have an action field which takes values like remove_key, add_key, update_key, etc.

the lazy_storage_diff field in RPC JSON doesn't seem to have these same values, instead it seems like the action is mostly update. for a concrete example:

two of the bigmap diffs for this transaction are:

{
  "bigmap": 21409,
  "path": "names_taken",
  "action": "remove_key",
  ...
},
{
  "bigmap": 21409,
  "path": "names_taken",
  "action": "add_key",
  ...
}

however if you check the RPC JSON view, the corresponding diffs are as follows:

{
  "kind": "big_map",
  "id": "21409",
  "diff": {
    "action": "update",
    "updates": [...] // 2 items
  }
}

does anyone know how to derive the more specific actions like add_key and remove_key from the RPC JSON?

1 Answer 1

2

If RPC's bigmap diff doesn't contain value, like this:


{
  "key_hash": "exprv5CuRy2eC8Z7n2KyRX4wyHDSFPosiRqL4cQTRqErC358jpYj7X",
  "key": {
    "bytes": "636861726c6573"
  }
}

then the key has been removed. Otherwise, if it does contain value, like this:

{
  "key_hash": "exprtgjf6jkgFvyM5xJDYVpBXBKb7MtiGvc28QLftPHtzguNsNpH4W",
  "key": {
    "bytes": "626c6f636b79746f70"
  },
  "value": {
    "prim": "True"
  }
}

then the key was either added or updated, you don't know for sure, and there is no an easy way to know that :)

You can try to use these two RPC endpoints to check if that key existed before the operation:

  • /chains/main/blocks/{op_level} (extract all updates of that key from the current block (if any), sort them chronologically, and look at the last one before the operation, to see if the key existed before the operation);
  • /chains/main/blocks/{op_level - 1}/context/big_maps/{bigmap}/{key_hash} (check if the key existed at the end of the previous block).

So, if it didn't exist before the operation, then it was added, or updated otherwise.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.