Skip to content

Commit

Permalink
fix: backwards compatibility for old data post out-of-order fix (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasPennie authored Aug 23, 2023
1 parent 02d3022 commit d22227f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 20 deletions.
1 change: 1 addition & 0 deletions das_api/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub struct SearchAssets {

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]

pub struct GetAssetsByAuthority {
pub authority_address: String,
pub sort_by: Option<AssetSorting>,
Expand Down
2 changes: 1 addition & 1 deletion digital_asset_types/src/dao/generated/asset_grouping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Model {
pub group_value: Option<String>,
pub seq: Option<i64>,
pub slot_updated: Option<i64>,
pub verified: bool,
pub verified: Option<bool>,
pub group_info_seq: Option<i64>,
}

Expand Down
32 changes: 26 additions & 6 deletions digital_asset_types/src/dao/scopes/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ pub async fn get_grouping(
Condition::all()
.add(asset_grouping::Column::GroupKey.eq(group_key))
.add(asset_grouping::Column::GroupValue.eq(group_value))
.add(asset_grouping::Column::Verified.eq(true)),
.add(
Condition::any()
.add(asset_grouping::Column::Verified.eq(true))
.add(asset_grouping::Column::Verified.is_null()),
),
)
.count(conn)
.await?;
Expand All @@ -95,7 +99,11 @@ pub async fn get_by_grouping(
let condition = asset_grouping::Column::GroupKey
.eq(group_key)
.and(asset_grouping::Column::GroupValue.eq(group_value))
.and(asset_grouping::Column::Verified.eq(true));
.and(
asset_grouping::Column::Verified
.eq(true)
.or(asset_grouping::Column::Verified.is_null()),
);
get_by_related_condition(
conn,
Condition::all()
Expand Down Expand Up @@ -270,7 +278,13 @@ pub async fn get_related_for_assets(
let grouping = asset_grouping::Entity::find()
.filter(asset_grouping::Column::AssetId.is_in(ids.clone()))
.filter(asset_grouping::Column::GroupValue.is_not_null())
.filter(asset_grouping::Column::Verified.eq(true))
.filter(
Condition::any()
.add(asset_grouping::Column::Verified.eq(true))
// Older versions of the indexer did not have the verified flag. A group would be present if and only if it was verified.
// Therefore if verified is null, we can assume that the group is verified.
.add(asset_grouping::Column::Verified.is_null()),
)
.order_by_asc(asset_grouping::Column::AssetId)
.all(conn)
.await?;
Expand Down Expand Up @@ -322,7 +336,7 @@ pub async fn get_by_id(
let asset_data: (asset::Model, asset_data::Model) =
asset_data.one(conn).await.and_then(|o| match o {
Some((a, Some(d))) => Ok((a, d)),
_ => Err(DbErr::RecordNotFound("Asset Not Found".to_string()))
_ => Err(DbErr::RecordNotFound("Asset Not Found".to_string())),
})?;

let (asset, data) = asset_data;
Expand All @@ -333,13 +347,19 @@ pub async fn get_by_id(
.await?;
let creators: Vec<asset_creators::Model> = asset_creators::Entity::find()
.filter(asset_creators::Column::AssetId.eq(asset.id.clone()))
.order_by_asc(asset_creators::Column::AssetId)
.order_by_asc(asset_creators::Column::Position)
.all(conn)
.await?;
let grouping: Vec<asset_grouping::Model> = asset_grouping::Entity::find()
.filter(asset_grouping::Column::AssetId.eq(asset.id.clone()))
.filter(asset_grouping::Column::GroupValue.is_not_null())
.filter(asset_grouping::Column::Verified.eq(true))
.filter(
Condition::any()
.add(asset_grouping::Column::Verified.eq(true))
// Older versions of the indexer did not have the verified flag. A group would be present if and only if it was verified.
// Therefore if verified is null, we can assume that the group is verified.
.add(asset_grouping::Column::Verified.is_null()),
)
.order_by_asc(asset_grouping::Column::AssetId)
.all(conn)
.await?;
Expand Down
14 changes: 5 additions & 9 deletions digital_asset_types/src/dapi/common/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ pub fn to_grouping(groups: Vec<asset_grouping::Model>) -> Result<Vec<Group>, DbE
group_key: model.group_key.clone(),
group_value: Some(
model
.group_value
.clone()
.ok_or(DbErr::Custom("Group value not found".to_string()))?,
.group_value
.clone()
.ok_or(DbErr::Custom("Group value not found".to_string()))?,
),
collection_metadata: None,
})
Expand Down Expand Up @@ -408,12 +408,8 @@ pub fn asset_to_rpc(
compression: Some(Compression {
eligible: asset.compressible,
compressed: asset.compressed,
leaf_id: asset
.nonce
.ok_or(DbErr::Custom("Nonce not found".to_string()))?,
seq: asset
.seq
.ok_or(DbErr::Custom("Seq not found".to_string()))?,
leaf_id: asset.nonce.unwrap_or(0 as i64),
seq: asset.seq.unwrap_or(0 as i64),
tree: asset
.tree_id
.map(|s| bs58::encode(s).into_string())
Expand Down
2 changes: 1 addition & 1 deletion nft_ingester/src/program_transformers/bubblegum/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ where
asset_id: Set(asset_id),
group_key: Set("collection".to_string()),
group_value: Set(group_value),
verified: Set(verified),
verified: Set(Some(verified)),
slot_updated: Set(Some(slot_updated)),
group_info_seq: Set(Some(seq)),
..Default::default()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
specification_version: Set(Some(SpecificationVersions::V1)),
specification_asset_class: Set(Some(class)),
tree_id: Set(None),
nonce: Set(None),
seq: Set(None),
nonce: Set(Some(0)),
seq: Set(Some(0)),
leaf: Set(None),
compressed: Set(false),
compressible: Set(false),
Expand Down Expand Up @@ -272,7 +272,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(c.verified),
verified: Set(Some(c.verified)),
seq: Set(None),
slot_updated: Set(Some(slot_i)),
..Default::default()
Expand Down

0 comments on commit d22227f

Please sign in to comment.