forked from ordinals/ord
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ordzaar): methods and apis (#4)
- Loading branch information
Showing
6 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use super::*; | ||
|
||
#[derive(Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct InscriptionData { | ||
pub inscription_id: InscriptionId, | ||
pub number: i32, | ||
pub sequence: u32, | ||
pub genesis_height: u32, | ||
pub genesis_fee: u64, | ||
pub sat: Option<Sat>, | ||
pub satpoint: SatPoint, | ||
pub timestamp: i64, | ||
} | ||
|
||
impl InscriptionData { | ||
pub fn new( | ||
genesis_fee: u64, | ||
genesis_height: u32, | ||
inscription_id: InscriptionId, | ||
number: i32, | ||
sequence: u32, | ||
sat: Option<Sat>, | ||
satpoint: SatPoint, | ||
timestamp: DateTime<Utc>, | ||
) -> Self { | ||
Self { | ||
inscription_id, | ||
number, | ||
sequence, | ||
genesis_height, | ||
genesis_fee, | ||
sat, | ||
satpoint, | ||
timestamp: timestamp.timestamp(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct InscriptionIds { | ||
pub ids: Vec<InscriptionId>, | ||
} |
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,4 @@ | ||
use super::*; | ||
|
||
pub mod inscriptions; | ||
pub mod ordinals; |
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,92 @@ | ||
use super::*; | ||
|
||
#[derive(Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct OrdinalJson { | ||
pub number: u64, | ||
pub decimal: String, | ||
pub degree: String, | ||
pub name: String, | ||
pub height: u32, | ||
pub cycle: u32, | ||
pub epoch: u32, | ||
pub period: u32, | ||
pub offset: u64, | ||
pub rarity: Rarity, | ||
pub output: OutPoint, | ||
pub start: u64, | ||
pub end: u64, | ||
pub size: u64, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct Output { | ||
pub output: OutPoint, | ||
pub start: u64, | ||
pub end: u64, | ||
pub size: u64, | ||
pub offset: u64, | ||
pub rarity: Rarity, | ||
pub name: String, | ||
} | ||
|
||
pub fn get_ordinals(index: &Index, outpoint: OutPoint) -> Result<Vec<OrdinalJson>> { | ||
match index.list(outpoint)? { | ||
Some(crate::index::List::Unspent(ranges)) => { | ||
let mut ordinals = Vec::new(); | ||
for Output { | ||
output, | ||
start, | ||
end, | ||
size, | ||
offset, | ||
rarity, | ||
name, | ||
} in list(outpoint, ranges) | ||
{ | ||
let sat = Sat(start); | ||
ordinals.push(OrdinalJson { | ||
number: sat.n(), | ||
decimal: sat.decimal().to_string(), | ||
degree: sat.degree().to_string(), | ||
name, | ||
height: sat.height().0, | ||
cycle: sat.cycle(), | ||
epoch: sat.epoch().0, | ||
period: sat.period(), | ||
offset, | ||
rarity, | ||
output, | ||
start, | ||
end, | ||
size, | ||
}); | ||
} | ||
Ok(ordinals) | ||
} | ||
Some(crate::index::List::Spent) => Ok(Vec::new()), | ||
None => Ok(Vec::new()), | ||
} | ||
} | ||
|
||
fn list(outpoint: OutPoint, ranges: Vec<(u64, u64)>) -> Vec<Output> { | ||
let mut offset = 0; | ||
ranges | ||
.into_iter() | ||
.map(|(start, end)| { | ||
let size = end - start; | ||
let output = Output { | ||
output: outpoint, | ||
start, | ||
end, | ||
size, | ||
offset, | ||
name: Sat(start).name(), | ||
rarity: Sat(start).rarity(), | ||
}; | ||
|
||
offset += size; | ||
|
||
output | ||
}) | ||
.collect() | ||
} |
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