From 91e7ca6f3abf1397f62964d6893c52fe2f76bc5b Mon Sep 17 00:00:00 2001 From: raphjaph Date: Tue, 22 Aug 2023 00:39:50 +0200 Subject: [PATCH 1/3] show inscriptions paying hightest inscription fee --- src/index/block_index.rs | 25 +++++++++++++++++++++++++ src/subcommand/server.rs | 16 ++++++++++++++-- src/templates/block.rs | 25 +++++++++++++++++++++---- templates/block.html | 6 ++++++ 4 files changed, 66 insertions(+), 6 deletions(-) diff --git a/src/index/block_index.rs b/src/index/block_index.rs index c036080f22..e483f2a124 100644 --- a/src/index/block_index.rs +++ b/src/index/block_index.rs @@ -198,4 +198,29 @@ impl BlockIndex { Ok(inscriptions) } + + pub(crate) fn get_highest_paying_inscriptions_in_block( + &self, + index: &Index, + block_height: u64, + n: usize, + ) -> Result> { + let inscription_ids = self.get_inscriptions_in_block(index, block_height)?; + + let mut inscription_to_fee: Vec<(InscriptionId, u64)> = Vec::new(); + for id in inscription_ids { + inscription_to_fee.push((id, index.get_inscription_entry(id)?.unwrap().fee)); + } + + inscription_to_fee.sort_by_key(|(_, fee)| *fee); + + Ok( + inscription_to_fee + .iter() + .map(|(id, _)| *id) + .rev() + .take(n) + .collect(), + ) + } } diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 46b9fac786..550c55abd5 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -566,6 +566,7 @@ impl Server { async fn block( Extension(page_config): Extension>, Extension(index): Extension>, + Extension(block_index_state): Extension>, Path(DeserializeFromStr(query)): Path>, ) -> ServerResult> { let (block, height) = match query { @@ -589,9 +590,20 @@ impl Server { } }; + let inscriptions = block_index_state + .block_index + .read() + .unwrap() + .get_highest_paying_inscriptions_in_block(&index, height, 2000)?; + Ok( - BlockHtml::new(block, Height(height), Self::index_height(&index)?) - .page(page_config, index.has_sat_index()?), + BlockHtml::new( + block, + Height(height), + Self::index_height(&index)?, + inscriptions, + ) + .page(page_config, index.has_sat_index()?), ) } diff --git a/src/templates/block.rs b/src/templates/block.rs index d05988ff91..5193f31ba8 100644 --- a/src/templates/block.rs +++ b/src/templates/block.rs @@ -7,16 +7,23 @@ pub(crate) struct BlockHtml { best_height: Height, block: Block, height: Height, + inscriptions: Vec, } impl BlockHtml { - pub(crate) fn new(block: Block, height: Height, best_height: Height) -> Self { + pub(crate) fn new( + block: Block, + height: Height, + best_height: Height, + inscriptions: Vec, + ) -> Self { Self { hash: block.header.block_hash(), target: BlockHash::from_raw_hash(Hash::from_byte_array(block.header.target().to_be_bytes())), block, height, best_height, + inscriptions, } } } @@ -34,7 +41,12 @@ mod tests { #[test] fn html() { assert_regex_match!( - BlockHtml::new(Chain::Mainnet.genesis_block(), Height(0), Height(0)), + BlockHtml::new( + Chain::Mainnet.genesis_block(), + Height(0), + Height(0), + vec![inscription_id(1), inscription_id(2)] + ), "

Block 0

@@ -48,6 +60,11 @@ mod tests { prev next .* +

2 Inscriptions

+
+ + +

1 Transaction

  • [[:xdigit:]]{64}
  • @@ -60,7 +77,7 @@ mod tests { #[test] fn next_active_when_not_last() { assert_regex_match!( - BlockHtml::new(Chain::Mainnet.genesis_block(), Height(0), Height(1)), + BlockHtml::new(Chain::Mainnet.genesis_block(), Height(0), Height(1), vec![]), r"

    Block 0

    .*prev\s*.*" ); } @@ -68,7 +85,7 @@ mod tests { #[test] fn prev_active_when_not_first() { assert_regex_match!( - BlockHtml::new(Chain::Mainnet.genesis_block(), Height(1), Height(1)), + BlockHtml::new(Chain::Mainnet.genesis_block(), Height(1), Height(1), vec![]), r"

    Block 1

    .*\s*next.*", ); } diff --git a/templates/block.html b/templates/block.html index e5047f842d..055c103cc2 100644 --- a/templates/block.html +++ b/templates/block.html @@ -21,6 +21,12 @@

    Block {{ self.height }}

    next %% } +

    {{"Inscription".tally(self.inscriptions.len())}}

    +
    +%% for id in &self.inscriptions { + {{Iframe::thumbnail(*id)}} +%% } +

    {{"Transaction".tally(self.block.txdata.len())}}

      %% for tx in &self.block.txdata { From 6e72e8ce9b7a0ab9e6821b8de7e41b208cfd7536 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Sun, 27 Aug 2023 18:23:32 +0200 Subject: [PATCH 2/3] sooo pretty now --- src/index.rs | 14 -------------- src/subcommand/server.rs | 19 ++++++++++++++----- src/templates/home.rs | 6 +++--- static/index.css | 23 +++++++++++++++++++++-- templates/home.html | 23 +++++++++++++---------- templates/inscriptions-block.html | 2 +- 6 files changed, 52 insertions(+), 35 deletions(-) diff --git a/src/index.rs b/src/index.rs index 6f520cc5e8..799a8d2169 100644 --- a/src/index.rs +++ b/src/index.rs @@ -876,20 +876,6 @@ impl Index { Ok(result) } - pub(crate) fn get_homepage_inscriptions(&self) -> Result> { - Ok( - self - .database - .begin_read()? - .open_table(INSCRIPTION_NUMBER_TO_INSCRIPTION_ID)? - .iter()? - .rev() - .take(8) - .flat_map(|result| result.map(|(_number, id)| Entry::load(*id.value()))) - .collect(), - ) - } - pub(crate) fn get_latest_inscriptions_with_prev_and_next( &self, n: usize, diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 291e302721..1973604c33 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -560,15 +560,24 @@ impl Server { async fn home( Extension(page_config): Extension>, Extension(index): Extension>, + Extension(block_index_state): Extension>, ) -> ServerResult> { - Ok( - HomeHtml::new(index.blocks(100)?, index.get_homepage_inscriptions()?) - .page(page_config, index.has_sat_index()?), - ) + let blocks = index.blocks(100)?; + let mut featured_blocks = BTreeMap::new(); + for (height, hash) in blocks.iter().take(5) { + let inscriptions = block_index_state + .block_index + .read() + .unwrap() + .get_highest_paying_inscriptions_in_block(&index, *height, 8)?; + featured_blocks.insert(*hash, inscriptions); + } + + Ok(HomeHtml::new(blocks, featured_blocks).page(page_config, index.has_sat_index()?)) } async fn install_script() -> Redirect { - Redirect::to("https://raw.githubusercontent.com/casey/ord/master/install.sh") + Redirect::to("https://raw.githubusercontent.com/ordinals/ord/master/install.sh") } async fn block( diff --git a/src/templates/home.rs b/src/templates/home.rs index 8cfa012b0b..a052063ae5 100644 --- a/src/templates/home.rs +++ b/src/templates/home.rs @@ -4,11 +4,11 @@ use super::*; pub(crate) struct HomeHtml { last: u64, blocks: Vec, - inscriptions: Vec, + featured_blocks: BTreeMap>, } impl HomeHtml { - pub(crate) fn new(blocks: Vec<(u64, BlockHash)>, inscriptions: Vec) -> Self { + pub(crate) fn new(blocks: Vec<(u64, BlockHash)>, featured_blocks: BTreeMap>) -> Self { Self { last: blocks .get(0) @@ -16,7 +16,7 @@ impl HomeHtml { .cloned() .unwrap_or(0), blocks: blocks.into_iter().map(|(_, hash)| hash).collect(), - inscriptions, + featured_blocks, } } } diff --git a/static/index.css b/static/index.css index a8faeb6616..d80f739a8e 100644 --- a/static/index.css +++ b/static/index.css @@ -101,13 +101,32 @@ ol, ul { } } -.blocks { +.block-list { font-family: monospace, monospace; list-style-position: inside; - padding-inline-start: 1rem; white-space: nowrap; } +.block { + background-color: var(--light-bg); + box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px, var(--light-bg) 0px 0px 0px 3px; + margin: 3%; + padding: 0.5%; + text-align: center; +} + +.block a { + color: var(--light-fg); + margin-top: 1%; +} + +.block h2 { + margin: 1%; +} + +.light-fg a { + color: var(--light-fg); +} .center { text-align: center; } diff --git a/templates/home.html b/templates/home.html index 24a503a6d7..328e2ffa14 100644 --- a/templates/home.html +++ b/templates/home.html @@ -1,15 +1,18 @@ -%% if !&self.inscriptions.is_empty() { -

      Latest Inscriptions

      -
      -%% for id in &self.inscriptions { - {{Iframe::thumbnail(*id)}} +%% for (i, hash) in self.blocks.iter().enumerate() { +%% if let Some(inscription_ids) = &self.featured_blocks.get(hash) { +
      +

      Block {{ self.last - i as u64 }}

      +
      +%% for id in *inscription_ids { + {{ Iframe::thumbnail(*id) }} %% } +
      - +%% } else { +%% if i == self.featured_blocks.len() { +
        +%% } +
      1. {{ hash }}
      2. %% } -

        Latest Blocks

        -
          -%% for hash in &self.blocks { -
        1. {{hash}}
        2. %% }
        diff --git a/templates/inscriptions-block.html b/templates/inscriptions-block.html index 467ce3eba7..d087d147b0 100644 --- a/templates/inscriptions-block.html +++ b/templates/inscriptions-block.html @@ -1,4 +1,4 @@ -

        Inscriptions in Block {{ &self.block }}

        +

        Inscriptions in Block {{ &self.block }}

        %% for id in &self.inscriptions { {{ Iframe::thumbnail(*id) }} From ffe796876cb39e0b278407b148610e1cbf88c1ed Mon Sep 17 00:00:00 2001 From: raphjaph Date: Sun, 27 Aug 2023 18:55:02 +0200 Subject: [PATCH 3/3] quick fix --- src/subcommand/server.rs | 26 +++++++++------ src/templates/home.rs | 49 ++++++++++++++++++++--------- src/templates/inscriptions_block.rs | 4 +-- tests/server.rs | 43 ------------------------- 4 files changed, 52 insertions(+), 70 deletions(-) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 1973604c33..90f2ef1963 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -1554,7 +1554,7 @@ mod tests { fn install_sh_redirects_to_github() { TestServer::new().assert_redirect( "/install.sh", - "https://raw.githubusercontent.com/casey/ord/master/install.sh", + "https://raw.githubusercontent.com/ordinals/ord/master/install.sh", ); } @@ -1969,15 +1969,21 @@ mod tests { test_server.mine_blocks(1); test_server.assert_response_regex( - "/", - StatusCode::OK, - ".*Ordinals.* -

        Latest Blocks

        -
          -
        1. [[:xdigit:]]{64}
        2. -
        3. 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
        4. + "/", + StatusCode::OK, + ".*Ordinals.* +
          +

          Block 1

          +
          +
          +
          +
          +

          Block 0

          +
          +
          +
        .*", - ); + ); } #[test] @@ -1998,7 +2004,7 @@ mod tests { test_server.assert_response_regex( "/", StatusCode::OK, - ".*
          \n(
        1. [[:xdigit:]]{64}
        2. \n){100}
        .*" + ".*
          \n(
        1. [[:xdigit:]]{64}
        2. \n){95}
        .*" ); } diff --git a/src/templates/home.rs b/src/templates/home.rs index a052063ae5..137415cde5 100644 --- a/src/templates/home.rs +++ b/src/templates/home.rs @@ -8,7 +8,10 @@ pub(crate) struct HomeHtml { } impl HomeHtml { - pub(crate) fn new(blocks: Vec<(u64, BlockHash)>, featured_blocks: BTreeMap>) -> Self { + pub(crate) fn new( + blocks: Vec<(u64, BlockHash)>, + featured_blocks: BTreeMap>, + ) -> Self { Self { last: blocks .get(0) @@ -33,9 +36,23 @@ mod tests { #[test] fn html() { + let mut feature_blocks = BTreeMap::new(); + feature_blocks.insert( + "2222222222222222222222222222222222222222222222222222222222222222" + .parse() + .unwrap(), + vec![inscription_id(1), inscription_id(2)], + ); + assert_regex_match!( &HomeHtml::new( vec![ + ( + 1260002, + "2222222222222222222222222222222222222222222222222222222222222222" + .parse() + .unwrap() + ), ( 1260001, "1111111111111111111111111111111111111111111111111111111111111111" @@ -49,21 +66,23 @@ mod tests { .unwrap() ) ], - vec![inscription_id(1), inscription_id(2)], + feature_blocks, ) - .to_string(), - "

        Latest Inscriptions

        -
        - - -
        - -

        Latest Blocks

        -
          -
        1. 1{64}
        2. -
        3. 0{64}
        4. -
        -", + .to_string() + .unindent(), + "
        +

        Block 1260002

        +
        + + +
        +
        +
          +
        1. 1{64}
        2. +
        3. 0{64}
        4. +
        + " + .unindent(), ); } } diff --git a/src/templates/inscriptions_block.rs b/src/templates/inscriptions_block.rs index a3fc6a2a51..9619934535 100644 --- a/src/templates/inscriptions_block.rs +++ b/src/templates/inscriptions_block.rs @@ -67,7 +67,7 @@ mod tests { next_page: None, }, " -

        Inscriptions in Block 21

        +

        Inscriptions in Block 21

        @@ -93,7 +93,7 @@ mod tests { prev_page: Some(1), }, " -

        Inscriptions in Block 21

        +

        Inscriptions in Block 21

        diff --git a/tests/server.rs b/tests/server.rs index c893cc901b..ff69555cae 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -195,49 +195,6 @@ fn inscription_content() { assert_eq!(response.bytes().unwrap(), "FOO"); } -#[test] -fn home_page_includes_latest_inscriptions() { - let rpc_server = test_bitcoincore_rpc::spawn(); - create_wallet(&rpc_server); - - let Inscribe { inscription, .. } = inscribe(&rpc_server); - - TestServer::spawn_with_args(&rpc_server, &[]).assert_response_regex( - "/", - format!( - ".*

        Latest Inscriptions

        -