Skip to content

Commit

Permalink
Add missing api endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchTurner committed Jan 20, 2025
1 parent cdfec32 commit c57b645
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions crates/services/shared-sequencer/src/http_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,39 @@ pub async fn estimate_transaction(
}

pub async fn get_account_prefix(api_url: &str) -> anyhow::Result<String> {
let r = reqwest::get(format!("{api_url}/cosmos/auth/v1beta1/bech32")).await?;
let path = "/cosmos/auth/v1beta1/bech32";
let full_url = Url::parse(api_url)?.join(path).unwrap();
let r = reqwest::get(full_url).await?;
let text = r.text().await?;
let resp: api_types::AccountPrefix =
serde_json::from_str(&text).with_context(|| format!("response text {text}"))?;
Ok(resp.bech32_prefix)
}

pub async fn chain_id(api_url: &str) -> anyhow::Result<String> {
let r = reqwest::get(format!(
"{api_url}/cosmos/base/tendermint/v1beta1/node_info"
))
.await?;
let path = "/cosmos/base/tendermint/v1beta1/node_info";
let full_url = Url::parse(api_url)?.join(path).unwrap();
let r = reqwest::get(full_url).await?;
let text = r.text().await?;
let resp: api_types::NodeInfo =
serde_json::from_str(&text).with_context(|| format!("response text {text}"))?;
Ok(resp.default_node_info.network)
}

pub async fn config(api_url: &str) -> anyhow::Result<api_types::Config> {
let r = reqwest::get(format!("{api_url}/cosmos/base/node/v1beta1/config")).await?;
let path = "/cosmos/base/node/v1beta1/config";
let full_url = Url::parse(api_url)?.join(path).unwrap();
let r = reqwest::get(full_url).await?;
let text = r.text().await?;
let resp: api_types::Config =
serde_json::from_str(&text).with_context(|| format!("response text {text}"))?;
Ok(resp)
}

pub async fn coin_denom(api_url: &str) -> anyhow::Result<String> {
let r = reqwest::get(format!("{api_url}/cosmos/staking/v1beta1/params")).await?;
let path = "/cosmos/staking/v1beta1/params";
let full_url = Url::parse(api_url)?.join(path).unwrap();
let r = reqwest::get(full_url).await?;
let text = r.text().await?;
let resp: api_types::StakingParams =
serde_json::from_str(&text).with_context(|| format!("response text {text}"))?;
Expand All @@ -140,7 +145,9 @@ pub async fn get_account(
api_url: &str,
id: AccountId,
) -> anyhow::Result<AccountMetadata> {
let r = reqwest::get(format!("{api_url}/cosmos/auth/v1beta1/accounts/{id}")).await?;
let path = format!("/cosmos/auth/v1beta1/accounts/{id}");
let full_url = Url::parse(api_url)?.join(&path).unwrap();
let r = reqwest::get(full_url).await?;
let text = r.text().await?;
let resp: api_types::AccountResponse =
serde_json::from_str(&text).with_context(|| format!("response text {text}"))?;
Expand Down Expand Up @@ -168,10 +175,9 @@ pub struct TopicInfo {

pub async fn get_topic(api_url: &str, id: [u8; 32]) -> anyhow::Result<Option<TopicInfo>> {
let id_b64 = BASE64_STANDARD.encode(id);
let r = reqwest::get(format!(
"{api_url}/fuelsequencer/sequencing/v1/topic/{id_b64}"
))
.await?;
let path = format!("/fuelsequencer/sequencing/v1/topic/{id_b64}");
let full_url = Url::parse(api_url)?.join(&path).unwrap();
let r = reqwest::get(full_url).await?;
if r.status() == 404 {
return Ok(None);
}
Expand Down

0 comments on commit c57b645

Please sign in to comment.