Skip to content

Commit

Permalink
Add raw_name and raw_symbol (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
linuskendall authored Sep 19, 2023
1 parent 2a58da5 commit baba78b
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 3 deletions.
6 changes: 6 additions & 0 deletions digital_asset_types/src/dao/generated/asset_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub struct Model {
pub metadata: Json,
pub slot_updated: i64,
pub reindex: Option<bool>,
pub raw_name: Vec<u8>,
pub raw_symbol: Vec<u8>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
Expand All @@ -36,6 +38,8 @@ pub enum Column {
Metadata,
SlotUpdated,
Reindex,
RawName,
RawSymbol,
}

#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
Expand Down Expand Up @@ -67,6 +71,8 @@ impl ColumnTrait for Column {
Self::Metadata => ColumnType::JsonBinary.def(),
Self::SlotUpdated => ColumnType::BigInteger.def(),
Self::Reindex => ColumnType::Boolean.def(),
Self::RawName => ColumnType::Binary.def(),
Self::RawSymbol => ColumnType::Binary.def(),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions digital_asset_types/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ 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(),
},
)
}
Expand Down
2 changes: 2 additions & 0 deletions digital_asset_types/tests/json_parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ 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(),
};

v1_content_from_json(&asset_data).unwrap()
Expand Down
4 changes: 3 additions & 1 deletion migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod m20230720_120101_add_asset_grouping_verified;
mod m20230720_130101_remove_asset_grouping_null_constraints;
mod m20230724_120101_add_group_info_seq;
mod m20230726_013107_remove_not_null_constraint_from_group_value;
mod m20230918_182123_add_raw_name_symbol;

pub struct Migrator;

Expand Down Expand Up @@ -58,11 +59,12 @@ impl MigratorTrait for Migrator {
Box::new(m20230615_120101_remove_asset_null_constraints::Migration),
Box::new(m20230620_120101_add_was_decompressed::Migration),
Box::new(m20230623_120101_add_leaf_sequence_number::Migration),
Box::new(m20230726_013107_remove_not_null_constraint_from_group_value::Migration),
Box::new(m20230712_120101_remove_asset_creators_null_constraints::Migration),
Box::new(m20230720_120101_add_asset_grouping_verified::Migration),
Box::new(m20230720_130101_remove_asset_grouping_null_constraints::Migration),
Box::new(m20230724_120101_add_group_info_seq::Migration),
Box::new(m20230726_013107_remove_not_null_constraint_from_group_value::Migration),
Box::new(m20230918_182123_add_raw_name_symbol::Migration),
]
}
}
57 changes: 57 additions & 0 deletions migration/src/m20230918_182123_add_raw_name_symbol.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
sea_query::Table::alter()
.table(asset_data::Entity)
.add_column(ColumnDef::new(Alias::new("raw_name")).binary())
.to_owned(),
)
.await?;
manager
.alter_table(
sea_query::Table::alter()
.table(asset_data::Entity)
.add_column(ColumnDef::new(Alias::new("raw_symbol")).binary())
.to_owned(),
)
.await?;
Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
sea_query::Table::alter()
.table(asset_data::Entity)
.drop_column(Alias::new("raw_name"))
.to_owned(),
)
.await?;

manager
.alter_table(
sea_query::Table::alter()
.table(asset_data::Entity)
.drop_column(Alias::new("raw_symbol"))
.to_owned(),
)
.await?;
Ok(())
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
enum Post {
Table,
Id,
Title,
Text,
}
4 changes: 4 additions & 0 deletions nft_ingester/src/program_transformers/bubblegum/mint_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ where
let id_bytes = id.to_bytes();
let slot_i = bundle.slot as i64;
let uri = metadata.uri.trim().replace('\0', "");
let name = metadata.name.clone().into_bytes();
let symbol = metadata.symbol.clone().into_bytes();
let mut chain_data = ChainDataV1 {
name: metadata.name.clone(),
symbol: metadata.symbol.clone(),
Expand Down Expand Up @@ -95,6 +97,8 @@ where
metadata_mutability: Set(Mutability::Mutable),
slot_updated: Set(slot_i),
reindex: Set(Some(true)),
raw_name: Set(name.to_vec()),
raw_symbol: Set(symbol.to_vec()),
..Default::default()
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
},
None => (NotSet, NotSet),
};
let name = data.name.clone().into_bytes();
let symbol = data.symbol.clone().into_bytes();
let mut chain_data = ChainDataV1 {
name: data.name,
symbol: data.symbol,
name: data.name.clone(),
symbol: data.symbol.clone(),
edition_nonce: metadata.edition_nonce,
primary_sale_happened: metadata.primary_sale_happened,
token_standard: metadata.token_standard,
Expand All @@ -191,6 +193,8 @@ 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()),
};
let txn = conn.begin().await?;
let mut query = asset_data::Entity::insert(asset_data_model)
Expand Down

0 comments on commit baba78b

Please sign in to comment.