Skip to content

Commit 1fdbd5d

Browse files
committed
refactor: Enhance code readability and organization in voting.rs of Predictify Hybrid contract by aligning function parameters, improving whitespace, and reordering imports for better maintainability.
1 parent 784760b commit 1fdbd5d

1 file changed

Lines changed: 28 additions & 30 deletions

File tree

contracts/predictify-hybrid/src/voting.rs

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use crate::{
33
markets::{MarketAnalytics, MarketCreator, MarketStateManager, MarketUtils, MarketValidator},
44
types::{Market, OracleConfig, OracleProvider},
55
};
6-
use soroban_sdk::{
7-
contracttype, panic_with_error, vec, Address, Env, Map, String, Symbol, Vec,
8-
};
6+
use soroban_sdk::{contracttype, panic_with_error, vec, Address, Env, Map, String, Symbol, Vec};
97

108
// ===== CONSTANTS =====
119

@@ -114,11 +112,7 @@ impl VotingManager {
114112
}
115113

116114
/// Process winnings claim for a user
117-
pub fn process_claim(
118-
env: &Env,
119-
user: Address,
120-
market_id: Symbol,
121-
) -> Result<i128, Error> {
115+
pub fn process_claim(env: &Env, user: Address, market_id: Symbol) -> Result<i128, Error> {
122116
// Require authentication from the user
123117
user.require_auth();
124118

@@ -142,14 +136,10 @@ impl VotingManager {
142136
}
143137

144138
/// Collect platform fees from a market
145-
pub fn collect_fees(
146-
env: &Env,
147-
admin: Address,
148-
market_id: Symbol,
149-
) -> Result<i128, Error> {
139+
pub fn collect_fees(env: &Env, admin: Address, market_id: Symbol) -> Result<i128, Error> {
150140
// Require authentication from the admin
151141
admin.require_auth();
152-
142+
153143
// Validate admin permissions
154144
VotingValidator::validate_admin_authentication(env, &admin)?;
155145

@@ -446,7 +436,8 @@ impl VotingAnalytics {
446436
total_squared_stakes += stake * stake;
447437
}
448438

449-
let concentration = (total_squared_stakes as f64) / ((market.total_staked * market.total_staked) as f64);
439+
let concentration =
440+
(total_squared_stakes as f64) / ((market.total_staked * market.total_staked) as f64);
450441
concentration.min(1.0)
451442
}
452443

@@ -535,7 +526,7 @@ mod tests {
535526
fn test_voting_validator_authentication() {
536527
let env = Env::default();
537528
let user = Address::generate(&env);
538-
529+
539530
// Should not panic for valid user
540531
assert!(VotingValidator::validate_user_authentication(&user).is_ok());
541532
}
@@ -544,7 +535,7 @@ mod tests {
544535
fn test_voting_validator_stake_validation() {
545536
// Valid stake
546537
assert!(VotingValidator::validate_dispute_stake(MIN_DISPUTE_STAKE).is_ok());
547-
538+
548539
// Invalid stake
549540
assert!(VotingValidator::validate_dispute_stake(MIN_DISPUTE_STAKE - 1).is_err());
550541
}
@@ -556,7 +547,11 @@ mod tests {
556547
&env,
557548
Address::generate(&env),
558549
String::from_str(&env, "Test Market"),
559-
vec![&env, String::from_str(&env, "yes"), String::from_str(&env, "no")],
550+
vec![
551+
&env,
552+
String::from_str(&env, "yes"),
553+
String::from_str(&env, "no"),
554+
],
560555
env.ledger().timestamp() + 86400,
561556
OracleConfig::new(
562557
OracleProvider::Pyth,
@@ -578,7 +573,11 @@ mod tests {
578573
&env,
579574
Address::generate(&env),
580575
String::from_str(&env, "Test Market"),
581-
vec![&env, String::from_str(&env, "yes"), String::from_str(&env, "no")],
576+
vec![
577+
&env,
578+
String::from_str(&env, "yes"),
579+
String::from_str(&env, "no"),
580+
],
582581
env.ledger().timestamp() + 86400,
583582
OracleConfig::new(
584583
OracleProvider::Pyth,
@@ -591,7 +590,7 @@ mod tests {
591590
// Add some test votes
592591
let user1 = Address::generate(&env);
593592
let user2 = Address::generate(&env);
594-
593+
595594
market.add_vote(user1, String::from_str(&env, "yes"), 1000);
596595
market.add_vote(user2, String::from_str(&env, "no"), 2000);
597596

@@ -606,7 +605,11 @@ mod tests {
606605
&env,
607606
Address::generate(&env),
608607
String::from_str(&env, "Test Market"),
609-
vec![&env, String::from_str(&env, "yes"), String::from_str(&env, "no")],
608+
vec![
609+
&env,
610+
String::from_str(&env, "yes"),
611+
String::from_str(&env, "no"),
612+
],
610613
env.ledger().timestamp() + 86400,
611614
OracleConfig::new(
612615
OracleProvider::Pyth,
@@ -630,17 +633,12 @@ mod tests {
630633
fn test_testing_utilities() {
631634
let env = Env::default();
632635
let user = Address::generate(&env);
633-
634-
let vote = testing::create_test_vote(
635-
&env,
636-
user,
637-
String::from_str(&env, "yes"),
638-
1000,
639-
);
636+
637+
let vote = testing::create_test_vote(&env, user, String::from_str(&env, "yes"), 1000);
640638

641639
assert!(testing::validate_vote_structure(&vote).is_ok());
642-
640+
643641
let stats = testing::create_test_voting_stats(&env);
644642
assert!(testing::validate_voting_stats(&stats).is_ok());
645643
}
646-
}
644+
}

0 commit comments

Comments
 (0)