Skip to main content

Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

One connection to one network’s websocket.

Implementations§

Source§

impl Session

Source

pub fn tick(&mut self, now: u64) -> Tick

What the socket needs at now: a ping every Timing::ping_after_ms, busy or not, or a reconnect after Timing::silent_ms of nothing at all.

Source

pub fn due(&self) -> Option<u64>

When a tick next has something to do; None while closed.

Source

pub fn closed(&mut self, now: u64, random: u64) -> Retry

The socket closed at now, or a connect failed. Gives how long to wait before the next connect, and the transactions left unanswered. The wait doubles from Timing::first_retry_ms to Timing::last_retry_ms and random adds up to a quarter more, so many clients dropped at once do not return at once. It starts over after a socket that held (Timing::steady_ms). There is no last attempt.

Source§

impl Session

Source

pub fn new(network: Network) -> Self

A closed session on network’s socket, with the venue’s limits and the default timing.

Source

pub const fn read_only(self) -> Self

On the read-only socket (?readonly=true), which serves every channel, private ones with their token included, from restricted regions too, and takes no transactions.

Source

pub const fn with_limits(self, limits: Limits) -> Self

A connection’s share of the limits; sessions sharing an IP split its accounts.

Source

pub const fn with_timing(self, timing: Timing) -> Self

Source

pub fn with_auth(self, token: impl Into<String>) -> Self

With the account’s auth token (crate::Client::auth_token) for the channels that take it. A token reads one account and lapses (eight hours at most): set a fresh one before it does with Session::set_auth.

Source

pub fn set_auth(&mut self, token: Option<String>)

A fresh token, or none. The venue reads a token when a channel is subscribed: what is already subscribed goes on, and the new one goes out with the next subscribe, resubscribe or reconnect.

Source

pub const fn network(&self) -> Network

Source

pub const fn is_read_only(&self) -> bool

Source

pub const fn url(&self) -> &'static str

Where to connect: the network’s socket, or its read-only one.

Source

pub const fn is_open(&self) -> bool

Source

pub fn wanted(&self) -> &[Subscription]

What this session subscribes to on every socket, in the order it was asked for.

Source

pub fn accounts(&self) -> usize

The distinct accounts the wanted subscriptions follow.

Source

pub fn waiting(&self) -> &[u64]

The ids of transactions sent on this socket and not yet answered.

Source

pub fn subscribe( &mut self, subscription: Subscription, ) -> Result<Option<String>, Refused>

Wants subscription from now on, on this socket and every later one. Gives the frame to send when the socket is open and it is new; nothing when it was already wanted (the venue refuses a second subscribe). Past the limits, without the token it needs, or on a network that does not serve it, it is refused and not kept.

Source

pub fn unsubscribe(&mut self, subscription: &Subscription) -> Option<String>

Stops wanting subscription. Gives the frame to send when the socket is open and it was wanted.

Source

pub fn resubscribe(&mut self, subscription: &Subscription) -> Vec<String>

An unsubscribe and a subscribe for a fresh snapshot of what is wanted, on an open socket; nothing otherwise. A second subscribe alone the venue refuses.

Source

pub fn send_tx(&mut self, signed: &Signed) -> Result<(u64, String), Refused>

A signed transaction’s frame (jsonapi/sendtx) and the id its answer will name. Only on an open socket that is not read-only, and only while fewer than the limit wait for an answer. One with the owner’s signature: Session::send_tx_info with Signed::tx_info_with_l1.

Source

pub fn send_tx_info( &mut self, tx_type: u8, tx_info: &str, ) -> Result<(u64, String), Refused>

Session::send_tx for a type and tx_info as signed.

Source

pub fn send_tx_batch( &mut self, signed: &[Signed], ) -> Result<(u64, String), Refused>

Up to fifty signed transactions as one batch (jsonapi/sendtxbatch): one account and API key, consecutive nonces. None may need the owner’s signature.

Source

pub fn send_tx_batch_infos( &mut self, txs: &[(u8, String)], ) -> Result<(u64, String), Refused>

Session::send_tx_batch for types and tx_infos as signed.

Source

pub fn opened(&mut self, now: u64) -> Vec<String>

The socket opened at now. Gives the frames that subscribe to everything wanted, in order. Each book’s chain starts again from its snapshot.

Source

pub fn received(&mut self, now: u64, text: &str) -> Result<Frame, BadFrame>

A text frame arrived at now. Anything that arrives shows the socket is alive, whether it reads or not. A transaction’s answer or refusal stops it waiting; a ping is owed a pong; an order book update that does not follow its book comes back as Frame::Gap, and the resubscribe that brings a fresh snapshot is owed (Session::owed).

Source

pub fn owed(&mut self) -> Vec<String>

The frames the venue is owed, to send now and once: the pong to its ping, the unsubscribe and subscribe that bring a book a fresh snapshot after a gap.

Trait Implementations§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Session

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
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