关于 log 的指令。
| 以下是Yul 文档中摘出来的部分。 | 指令 | 解释 |
|---|---|---|
| log0(p, s) | log data mem[p…(p+s)) | |
| log1(p, s, t1) | log data mem[p…(p+s)) with topic t1 | |
| log2(p, s, t1, t2) | log data mem[p…(p+s)) with topics t1, t2 | |
| log3(p, s, t1, t2, t3) | log data mem[p…(p+s)) with topics t1, t2, t3 | |
| log4(p, s, t1, t2, t3, t4) | log data mem[p…(p+s)) with topics t1, t2, t3, t4 |
总体来说,事件的哈希值通常作为第一个 topic (topics[0]),而所有用 indexed 修饰的字段会分别作为其他 topics(如 topics[1], topics[2], 等)存储在日志中。这些 topics 用于有效地过滤和检索特定事件。而未被 indexed 修饰的字段的数据则会被存储在日志的 data 部分,这些数据在内存中指定的范围内取出。
这么说可能有些看不懂,看以下两个例子就明白了。
event SomeLog(uint256 indexed a, uint256 indexed b);
function emitLog() exter... 如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!