diff --git a/build/StarcoinFramework/BuildInfo.yaml b/build/StarcoinFramework/BuildInfo.yaml index 89da9a27..7dfd564e 100644 --- a/build/StarcoinFramework/BuildInfo.yaml +++ b/build/StarcoinFramework/BuildInfo.yaml @@ -84,6 +84,9 @@ compiled_package_info: ? address: "0x00000000000000000000000000000001" name: Event : StarcoinFramework + ? address: "0x00000000000000000000000000000001" + name: EventUtil + : StarcoinFramework ? address: "0x00000000000000000000000000000001" name: FixedPoint32 : StarcoinFramework @@ -264,7 +267,7 @@ compiled_package_info: ? address: "0x00000000000000000000000000000001" name: YieldFarmingV2 : StarcoinFramework - source_digest: 2317458930368CCF368CBFCFD2A2D84B74B03521306A30839C2CFFA9D0DCF89E + source_digest: 292D789D77E5CCC4DC7A710845C6751F5308EBD27AECB68680A2DF92F7A057F6 build_flags: dev_mode: false test_mode: false diff --git a/build/StarcoinFramework/bytecode_modules/EventUtil.mv b/build/StarcoinFramework/bytecode_modules/EventUtil.mv new file mode 100644 index 00000000..bcf5fb84 Binary files /dev/null and b/build/StarcoinFramework/bytecode_modules/EventUtil.mv differ diff --git a/build/StarcoinFramework/docs/EventUtil.md b/build/StarcoinFramework/docs/EventUtil.md new file mode 100644 index 00000000..420e3c6f --- /dev/null +++ b/build/StarcoinFramework/docs/EventUtil.md @@ -0,0 +1,175 @@ + + + +# Module `0x1::EventUtil` + + + +- [Resource `EventHandleWrapper`](#0x1_EventUtil_EventHandleWrapper) +- [Constants](#@Constants_0) +- [Function `init_event`](#0x1_EventUtil_init_event) +- [Function `uninit_event`](#0x1_EventUtil_uninit_event) +- [Function `emit_event`](#0x1_EventUtil_emit_event) +- [Function `exist_event`](#0x1_EventUtil_exist_event) + + +
use 0x1::Errors;
+use 0x1::Event;
+use 0x1::Signer;
+
+
+
+
+
+
+## Resource `EventHandleWrapper`
+
+
+
+struct EventHandleWrapper<EventT: drop, store> has key
+
+
+
+
+handle: Event::EventHandle<EventT>
+const ERR_INIT_REPEATE: u64 = 101;
+
+
+
+
+
+
+
+
+const ERR_RESOURCE_NOT_EXISTS: u64 = 102;
+
+
+
+
+
+
+## Function `init_event`
+
+
+
+public fun init_event<EventT: drop, store>(sender: &signer)
+
+
+
+
+public fun init_event<EventT: store + drop>(sender: &signer) {
+ let broker = Signer::address_of(sender);
+ assert!(!exists<EventHandleWrapper<EventT>>(broker), Errors::invalid_state(ERR_INIT_REPEATE));
+ move_to(sender, EventHandleWrapper<EventT> {
+ handle: Event::new_event_handle<EventT>(sender)
+ });
+}
+
+
+
+
+public fun uninit_event<EventT: drop, store>(sender: &signer)
+
+
+
+
+public fun uninit_event<EventT: store + drop>(sender: &signer) acquires EventHandleWrapper {
+ let broker = Signer::address_of(sender);
+ assert!(exists<EventHandleWrapper<EventT>>(broker), Errors::invalid_state(ERR_RESOURCE_NOT_EXISTS));
+ let EventHandleWrapper<EventT> { handle } = move_from<EventHandleWrapper<EventT>>(broker);
+ Event::destroy_handle<EventT>(handle);
+}
+
+
+
+
+public fun emit_event<EventT: drop, store>(broker: address, event: EventT)
+
+
+
+
+public fun emit_event<EventT: store + drop>(broker: address, event: EventT) acquires EventHandleWrapper {
+ let event_handle = borrow_global_mut<EventHandleWrapper<EventT>>(broker);
+ Event::emit_event(&mut event_handle.handle, event);
+}
+
+
+
+
+public fun exist_event<EventT: drop, store>(broker: address): bool
+
+
+
+
+public fun exist_event<EventT: store + drop>(broker: address): bool {
+ exists<EventHandleWrapper<EventT>>(broker)
+}
+
+
+
+
+