The Go bindings have a type called Log
that has the following fields
type Log struct {
// Consensus fields:
// address of the contract that generated the event
Address common.Address `json:"address" gencodec:"required"`
// list of topics provided by the contract.
Topics []common.Hash `json:"topics" gencodec:"required"`
// supplied by the contract, usually ABI-encoded
Data []byte `json:"data" gencodec:"required"`
[...]
}
Let's say I have an event like this event SomethingHappened(uint256 indexed id, address indexed participant1, address indexed participant2, uint256 value1, uint256 value2);
There are 4 topics and they are filled as follows, they are of type common.Hash
:
- The first topic is the hash of the event signature:
SHA3("SomethingHappened(uint256,address,address,uint256,uint256)")
- The second topic is the encoded
uint256
that can be read using the big library:new(big.Int).SetBytes(log.Topics[1].Bytes())
- and 4. are the two addresses of the participants. Since
common.Hash
is 32 bytes long andcommon.Address
is 20 bytes, you can get the address like this:common.BytesToAddress(log.Topics[2].Bytes()[12:32])
.
Now, that's not that convenient to do, but it's still possible. When we try to access the last two arguments, however, I get lost. They are encoded somehow in the Data []byte
field of the common.Log
struct. The documentation mentions they are "ABI-encoded" but offers not way to do anything with that data. abigen also has no support for event variables, so I'm really lost on how to access those values.