1use defuse_serde_utils::base64::Base64;
2use near_sdk::{AccountIdRef, near};
3use serde_with::serde_as;
4use std::{borrow::Cow, collections::BTreeSet};
5
6use crate::{Nonce, Salt, public_key::PublicKey};
7
8#[must_use = "make sure to `.emit()` this event"]
9#[near(serializers = [json])]
10#[derive(Debug, Clone)]
11pub struct AccountEvent<'a, T> {
12 pub account_id: Cow<'a, AccountIdRef>,
13
14 #[serde(flatten)]
15 pub event: T,
16}
17
18impl<T> AccountEvent<'_, T> {
19 pub fn into_owned(self) -> AccountEvent<'static, T> {
20 AccountEvent {
21 account_id: Cow::Owned(self.account_id.into_owned()),
22 event: self.event,
23 }
24 }
25}
26
27impl<'a, T> AccountEvent<'a, T> {
28 #[inline]
29 pub fn new(account_id: impl Into<Cow<'a, AccountIdRef>>, event: T) -> Self {
30 Self {
31 account_id: account_id.into(),
32 event,
33 }
34 }
35}
36
37#[must_use = "make sure to `.emit()` this event"]
38#[near(serializers = [json])]
39#[derive(Debug, Clone)]
40pub struct PublicKeyEvent<'a> {
41 pub public_key: Cow<'a, PublicKey>,
42}
43
44#[near(serializers = [json])]
45#[derive(Debug, Clone)]
46pub struct NonceEvent {
47 #[serde_as(as = "Base64")]
48 pub nonce: Nonce,
49}
50
51impl NonceEvent {
52 #[inline]
53 pub const fn new(nonce: Nonce) -> Self {
54 Self { nonce }
55 }
56}
57
58#[must_use = "make sure to `.emit()` this event"]
59#[near(serializers = [json])]
60#[derive(Debug, Clone)]
61pub struct SaltRotationEvent {
62 pub current: Salt,
63 pub invalidated: BTreeSet<Salt>,
64}