Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into embellish-block-page
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Oct 4, 2022
2 parents 720e305 + c89e539 commit c7bc207
Show file tree
Hide file tree
Showing 22 changed files with 98 additions and 126 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
/index.redb
/ord.log
/target
/test-times.txt
/tmp
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ http = "0.2.6"
lazy_static = "1.4.0"
log = "0.4.14"
mime_guess = "2.0.4"
primes = "0.3.0"
rayon = "1.5.1"
redb = "0.7.0"
regex = "1.6.0"
Expand Down
1 change: 0 additions & 1 deletion docs/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ build_search_index = false

[markdown]
highlight_code = true
highlight_theme = "base16-atelierdune-light"

[extra]
7 changes: 6 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ test-deploy:
. root@192.168.56.4:ord
ssh root@192.168.56.4 'cd ord && ./deploy/setup'

report-test-time:
time-tests:
cargo +nightly test -- -Z unstable-options --report-time

profile-tests:
cargo +nightly test -- -Z unstable-options --report-time \
| sed -n 's/^test \(.*\) ... ok <\(.*\)s>/\2 \1/p' | sort -n \
| tee test-times.txt

status:
ssh root@65.108.68.37 systemctl status bitcoind
ssh root@65.108.68.37 systemctl status ord
Expand Down
14 changes: 7 additions & 7 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ use {
pub(crate) struct Options {
#[clap(
long,
help = "Limit the ordinal index to <MAX_INDEX_SIZE> bytes. [mainnet, testnet, and signet default: 1 TiB, regtest default: 10 MiB]"
help = "Limit the ordinal index to <MAX_INDEX_SIZE> bytes. This cannot be changed later. [mainnet, testnet, and signet default: 1 TiB, regtest default: 10 MiB]"
)]
max_index_size: Option<Bytes>,
#[clap(long)]
#[clap(long, help = "Load Bitcoin Core RPC cookie file from <COOKIE_FILE>.")]
cookie_file: Option<PathBuf>,
#[clap(long)]
#[clap(long, help = "Connect to Bitcoin Core RPC at <RPC_URL>.")]
rpc_url: Option<String>,
#[clap(long, arg_enum, default_value = "mainnet")]
#[clap(long, arg_enum, default_value = "mainnet", help = "Index <CHAIN>.")]
pub(crate) chain: Chain,
#[clap(long)]
#[clap(long, help = "Store index in <DATA_DIR>.")]
data_dir: Option<PathBuf>,
#[clap(long)]
#[clap(long, help = "Load Bitcoin Core data dir from <BITCOIN_DATA_DIR>.")]
bitcoin_data_dir: Option<PathBuf>,
#[clap(long)]
#[clap(long, help = "Limit index to <HEIGHT_LIMIT> blocks.")]
pub(crate) height_limit: Option<u64>,
}

Expand Down
4 changes: 0 additions & 4 deletions src/ordinal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ impl Ordinal {
self.into()
}

pub(crate) fn prime(self) -> bool {
primes::is_prime(self.0)
}

pub(crate) fn name(self) -> String {
let mut x = Self::SUPPLY - self.0;
let mut name = String::new();
Expand Down
1 change: 1 addition & 0 deletions src/subcommand/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;

#[derive(Debug, Parser)]
pub(crate) struct Find {
#[clap(help = "Find output and offset of <ORDINAL>.")]
ordinal: Ordinal,
}

Expand Down
1 change: 1 addition & 0 deletions src/subcommand/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;

#[derive(Debug, Parser)]
pub(crate) struct List {
#[clap(help = "List ordinal ranges in <OUTPOINT>.")]
outpoint: OutPoint,
}

Expand Down
1 change: 1 addition & 0 deletions src/subcommand/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;

#[derive(Debug, Parser)]
pub(crate) struct Parse {
#[clap(help = "Parse <ORDINAL>.")]
ordinal: Ordinal,
}

Expand Down
3 changes: 2 additions & 1 deletion src/subcommand/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use super::*;

#[derive(Debug, Parser)]
pub(crate) struct Range {
#[clap(long)]
#[clap(long, help = "Display range as names.")]
name: bool,
#[clap(help = "List ordinal range in subsidy at <HEIGHT>.")]
height: Height,
}

Expand Down
88 changes: 23 additions & 65 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ impl IntoResponse for ServerError {
}
}

fn html_status(status_code: StatusCode) -> (StatusCode, Html<&'static str>) {
(
status_code,
Html(status_code.canonical_reason().unwrap_or_default()),
)
}

#[derive(Deserialize)]
struct Search {
query: String,
Expand Down Expand Up @@ -270,16 +277,7 @@ impl Server {
Ok(height) => ClockSvg::new(height).into_response(),
Err(err) => {
eprintln!("Failed to retrieve height from index: {err}");
(
StatusCode::INTERNAL_SERVER_ERROR,
Html(
StatusCode::INTERNAL_SERVER_ERROR
.canonical_reason()
.unwrap_or_default()
.to_string(),
),
)
.into_response()
html_status(StatusCode::INTERNAL_SERVER_ERROR).into_response()
}
}
}
Expand All @@ -292,16 +290,7 @@ impl Server {
Ok(blocktime) => OrdinalHtml { ordinal, blocktime }.page().into_response(),
Err(err) => {
eprintln!("Failed to retrieve blocktime from index: {err}");
(
StatusCode::INTERNAL_SERVER_ERROR,
Html(
StatusCode::INTERNAL_SERVER_ERROR
.canonical_reason()
.unwrap_or_default()
.to_string(),
),
)
.into_response()
html_status(StatusCode::INTERNAL_SERVER_ERROR).into_response()
}
}
}
Expand Down Expand Up @@ -357,16 +346,7 @@ impl Server {
Ok(blocks) => HomeHtml::new(blocks).page().into_response(),
Err(err) => {
eprintln!("Error getting blocks: {err}");
(
StatusCode::INTERNAL_SERVER_ERROR,
Html(
StatusCode::INTERNAL_SERVER_ERROR
.canonical_reason()
.unwrap_or_default()
.to_string(),
),
)
.into_response()
html_status(StatusCode::INTERNAL_SERVER_ERROR).into_response()
}
}
}
Expand Down Expand Up @@ -420,16 +400,7 @@ impl Server {
.into_response(),
Err(error) => {
eprintln!("Error serving request for block with hash {hash}: {error}");
(
StatusCode::INTERNAL_SERVER_ERROR,
Html(
StatusCode::INTERNAL_SERVER_ERROR
.canonical_reason()
.unwrap_or_default()
.to_string(),
),
)
.into_response()
html_status(StatusCode::INTERNAL_SERVER_ERROR).into_response()
}
}
}
Expand All @@ -443,28 +414,10 @@ impl Server {
Ok(Some(transaction)) => TransactionHtml::new(transaction, network.0)
.page()
.into_response(),
Ok(None) => (
StatusCode::NOT_FOUND,
Html(
StatusCode::NOT_FOUND
.canonical_reason()
.unwrap_or_default()
.to_string(),
),
)
.into_response(),
Ok(None) => html_status(StatusCode::NOT_FOUND).into_response(),
Err(error) => {
eprintln!("Error serving request for transaction with txid {txid}: {error}");
(
StatusCode::INTERNAL_SERVER_ERROR,
Html(
StatusCode::INTERNAL_SERVER_ERROR
.canonical_reason()
.unwrap_or_default()
.to_string(),
),
)
.into_response()
html_status(StatusCode::INTERNAL_SERVER_ERROR).into_response()
}
}
}
Expand Down Expand Up @@ -976,7 +929,7 @@ mod tests {
TestServer::new().assert_response_regex(
"/range/0/1",
StatusCode::OK,
r".*<title>Ordinal range \[0,1\)</title>.*<h1>Ordinal range \[0,1\)</h1>
r".*<title>Ordinal range 0–1</title>.*<h1>Ordinal range 0–1</h1>
<dl>
<dt>value</dt><dd>1</dd>
<dt>first</dt><dd><a href=/ordinal/0 class=mythic>0</a></dd>
Expand Down Expand Up @@ -1055,7 +1008,7 @@ mod tests {
</dl>
<h2>1 Ordinal Range</h2>
<ul class=monospace>
<li><a href=/range/0/5000000000 class=mythic>\\[0,5000000000\\)</a></li>
<li><a href=/range/0/5000000000 class=mythic>0–5000000000</a></li>
</ul>.*",
);
}
Expand Down Expand Up @@ -1090,7 +1043,12 @@ mod tests {
".*<title>Ordinals</title>.*<h1>Ordinals</h1>
<nav>.*</nav>
.*
<h2>Recent Blocks</h2>
<h2>Latest Blocks</h2>
<dl>
<dt>cycle</dt><dd>0</dd>
<dt>epoch</dt><dd>0</dd>
<dt>period</dt><dd>0</dd>
</dl>
<ol start=1 reversed class='blocks monospace'>
<li><a href=/block/[[:xdigit:]]{64} class=uncommon>[[:xdigit:]]{64}</a></li>
<li><a href=/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f class=mythic>000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f</a></li>
Expand All @@ -1102,12 +1060,12 @@ mod tests {
fn home_block_limit() {
let test_server = TestServer::new();

test_server.bitcoin_rpc_server.mine_blocks(200);
test_server.bitcoin_rpc_server.mine_blocks(101);

test_server.assert_response_regex(
"/",
StatusCode::OK,
".*<ol start=200 reversed class='blocks monospace'>\n( <li><a href=/block/[[:xdigit:]]{64} class=uncommon>[[:xdigit:]]{64}</a></li>\n){100}</ol>.*"
".*<ol start=101 reversed class='blocks monospace'>\n( <li><a href=/block/[[:xdigit:]]{64} class=uncommon>[[:xdigit:]]{64}</a></li>\n){100}</ol>.*"
);
}

Expand Down
19 changes: 14 additions & 5 deletions src/subcommand/server/templates/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ use super::*;
pub(crate) struct HomeHtml {
last: u64,
blocks: Vec<(Rarity, BlockHash)>,
starting_ordinal: Option<Ordinal>,
}

impl HomeHtml {
pub(crate) fn new(blocks: Vec<(u64, BlockHash)>) -> Self {
Self {
starting_ordinal: blocks
.get(0)
.map(|(height, _)| Height(*height).starting_ordinal()),
last: blocks
.get(0)
.map(|(height, _)| height)
Expand Down Expand Up @@ -37,13 +41,13 @@ mod tests {
assert_regex_match!(
&HomeHtml::new(vec![
(
1,
1260001,
"1111111111111111111111111111111111111111111111111111111111111111"
.parse()
.unwrap()
),
(
0,
1260000,
"0000000000000000000000000000000000000000000000000000000000000000"
.parse()
.unwrap()
Expand All @@ -54,10 +58,15 @@ mod tests {
<nav>.*</nav>
<h2>Search</h2>
<form action=/search method=get>.*</form>
<h2>Recent Blocks</h2>
<ol start=1 reversed class='blocks monospace'>
<h2>Latest Blocks</h2>
<dl>
<dt>cycle</dt><dd>1</dd>
<dt>epoch</dt><dd>6</dd>
<dt>period</dt><dd>625</dd>
</dl>
<ol start=1260001 reversed class='blocks monospace'>
<li><a href=/block/1{64} class=uncommon>1{64}</a></li>
<li><a href=/block/0{64} class=mythic>0{64}</a></li>
<li><a href=/block/0{64} class=legendary>0{64}</a></li>
</ol>
",
);
Expand Down
Loading

0 comments on commit c7bc207

Please sign in to comment.