fix: Use synchronous http library (ureq)

It's tricky to create a nested async task like async -> sync -> async,
and `to_reth_block` doesn't need to be too complex.
This commit is contained in:
sprites0
2025-06-22 19:08:47 -04:00
parent b1fbe436b1
commit 255a3449e5
2 changed files with 10 additions and 18 deletions

View File

@ -37,25 +37,24 @@ impl SpotId {
}
}
async fn fetch_spot_meta(chain_id: u64) -> Result<SpotMeta> {
fn fetch_spot_meta(chain_id: u64) -> Result<SpotMeta> {
let url = match chain_id {
MAINNET_CHAIN_ID => "https://api.hyperliquid.xyz/info",
TESTNET_CHAIN_ID => "https://api.hyperliquid-testnet.xyz/info",
_ => return Err(Error::msg("unknown chain id")),
};
let client = reqwest::Client::new();
let response = client
.post(url)
.json(&serde_json::json!({"type": "spotMeta"}))
.send()
.await?;
Ok(response.json().await?)
let response = ureq::post(url)
.header("Content-Type", "application/json")
.send(serde_json::json!({"type": "spotMeta"}).to_string())?
.into_body()
.read_to_string()?;
Ok(serde_json::from_str(&response)?)
}
pub(crate) async fn erc20_contract_to_spot_token(
pub(crate) fn erc20_contract_to_spot_token(
chain_id: u64,
) -> Result<BTreeMap<Address, SpotId>> {
let meta = fetch_spot_meta(chain_id).await?;
let meta = fetch_spot_meta(chain_id)?;
let mut map = BTreeMap::new();
for token in &meta.tokens {
if let Some(evm_contract) = &token.evm_contract {

View File

@ -104,14 +104,7 @@ fn system_tx_to_reth_transaction(
to
);
let rt = Handle::current();
futures::executor::block_on(async {
rt.spawn(async move {
*EVM_MAP.lock().unwrap() =
erc20_contract_to_spot_token(chain_id).await.unwrap();
})
.await
.expect("failed to spawn");
});
*EVM_MAP.lock().unwrap() = erc20_contract_to_spot_token(chain_id).unwrap();
}
};
let signature = Signature::new(U256::from(0x1), s, true);