pub struct SignBytesResolver { /* private fields */ }Expand description
Resolves SignBytesMode::Auto to a concrete version per network, caching
each answer per (rest_url, chain_id) for a TTL (default
DEFAULT_SIGN_BYTES_CACHE_TTL).
For a non-legacy chain the answer is v2 with no network call. For a legacy
chain it asks GET {rest_url}/cosmos/upgrade/v1beta1/applied_plan/{name}
({"height":"<n>"}; a missing height means 0) for every name in
SIGN_BYTES_V2_UPGRADES, stopping at the first positive height, and
applies sign_bytes_version_for. Mainnet therefore costs one request once
it has upgraded, and the testnet two.
Implementations§
Source§impl SignBytesResolver
impl SignBytesResolver
Sourcepub fn with_client(http: Client) -> Self
pub fn with_client(http: Client) -> Self
A resolver using the supplied HTTP client and the default TTL.
Sourcepub fn with_ttl(self, ttl: Duration) -> Self
pub fn with_ttl(self, ttl: Duration) -> Self
Sets the cache TTL (Duration::ZERO disables caching).
Sourcepub async fn resolve(
&self,
mode: SignBytesMode,
chain_id: &str,
rest_url: Option<&str>,
) -> Result<SignBytesVersion>
pub async fn resolve( &self, mode: SignBytesMode, chain_id: &str, rest_url: Option<&str>, ) -> Result<SignBytesVersion>
Resolves mode for chain_id.
V1/V2→ returned as-is, no network.Autoon a non-legacy chain → v2, no network.Autoon a legacy chain → the cached answer for(rest_url, chain_id)when fresh, else the node is asked. Norest_url, or a failed query, is an error (never a guess).
Sourcepub async fn force_refresh(
&self,
chain_id: &str,
rest_url: Option<&str>,
) -> Result<SignBytesVersion>
pub async fn force_refresh( &self, chain_id: &str, rest_url: Option<&str>, ) -> Result<SignBytesVersion>
Re-asks the node for chain_id, bypassing (and then refreshing) the
cache. A non-legacy chain still resolves to v2 without a network call.
Sourcepub fn invalidate(&self, rest_url: &str, chain_id: &str)
pub fn invalidate(&self, rest_url: &str, chain_id: &str)
Drops the cached answer for (rest_url, chain_id).
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Drops every cached answer.
Sourcepub async fn fetch_v2_applied_height(
&self,
rest_url: &str,
plan_name: Option<&str>,
) -> Result<i64>
pub async fn fetch_v2_applied_height( &self, rest_url: &str, plan_name: Option<&str>, ) -> Result<i64>
Asks rest_url for the height at which ONE upgrade name was applied
(0 when it has not been, or when the node answers {}).
plan_name defaults to SIGN_BYTES_V2_UPGRADE when None. The
resolver itself uses SignBytesResolver::fetch_v2_applied_height_any,
which covers every name the switch shipped under.
Sourcepub async fn fetch_v2_applied_height_any(&self, rest_url: &str) -> Result<i64>
pub async fn fetch_v2_applied_height_any(&self, rest_url: &str) -> Result<i64>
The height at which the v2 switch was applied on rest_url’s chain,
under ANY of SIGN_BYTES_V2_UPGRADES (0 when under none of them).
The names are asked in order and the first positive height is returned without asking the rest, so a network that upgraded under the primary name costs a single request. Any failed query is an error, never a guess.