Skip to content

Commit

Permalink
Merge branch 'master' into output_recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
1stBitcoinSent authored Nov 22, 2024
2 parents 72e369e + 79f7c8e commit 76d08f0
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 59 deletions.
15 changes: 15 additions & 0 deletions bin/replicate
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -euxo pipefail

systemctl stop ord

for host in alpha bravo; do
rsync \
--archive \
--progress \
/var/lib/ord/index.redb \
root@$host.ordinals.net:/var/lib/ord/index.redb.new
done

systemctl restart ord
25 changes: 25 additions & 0 deletions bin/swap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

set -euxo pipefail

die() {
echo "$1"
exit 1
}

new=/var/lib/ord/index.redb.new
current=/var/lib/ord/index.redb
old=/var/lib/ord/index.redb.old

[[ -f $new ]] || die "new index missing: $new"
[[ -f $current ]] || die "old index missing: $current"
[[ ! -f $old ]] || die "backup index already exists: $old"

systemctl stop ord

chown ord:ord $new

mv $current $old
mv $new $current

systemctl restart ord
59 changes: 20 additions & 39 deletions docs/theme/index.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE HTML>
<html lang="{{ language }}" class="{{ default_theme }}" dir="{{ text_direction }}">
<html lang="{{ language }}" class="{{ default_theme }} sidebar-visible" dir="{{ text_direction }}">
<head>
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
Expand Down Expand Up @@ -52,15 +52,17 @@
<!-- MathJax -->
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
{{/if}}
</head>
<body class="sidebar-visible no-js">
<div id="body-container">

<!-- Provide site root to javascript -->
<script>
var path_to_root = "{{ path_to_root }}";
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "{{ preferred_dark_theme }}" : "{{ default_theme }}";
</script>

<!-- Start loading toc.js asap -->
<script src="{{ path_to_root }}toc.js"></script>
</head>
<body>
<div id="body-container">
<!-- Work around some values being stored in localStorage wrapped in quotes -->
<script>
try {
Expand All @@ -82,19 +84,16 @@
var theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
var html = document.querySelector('html');
const html = document.documentElement;
html.classList.remove('{{ default_theme }}')
html.classList.add(theme);
var body = document.querySelector('body');
body.classList.remove('no-js')
body.classList.add('js');
html.classList.add("js");
</script>

<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">

<!-- Hide / unhide sidebar before it is displayed -->
<script>
var body = document.querySelector('body');
var sidebar = null;
var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
if (document.body.clientWidth >= 1080) {
Expand All @@ -104,39 +103,21 @@
sidebar = 'hidden';
}
sidebar_toggle.checked = sidebar === 'visible';
body.classList.remove('sidebar-visible');
body.classList.add("sidebar-" + sidebar);
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
</script>

<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<div class="sidebar-scrollbox">
{{#toc}}{{/toc}}
<!-- populated by js -->
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
<noscript>
<iframe class="sidebar-iframe-outer" src="{{ path_to_root }}toc.html"></iframe>
</noscript>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
</div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
</nav>

<!-- Track and set sidebar scroll position -->
<script>
var sidebarScrollbox = document.querySelector('#sidebar .sidebar-scrollbox');
sidebarScrollbox.addEventListener('click', function(e) {
if (e.target.tagName === 'A') {
sessionStorage.setItem('sidebar-scroll', sidebarScrollbox.scrollTop);
}
}, { passive: true });
var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll');
sessionStorage.removeItem('sidebar-scroll');
if (sidebarScrollTop) {
// preserve sidebar scroll position when navigating via links within sidebar
sidebarScrollbox.scrollTop = sidebarScrollTop;
} else {
// scroll sidebar to current active section when navigating via "next/previous chapter" buttons
var activeSection = document.querySelector('#sidebar .active');
if (activeSection) {
activeSection.scrollIntoView({ block: 'center' });
}
}
</script>

<div id="page-wrapper" class="page-wrapper">

<div class="page">
Expand Down Expand Up @@ -165,7 +146,6 @@
</div>

<h1 class="menu-title">{{ book_title }}</h1>

<div class="right-buttons">
<button id="language-toggle" class="icon-button" type="button"
title="Change language" aria-label="Change language"
Expand Down Expand Up @@ -228,7 +208,6 @@
if (selectedLang) {
selectedLang.parentNode.classList.add("theme-selected");
}
// The path to the root, taking the current
// language into account.
{{#if (eq language "en")}}
Expand All @@ -248,6 +227,8 @@
}
</script>



{{#if print_enable}}
<a href="{{ path_to_root }}print.html" title="Print this book" aria-label="Print this book">
<i id="print-button" class="fa fa-print"></i>
Expand Down
8 changes: 8 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,11 @@ benchmark-server:

update-contributors:
cargo run --release --package update-contributors

replicate:
rsync --archive bin/replicate root@charlie.ordinals.net:replicate
ssh root@charlie.ordinals.net ./replicate

swap host:
rsync --archive bin/swap root@{{ host }}.ordinals.net:swap
ssh root@{{ host }}.ordinals.net ./swap
2 changes: 2 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub struct Inscription {
pub satpoint: SatPoint,
pub timestamp: i64,
pub value: Option<u64>,
pub metaprotocol: Option<String>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -195,6 +196,7 @@ impl Output {

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Sat {
pub address: Option<String>,
pub block: u32,
pub charms: Vec<Charm>,
pub cycle: u32,
Expand Down
1 change: 1 addition & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,7 @@ impl Index {
satpoint,
timestamp: timestamp(entry.timestamp.into()).timestamp(),
value: output.as_ref().map(|o| o.value.to_sat()),
metaprotocol: inscription.metaprotocol().map(|s| s.to_string()),
},
output,
inscription,
Expand Down
9 changes: 3 additions & 6 deletions src/inscriptions/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ impl Inscription {
bytes
}

pub(crate) fn append_reveal_script_to_builder(
&self,
mut builder: script::Builder,
) -> script::Builder {
pub fn append_reveal_script_to_builder(&self, mut builder: script::Builder) -> script::Builder {
builder = builder
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
Expand Down Expand Up @@ -149,7 +146,7 @@ impl Inscription {
self.append_reveal_script_to_builder(builder).into_script()
}

pub(crate) fn append_batch_reveal_script_to_builder(
pub fn append_batch_reveal_script_to_builder(
inscriptions: &[Inscription],
mut builder: script::Builder,
) -> script::Builder {
Expand All @@ -160,7 +157,7 @@ impl Inscription {
builder
}

pub(crate) fn append_batch_reveal_script(
pub fn append_batch_reveal_script(
inscriptions: &[Inscription],
builder: script::Builder,
) -> ScriptBuf {
Expand Down
44 changes: 34 additions & 10 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,31 +571,55 @@ impl Server {

let charms = sat.charms();

let address = if let Some(satpoint) = satpoint {
if satpoint.outpoint == unbound_outpoint() {
None
} else {
let tx = index
.get_transaction(satpoint.outpoint.txid)?
.context("could not get transaction for sat")?;

let tx_out = tx
.output
.get::<usize>(satpoint.outpoint.vout.try_into().unwrap())
.context("could not get vout for sat")?;

server_config
.chain
.address_from_script(&tx_out.script_pubkey)
.ok()
}
} else {
None
};

Ok(if accept_json {
Json(api::Sat {
number: sat.0,
decimal: sat.decimal().to_string(),
degree: sat.degree().to_string(),
name: sat.name(),
address: address.map(|address| address.to_string()),
block: sat.height().0,
charms: Charm::charms(charms),
cycle: sat.cycle(),
decimal: sat.decimal().to_string(),
degree: sat.degree().to_string(),
epoch: sat.epoch().0,
period: sat.period(),
inscriptions,
name: sat.name(),
number: sat.0,
offset: sat.third(),
rarity: sat.rarity(),
percentile: sat.percentile(),
period: sat.period(),
rarity: sat.rarity(),
satpoint,
timestamp: blocktime.timestamp().timestamp(),
inscriptions,
charms: Charm::charms(charms),
})
.into_response()
} else {
SatHtml {
sat,
satpoint,
address,
blocktime,
inscriptions,
sat,
satpoint,
}
.page(server_config)
.into_response()
Expand Down
22 changes: 22 additions & 0 deletions src/templates/sat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;

#[derive(Boilerplate)]
pub(crate) struct SatHtml {
pub(crate) address: Option<Address>,
pub(crate) blocktime: Blocktime,
pub(crate) inscriptions: Vec<InscriptionId>,
pub(crate) sat: Sat,
Expand All @@ -22,6 +23,7 @@ mod tests {
fn first() {
assert_regex_match!(
SatHtml {
address: None,
sat: Sat(0),
satpoint: None,
blocktime: Blocktime::confirmed(0),
Expand Down Expand Up @@ -61,6 +63,7 @@ mod tests {
fn last() {
assert_regex_match!(
SatHtml {
address: None,
sat: Sat(2099999997689999),
satpoint: None,
blocktime: Blocktime::confirmed(0),
Expand Down Expand Up @@ -98,6 +101,7 @@ mod tests {
fn sat_with_next_and_prev() {
assert_regex_match!(
SatHtml {
address: None,
sat: Sat(1),
satpoint: None,
blocktime: Blocktime::confirmed(0),
Expand All @@ -111,6 +115,7 @@ mod tests {
fn sat_with_inscription() {
assert_regex_match!(
SatHtml {
address: None,
sat: Sat(0),
satpoint: None,
blocktime: Blocktime::confirmed(0),
Expand All @@ -132,6 +137,7 @@ mod tests {
fn sat_with_reinscription() {
assert_regex_match!(
SatHtml {
address: None,
sat: Sat(0),
satpoint: None,
blocktime: Blocktime::confirmed(0),
Expand All @@ -154,6 +160,7 @@ mod tests {
fn last_sat_next_link_is_disabled() {
assert_regex_match!(
SatHtml {
address: None,
sat: Sat::LAST,
satpoint: None,
blocktime: Blocktime::confirmed(0),
Expand All @@ -167,6 +174,7 @@ mod tests {
fn sat_with_satpoint() {
assert_regex_match!(
SatHtml {
address: None,
sat: Sat(0),
satpoint: Some(satpoint(1, 0)),
blocktime: Blocktime::confirmed(0),
Expand All @@ -175,4 +183,18 @@ mod tests {
"<h1>Sat 0</h1>.*<dt>location</dt><dd><a class=collapse href=/satpoint/1{64}:1:0>1{64}:1:0</a></dd>.*",
);
}

#[test]
fn sat_with_address() {
assert_regex_match!(
SatHtml {
address: Some(address(0)),
sat: Sat(0),
satpoint: Some(satpoint(1, 0)),
blocktime: Blocktime::confirmed(0),
inscriptions: Vec::new(),
},
"<h1>Sat 0</h1>.*<dt>address</dt><dd class=monospace><a href=/address/bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4>bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4</a></dd>.*",
);
}
}
2 changes: 1 addition & 1 deletion src/wallet/batch/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl File {
if sat_or_satpoint {
ensure!(
batchfile.mode == Mode::SameSat,
"neither `sat` nor `satpoint` can be set in `same-sat` mode",
"`sat` or `satpoint` can only be set in `same-sat` mode",
);
}

Expand Down
Loading

0 comments on commit 76d08f0

Please sign in to comment.