Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sat instead of satoshi throughout codebase #1184

Merged
merged 4 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl Index {
}
}

fn require_satoshi_index(&self, feature: &str) -> Result {
fn require_sat_index(&self, feature: &str) -> Result {
if !self.has_sat_index()? {
bail!("{feature} requires index created with `--index-sats` flag")
}
Expand Down Expand Up @@ -572,7 +572,7 @@ impl Index {
}

pub(crate) fn find(&self, sat: u64) -> Result<Option<SatPoint>> {
self.require_satoshi_index("find")?;
self.require_sat_index("find")?;

let rtx = self.begin_read()?;

Expand Down Expand Up @@ -612,7 +612,7 @@ impl Index {
}

pub(crate) fn list(&self, outpoint: OutPoint) -> Result<Option<List>> {
self.require_satoshi_index("list")?;
self.require_sat_index("list")?;

let outpoint_encoded = encode_outpoint(outpoint);

Expand Down Expand Up @@ -1237,7 +1237,7 @@ mod tests {
}

#[test]
fn find_first_satoshi_spent_in_second_block() {
fn find_first_sat_spent_in_second_block() {
let context = Context::builder().arg("--index-sats").build();
context.mine_blocks(1);
let spend_txid = context.rpc_server.broadcast_tx(TransactionTemplate {
Expand Down
10 changes: 5 additions & 5 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ mod tests {
}

#[test]
fn output_with_satoshi_index() {
fn output_with_sat_index() {
TestServer::new_with_args(&["--index-sats"]).assert_response_regex(
"/output/4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0",
StatusCode::OK,
Expand All @@ -1175,7 +1175,7 @@ mod tests {
}

#[test]
fn output_without_satoshi_index() {
fn output_without_sat_index() {
TestServer::new().assert_response_regex(
"/output/4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0",
StatusCode::OK,
Expand Down Expand Up @@ -1410,7 +1410,7 @@ next.*",
}

#[test]
fn rare_without_satoshi_index() {
fn rare_without_sat_index() {
TestServer::new_with_args(&[]).assert_response(
"/rare.txt",
StatusCode::NOT_FOUND,
Expand All @@ -1419,7 +1419,7 @@ next.*",
}

#[test]
fn show_rare_txt_in_header_with_satoshi_index() {
fn show_rare_txt_in_header_with_sat_index() {
TestServer::new_with_args(&["--index-sats"]).assert_response_regex(
"/",
StatusCode::OK,
Expand All @@ -1440,7 +1440,7 @@ next.*",
}

#[test]
fn dont_show_rare_txt_in_header_without_satoshi_index() {
fn dont_show_rare_txt_in_header_without_sat_index() {
TestServer::new().assert_response_regex(
"/",
StatusCode::OK,
Expand Down
40 changes: 20 additions & 20 deletions src/subcommand/wallet/sats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ impl Sats {
let utxos = get_unspent_output_ranges(&options, &index)?;

if let Some(path) = &self.tsv {
for (output, sat) in satoshis_from_tsv(
for (output, sat) in sats_from_tsv(
utxos,
&fs::read_to_string(path)
.with_context(|| format!("I/O error reading `{}`", path.display()))?,
)? {
println!("{output}\t{sat}");
}
} else {
for (output, sat, offset, rarity) in rare_satoshis(utxos) {
for (output, sat, offset, rarity) in rare_sats(utxos) {
println!("{output}\t{sat}\t{offset}\t{rarity}");
}
}
Expand All @@ -34,7 +34,7 @@ impl Sats {
}
}

fn rare_satoshis(utxos: Vec<(OutPoint, Vec<(u64, u64)>)>) -> Vec<(OutPoint, Sat, u64, Rarity)> {
fn rare_sats(utxos: Vec<(OutPoint, Vec<(u64, u64)>)>) -> Vec<(OutPoint, Sat, u64, Rarity)> {
utxos
.into_iter()
.flat_map(|(outpoint, sat_ranges)| {
Expand All @@ -54,7 +54,7 @@ fn rare_satoshis(utxos: Vec<(OutPoint, Vec<(u64, u64)>)>) -> Vec<(OutPoint, Sat,
.collect()
}

fn satoshis_from_tsv(
fn sats_from_tsv(
utxos: Vec<(OutPoint, Vec<(u64, u64)>)>,
tsv: &str,
) -> Result<Vec<(OutPoint, &str)>> {
Expand Down Expand Up @@ -115,7 +115,7 @@ mod tests {
#[test]
fn identify_no_rare_sats() {
assert_eq!(
rare_satoshis(vec![(
rare_sats(vec![(
outpoint(1),
vec![(51 * COIN_VALUE, 100 * COIN_VALUE), (1234, 5678)],
)]),
Expand All @@ -126,7 +126,7 @@ mod tests {
#[test]
fn identify_one_rare_sat() {
assert_eq!(
rare_satoshis(vec![(
rare_sats(vec![(
outpoint(1),
vec![(10, 80), (50 * COIN_VALUE, 100 * COIN_VALUE)],
)]),
Expand All @@ -137,7 +137,7 @@ mod tests {
#[test]
fn identify_two_rare_sats() {
assert_eq!(
rare_satoshis(vec![(
rare_sats(vec![(
outpoint(1),
vec![(0, 100), (1050000000000000, 1150000000000000)],
)]),
Expand All @@ -151,7 +151,7 @@ mod tests {
#[test]
fn identify_rare_sats_in_different_outpoints() {
assert_eq!(
rare_satoshis(vec![
rare_sats(vec![
(outpoint(1), vec![(50 * COIN_VALUE, 55 * COIN_VALUE)]),
(outpoint(2), vec![(100 * COIN_VALUE, 111 * COIN_VALUE)],),
]),
Expand All @@ -165,55 +165,55 @@ mod tests {
#[test]
fn identify_from_tsv_none() {
assert_eq!(
satoshis_from_tsv(vec![(outpoint(1), vec![(0, 1)])], "1\n").unwrap(),
sats_from_tsv(vec![(outpoint(1), vec![(0, 1)])], "1\n").unwrap(),
vec![]
)
}

#[test]
fn identify_from_tsv_single() {
assert_eq!(
satoshis_from_tsv(vec![(outpoint(1), vec![(0, 1)])], "0\n").unwrap(),
sats_from_tsv(vec![(outpoint(1), vec![(0, 1)])], "0\n").unwrap(),
vec![(outpoint(1), "0"),]
)
}

#[test]
fn identify_from_tsv_two_in_one_range() {
assert_eq!(
satoshis_from_tsv(vec![(outpoint(1), vec![(0, 2)])], "0\n1\n").unwrap(),
sats_from_tsv(vec![(outpoint(1), vec![(0, 2)])], "0\n1\n").unwrap(),
vec![(outpoint(1), "0"), (outpoint(1), "1"),]
)
}

#[test]
fn identify_from_tsv_out_of_order_tsv() {
assert_eq!(
satoshis_from_tsv(vec![(outpoint(1), vec![(0, 2)])], "1\n0\n").unwrap(),
sats_from_tsv(vec![(outpoint(1), vec![(0, 2)])], "1\n0\n").unwrap(),
vec![(outpoint(1), "0"), (outpoint(1), "1"),]
)
}

#[test]
fn identify_from_tsv_out_of_order_ranges() {
assert_eq!(
satoshis_from_tsv(vec![(outpoint(1), vec![(1, 2), (0, 1)])], "1\n0\n").unwrap(),
sats_from_tsv(vec![(outpoint(1), vec![(1, 2), (0, 1)])], "1\n0\n").unwrap(),
vec![(outpoint(1), "0"), (outpoint(1), "1"),]
)
}

#[test]
fn identify_from_tsv_two_in_two_ranges() {
assert_eq!(
satoshis_from_tsv(vec![(outpoint(1), vec![(0, 1), (1, 2)])], "0\n1\n").unwrap(),
sats_from_tsv(vec![(outpoint(1), vec![(0, 1), (1, 2)])], "0\n1\n").unwrap(),
vec![(outpoint(1), "0"), (outpoint(1), "1"),]
)
}

#[test]
fn identify_from_tsv_two_in_two_outputs() {
assert_eq!(
satoshis_from_tsv(
sats_from_tsv(
vec![(outpoint(1), vec![(0, 1)]), (outpoint(2), vec![(1, 2)])],
"0\n1\n"
)
Expand All @@ -225,31 +225,31 @@ mod tests {
#[test]
fn identify_from_tsv_ignores_extra_columns() {
assert_eq!(
satoshis_from_tsv(vec![(outpoint(1), vec![(0, 1)])], "0\t===\n").unwrap(),
sats_from_tsv(vec![(outpoint(1), vec![(0, 1)])], "0\t===\n").unwrap(),
vec![(outpoint(1), "0"),]
)
}

#[test]
fn identify_from_tsv_ignores_empty_lines() {
assert_eq!(
satoshis_from_tsv(vec![(outpoint(1), vec![(0, 1)])], "0\n\n\n").unwrap(),
sats_from_tsv(vec![(outpoint(1), vec![(0, 1)])], "0\n\n\n").unwrap(),
vec![(outpoint(1), "0"),]
)
}

#[test]
fn identify_from_tsv_ignores_comments() {
assert_eq!(
satoshis_from_tsv(vec![(outpoint(1), vec![(0, 1)])], "0\n#===\n").unwrap(),
sats_from_tsv(vec![(outpoint(1), vec![(0, 1)])], "0\n#===\n").unwrap(),
vec![(outpoint(1), "0"),]
)
}

#[test]
fn parse_error_reports_line_and_value() {
assert_eq!(
satoshis_from_tsv(vec![(outpoint(1), vec![(0, 1)])], "0\n===\n")
sats_from_tsv(vec![(outpoint(1), vec![(0, 1)])], "0\n===\n")
.unwrap_err()
.to_string(),
"failed to parse sat from string \"===\" on line 2: invalid digit found in string",
Expand Down Expand Up @@ -282,7 +282,7 @@ mod tests {

let start = Instant::now();
assert_eq!(
satoshis_from_tsv(utxos, &tsv)
sats_from_tsv(utxos, &tsv)
.unwrap()
.into_iter()
.map(|(outpoint, s)| (outpoint, s.parse().unwrap()))
Expand Down
12 changes: 6 additions & 6 deletions src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ mod transaction;
pub(crate) struct PageHtml<T: PageContent> {
chain: Chain,
content: T,
has_satoshi_index: bool,
has_sat_index: bool,
}

impl<T> PageHtml<T>
where
T: PageContent,
{
pub(crate) fn new(content: T, chain: Chain, has_satoshi_index: bool) -> Self {
pub(crate) fn new(content: T, chain: Chain, has_sat_index: bool) -> Self {
Self {
content,
has_satoshi_index,
has_sat_index,
chain,
}
}
Expand All @@ -47,11 +47,11 @@ where
pub(crate) trait PageContent: Display + 'static {
fn title(&self) -> String;

fn page(self, chain: Chain, has_satoshi_index: bool) -> PageHtml<Self>
fn page(self, chain: Chain, has_sat_index: bool) -> PageHtml<Self>
where
Self: Sized,
{
PageHtml::new(self, chain, has_satoshi_index)
PageHtml::new(self, chain, has_sat_index)
}

fn preview_image_url(&self) -> Option<Trusted<String>> {
Expand Down Expand Up @@ -114,7 +114,7 @@ mod tests {
}

#[test]
fn page_no_satoshi_index() {
fn page_no_sat_index() {
struct Foo;

impl Display for Foo {
Expand Down
2 changes: 1 addition & 1 deletion templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<a href=https://docs.ordinals.com/>Handbook</a>
<a href=https://github.com/casey/ord>GitHub</a>
<a href=/clock>Clock</a>
%% if self.has_satoshi_index {
%% if self.has_sat_index {
<a href=/rare.txt>rare.txt</a>
%% }
<form action=/search method=get>
Expand Down