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