본문으로 건너뛰기

Module sui::event

Events 모듈이다. transaction의 effects certificate 일부로 custom MoveEvent를 생성하고 전송하는

sui::event::emit
함수를 정의한다.

모든 MoveEvent는 다음 속성을 가진다:

  • sender
  • 타입 시그니처(T)
  • event 데이터(T의 값)
  • timestamp(노드 로컬)
  • transaction digest

예시:

module my::marketplace {
use sui::event;
/* ... */
struct ItemPurchased has copy, drop {
item_id: ID, buyer: address
}
entry fun buy(/* .... */) {
/* ... */
event::emit(ItemPurchased { item_id: ..., buyer: .... })
}
}

Function emit

custom Move event를 emit하여 데이터를 offchain으로 보낸다.

custom index를 만들고 특정 애플리케이션에 가장 알맞은 방식으로 onchain activity를 추적하는 데 사용한다.

타입 T는 event를 인덱싱하는 주요 수단이며,

emit(MyEvent<phantom T>)
와 같이 phantom 매개변수를 포함할 수 있다.

public fun emit<T: copy, drop>(event: T)
Click to open
Implementation
public native fun emit<T: copy + drop>(event: T);