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, K> Client<H, K>
impl<H: Http, K> Client<H, K>
Sourcepub fn new(http: H, network: Network, clock: Clock, key: K) -> Self
pub fn new(http: H, network: Network, clock: Clock, key: K) -> Self
One network, through http, signing with key.
Sourcepub fn with_tier(self, tier: Tier) -> Self
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.
Sourcepub fn with_read_token(self, token: impl Into<String>) -> Self
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.
pub const fn network(&self) -> Network
pub const fn tier(&self) -> Tier
pub const fn http(&self) -> &H
pub const fn key(&self) -> &K
Sourcepub fn spent(&self) -> Spent
pub fn spent(&self) -> Spent
What went out over the last minute, and whether the gate is closed.
Sourcepub async fn warm(&self)
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.
Sourcepub fn forget_nonce(&self)
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>
impl<H: Http, K: Credentials> Client<H, K>
Sourcepub fn auth_token(&self) -> Option<String>
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.
impl<H: Http> Client<H, ApiKey>
Whether the key is in place, which needs no signature.
Sourcepub async fn is_registered(&self) -> Result<bool, ApiError>
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.
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.
Sourcepub async fn next_nonce(&self) -> Result<u64, ApiError>
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.
Sourcepub fn expiry(&self) -> u64
pub fn expiry(&self) -> u64
When a transaction signed now lapses: ten minutes less a second, as lighter-go signs.
Sourcepub fn sign_at(
&self,
tx: &(impl Tx + ?Sized),
nonce: u64,
expired_at: u64,
) -> Result<Signed, SignTxError>
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.
Sourcepub async fn sign(&self, tx: &(impl Tx + ?Sized)) -> Result<Signed, SendError>
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.
Sourcepub async fn send(&self, tx: &(impl Tx + ?Sized)) -> Result<Sent, SendError>
pub async fn send(&self, tx: &(impl Tx + ?Sized)) -> Result<Sent, SendError>
Signs tx at the key’s next nonce and sends it.
Sourcepub async fn send_with_owner(
&self,
tx: &(impl Tx + ?Sized),
owner: &impl Wallet,
) -> Result<Sent, SendError>
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.
Sourcepub async fn submit(
&self,
signed: &Signed,
owner_signature: Option<&L1Signature>,
) -> Result<Sent, ApiError>
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.
Sourcepub async fn send_batch(&self, txs: &[&dyn Tx]) -> Result<SentBatch, SendError>
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.
Sourcepub async fn register(&self, owner: &impl Wallet) -> Result<Sent, SendError>
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.