Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a metaprotocol field to the api::Inscription struct to display in the server’s JSON output #4047

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading