pub struct AccessToken { /* private fields */ }Expand description
Domain Entity: AccessToken
Represents a reader’s access to a specific article. Access tokens are issued after successful payment and grant time-limited access.
Domain Rules:
- Token is tied to a specific article and reader wallet
- Token has an expiration date (default 30 days)
- Token can be revoked (e.g., on refund)
- Token cannot be transferred to another wallet
- Expired or revoked tokens do not grant access
Implementations§
Source§impl AccessToken
impl AccessToken
Sourcepub fn new_paid(
tenant_id: TenantId,
article_id: ArticleId,
creator_id: CreatorId,
reader_wallet: WalletAddress,
transaction_id: TransactionId,
token_hash: String,
) -> Result<Self>
pub fn new_paid( tenant_id: TenantId, article_id: ArticleId, creator_id: CreatorId, reader_wallet: WalletAddress, transaction_id: TransactionId, token_hash: String, ) -> Result<Self>
Create a new access token for a paid transaction
Sourcepub fn new_with_duration(
tenant_id: TenantId,
article_id: ArticleId,
creator_id: CreatorId,
reader_wallet: WalletAddress,
transaction_id: Option<TransactionId>,
access_method: AccessMethod,
token_hash: String,
duration_days: i64,
) -> Result<Self>
pub fn new_with_duration( tenant_id: TenantId, article_id: ArticleId, creator_id: CreatorId, reader_wallet: WalletAddress, transaction_id: Option<TransactionId>, access_method: AccessMethod, token_hash: String, duration_days: i64, ) -> Result<Self>
Create a new access token with custom duration
Sourcepub fn new_free(
tenant_id: TenantId,
article_id: ArticleId,
creator_id: CreatorId,
reader_wallet: WalletAddress,
token_hash: String,
duration_days: i64,
) -> Result<Self>
pub fn new_free( tenant_id: TenantId, article_id: ArticleId, creator_id: CreatorId, reader_wallet: WalletAddress, token_hash: String, duration_days: i64, ) -> Result<Self>
Create a free access token (promotional)
Sourcepub fn reconstruct(
id: AccessTokenId,
tenant_id: TenantId,
article_id: ArticleId,
creator_id: CreatorId,
reader_wallet: WalletAddress,
transaction_id: Option<TransactionId>,
access_method: AccessMethod,
token_hash: String,
issued_at: DateTime<Utc>,
expires_at: DateTime<Utc>,
revoked: bool,
revoked_at: Option<DateTime<Utc>>,
revocation_reason: Option<String>,
last_accessed_at: Option<DateTime<Utc>>,
access_count: u32,
metadata: Value,
) -> Self
pub fn reconstruct( id: AccessTokenId, tenant_id: TenantId, article_id: ArticleId, creator_id: CreatorId, reader_wallet: WalletAddress, transaction_id: Option<TransactionId>, access_method: AccessMethod, token_hash: String, issued_at: DateTime<Utc>, expires_at: DateTime<Utc>, revoked: bool, revoked_at: Option<DateTime<Utc>>, revocation_reason: Option<String>, last_accessed_at: Option<DateTime<Utc>>, access_count: u32, metadata: Value, ) -> Self
Reconstruct access token from storage (bypasses validation)
pub fn id(&self) -> &AccessTokenId
pub fn tenant_id(&self) -> &TenantId
pub fn article_id(&self) -> &ArticleId
pub fn creator_id(&self) -> &CreatorId
pub fn reader_wallet(&self) -> &WalletAddress
pub fn transaction_id(&self) -> Option<&TransactionId>
pub fn access_method(&self) -> AccessMethod
pub fn token_hash(&self) -> &str
pub fn issued_at(&self) -> DateTime<Utc>
pub fn expires_at(&self) -> DateTime<Utc>
pub fn is_revoked(&self) -> bool
pub fn revoked_at(&self) -> Option<DateTime<Utc>>
pub fn revocation_reason(&self) -> Option<&str>
pub fn last_accessed_at(&self) -> Option<DateTime<Utc>>
pub fn access_count(&self) -> u32
pub fn metadata(&self) -> &Value
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if token is expired
Sourcepub fn grants_access_to(
&self,
article_id: &ArticleId,
wallet: &WalletAddress,
) -> bool
pub fn grants_access_to( &self, article_id: &ArticleId, wallet: &WalletAddress, ) -> bool
Check if this token grants access to a specific article for a specific wallet
Sourcepub fn remaining_seconds(&self) -> i64
pub fn remaining_seconds(&self) -> i64
Get remaining access time in seconds
Sourcepub fn remaining_days(&self) -> i64
pub fn remaining_days(&self) -> i64
Get remaining access time in days
Sourcepub fn record_access(&mut self)
pub fn record_access(&mut self)
Record an access (reading the article)
Sourcepub fn update_metadata(&mut self, metadata: Value)
pub fn update_metadata(&mut self, metadata: Value)
Update metadata
Trait Implementations§
Source§impl Clone for AccessToken
impl Clone for AccessToken
Source§fn clone(&self) -> AccessToken
fn clone(&self) -> AccessToken
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for AccessToken
impl Debug for AccessToken
Source§impl<'de> Deserialize<'de> for AccessToken
impl<'de> Deserialize<'de> for AccessToken
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<&AccessToken> for AccessTokenDto
impl From<&AccessToken> for AccessTokenDto
Source§fn from(token: &AccessToken) -> Self
fn from(token: &AccessToken) -> Self
Converts to this type from the input type.
Source§impl From<AccessToken> for AccessTokenDto
impl From<AccessToken> for AccessTokenDto
Source§fn from(token: AccessToken) -> Self
fn from(token: AccessToken) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for AccessToken
impl RefUnwindSafe for AccessToken
impl Send for AccessToken
impl Sync for AccessToken
impl Unpin for AccessToken
impl UnwindSafe for AccessToken
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more