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
6 changes: 1 addition & 5 deletions backend/services/notification/alerting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
* Channels are pluggable; add as many as needed.
*/

<<<<<<< HEAD:backend/services/alerting.ts
import { logger } from './logging';
import type { Alert, AlertChannelConfig } from './types';
=======
import { logger } from '../../services/logging';
import type { Alert, AlertChannelConfig } from '../shared/types';
>>>>>>> main:backend/services/notification/alerting.ts

export interface AlertDispatcher {
send(alert: Alert): Promise<void>;
Expand Down
124 changes: 124 additions & 0 deletions contracts/batch/src/batch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/// Batch module – shared types for the SubTrackr batch operations contract.
use soroban_sdk::{contracttype, String, Vec};
use subtrackr_types::SubscriptionId;

// ── Subscription status ───────────────────────────────────────────────────────

#[contracttype]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum SubStatus {
Active,
Paused,
Cancelled,
}

// ── Subscription record (lightweight on-chain representation) ─────────────────

#[contracttype]
#[derive(Clone)]
pub struct SubRecord {
pub exists: bool,
pub status: SubStatus,
pub charged: i128,
}

// ── Operation types ───────────────────────────────────────────────────────────

#[contracttype]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum OperationType {
Create,
Charge,
Update,
Cancel,
Noop,
}

// ── Cancellation reasons ──────────────────────────────────────────────────────

#[contracttype]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum CancelReason {
UserRequested,
PaymentFailed,
Expired,
Custom,
}

// ── Batch operation input ─────────────────────────────────────────────────────

#[contracttype]
#[derive(Clone)]
pub struct BatchOperation {
/// Ordered list of subscription IDs to process.
pub subscription_ids: Vec<SubscriptionId>,
/// Parallel i128 parameter per subscription (e.g. charge amount).
pub params: Vec<i128>,
/// Cancellation reasons aligned with subscription_ids for Cancel ops.
pub cancel_reasons: Vec<CancelReason>,
pub operation_type: OperationType,
}

// ── Per-operation result ──────────────────────────────────────────────────────

#[contracttype]
#[derive(Clone)]
pub struct OperationResult {
pub subscription_id: SubscriptionId,
pub success: bool,
/// Non-zero error code on failure.
pub code: u32,
/// Optional human-readable reason.
pub reason: Option<String>,
}

// ── Batch-wide result ─────────────────────────────────────────────────────────

#[contracttype]
#[derive(Clone)]
pub struct BatchResult {
pub results: Vec<OperationResult>,
pub state: BatchState,
pub total_operations: u32,
pub successful_operations: u32,
pub failed_operations: u32,
pub skipped_operations: u32,
/// Whether all operations must succeed or all roll back.
pub atomic: bool,
/// True when an atomic batch was rolled back due to failure.
pub rolled_back: bool,
}

// ── Batch execution state ─────────────────────────────────────────────────────

#[contracttype]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum BatchState {
Pending,
Executing,
Completed,
PartiallyCompleted,
Failed,
RolledBack,
}

// ── Status summary returned to callers ───────────────────────────────────────

#[contracttype]
#[derive(Clone)]
pub struct BatchStatus {
pub batch_id: u64,
pub state: BatchState,
pub total: u32,
pub succeeded: u32,
pub failed: u32,
}

// ── Optional filter for history queries ──────────────────────────────────────

#[contracttype]
#[derive(Clone)]
pub struct BatchFilter {
pub operation_type: Option<OperationType>,
pub state: Option<BatchState>,
}
20 changes: 15 additions & 5 deletions contracts/credit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use soroban_sdk::{
contract, contracterror, contractimpl, contracttype, symbol_short, Address, Env, String, Vec,
};
use subtrackr_types::{SubscriptionId, CoreError};
use subtrackr_types::{CoreError, SubscriptionId};

/// Maximum retained transaction-history and lot entries per account.
const MAX_HISTORY: u32 = 128;
Expand Down Expand Up @@ -391,7 +391,9 @@ impl SubTrackrCredit {
created_at: now,
updated_at: now,
};
env.storage().persistent().set(&DataKey::Wallet(wallet_id), &wallet);
env.storage()
.persistent()
.set(&DataKey::Wallet(wallet_id), &wallet);
env.events()
.publish((symbol_short!("wallet"), subscriber), wallet_id);
wallet_id
Expand Down Expand Up @@ -420,7 +422,9 @@ impl SubTrackrCredit {
wallet.balance += amount;
wallet.total_deposited += amount;
wallet.updated_at = now;
env.storage().persistent().set(&DataKey::Wallet(wallet_id), &wallet);
env.storage()
.persistent()
.set(&DataKey::Wallet(wallet_id), &wallet);
Ok(PrepaymentSnapshot {
wallet_id,
balance: wallet.balance,
Expand Down Expand Up @@ -454,7 +458,9 @@ impl SubTrackrCredit {
wallet.balance -= amount;
wallet.total_withdrawn += amount;
wallet.updated_at = now;
env.storage().persistent().set(&DataKey::Wallet(wallet_id), &wallet);
env.storage()
.persistent()
.set(&DataKey::Wallet(wallet_id), &wallet);
Ok(PrepaymentSnapshot {
wallet_id,
balance: wallet.balance,
Expand Down Expand Up @@ -533,7 +539,11 @@ impl SubTrackrCredit {
}

fn next_wallet_id(env: &Env) -> u64 {
let base: u64 = env.storage().instance().get(&symbol_short!("NWID")).unwrap_or(0);
let base: u64 = env
.storage()
.instance()
.get(&symbol_short!("NWID"))
.unwrap_or(0);
env.storage()
.instance()
.set(&symbol_short!("NWID"), &(base + 1));
Expand Down
4 changes: 0 additions & 4 deletions contracts/subscription/src/gas_optimization.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/// Gas Optimization and Targeting Module
/// Provides optimization recommendations and tracks gas targets
#![allow(dead_code)]
//! Gas Optimization and Targeting Module
//! Provides optimization recommendations and tracks gas targets.

use soroban_sdk::{Env, String, Vec};

/// Optimization level
Expand Down
5 changes: 0 additions & 5 deletions contracts/subscription/src/gas_profiler.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/// Gas Profiling Module for SubTrackr Subscription Contract
/// Tracks gas consumption for each contract function and provides optimization insights
use soroban_sdk::{Address, Env, String, Symbol, Vec};
#![allow(dead_code)]
#![allow(unused_variables)]
//! Gas Profiling Module for SubTrackr Subscription Contract
//! Tracks gas consumption for each contract function and provides optimization insights.
use soroban_sdk::{Address, Env, String, Vec};

/// Gas profile entry for a function call
Expand Down
11 changes: 1 addition & 10 deletions contracts/subscription/src/gas_storage.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
use crate::gas_profiler::GasProfile;
/// Gas Storage Module
/// Manages storage and retrieval of gas profiling metrics
use soroban_sdk::{Address, Env, IntoVal, String as SorobanString, TryFromVal, Val, Vec};
#![allow(dead_code)]
#![allow(unused_variables)]
//! Gas Storage Module
//! Manages storage and retrieval of gas profiling metrics.
use soroban_sdk::{Address, Env, String as SorobanString};
use crate::gas_profiler::{GasProfile};

/// Storage keys for gas metrics
#[derive(Clone)]
Expand Down Expand Up @@ -152,9 +145,7 @@ impl GasMetricsStorage {
pub fn get_metrics_summary(env: &Env, storage: &Address) -> (u64, u64, u64) {
let total_gas = Self::get_total_gas_used(env, storage);
let total_calls = Self::get_total_call_count(env, storage);
let avg_gas = total_gas
.checked_div(total_calls)
.unwrap_or(0);
let avg_gas = total_gas.checked_div(total_calls).unwrap_or(0);
(total_gas, total_calls, avg_gas)
}
}
Expand Down
Loading
Loading