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

Use https://signet.ordinals.com as default signet publish URL #649

Merged
merged 4 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
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
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