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

Add runes to parse command #2830

Merged
merged 3 commits into from
Dec 11, 2023
Merged
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
5 changes: 5 additions & 0 deletions src/object.rs
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ pub enum Object {
InscriptionId(InscriptionId),
Integer(u128),
OutPoint(OutPoint),
Rune(Rune),
Sat(Sat),
SatPoint(SatPoint),
}
@@ -26,6 +27,7 @@ impl FromStr for Object {
InscriptionId => Ok(Self::InscriptionId(s.parse()?)),
Integer => Ok(Self::Integer(s.parse()?)),
OutPoint => Ok(Self::OutPoint(s.parse()?)),
Rune => Ok(Self::Rune(s.parse()?)),
SatPoint => Ok(Self::SatPoint(s.parse()?)),
}
}
@@ -44,6 +46,7 @@ impl Display for Object {
Self::InscriptionId(inscription_id) => write!(f, "{inscription_id}"),
Self::Integer(integer) => write!(f, "{integer}"),
Self::OutPoint(outpoint) => write!(f, "{outpoint}"),
Self::Rune(rune) => write!(f, "{rune}"),
Self::Sat(sat) => write!(f, "{sat}"),
Self::SatPoint(satpoint) => write!(f, "{satpoint}"),
}
@@ -196,5 +199,7 @@ mod tests {
.unwrap(),
),
);
case("A", Object::Rune(Rune(0)));
case("B", Object::Rune(Rune(1)));
}
}
3 changes: 3 additions & 0 deletions src/representation.rs
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ pub(crate) enum Representation {
Name,
OutPoint,
Percentile,
Rune,
SatPoint,
}

@@ -28,6 +29,7 @@ impl Representation {
Self::Name => r"^[a-z]{1,11}$",
Self::OutPoint => r"^[[:xdigit:]]{64}:\d+$",
Self::Percentile => r"^.*%$",
Self::Rune => r"^[A-Z]+$",
Self::SatPoint => r"^[[:xdigit:]]{64}:\d+:\d+$",
},
)
@@ -56,6 +58,7 @@ const PATTERNS: &[(Representation, &str)] = &[
Representation::Name.pattern(),
Representation::OutPoint.pattern(),
Representation::Percentile.pattern(),
Representation::Rune.pattern(),
Representation::SatPoint.pattern(),
];

2 changes: 1 addition & 1 deletion tests/parse.rs
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ fn hash() {

#[test]
fn unrecognized_object() {
CommandBuilder::new("parse A")
CommandBuilder::new("parse Az")
.stderr_regex(r"error: .*: unrecognized object\n.*")
.expected_exit_code(2)
.run_and_extract_stdout();