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

View File

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