Skip to content

對indexed关键字的疑惑 #406

Closed Answered by XdpCs
0xethanchen asked this question in Q&A
Discussion options

You must be logged in to vote

You can use this demo.

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

contract aa {
    struct S {
        uint a;
        uint b;
    }
    mapping(uint=>uint) public aa;
    
    event a(S indexed s);
    event b(mapping(uint=>uint) indexed aaa);
    
    function f() public returns (S memory) {
        emit a(S(1, 2));
        aa[11]=22;
        emit b(aa);
        return S(1, 2);
    }
}

You will get this error.

from solidity:
TypeError: Type containing a (nested) mapping is not allowed as event parameter type.
  --> contracts/1_Storage.sol:12:13:
   |
12 |     event b(mapping(uint=>uint) indexed aaa);
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@0xethanchen
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by XdpCs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants