ord/subcommand/server/
query.rs1use super::*;
2
3pub(super) enum Block {
4 Height(u32),
5 Hash(BlockHash),
6}
7
8impl FromStr for Block {
9 type Err = Error;
10
11 fn from_str(s: &str) -> Result<Self, Self::Err> {
12 Ok(if s.len() == 64 {
13 Self::Hash(s.parse()?)
14 } else {
15 Self::Height(s.parse()?)
16 })
17 }
18}
19
20#[derive(Copy, Clone, Debug)]
21pub enum Inscription {
22 Id(InscriptionId),
23 Number(i32),
24 Sat(Sat),
25}
26
27impl FromStr for Inscription {
28 type Err = Error;
29
30 fn from_str(s: &str) -> Result<Self, Self::Err> {
31 if re::INSCRIPTION_ID.is_match(s) {
32 Ok(Self::Id(s.parse()?))
33 } else if re::INSCRIPTION_NUMBER.is_match(s) {
34 Ok(Self::Number(s.parse()?))
35 } else if re::SAT_NAME.is_match(s) {
36 Ok(Self::Sat(s.parse()?))
37 } else {
38 Err(anyhow!("bad inscription query {s}"))
39 }
40 }
41}
42
43impl Display for Inscription {
44 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
45 match self {
46 Self::Id(id) => write!(f, "{id}"),
47 Self::Number(number) => write!(f, "{number}"),
48 Self::Sat(sat) => write!(f, "on sat {}", sat.name()),
49 }
50 }
51}
52
53#[derive(Debug)]
54pub(super) enum Rune {
55 Spaced(SpacedRune),
56 Id(RuneId),
57 Number(u64),
58}
59
60impl FromStr for Rune {
61 type Err = Error;
62
63 fn from_str(s: &str) -> Result<Self, Self::Err> {
64 if s.contains(':') {
65 Ok(Self::Id(s.parse()?))
66 } else if re::RUNE_NUMBER.is_match(s) {
67 Ok(Self::Number(s.parse()?))
68 } else {
69 Ok(Self::Spaced(s.parse()?))
70 }
71 }
72}