diem_types/account_config/resources/
account.rs1use crate::{
9 account_config::{
10 constants::ACCOUNT_MODULE_NAME, KeyRotationCapabilityResource,
11 WithdrawCapabilityResource,
12 },
13 event::EventHandle,
14};
15use move_core_types::move_resource::MoveResource;
16#[cfg(any(test, feature = "fuzzing"))]
17use proptest_derive::Arbitrary;
18use serde::{Deserialize, Serialize};
19
20#[derive(Debug, Serialize, Deserialize)]
24#[cfg_attr(any(test, feature = "fuzzing"), derive(Arbitrary))]
25pub struct AccountResource {
26 authentication_key: Vec<u8>,
27 withdrawal_capability: Option<WithdrawCapabilityResource>,
28 key_rotation_capability: Option<KeyRotationCapabilityResource>,
29 received_events: EventHandle,
30 sent_events: EventHandle,
31 sequence_number: u64,
32}
33
34impl AccountResource {
35 pub fn new(
37 sequence_number: u64, authentication_key: Vec<u8>,
38 withdrawal_capability: Option<WithdrawCapabilityResource>,
39 key_rotation_capability: Option<KeyRotationCapabilityResource>,
40 sent_events: EventHandle, received_events: EventHandle,
41 ) -> Self {
42 AccountResource {
43 sequence_number,
44 withdrawal_capability,
45 key_rotation_capability,
46 authentication_key,
47 sent_events,
48 received_events,
49 }
50 }
51
52 pub fn sequence_number(&self) -> u64 { self.sequence_number }
54
55 pub fn has_delegated_withdrawal_capability(&self) -> bool {
57 self.withdrawal_capability.is_none()
58 }
59
60 pub fn has_delegated_key_rotation_capability(&self) -> bool {
62 self.key_rotation_capability.is_none()
63 }
64
65 pub fn authentication_key(&self) -> &[u8] { &self.authentication_key }
67
68 pub fn sent_events(&self) -> &EventHandle { &self.sent_events }
70
71 pub fn received_events(&self) -> &EventHandle { &self.received_events }
73}
74
75impl MoveResource for AccountResource {
76 const MODULE_NAME: &'static str = ACCOUNT_MODULE_NAME;
77 const STRUCT_NAME: &'static str = ACCOUNT_MODULE_NAME;
78}