Skip to main content

SignBytesResolver

Struct SignBytesResolver 

Source
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

Source

pub fn new() -> Self

A resolver with a fresh HTTP client and the default TTL.

Source

pub fn with_client(http: Client) -> Self

A resolver using the supplied HTTP client and the default TTL.

Source

pub fn with_ttl(self, ttl: Duration) -> Self

Sets the cache TTL (Duration::ZERO disables caching).

Source

pub fn ttl(&self) -> Duration

The configured cache TTL.

Source

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.
  • Auto on a non-legacy chain → v2, no network.
  • Auto on a legacy chain → the cached answer for (rest_url, chain_id) when fresh, else the node is asked. No rest_url, or a failed query, is an error (never a guess).
Source

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.

Source

pub fn invalidate(&self, rest_url: &str, chain_id: &str)

Drops the cached answer for (rest_url, chain_id).

Source

pub fn clear_cache(&self)

Drops every cached answer.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for SignBytesResolver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SignBytesResolver

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more