forked from ordinals/ord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
553 additions
and
198 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,49 @@ | ||
use super::*; | ||
|
||
pub(crate) fn run(blocksdir: Option<&Path>, ordinal: Ordinal, at_height: u64) -> Result<()> { | ||
let index = Index::new(blocksdir)?; | ||
#[derive(StructOpt)] | ||
pub(crate) struct Find { | ||
#[structopt(long)] | ||
blocksdir: Option<PathBuf>, | ||
#[structopt(long)] | ||
as_of_height: u64, | ||
#[structopt(long)] | ||
slot: bool, | ||
ordinal: Ordinal, | ||
} | ||
|
||
impl Find { | ||
pub(crate) fn run(self) -> Result<()> { | ||
let index = Index::new(self.blocksdir.as_deref())?; | ||
|
||
let height = ordinal.height().n(); | ||
assert!(height < 100); | ||
assert!(height == at_height); | ||
let creation_height = self.ordinal.height().n(); | ||
let block = index.block(creation_height)?.unwrap(); | ||
|
||
let block = index.block(height)?; | ||
let offset = self.ordinal.subsidy_position(); | ||
let mut satpoint = SatPoint::from_transaction_and_offset(&block.txdata[0], offset); | ||
let mut slot = (creation_height, 0, satpoint.outpoint.vout, offset); | ||
|
||
let mut offset = ordinal.subsidy_position(); | ||
for (index, output) in block.txdata[0].output.iter().enumerate() { | ||
if output.value > offset { | ||
println!("{}:{index}:{offset}", block.txdata[0].txid()); | ||
break; | ||
for height in (creation_height + 1)..(self.as_of_height + 1) { | ||
match index.block(height)? { | ||
Some(block) => { | ||
for (txindex, transaction) in block.txdata.iter().enumerate() { | ||
for input in &transaction.input { | ||
if input.previous_output == satpoint.outpoint { | ||
satpoint = SatPoint::from_transaction_and_offset(transaction, satpoint.offset); | ||
slot = (height, txindex, satpoint.outpoint.vout, satpoint.offset); | ||
} | ||
} | ||
} | ||
} | ||
None => break, | ||
} | ||
} | ||
offset -= output.value; | ||
} | ||
|
||
Ok(()) | ||
if self.slot { | ||
println!("{}.{}.{}.{}", slot.0, slot.1, slot.2, slot.3); | ||
} else { | ||
println!("{satpoint}"); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use super::*; | ||
|
||
#[derive(StructOpt)] | ||
pub(crate) struct List { | ||
#[structopt(long)] | ||
blocksdir: Option<PathBuf>, | ||
outpoint: OutPoint, | ||
} | ||
|
||
impl List { | ||
pub(crate) fn run(self) -> Result<()> { | ||
let index = Index::new(self.blocksdir.as_deref())?; | ||
let ranges = index.list(self.outpoint)?; | ||
|
||
for (start, end) in ranges { | ||
println!("[{start},{end})"); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use super::*; | ||
|
||
#[derive(StructOpt)] | ||
pub(crate) struct Name { | ||
name: String, | ||
} | ||
|
||
impl Name { | ||
pub(crate) fn run(self) -> Result { | ||
for c in self.name.chars() { | ||
if !('a'..='z').contains(&c) { | ||
return Err("Invalid name".into()); | ||
} | ||
} | ||
|
||
let mut min = 0; | ||
let mut max = 2099999997690000; | ||
let mut guess = max / 2; | ||
|
||
loop { | ||
log::info!("min max guess: {} {} {}", min, max, guess); | ||
|
||
let name = Ordinal::new(guess).name(); | ||
|
||
match name | ||
.len() | ||
.cmp(&self.name.len()) | ||
.then(name.deref().cmp(&self.name)) | ||
.reverse() | ||
{ | ||
Ordering::Less => min = guess + 1, | ||
Ordering::Equal => break, | ||
Ordering::Greater => max = guess, | ||
} | ||
|
||
if max - min == 0 { | ||
return Err("Name out of range".into()); | ||
} | ||
|
||
guess = min + (max - min) / 2; | ||
} | ||
|
||
println!("{}", guess); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,40 @@ | ||
use super::*; | ||
|
||
pub(crate) fn run(height: Height, name_range: bool) -> Result { | ||
let mut start = 0; | ||
#[derive(StructOpt)] | ||
pub(crate) struct Range { | ||
#[structopt(long)] | ||
name: bool, | ||
height: Height, | ||
} | ||
|
||
impl Range { | ||
pub(crate) fn run(self) -> Result { | ||
let mut start = 0; | ||
|
||
for n in 0..height.n() { | ||
let subsidy = Height(n).subsidy(); | ||
for n in 0..self.height.n() { | ||
let subsidy = Height(n).subsidy(); | ||
|
||
if subsidy == 0 { | ||
break; | ||
if subsidy == 0 { | ||
break; | ||
} | ||
|
||
start += subsidy; | ||
} | ||
|
||
start += subsidy; | ||
} | ||
let end = start + self.height.subsidy(); | ||
|
||
let end = start + height.subsidy(); | ||
|
||
if name_range { | ||
let (start, end) = match (Ordinal::new_checked(start), Ordinal::new_checked(end)) { | ||
(Some(start), Some(end)) => (start.name(), end.name()), | ||
(Some(start), None) => (start.name(), start.name()), | ||
(None, None) => (Ordinal::LAST.name(), Ordinal::LAST.name()), | ||
(None, Some(_)) => unreachable!(), | ||
}; | ||
println!("[{},{})", start, end); | ||
} else { | ||
println!("[{},{})", start, end); | ||
} | ||
if self.name { | ||
let (start, end) = match (Ordinal::new_checked(start), Ordinal::new_checked(end)) { | ||
(Some(start), Some(end)) => (start.name(), end.name()), | ||
(Some(start), None) => (start.name(), start.name()), | ||
(None, None) => (Ordinal::LAST.name(), Ordinal::LAST.name()), | ||
(None, Some(_)) => unreachable!(), | ||
}; | ||
println!("[{},{})", start, end); | ||
} else { | ||
println!("[{},{})", start, end); | ||
} | ||
|
||
Ok(()) | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.