-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add name and symbol to the asset_data table #54
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,35 @@ pub fn safe_select<'a>( | |
.and_then(|v| v.pop()) | ||
} | ||
|
||
#[cfg(feature = "fetch-raw-fields")] | ||
async fn process_raw_fields( | ||
name: Option<String>, | ||
symbol: Option<String>, | ||
asset_data: &AssetData, | ||
) -> (Option<String>, Option<String>) { | ||
let name_result = if let Some(name) = &name { | ||
let raw_name = asset_data.raw_name.clone(); | ||
match String::from_utf8(raw_name) { | ||
Ok(s) => Some(s), | ||
Err(_) => Some(name.clone()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Under what scenarios would this happen? Do you have an example NFT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can fail if the utf8 check validation of the string fails. I don't have an example nft |
||
} | ||
} else { | ||
None | ||
}; | ||
|
||
let symbol_result = if let Some(symbol) = &symbol { | ||
let raw_symbol = asset_data.raw_symbol.clone(); | ||
match String::from_utf8(raw_symbol) { | ||
Ok(s) => Some(s), | ||
Err(_) => Some(symbol.clone()), | ||
} | ||
} else { | ||
None | ||
}; | ||
|
||
(name_result, symbol_result) | ||
} | ||
|
||
pub fn v1_content_from_json( | ||
asset_data: &asset_data::Model, | ||
cdn_prefix: Option<String>, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use digital_asset_types::dao::asset_data; | ||
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(()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How will this function be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, I am using it for testing purpose. Its disabled due the compile/build time flag. However, based on a new optional field in the api, we will extract the raw fields or the sanitised fields