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

Overhaul traits #255

Merged
merged 5 commits into from
Jul 19, 2022
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
20 changes: 0 additions & 20 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ dirs = "4.0.0"
env_logger = "0.9.0"
executable-path = "1.0.0"
http = "0.2.6"
integer-cbrt = "0.1.2"
integer-sqrt = "0.1.5"
jsonrpc = "0.12.1"
lazy_static = "1.4.0"
log = "0.4.14"
Expand Down
18 changes: 9 additions & 9 deletions docs/bounties/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ <h1>Ordinal Bounties</h1>
<th>Address</th>
</tr>
<tr>
<td>Legendary</td>
<td>Epic</td>
<td>3</td>
<td>1</td>
<td>1 BTC</td>
<td>1PE7u4wbDP2RqfKN6geD1bG57v9Gj9FXm3</td>
</tr>
<tr>
<td>Epic</td>
<td>Rare</td>
<td>360</td>
<td>10</td>
<td>0.01 BTC</td>
<td>145Z7PFHyVrwiMWwEcUmDgFbmUbQSU9aap</td>
</tr>
<tr>
<td>Rare</td>
<td>Uncommon</td>
<td>~730,000</td>
<td>100</td>
<td>0.001 BTC</td>
<td>1Hyr94uypwWq5CQffaXHvwUMEyBPp3TUZH</td>
</tr>
<tr>
<td>Illusive</td>
<td>Elusive</td>
<td>1</td>
<td>1</td>
<td>0.1 BTC</td>
Expand Down Expand Up @@ -75,13 +75,13 @@ <h1>Ordinal Bounties</h1>
<section>
<h2>Definitions</h2>

<p>A <dfn>legendary</dfn> satoshi is the first satoshi mined in the first block after a halving. They are <em>exceedingly</em> rare. Three have been mined, and there is one legendary sat per 6,336,854 BTC in circulation.</p>
<p>An <dfn>epic</dfn> satoshi is the first satoshi mined in the first block after a halving. They are <em>exceedingly</em> rare. Three have been mined, and there is one epic sat per 6,336,854 BTC in circulation.</p>

<p>An <dfn>epic</dfn> satoshi is the first satoshi mined in the first block after a difficulty adjustment period. They are <em>very</em> rare. 361 have been mined, and there is one epic sat per 52,423 BTC in circulation.</p>
<p>A <dfn>rare</dfn> satoshi is the first satoshi mined in the first block after a difficulty adjustment period. They are <em>very</em> rare. 361 have been mined, and there is one epic sat per 52,423 BTC in circulation.</p>

<p>A <dfn>rare</dfn> satoshi is the first satoshi mined in every block. They are moderately rare. More than 730,000 have been mined, and there is one rare sat per 26 BTC in circulation.</p>
<p>An <dfn>uncommon</dfn> satoshi is the first satoshi mined in every block. They are moderately rare. More than 730,000 have been mined, and there is one rare sat per 26 BTC in circulation.</p>

<p>There is only one <dfn>illusive</dfn> satoshi, that with ordinal number 623624999999999. Why is left as an exercise to the reader.</p>
<p>There is only one <dfn>elusive</dfn> satoshi, that with ordinal number 623624999999999. Why is left as an exercise to the reader.</p>

<p>All sats mined in block 124724 are <dfn>cursed</dfn>. Again, figuring out why is left as an exercise to the reader.</p>

Expand Down Expand Up @@ -122,7 +122,7 @@ <h2>Hints</h2>

<li>Satoshi was the oridinal developer of ordinal theory. However, he knew that others would consider it heretical and dangerous, so he hid his knowledge, and it was lost to the sands of time. This potent theory is only now being rediscovered. You can help by researching rare ordinals.</li>

<li>The three legendary ordinals mined so far are:
<li>The three epic ordinals mined so far are:
<table>
<tr>
<th>Reward Era</th>
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ use {
chrono::{DateTime, NaiveDateTime, Utc},
clap::Parser,
derive_more::{Display, FromStr},
integer_cbrt::IntegerCubeRoot,
integer_sqrt::IntegerSquareRoot,
lazy_static::lazy_static,
qrcode_generator::QrCodeEcc,
redb::{Database, ReadableTable, Table, TableDefinition, WriteTransaction},
Expand Down Expand Up @@ -47,6 +45,9 @@ use {
tower_http::cors::{Any, CorsLayer},
};

const PERIOD_BLOCKS: u64 = 2016;
const CYCLE_EPOCHS: u64 = 6;

mod arguments;
mod bytes;
mod epoch;
Expand Down
39 changes: 19 additions & 20 deletions src/ordinal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ impl Ordinal {
self.epoch().starting_height() + self.epoch_position() / self.epoch().subsidy()
}

pub(crate) fn cycle(self) -> u64 {
Epoch::from(self).0 / CYCLE_EPOCHS
}

pub(crate) fn epoch(self) -> Epoch {
self.into()
}

pub(crate) fn period(self) -> u64 {
self.0 / PERIOD_BLOCKS
}

pub(crate) fn subsidy_position(self) -> u64 {
self.epoch_position() % self.epoch().subsidy()
}
Expand All @@ -44,16 +52,6 @@ impl Ordinal {
}
name.chars().rev().collect()
}

pub(crate) fn population(self) -> u64 {
let mut n = self.0;
let mut population = 0;
while n > 0 {
population += n & 1;
n >>= 1;
}
population
}
}

impl PartialEq<u64> for Ordinal {
Expand Down Expand Up @@ -104,16 +102,6 @@ mod tests {
assert_eq!(Ordinal(2099999997689999).name(), "a");
}

#[test]
fn population() {
assert_eq!(Ordinal(0).population(), 0);
assert_eq!(Ordinal(1).population(), 1);
assert_eq!(
Ordinal(0b11111111111111111111111111111111111111111111111111).population(),
50
);
}

#[test]
fn epoch() {
assert_eq!(Ordinal(0).epoch(), 0);
Expand Down Expand Up @@ -194,4 +182,15 @@ mod tests {
assert_eq!("0".parse::<Ordinal>().unwrap(), 0);
assert!("foo".parse::<Ordinal>().is_err());
}

#[test]
fn cycle() {
assert_eq!(Epoch::BLOCKS * CYCLE_EPOCHS % PERIOD_BLOCKS, 0);

for i in 1..CYCLE_EPOCHS {
assert_ne!(i * Epoch::BLOCKS % PERIOD_BLOCKS, 0);
}

assert_eq!(CYCLE_EPOCHS * Epoch::BLOCKS % PERIOD_BLOCKS, 0);
}
}
77 changes: 23 additions & 54 deletions src/subcommand/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,70 +11,39 @@ impl Traits {
return Err(anyhow!("Invalid ordinal"));
}

let n = self.ordinal.n();

if n % 2 == 0 {
println!("even");
} else {
println!("odd");
}

let isqrt = n.integer_sqrt();
if isqrt * isqrt == n {
println!("square");
}

let icbrt = n.integer_cbrt();
if icbrt * icbrt * icbrt == n {
println!("cube");
}

let digits = n.to_string().chars().collect::<Vec<char>>();

let pi = std::f64::consts::PI.to_string().replace('.', "");
let s = n.to_string();
if s == pi[..s.len()] {
println!("pi");
}

if digits.chunks(2).all(|chunk| chunk == ['6', '9']) {
println!("nice");
}

if digits.iter().all(|c| *c == '7') {
println!("angelic");
}

println!(
"luck: {}/{}",
digits.iter().filter(|c| **c == '8').count() as i64
- digits.iter().filter(|c| **c == '4').count() as i64,
digits.len()
);

println!("population: {}", self.ordinal.population());

println!("name: {}", self.ordinal.name());

if let Some(character) = char::from_u32((n % 0x110000) as u32) {
println!("character: {:?}", character);
}
println!("cycle: {}", self.ordinal.cycle());

println!("epoch: {}", self.ordinal.epoch());

println!("height: {}", self.ordinal.height());

if self.ordinal.subsidy_position() == 0 {
println!("shiny");
}
println!("period: {}", self.ordinal.period());

println!("offset: {}", self.ordinal.subsidy_position());

let height = self.ordinal.height().n();
let c = height / (CYCLE_EPOCHS * Epoch::BLOCKS);
let e = height % Epoch::BLOCKS;
let p = height % PERIOD_BLOCKS;
let o = self.ordinal.subsidy_position();
println!("degree: {c}°{e}′{p}″{o}‴");

if self.ordinal.height() == 124724 {
if self.ordinal == 623624999999999 {
println!("illusive");
println!(
"rarity: {}",
if o == 0 && p == 0 && e == 0 {
"legendary"
} else if o == 0 && e == 0 {
"epic"
} else if o == 0 && p == 0 {
"rare"
} else if o == 0 {
"uncommon"
} else {
println!("cursed");
"common"
}
}
);

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use {
},
regex::Regex,
std::{
collections::BTreeSet,
collections::BTreeMap,
error::Error,
fs,
net::TcpListener,
Expand Down
Loading