1use std::borrow::Cow;
2
3use defuse_crypto::PublicKey;
4use near_sdk::{AccountIdRef, near};
5
6#[must_use = "make sure to `.emit()` this event"]
7#[near(serializers = [json])]
8#[derive(Debug, Clone)]
9pub struct AccountEvent<'a, T> {
10 pub account_id: Cow<'a, AccountIdRef>,
11
12 #[serde(flatten)]
13 pub event: T,
14}
15
16impl<T> AccountEvent<'_, T> {
17 pub fn into_owned(self) -> AccountEvent<'static, T> {
18 AccountEvent {
19 account_id: Cow::Owned(self.account_id.into_owned()),
20 event: self.event,
21 }
22 }
23}
24
25impl<'a, T> AccountEvent<'a, T> {
26 #[inline]
27 pub fn new(account_id: impl Into<Cow<'a, AccountIdRef>>, event: T) -> Self {
28 Self {
29 account_id: account_id.into(),
30 event,
31 }
32 }
33}
34
35#[must_use = "make sure to `.emit()` this event"]
36#[near(serializers = [json])]
37#[derive(Debug, Clone)]
38pub struct PublicKeyEvent<'a> {
39 pub public_key: Cow<'a, PublicKey>,
40}