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
5 changes: 5 additions & 0 deletions contracts/predictify-hybrid/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ pub enum AdminPermission {
ViewAnalytic,
/// Emergency actions
Emergency,
/// Configure system settings
ConfigAdmin,
}

/// Admin action record
Expand Down Expand Up @@ -3549,6 +3551,9 @@ impl AdminUtils {
AdminPermission::Emergency => {
String::from_str(&soroban_sdk::Env::default(), "Emergency")
}
AdminPermission::ConfigAdmin => {
String::from_str(&soroban_sdk::Env::default(), "ConfigAdmin")
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/predictify-hybrid/src/analytics_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl AnalyticsSnapshotManager {
for (outcome, count) in counts.iter() {
ordered.push((outcome, count));
}
ordered.sort_by(|left, right| left.0.to_string().cmp(&right.0.to_string()));
ordered.sort_by(|left, right| left.0.cmp(&right.0));

for (outcome, count) in ordered {
outcome_counts.push_back(OutcomeCount { outcome, count });
Expand Down
28 changes: 17 additions & 11 deletions contracts/predictify-hybrid/src/audit_trail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub struct AuditRecord {
pub struct AuditEntryV2 {
pub index: u64,
pub action: Symbol,
pub reason_idx: u8,
pub reason_idx: u32,
pub actor: Address,
pub ts: u64,
pub ref_id: BytesN<32>,
Expand Down Expand Up @@ -110,14 +110,18 @@ impl AuditTrailManager {
}

/// Registers a new reason in the append-only reason table (admin-gated).
/// Returns the u8 index assigned to the reason.
/// Returns the u32 index assigned to the reason.
pub fn add_reason(
env: &Env,
admin: &Address,
reason: String,
) -> Result<u8, crate::err::Error> {
) -> Result<u32, crate::err::Error> {
// Require admin authentication
crate::admin::AdminManager::require_admin_auth(env, admin)?;
admin.require_auth();
let stored_admin: Address = env.storage().persistent().get(&Symbol::new(env, "Admin")).ok_or(crate::err::Error::AdminNotSet)?;
if admin != &stored_admin {
return Err(crate::err::Error::Unauthorized);
}

let mut reasons: Vec<String> = env
.storage()
Expand All @@ -129,7 +133,7 @@ impl AuditTrailManager {
return Err(crate::err::Error::ReasonTableFull);
}

let idx = reasons.len() as u8;
let idx = reasons.len() as u32;
reasons.push_back(reason);

env.storage()
Expand All @@ -139,8 +143,8 @@ impl AuditTrailManager {
Ok(idx)
}

/// Retrieves a reason from the table by its u8 index.
pub fn get_reason(env: &Env, index: u8) -> Option<String> {
/// Retrieves a reason from the table by its u32 index.
pub fn get_reason(env: &Env, index: u32) -> Option<String> {
let reasons: Vec<String> = env
.storage()
.persistent()
Expand Down Expand Up @@ -209,7 +213,7 @@ impl AuditTrailManager {
pub fn append_record_v2(
env: &Env,
action: Symbol,
reason_idx: u8,
reason_idx: u32,
actor: Address,
ref_id: BytesN<32>,
override_nonce: Option<u64>,
Expand Down Expand Up @@ -340,14 +344,16 @@ impl AuditTrailManager {
}

let versioned = versioned_opt.unwrap();
let (actual_hash, prev_hash) = match versioned {
let (actual_hash, prev_hash): (BytesN<32>, BytesN<32>) = match versioned {
AuditRecordVersion::V1(v1) => {
let prev = v1.prev_record_hash.clone();
let record_bytes = v1.to_xdr(env);
(env.crypto().sha256(&record_bytes).into(), v1.prev_record_hash)
(env.crypto().sha256(&record_bytes).into(), prev)
}
AuditRecordVersion::V2(v2) => {
let prev = v2.prev_record_hash.clone();
let record_bytes = v2.to_xdr(env);
(env.crypto().sha256(&record_bytes).into(), v2.prev_record_hash)
(env.crypto().sha256(&record_bytes).into(), prev)
}
};

Expand Down
Loading
Loading