diff --git a/src/api.rs b/src/api.rs index 2867fdfae3..0983b5225e 100644 --- a/src/api.rs +++ b/src/api.rs @@ -80,6 +80,7 @@ pub struct Inscription { pub children: Vec, pub content_length: Option, pub content_type: Option, + pub effective_content_type: Option, pub fee: u64, pub height: u32, pub id: InscriptionId, diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 1522cb70bf..92de3206c3 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -1519,6 +1519,17 @@ 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 @@ -1535,6 +1546,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 abc8b635ed..ac02c1c122 100644 --- a/tests/json_api.rs +++ b/tests/json_api.rs @@ -160,6 +160,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, diff --git a/tests/wallet/inscribe.rs b/tests/wallet/inscribe.rs index 1f35ecde7b..755e98c9ac 100644 --- a/tests/wallet/inscribe.rs +++ b/tests/wallet/inscribe.rs @@ -2185,6 +2185,39 @@ 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::(); + + 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 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();