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
2 changes: 1 addition & 1 deletion contracts/predictify-hybrid/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl AdminInitializer {
Environment::Mainnet => ConfigManager::get_mainnet_config(env),
Environment::Custom => ConfigManager::get_development_config(env),
};
ConfigManager::validate_config(env, &config)?;
crate::config::ConfigValidator::validate_contract_config(&config)?;

// Initialize basic admin setup
AdminInitializer::initialize(env, admin)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#![cfg(test)]

use alloc::format;
use soroban_sdk::{symbol_short, testutils::Events, Env, Symbol, Vec};

use crate::event_topic_compat::{
Expand Down
2 changes: 2 additions & 0 deletions contracts/predictify-hybrid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ mod market_audit_tests;
mod test_audit_trail;
#[cfg(test)]
mod event_topic_compat_tests;
#[cfg(test)]
mod storage_layout_tests;
// #[cfg(any())]
// mod utils_tests;
// THis is the band protocol wasm std_reference.wasm
Expand Down
54 changes: 37 additions & 17 deletions contracts/predictify-hybrid/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,22 +513,39 @@ impl StorageOptimizer {
let max_ttl = env.storage().max_ttl();
let mut pressures = alloc::vec::Vec::new();

for key in keys.iter() {
let mut remaining = None;

if env.storage().persistent().has(&key) {
remaining = Some(0u32);
} else if env.storage().temporary().has(&key) {
remaining = Some(0u32);
} else if env.storage().instance().has(&key) {
remaining = Some(0u32);
#[cfg(any(test, feature = "testutils"))]
{
use soroban_sdk::testutils::storage::{Instance as _, Persistent as _, Temporary as _};
for key in keys.iter() {
let mut remaining = None;
if env.storage().persistent().has(&key) {
remaining = Some(env.storage().persistent().get_ttl(&key));
} else if env.storage().temporary().has(&key) {
remaining = Some(env.storage().temporary().get_ttl(&key));
} else if env.storage().instance().has(&key) {
remaining = Some(env.storage().instance().get_ttl());
}
if let Some(r) = remaining {
let bump = MARKET_TTL_LEDGERS.min(max_ttl);
pressures.push(StorageTtlPressure {
key_repr: soroban_sdk::String::from_str(env, "storage_key"),
remaining_ledgers: r,
recommended_bump: bump,
});
}
}

if let Some(r) = remaining {
}

#[cfg(not(any(test, feature = "testutils")))]
for key in keys.iter() {
let exists = env.storage().persistent().has(&key)
|| env.storage().temporary().has(&key)
|| env.storage().instance().has(&key);
if exists {
let bump = MARKET_TTL_LEDGERS.min(max_ttl);
pressures.push(StorageTtlPressure {
key_repr: soroban_sdk::String::from_str(env, "storage_key"),
remaining_ledgers: r,
remaining_ledgers: 0,
recommended_bump: bump,
});
}
Expand Down Expand Up @@ -1020,11 +1037,14 @@ impl StorageOptimizer {

/// Generate market ID from question
fn generate_market_id(env: &Env, question: &String) -> Symbol {
// Simple hash-based ID generation
let mut hash = 0i128;
// Simplified hash generation - in real implementation, you'd properly hash the string
hash = hash.wrapping_add(question.len() as i128);
soroban_sdk::Symbol::new(env, "market")
use soroban_sdk::xdr::ToXdr;
let hash = env.crypto().sha256(&question.to_xdr(env));
let hash_bytes = hash.to_bytes();
let hex: alloc::string::String = (0..4)
.map(|i| alloc::format!("{:02x}", hash_bytes.get(i).unwrap_or(0)))
.collect();
let id_str = alloc::format!("mkt_{}", hex);
Symbol::new(env, &id_str)
}

/// Archive market data before deletion
Expand Down
Loading
Loading