Skip to content

Commit

Permalink
Use https://signet.ordinals.com as default signet publish URL (ordina…
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Oct 13, 2022
1 parent f1fcb75 commit 6e00a3d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
27 changes: 27 additions & 0 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ impl Chain {
}
}

pub(crate) fn default_publish_url(self) -> Option<Url> {
match self {
Self::Mainnet => Some("https://ordinals.com".parse().unwrap()),
Self::Signet => Some("https://signet.ordinals.com".parse().unwrap()),
Self::Regtest | Self::Testnet => None,
}
}

pub(crate) fn default_rpc_port(self) -> u16 {
match self {
Self::Mainnet => 8332,
Expand Down Expand Up @@ -72,3 +80,22 @@ impl Display for Chain {
)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn default_publish_url() {
assert_eq!(
Chain::Mainnet.default_publish_url(),
Some("https://ordinals.com".parse().unwrap())
);
assert_eq!(
Chain::Signet.default_publish_url(),
Some("https://signet.ordinals.com".parse().unwrap())
);
assert_eq!(Chain::Testnet.default_publish_url(), None,);
assert_eq!(Chain::Regtest.default_publish_url(), None,);
}
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use {
clap::Parser,
derive_more::{Display, FromStr},
regex::Regex,
reqwest::Url,
serde::{Deserialize, Serialize},
std::{
collections::VecDeque,
Expand Down
13 changes: 8 additions & 5 deletions src/subcommand/rune/publish.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use {super::*, reqwest::Url};
use super::*;

#[derive(Debug, Parser)]
pub(crate) struct Publish {
Expand All @@ -8,10 +8,9 @@ pub(crate) struct Publish {
ordinal: Ordinal,
#[clap(
long,
default_value = "https://ordinals.com/",
help = "Publish rune to <PUBLISH_URL>."
help = "Publish rune to <PUBLISH_URL>. [mainnet default: https://ordinals.com, signet default: https://signet.ordinals.com]"
)]
publish_url: Url,
publish_url: Option<Url>,
}

impl Publish {
Expand All @@ -26,7 +25,11 @@ impl Publish {

let json = serde_json::to_string(&rune)?;

let url = self.publish_url.join("rune")?;
let url = self
.publish_url
.or_else(|| options.chain.default_publish_url())
.ok_or_else(|| anyhow!("No default <PUBLISH_URL> for {}", options.chain))?
.join("rune")?;

let response = reqwest::blocking::Client::new()
.put(url.clone())
Expand Down

0 comments on commit 6e00a3d

Please sign in to comment.