Skip to content

Commit f7e4085

Browse files
authored
Return properties from inscription JSON API (#4425)
1 parent b5f3351 commit f7e4085

File tree

6 files changed

+38
-14
lines changed

6 files changed

+38
-14
lines changed

src/api.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,17 @@ pub struct Inscription {
108108
pub fee: u64,
109109
pub height: u32,
110110
pub id: InscriptionId,
111+
pub metaprotocol: Option<String>,
111112
pub next: Option<InscriptionId>,
112113
pub number: i32,
113114
pub parents: Vec<InscriptionId>,
114115
pub previous: Option<InscriptionId>,
116+
pub properties: Properties,
115117
pub rune: Option<SpacedRune>,
116118
pub sat: Option<ordinals::Sat>,
117119
pub satpoint: SatPoint,
118120
pub timestamp: i64,
119121
pub value: Option<u64>,
120-
pub metaprotocol: Option<String>,
121122
}
122123

123124
#[derive(Debug, PartialEq, Serialize, Deserialize)]

src/index.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,7 @@ impl Index {
22872287
number: entry.inscription_number,
22882288
parents,
22892289
previous,
2290+
properties: inscription.properties(),
22902291
rune,
22912292
sat: entry.sat,
22922293
satpoint,

src/properties.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use super::*;
33
mod raw;
44

55
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
6+
#[serde(deny_unknown_fields)]
67
pub struct Attributes {
78
pub title: Option<String>,
89
}
@@ -25,19 +26,18 @@ impl From<raw::Attributes> for Attributes {
2526
}
2627
}
2728

28-
#[serde_with::skip_serializing_none]
2929
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
3030
#[serde(deny_unknown_fields)]
3131
pub struct Item {
3232
pub id: InscriptionId,
33-
#[serde(flatten)]
3433
pub attributes: Attributes,
3534
}
3635

37-
#[derive(Debug, Default, PartialEq)]
36+
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
37+
#[serde(deny_unknown_fields)]
3838
pub struct Properties {
39-
pub(crate) gallery: Vec<Item>,
40-
pub(crate) attributes: Attributes,
39+
pub gallery: Vec<Item>,
40+
pub attributes: Attributes,
4141
}
4242

4343
impl Properties {

src/wallet/batch/entry.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ pub struct Entry {
1616
pub satpoint: Option<SatPoint>,
1717
}
1818

19+
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
20+
#[serde(deny_unknown_fields)]
21+
pub struct Item {
22+
pub id: InscriptionId,
23+
#[serde(flatten)]
24+
pub attributes: Attributes,
25+
}
26+
1927
impl Entry {
2028
pub(crate) fn metadata(&self) -> Result<Option<Vec<u8>>> {
2129
match &self.metadata {

src/wallet/batch/file.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,15 @@ impl File {
156156
entry.file.clone(),
157157
Some(pointer),
158158
Properties {
159-
gallery: entry.gallery.clone(),
159+
gallery: entry
160+
.gallery
161+
.clone()
162+
.into_iter()
163+
.map(|item| Item {
164+
id: item.id,
165+
attributes: item.attributes,
166+
})
167+
.collect(),
160168
attributes: entry.attributes.clone(),
161169
},
162170
self
@@ -468,15 +476,15 @@ inscriptions:
468476
batch::Entry {
469477
file: Some("gallery.png".into()),
470478
gallery: vec![
471-
Item {
479+
batch::entry::Item {
472480
id: "a4676e57277b70171d69dc6ad2781485b491fe0ff5870f6f6b01999e7180b29ei0"
473481
.parse()
474482
.unwrap(),
475483
attributes: Attributes {
476484
title: Some("Incredible".into()),
477485
},
478486
},
479-
Item {
487+
batch::entry::Item {
480488
id: "a4676e57277b70171d69dc6ad2781485b491fe0ff5870f6f6b01999e7180b29ei3"
481489
.parse()
482490
.unwrap(),

tests/json_api.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use {
22
super::*,
33
bitcoin::{BlockHash, ScriptBuf},
4-
ord::subcommand::wallet::send::Output,
5-
ord::{Envelope, Inscription},
4+
ord::{Attributes, Envelope, Inscription, Properties, subcommand::wallet::send::Output},
65
};
76

87
#[test]
@@ -180,6 +179,7 @@ fn get_inscription() {
180179
value: Some(10000),
181180
parents: Vec::new(),
182181
previous: None,
182+
properties: default(),
183183
rune: None,
184184
sat: Some(Sat(50 * COIN_VALUE)),
185185
satpoint: SatPoint::from_str(&format!("{}:{}:{}", reveal, 0, 0)).unwrap(),
@@ -190,7 +190,7 @@ fn get_inscription() {
190190
}
191191

192192
#[test]
193-
fn get_inscription_with_metaprotocol() {
193+
fn get_inscription_with_metaprotocol_and_properties() {
194194
let core = mockcore::spawn();
195195
let ord = TestServer::spawn_with_server_args(&core, &["--index-sats"], &[]);
196196

@@ -199,7 +199,7 @@ fn get_inscription_with_metaprotocol() {
199199
core.mine_blocks(1);
200200

201201
let output = CommandBuilder::new(format!(
202-
"--chain {} wallet inscribe --fee-rate 1 --file foo.txt --metaprotocol foo",
202+
"--chain {} wallet inscribe --fee-rate 1 --file foo.txt --metaprotocol foo --title bar",
203203
core.network()
204204
))
205205
.write("foo.txt", "FOO")
@@ -228,14 +228,20 @@ fn get_inscription_with_metaprotocol() {
228228
content_length: Some(3),
229229
content_type: Some("text/plain;charset=utf-8".to_string()),
230230
effective_content_type: Some("text/plain;charset=utf-8".to_string()),
231-
fee: 140,
231+
fee: 143,
232232
height: 2,
233233
id: output.inscriptions[0].id,
234234
number: 0,
235235
next: None,
236236
value: Some(10000),
237237
parents: Vec::new(),
238238
previous: None,
239+
properties: Properties {
240+
gallery: Vec::new(),
241+
attributes: Attributes {
242+
title: Some("bar".into()),
243+
},
244+
},
239245
rune: None,
240246
sat: Some(Sat(50 * COIN_VALUE)),
241247
satpoint: SatPoint::from_str(&format!("{}:{}:{}", output.reveal, 0, 0)).unwrap(),

0 commit comments

Comments
 (0)