Skip to main content

Client

Struct Client 

Source
pub struct Client<H, K = ()> { /* private fields */ }
Expand description

Reads for any module (markets::order_books(&client)) and, with an ApiKey, transactions. K is () for a client that only reads.

Each client counts its key’s nonces, so give every key one client. A read that is the account’s own carries an auth token, minted from the key and kept until shortly before it lapses, or the read-only token the client was given.

Implementations§

Source§

impl<H: Http> Client<H>

Source

pub fn reader(http: H, network: Network, clock: Clock) -> Self

A client that reads and never signs.

Source§

impl<H: Http, K> Client<H, K>

Source

pub fn new(http: H, network: Network, clock: Clock, key: K) -> Self

One network, through http, signing with key.

Source

pub fn with_tier(self, tier: Tier) -> Self

The account’s tier, whose budget the client paces its reads against: Standard unless the account opted into another.

Source

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

A read-only token (ro:..., from tokens/create), carried by the account’s own reads when the client holds no key to mint one.

Source

pub const fn network(&self) -> Network

Source

pub const fn tier(&self) -> Tier

Source

pub const fn http(&self) -> &H

Source

pub const fn key(&self) -> &K

Source

pub fn now_ms(&self) -> u64

Now, by the client’s clock: unix milliseconds.

Source

pub fn spent(&self) -> Spent

What went out over the last minute, and whether the gate is closed.

Source

pub async fn warm(&self)

Opens, or refreshes, the connection transactions travel on, with the venue’s status (/), counted like any other read. Nothing is signed and the answer is dropped: a program warms before its first order so that order skips DNS and the TLS handshake.

Source

pub fn forget_nonce(&self)

The key’s nonce count is wrong or unknown: the next transaction asks nextNonce.

Source§

impl<H: Http, K: Credentials> Client<H, K>

Source

pub fn auth_token(&self) -> Option<String>

The token the account’s own reads and channels carry: one minted from the key for seven hours (minted again with half an hour left), else the read-only token; None when there is neither.

Source§

impl<H: Http> Client<H, ApiKey>

Whether the key is in place, which needs no signature.

Source

pub async fn is_registered(&self) -> Result<bool, ApiError>

Whether the venue lists this client’s key at its slot: true once a registration has executed, a few seconds after it is taken.

Source§

impl<H: Http> Client<H, ApiKey>

Sending needs the sign feature, for the randomness every Schnorr signature draws. Each signature is verified before anything is posted, and each owner’s signature recovered.

One client’s transactions go out in turn, each signed at the key’s next nonce: counted from nextNonce, moved on by every one the venue takes, kept for the next after a refusal (it was turned away before it counted), and asked again after an answer that never came or a refused nonce. A refused nonce is signed and sent once more at the venue’s count.

Source

pub async fn next_nonce(&self) -> Result<u64, ApiError>

The nonce the key’s next transaction signs at: counted here, asked of the venue (nextNonce) when not known. Nothing is taken.

Source

pub fn expiry(&self) -> u64

When a transaction signed now lapses: ten minutes less a second, as lighter-go signs.

Source

pub fn sign_at( &self, tx: &(impl Tx + ?Sized), nonce: u64, expired_at: u64, ) -> Result<Signed, SignTxError>

Signs tx at nonce, lapsing at expired_at. The nonce must be the key’s next; nothing is counted.

Source

pub async fn sign(&self, tx: &(impl Tx + ?Sized)) -> Result<Signed, SendError>

Signs tx at the key’s next nonce, for a program that posts it itself (over the websocket, say). Its nonce is counted as used: if the venue never takes it, call Client::forget_nonce.

Source

pub async fn send(&self, tx: &(impl Tx + ?Sized)) -> Result<Sent, SendError>

Signs tx at the key’s next nonce and sends it.

Source

pub async fn send_with_owner( &self, tx: &(impl Tx + ?Sized), owner: &impl Wallet, ) -> Result<Sent, SendError>

Signs tx, has owner sign what the venue asks the owner to (a key registration, a transfer to another owner, an integrator approval with fees), and sends it. The owner’s signature must recover to owner’s address before anything is posted, and the owner is never asked twice: a refused nonce comes back as it is.

Source

pub async fn submit( &self, signed: &Signed, owner_signature: Option<&L1Signature>, ) -> Result<Sent, ApiError>

Sends a transaction signed earlier (Client::sign) once, with the owner’s signature if it carries one. The nonce is the caller’s to settle: forget it if the answer never came.

Source

pub async fn send_batch(&self, txs: &[&dyn Tx]) -> Result<SentBatch, SendError>

Signs up to fifty transactions at consecutive nonces and sends them as one batch. None may need the owner’s signature.

Source

pub async fn register(&self, owner: &impl Wallet) -> Result<Sent, SendError>

Registers this client’s key at its slot, signed by the key and by owner, the account’s L1 address. It replaces whatever key sat there: choose the slot with crate::account::keys::pick_slot. The slots Lighter’s own apps hold (0 to 3, and 157 on Robinhood Chain) are refused: registering there logs the app out.

Trait Implementations§

Source§

impl<H: Http, K> Debug for Client<H, K>

Its network and tier; never its key, its tokens or its transport.

Source§

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

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

impl<H: Http, K: Credentials> Transport for Client<H, K>

Source§

async fn call(&self, call: Call) -> Result<String, TransportError>

Auto Trait Implementations§

§

impl<H, K = ()> !Freeze for Client<H, K>

§

impl<H, K = ()> !RefUnwindSafe for Client<H, K>

§

impl<H, K> Send for Client<H, K>
where Api<H>: Send, K: Send,

§

impl<H, K> Sync for Client<H, K>
where Api<H>: Sync, K: Sync,

§

impl<H, K> Unpin for Client<H, K>
where Api<H>: Unpin, K: Unpin,

§

impl<H, K> UnsafeUnpin for Client<H, K>
where Api<H>: UnsafeUnpin, K: UnsafeUnpin,

§

impl<H, K> UnwindSafe for Client<H, K>
where Api<H>: UnwindSafe, K: UnwindSafe,

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<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