Solidity event

https://rareskills.io/post/ethereum-events

Topic

// ToDo

indexed

// ToDo

이벤트 emit문 내에서 함수 호출 시 실행 순서

emit Hello(a(), b(), c(), d()) 했을 때, c, d가 indexed 라면 d, c 가 먼저 실행된다. 솔리디티 버전에 따라 다를 지는 모르겠다만 일단 0.8.30에서는 적용되었다.

contract Test {
    event Indexedtest(uint256 a, uint256 indexed b, uint256 c, uint256 indexed d);
    event Unindexedtest(uint256 a, uint256 b, uint256 c, uint256 d);
    event executed(string name);
 
    function indexedtest() external {
        emit Indexedtest(a(), b(), c(), d()); // d, b, a, b 순서로 실행
    }
 
    function unindexedtest() external {
        emit Unindexedtest(a(), b(), c(), d()); // a, b, c, d 순서로 실행
    }
 
    function a() internal returns (uint256) {
        emit executed("a");
        return 1;
    }
    function b() internal returns (uint256) {
        emit executed("b");
        return 2;
    }
    function c() internal returns (uint256){
        emit executed("c");
        return 3;
    }
    function d() internal returns (uint256){
        emit executed("d");
        return 4;
    }
}

tags: blockchain, smart contract, solidity