Skip to content
Merged
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
16 changes: 13 additions & 3 deletions .github/workflows/docs-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ jobs:

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
targets: wasm32-unknown-unknown

- name: Cache cargo
uses: Swatinem/rust-cache@v2

# 1. Link checking system (Temporarily disabled)
# - name: Lychee Link Checker
Expand All @@ -22,6 +28,10 @@ jobs:
# args: --config lychee.toml "./**/*.md"
# fail: true

# 2. Validate code examples (This stays!)
- name: Verify Code Snippets
run: cargo test --doc
# 2. Validate code examples (per workspace member)
- name: Verify Code Snippets (teachlink)
run: cargo test --doc -p teachlink-contract
- name: Verify Code Snippets (governance)
run: cargo test --doc -p governance-contract
- name: Verify Code Snippets (insurance)
run: cargo test --doc -p enhanced-insurance
39 changes: 39 additions & 0 deletions contracts/teachlink/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,42 @@ pub struct MetadataUpdatedEvent {
pub owner: Address,
pub timestamp: u64,
}

// ================= Advanced Analytics & Reporting Events =================

#[contractevent]
#[derive(Clone, Debug)]
pub struct ReportGeneratedEvent {
pub report_id: u64,
pub report_type: crate::types::ReportType,
pub generated_by: Address,
pub period_start: u64,
pub period_end: u64,
}

#[contractevent]
#[derive(Clone, Debug)]
pub struct ReportScheduledEvent {
pub schedule_id: u64,
pub template_id: u64,
pub owner: Address,
pub next_run_at: u64,
}

#[contractevent]
#[derive(Clone, Debug)]
pub struct ReportCommentAddedEvent {
pub report_id: u64,
pub comment_id: u64,
pub author: Address,
}

#[contractevent]
#[derive(Clone, Debug)]
pub struct AlertTriggeredEvent {
pub rule_id: u64,
pub condition_type: crate::types::AlertConditionType,
pub current_value: i128,
pub threshold: i128,
pub triggered_at: u64,
}
130 changes: 121 additions & 9 deletions contracts/teachlink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
//! | [`audit`] | Audit trail and compliance reporting |
//! | [`atomic_swap`] | Cross-chain atomic swaps |
//! | [`analytics`] | Bridge monitoring and analytics |
//! | [`reporting`] | Advanced analytics, report templates, dashboards, and alerting |
//! | [`rewards`] | Reward pool management and distribution |
//! | [`escrow`] | Multi-signature escrow with dispute resolution |
//! | [`tokenization`] | Educational content NFT minting and management |
Expand Down Expand Up @@ -107,6 +108,7 @@ mod notification;
mod notification_events_basic;
// mod notification_tests; // TODO: Re-enable when testutils dependencies are resolved
mod notification_types;
mod reporting;
mod rewards;
mod slashing;
// mod social_events;
Expand All @@ -118,15 +120,17 @@ pub mod validation;

pub use errors::{BridgeError, EscrowError, RewardsError};
pub use types::{
ArbitratorProfile, AtomicSwap, AuditRecord, BridgeMetrics, BridgeProposal, BridgeTransaction,
ChainConfig, ChainMetrics, ComplianceReport, ConsensusState, ContentMetadata, ContentToken,
ContentTokenParameters, CrossChainMessage, CrossChainPacket, DisputeOutcome, EmergencyState,
Escrow, EscrowMetrics, EscrowParameters, EscrowStatus, LiquidityPool, MultiChainAsset,
NotificationChannel, NotificationContent, NotificationPreference, NotificationSchedule,
NotificationTemplate, NotificationTracking, OperationType, PacketStatus, ProposalStatus,
ProvenanceRecord, RewardRate, RewardType, SlashingReason, SlashingRecord, SwapStatus,
TransferType, UserNotificationSettings, UserReputation, UserReward, ValidatorInfo,
ValidatorReward, ValidatorSignature,
AlertConditionType, AlertRule, ArbitratorProfile, AtomicSwap, AuditRecord, BridgeMetrics,
BridgeProposal, BridgeTransaction, ChainConfig, ChainMetrics, ComplianceReport, ConsensusState,
ContentMetadata, ContentToken, ContentTokenParameters, CrossChainMessage, CrossChainPacket,
DashboardAnalytics, DisputeOutcome, EmergencyState, Escrow, EscrowMetrics, EscrowParameters,
EscrowStatus, LiquidityPool, MultiChainAsset, NotificationChannel, NotificationContent,
NotificationPreference, NotificationSchedule, NotificationTemplate, NotificationTracking,
OperationType, PacketStatus, ProposalStatus, ProvenanceRecord, ReportComment, ReportSchedule,
ReportSnapshot, ReportTemplate, ReportType, ReportUsage, RewardRate, RewardType,
SlashingReason, SlashingRecord, SwapStatus, TransferType, UserNotificationSettings,
UserReputation, UserReward, ValidatorInfo, ValidatorReward, ValidatorSignature,
VisualizationDataPoint,
};

/// TeachLink main contract.
Expand Down Expand Up @@ -688,6 +692,114 @@ impl TeachLinkBridge {
analytics::AnalyticsManager::get_bridge_statistics(&env)
}

// ========== Advanced Analytics & Reporting Functions ==========

/// Get dashboard-ready aggregate analytics for visualizations
pub fn get_dashboard_analytics(env: Env) -> DashboardAnalytics {
reporting::ReportingManager::get_dashboard_analytics(&env)
}

/// Create a report template
pub fn create_report_template(
env: Env,
creator: Address,
name: Bytes,
report_type: ReportType,
config: Bytes,
) -> Result<u64, BridgeError> {
reporting::ReportingManager::create_report_template(&env, creator, name, report_type, config)
}

/// Get report template by id
pub fn get_report_template(env: Env, template_id: u64) -> Option<ReportTemplate> {
reporting::ReportingManager::get_report_template(&env, template_id)
}

/// Schedule a report
pub fn schedule_report(
env: Env,
owner: Address,
template_id: u64,
next_run_at: u64,
interval_seconds: u64,
) -> Result<u64, BridgeError> {
reporting::ReportingManager::schedule_report(&env, owner, template_id, next_run_at, interval_seconds)
}

/// Get scheduled reports for an owner
pub fn get_scheduled_reports(env: Env, owner: Address) -> Vec<ReportSchedule> {
reporting::ReportingManager::get_scheduled_reports(&env, owner)
}

/// Generate a report snapshot
pub fn generate_report_snapshot(
env: Env,
generator: Address,
template_id: u64,
period_start: u64,
period_end: u64,
) -> Result<u64, BridgeError> {
reporting::ReportingManager::generate_report_snapshot(
&env, generator, template_id, period_start, period_end,
)
}

/// Get report snapshot by id
pub fn get_report_snapshot(env: Env, report_id: u64) -> Option<ReportSnapshot> {
reporting::ReportingManager::get_report_snapshot(&env, report_id)
}

/// Record report view for usage analytics
pub fn record_report_view(env: Env, report_id: u64, viewer: Address) -> Result<(), BridgeError> {
reporting::ReportingManager::record_report_view(&env, report_id, viewer)
}

/// Get report usage count
pub fn get_report_usage_count(env: Env, report_id: u64) -> u32 {
reporting::ReportingManager::get_report_usage_count(&env, report_id)
}

/// Add comment to a report
pub fn add_report_comment(
env: Env,
report_id: u64,
author: Address,
body: Bytes,
) -> Result<u64, BridgeError> {
reporting::ReportingManager::add_report_comment(&env, report_id, author, body)
}

/// Get comments for a report
pub fn get_report_comments(env: Env, report_id: u64) -> Vec<ReportComment> {
reporting::ReportingManager::get_report_comments(&env, report_id)
}

/// Create an alert rule
pub fn create_alert_rule(
env: Env,
owner: Address,
name: Bytes,
condition_type: AlertConditionType,
threshold: i128,
) -> Result<u64, BridgeError> {
reporting::ReportingManager::create_alert_rule(&env, owner, name, condition_type, threshold)
}

/// Get alert rules for an owner
pub fn get_alert_rules(env: Env, owner: Address) -> Vec<AlertRule> {
reporting::ReportingManager::get_alert_rules(&env, owner)
}

/// Evaluate alert rules (returns triggered rule ids)
pub fn evaluate_alerts(env: Env) -> Vec<u64> {
reporting::ReportingManager::evaluate_alerts(&env)
}

/// Get recent report snapshots
pub fn get_recent_report_snapshots(env: Env, limit: u32) -> Vec<ReportSnapshot> {
reporting::ReportingManager::get_recent_report_snapshots(&env, limit)
}

// ========== Rewards Functions ==========

/// Initialize the rewards system
Expand Down
Loading