Skip to content

Commit

Permalink
store data as is in the database (metaplex-foundation#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil Acharya authored Jun 3, 2023
1 parent 404acdb commit 2c453f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
19 changes: 17 additions & 2 deletions digital_asset_types/src/dapi/common/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ pub fn safe_select<'a>(
.and_then(|v| v.pop())
}

fn sanitize(val: Value) -> Result<String, &'static str> {
match val {
Value::String(s) => Ok(s.trim().replace("\0", "").to_string()),
_ => Err("Provided value is not a string"),
}
}

pub fn v1_content_from_json(
asset_data: &asset_data::Model,
cdn_prefix: Option<String>,
Expand All @@ -141,15 +148,23 @@ pub fn v1_content_from_json(
let mut meta: MetadataMap = MetadataMap::new();
let name = safe_select(chain_data_selector, "$.name");
if let Some(name) = name {
meta.set_item("name", name.clone());
if let Ok(name) = sanitize(name.clone()) {
meta.set_item("name", Value::String(name));
} else {
meta.set_item("name", name.clone());
}
}
let desc = safe_select(selector, "$.description");
if let Some(desc) = desc {
meta.set_item("description", desc.clone());
}
let symbol = safe_select(chain_data_selector, "$.symbol");
if let Some(symbol) = symbol {
meta.set_item("symbol", symbol.clone());
if let Ok(symbol) = sanitize(symbol.clone()) {
meta.set_item("symbol", Value::String(symbol));
} else {
meta.set_item("symbol", symbol.clone());
}
}
let symbol = safe_select(selector, "$.attributes");
if let Some(symbol) = symbol {
Expand Down
3 changes: 1 addition & 2 deletions nft_ingester/src/program_transformers/bubblegum/mint_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ where
let id_bytes = id.to_bytes();
let slot_i = bundle.slot as i64;
let uri = metadata.uri.trim().replace('\0', "");
let mut chain_data = ChainDataV1 {
let chain_data = ChainDataV1 {
name: metadata.name.clone(),
symbol: metadata.symbol.clone(),
edition_nonce: metadata.edition_nonce,
Expand All @@ -73,7 +73,6 @@ where
total: u.total,
}),
};
chain_data.sanitize();
let chain_data_json = serde_json::to_value(chain_data)
.map_err(|e| IngesterError::DeserializationError(e.to_string()))?;
let chain_mutability = match metadata.is_mutable {
Expand Down

0 comments on commit 2c453f6

Please sign in to comment.