Unexpected hashing for `indexed string` params
Bug report
Considering this event MyEvent(indexed string myIndexedString, string myString):
-
stringworks as expected and can be retrieved and indexed (e.g. event.params.myString is the emitted string) -
indexed stringhas unexpected hashed value, and unable to decode back to the emitted value (e.g. event.params.myIndexedString is a hash of the emitted string)
Relevant log output
My actual contract event is:
`event ConfigChanged(string indexed key, uint indexed newValue, address indexed newAddress);`
And the error output is:
Nov 13 07:31:48.050 WARN Bytes contain invalid UTF8. This may be caused by attempting to convert a value such as an address that cannot be parsed to a unicode string. You may want to use 'toHexString()' instead. String (truncated to 1024 chars): '\u{0008}y��Ԃ�\u{000b}��㛥��\u{0012}Jᙺ� 7�\u{0013}K!'', sgd: 1, subgraph_id: QmQDMB7r7TxH2YyvPcsPwFiidzjZTksFrSQnmqrXfBCs6a, component: SubgraphInstanceManager
Nov 13 07:31:48.050 INFO handleConfigChanged: key=\u{0008}y��Ԃ�\u{000b}��㛥��\u{0012}Jᙺ� 7�\u{0013}K!' newValue=3600 newAddress=0x0000000000000000000000000000000000000000 blockNumber=88, data_source: StreamrConfig, sgd: 1, subgraph_id: QmQDMB7r7TxH2YyvPcsPwFiidzjZTksFrSQnmqrXfBCs6a, component: SubgraphInstanceManager > UserMapping
Nov 13 07:31:48.050 ERRO handleConfigChanged: unknown key=\u{0008}y��Ԃ�\u{000b}��㛥��\u{0012}Jᙺ� 7�\u{0013}K!', data_source: StreamrConfig, sgd: 1, subgraph_id: QmQDMB7r7TxH2YyvPcsPwFiidzjZTksFrSQnmqrXfBCs6a, component: SubgraphInstanceManager > UserMapping
### IPFS hash
_No response_
### Subgraph name or link to explorer
_No response_
### Some information to help us out
- [ ] Tick this box if this bug is caused by a regression found in the latest release.
- [ ] Tick this box if this bug is specific to the hosted service.
- [X] I have searched the issue tracker to make sure this issue is not a duplicate.
### OS information
macOS
Hi @samigabor can you share the assemblyscript handler code that causes this error?
When that error occured I had it like this:
export function handleConfigChanged(event: ConfigChanged): void {
let key = event.params.key.toString()
let newValue = event.params.newValue
let newAddress = event.params.newAddress.toHexString()
log.info('handleConfigChanged: key={} newValue={} newAddress={} blockNumber={}',
[key, newValue.toString(), newAddress, event.block.number.toString()])
if (event.params.key == "slashingFraction") { network.slashingFraction = newValue }
else if (key == "voterRegistry") { network.voterRegistry = newAddress }
// ...
}
But changing
let key = event.params.key.toString()
to
let key = event.params.key.toHexString()
would display the actual hash, not that gibberish thing...
My workaround was to generate the hashes on the side (e.g. from strings like the "slashingFraction") and do that comparison instead. Changed from:
if (event.params.key.toHexString() == "slashingFraction") { /*...*/ }
to
if (event.params.key.toHexString() == "0x1244ece3f5099e14b39eb81a51e3cd18b792bc2a2335d9222b07f97c2fe13326") { /*...*/ }
It may not even be a subgraph-related behavior, though, and can be viewed on Etherscan logs where indexed strings are handled differently. The data field is empty... If that were just a string instead, it would have been added to data.
Looks like this issue has been open for 6 months with no activity. Is it still relevant? If not, please remember to close it.