1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::{
account_address::AccountAddress,
account_config::{constants::ACCOUNT_MODULE_NAME, resources::AccountResource},
};
use anyhow::Result;
use move_core_types::{
identifier::{IdentStr, Identifier},
move_resource::MoveResource,
};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
pub static ACCOUNT_RECEIVED_EVENT_PATH: Lazy<Vec<u8>> = Lazy::new(|| {
let mut path = AccountResource::resource_path();
path.extend_from_slice(b"/received_events_count/");
path
});
#[derive(Debug, Serialize, Deserialize)]
pub struct ReceivedPaymentEvent {
amount: u64,
currency_code: Identifier,
sender: AccountAddress,
metadata: Vec<u8>,
}
impl ReceivedPaymentEvent {
pub fn try_from_bytes(bytes: &[u8]) -> Result<Self> {
bcs::from_bytes(bytes).map_err(Into::into)
}
pub fn sender(&self) -> AccountAddress {
self.sender
}
pub fn amount(&self) -> u64 {
self.amount
}
pub fn metadata(&self) -> &[u8] {
&self.metadata
}
pub fn currency_code(&self) -> &IdentStr {
&self.currency_code
}
}
impl MoveResource for ReceivedPaymentEvent {
const MODULE_NAME: &'static str = ACCOUNT_MODULE_NAME;
const STRUCT_NAME: &'static str = "ReceivedPaymentEvent";
}