This commit is contained in:
2026-05-05 05:03:11 +02:00
parent 3e994995d7
commit f2c227e08f
132 changed files with 5767 additions and 4461 deletions

View File

@@ -32,10 +32,7 @@ impl KbWalletObservationService {
/// Creates a new wallet-observation service.
pub fn new(database: std::sync::Arc<crate::KbDatabase>) -> Self {
let persistence = crate::KbDetectionPersistenceService::new(database.clone());
Self {
database,
persistence,
}
return Self { database, persistence };
}
/// Records observed wallets and participations for one resolved transaction signature.
@@ -56,7 +53,7 @@ impl KbWalletObservationService {
"cannot record wallet observations for unknown transaction '{}'",
signature
)));
}
},
};
let transaction_id = match transaction.id {
Some(transaction_id) => transaction_id,
@@ -65,7 +62,7 @@ impl KbWalletObservationService {
"transaction '{}' has no internal id",
signature
)));
}
},
};
let decoded_events_result = crate::list_dex_decoded_events_by_transaction_id(
self.database.as_ref(),
@@ -84,7 +81,7 @@ impl KbWalletObservationService {
return Err(crate::KbError::InvalidState(
"decoded event has no internal id".to_string(),
));
}
},
};
let pool_id = match decoded_event.pool_account.clone() {
Some(pool_address) => {
@@ -99,7 +96,7 @@ impl KbWalletObservationService {
Some(pool) => pool.id,
None => None,
}
}
},
None => None,
};
let pair_id = match pool_id {
@@ -114,7 +111,7 @@ impl KbWalletObservationService {
Some(pair) => pair.id,
None => None,
}
}
},
None => None,
};
let payload_result =
@@ -126,7 +123,7 @@ impl KbWalletObservationService {
"cannot parse decoded_event payload_json '{}': {}",
decoded_event.payload_json, error
)));
}
},
};
let observed_roles = kb_collect_wallet_roles(&payload);
for (role, wallet_address) in observed_roles {
@@ -150,12 +147,12 @@ impl KbWalletObservationService {
Ok(_) => wallet_id,
Err(error) => return Err(error),
}
}
},
None => {
return Err(crate::KbError::InvalidState(
"wallet has no internal id".to_string(),
));
}
},
},
None => {
let dto = crate::KbWalletDto::new(wallet_address.clone(), None);
@@ -165,7 +162,7 @@ impl KbWalletObservationService {
Ok(wallet_id) => wallet_id,
Err(error) => return Err(error),
}
}
},
};
let participation_dto = crate::KbWalletParticipationDto::new(
wallet_id,
@@ -245,7 +242,7 @@ impl KbWalletObservationService {
});
}
}
Ok(results)
return Ok(results);
}
}
@@ -271,7 +268,7 @@ fn kb_collect_wallet_roles(
results.push((role.to_string(), address));
}
}
results
return results;
}
fn kb_extract_strings_for_candidate_keys(
@@ -280,7 +277,7 @@ fn kb_extract_strings_for_candidate_keys(
) -> std::vec::Vec<std::string::String> {
let mut values = std::vec::Vec::new();
kb_extract_strings_for_candidate_keys_inner(value, candidate_keys, &mut values);
values
return values;
}
fn kb_extract_strings_for_candidate_keys_inner(
@@ -336,7 +333,7 @@ mod tests {
Ok(database) => database,
Err(error) => panic!("database init must succeed: {}", error),
};
std::sync::Arc::new(database)
return std::sync::Arc::new(database);
}
async fn seed_fluxbeam_transaction(
@@ -411,9 +408,8 @@ mod tests {
let database = make_database().await;
seed_fluxbeam_transaction(database.clone(), "sig-wallet-observation-1").await;
let service = crate::KbWalletObservationService::new(database.clone());
let record_result = service
.record_transaction_by_signature("sig-wallet-observation-1")
.await;
let record_result =
service.record_transaction_by_signature("sig-wallet-observation-1").await;
let results = match record_result {
Ok(results) => results,
Err(error) => panic!("wallet observation must succeed: {}", error),
@@ -450,9 +446,8 @@ mod tests {
let database = make_database().await;
seed_fluxbeam_transaction(database.clone(), "sig-wallet-observation-2").await;
let service = crate::KbWalletObservationService::new(database.clone());
let first_result = service
.record_transaction_by_signature("sig-wallet-observation-2")
.await;
let first_result =
service.record_transaction_by_signature("sig-wallet-observation-2").await;
let first_results = match first_result {
Ok(first_results) => first_results,
Err(error) => panic!("first wallet observation must succeed: {}", error),
@@ -460,9 +455,8 @@ mod tests {
assert_eq!(first_results.len(), 2);
assert!(first_results[0].created_participation);
assert!(first_results[1].created_participation);
let second_result = service
.record_transaction_by_signature("sig-wallet-observation-2")
.await;
let second_result =
service.record_transaction_by_signature("sig-wallet-observation-2").await;
let second_results = match second_result {
Ok(second_results) => second_results,
Err(error) => panic!("second wallet observation must succeed: {}", error),