Hi,
I'm on v4 and using contract.interface.parseLog(log) and my event has some indexed parameters but I'm having trouble actually receiving the values of those. Obviously these are treated as extra topics, but how can I get the actual data? I found this note in the v3 documentation:
// Parse event topics and data (returns all entries)
// Note: Any indexed entry which is not a 32 byte value is hashed.
// Dynamic arrays are hashed as a static sized array.
This is what my event looks like
event MarketRegistered(
uint256 indexed startDate,
uint256 indexed expiryDate,
string indexed referenceEntity,
string test,
bytes32 marketHash
);
and I get this when using the new interface.parseLog() method:
{ '0': { _hex: '0x5b5e03b6' },
'1': { _hex: '0x5bc8cd36' },
'2':
{ hash:
'0x1de46e819416afc37058fd1cf806b9bcf96fa5d23b3ae565d6c72f0e19be9a9e' },
'3': 'TESTT',
'4':
'0x5c7949e8eb1ac99acafca2b83a779c66bbdbb1b10c3dfd8757eb7655085dc515',
startDate: { _hex: '0x5b5e03b6' },
expiryDate: { _hex: '0x5bc8cd36' },
referenceEntity:
{ hash:
'0x1de46e819416afc37058fd1cf806b9bcf96fa5d23b3ae565d6c72f0e19be9a9e' },
test: 'TESTT',
marketHash:
'0x5c7949e8eb1ac99acafca2b83a779c66bbdbb1b10c3dfd8757eb7655085dc515',
length: 5 }
How can I dig deeper and get the values of the indexed fields (not the hashed versions)? It seems like parseLog is only taking the first topic.
Thank you for this awesome library.
The startDate and expiryDate are correctly returned as BigNumbers. The only indexed parameter you are not getting the value from is referenceEntity, for which you will get just the hash; the actual string is not available in the log at all; the Solidity code only includes the hashed value of dynamic lengthed parameters. If you wish to have both, the value and the ability to filter on it, you will need an event that looks more like:
MarketRegistered(
uint256 indexed startDate,
uint256 indexed expiryDate,
string indexed filterRefEntity,
string refEntity,
bytes32 marketHash
);
You can use the filterRefEntity for filtering, and the refEntity for its value.
Does that make sense?
Yes, thank you!
Slightly related, it seems like in v4 LogDescription.values is an any[] from parseLog whereas it is actually an object (the thing in the original post). I believe the typing is slightly off? For instance, if I do Object.keys(), I receive
[ '0',
'1',
'2',
'3',
'4',
'startDate',
'expiryDate',
'referenceEntity',
'test',
'marketHash',
'length' ]
The workaround I'm currently using is to just cast it to any.
You are absolutely correct. There are a few places like that I'll fix right now.
The objects are meant to behave like both an array and a dictionary, so if you have function foo() returns (uint foo, address bar) you can use result[0] or result.foo, and a result.length has a meaningful value.
Closing this now. If you have further issues, please feel free to re-open. :)
Most helpful comment
The startDate and expiryDate are correctly returned as BigNumbers. The only indexed parameter you are not getting the value from is referenceEntity, for which you will get just the hash; the actual string is not available in the log at all; the Solidity code only includes the hashed value of dynamic lengthed parameters. If you wish to have both, the value and the ability to filter on it, you will need an event that looks more like:
You can use the filterRefEntity for filtering, and the refEntity for its value.
Does that make sense?