Given a smart contract address passed as a parameter, this module returns the logs attached to the contract.
Running the Substreams
First, generate the Protobuf modules and build the Rust code:
makeprotogen
makebuild
Now, you can run the Substreams. The logs retrieved correspond to the 0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d (BoredApeYachtClub smart contract). To avoid iterating over the full blockchain, the following command starts at block 17717995 and finished at block 17718004. Therefore, only the BoredApeYachtClub smart contract logs that happened within this block range are printed.
In this example, you do not need to parse the parameters, as contract_address is the only string passed and you can use it directly. However, it is necessary to verify that the parameter is a valid Ethereum; this verification is performed by the verify_parameter function.
Then, you iterate over the events of the contract:
The .logs() function iterates over the logs of successful transactions within the block.
For every log of a successful transaction, you verify if its address matches the smart contract address (i.e. you verify if the log was actually emitted by the smart contract). For the comparison, both log.address() and contract_address are converted to Vec<u8>.
Every filtered log (i.e. every log that belongs to the smart contract) is mapped to a pb::eth::event::v1::Event struct, which was specified in the Protobuf definition.