From ea11900a56d73545eb9c4ebc3b1325a7e24f3292 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 23 Feb 2024 14:05:24 -0800 Subject: [PATCH 1/6] Modify --- src/json.rs | 150 +++++++++++++++++++++++++++++++++++ src/lib.rs | 3 +- src/subcommand/server.rs | 85 ++++++++++---------- src/templates.rs | 10 +-- src/templates/block.rs | 45 ----------- src/templates/children.rs | 7 -- src/templates/inscription.rs | 21 ----- src/templates/output.rs | 41 ---------- src/templates/sat.rs | 30 ------- src/wallet.rs | 12 +-- tests/json_api.rs | 26 +++--- tests/lib.rs | 7 +- tests/wallet/inscribe.rs | 12 +-- tests/wallet/send.rs | 4 +- 14 files changed, 229 insertions(+), 224 deletions(-) create mode 100644 src/json.rs diff --git a/src/json.rs b/src/json.rs new file mode 100644 index 0000000000..09a66e90c5 --- /dev/null +++ b/src/json.rs @@ -0,0 +1,150 @@ +use super::{ + target_as_block_hash, BlockHash, Chain, Deserialize, Height, InscriptionId, OutPoint, Pile, + Rarity, SatPoint, Serialize, SpacedRune, TxMerkleNode, TxOut, +}; + +// todo: sort + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Sat { + pub number: u64, + pub decimal: String, + pub degree: String, + pub name: String, + pub block: u32, + pub cycle: u32, + pub epoch: u32, + pub period: u32, + pub offset: u64, + pub rarity: Rarity, + pub percentile: String, + pub satpoint: Option, + pub timestamp: i64, + pub inscriptions: Vec, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Block { + pub hash: BlockHash, + pub target: BlockHash, + pub best_height: u32, + pub height: u32, + pub inscriptions: Vec, +} + +impl Block { + pub(crate) fn new( + block: bitcoin::Block, + height: Height, + best_height: Height, + inscriptions: Vec, + ) -> Self { + Self { + hash: block.header.block_hash(), + target: target_as_block_hash(block.header.target()), + height: height.0, + best_height: best_height.0, + inscriptions, + } + } +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Output { + pub address: Option, + pub indexed: bool, + pub inscriptions: Vec, + pub runes: Vec<(SpacedRune, Pile)>, + pub sat_ranges: Option>, + pub script_pubkey: String, + pub spent: bool, + pub transaction: String, + pub value: u64, +} + +impl Output { + pub fn new( + chain: Chain, + inscriptions: Vec, + outpoint: OutPoint, + output: TxOut, + indexed: bool, + runes: Vec<(SpacedRune, Pile)>, + sat_ranges: Option>, + spent: bool, + ) -> Self { + Self { + address: chain + .address_from_script(&output.script_pubkey) + .ok() + .map(|address| address.to_string()), + indexed, + inscriptions, + runes, + sat_ranges, + script_pubkey: output.script_pubkey.to_asm_string(), + spent, + transaction: outpoint.txid.to_string(), + value: output.value, + } + } +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct BlockInfo { + pub bits: u32, + pub chainwork: u128, + pub confirmations: i32, + pub difficulty: f64, + pub hash: BlockHash, + pub height: u32, + pub median_time: Option, + pub merkle_root: TxMerkleNode, + pub next_block: Option, + pub nonce: u32, + pub previous_block: Option, + pub target: BlockHash, + pub timestamp: u64, + pub transaction_count: u64, + pub version: u32, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Children { + pub ids: Vec, + pub more: bool, + pub page: usize, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] +pub struct Inscription { + pub address: Option, + pub charms: Vec, + pub children: Vec, + pub content_length: Option, + pub content_type: Option, + pub genesis_fee: u64, + pub genesis_height: u32, + pub inscription_id: InscriptionId, + pub inscription_number: i32, + pub next: Option, + pub output_value: Option, + pub parent: Option, + pub previous: Option, + pub rune: Option, + pub sat: Option, + pub satpoint: SatPoint, + pub timestamp: i64, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct SatInscriptions { + pub ids: Vec, + pub more: bool, + pub page: u64, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct SatInscription { + pub id: Option, +} diff --git a/src/lib.rs b/src/lib.rs index 4b09ba1832..ce243d3304 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,7 +71,7 @@ use { time::{Duration, Instant, SystemTime}, }, sysinfo::System, - templates::{InscriptionJson, OutputJson, RuneJson, StatusJson}, + templates::{RuneJson, StatusJson}, tokio::{runtime::Runtime, task}, }; @@ -111,6 +111,7 @@ mod decimal; mod fee_rate; pub mod index; mod inscriptions; +pub mod json; mod object; pub mod options; pub mod outgoing; diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 0461c37bae..1414389516 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -8,14 +8,13 @@ use { crate::{ server_config::ServerConfig, templates::{ - BlockHtml, BlockInfoJson, BlockJson, BlocksHtml, BlocksJson, ChildrenHtml, ChildrenJson, - ClockSvg, CollectionsHtml, HomeHtml, InputHtml, InscriptionHtml, InscriptionJson, - InscriptionRecursiveJson, InscriptionsBlockHtml, InscriptionsHtml, InscriptionsJson, - OutputHtml, OutputJson, PageContent, PageHtml, PreviewAudioHtml, PreviewCodeHtml, - PreviewFontHtml, PreviewImageHtml, PreviewMarkdownHtml, PreviewModelHtml, PreviewPdfHtml, - PreviewTextHtml, PreviewUnknownHtml, PreviewVideoHtml, RangeHtml, RareTxt, RuneBalancesHtml, - RuneHtml, RuneJson, RunesHtml, RunesJson, SatHtml, SatInscriptionJson, SatInscriptionsJson, - SatJson, TransactionHtml, TransactionJson, + BlockHtml, BlocksHtml, BlocksJson, ChildrenHtml, ClockSvg, CollectionsHtml, HomeHtml, + InputHtml, InscriptionHtml, InscriptionRecursiveJson, InscriptionsBlockHtml, + InscriptionsHtml, InscriptionsJson, OutputHtml, PageContent, PageHtml, PreviewAudioHtml, + PreviewCodeHtml, PreviewFontHtml, PreviewImageHtml, PreviewMarkdownHtml, PreviewModelHtml, + PreviewPdfHtml, PreviewTextHtml, PreviewUnknownHtml, PreviewVideoHtml, RangeHtml, RareTxt, + RuneBalancesHtml, RuneHtml, RuneJson, RunesHtml, RunesJson, SatHtml, TransactionHtml, + TransactionJson, }, }, axum::{ @@ -539,7 +538,7 @@ impl Server { }); let blocktime = index.block_time(sat.height())?; Ok(if accept_json { - Json(SatJson { + Json(json::Sat { number: sat.0, decimal: sat.decimal().to_string(), degree: sat.degree().to_string(), @@ -618,7 +617,7 @@ impl Server { let spent = index.is_output_spent(outpoint)?; Ok(if accept_json { - Json(OutputJson::new( + Json(json::Output::new( server_config.chain, inscriptions, outpoint, @@ -803,7 +802,7 @@ impl Server { Ok(if accept_json { let inscriptions = index.get_inscriptions_in_block(height)?; - Json(BlockJson::new( + Json(json::Block::new( block, Height(height), Self::index_height(&index)?, @@ -1143,7 +1142,7 @@ impl Server { async fn block_info( Extension(index): Extension>, Path(DeserializeFromStr(query)): Path>, - ) -> ServerResult> { + ) -> ServerResult> { task::block_in_place(|| { let hash = match query { BlockQuery::Hash(hash) => hash, @@ -1160,7 +1159,7 @@ impl Server { .block_header(hash)? .ok_or_not_found(|| format!("block {hash}"))?; - Ok(Json(BlockInfoJson { + Ok(Json(json::BlockInfo { bits: header.bits.to_consensus(), chainwork: chainwork(&info.chainwork), confirmations: info.confirmations, @@ -1443,7 +1442,7 @@ impl Server { .ok_or_not_found(|| format!("inscription {query}"))?; Ok(if accept_json { - Json(InscriptionJson { + Json(json::Inscription { inscription_id: info.entry.id, charms: Charm::ALL .iter() @@ -1598,7 +1597,7 @@ impl Server { let (ids, more) = index.get_children_by_sequence_number_paginated(parent_sequence_number, 100, page)?; - Ok(Json(ChildrenJson { ids, more, page }).into_response()) + Ok(Json(json::Children { ids, more, page }).into_response()) }) } @@ -1712,14 +1711,14 @@ impl Server { async fn sat_inscriptions( Extension(index): Extension>, Path(sat): Path, - ) -> ServerResult> { + ) -> ServerResult> { Self::sat_inscriptions_paginated(Extension(index), Path((sat, 0))).await } async fn sat_inscriptions_paginated( Extension(index): Extension>, Path((sat, page)): Path<(u64, u64)>, - ) -> ServerResult> { + ) -> ServerResult> { task::block_in_place(|| { if !index.has_sat_index() { return Err(ServerError::NotFound( @@ -1729,14 +1728,14 @@ impl Server { let (ids, more) = index.get_inscription_ids_by_sat_paginated(Sat(sat), 100, page)?; - Ok(Json(SatInscriptionsJson { ids, more, page })) + Ok(Json(json::SatInscriptions { ids, more, page })) }) } async fn sat_inscription_at_index( Extension(index): Extension>, Path((DeserializeFromStr(sat), inscription_index)): Path<(DeserializeFromStr, isize)>, - ) -> ServerResult> { + ) -> ServerResult> { task::block_in_place(|| { if !index.has_sat_index() { return Err(ServerError::NotFound( @@ -1746,7 +1745,7 @@ impl Server { let id = index.get_inscription_id_by_sat_indexed(sat, inscription_index)?; - Ok(Json(SatInscriptionJson { id })) + Ok(Json(json::SatInscription { id })) }) } @@ -2764,8 +2763,8 @@ mod tests { ); assert_eq!( - server.get_json::(format!("/output/{output}")), - OutputJson { + server.get_json::(format!("/output/{output}")), + json::Output { value: 5000000000, script_pubkey: String::new(), address: None, @@ -4409,14 +4408,14 @@ next assert_eq!( server - .get_json::(format!("/inscription/{inscription_id}")) + .get_json::(format!("/inscription/{inscription_id}")) .parent, Some(parent_inscription_id), ); assert_eq!( server - .get_json::(format!("/inscription/{parent_inscription_id}")) + .get_json::(format!("/inscription/{parent_inscription_id}")) .children, [inscription_id], ); @@ -5087,8 +5086,8 @@ next let server = TestServer::new_with_regtest_with_index_sats(); assert_eq!( - server.get_json::("/r/sat/5000000000"), - SatInscriptionsJson { + server.get_json::("/r/sat/5000000000"), + json::SatInscriptions { ids: vec![], page: 0, more: false @@ -5096,8 +5095,8 @@ next ); assert_eq!( - server.get_json::("/r/sat/5000000000/at/0"), - SatInscriptionJson { id: None } + server.get_json::("/r/sat/5000000000/at/0"), + json::SatInscription { id: None } ); server.mine_blocks(1); @@ -5123,10 +5122,10 @@ next ids.push(InscriptionId { txid, index: 0 }); } - let paginated_response = server.get_json::("/r/sat/5000000000"); + let paginated_response = server.get_json::("/r/sat/5000000000"); let equivalent_paginated_response = - server.get_json::("/r/sat/5000000000/0"); + server.get_json::("/r/sat/5000000000/0"); assert_eq!(paginated_response.ids.len(), 100); assert!(paginated_response.more); @@ -5139,7 +5138,7 @@ next assert_eq!(paginated_response.more, equivalent_paginated_response.more); assert_eq!(paginated_response.page, equivalent_paginated_response.page); - let paginated_response = server.get_json::("/r/sat/5000000000/1"); + let paginated_response = server.get_json::("/r/sat/5000000000/1"); assert_eq!(paginated_response.ids.len(), 11); assert!(!paginated_response.more); @@ -5147,34 +5146,34 @@ next assert_eq!( server - .get_json::("/r/sat/5000000000/at/0") + .get_json::("/r/sat/5000000000/at/0") .id, Some(ids[0]) ); assert_eq!( server - .get_json::("/r/sat/5000000000/at/-111") + .get_json::("/r/sat/5000000000/at/-111") .id, Some(ids[0]) ); assert_eq!( server - .get_json::("/r/sat/5000000000/at/110") + .get_json::("/r/sat/5000000000/at/110") .id, Some(ids[110]) ); assert_eq!( server - .get_json::("/r/sat/5000000000/at/-1") + .get_json::("/r/sat/5000000000/at/-1") .id, Some(ids[110]) ); assert!(server - .get_json::("/r/sat/5000000000/at/111") + .get_json::("/r/sat/5000000000/at/111") .id .is_none()); } @@ -5203,7 +5202,7 @@ next server.mine_blocks(1); let children_json = - server.get_json::(format!("/r/children/{parent_inscription_id}")); + server.get_json::(format!("/r/children/{parent_inscription_id}")); assert_eq!(children_json.ids.len(), 0); let mut builder = script::Builder::new(); @@ -5233,7 +5232,7 @@ next let hundred_eleventh_child_inscription_id = InscriptionId { txid, index: 110 }; let children_json = - server.get_json::(format!("/r/children/{parent_inscription_id}")); + server.get_json::(format!("/r/children/{parent_inscription_id}")); assert_eq!(children_json.ids.len(), 100); assert_eq!(children_json.ids[0], first_child_inscription_id); @@ -5242,7 +5241,7 @@ next assert_eq!(children_json.page, 0); let children_json = - server.get_json::(format!("/r/children/{parent_inscription_id}/1")); + server.get_json::(format!("/r/children/{parent_inscription_id}/1")); assert_eq!(children_json.ids.len(), 11); assert_eq!(children_json.ids[0], hundred_first_child_inscription_id); @@ -5372,8 +5371,8 @@ next let server = TestServer::new(); pretty_assert_eq!( - server.get_json::("/r/blockinfo/0"), - BlockInfoJson { + server.get_json::("/r/blockinfo/0"), + json::BlockInfo { bits: 486604799, chainwork: 0, confirmations: 0, @@ -5399,8 +5398,8 @@ next server.mine_blocks(1); pretty_assert_eq!( - server.get_json::("/r/blockinfo/1"), - BlockInfoJson { + server.get_json::("/r/blockinfo/1"), + json::BlockInfo { bits: 0, chainwork: 0, confirmations: 0, diff --git a/src/templates.rs b/src/templates.rs index 2dedc4bb12..e76cc241ea 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -1,19 +1,19 @@ use {super::*, boilerplate::Boilerplate}; pub(crate) use { - block::{BlockHtml, BlockInfoJson, BlockJson}, + block::BlockHtml, blocks::{BlocksHtml, BlocksJson}, - children::{ChildrenHtml, ChildrenJson}, + children::ChildrenHtml, clock::ClockSvg, collections::CollectionsHtml, home::HomeHtml, iframe::Iframe, input::InputHtml, - inscription::{InscriptionHtml, InscriptionJson, InscriptionRecursiveJson}, + inscription::{InscriptionHtml, InscriptionRecursiveJson}, inscriptions::{InscriptionsHtml, InscriptionsJson}, inscriptions_block::InscriptionsBlockHtml, metadata::MetadataHtml, - output::{OutputHtml, OutputJson}, + output::OutputHtml, preview::{ PreviewAudioHtml, PreviewCodeHtml, PreviewFontHtml, PreviewImageHtml, PreviewMarkdownHtml, PreviewModelHtml, PreviewPdfHtml, PreviewTextHtml, PreviewUnknownHtml, PreviewVideoHtml, @@ -23,7 +23,7 @@ pub(crate) use { rune::{RuneHtml, RuneJson}, rune_balances::RuneBalancesHtml, runes::{RunesHtml, RunesJson}, - sat::{SatHtml, SatInscriptionJson, SatInscriptionsJson, SatJson}, + sat::SatHtml, server_config::ServerConfig, status::{StatusHtml, StatusJson}, transaction::{TransactionHtml, TransactionJson}, diff --git a/src/templates/block.rs b/src/templates/block.rs index fb4bfba846..f5d1294e74 100644 --- a/src/templates/block.rs +++ b/src/templates/block.rs @@ -31,51 +31,6 @@ impl BlockHtml { } } -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct BlockJson { - pub hash: BlockHash, - pub target: BlockHash, - pub best_height: u32, - pub height: u32, - pub inscriptions: Vec, -} - -impl BlockJson { - pub(crate) fn new( - block: Block, - height: Height, - best_height: Height, - inscriptions: Vec, - ) -> Self { - Self { - hash: block.header.block_hash(), - target: target_as_block_hash(block.header.target()), - height: height.0, - best_height: best_height.0, - inscriptions, - } - } -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct BlockInfoJson { - pub bits: u32, - pub chainwork: u128, - pub confirmations: i32, - pub difficulty: f64, - pub hash: BlockHash, - pub height: u32, - pub median_time: Option, - pub merkle_root: TxMerkleNode, - pub next_block: Option, - pub nonce: u32, - pub previous_block: Option, - pub target: BlockHash, - pub timestamp: u64, - pub transaction_count: u64, - pub version: u32, -} - impl PageContent for BlockHtml { fn title(&self) -> String { format!("Block {}", self.height) diff --git a/src/templates/children.rs b/src/templates/children.rs index d495abdcea..ac3621d57a 100644 --- a/src/templates/children.rs +++ b/src/templates/children.rs @@ -9,13 +9,6 @@ pub(crate) struct ChildrenHtml { pub(crate) next_page: Option, } -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct ChildrenJson { - pub ids: Vec, - pub more: bool, - pub page: usize, -} - impl PageContent for ChildrenHtml { fn title(&self) -> String { format!("Inscription {} Children", self.parent_number) diff --git a/src/templates/inscription.rs b/src/templates/inscription.rs index b23d5dd890..45b662ee8f 100644 --- a/src/templates/inscription.rs +++ b/src/templates/inscription.rs @@ -35,27 +35,6 @@ pub struct InscriptionRecursiveJson { pub value: Option, } -#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] -pub struct InscriptionJson { - pub address: Option, - pub charms: Vec, - pub children: Vec, - pub content_length: Option, - pub content_type: Option, - pub genesis_fee: u64, - pub genesis_height: u32, - pub inscription_id: InscriptionId, - pub inscription_number: i32, - pub next: Option, - pub output_value: Option, - pub parent: Option, - pub previous: Option, - pub rune: Option, - pub sat: Option, - pub satpoint: SatPoint, - pub timestamp: i64, -} - impl PageContent for InscriptionHtml { fn title(&self) -> String { format!("Inscription {}", self.inscription_number) diff --git a/src/templates/output.rs b/src/templates/output.rs index 58fa66cfac..a929d4b83d 100644 --- a/src/templates/output.rs +++ b/src/templates/output.rs @@ -11,47 +11,6 @@ pub(crate) struct OutputHtml { pub(crate) spent: bool, } -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct OutputJson { - pub address: Option, - pub indexed: bool, - pub inscriptions: Vec, - pub runes: Vec<(SpacedRune, Pile)>, - pub sat_ranges: Option>, - pub script_pubkey: String, - pub spent: bool, - pub transaction: String, - pub value: u64, -} - -impl OutputJson { - pub fn new( - chain: Chain, - inscriptions: Vec, - outpoint: OutPoint, - output: TxOut, - indexed: bool, - runes: Vec<(SpacedRune, Pile)>, - sat_ranges: Option>, - spent: bool, - ) -> Self { - Self { - address: chain - .address_from_script(&output.script_pubkey) - .ok() - .map(|address| address.to_string()), - indexed, - inscriptions, - runes, - sat_ranges, - script_pubkey: output.script_pubkey.to_asm_string(), - spent, - transaction: outpoint.txid.to_string(), - value: output.value, - } - } -} - impl PageContent for OutputHtml { fn title(&self) -> String { format!("Output {}", self.outpoint) diff --git a/src/templates/sat.rs b/src/templates/sat.rs index 6567e9cbfd..fd1c5bab7d 100644 --- a/src/templates/sat.rs +++ b/src/templates/sat.rs @@ -8,36 +8,6 @@ pub(crate) struct SatHtml { pub(crate) inscriptions: Vec, } -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct SatJson { - pub number: u64, - pub decimal: String, - pub degree: String, - pub name: String, - pub block: u32, - pub cycle: u32, - pub epoch: u32, - pub period: u32, - pub offset: u64, - pub rarity: Rarity, - pub percentile: String, - pub satpoint: Option, - pub timestamp: i64, - pub inscriptions: Vec, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct SatInscriptionsJson { - pub ids: Vec, - pub more: bool, - pub page: u64, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct SatInscriptionJson { - pub id: Option, -} - impl PageContent for SatHtml { fn title(&self) -> String { format!("Sat {}", self.sat) diff --git a/src/wallet.rs b/src/wallet.rs index f4696f2e12..efefe16e34 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -47,9 +47,9 @@ pub(crate) struct Wallet { has_rune_index: bool, utxos: BTreeMap, locked_utxos: BTreeMap, - output_info: BTreeMap, + output_info: BTreeMap, inscriptions: BTreeMap>, - inscription_info: BTreeMap, + inscription_info: BTreeMap, } impl Wallet { @@ -181,14 +181,14 @@ impl Wallet { }) } - async fn get_output(ord_client: &OrdClient, output: OutPoint) -> Result { + async fn get_output(ord_client: &OrdClient, output: OutPoint) -> Result { let response = ord_client.get(&format!("/output/{output}")).await?; if !response.status().is_success() { bail!("wallet failed get output: {}", response.text().await?); } - let output_json: OutputJson = serde_json::from_str(&response.text().await?)?; + let output_json: json::Output = serde_json::from_str(&response.text().await?)?; if !output_json.indexed { bail!("output in wallet but not in ord server: {output}"); @@ -245,7 +245,7 @@ impl Wallet { async fn get_inscription_info( ord_client: &OrdClient, inscription_id: InscriptionId, - ) -> Result { + ) -> Result { let response = ord_client .get(&format!("/inscription/{inscription_id}")) .await?; @@ -329,7 +329,7 @@ impl Wallet { &self.inscriptions } - pub(crate) fn inscription_info(&self) -> BTreeMap { + pub(crate) fn inscription_info(&self) -> BTreeMap { self.inscription_info.clone() } diff --git a/tests/json_api.rs b/tests/json_api.rs index d95f624932..f9af3b60da 100644 --- a/tests/json_api.rs +++ b/tests/json_api.rs @@ -9,14 +9,14 @@ fn get_sat_without_sat_index() { assert_eq!(response.status(), StatusCode::OK); - let mut sat_json: SatJson = serde_json::from_str(&response.text().unwrap()).unwrap(); + let mut sat_json: json::Sat = serde_json::from_str(&response.text().unwrap()).unwrap(); // this is a hack to ignore the timestamp, since it changes for every request sat_json.timestamp = 0; pretty_assert_eq!( sat_json, - SatJson { + json::Sat { number: 2099999997689999, decimal: "6929999.0".into(), degree: "5°209999′1007″0‴".into(), @@ -50,11 +50,11 @@ fn get_sat_with_inscription_and_sat_index() { assert_eq!(response.status(), StatusCode::OK); - let sat_json: SatJson = serde_json::from_str(&response.text().unwrap()).unwrap(); + let sat_json: json::Sat = serde_json::from_str(&response.text().unwrap()).unwrap(); pretty_assert_eq!( sat_json, - SatJson { + json::Sat { number: 50 * COIN_VALUE, decimal: "1.0".into(), degree: "0°1′1″0‴".into(), @@ -106,11 +106,11 @@ fn get_sat_with_inscription_on_common_sat_and_more_inscriptions() { assert_eq!(response.status(), StatusCode::OK); - let sat_json: SatJson = serde_json::from_str(&response.text().unwrap()).unwrap(); + let sat_json: json::Sat = serde_json::from_str(&response.text().unwrap()).unwrap(); pretty_assert_eq!( sat_json, - SatJson { + json::Sat { number: 3 * 50 * COIN_VALUE + 1, decimal: "3.1".into(), degree: "0°3′3″1‴".into(), @@ -144,14 +144,14 @@ fn get_inscription() { assert_eq!(response.status(), StatusCode::OK); - let mut inscription_json: InscriptionJson = + let mut inscription_json: json::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, - InscriptionJson { + json::Inscription { address: None, charms: vec!["coin".into(), "uncommon".into()], children: Vec::new(), @@ -318,7 +318,7 @@ fn get_output() { assert_eq!(response.status(), StatusCode::OK); assert!( - !serde_json::from_str::(&response.text().unwrap()) + !serde_json::from_str::(&response.text().unwrap()) .unwrap() .indexed ); @@ -328,11 +328,11 @@ fn get_output() { let response = server.json_request(format!("/output/{}:0", txid)); assert_eq!(response.status(), StatusCode::OK); - let output_json: OutputJson = serde_json::from_str(&response.text().unwrap()).unwrap(); + let output_json: json::Output = serde_json::from_str(&response.text().unwrap()).unwrap(); pretty_assert_eq!( output_json, - OutputJson { + json::Output { address: None, inscriptions: vec![ InscriptionId { txid, index: 0 }, @@ -376,11 +376,11 @@ fn get_block() { assert_eq!(response.status(), StatusCode::OK); - let block_json: BlockJson = serde_json::from_str(&response.text().unwrap()).unwrap(); + let block_json: json::Block = serde_json::from_str(&response.text().unwrap()).unwrap(); assert_eq!( block_json, - BlockJson { + json::Block { hash: "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" .parse::() .unwrap(), diff --git a/tests/lib.rs b/tests/lib.rs index f1f3c924b3..a919309b8c 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -12,13 +12,12 @@ use { executable_path::executable_path, ord::{ chain::Chain, + json, outgoing::Outgoing, subcommand::runes::RuneInfo, templates::{ - block::BlockJson, blocks::BlocksJson, inscription::InscriptionJson, - inscription::InscriptionRecursiveJson, inscriptions::InscriptionsJson, output::OutputJson, - rune::RuneJson, runes::RunesJson, sat::SatJson, status::StatusJson, - transaction::TransactionJson, + blocks::BlocksJson, inscription::InscriptionRecursiveJson, inscriptions::InscriptionsJson, + rune::RuneJson, runes::RunesJson, status::StatusJson, transaction::TransactionJson, }, Edict, InscriptionId, Rune, RuneEntry, RuneId, Runestone, }, diff --git a/tests/wallet/inscribe.rs b/tests/wallet/inscribe.rs index e6e613e3d2..29fb6a4003 100644 --- a/tests/wallet/inscribe.rs +++ b/tests/wallet/inscribe.rs @@ -2207,7 +2207,7 @@ fn batch_inscribe_with_satpoints_with_parent() { offset: 0, }; - let sat_1 = serde_json::from_str::( + let sat_1 = serde_json::from_str::( &ord_rpc_server .json_request(format!("/output/{}", satpoint_1.outpoint)) .text() @@ -2218,7 +2218,7 @@ fn batch_inscribe_with_satpoints_with_parent() { .unwrap()[0] .0; - let sat_2 = serde_json::from_str::( + let sat_2 = serde_json::from_str::( &ord_rpc_server .json_request(format!("/output/{}", satpoint_2.outpoint)) .text() @@ -2229,7 +2229,7 @@ fn batch_inscribe_with_satpoints_with_parent() { .unwrap()[0] .0; - let sat_3 = serde_json::from_str::( + let sat_3 = serde_json::from_str::( &ord_rpc_server .json_request(format!("/output/{}", satpoint_3.outpoint)) .text() @@ -2389,7 +2389,7 @@ fn batch_inscribe_with_satpoints_with_different_sizes() { offset: 0, }; - let output_1 = serde_json::from_str::( + let output_1 = serde_json::from_str::( &ord_rpc_server .json_request(format!("/output/{}", satpoint_1.outpoint)) .text() @@ -2398,7 +2398,7 @@ fn batch_inscribe_with_satpoints_with_different_sizes() { .unwrap(); assert_eq!(output_1.value, 25 * COIN_VALUE); - let output_2 = serde_json::from_str::( + let output_2 = serde_json::from_str::( &ord_rpc_server .json_request(format!("/output/{}", satpoint_2.outpoint)) .text() @@ -2407,7 +2407,7 @@ fn batch_inscribe_with_satpoints_with_different_sizes() { .unwrap(); assert_eq!(output_2.value, COIN_VALUE); - let output_3 = serde_json::from_str::( + let output_3 = serde_json::from_str::( &ord_rpc_server .json_request(format!("/output/{}", satpoint_3.outpoint)) .text() diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index 7308431897..546d63f05e 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -280,11 +280,11 @@ fn splitting_merged_inscriptions_is_possible() { let response = ord_rpc_server.json_request(format!("/output/{}:0", reveal_txid)); assert_eq!(response.status(), StatusCode::OK); - let output_json: OutputJson = serde_json::from_str(&response.text().unwrap()).unwrap(); + let output_json: json::Output = serde_json::from_str(&response.text().unwrap()).unwrap(); pretty_assert_eq!( output_json, - OutputJson { + json::Output { address: None, inscriptions: vec![ InscriptionId { From b3f27941de206b2f0776b3f936bd08465b5fb781 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 23 Feb 2024 14:07:19 -0800 Subject: [PATCH 2/6] Tweak --- src/json.rs | 7 +++++++ src/subcommand/server.rs | 13 ++++++------- src/templates.rs | 2 +- src/templates/inscriptions.rs | 7 ------- tests/json_api.rs | 6 +++--- tests/lib.rs | 4 ++-- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/json.rs b/src/json.rs index 09a66e90c5..690444e978 100644 --- a/src/json.rs +++ b/src/json.rs @@ -148,3 +148,10 @@ pub struct SatInscriptions { pub struct SatInscription { pub id: Option, } + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Inscriptions { + pub inscriptions: Vec, + pub more: bool, + pub page_index: u32, +} diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 1414389516..1a32097c92 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -10,11 +10,10 @@ use { templates::{ BlockHtml, BlocksHtml, BlocksJson, ChildrenHtml, ClockSvg, CollectionsHtml, HomeHtml, InputHtml, InscriptionHtml, InscriptionRecursiveJson, InscriptionsBlockHtml, - InscriptionsHtml, InscriptionsJson, OutputHtml, PageContent, PageHtml, PreviewAudioHtml, - PreviewCodeHtml, PreviewFontHtml, PreviewImageHtml, PreviewMarkdownHtml, PreviewModelHtml, - PreviewPdfHtml, PreviewTextHtml, PreviewUnknownHtml, PreviewVideoHtml, RangeHtml, RareTxt, - RuneBalancesHtml, RuneHtml, RuneJson, RunesHtml, RunesJson, SatHtml, TransactionHtml, - TransactionJson, + InscriptionsHtml, OutputHtml, PageContent, PageHtml, PreviewAudioHtml, PreviewCodeHtml, + PreviewFontHtml, PreviewImageHtml, PreviewMarkdownHtml, PreviewModelHtml, PreviewPdfHtml, + PreviewTextHtml, PreviewUnknownHtml, PreviewVideoHtml, RangeHtml, RareTxt, RuneBalancesHtml, + RuneHtml, RuneJson, RunesHtml, RunesJson, SatHtml, TransactionHtml, TransactionJson, }, }, axum::{ @@ -1629,7 +1628,7 @@ impl Server { let next = more.then_some(page_index + 1); Ok(if accept_json { - Json(InscriptionsJson { + Json(json::Inscriptions { inscriptions, page_index, more, @@ -1688,7 +1687,7 @@ impl Server { } Ok(if accept_json { - Json(InscriptionsJson { + Json(json::Inscriptions { inscriptions, page_index, more, diff --git a/src/templates.rs b/src/templates.rs index e76cc241ea..e00343126b 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -10,7 +10,7 @@ pub(crate) use { iframe::Iframe, input::InputHtml, inscription::{InscriptionHtml, InscriptionRecursiveJson}, - inscriptions::{InscriptionsHtml, InscriptionsJson}, + inscriptions::InscriptionsHtml, inscriptions_block::InscriptionsBlockHtml, metadata::MetadataHtml, output::OutputHtml, diff --git a/src/templates/inscriptions.rs b/src/templates/inscriptions.rs index 5d0d60065a..bed238b916 100644 --- a/src/templates/inscriptions.rs +++ b/src/templates/inscriptions.rs @@ -7,13 +7,6 @@ pub(crate) struct InscriptionsHtml { pub(crate) next: Option, } -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct InscriptionsJson { - pub inscriptions: Vec, - pub more: bool, - pub page_index: u32, -} - impl PageContent for InscriptionsHtml { fn title(&self) -> String { "Inscriptions".into() diff --git a/tests/json_api.rs b/tests/json_api.rs index f9af3b60da..5f35ef93a6 100644 --- a/tests/json_api.rs +++ b/tests/json_api.rs @@ -210,7 +210,7 @@ fn get_inscriptions() { let response = ord_rpc_server.json_request("/inscriptions"); assert_eq!(response.status(), StatusCode::OK); - let inscriptions_json: InscriptionsJson = + let inscriptions_json: json::Inscriptions = serde_json::from_str(&response.text().unwrap()).unwrap(); assert_eq!(inscriptions_json.inscriptions.len(), 100); @@ -219,7 +219,7 @@ fn get_inscriptions() { let response = ord_rpc_server.json_request("/inscriptions/1"); assert_eq!(response.status(), StatusCode::OK); - let inscriptions_json: InscriptionsJson = + let inscriptions_json: json::Inscriptions = serde_json::from_str(&response.text().unwrap()).unwrap(); assert_eq!(inscriptions_json.inscriptions.len(), 50); @@ -272,7 +272,7 @@ fn get_inscriptions_in_block() { let response = ord_rpc_server.json_request(format!("/inscriptions/block/{}", 11)); assert_eq!(response.status(), StatusCode::OK); - let inscriptions_json: InscriptionsJson = + let inscriptions_json: json::Inscriptions = serde_json::from_str(&response.text().unwrap()).unwrap(); pretty_assert_eq!( diff --git a/tests/lib.rs b/tests/lib.rs index a919309b8c..fd14c4947b 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -16,8 +16,8 @@ use { outgoing::Outgoing, subcommand::runes::RuneInfo, templates::{ - blocks::BlocksJson, inscription::InscriptionRecursiveJson, inscriptions::InscriptionsJson, - rune::RuneJson, runes::RunesJson, status::StatusJson, transaction::TransactionJson, + blocks::BlocksJson, inscription::InscriptionRecursiveJson, rune::RuneJson, runes::RunesJson, + status::StatusJson, transaction::TransactionJson, }, Edict, InscriptionId, Rune, RuneEntry, RuneId, Runestone, }, From cbb2343f0ff4d66a350969769f990ba9e3cc3873 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 23 Feb 2024 14:08:44 -0800 Subject: [PATCH 3/6] Enhance --- src/json.rs | 15 +++++++++++++++ src/subcommand/server.rs | 12 ++++++------ src/templates.rs | 2 +- src/templates/inscription.rs | 15 --------------- tests/lib.rs | 4 ++-- tests/server.rs | 4 ++-- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/json.rs b/src/json.rs index 690444e978..4d7e85b2cb 100644 --- a/src/json.rs +++ b/src/json.rs @@ -155,3 +155,18 @@ pub struct Inscriptions { pub more: bool, pub page_index: u32, } + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct InscriptionRecursive { + pub charms: Vec, + pub content_type: Option, + pub content_length: Option, + pub fee: u64, + pub height: u32, + pub number: i32, + pub output: OutPoint, + pub sat: Option, + pub satpoint: SatPoint, + pub timestamp: i64, + pub value: Option, +} diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 1a32097c92..0c1f8fe94f 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -9,11 +9,11 @@ use { server_config::ServerConfig, templates::{ BlockHtml, BlocksHtml, BlocksJson, ChildrenHtml, ClockSvg, CollectionsHtml, HomeHtml, - InputHtml, InscriptionHtml, InscriptionRecursiveJson, InscriptionsBlockHtml, - InscriptionsHtml, OutputHtml, PageContent, PageHtml, PreviewAudioHtml, PreviewCodeHtml, - PreviewFontHtml, PreviewImageHtml, PreviewMarkdownHtml, PreviewModelHtml, PreviewPdfHtml, - PreviewTextHtml, PreviewUnknownHtml, PreviewVideoHtml, RangeHtml, RareTxt, RuneBalancesHtml, - RuneHtml, RuneJson, RunesHtml, RunesJson, SatHtml, TransactionHtml, TransactionJson, + InputHtml, InscriptionHtml, InscriptionsBlockHtml, InscriptionsHtml, OutputHtml, PageContent, + PageHtml, PreviewAudioHtml, PreviewCodeHtml, PreviewFontHtml, PreviewImageHtml, + PreviewMarkdownHtml, PreviewModelHtml, PreviewPdfHtml, PreviewTextHtml, PreviewUnknownHtml, + PreviewVideoHtml, RangeHtml, RareTxt, RuneBalancesHtml, RuneHtml, RuneJson, RunesHtml, + RunesJson, SatHtml, TransactionHtml, TransactionJson, }, }, axum::{ @@ -912,7 +912,7 @@ impl Server { }; Ok( - Json(InscriptionRecursiveJson { + Json(json::InscriptionRecursive { charms: Charm::ALL .iter() .filter(|charm| charm.is_set(entry.charms)) diff --git a/src/templates.rs b/src/templates.rs index e00343126b..27a6efe830 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -9,7 +9,7 @@ pub(crate) use { home::HomeHtml, iframe::Iframe, input::InputHtml, - inscription::{InscriptionHtml, InscriptionRecursiveJson}, + inscription::InscriptionHtml, inscriptions::InscriptionsHtml, inscriptions_block::InscriptionsBlockHtml, metadata::MetadataHtml, diff --git a/src/templates/inscription.rs b/src/templates/inscription.rs index 45b662ee8f..229ea90472 100644 --- a/src/templates/inscription.rs +++ b/src/templates/inscription.rs @@ -20,21 +20,6 @@ pub(crate) struct InscriptionHtml { pub(crate) charms: u16, } -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct InscriptionRecursiveJson { - pub charms: Vec, - pub content_type: Option, - pub content_length: Option, - pub fee: u64, - pub height: u32, - pub number: i32, - pub output: OutPoint, - pub sat: Option, - pub satpoint: SatPoint, - pub timestamp: i64, - pub value: Option, -} - impl PageContent for InscriptionHtml { fn title(&self) -> String { format!("Inscription {}", self.inscription_number) diff --git a/tests/lib.rs b/tests/lib.rs index fd14c4947b..b91de85feb 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -16,8 +16,8 @@ use { outgoing::Outgoing, subcommand::runes::RuneInfo, templates::{ - blocks::BlocksJson, inscription::InscriptionRecursiveJson, rune::RuneJson, runes::RunesJson, - status::StatusJson, transaction::TransactionJson, + blocks::BlocksJson, rune::RuneJson, runes::RunesJson, status::StatusJson, + transaction::TransactionJson, }, Edict, InscriptionId, Rune, RuneEntry, RuneId, Runestone, }, diff --git a/tests/server.rs b/tests/server.rs index d1b1034f05..4f519d1e2b 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -308,12 +308,12 @@ fn recursive_inscription_endpoint() { "application/json" ); - let inscription_recursive_json: InscriptionRecursiveJson = + let inscription_recursive_json: json::InscriptionRecursive = serde_json::from_str(&response.text().unwrap()).unwrap(); pretty_assert_eq!( inscription_recursive_json, - InscriptionRecursiveJson { + json::InscriptionRecursive { charms: vec!["coin".into(), "uncommon".into()], content_type: Some("text/plain;charset=utf-8".to_string()), content_length: Some(3), From 6e2a3e40560e0303e4ec0f937ff020524a9d4eea Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 23 Feb 2024 14:09:31 -0800 Subject: [PATCH 4/6] Tweak --- src/{json.rs => api.rs} | 0 src/lib.rs | 2 +- src/subcommand/server.rs | 76 ++++++++++++++++++++-------------------- src/wallet.rs | 12 +++---- tests/json_api.rs | 32 ++++++++--------- tests/lib.rs | 2 +- tests/server.rs | 4 +-- tests/wallet/inscribe.rs | 12 +++---- tests/wallet/send.rs | 4 +-- 9 files changed, 72 insertions(+), 72 deletions(-) rename src/{json.rs => api.rs} (100%) diff --git a/src/json.rs b/src/api.rs similarity index 100% rename from src/json.rs rename to src/api.rs diff --git a/src/lib.rs b/src/lib.rs index ce243d3304..1cce3434cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,6 +103,7 @@ macro_rules! tprintln { }; } +pub mod api; pub mod arguments; mod blocktime; pub mod chain; @@ -111,7 +112,6 @@ mod decimal; mod fee_rate; pub mod index; mod inscriptions; -pub mod json; mod object; pub mod options; pub mod outgoing; diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 0c1f8fe94f..64ca2e5731 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -537,7 +537,7 @@ impl Server { }); let blocktime = index.block_time(sat.height())?; Ok(if accept_json { - Json(json::Sat { + Json(api::Sat { number: sat.0, decimal: sat.decimal().to_string(), degree: sat.degree().to_string(), @@ -616,7 +616,7 @@ impl Server { let spent = index.is_output_spent(outpoint)?; Ok(if accept_json { - Json(json::Output::new( + Json(api::Output::new( server_config.chain, inscriptions, outpoint, @@ -801,7 +801,7 @@ impl Server { Ok(if accept_json { let inscriptions = index.get_inscriptions_in_block(height)?; - Json(json::Block::new( + Json(api::Block::new( block, Height(height), Self::index_height(&index)?, @@ -912,7 +912,7 @@ impl Server { }; Ok( - Json(json::InscriptionRecursive { + Json(api::InscriptionRecursive { charms: Charm::ALL .iter() .filter(|charm| charm.is_set(entry.charms)) @@ -1141,7 +1141,7 @@ impl Server { async fn block_info( Extension(index): Extension>, Path(DeserializeFromStr(query)): Path>, - ) -> ServerResult> { + ) -> ServerResult> { task::block_in_place(|| { let hash = match query { BlockQuery::Hash(hash) => hash, @@ -1158,7 +1158,7 @@ impl Server { .block_header(hash)? .ok_or_not_found(|| format!("block {hash}"))?; - Ok(Json(json::BlockInfo { + Ok(Json(api::BlockInfo { bits: header.bits.to_consensus(), chainwork: chainwork(&info.chainwork), confirmations: info.confirmations, @@ -1441,7 +1441,7 @@ impl Server { .ok_or_not_found(|| format!("inscription {query}"))?; Ok(if accept_json { - Json(json::Inscription { + Json(api::Inscription { inscription_id: info.entry.id, charms: Charm::ALL .iter() @@ -1596,7 +1596,7 @@ impl Server { let (ids, more) = index.get_children_by_sequence_number_paginated(parent_sequence_number, 100, page)?; - Ok(Json(json::Children { ids, more, page }).into_response()) + Ok(Json(api::Children { ids, more, page }).into_response()) }) } @@ -1628,7 +1628,7 @@ impl Server { let next = more.then_some(page_index + 1); Ok(if accept_json { - Json(json::Inscriptions { + Json(api::Inscriptions { inscriptions, page_index, more, @@ -1687,7 +1687,7 @@ impl Server { } Ok(if accept_json { - Json(json::Inscriptions { + Json(api::Inscriptions { inscriptions, page_index, more, @@ -1710,14 +1710,14 @@ impl Server { async fn sat_inscriptions( Extension(index): Extension>, Path(sat): Path, - ) -> ServerResult> { + ) -> ServerResult> { Self::sat_inscriptions_paginated(Extension(index), Path((sat, 0))).await } async fn sat_inscriptions_paginated( Extension(index): Extension>, Path((sat, page)): Path<(u64, u64)>, - ) -> ServerResult> { + ) -> ServerResult> { task::block_in_place(|| { if !index.has_sat_index() { return Err(ServerError::NotFound( @@ -1727,14 +1727,14 @@ impl Server { let (ids, more) = index.get_inscription_ids_by_sat_paginated(Sat(sat), 100, page)?; - Ok(Json(json::SatInscriptions { ids, more, page })) + Ok(Json(api::SatInscriptions { ids, more, page })) }) } async fn sat_inscription_at_index( Extension(index): Extension>, Path((DeserializeFromStr(sat), inscription_index)): Path<(DeserializeFromStr, isize)>, - ) -> ServerResult> { + ) -> ServerResult> { task::block_in_place(|| { if !index.has_sat_index() { return Err(ServerError::NotFound( @@ -1744,7 +1744,7 @@ impl Server { let id = index.get_inscription_id_by_sat_indexed(sat, inscription_index)?; - Ok(Json(json::SatInscription { id })) + Ok(Json(api::SatInscription { id })) }) } @@ -2762,8 +2762,8 @@ mod tests { ); assert_eq!( - server.get_json::(format!("/output/{output}")), - json::Output { + server.get_json::(format!("/output/{output}")), + api::Output { value: 5000000000, script_pubkey: String::new(), address: None, @@ -4407,14 +4407,14 @@ next assert_eq!( server - .get_json::(format!("/inscription/{inscription_id}")) + .get_json::(format!("/inscription/{inscription_id}")) .parent, Some(parent_inscription_id), ); assert_eq!( server - .get_json::(format!("/inscription/{parent_inscription_id}")) + .get_json::(format!("/inscription/{parent_inscription_id}")) .children, [inscription_id], ); @@ -5085,8 +5085,8 @@ next let server = TestServer::new_with_regtest_with_index_sats(); assert_eq!( - server.get_json::("/r/sat/5000000000"), - json::SatInscriptions { + server.get_json::("/r/sat/5000000000"), + api::SatInscriptions { ids: vec![], page: 0, more: false @@ -5094,8 +5094,8 @@ next ); assert_eq!( - server.get_json::("/r/sat/5000000000/at/0"), - json::SatInscription { id: None } + server.get_json::("/r/sat/5000000000/at/0"), + api::SatInscription { id: None } ); server.mine_blocks(1); @@ -5121,10 +5121,10 @@ next ids.push(InscriptionId { txid, index: 0 }); } - let paginated_response = server.get_json::("/r/sat/5000000000"); + let paginated_response = server.get_json::("/r/sat/5000000000"); let equivalent_paginated_response = - server.get_json::("/r/sat/5000000000/0"); + server.get_json::("/r/sat/5000000000/0"); assert_eq!(paginated_response.ids.len(), 100); assert!(paginated_response.more); @@ -5137,7 +5137,7 @@ next assert_eq!(paginated_response.more, equivalent_paginated_response.more); assert_eq!(paginated_response.page, equivalent_paginated_response.page); - let paginated_response = server.get_json::("/r/sat/5000000000/1"); + let paginated_response = server.get_json::("/r/sat/5000000000/1"); assert_eq!(paginated_response.ids.len(), 11); assert!(!paginated_response.more); @@ -5145,34 +5145,34 @@ next assert_eq!( server - .get_json::("/r/sat/5000000000/at/0") + .get_json::("/r/sat/5000000000/at/0") .id, Some(ids[0]) ); assert_eq!( server - .get_json::("/r/sat/5000000000/at/-111") + .get_json::("/r/sat/5000000000/at/-111") .id, Some(ids[0]) ); assert_eq!( server - .get_json::("/r/sat/5000000000/at/110") + .get_json::("/r/sat/5000000000/at/110") .id, Some(ids[110]) ); assert_eq!( server - .get_json::("/r/sat/5000000000/at/-1") + .get_json::("/r/sat/5000000000/at/-1") .id, Some(ids[110]) ); assert!(server - .get_json::("/r/sat/5000000000/at/111") + .get_json::("/r/sat/5000000000/at/111") .id .is_none()); } @@ -5201,7 +5201,7 @@ next server.mine_blocks(1); let children_json = - server.get_json::(format!("/r/children/{parent_inscription_id}")); + server.get_json::(format!("/r/children/{parent_inscription_id}")); assert_eq!(children_json.ids.len(), 0); let mut builder = script::Builder::new(); @@ -5231,7 +5231,7 @@ next let hundred_eleventh_child_inscription_id = InscriptionId { txid, index: 110 }; let children_json = - server.get_json::(format!("/r/children/{parent_inscription_id}")); + server.get_json::(format!("/r/children/{parent_inscription_id}")); assert_eq!(children_json.ids.len(), 100); assert_eq!(children_json.ids[0], first_child_inscription_id); @@ -5240,7 +5240,7 @@ next assert_eq!(children_json.page, 0); let children_json = - server.get_json::(format!("/r/children/{parent_inscription_id}/1")); + server.get_json::(format!("/r/children/{parent_inscription_id}/1")); assert_eq!(children_json.ids.len(), 11); assert_eq!(children_json.ids[0], hundred_first_child_inscription_id); @@ -5370,8 +5370,8 @@ next let server = TestServer::new(); pretty_assert_eq!( - server.get_json::("/r/blockinfo/0"), - json::BlockInfo { + server.get_json::("/r/blockinfo/0"), + api::BlockInfo { bits: 486604799, chainwork: 0, confirmations: 0, @@ -5397,8 +5397,8 @@ next server.mine_blocks(1); pretty_assert_eq!( - server.get_json::("/r/blockinfo/1"), - json::BlockInfo { + server.get_json::("/r/blockinfo/1"), + api::BlockInfo { bits: 0, chainwork: 0, confirmations: 0, diff --git a/src/wallet.rs b/src/wallet.rs index efefe16e34..44d7e96853 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -47,9 +47,9 @@ pub(crate) struct Wallet { has_rune_index: bool, utxos: BTreeMap, locked_utxos: BTreeMap, - output_info: BTreeMap, + output_info: BTreeMap, inscriptions: BTreeMap>, - inscription_info: BTreeMap, + inscription_info: BTreeMap, } impl Wallet { @@ -181,14 +181,14 @@ impl Wallet { }) } - async fn get_output(ord_client: &OrdClient, output: OutPoint) -> Result { + async fn get_output(ord_client: &OrdClient, output: OutPoint) -> Result { let response = ord_client.get(&format!("/output/{output}")).await?; if !response.status().is_success() { bail!("wallet failed get output: {}", response.text().await?); } - let output_json: json::Output = serde_json::from_str(&response.text().await?)?; + let output_json: api::Output = serde_json::from_str(&response.text().await?)?; if !output_json.indexed { bail!("output in wallet but not in ord server: {output}"); @@ -245,7 +245,7 @@ impl Wallet { async fn get_inscription_info( ord_client: &OrdClient, inscription_id: InscriptionId, - ) -> Result { + ) -> Result { let response = ord_client .get(&format!("/inscription/{inscription_id}")) .await?; @@ -329,7 +329,7 @@ impl Wallet { &self.inscriptions } - pub(crate) fn inscription_info(&self) -> BTreeMap { + pub(crate) fn inscription_info(&self) -> BTreeMap { self.inscription_info.clone() } diff --git a/tests/json_api.rs b/tests/json_api.rs index 5f35ef93a6..56b1eefafe 100644 --- a/tests/json_api.rs +++ b/tests/json_api.rs @@ -9,14 +9,14 @@ fn get_sat_without_sat_index() { assert_eq!(response.status(), StatusCode::OK); - let mut sat_json: json::Sat = serde_json::from_str(&response.text().unwrap()).unwrap(); + let mut sat_json: api::Sat = serde_json::from_str(&response.text().unwrap()).unwrap(); // this is a hack to ignore the timestamp, since it changes for every request sat_json.timestamp = 0; pretty_assert_eq!( sat_json, - json::Sat { + api::Sat { number: 2099999997689999, decimal: "6929999.0".into(), degree: "5°209999′1007″0‴".into(), @@ -50,11 +50,11 @@ fn get_sat_with_inscription_and_sat_index() { assert_eq!(response.status(), StatusCode::OK); - let sat_json: json::Sat = serde_json::from_str(&response.text().unwrap()).unwrap(); + let sat_json: api::Sat = serde_json::from_str(&response.text().unwrap()).unwrap(); pretty_assert_eq!( sat_json, - json::Sat { + api::Sat { number: 50 * COIN_VALUE, decimal: "1.0".into(), degree: "0°1′1″0‴".into(), @@ -106,11 +106,11 @@ fn get_sat_with_inscription_on_common_sat_and_more_inscriptions() { assert_eq!(response.status(), StatusCode::OK); - let sat_json: json::Sat = serde_json::from_str(&response.text().unwrap()).unwrap(); + let sat_json: api::Sat = serde_json::from_str(&response.text().unwrap()).unwrap(); pretty_assert_eq!( sat_json, - json::Sat { + api::Sat { number: 3 * 50 * COIN_VALUE + 1, decimal: "3.1".into(), degree: "0°3′3″1‴".into(), @@ -144,14 +144,14 @@ fn get_inscription() { assert_eq!(response.status(), StatusCode::OK); - let mut inscription_json: json::Inscription = + 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, - json::Inscription { + api::Inscription { address: None, charms: vec!["coin".into(), "uncommon".into()], children: Vec::new(), @@ -210,7 +210,7 @@ fn get_inscriptions() { let response = ord_rpc_server.json_request("/inscriptions"); assert_eq!(response.status(), StatusCode::OK); - let inscriptions_json: json::Inscriptions = + let inscriptions_json: api::Inscriptions = serde_json::from_str(&response.text().unwrap()).unwrap(); assert_eq!(inscriptions_json.inscriptions.len(), 100); @@ -219,7 +219,7 @@ fn get_inscriptions() { let response = ord_rpc_server.json_request("/inscriptions/1"); assert_eq!(response.status(), StatusCode::OK); - let inscriptions_json: json::Inscriptions = + let inscriptions_json: api::Inscriptions = serde_json::from_str(&response.text().unwrap()).unwrap(); assert_eq!(inscriptions_json.inscriptions.len(), 50); @@ -272,7 +272,7 @@ fn get_inscriptions_in_block() { let response = ord_rpc_server.json_request(format!("/inscriptions/block/{}", 11)); assert_eq!(response.status(), StatusCode::OK); - let inscriptions_json: json::Inscriptions = + let inscriptions_json: api::Inscriptions = serde_json::from_str(&response.text().unwrap()).unwrap(); pretty_assert_eq!( @@ -318,7 +318,7 @@ fn get_output() { assert_eq!(response.status(), StatusCode::OK); assert!( - !serde_json::from_str::(&response.text().unwrap()) + !serde_json::from_str::(&response.text().unwrap()) .unwrap() .indexed ); @@ -328,11 +328,11 @@ fn get_output() { let response = server.json_request(format!("/output/{}:0", txid)); assert_eq!(response.status(), StatusCode::OK); - let output_json: json::Output = serde_json::from_str(&response.text().unwrap()).unwrap(); + let output_json: api::Output = serde_json::from_str(&response.text().unwrap()).unwrap(); pretty_assert_eq!( output_json, - json::Output { + api::Output { address: None, inscriptions: vec![ InscriptionId { txid, index: 0 }, @@ -376,11 +376,11 @@ fn get_block() { assert_eq!(response.status(), StatusCode::OK); - let block_json: json::Block = serde_json::from_str(&response.text().unwrap()).unwrap(); + let block_json: api::Block = serde_json::from_str(&response.text().unwrap()).unwrap(); assert_eq!( block_json, - json::Block { + api::Block { hash: "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" .parse::() .unwrap(), diff --git a/tests/lib.rs b/tests/lib.rs index b91de85feb..0e2a633865 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -11,8 +11,8 @@ use { chrono::{DateTime, Utc}, executable_path::executable_path, ord::{ + api, chain::Chain, - json, outgoing::Outgoing, subcommand::runes::RuneInfo, templates::{ diff --git a/tests/server.rs b/tests/server.rs index 4f519d1e2b..6e30e5bdf6 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -308,12 +308,12 @@ fn recursive_inscription_endpoint() { "application/json" ); - let inscription_recursive_json: json::InscriptionRecursive = + let inscription_recursive_json: api::InscriptionRecursive = serde_json::from_str(&response.text().unwrap()).unwrap(); pretty_assert_eq!( inscription_recursive_json, - json::InscriptionRecursive { + api::InscriptionRecursive { charms: vec!["coin".into(), "uncommon".into()], content_type: Some("text/plain;charset=utf-8".to_string()), content_length: Some(3), diff --git a/tests/wallet/inscribe.rs b/tests/wallet/inscribe.rs index 29fb6a4003..143e2318a2 100644 --- a/tests/wallet/inscribe.rs +++ b/tests/wallet/inscribe.rs @@ -2207,7 +2207,7 @@ fn batch_inscribe_with_satpoints_with_parent() { offset: 0, }; - let sat_1 = serde_json::from_str::( + let sat_1 = serde_json::from_str::( &ord_rpc_server .json_request(format!("/output/{}", satpoint_1.outpoint)) .text() @@ -2218,7 +2218,7 @@ fn batch_inscribe_with_satpoints_with_parent() { .unwrap()[0] .0; - let sat_2 = serde_json::from_str::( + let sat_2 = serde_json::from_str::( &ord_rpc_server .json_request(format!("/output/{}", satpoint_2.outpoint)) .text() @@ -2229,7 +2229,7 @@ fn batch_inscribe_with_satpoints_with_parent() { .unwrap()[0] .0; - let sat_3 = serde_json::from_str::( + let sat_3 = serde_json::from_str::( &ord_rpc_server .json_request(format!("/output/{}", satpoint_3.outpoint)) .text() @@ -2389,7 +2389,7 @@ fn batch_inscribe_with_satpoints_with_different_sizes() { offset: 0, }; - let output_1 = serde_json::from_str::( + let output_1 = serde_json::from_str::( &ord_rpc_server .json_request(format!("/output/{}", satpoint_1.outpoint)) .text() @@ -2398,7 +2398,7 @@ fn batch_inscribe_with_satpoints_with_different_sizes() { .unwrap(); assert_eq!(output_1.value, 25 * COIN_VALUE); - let output_2 = serde_json::from_str::( + let output_2 = serde_json::from_str::( &ord_rpc_server .json_request(format!("/output/{}", satpoint_2.outpoint)) .text() @@ -2407,7 +2407,7 @@ fn batch_inscribe_with_satpoints_with_different_sizes() { .unwrap(); assert_eq!(output_2.value, COIN_VALUE); - let output_3 = serde_json::from_str::( + let output_3 = serde_json::from_str::( &ord_rpc_server .json_request(format!("/output/{}", satpoint_3.outpoint)) .text() diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index 546d63f05e..1aefd8abdd 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -280,11 +280,11 @@ fn splitting_merged_inscriptions_is_possible() { let response = ord_rpc_server.json_request(format!("/output/{}:0", reveal_txid)); assert_eq!(response.status(), StatusCode::OK); - let output_json: json::Output = serde_json::from_str(&response.text().unwrap()).unwrap(); + let output_json: api::Output = serde_json::from_str(&response.text().unwrap()).unwrap(); pretty_assert_eq!( output_json, - json::Output { + api::Output { address: None, inscriptions: vec![ InscriptionId { From 82295b2d6ec74bf747de8ab479f2d4389885c705 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 23 Feb 2024 14:10:57 -0800 Subject: [PATCH 5/6] Amend --- src/api.rs | 158 ++++++++++++++++++++++++++--------------------------- 1 file changed, 78 insertions(+), 80 deletions(-) diff --git a/src/api.rs b/src/api.rs index 4d7e85b2cb..44a2eadde8 100644 --- a/src/api.rs +++ b/src/api.rs @@ -3,26 +3,6 @@ use super::{ Rarity, SatPoint, Serialize, SpacedRune, TxMerkleNode, TxOut, }; -// todo: sort - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct Sat { - pub number: u64, - pub decimal: String, - pub degree: String, - pub name: String, - pub block: u32, - pub cycle: u32, - pub epoch: u32, - pub period: u32, - pub offset: u64, - pub rarity: Rarity, - pub percentile: String, - pub satpoint: Option, - pub timestamp: i64, - pub inscriptions: Vec, -} - #[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct Block { pub hash: BlockHash, @@ -49,47 +29,6 @@ impl Block { } } -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct Output { - pub address: Option, - pub indexed: bool, - pub inscriptions: Vec, - pub runes: Vec<(SpacedRune, Pile)>, - pub sat_ranges: Option>, - pub script_pubkey: String, - pub spent: bool, - pub transaction: String, - pub value: u64, -} - -impl Output { - pub fn new( - chain: Chain, - inscriptions: Vec, - outpoint: OutPoint, - output: TxOut, - indexed: bool, - runes: Vec<(SpacedRune, Pile)>, - sat_ranges: Option>, - spent: bool, - ) -> Self { - Self { - address: chain - .address_from_script(&output.script_pubkey) - .ok() - .map(|address| address.to_string()), - indexed, - inscriptions, - runes, - sat_ranges, - script_pubkey: output.script_pubkey.to_asm_string(), - spent, - transaction: outpoint.txid.to_string(), - value: output.value, - } - } -} - #[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct BlockInfo { pub bits: u32, @@ -137,25 +76,6 @@ pub struct Inscription { pub timestamp: i64, } -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct SatInscriptions { - pub ids: Vec, - pub more: bool, - pub page: u64, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct SatInscription { - pub id: Option, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct Inscriptions { - pub inscriptions: Vec, - pub more: bool, - pub page_index: u32, -} - #[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct InscriptionRecursive { pub charms: Vec, @@ -170,3 +90,81 @@ pub struct InscriptionRecursive { pub timestamp: i64, pub value: Option, } + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Inscriptions { + pub inscriptions: Vec, + pub more: bool, + pub page_index: u32, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Output { + pub address: Option, + pub indexed: bool, + pub inscriptions: Vec, + pub runes: Vec<(SpacedRune, Pile)>, + pub sat_ranges: Option>, + pub script_pubkey: String, + pub spent: bool, + pub transaction: String, + pub value: u64, +} + +impl Output { + pub fn new( + chain: Chain, + inscriptions: Vec, + outpoint: OutPoint, + output: TxOut, + indexed: bool, + runes: Vec<(SpacedRune, Pile)>, + sat_ranges: Option>, + spent: bool, + ) -> Self { + Self { + address: chain + .address_from_script(&output.script_pubkey) + .ok() + .map(|address| address.to_string()), + indexed, + inscriptions, + runes, + sat_ranges, + script_pubkey: output.script_pubkey.to_asm_string(), + spent, + transaction: outpoint.txid.to_string(), + value: output.value, + } + } +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct Sat { + pub number: u64, + pub decimal: String, + pub degree: String, + pub name: String, + pub block: u32, + pub cycle: u32, + pub epoch: u32, + pub period: u32, + pub offset: u64, + pub rarity: Rarity, + pub percentile: String, + pub satpoint: Option, + pub timestamp: i64, + pub inscriptions: Vec, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct SatInscription { + pub id: Option, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +pub struct SatInscriptions { + pub ids: Vec, + pub more: bool, + pub page: u64, +} From 827d2c1d08f6d141072f662ce44c3e90270b1669 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 23 Feb 2024 14:31:09 -0800 Subject: [PATCH 6/6] Amend --- src/api.rs | 5 +++++ src/lib.rs | 1 - src/subcommand/server.rs | 19 +++++++++---------- src/templates.rs | 10 +++++----- src/templates/blocks.rs | 2 -- src/templates/rune.rs | 2 -- src/templates/runes.rs | 2 -- src/templates/status.rs | 2 -- src/templates/transaction.rs | 2 -- src/wallet.rs | 4 ++-- tests/json_api.rs | 20 ++++++++++---------- tests/lib.rs | 11 ++--------- 12 files changed, 33 insertions(+), 47 deletions(-) diff --git a/src/api.rs b/src/api.rs index 44a2eadde8..e1db4f0b4a 100644 --- a/src/api.rs +++ b/src/api.rs @@ -3,6 +3,11 @@ use super::{ Rarity, SatPoint, Serialize, SpacedRune, TxMerkleNode, TxOut, }; +pub use crate::templates::{ + BlocksHtml as Blocks, RuneHtml as Rune, RunesHtml as Runes, StatusHtml as Status, + TransactionHtml as Transaction, +}; + #[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct Block { pub hash: BlockHash, diff --git a/src/lib.rs b/src/lib.rs index 1cce3434cf..ba7410dd55 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,7 +71,6 @@ use { time::{Duration, Instant, SystemTime}, }, sysinfo::System, - templates::{RuneJson, StatusJson}, tokio::{runtime::Runtime, task}, }; diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 64ca2e5731..81eb198fda 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -8,12 +8,11 @@ use { crate::{ server_config::ServerConfig, templates::{ - BlockHtml, BlocksHtml, BlocksJson, ChildrenHtml, ClockSvg, CollectionsHtml, HomeHtml, - InputHtml, InscriptionHtml, InscriptionsBlockHtml, InscriptionsHtml, OutputHtml, PageContent, - PageHtml, PreviewAudioHtml, PreviewCodeHtml, PreviewFontHtml, PreviewImageHtml, - PreviewMarkdownHtml, PreviewModelHtml, PreviewPdfHtml, PreviewTextHtml, PreviewUnknownHtml, - PreviewVideoHtml, RangeHtml, RareTxt, RuneBalancesHtml, RuneHtml, RuneJson, RunesHtml, - RunesJson, SatHtml, TransactionHtml, TransactionJson, + BlockHtml, BlocksHtml, ChildrenHtml, ClockSvg, CollectionsHtml, HomeHtml, InputHtml, + InscriptionHtml, InscriptionsBlockHtml, InscriptionsHtml, OutputHtml, PageContent, PageHtml, + PreviewAudioHtml, PreviewCodeHtml, PreviewFontHtml, PreviewImageHtml, PreviewMarkdownHtml, + PreviewModelHtml, PreviewPdfHtml, PreviewTextHtml, PreviewUnknownHtml, PreviewVideoHtml, + RangeHtml, RareTxt, RuneBalancesHtml, RuneHtml, RunesHtml, SatHtml, TransactionHtml, }, }, axum::{ @@ -681,7 +680,7 @@ impl Server { .ok_or_not_found(|| format!("rune {spaced_rune}"))?; Ok(if accept_json { - Json(RuneJson { entry, id, parent }).into_response() + Json(api::Rune { entry, id, parent }).into_response() } else { RuneHtml { entry, id, parent } .page(server_config) @@ -697,7 +696,7 @@ impl Server { ) -> ServerResult { task::block_in_place(|| { Ok(if accept_json { - Json(RunesJson { + Json(api::Runes { entries: index.runes()?, }) .into_response() @@ -758,7 +757,7 @@ impl Server { } Ok(if accept_json { - Json(BlocksJson::new(blocks, featured_blocks)).into_response() + Json(api::Blocks::new(blocks, featured_blocks)).into_response() } else { BlocksHtml::new(blocks, featured_blocks) .page(server_config) @@ -838,7 +837,7 @@ impl Server { let inscription_count = index.inscription_count(txid)?; Ok(if accept_json { - Json(TransactionJson { + Json(api::Transaction { chain: server_config.chain, etching: index.get_etching(txid)?, inscription_count, diff --git a/src/templates.rs b/src/templates.rs index 27a6efe830..e0474c34a3 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -2,7 +2,6 @@ use {super::*, boilerplate::Boilerplate}; pub(crate) use { block::BlockHtml, - blocks::{BlocksHtml, BlocksJson}, children::ChildrenHtml, clock::ClockSvg, collections::CollectionsHtml, @@ -20,13 +19,14 @@ pub(crate) use { }, range::RangeHtml, rare::RareTxt, - rune::{RuneHtml, RuneJson}, rune_balances::RuneBalancesHtml, - runes::{RunesHtml, RunesJson}, sat::SatHtml, server_config::ServerConfig, - status::{StatusHtml, StatusJson}, - transaction::{TransactionHtml, TransactionJson}, +}; + +pub use { + blocks::BlocksHtml, rune::RuneHtml, runes::RunesHtml, status::StatusHtml, + transaction::TransactionHtml, }; pub mod block; diff --git a/src/templates/blocks.rs b/src/templates/blocks.rs index 6a63b9e2d8..8bf1747d8f 100644 --- a/src/templates/blocks.rs +++ b/src/templates/blocks.rs @@ -1,7 +1,5 @@ use super::*; -pub type BlocksJson = BlocksHtml; - #[derive(Boilerplate, Debug, PartialEq, Serialize, Deserialize)] pub struct BlocksHtml { pub last: u32, diff --git a/src/templates/rune.rs b/src/templates/rune.rs index 83651b4045..74729479ec 100644 --- a/src/templates/rune.rs +++ b/src/templates/rune.rs @@ -1,7 +1,5 @@ use super::*; -pub type RuneJson = RuneHtml; - #[derive(Boilerplate, Debug, PartialEq, Serialize, Deserialize)] pub struct RuneHtml { pub entry: RuneEntry, diff --git a/src/templates/runes.rs b/src/templates/runes.rs index ace35fca32..c8e9951e1a 100644 --- a/src/templates/runes.rs +++ b/src/templates/runes.rs @@ -1,7 +1,5 @@ use super::*; -pub type RunesJson = RunesHtml; - #[derive(Boilerplate, Debug, PartialEq, Serialize, Deserialize)] pub struct RunesHtml { pub entries: Vec<(RuneId, RuneEntry)>, diff --git a/src/templates/status.rs b/src/templates/status.rs index b36fda057e..b96cf26241 100644 --- a/src/templates/status.rs +++ b/src/templates/status.rs @@ -1,7 +1,5 @@ use super::*; -pub type StatusJson = StatusHtml; - #[derive(Boilerplate, Debug, PartialEq, Serialize, Deserialize)] pub struct StatusHtml { pub blessed_inscriptions: u64, diff --git a/src/templates/transaction.rs b/src/templates/transaction.rs index a2f741bec3..b62e6efafd 100644 --- a/src/templates/transaction.rs +++ b/src/templates/transaction.rs @@ -1,7 +1,5 @@ use super::*; -pub type TransactionJson = TransactionHtml; - #[derive(Boilerplate, Debug, PartialEq, Serialize, Deserialize)] pub struct TransactionHtml { pub chain: Chain, diff --git a/src/wallet.rs b/src/wallet.rs index 44d7e96853..626fc604e1 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -257,7 +257,7 @@ impl Wallet { Ok(serde_json::from_str(&response.text().await?)?) } - async fn get_server_status(ord_client: &OrdClient) -> Result { + async fn get_server_status(ord_client: &OrdClient) -> Result { let response = ord_client.get("/status").await?; if !response.status().is_success() { @@ -440,7 +440,7 @@ impl Wallet { return Ok(None); } - let rune_json: RuneJson = serde_json::from_str(&response.text()?)?; + let rune_json: api::Rune = serde_json::from_str(&response.text()?)?; Ok(Some((rune_json.id, rune_json.entry, rune_json.parent))) } diff --git a/tests/json_api.rs b/tests/json_api.rs index 56b1eefafe..6d514b4eaf 100644 --- a/tests/json_api.rs +++ b/tests/json_api.rs @@ -413,11 +413,11 @@ fn get_blocks() { assert_eq!(response.status(), StatusCode::OK); - let blocks_json: BlocksJson = serde_json::from_str(&response.text().unwrap()).unwrap(); + let blocks_json: api::Blocks = serde_json::from_str(&response.text().unwrap()).unwrap(); pretty_assert_eq!( blocks_json, - BlocksJson { + api::Blocks { last: 101, blocks: blocks.clone(), featured_blocks: blocks @@ -444,8 +444,8 @@ fn get_transaction() { assert_eq!(response.status(), StatusCode::OK); assert_eq!( - serde_json::from_str::(&response.text().unwrap()).unwrap(), - TransactionJson { + serde_json::from_str::(&response.text().unwrap()).unwrap(), + api::Transaction { chain: Chain::Mainnet, etching: None, inscription_count: 0, @@ -476,7 +476,7 @@ fn get_status() { assert_eq!(response.status(), StatusCode::OK); - let mut status_json: StatusJson = serde_json::from_str(&response.text().unwrap()).unwrap(); + let mut status_json: api::Status = serde_json::from_str(&response.text().unwrap()).unwrap(); let dummy_started = "2012-12-12 12:12:12+00:00" .parse::>() @@ -489,7 +489,7 @@ fn get_status() { pretty_assert_eq!( status_json, - StatusJson { + api::Status { blessed_inscriptions: 1, chain: Chain::Regtest, content_type_counts: vec![(Some("text/plain;charset=utf-8".into()), 1)], @@ -531,11 +531,11 @@ fn get_runes() { let response = ord_rpc_server.json_request(format!("/rune/{}", a.rune)); assert_eq!(response.status(), StatusCode::OK); - let rune_json: RuneJson = serde_json::from_str(&response.text().unwrap()).unwrap(); + let rune_json: api::Rune = serde_json::from_str(&response.text().unwrap()).unwrap(); pretty_assert_eq!( rune_json, - RuneJson { + api::Rune { entry: RuneEntry { burned: 0, mint: None, @@ -561,11 +561,11 @@ fn get_runes() { assert_eq!(response.status(), StatusCode::OK); - let runes_json: RunesJson = serde_json::from_str(&response.text().unwrap()).unwrap(); + let runes_json: api::Runes = serde_json::from_str(&response.text().unwrap()).unwrap(); pretty_assert_eq!( runes_json, - RunesJson { + api::Runes { entries: vec![ ( RuneId { diff --git a/tests/lib.rs b/tests/lib.rs index 0e2a633865..fc0933d4eb 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -11,15 +11,8 @@ use { chrono::{DateTime, Utc}, executable_path::executable_path, ord::{ - api, - chain::Chain, - outgoing::Outgoing, - subcommand::runes::RuneInfo, - templates::{ - blocks::BlocksJson, rune::RuneJson, runes::RunesJson, status::StatusJson, - transaction::TransactionJson, - }, - Edict, InscriptionId, Rune, RuneEntry, RuneId, Runestone, + api, chain::Chain, outgoing::Outgoing, subcommand::runes::RuneInfo, Edict, InscriptionId, Rune, + RuneEntry, RuneId, Runestone, }, ordinals::{Rarity, Sat, SatPoint}, pretty_assertions::assert_eq as pretty_assert_eq,