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

Satoshi Endpoint Proxy #4021

Open
arik-so opened this issue Oct 25, 2024 · 3 comments
Open

Satoshi Endpoint Proxy #4021

arik-so opened this issue Oct 25, 2024 · 3 comments

Comments

@arik-so
Copy link
Contributor

arik-so commented Oct 25, 2024

The server --proxy option is helpful for testing mainnet inscriptions' behavior locally, but a lot of inscriptions that require such testing rely on a specific dynamically inscribed ordinal, which is usually uninscribed locally, and breaks testability.

I wonder whether allowing the --proxy option to also apply as a fallback for the /r/sat/:sat/at/:index endpoint might be worth pursuing? That should help with resolving dynamic content.

@arik-so
Copy link
Contributor Author

arik-so commented Oct 25, 2024

If the Self::proxy() return type were correct, the following spaghetti code might be an approximation:

  async fn sat_inscription_at_index(
    Extension(index): Extension<Arc<Index>>,
    Extension(server_config): Extension<Arc<ServerConfig>>,
    Path((DeserializeFromStr(sat), inscription_index)): Path<(DeserializeFromStr<Sat>, isize)>,
  ) -> ServerResult<Json<api::SatInscription>> {
    task::block_in_place(|| {
      if !index.has_sat_index() {
        return if let Some(proxy) = server_config.proxy.as_ref() {
          Self::proxy(proxy, &format!("r/sat/{}/at/{}", sat, inscription_index))
        } else {
          Err(ServerError::NotFound(
            "this server has no sat index".to_string(),
          ))
        };
      }

      let id = index.get_inscription_id_by_sat_indexed(sat, inscription_index)?;
      if id.is_none() {
        if let Some(proxy) = server_config.proxy.as_ref() {
          return Self::proxy(proxy, &format!("r/sat/{}/at/{}", sat, inscription_index));
        }
      }

      Ok(Json(api::SatInscription { id }))
    })
  }

@raphjaph
Copy link
Collaborator

Yes, this is a good idea. I even have an issue for this #3806

@arik-so
Copy link
Contributor Author

arik-so commented Oct 26, 2024

Oh oops, sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants