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.
Move runes types into ordinals crate (ordinals#3391)
- Loading branch information
1 parent
67659a1
commit 8c0fbaa
Showing
35 changed files
with
624 additions
and
407 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 was deleted.
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use super::*; | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq)] | ||
pub enum Cenotaph { | ||
EdictOutput, | ||
EdictRuneId, | ||
Opcode, | ||
SupplyOverflow, | ||
TrailingIntegers, | ||
TruncatedField, | ||
UnrecognizedEvenTag, | ||
UnrecognizedFlag, | ||
Varint, | ||
} | ||
|
||
impl Cenotaph { | ||
pub const ALL: [Self; 9] = [ | ||
Self::EdictOutput, | ||
Self::EdictRuneId, | ||
Self::Opcode, | ||
Self::SupplyOverflow, | ||
Self::TrailingIntegers, | ||
Self::TruncatedField, | ||
Self::UnrecognizedEvenTag, | ||
Self::UnrecognizedFlag, | ||
Self::Varint, | ||
]; | ||
|
||
pub fn flag(self) -> u32 { | ||
1 << (self as u32) | ||
} | ||
} | ||
|
||
impl Display for Cenotaph { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::EdictOutput => write!(f, "edict output greater than transaction output count"), | ||
Self::EdictRuneId => write!(f, "invalid rune ID in edict"), | ||
Self::Opcode => write!(f, "non-pushdata opcode in OP_RETURN"), | ||
Self::SupplyOverflow => write!(f, "supply overflows u128"), | ||
Self::TrailingIntegers => write!(f, "trailing integers in body"), | ||
Self::TruncatedField => write!(f, "field with missing value"), | ||
Self::UnrecognizedEvenTag => write!(f, "unrecognized even tag"), | ||
Self::UnrecognizedFlag => write!(f, "unrecognized field"), | ||
Self::Varint => write!(f, "invalid varint"), | ||
} | ||
} | ||
} | ||
|
||
impl From<Cenotaph> for Runestone { | ||
fn from(cenotaph: Cenotaph) -> Self { | ||
Self { | ||
cenotaph: cenotaph.flag(), | ||
..default() | ||
} | ||
} | ||
} | ||
|
||
impl From<Cenotaph> for u32 { | ||
fn from(cenotaph: Cenotaph) -> Self { | ||
cenotaph.flag() | ||
} | ||
} |
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
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,39 @@ | ||
use super::*; | ||
|
||
#[derive(Default, Serialize, Deserialize, Debug, PartialEq, Copy, Clone, Eq)] | ||
pub struct Etching { | ||
pub divisibility: Option<u8>, | ||
pub premine: Option<u128>, | ||
pub rune: Option<Rune>, | ||
pub spacers: Option<u32>, | ||
pub symbol: Option<char>, | ||
pub terms: Option<Terms>, | ||
} | ||
|
||
impl Etching { | ||
pub const MAX_DIVISIBILITY: u8 = 38; | ||
pub const MAX_SPACERS: u32 = 0b00000111_11111111_11111111_11111111; | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn max_spacers() { | ||
let mut rune = String::new(); | ||
|
||
for (i, c) in Rune(u128::MAX).to_string().chars().enumerate() { | ||
if i > 0 { | ||
rune.push('•'); | ||
} | ||
|
||
rune.push(c); | ||
} | ||
|
||
assert_eq!( | ||
Etching::MAX_SPACERS, | ||
rune.parse::<SpacedRune>().unwrap().spacers | ||
); | ||
} | ||
} |
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
Oops, something went wrong.