use crate::{
account_config::{
constants::ACCOUNT_MODULE_NAME, KeyRotationCapabilityResource,
WithdrawCapabilityResource,
},
event::EventHandle,
};
use move_core_types::move_resource::MoveResource;
#[cfg(any(test, feature = "fuzzing"))]
use proptest_derive::Arbitrary;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(any(test, feature = "fuzzing"), derive(Arbitrary))]
pub struct AccountResource {
authentication_key: Vec<u8>,
withdrawal_capability: Option<WithdrawCapabilityResource>,
key_rotation_capability: Option<KeyRotationCapabilityResource>,
received_events: EventHandle,
sent_events: EventHandle,
sequence_number: u64,
}
impl AccountResource {
pub fn new(
sequence_number: u64, authentication_key: Vec<u8>,
withdrawal_capability: Option<WithdrawCapabilityResource>,
key_rotation_capability: Option<KeyRotationCapabilityResource>,
sent_events: EventHandle, received_events: EventHandle,
) -> Self {
AccountResource {
sequence_number,
withdrawal_capability,
key_rotation_capability,
authentication_key,
sent_events,
received_events,
}
}
pub fn sequence_number(&self) -> u64 { self.sequence_number }
pub fn has_delegated_withdrawal_capability(&self) -> bool {
self.withdrawal_capability.is_none()
}
pub fn has_delegated_key_rotation_capability(&self) -> bool {
self.key_rotation_capability.is_none()
}
pub fn authentication_key(&self) -> &[u8] { &self.authentication_key }
pub fn sent_events(&self) -> &EventHandle { &self.sent_events }
pub fn received_events(&self) -> &EventHandle { &self.received_events }
}
impl MoveResource for AccountResource {
const MODULE_NAME: &'static str = ACCOUNT_MODULE_NAME;
const STRUCT_NAME: &'static str = ACCOUNT_MODULE_NAME;
}