Skip to content

Commit

Permalink
Change creator metadata updates to use new creators_added_seq
Browse files Browse the repository at this point in the history
  • Loading branch information
danenbm committed Oct 23, 2023
1 parent f2b1218 commit 77020fa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 59 deletions.
2 changes: 1 addition & 1 deletion digital_asset_types/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
)
}
Expand Down Expand Up @@ -188,7 +189,6 @@ pub fn create_asset_creator(
verified_seq: Some(0),
slot_updated: Some(0),
position: 0,
base_info_seq: Some(0),
},
)
}
Expand Down
72 changes: 36 additions & 36 deletions nft_ingester/src/program_transformers/bubblegum/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,40 +391,6 @@ where
Ok(())
}

pub async fn upsert_asset_with_creators_added_seq<T>(
txn: &T,
id: Vec<u8>,
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<T>(
txn: &T,
asset_id: Vec<u8>,
Expand Down Expand Up @@ -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<T>(
txn: &T,
id: Vec<u8>,
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(())
}
6 changes: 2 additions & 4 deletions nft_ingester/src/program_transformers/bubblegum/mint_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
});

Expand Down Expand Up @@ -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([
Expand Down
21 changes: 3 additions & 18 deletions nft_ingester/src/program_transformers/bubblegum/update_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
});

Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit 77020fa

Please sign in to comment.