diff --git a/digital_asset_types/tests/common.rs b/digital_asset_types/tests/common.rs index ef551f251..50bfc194a 100644 --- a/digital_asset_types/tests/common.rs +++ b/digital_asset_types/tests/common.rs @@ -160,6 +160,7 @@ pub fn create_asset( was_decompressed: false, leaf_seq: Some(0), royalty_amount_seq: Some(0), + creators_added_seq: Some(0), }, ) } @@ -188,7 +189,6 @@ pub fn create_asset_creator( verified_seq: Some(0), slot_updated: Some(0), position: 0, - base_info_seq: Some(0), }, ) } diff --git a/nft_ingester/src/program_transformers/bubblegum/db.rs b/nft_ingester/src/program_transformers/bubblegum/db.rs index d207a44a9..2738bcb7f 100644 --- a/nft_ingester/src/program_transformers/bubblegum/db.rs +++ b/nft_ingester/src/program_transformers/bubblegum/db.rs @@ -391,40 +391,6 @@ where Ok(()) } -pub async fn upsert_asset_with_creators_added_seq( - txn: &T, - id: Vec, - seq: i64, -) -> Result<(), IngesterError> -where - T: ConnectionTrait + TransactionTrait, -{ - let model = asset::ActiveModel { - id: Set(id), - seq: Set(Some(seq)), - ..Default::default() - }; - - let mut query = asset::Entity::insert(model) - .on_conflict( - OnConflict::column(asset::Column::Id) - .update_columns([asset::Column::Seq]) - .to_owned(), - ) - .build(DbBackend::Postgres); - - query.sql = format!( - "{} WHERE excluded.creators_added_seq >= asset.creators_added_seq OR asset.creators_added_seq IS NULL", - query.sql - ); - - txn.execute(query) - .await - .map_err(|db_err| IngesterError::StorageWriteError(db_err.to_string()))?; - - Ok(()) -} - pub async fn upsert_collection_info( txn: &T, asset_id: Vec, @@ -602,11 +568,45 @@ where T: ConnectionTrait + TransactionTrait, { if let Some(asset) = asset::Entity::find_by_id(id).one(txn).await? { - if let Some(creator_array_seq) = asset.seq { - if seq < creator_array_seq { + if let Some(creators_added_seq) = asset.creators_added_seq { + if seq < creators_added_seq { return Ok(false); } } } Ok(true) } + +pub async fn upsert_asset_with_creators_added_seq( + txn: &T, + id: Vec, + seq: i64, +) -> Result<(), IngesterError> +where + T: ConnectionTrait + TransactionTrait, +{ + let model = asset::ActiveModel { + id: Set(id), + creators_added_seq: Set(Some(seq)), + ..Default::default() + }; + + let mut query = asset::Entity::insert(model) + .on_conflict( + OnConflict::column(asset::Column::Id) + .update_columns([asset::Column::CreatorsAddedSeq]) + .to_owned(), + ) + .build(DbBackend::Postgres); + + query.sql = format!( + "{} WHERE excluded.creators_added_seq >= asset.creators_added_seq OR asset.creators_added_seq IS NULL", + query.sql + ); + + txn.execute(query) + .await + .map_err(|db_err| IngesterError::StorageWriteError(db_err.to_string()))?; + + Ok(()) +} diff --git a/nft_ingester/src/program_transformers/bubblegum/mint_v1.rs b/nft_ingester/src/program_transformers/bubblegum/mint_v1.rs index 1c7cba0fe..8ba918e52 100644 --- a/nft_ingester/src/program_transformers/bubblegum/mint_v1.rs +++ b/nft_ingester/src/program_transformers/bubblegum/mint_v1.rs @@ -244,7 +244,6 @@ where position: Set(i as i16), share: Set(c.share as i32), slot_updated: Set(Some(slot_i)), - base_info_seq: Set(Some(seq as i64)), ..Default::default() }); @@ -276,9 +275,8 @@ where .build(DbBackend::Postgres); txn.execute(query).await?; - // This statement will update whether the creator is verified and the `seq` - // number. `seq` is used to protect the `verified` field, allowing for `mint` - // and `verifyCreator` to be processed out of order. + // This statement will update whether the creator is verified and the + // `verified_seq` number. let mut query = asset_creators::Entity::insert_many(db_creator_verified_infos) .on_conflict( OnConflict::columns([ diff --git a/nft_ingester/src/program_transformers/bubblegum/update_metadata.rs b/nft_ingester/src/program_transformers/bubblegum/update_metadata.rs index 2d2f6d37a..1b08f20e4 100644 --- a/nft_ingester/src/program_transformers/bubblegum/update_metadata.rs +++ b/nft_ingester/src/program_transformers/bubblegum/update_metadata.rs @@ -191,7 +191,6 @@ where position: Set(i as i16), share: Set(c.share as i32), slot_updated: Set(Some(slot_i)), - base_info_seq: Set(Some(seq as i64)), ..Default::default() }); @@ -221,20 +220,13 @@ where .add( asset_creators::Column::Creator .is_in(db_creators_to_remove), - ) - .add( - Condition::any() - .add(asset_creators::Column::BaseInfoSeq.lt(seq as i64)) - .add(asset_creators::Column::BaseInfoSeq.is_null()), ), ) .exec(txn) .await?; - // This statement will update base information for each creator and the - // `base_info_seq` number, allows for `mintV1` and `update_metadata` to be - // processed out of order. - let mut query = asset_creators::Entity::insert_many(db_creator_infos) + // This statement will update base information for each creator. + let query = asset_creators::Entity::insert_many(db_creator_infos) .on_conflict( OnConflict::columns([ asset_creators::Column::AssetId, @@ -244,21 +236,14 @@ where asset_creators::Column::Position, asset_creators::Column::Share, asset_creators::Column::SlotUpdated, - asset_creators::Column::BaseInfoSeq, ]) .to_owned(), ) .build(DbBackend::Postgres); - query.sql = format!( - "{} WHERE excluded.base_info_seq >= asset_creators.base_info_seq OR asset_creators.base_info_seq IS NULL", - query.sql - ); txn.execute(query).await?; // This statement will update whether the creator is verified and the - // `verified_seq` number, which is used to protect the `verified` field, - // allowing for `mintV1`, `update_metadata`, and `verifyCreator` to be - // processed out of order. + // `verified_seq` number. let mut query = asset_creators::Entity::insert_many(db_creator_verified_infos) .on_conflict(