Skip to content

Commit

Permalink
Merge pull request #30 from okx/fix/support_media
Browse files Browse the repository at this point in the history
Fix/support media
  • Loading branch information
wanyvic authored May 11, 2023
2 parents 302c5da + 1d2ed18 commit 7cdbb30
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/brc20/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ pub enum Error<L: LedgerRead> {

#[derive(Debug, PartialEq, thiserror::Error)]
pub enum JSONError {
#[error("invalid content type")]
InvalidContentType,

#[error("unsupport content type")]
UnSupportContentType,

#[error("invalid json string")]
InvalidJson,

Expand Down
15 changes: 12 additions & 3 deletions src/brc20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ pub use self::{

use ledger::{LedgerRead, LedgerReadWrite};

const MEDIA_TYPE_TEXT: &str = "text/plain;charset=utf-8";
const MEDIA_TYPE_JSON: &str = "application/json";

pub fn deserialize_brc20_operation(inscription: Inscription) -> Result<Operation> {
Ok(deserialize_brc20(std::str::from_utf8(
inscription.body().ok_or(JSONError::InvalidJson)?,
)?)?)
match inscription
.content_type()
.ok_or(JSONError::InvalidContentType)?
{
MEDIA_TYPE_TEXT | MEDIA_TYPE_JSON => Ok(deserialize_brc20(std::str::from_utf8(
inscription.body().ok_or(JSONError::InvalidJson)?,
)?)?),
&_ => Err(JSONError::UnSupportContentType.into()),
}
}

0 comments on commit 7cdbb30

Please sign in to comment.