Skip to content

Commit

Permalink
feat(storage): update comment from PR
Browse files Browse the repository at this point in the history
  • Loading branch information
kwiss committed Sep 26, 2023
1 parent 6241dc2 commit dc40048
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
2 changes: 1 addition & 1 deletion crates/ark-indexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub async fn main_loop<T: StorageManager>(storage: T) -> Result<()> {
}
};

match token_manager.format_token(&token_event).await {
match token_manager.format_and_register_token(&token_event).await {
Ok(()) => (),
Err(err) => {
log::error!("Can't format token {:?}\ntevent: {:?}", err, token_event);
Expand Down
30 changes: 6 additions & 24 deletions crates/ark-indexer/src/managers/token_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,12 @@ impl<'a, T: StorageManager, C: StarknetClient> TokenManager<'a, T, C> {
}

/// Formats a token registry from the token event data.
pub async fn format_token(&mut self, event: &TokenEvent) -> Result<()> {
pub async fn format_and_register_token(&mut self, event: &TokenEvent) -> Result<()> {
self.reset_token();

self.token.address = event.contract_address.clone();
self.token.token_id = event.token_id.clone();
self.token.formated_token_id = event.formated_token_id.clone();
self.token.mint_address = if event.event_type == EventType::Mint {
Some(event.to_address_field_element)
} else {
None
};
self.token.mint_timestamp = if event.event_type == EventType::Mint {
Some(event.timestamp)
} else {
None
};
self.token.mint_transaction_hash = if event.event_type == EventType::Mint {
Some(event.transaction_hash.clone())
} else {
None
};
self.token.mint_block_number = if event.event_type == EventType::Mint {
Some(event.block_number)
} else {
None
};

let token_owner = self
.get_token_owner(
FieldElement::from_hex_be(&event.contract_address)
Expand All @@ -58,10 +37,13 @@ impl<'a, T: StorageManager, C: StarknetClient> TokenManager<'a, T, C> {
event.token_id.high,
)
.await?[0];

self.token.owner = format!("{:#064x}", token_owner);

if event.event_type == EventType::Mint {
self.token.mint_address = Some(event.to_address_field_element);
self.token.mint_timestamp = Some(event.timestamp);
self.token.mint_transaction_hash = Some(event.transaction_hash.clone());
self.token.mint_block_number = Some(event.block_number);
self.storage
.register_mint(&self.token, event.block_number)
.await?;
Expand All @@ -70,8 +52,8 @@ impl<'a, T: StorageManager, C: StarknetClient> TokenManager<'a, T, C> {
.register_token(&self.token, event.block_number)
.await?;
}

Ok(())

}

/// Resets the token registry.
Expand Down

0 comments on commit dc40048

Please sign in to comment.