Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rust] handle burn properly for partial burns #327

Merged
merged 4 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions rust/processor/src/models/token_v2_models/v2_token_ownerships.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,16 @@ impl TokenOwnershipV2 {
}

/// This handles the case where token is burned but objectCore is still there
pub fn get_burned_nft_v2_from_write_resource(
pub async fn get_burned_nft_v2_from_write_resource(
write_resource: &WriteResource,
txn_version: i64,
write_set_change_index: i64,
txn_timestamp: chrono::NaiveDateTime,
prior_nft_ownership: &AHashMap<String, NFTOwnershipV2>,
tokens_burned: &TokenV2Burned,
conn: &mut PgPoolConnection<'_>,
query_retries: u32,
query_retry_delay_ms: u64,
) -> anyhow::Result<Option<(Self, CurrentTokenOwnershipV2)>> {
let token_data_id = standardize_address(&write_resource.address.to_string());
if tokens_burned
Expand Down Expand Up @@ -279,14 +283,53 @@ impl TokenOwnershipV2 {
non_transferrable_by_owner: Some(is_soulbound),
},
)));
} else {
return Self::get_burned_nft_v2_helper(
&token_data_id,
txn_version,
write_set_change_index,
txn_timestamp,
prior_nft_ownership,
tokens_burned,
conn,
query_retries,
query_retry_delay_ms,
)
.await;
}
}
Ok(None)
}

/// This handles the case where token is burned and objectCore is deleted
pub async fn get_burned_nft_v2_from_delete_resource(
write_resource: &DeleteResource,
delete_resource: &DeleteResource,
txn_version: i64,
write_set_change_index: i64,
txn_timestamp: chrono::NaiveDateTime,
prior_nft_ownership: &AHashMap<String, NFTOwnershipV2>,
tokens_burned: &TokenV2Burned,
conn: &mut PgPoolConnection<'_>,
query_retries: u32,
query_retry_delay_ms: u64,
) -> anyhow::Result<Option<(Self, CurrentTokenOwnershipV2)>> {
let token_address = standardize_address(&delete_resource.address.to_string());
Self::get_burned_nft_v2_helper(
&token_address,
txn_version,
write_set_change_index,
txn_timestamp,
prior_nft_ownership,
tokens_burned,
conn,
query_retries,
query_retry_delay_ms,
)
.await
}

async fn get_burned_nft_v2_helper(
token_address: &str,
txn_version: i64,
write_set_change_index: i64,
txn_timestamp: chrono::NaiveDateTime,
Expand All @@ -296,7 +339,7 @@ impl TokenOwnershipV2 {
query_retries: u32,
query_retry_delay_ms: u64,
) -> anyhow::Result<Option<(Self, CurrentTokenOwnershipV2)>> {
let token_address = standardize_address(&write_resource.address.to_string());
let token_address = standardize_address(token_address);
if let Some(burn_event) = tokens_burned.get(&token_address) {
// 1. Try to lookup token address in burn event mapping
let previous_owner = if let Some(burn_event) = burn_event {
Expand Down
5 changes: 5 additions & 0 deletions rust/processor/src/processors/token_v2_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,13 @@ async fn parse_v2_token(
txn_version,
wsc_index,
txn_timestamp,
&prior_nft_ownership,
&tokens_burned,
conn,
query_retries,
query_retry_delay_ms,
)
.await
.unwrap()
{
token_ownerships_v2.push(nft_ownership);
Expand Down
Loading