Skip to content

Commit

Permalink
Add field metaprotocol to api::Inscription (#4047)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbehouse authored Nov 21, 2024
1 parent 6a9b3bd commit 4695b2b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub struct Inscription {
pub satpoint: SatPoint,
pub timestamp: i64,
pub value: Option<u64>,
pub metaprotocol: Option<String>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
Expand Down
1 change: 1 addition & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
57 changes: 57 additions & 0 deletions tests/json_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,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::<Batch>();

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();
Expand Down

0 comments on commit 4695b2b

Please sign in to comment.