Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
271 changes: 271 additions & 0 deletions src/base/events.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
use starknet::{
ContractAddress
};
use crate::base::types::{Permissions,VerificationType,RefundRequestReason,ContentUpdateType};
#[derive(Drop, starknet::Event)]
pub struct TokenBoundAccountCreated {
pub id: u256,
}


#[derive(Drop, starknet::Event)]
pub struct EmergencyPaused {
pub paused_by: ContractAddress,
pub timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct EmergencyUnpause {
pub unpaused_by: ContractAddress,
pub timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct UserUpdated {
pub user_id: u256,
}

#[derive(Drop, starknet::Event)]
pub struct SubscriptionCreated {
pub user_id: u256,
pub end_date: u64,
pub amount: u256,
}

#[derive(Drop, starknet::Event)]
pub struct SubscriptionRenewed {
pub user: ContractAddress,
pub subscription_id: u256,
pub new_end_time: u64,
}

#[derive(Drop, starknet::Event)]
pub struct ReceiptGenerated {
pub receipt_id: u256,
}

#[derive(Drop, starknet::Event)]
pub struct SubscriptionCancelled {
pub user: ContractAddress,
pub subscription_id: u256,
}
#[derive(Drop, starknet::Event)]
pub struct AccessVerified {
pub user_id: u256,
pub content_id: felt252,
pub has_access: bool,
}

#[derive(Drop, starknet::Event)]
pub struct UserCreated {
pub id: u256,
}

#[derive(Drop, starknet::Event)]
pub struct PaymentProcessed {
pub payment_id: u256,
pub subscription_id: u256,
pub subscriber: ContractAddress,
pub amount: u256,
pub timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct RecurringPaymentProcessed {
pub payment_id: u256,
pub subscription_id: u256,
pub subscriber: ContractAddress,
pub amount: u256,
pub timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct PaymentVerified {
pub payment_id: u256,
pub subscription_id: u256,
pub timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct RefundProcessed {
pub payment_id: u256,
pub subscription_id: u256,
pub amount: u256,
pub timestamp: u64,
}

// Permission-related events
#[derive(Drop, starknet::Event)]
pub struct PermissionGranted {
pub account_id: u256,
pub operator: ContractAddress,
pub permissions: Permissions,
}

#[derive(Drop, starknet::Event)]
pub struct PermissionRevoked {
pub account_id: u256,
pub operator: ContractAddress,
}

#[derive(Drop, starknet::Event)]
pub struct PermissionModified {
pub account_id: u256,
pub permissions: Permissions,
}

// NEW - Delegation-related events
#[derive(Drop, starknet::Event)]
pub struct DelegationCreated {
pub delegator: ContractAddress,
pub delegate: ContractAddress,
pub permissions: u64,
pub expiration: u64,
pub max_actions: u64,
}

#[derive(Drop, starknet::Event)]
pub struct DelegationRevoked {
pub delegator: ContractAddress,
pub delegate: ContractAddress,
}

#[derive(Drop, starknet::Event)]
pub struct DelegationUsed {
pub delegator: ContractAddress,
pub delegate: ContractAddress,
pub permission: u64,
pub remaining_actions: u64,
}

#[derive(Drop, starknet::Event)]
pub struct DelegationExpired {
pub delegator: ContractAddress,
pub delegate: ContractAddress,
}

#[derive(Drop, starknet::Event)]
pub struct ContentRegistered {
pub content_id: felt252,
pub creator: ContractAddress,
}

#[derive(Drop, starknet::Event)]
pub struct UserVerificationStatusChanged {
#[key]
pub user: ContractAddress,
pub verification_type: VerificationType,
pub is_verified: bool,
pub timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct ContentPermissionsGranted {
#[key]
pub content_id: felt252,
#[key]
pub user: ContractAddress,
pub permissions: Permissions,
pub timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct ContentPurchased {
pub purchase_id: u256,
pub content_id: felt252,
pub buyer: ContractAddress,
pub price: u256,
pub timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct PurchaseStatusUpdated {
pub purchase_id: u256,
pub new_status: u8, // Using u8 for status code instead of PurchaseStatus enum
pub timestamp: u64,
}

// Payout and Refunds
#[derive(Drop, starknet::Event)]
pub struct PayoutExecuted {
pub recipients: Array<ContractAddress>,
pub timestamp: u64,
pub amount_paid: u256,
}

#[derive(Drop, starknet::Event)]
pub struct PayoutScheduleSet {
pub start_time: u64,
pub setter: ContractAddress,
pub interval: u64,
}

#[derive(Drop, starknet::Event)]
pub struct RefundRequested {
pub user: ContractAddress,
pub content_id: felt252,
pub purchase_id: u256,
pub reason: RefundRequestReason,
}

#[derive(Drop, starknet::Event)]
pub struct RefundApproved {
pub approver: ContractAddress,
pub user_id: u256,
pub content_id: felt252,
pub refund_id: u64,
}

#[derive(Drop, starknet::Event)]
pub struct RefundDeclined {
pub decliner: ContractAddress,
pub user_id: u256,
pub content_id: felt252,
pub refund_id: u64,
}

#[derive(Drop, starknet::Event)]
pub struct RefundTimedOut {
pub user_id: u256,
pub content_id: felt252,
pub refund_id: u64,
}

#[derive(Drop, starknet::Event)]
pub struct RefundPaid {
pub refund_id: u64,
pub content_id: felt252,
pub purchase_id: u256,
pub executor: ContractAddress,
pub user_id: u256,
}

#[derive(Drop, starknet::Event)]
pub struct PlatformFeeChanged {
pub new_fee: u256,
pub timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct RefundWindowChanged {
pub new_window: u64,
pub timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct ContentUpdated {
pub content_id: felt252,
pub updater: ContractAddress,
pub version: u64,
pub update_type: ContentUpdateType,
pub timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct ContentUpdateHistoryRecorded {
pub content_id: felt252,
pub version: u64,
pub updater: ContractAddress,
pub update_type: ContentUpdateType,
pub timestamp: u64,
}
115 changes: 115 additions & 0 deletions src/base/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,118 @@ pub struct Receipt {
pub issued_at: u64,
pub transaction_hash: felt252,
}


#[derive(Copy, Drop, Serde, starknet::Store, PartialEq, Debug)]
pub enum ContentType {
#[default]
Text,
Video,
Image,
// Any other content type
}

#[derive(Copy, Drop, Serde, starknet::Store, PartialEq, Debug)]
pub enum Category {
Software,
#[default]
Education,
Literature,
Art,
}

#[derive(Copy, Drop, Serde, starknet::Store, PartialEq, Debug)]
pub enum SubscriptionStatus {
Active,
#[default]
Inactive,
Cancelled,
}

#[derive(Copy, Drop, Serde, starknet::Store, Debug)]
pub struct ContentMetadata {
pub content_id: felt252,
pub title: felt252,
pub description: felt252,
pub content_type: ContentType,
pub creator: ContractAddress,
pub category: Category,
pub last_updated: u64,
pub version: u64,
}

#[derive(Copy, Drop, Serde, starknet::Store, Debug)]
pub struct ContentUpdateHistory {
pub content_id: felt252,
pub version: u64,
pub updater: ContractAddress,
pub timestamp: u64,
pub update_type: ContentUpdateType,
pub previous_title: felt252,
pub previous_description: felt252,
pub previous_content_type: ContentType,
pub previous_category: Category,
pub new_title: felt252,
pub new_description: felt252,
pub new_content_type: ContentType,
pub new_category: Category,
}

#[derive(Copy, Drop, Serde, starknet::Store, PartialEq, Debug)]
pub enum ContentUpdateType {
#[default]
Full,
Partial,
Title,
Description,
ContentType,
Category,
}

#[derive(Drop, Serde, starknet::Store, Clone)]
pub struct Subscription {
pub id: u256,
pub subscriber: ContractAddress,
pub plan_id: u256,
pub amount: u256,
pub start_date: u64,
pub end_date: u64,
pub is_active: bool,
pub last_payment_date: u64,
pub subscription_type: PlanType,
pub status: SubscriptionStatus,
}

#[derive(Drop, Serde, starknet::Store, Clone, PartialEq)]
pub enum PlanType {
#[default]
MONTHLY,
YEARLY,
TRIAL,
}

#[derive(Copy, Drop, Serde, starknet::Store, Debug)]
pub struct AccessCache {
pub user_id: u256,
pub content_id: felt252,
pub has_access: bool,
pub timestamp: u64,
pub expiry: u64,
}
#[derive(Copy, Drop, Serde, starknet::Store, Debug)]
pub struct ContentAccess {
pub content_id: felt252,
pub access_type: AccessType,
pub requires_subscription: bool,
pub is_premium: bool,
}

#[derive(Copy, Drop, Serde, starknet::Store, Debug)]
pub struct Payment {
pub id: u256,
pub subscription_id: u256,
pub amount: u256,
pub timestamp: u64,
pub is_verified: bool,
pub is_refunded: bool,
}
Loading
Loading