Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Jan 30, 2024
1 parent f4bc868 commit 1250f0a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 50 deletions.
12 changes: 5 additions & 7 deletions contracts/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl Contract {
);
// we need to check class, because the query can return a "next" token if a user
// doesn't have the token of requested class.
if !(!tokens.is_empty() && tokens[0].1[0].metadata.class == *cls) {
if tokens.is_empty() || tokens[0].1[0].metadata.class != *cls {
return vec![];
}
proof.push(tokens[0].1[0].token)
Expand Down Expand Up @@ -422,12 +422,10 @@ impl Contract {

let now = env::block_timestamp_ms();
let mut lock = self.transfer_lock.get(&caller).unwrap_or(now);
if lock_duration > 0 {
if lock < now + lock_duration {
lock = now + lock_duration;
self.transfer_lock.insert(&caller, &lock);
events::emit_transfer_lock(caller.clone(), lock)
}
if lock_duration > 0 && lock < now + lock_duration {
lock = now + lock_duration;
self.transfer_lock.insert(&caller, &lock);
events::emit_transfer_lock(caller.clone(), lock)
}

let args = IsHumanLockCallbackArgs {
Expand Down
87 changes: 44 additions & 43 deletions contracts/registry/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,14 @@ impl SBTRegistry for Contract {
.get(&(owner_id.clone(), issuer_id))
.unwrap();
self.supply_by_owner
.insert(&(owner_id, issuer_id), &(old_supply - &tokens_revoked));
.insert(&(owner_id, issuer_id), &(old_supply - tokens_revoked));
}

// update supply by class
for (class_id, tokens_revoked) in revoked_per_class {
let old_supply = self.supply_by_class.get(&(issuer_id, class_id)).unwrap();
self.supply_by_class
.insert(&(issuer_id, class_id), &(&old_supply - &tokens_revoked));
.insert(&(issuer_id, class_id), &(old_supply - tokens_revoked));
}

// update supply by issuer
Expand Down Expand Up @@ -434,53 +434,53 @@ impl SBTRegistry for Contract {

// Check if all tokens were burned
return self.sbt_supply_by_owner(owner.clone(), issuer, None) == 0;
} else {
let (_, non_expired_tokens) = self
.sbt_tokens_by_owner(
owner.clone(),
Some(issuer.clone()),
None,
Some(MAX_REVOKE_PER_CALL),
Some(false),
)
.pop()
.unwrap();

if non_expired_tokens.is_empty() {
return true;
}
}

let is_finished = non_expired_tokens.len() < MAX_REVOKE_PER_CALL as usize;
let (_, non_expired_tokens) = self
.sbt_tokens_by_owner(
owner.clone(),
Some(issuer.clone()),
None,
Some(MAX_REVOKE_PER_CALL),
Some(false),
)
.pop()
.unwrap();

if non_expired_tokens.is_empty() {
return true;
}

let mut token_ids: Vec<TokenId> = Vec::new();
let is_finished = non_expired_tokens.len() < MAX_REVOKE_PER_CALL as usize;

// Revoke: Update expire date for all tokens to current_timestamp
let now = env::block_timestamp_ms();
for mut t in non_expired_tokens {
token_ids.push(t.token);
t.metadata.expires_at = Some(now);
let token_data = TokenData {
owner: owner.clone(),
metadata: t.metadata.into(),
};
self.issuer_tokens.insert(
&IssuerTokenId {
issuer_id,
token: t.token,
},
&token_data,
);
}
let mut token_ids: Vec<TokenId> = Vec::new();

SbtTokensEvent {
issuer,
tokens: token_ids,
}
.emit_revoke();
// Revoke: Update expire date for all tokens to current_timestamp
let now = env::block_timestamp_ms();
for mut t in non_expired_tokens {
token_ids.push(t.token);
t.metadata.expires_at = Some(now);
let token_data = TokenData {
owner: owner.clone(),
metadata: t.metadata.into(),
};
self.issuer_tokens.insert(
&IssuerTokenId {
issuer_id,
token: t.token,
},
&token_data,
);
}

// Check if all tokens were revoked
return is_finished;
SbtTokensEvent {
issuer,
tokens: token_ids,
}
.emit_revoke();

// Check if all tokens were revoked
is_finished
}

/// Allows issuer to update token metadata reference and reference_hash.
Expand All @@ -499,6 +499,7 @@ impl SBTRegistry for Contract {
token: 0,
};
let mut idx = 0;
#[allow(clippy::explicit_counter_loop)]
for (tid, reference, reference_hash) in updates {
key.token = tid;
let mut t = match self.issuer_tokens.get(&key) {
Expand Down

0 comments on commit 1250f0a

Please sign in to comment.