diff --git a/Cargo.lock b/Cargo.lock index 8d3d2e28..a7b0d13a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,7 +8,7 @@ version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "once_cell", "version_check", "zerocopy 0.7.35", @@ -222,6 +222,12 @@ dependencies = [ "shlex", ] +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" @@ -311,7 +317,7 @@ version = "4.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "curve25519-dalek-derive", "digest", @@ -552,7 +558,7 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "libc", "wasi", @@ -710,7 +716,7 @@ version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "ecdsa", "elliptic-curve", "sha2", @@ -749,6 +755,12 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" + [[package]] name = "num-bigint" version = "0.4.6" @@ -848,6 +860,7 @@ name = "predictify-hybrid" version = "0.0.0" dependencies = [ "soroban-sdk", + "wee_alloc", ] [[package]] @@ -1035,7 +1048,7 @@ version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "digest", ] @@ -1425,7 +1438,7 @@ version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "once_cell", "rustversion", "wasm-bindgen-macro", @@ -1514,6 +1527,40 @@ dependencies = [ "indexmap-nostd", ] +[[package]] +name = "wee_alloc" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "memory_units", + "winapi", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-core" version = "0.52.0" diff --git a/contracts/predictify-hybrid/Cargo.toml b/contracts/predictify-hybrid/Cargo.toml index 6284fd37..880216b1 100644 --- a/contracts/predictify-hybrid/Cargo.toml +++ b/contracts/predictify-hybrid/Cargo.toml @@ -10,6 +10,7 @@ doctest = false [dependencies] soroban-sdk = { workspace = true } +wee_alloc = "0.4.5" [dev-dependencies] diff --git a/contracts/predictify-hybrid/src/lib.rs b/contracts/predictify-hybrid/src/lib.rs index 2ba327b9..be8f0dd3 100644 --- a/contracts/predictify-hybrid/src/lib.rs +++ b/contracts/predictify-hybrid/src/lib.rs @@ -29,7 +29,6 @@ use types::*; /// Oracle integration and management module pub mod oracles; -use oracles::{OracleInterface}; /// Market creation and state management module pub mod markets; @@ -61,11 +60,11 @@ use utils::{TimeUtils, StringUtils, NumericUtils, ValidationUtils, CommonUtils}; /// Event logging and monitoring module pub mod events; -use events::{EventEmitter, EventLogger, EventHelpers, EventTestingUtils, EventDocumentation}; +use events::{EventLogger, EventHelpers, EventTestingUtils, EventDocumentation}; /// Admin controls and functions module pub mod admin; -use admin::{AdminInitializer, AdminFunctions, AdminAccessControl}; +use admin::{AdminInitializer, AdminFunctions}; /// Market extensions and modifications module pub mod extensions; @@ -80,7 +79,6 @@ use validation::{ FeeValidator as ValidationFeeValidator, VoteValidator as ValidationVoteValidator, DisputeValidator as ValidationDisputeValidator, - ConfigValidator as ValidationConfigValidator, ComprehensiveValidator, ValidationDocumentation, }; diff --git a/contracts/predictify-hybrid/src/resolution.rs b/contracts/predictify-hybrid/src/resolution.rs index d079a63a..4a35f7db 100644 --- a/contracts/predictify-hybrid/src/resolution.rs +++ b/contracts/predictify-hybrid/src/resolution.rs @@ -1,5 +1,4 @@ -use soroban_sdk::{contracttype, Address, Env, Map, String, Symbol, Vec}; -use soroban_sdk::vec; +use soroban_sdk::{contracttype, vec, Address, Env, Map, String, Symbol, Vec}; use crate::errors::Error; use crate::markets::{MarketAnalytics, MarketStateManager, MarketUtils, CommunityConsensus}; diff --git a/contracts/predictify-hybrid/src/test.rs b/contracts/predictify-hybrid/src/test.rs index 181e2669..5ce57c33 100644 --- a/contracts/predictify-hybrid/src/test.rs +++ b/contracts/predictify-hybrid/src/test.rs @@ -3,6 +3,7 @@ use super::*; use crate::errors::Error; use crate::oracles::ReflectorOracle; +use crate::oracles::OracleInterface; use soroban_sdk::{ testutils::{Address as _, Ledger, LedgerInfo}, token::{Client as TokenClient, StellarAssetClient}, diff --git a/contracts/predictify-hybrid/src/utils.rs b/contracts/predictify-hybrid/src/utils.rs index eccec3cd..6841311d 100644 --- a/contracts/predictify-hybrid/src/utils.rs +++ b/contracts/predictify-hybrid/src/utils.rs @@ -2,6 +2,7 @@ extern crate alloc; use soroban_sdk::{Address, Env, Map, String, Symbol, Vec}; use alloc::string::ToString; +use core::str; use crate::errors::Error; @@ -108,93 +109,106 @@ pub struct StringUtils; impl StringUtils { /// Convert string to uppercase - pub fn to_uppercase(env: &Env, s: &String) -> String { - // For now, return the original string since we can't easily convert Soroban String - // This is a limitation of the current Soroban SDK - s.clone() + pub fn to_uppercase(s: &String) -> String { + let env = Env::default(); + let rust_string = s.to_string(); + let result = rust_string.to_uppercase(); + String::from_str(&env, &result) } /// Convert string to lowercase - pub fn to_lowercase(env: &Env, s: &String) -> String { - // For now, return the original string since we can't easily convert Soroban String - // This is a limitation of the current Soroban SDK - s.clone() + pub fn to_lowercase(s: &String) -> String { + let env = Env::default(); + let rust_string = s.to_string(); + let result = rust_string.to_lowercase(); + String::from_str(&env, &result) } /// Trim whitespace from string - pub fn trim(env: &Env, s: &String) -> String { - // For now, return the original string since we can't easily convert Soroban String - // This is a limitation of the current Soroban SDK - s.clone() + pub fn trim(s: &String) -> String { + let env = Env::default(); + let rust_string = s.to_string(); + let trimmed = rust_string.trim(); + String::from_str(&env, trimmed) } /// Truncate string to specified length - pub fn truncate(env: &Env, s: &String, max_length: u32) -> String { - // For now, return the original string since we can't easily convert Soroban String - // This is a limitation of the current Soroban SDK - s.clone() + pub fn truncate(s: &String, max_length: u32) -> String { + let env = Env::default(); + let rust_string = s.to_string(); + let max_len = max_length as usize; + let truncated: alloc::string::String = rust_string.chars().take(max_len).collect(); + String::from_str(&env, &truncated) } /// Split string by delimiter - pub fn split(env: &Env, s: &String, delimiter: &str) -> Vec { - // For now, return a vector with the original string since we can't easily convert Soroban String - // This is a limitation of the current Soroban SDK - let mut result = Vec::new(env); - result.push_back(s.clone()); + pub fn split(s: &String, delimiter: &str) -> Vec { + let env = Env::default(); + let rust_string = s.to_string(); + let parts = rust_string.split(delimiter); + let mut result = Vec::new(&env); + for part in parts { + result.push_back(String::from_str(&env, part)); + } result } /// Join strings with delimiter - pub fn join(env: &Env, strings: &Vec, delimiter: &str) -> String { - // For now, return the first string since we can't easily convert Soroban String - // This is a limitation of the current Soroban SDK - if strings.len() > 0 { - strings.get_unchecked(0).clone() - } else { - String::from_str(env, "") + pub fn join(strings: &Vec, delimiter: &str) -> String { + let env = Env::default(); + let mut result = alloc::string::String::new(); + for (i, s) in strings.iter().enumerate() { + if i > 0 { + result.push_str(delimiter); + } + let rust_string = s.to_string(); + result.push_str(&rust_string); } } /// Check if string contains substring pub fn contains(s: &String, substring: &str) -> bool { - // For now, return false since we can't easily convert Soroban String - // This is a limitation of the current Soroban SDK - false + let rust_string = s.to_string(); + rust_string.contains(substring) } /// Check if string starts with prefix pub fn starts_with(s: &String, prefix: &str) -> bool { - // For now, return false since we can't easily convert Soroban String - // This is a limitation of the current Soroban SDK - false + let rust_string = s.to_string(); + rust_string.starts_with(prefix) } /// Check if string ends with suffix pub fn ends_with(s: &String, suffix: &str) -> bool { - // For now, return false since we can't easily convert Soroban String - // This is a limitation of the current Soroban SDK - false + let rust_string = s.to_string(); + rust_string.ends_with(suffix) } /// Replace substring in string - pub fn replace(env: &Env, s: &String, old: &str, new: &str) -> String { - // For now, return the original string since we can't easily convert Soroban String - // This is a limitation of the current Soroban SDK - s.clone() + pub fn replace(s: &String, old: &str, new: &str) -> String { + let env = Env::default(); + let rust_string = s.to_string(); + let replaced = rust_string.replace(old, new); + String::from_str(&env, &replaced) } /// Validate string length pub fn validate_string_length(s: &String, min_length: u32, max_length: u32) -> Result<(), Error> { - // For now, return Ok since we can't easily get the length of Soroban String - // This is a limitation of the current Soroban SDK - Ok(()) + let rust_string = s.to_string(); + let len = rust_string.len() as u32; + if len < min_length || len > max_length { + Err(Error::InvalidInput) + } else { + Ok(()) + } } - /// Sanitize string by removing special characters - pub fn sanitize_string(env: &Env, s: &String) -> String { - // For now, return the original string since we can't easily convert Soroban String - // This is a limitation of the current Soroban SDK - s.clone() + /// Sanitize string (remove special characters) + pub fn sanitize_string(s: &String) -> String { + let env = Env::default(); + let rust_string = s.to_string(); + let sanitized: alloc::string::String = rust_string.chars().filter(|c| c.is_alphanumeric() || c.is_whitespace()).collect(); + String::from_str(&env, &sanitized) } /// Generate random string @@ -294,9 +308,8 @@ impl NumericUtils { /// Convert string to number pub fn string_to_i128(s: &String) -> i128 { - // For now, return 0 since we can't easily convert Soroban String - // This is a limitation of the current Soroban SDK - 0 + let rust_string = s.to_string(); + rust_string.parse::().unwrap_or(0) } } @@ -330,16 +343,14 @@ impl ValidationUtils { /// Validate email format (basic) pub fn validate_email(email: &String) -> bool { - // For now, return true since we can't easily convert Soroban String - // This is a limitation of the current Soroban SDK - true + let rust_string = email.to_string(); + rust_string.contains("@") && rust_string.contains(".") } /// Validate URL format (basic) pub fn validate_url(url: &String) -> bool { - // For now, return true since we can't easily convert Soroban String - // This is a limitation of the current Soroban SDK - true + let rust_string = url.to_string(); + rust_string.starts_with("http://") || rust_string.starts_with("https://") } } diff --git a/contracts/predictify-hybrid/src/voting.rs b/contracts/predictify-hybrid/src/voting.rs index d96ffccb..d3cecd5e 100644 --- a/contracts/predictify-hybrid/src/voting.rs +++ b/contracts/predictify-hybrid/src/voting.rs @@ -864,6 +864,7 @@ pub mod testing { mod tests { use super::*; use soroban_sdk::testutils::Address as _; + use crate::types::{OracleConfig, OracleProvider}; #[test] fn test_voting_validator_authentication() {