Skip to content

Commit 53d1d35

Browse files
committed
style(contracts): apply cargo fmt to all Rust files (#253)
1 parent 173bf51 commit 53d1d35

16 files changed

Lines changed: 711 additions & 431 deletions

contracts/src/attestation_protocol.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
//! - It can withdraw with [`revoke_attestation`].
1414
//! - The contract admin can [`deactivate_attester`] (and [`reactivate_attester`]).
1515
16-
use soroban_sdk::{contracterror, contracttype, panic_with_error, Address, BytesN, Env, String, Vec};
16+
use soroban_sdk::{
17+
contracterror, contracttype, panic_with_error, Address, BytesN, Env, String, Vec,
18+
};
1719

1820
use crate::credential_registry;
1921
use crate::utils::validation::{

contracts/src/attestation_protocol_test.rs

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ fn setup() -> (Env, Address, Address) {
2929
(env, contract_id, admin)
3030
}
3131

32-
fn create_credential(client: &AetherMintContractClient, admin: &Address, recipient: &Address) -> u64 {
32+
fn create_credential(
33+
client: &AetherMintContractClient,
34+
admin: &Address,
35+
recipient: &Address,
36+
) -> u64 {
3337
let env = client.env.clone();
3438
client.issue_credential_with_expiration(
3539
admin,
@@ -101,7 +105,10 @@ fn test_attest_and_verify_credential() {
101105
let record = attestations.get(0).unwrap();
102106
assert_eq!(record.attester, attester.clone());
103107
assert_eq!(record.credential_id, credential_id);
104-
assert_eq!(record.metadata, String::from_str(&env, "verified transcript"));
108+
assert_eq!(
109+
record.metadata,
110+
String::from_str(&env, "verified transcript")
111+
);
105112

106113
assert_eq!(client.get_attestation_count(&credential_id), 1);
107114
assert_eq!(client.get_attester(&attester).attestation_count, 1);
@@ -119,8 +126,18 @@ fn test_multiple_attesters() {
119126
client.register_attester(&attester_a, &String::from_str(&env, "MIT"), &key(&env));
120127
client.register_attester(&attester_b, &String::from_str(&env, "Stanford"), &key(&env));
121128

122-
client.attest_credential(&attester_a, &credential_id, &sig(&env), &String::from_str(&env, "a"));
123-
client.attest_credential(&attester_b, &credential_id, &sig(&env), &String::from_str(&env, "b"));
129+
client.attest_credential(
130+
&attester_a,
131+
&credential_id,
132+
&sig(&env),
133+
&String::from_str(&env, "a"),
134+
);
135+
client.attest_credential(
136+
&attester_b,
137+
&credential_id,
138+
&sig(&env),
139+
&String::from_str(&env, "b"),
140+
);
124141

125142
assert_eq!(client.get_attestations(&credential_id).len(), 2);
126143
assert_eq!(client.get_attestation_count(&credential_id), 2);
@@ -138,8 +155,18 @@ fn test_duplicate_attestation_fails() {
138155

139156
let credential_id = create_credential(&client, &admin, &recipient);
140157
client.register_attester(&attester, &String::from_str(&env, "MIT"), &key(&env));
141-
client.attest_credential(&attester, &credential_id, &sig(&env), &String::from_str(&env, "x"));
142-
client.attest_credential(&attester, &credential_id, &sig(&env), &String::from_str(&env, "y"));
158+
client.attest_credential(
159+
&attester,
160+
&credential_id,
161+
&sig(&env),
162+
&String::from_str(&env, "x"),
163+
);
164+
client.attest_credential(
165+
&attester,
166+
&credential_id,
167+
&sig(&env),
168+
&String::from_str(&env, "y"),
169+
);
143170
}
144171

145172
#[test]
@@ -151,7 +178,12 @@ fn test_revoke_attestation() {
151178

152179
let credential_id = create_credential(&client, &admin, &recipient);
153180
client.register_attester(&attester, &String::from_str(&env, "MIT"), &key(&env));
154-
client.attest_credential(&attester, &credential_id, &sig(&env), &String::from_str(&env, "x"));
181+
client.attest_credential(
182+
&attester,
183+
&credential_id,
184+
&sig(&env),
185+
&String::from_str(&env, "x"),
186+
);
155187
assert_eq!(client.get_attestation_count(&credential_id), 1);
156188

157189
client.revoke_attestation(&attester, &credential_id);
@@ -182,7 +214,12 @@ fn test_attest_by_unregistered_attester_fails() {
182214
let recipient = Address::generate(&env);
183215
let attester = Address::generate(&env);
184216
let credential_id = create_credential(&client, &admin, &recipient);
185-
client.attest_credential(&attester, &credential_id, &sig(&env), &String::from_str(&env, "x"));
217+
client.attest_credential(
218+
&attester,
219+
&credential_id,
220+
&sig(&env),
221+
&String::from_str(&env, "x"),
222+
);
186223
}
187224

188225
#[test]
@@ -211,7 +248,12 @@ fn test_deactivate_and_reactivate_attester() {
211248
client.reactivate_attester(&admin, &attester);
212249
assert!(client.get_attester(&attester).is_active);
213250

214-
client.attest_credential(&attester, &credential_id, &sig(&env), &String::from_str(&env, "x"));
251+
client.attest_credential(
252+
&attester,
253+
&credential_id,
254+
&sig(&env),
255+
&String::from_str(&env, "x"),
256+
);
215257
assert!(client.is_attested_by(&credential_id, &attester));
216258
}
217259

@@ -226,7 +268,12 @@ fn test_deactivated_attester_cannot_attest() {
226268
let credential_id = create_credential(&client, &admin, &recipient);
227269
client.register_attester(&attester, &String::from_str(&env, "MIT"), &key(&env));
228270
client.deactivate_attester(&admin, &attester);
229-
client.attest_credential(&attester, &credential_id, &sig(&env), &String::from_str(&env, "x"));
271+
client.attest_credential(
272+
&attester,
273+
&credential_id,
274+
&sig(&env),
275+
&String::from_str(&env, "x"),
276+
);
230277
}
231278

232279
#[test]

contracts/src/credential_events.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,7 @@ pub fn get_credential_event(env: &Env, event_id: u64) -> Option<CredentialEventR
164164

165165
/// Fetch all event records associated with a given credential id,
166166
/// in insertion order.
167-
pub fn get_credential_events(
168-
env: &Env,
169-
credential_id: u64,
170-
) -> Vec<CredentialEventRecord> {
167+
pub fn get_credential_events(env: &Env, credential_id: u64) -> Vec<CredentialEventRecord> {
171168
let ids: Vec<u64> = env
172169
.storage()
173170
.instance()

contracts/src/credential_registry.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::credential_events::{
2-
publish_credential_event, CredentialLifecycleEvent,
3-
};
1+
use crate::credential_events::{publish_credential_event, CredentialLifecycleEvent};
42
use crate::utils::storage::{EntityType, StorageUtils};
53
use crate::utils::validation::{
64
validate_duration, validate_non_zero_address, validate_string_length, MAX_DESCRIPTION_LENGTH,
@@ -64,8 +62,8 @@ pub enum CredentialRegistryKey {
6462
UserCredentials(Address),
6563
CredentialCount,
6664
ExpiredCredentials,
67-
RenewalHistory(u64), // credential_id -> Vec<RenewalRecord>
68-
AttestationCount(u64), // credential_id -> number of active attestations
65+
RenewalHistory(u64), // credential_id -> Vec<RenewalRecord>
66+
AttestationCount(u64), // credential_id -> number of active attestations
6967
}
7068

7169
/// Renewal record for tracking credential renewals
@@ -163,12 +161,7 @@ pub fn issue_credential_with_expiration(
163161

164162
// Emit credential lifecycle event with consistent
165163
// (credential_id, actor, timestamp) payload and queryable record.
166-
publish_credential_event(
167-
env,
168-
CredentialLifecycleEvent::Issued,
169-
credential_id,
170-
issuer,
171-
);
164+
publish_credential_event(env, CredentialLifecycleEvent::Issued, credential_id, issuer);
172165

173166
credential_id
174167
}

contracts/src/credential_registry_test.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ fn setup_env() -> (Env, Address) {
1616
(env, admin)
1717
}
1818

19-
fn make_params(
20-
env: &Env,
21-
recipient: Address,
22-
_idx: u32,
23-
) -> BatchCredentialParams {
19+
fn make_params(env: &Env, recipient: Address, _idx: u32) -> BatchCredentialParams {
2420
BatchCredentialParams {
2521
recipient,
2622
title: String::from_str(env, "Soroban Bootcamp"),
@@ -187,7 +183,12 @@ fn test_batch_emits_lifecycle_events_for_each_credential() {
187183
for i in 0..3u32 {
188184
let cred_id = ids.get(i).unwrap();
189185
let events = crate::credential_events::get_credential_events(&env, cred_id);
190-
assert_eq!(events.len(), 1, "credential {} should have exactly 1 event", cred_id);
186+
assert_eq!(
187+
events.len(),
188+
1,
189+
"credential {} should have exactly 1 event",
190+
cred_id
191+
);
191192
assert_eq!(
192193
events.get(0).unwrap().event_type,
193194
crate::credential_events::CredentialLifecycleEvent::Issued,

contracts/src/credentials.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::credential_events::{
2-
publish_credential_event, CredentialLifecycleEvent,
3-
};
1+
use crate::credential_events::{publish_credential_event, CredentialLifecycleEvent};
42
use crate::utils::storage::{EntityType, StorageUtils};
53
use soroban_sdk::{contracttype, Address, Env, String, Symbol, Vec};
64

@@ -56,7 +54,9 @@ pub fn issue_credential(
5654
) -> u64 {
5755
issuer.require_auth();
5856

59-
let admin: Address = env.storage().instance()
57+
let admin: Address = env
58+
.storage()
59+
.instance()
6060
.get(&Symbol::new(env, "admin"))
6161
.unwrap_or_else(|| panic!("Admin not set"));
6262
if issuer != admin {
@@ -104,12 +104,7 @@ pub fn issue_credential(
104104
.set(&CredentialKey::CredentialCount, &credential_id);
105105

106106
// Emit lifecycle event (publishes on-chain event + records for queryability)
107-
publish_credential_event(
108-
env,
109-
CredentialLifecycleEvent::Issued,
110-
credential_id,
111-
issuer,
112-
);
107+
publish_credential_event(env, CredentialLifecycleEvent::Issued, credential_id, issuer);
113108

114109
credential_id
115110
}
@@ -150,7 +145,9 @@ pub fn verify_credential(env: &Env, credential_id: u64, verifier: Address) -> bo
150145
pub fn revoke_credential(env: &Env, credential_id: u64, revoker: Address) {
151146
revoker.require_auth();
152147

153-
let admin: Address = env.storage().instance()
148+
let admin: Address = env
149+
.storage()
150+
.instance()
154151
.get(&Symbol::new(env, "admin"))
155152
.unwrap_or_else(|| panic!("Admin not set"));
156153
if revoker != admin {
@@ -215,7 +212,7 @@ pub fn get_credential_revocation_time(env: &Env, credential_id: u64) -> Option<u
215212
.get(&CredentialKey::CredentialRevocations(credential_id))
216213
}
217214

218-
// Get credential count with optimized storage
215+
// Get credential count with optimized storage
219216
pub fn get_credential_count(env: &Env) -> u64 {
220217
env.storage()
221218
.instance()

contracts/src/credentials_test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ fn test_issue_and_verify_credential() {
5454

5555
// Integration: lifecycle events must be recorded by the unified
5656
// credential_events module so off-chain indexers can subscribe to them.
57-
let issued_records =
58-
crate::credential_events::get_credential_events(&env, cred_id);
57+
let issued_records = crate::credential_events::get_credential_events(&env, cred_id);
5958
assert_eq!(issued_records.len(), 3); // Issued, Verified, Revoked
6059
assert_eq!(
6160
issued_records.get(0).unwrap().event_type,

contracts/src/dna_storage.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,19 @@ fn verify_blockchain_reference(env: &Env, reference: &String) -> bool {
529529
// Simplified verification - check if credential exists on blockchain
530530
let mut reference_buf = [0u8; 64];
531531
let ref_len = reference.copy_into_slice(&mut reference_buf);
532-
if ref_len >= 5 && reference_buf[0] == b'c' && reference_buf[1] == b'r'
533-
&& reference_buf[2] == b'e' && reference_buf[3] == b'd' && reference_buf[4] == b'_' {
532+
if ref_len >= 5
533+
&& reference_buf[0] == b'c'
534+
&& reference_buf[1] == b'r'
535+
&& reference_buf[2] == b'e'
536+
&& reference_buf[3] == b'd'
537+
&& reference_buf[4] == b'_'
538+
{
534539
// Simplified: just check if any credential exists
535-
if let Some(_) = env.storage().persistent().get::<_, u64>(&DNAStorageKey::DNACredentialCount) {
540+
if let Some(_) = env
541+
.storage()
542+
.persistent()
543+
.get::<_, u64>(&DNAStorageKey::DNACredentialCount)
544+
{
536545
return true;
537546
}
538547
}
@@ -605,8 +614,8 @@ pub struct CheckpointMeta {
605614
pub checkpoint_id: u64,
606615
pub label: String,
607616
pub timestamp: u64,
608-
pub data_size: u32, // number of credential IDs captured
609-
pub hash: u64, // rolling hash of the snapshot
617+
pub data_size: u32, // number of credential IDs captured
618+
pub hash: u64, // rolling hash of the snapshot
610619
}
611620

612621
/// Storage keys for checkpoints.
@@ -687,9 +696,7 @@ pub fn create_checkpoint(env: &Env, label: String) -> u64 {
687696
.set(&CheckpointKey::Snapshot(checkpoint_id), &snapshot);
688697

689698
index.push_back(checkpoint_id);
690-
env.storage()
691-
.instance()
692-
.set(&CheckpointKey::Index, &index);
699+
env.storage().instance().set(&CheckpointKey::Index, &index);
693700

694701
// Verify integrity immediately after capture
695702
let recalc = snapshot_hash(&snapshot);

contracts/src/dna_storage_checkpoint_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
mod tests {
33
use crate::dna_services::verify_integrity;
44
use crate::dna_storage::{
5-
create_checkpoint, delete_checkpoint, list_checkpoints, restore_checkpoint,
6-
DNACredential, DNASequence, DNAStorageKey, DNAStorageProtocol,
7-
DnaMetadata, ErrorCorrectionLevel, MAX_CHECKPOINTS,
5+
create_checkpoint, delete_checkpoint, list_checkpoints, restore_checkpoint, DNACredential,
6+
DNASequence, DNAStorageKey, DNAStorageProtocol, DnaMetadata, ErrorCorrectionLevel,
7+
MAX_CHECKPOINTS,
88
};
99
use crate::lib::DataKey;
1010
use soroban_sdk::{testutils::Address as _, Address, Env, String, Vec};

0 commit comments

Comments
 (0)