Skip to content

Commit

Permalink
Hide all text (ordinals#2753)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph committed Nov 27, 2023
1 parent 3adccf8 commit 7219789
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 42 deletions.
53 changes: 12 additions & 41 deletions src/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,40 +309,14 @@ impl Inscription {

pub(crate) fn hidden(&self) -> bool {
let Some(content_type) = self.content_type() else {
return false;
};

if content_type.starts_with("application/json") {
return true;
}

if !content_type.starts_with("text/plain") {
return false;
}

let Some(body) = &self.body else {
return false;
};

let Ok(text) = str::from_utf8(body) else {
return false;
};

let trimmed = text.trim();

if trimmed.starts_with('{') && trimmed.ends_with('}') {
return true;
}

if trimmed.starts_with("gib bc1") {
return true;
}

if trimmed.ends_with(".bitmap") {
if content_type.starts_with("application/json") {
return true;
}

if trimmed.ends_with(".btc") {
if content_type.starts_with("text/plain") {
return true;
}

Expand Down Expand Up @@ -811,22 +785,19 @@ mod tests {
);
}

case(None, None, false);
case(None, None, true);
case(Some("foo"), None, false);
case(Some("foo"), Some("{}"), false);
case(Some("text/plain"), None, false);
case(Some("text/plain"), Some("foo{}bar"), false);
case(Some("text/plain"), Some("foo.btc"), true);

case(Some("text/plain"), Some("foo.bitmap"), true);
case(Some("text/plain"), Some("gib bc1"), true);
case(Some("text/plain"), Some("{}"), true);
case(Some("text/plain"), Some(" {} "), true);
case(Some("text/plain;charset=utf-8"), Some("foo.bitmap"), true);
case(Some("text/plain;charset=cn-big5"), Some("foo.bitmap"), true);
case(Some("text/plain"), None, true);
case(
Some("text/plain"),
Some("The fox jumped. The cow danced."),
true,
);
case(Some("text/plain;charset=utf-8"), Some("foo"), true);
case(Some("text/plain;charset=cn-big5"), Some("foo"), true);
case(Some("application/json"), Some("foo"), true);

assert!(!Inscription {
assert!(Inscription {
content_type: Some("text/plain".as_bytes().into()),
body: Some(b"{\xc3\x28}".as_slice().into()),
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2796,7 +2796,7 @@ mod tests {

for i in 0..101 {
let txid = server.bitcoin_rpc_server.broadcast_tx(TransactionTemplate {
inputs: &[(i + 1, 0, 0, inscription("text/plain", "hello").to_witness())],
inputs: &[(i + 1, 0, 0, inscription("foo", "hello").to_witness())],
..Default::default()
});
ids.push(InscriptionId { txid, index: 0 });
Expand Down

0 comments on commit 7219789

Please sign in to comment.