From 98849f5a5bd6eb23697304e97c70b9a52e634e3a Mon Sep 17 00:00:00 2001 From: Arik Sosman <git@arik.io> Date: Thu, 14 Mar 2024 13:24:53 -0700 Subject: [PATCH 1/4] Create effective content type field for delegating inscriptions. --- src/api.rs | 2 ++ src/subcommand/server.rs | 10 ++++++++++ tests/json_api.rs | 1 + 3 files changed, 13 insertions(+) diff --git a/src/api.rs b/src/api.rs index a1b9c5127b..f00411bf9a 100644 --- a/src/api.rs +++ b/src/api.rs @@ -83,6 +83,8 @@ pub struct Inscription { pub children: Vec<InscriptionId>, pub content_length: Option<usize>, pub content_type: Option<String>, + /// Exposes the "real" content type, applicable to delegating inscriptions + pub effective_content_type: Option<String>, pub fee: u64, pub height: u32, pub id: InscriptionId, diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 1ac3f2b6ac..cf26cd2ca6 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -1473,6 +1473,15 @@ impl Server { let info = Index::inscription_info(&index, query)? .ok_or_not_found(|| format!("inscription {query}"))?; + let effective_mime_type = if let Some(delegate_id) = info.inscription.delegate() { + let delegate_result = index.get_inscription_by_id(delegate_id); + if let Ok(Some(delegate)) = delegate_result { + delegate.content_type().map(str::to_string) + } else { + info.inscription.content_type().map(str::to_string) + } + } else { info.inscription.content_type().map(str::to_string) }; + Ok(if accept_json { Json(api::Inscription { address: info @@ -1493,6 +1502,7 @@ impl Server { children: info.children, content_length: info.inscription.content_length(), content_type: info.inscription.content_type().map(|s| s.to_string()), + effective_content_type: effective_mime_type, fee: info.entry.fee, height: info.entry.height, id: info.entry.id, diff --git a/tests/json_api.rs b/tests/json_api.rs index b41188dfab..f4360dee8e 100644 --- a/tests/json_api.rs +++ b/tests/json_api.rs @@ -157,6 +157,7 @@ fn get_inscription() { children: Vec::new(), content_length: Some(3), content_type: Some("text/plain;charset=utf-8".to_string()), + effective_content_type: Some("text/plain;charset=utf-8".to_string()), fee: 138, height: 2, id: inscription_id, From c4e7ee8a4f2b166b63a84f81428d6b086375711e Mon Sep 17 00:00:00 2001 From: Arik Sosman <git@arik.io> Date: Thu, 14 Mar 2024 14:49:23 -0700 Subject: [PATCH 2/4] Test effective content type return. --- tests/wallet/inscribe.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/wallet/inscribe.rs b/tests/wallet/inscribe.rs index e0efd95879..9d4e0a3ddf 100644 --- a/tests/wallet/inscribe.rs +++ b/tests/wallet/inscribe.rs @@ -2177,6 +2177,36 @@ fn file_inscribe_with_delegate_inscription() { ord_rpc_server.assert_response(format!("/content/{}", inscribe.inscriptions[0].id), "FOO"); } +#[test] +fn inscription_with_delegate_returns_effective_content_type() { + let bitcoin_rpc_server = test_bitcoincore_rpc::spawn(); + let ord_rpc_server = TestServer::spawn_with_server_args(&bitcoin_rpc_server, &[], &[]); + create_wallet(&bitcoin_rpc_server, &ord_rpc_server); + + bitcoin_rpc_server.mine_blocks(1); + let (delegate, _) = inscribe(&bitcoin_rpc_server, &ord_rpc_server); + + let inscribe = CommandBuilder::new(format!( + "wallet inscribe --fee-rate 1.0 --delegate {delegate} --file meow.wav" + )) + .write("meow.wav", [0; 2048]) + .bitcoin_rpc_server(&bitcoin_rpc_server) + .ord_rpc_server(&ord_rpc_server) + .run_and_deserialize_output::<Inscribe>(); + + bitcoin_rpc_server.mine_blocks(1); + + let inscription_id = inscribe.inscriptions[0].id; + let json_response = ord_rpc_server.json_request(format!("/inscription/{}", inscription_id)); + + let mut inscription_json: api::Inscription = + serde_json::from_str(&json_response.text().unwrap()).unwrap(); + assert_regex_match!(inscription_json.address.unwrap(), r"bc1p.*"); + + assert_eq!(inscription_json.content_type, Some("audio/wav".to_string())); + assert_eq!(inscription_json.effective_content_type, Some("text/plain;charset=utf-8".to_string())); +} + #[test] fn file_inscribe_with_non_existent_delegate_inscription() { let bitcoin_rpc_server = test_bitcoincore_rpc::spawn(); From 70a12e8378d0e607e9dd4bc9e3e0da21f18003c1 Mon Sep 17 00:00:00 2001 From: Arik Sosman <git@arik.io> Date: Thu, 14 Mar 2024 14:52:53 -0700 Subject: [PATCH 3/4] Fix formating. --- src/subcommand/server.rs | 4 +++- tests/wallet/inscribe.rs | 17 ++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index cf26cd2ca6..2db8d2cd3e 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -1480,7 +1480,9 @@ impl Server { } else { info.inscription.content_type().map(str::to_string) } - } else { info.inscription.content_type().map(str::to_string) }; + } else { + info.inscription.content_type().map(str::to_string) + }; Ok(if accept_json { Json(api::Inscription { diff --git a/tests/wallet/inscribe.rs b/tests/wallet/inscribe.rs index 9d4e0a3ddf..23fb5db0a4 100644 --- a/tests/wallet/inscribe.rs +++ b/tests/wallet/inscribe.rs @@ -2189,22 +2189,25 @@ fn inscription_with_delegate_returns_effective_content_type() { let inscribe = CommandBuilder::new(format!( "wallet inscribe --fee-rate 1.0 --delegate {delegate} --file meow.wav" )) - .write("meow.wav", [0; 2048]) - .bitcoin_rpc_server(&bitcoin_rpc_server) - .ord_rpc_server(&ord_rpc_server) - .run_and_deserialize_output::<Inscribe>(); + .write("meow.wav", [0; 2048]) + .bitcoin_rpc_server(&bitcoin_rpc_server) + .ord_rpc_server(&ord_rpc_server) + .run_and_deserialize_output::<Inscribe>(); bitcoin_rpc_server.mine_blocks(1); let inscription_id = inscribe.inscriptions[0].id; let json_response = ord_rpc_server.json_request(format!("/inscription/{}", inscription_id)); - let mut inscription_json: api::Inscription = - serde_json::from_str(&json_response.text().unwrap()).unwrap(); + let inscription_json: api::Inscription = + serde_json::from_str(&json_response.text().unwrap()).unwrap(); assert_regex_match!(inscription_json.address.unwrap(), r"bc1p.*"); assert_eq!(inscription_json.content_type, Some("audio/wav".to_string())); - assert_eq!(inscription_json.effective_content_type, Some("text/plain;charset=utf-8".to_string())); + assert_eq!( + inscription_json.effective_content_type, + Some("text/plain;charset=utf-8".to_string()) + ); } #[test] From e71567a6b34d67f03ffaa74783cb369121a4d41a Mon Sep 17 00:00:00 2001 From: raphjaph <raphjaph@protonmail.com> Date: Wed, 27 Mar 2024 15:01:21 -0700 Subject: [PATCH 4/4] Amend --- src/api.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/api.rs b/src/api.rs index f00411bf9a..f9bf4c7c8d 100644 --- a/src/api.rs +++ b/src/api.rs @@ -83,7 +83,6 @@ pub struct Inscription { pub children: Vec<InscriptionId>, pub content_length: Option<usize>, pub content_type: Option<String>, - /// Exposes the "real" content type, applicable to delegating inscriptions pub effective_content_type: Option<String>, pub fee: u64, pub height: u32,