diff --git a/src/api.rs b/src/api.rs index cbc92cad91..48e3e272f7 100644 --- a/src/api.rs +++ b/src/api.rs @@ -110,6 +110,7 @@ pub struct Inscription { pub satpoint: SatPoint, pub timestamp: i64, pub value: Option, + pub metaprotocol: Option, } #[derive(Debug, PartialEq, Serialize, Deserialize)] diff --git a/src/index.rs b/src/index.rs index 4cd24d3aec..302cbad4d7 100644 --- a/src/index.rs +++ b/src/index.rs @@ -2128,6 +2128,7 @@ impl Index { satpoint, timestamp: timestamp(entry.timestamp.into()).timestamp(), value: output.as_ref().map(|o| o.value.to_sat()), + metaprotocol: inscription.metaprotocol().map(|s| s.to_string()), }, output, inscription, diff --git a/tests/json_api.rs b/tests/json_api.rs index 2886291ff5..3089bb19cf 100644 --- a/tests/json_api.rs +++ b/tests/json_api.rs @@ -175,10 +175,67 @@ fn get_inscription() { sat: Some(Sat(50 * COIN_VALUE)), satpoint: SatPoint::from_str(&format!("{}:{}:{}", reveal, 0, 0)).unwrap(), timestamp: 2, + metaprotocol: None } ) } +#[test] +fn get_inscription_with_metaprotocol() { + let core = mockcore::spawn(); + let ord = TestServer::spawn_with_server_args(&core, &["--index-sats"], &[]); + + create_wallet(&core, &ord); + + core.mine_blocks(1); + + let output = CommandBuilder::new(format!( + "--chain {} wallet inscribe --fee-rate 1 --file foo.txt --metaprotocol foo", + core.network() + )) + .write("foo.txt", "FOO") + .core(&core) + .ord(&ord) + .run_and_deserialize_output::(); + + core.mine_blocks(1); + + let response = ord.json_request(format!("/inscription/{}", output.inscriptions[0].id)); + + assert_eq!(response.status(), StatusCode::OK); + + let mut inscription_json: api::Inscription = + serde_json::from_str(&response.text().unwrap()).unwrap(); + assert_regex_match!(inscription_json.address.unwrap(), r"bc1p.*"); + inscription_json.address = None; + + pretty_assert_eq!( + inscription_json, + api::Inscription { + address: None, + charms: vec![Charm::Coin, Charm::Uncommon], + child_count: 0, + 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: 140, + height: 2, + id: output.inscriptions[0].id, + number: 0, + next: None, + value: Some(10000), + parents: Vec::new(), + previous: None, + rune: None, + sat: Some(Sat(50 * COIN_VALUE)), + satpoint: SatPoint::from_str(&format!("{}:{}:{}", output.reveal, 0, 0)).unwrap(), + timestamp: 2, + metaprotocol: Some("foo".to_string()) + } + ); +} + #[test] fn get_inscriptions() { let core = mockcore::spawn();