Skip to content

Commit

Permalink
Use new sequence numbers for Bubblegum Update Metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
danenbm committed Oct 20, 2023
1 parent 660a6ba commit 213dac5
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 51 deletions.
12 changes: 8 additions & 4 deletions digital_asset_types/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ pub fn create_asset_data(
metadata: JsonValue::String("processing".to_string()),
slot_updated: 0,
reindex: None,
raw_name: metadata.name.into_bytes().to_vec().clone(),
raw_symbol: metadata.symbol.into_bytes().to_vec().clone(),
raw_name: Some(metadata.name.into_bytes().to_vec().clone()),
raw_symbol: Some(metadata.symbol.into_bytes().to_vec().clone()),
base_info_seq: Some(0),
download_metadata_seq: Some(0),
},
)
}
Expand Down Expand Up @@ -157,6 +159,7 @@ pub fn create_asset(
owner_delegate_seq: Some(0),
was_decompressed: false,
leaf_seq: Some(0),
royalty_amount_seq: Some(0),
},
)
}
Expand All @@ -182,9 +185,10 @@ pub fn create_asset_creator(
creator,
share,
verified,
seq: Some(0),
verified_seq: Some(0),
slot_updated: Some(0),
position: 0,
base_info_seq: Some(0),
},
)
}
Expand Down Expand Up @@ -231,7 +235,7 @@ pub fn create_asset_grouping(
id: row_num,
group_key: "collection".to_string(),
slot_updated: Some(0),
verified: Some(false),
verified: false,
group_info_seq: Some(0),
},
)
Expand Down
6 changes: 4 additions & 2 deletions digital_asset_types/tests/json_parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ pub async fn parse_onchain_json(json: serde_json::Value) -> Content {
metadata: json,
slot_updated: 0,
reindex: None,
raw_name: String::from("Handalf").into_bytes().to_vec(),
raw_symbol: String::from("").into_bytes().to_vec(),
raw_name: Some(String::from("Handalf").into_bytes().to_vec()),
raw_symbol: Some(String::from("").into_bytes().to_vec()),
base_info_seq: Some(0),
download_metadata_seq: Some(0),
};

v1_content_from_json(&asset_data).unwrap()
Expand Down
30 changes: 15 additions & 15 deletions nft_ingester/src/program_transformers/bubblegum/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ where
asset_id: Set(asset_id),
creator: Set(creator),
verified: Set(verified),
seq: Set(Some(seq)),
verified_seq: Set(Some(seq)),
..Default::default()
};

Expand All @@ -366,7 +366,7 @@ where
])
.update_columns([
asset_creators::Column::Verified,
asset_creators::Column::Seq,
asset_creators::Column::VerifiedSeq,
])
.to_owned(),
)
Expand Down Expand Up @@ -403,7 +403,7 @@ where
asset_id: Set(asset_id),
group_key: Set("collection".to_string()),
group_value: Set(group_value),
verified: Set(Some(verified)),
verified: Set(verified),
slot_updated: Set(Some(slot_updated)),
group_info_seq: Set(Some(seq)),
..Default::default()
Expand Down Expand Up @@ -450,7 +450,7 @@ pub async fn upsert_asset_data<T>(
reindex: Option<bool>,
raw_name: Vec<u8>,
raw_symbol: Vec<u8>,
_seq: i64,
seq: i64,
) -> Result<(), IngesterError>
where
T: ConnectionTrait + TransactionTrait,
Expand All @@ -464,9 +464,10 @@ where
metadata: Set(metadata),
slot_updated: Set(slot_updated),
reindex: Set(reindex),
raw_name: Set(raw_name),
raw_symbol: Set(raw_symbol),
//base_info_seq: Set(seq),
raw_name: Set(Some(raw_name)),
raw_symbol: Set(Some(raw_symbol)),
base_info_seq: Set(Some(seq)),
..Default::default()
};

let mut query = asset_data::Entity::insert(model)
Expand All @@ -477,15 +478,14 @@ where
asset_data::Column::ChainData,
asset_data::Column::MetadataUrl,
asset_data::Column::MetadataMutability,
// Don't update Metadata if it already exists. Even if we are doing
// and update_metadata and there's a new URI, the new background task
// will overwrite it.
//asset_data::Column::Metadata,
// Don't update asset_data::Column::Metadata if it already exists. Even if we
// are indexing `update_metadata`` and there's a new URI, the new background
// task will overwrite it.
asset_data::Column::SlotUpdated,
asset_data::Column::Reindex,
asset_data::Column::RawName,
asset_data::Column::RawSymbol,
//asset_data::Column::BaseInfoSeq,
asset_data::Column::BaseInfoSeq,
])
.to_owned(),
)
Expand All @@ -505,15 +505,15 @@ pub async fn upsert_asset_with_royalty_amount<T>(
txn: &T,
id: Vec<u8>,
royalty_amount: i32,
_seq: i64,
seq: i64,
) -> Result<(), IngesterError>
where
T: ConnectionTrait + TransactionTrait,
{
let model = asset::ActiveModel {
id: Set(id.clone()),
royalty_amount: Set(royalty_amount),
//royalty_amount_seq: Set(Some(seq)),
royalty_amount_seq: Set(Some(seq)),
..Default::default()
};

Expand All @@ -522,7 +522,7 @@ where
OnConflict::column(asset::Column::Id)
.update_columns([
asset::Column::RoyaltyAmount,
//asset::Column::RoyaltyAmountSeq,
asset::Column::RoyaltyAmountSeq,
])
.to_owned(),
)
Expand Down
8 changes: 4 additions & 4 deletions nft_ingester/src/program_transformers/bubblegum/mint_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ 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))
base_info_seq: Set(Some(seq as i64)),
..Default::default()
});

db_creator_verified_infos.push(asset_creators::ActiveModel {
asset_id: Set(id_bytes.to_vec()),
creator: Set(c.address.to_bytes().to_vec()),
verified: Set(c.verified),
//verified_seq: Set(Some(seq as i64)),
verified_seq: Set(Some(seq as i64)),
..Default::default()
});

Expand All @@ -267,7 +267,7 @@ where
asset_creators::Column::Position,
asset_creators::Column::Share,
asset_creators::Column::SlotUpdated,
//asset_creators::Column::BaseInfoSeq,
asset_creators::Column::BaseInfoSeq,
])
.to_owned(),
)
Expand All @@ -289,7 +289,7 @@ where
])
.update_columns([
asset_creators::Column::Verified,
//asset_creators::Column::VerifiedSeq,
asset_creators::Column::VerifiedSeq,
])
.to_owned(),
)
Expand Down
18 changes: 10 additions & 8 deletions nft_ingester/src/program_transformers/bubblegum/update_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,15 @@ 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()
});

db_creator_verified_infos.push(asset_creators::ActiveModel {
asset_id: Set(id_bytes.to_vec()),
creator: Set(c.address.to_bytes().to_vec()),
verified: Set(c.verified),
seq: Set(Some(seq as i64)),
verified_seq: Set(Some(seq as i64)),
..Default::default()
});

Expand All @@ -215,11 +216,12 @@ where
.filter(
Condition::all()
.add(asset_creators::Column::AssetId.eq(id_bytes.to_vec()))
.add(asset_creators::Column::Creator.is_in(db_creators_to_remove)), // .add(
// Condition::any()
// .add(asset_creators::Column::VerifiedSeq.lt(seq as i64))
// .add(asset_creators::Column::VerifiedSeq.is_null()),
// ),
.add(asset_creators::Column::Creator.is_in(db_creators_to_remove))
.add(
Condition::any()
.add(asset_creators::Column::VerifiedSeq.lt(seq as i64))
.add(asset_creators::Column::VerifiedSeq.is_null()),
),
)
.exec(txn)
.await?;
Expand All @@ -237,7 +239,7 @@ where
asset_creators::Column::Position,
asset_creators::Column::Share,
asset_creators::Column::SlotUpdated,
//asset_creators::Column::BaseInfoSeq,
asset_creators::Column::BaseInfoSeq,
])
.to_owned(),
)
Expand All @@ -260,7 +262,7 @@ where
])
.update_columns([
asset_creators::Column::Verified,
//asset_creators::Column::VerifiedSeq,
asset_creators::Column::VerifiedSeq,
])
.to_owned(),
)
Expand Down
17 changes: 8 additions & 9 deletions nft_ingester/src/program_transformers/token_metadata/v1_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
slot_updated: Set(slot_i),
reindex: Set(Some(true)),
id: Set(id.to_vec()),
raw_name: Set(name.to_vec()),
raw_symbol: Set(symbol.to_vec()),
raw_name: Set(Some(name.to_vec())),
raw_symbol: Set(Some(symbol.to_vec())),
download_metadata_seq: Set(Some(0)),
..Default::default()
};
let txn = conn.begin().await?;
let mut query = asset_data::Entity::insert(asset_data_model)
Expand All @@ -161,7 +163,8 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
asset_data::Column::MetadataMutability,
asset_data::Column::SlotUpdated,
asset_data::Column::Reindex,
//TODO RAW NAME
asset_data::Column::RawName,
asset_data::Column::RawSymbol,
])
.to_owned(),
)
Expand Down Expand Up @@ -195,9 +198,6 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
asset_data: Set(Some(id.to_vec())),
slot_updated: Set(Some(slot_i)),
burnt: Set(false),
//data_hash,
//creator_hash,
//leaf_seq,
..Default::default()
};
let mut query = asset::Entity::insert(model)
Expand Down Expand Up @@ -282,7 +282,7 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
asset_id: Set(id.to_vec()),
group_key: Set("collection".to_string()),
group_value: Set(Some(c.key.to_string())),
verified: Set(Some(c.verified)),
verified: Set(c.verified),
seq: Set(None),
slot_updated: Set(Some(slot_i)),
..Default::default()
Expand Down Expand Up @@ -333,7 +333,6 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
creator: Set(c.address.to_bytes().to_vec()),
share: Set(c.share as i32),
verified: Set(c.verified),
seq: Set(Some(0)),
slot_updated: Set(Some(slot_i)),
position: Set(i as i16),
..Default::default()
Expand All @@ -360,7 +359,7 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
asset_creators::Column::Creator,
asset_creators::Column::Share,
asset_creators::Column::Verified,
asset_creators::Column::Seq,
asset_creators::Column::VerifiedSeq,
asset_creators::Column::SlotUpdated,
])
.to_owned(),
Expand Down
18 changes: 9 additions & 9 deletions nft_ingester/src/tasks/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,22 @@ impl BgTask for DownloadMetadataTask {
id: Unchanged(download_metadata.asset_data_id.clone()),
metadata: Set(body),
reindex: Set(Some(false)),
//download_metadata_seq: Set(Some(download_metadata.seq)),
download_metadata_seq: Set(Some(download_metadata.seq)),
..Default::default()
};
debug!(
"download metadata for {:?}",
bs58::encode(download_metadata.asset_data_id.clone()).into_string()
);
let query = asset_data::Entity::update(model)
let mut query = asset_data::Entity::update(model)
.filter(asset_data::Column::Id.eq(download_metadata.asset_data_id.clone()));
// if download_metadata.seq != 0 {
// query.filter(
// Condition::any()
// .add(asset_data::Column::DownloadMetadataSeq.lt(download_metadata.seq))
// .add(asset_data::Column::DownloadMetadataSeq.is_null()),
// );
// }
if download_metadata.seq != 0 {
query = query.filter(
Condition::any()
.add(asset_data::Column::DownloadMetadataSeq.lt(download_metadata.seq))
.add(asset_data::Column::DownloadMetadataSeq.is_null()),
);
}
query.exec(db).await.map(|_| ()).map_err(|db| {
IngesterError::TaskManagerError(format!(
"Database error with {}, error: {}",
Expand Down

0 comments on commit 213dac5

Please sign in to comment.