Skip to content

Commit

Permalink
Merge pull request #24 from okx/yz/case_sensitive
Browse files Browse the repository at this point in the history
brc20 case sensitive
  • Loading branch information
wanyvic authored May 10, 2023
2 parents b5e72a6 + 186af7d commit cb939fb
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions src/brc20/operation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ pub enum Operation {
}

pub fn deserialize_brc20(s: &str) -> Result<Operation, JSONError> {
let mut value: Value = serde_json::from_str(s).map_err(|_| JSONError::InvalidJson)?;
let entry = value.as_object_mut().ok_or(JSONError::InvalidJson)?;
*entry = std::mem::take(entry)
.into_iter()
.map(|(k, v)| (k.to_lowercase(), v))
.collect();

let value: Value = serde_json::from_str(s).map_err(|_| JSONError::InvalidJson)?;
if value.get("p") != Some(&json!(PROTOCOL_LITERAL)) {
return Err(JSONError::NotBRC20Json);
}
Expand Down Expand Up @@ -135,14 +129,6 @@ mod tests {
}}"##
);

assert_eq!(
deserialize_brc20(&json_str).unwrap(),
Operation::Deploy(Deploy {
tick: "ordi".to_string(),
max_supply,
mint_limit: Some(mint_limit),
decimals: None
})
);
assert_eq!(deserialize_brc20(&json_str), Err(JSONError::NotBRC20Json));
}
}

0 comments on commit cb939fb

Please sign in to comment.