pub struct TxClient<T, S> { /* private fields */ }
Expand description
A client for submitting messages and transactions to celestia.
Client handles management of the accounts sequence (nonce), thus it should be the only party submitting transactions signed with given account. Using e.g. two distinct clients with the same account will make them invalidate each others nonces.
Implementations§
Source§impl<T, S> TxClient<T, S>where
T: GrpcService<UnsyncBoxBody<Bytes, Status>> + Clone,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::Error: Into<Box<dyn Error + Send + Sync>>,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Body<Data = Bytes> + Send + 'static,
<<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody as Body>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
S: DocSigner,
impl<T, S> TxClient<T, S>where
T: GrpcService<UnsyncBoxBody<Bytes, Status>> + Clone,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::Error: Into<Box<dyn Error + Send + Sync>>,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Body<Data = Bytes> + Send + 'static,
<<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody as Body>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
S: DocSigner,
Sourcepub async fn new(
transport: T,
account_address: &Address,
account_pubkey: VerifyingKey<Secp256k1>,
signer: S,
) -> Result<TxClient<T, S>, Error>
pub async fn new( transport: T, account_address: &Address, account_pubkey: VerifyingKey<Secp256k1>, signer: S, ) -> Result<TxClient<T, S>, Error>
Create a new transaction client.
Sourcepub async fn submit_message<M>(
&self,
message: M,
cfg: TxConfig,
) -> Result<TxInfo, Error>where
M: IntoAny,
pub async fn submit_message<M>(
&self,
message: M,
cfg: TxConfig,
) -> Result<TxInfo, Error>where
M: IntoAny,
Submit given message to celestia network.
When no gas price is specified through config, it will automatically handle updating client’s gas price when consensus updates minimal gas price.
§Example
use celestia_grpc::{TxClient, TxConfig};
use celestia_proto::cosmos::bank::v1beta1::MsgSend;
use celestia_types::state::{AccAddress, Coin};
use tendermint::crypto::default::ecdsa_secp256k1::SigningKey;
let signing_key = SigningKey::random(&mut rand_core::OsRng);
let public_key = *signing_key.verifying_key();
let address = AccAddress::new(public_key.into()).into();
let grpc_url = "public-celestia-mocha4-consensus.numia.xyz:9090";
let tx_client = TxClient::with_url(grpc_url, &address, public_key, signing_key)
.await
.unwrap();
let msg = MsgSend {
from_address: address.to_string(),
to_address: "celestia169s50psyj2f4la9a2235329xz7rk6c53zhw9mm".to_string(),
amount: vec![Coin::utia(12345).into()],
};
tx_client
.submit_message(msg.clone(), TxConfig::default())
.await
.unwrap();
Sourcepub async fn submit_blobs(
&self,
blobs: &[Blob],
cfg: TxConfig,
) -> Result<TxInfo, Error>
pub async fn submit_blobs( &self, blobs: &[Blob], cfg: TxConfig, ) -> Result<TxInfo, Error>
Submit given blobs to celestia network.
When no gas price is specified through config, it will automatically handle updating client’s gas price when consensus updates minimal gas price.
§Example
use celestia_grpc::{TxClient, TxConfig};
use celestia_types::state::{AccAddress, Coin};
use celestia_types::{AppVersion, Blob};
use celestia_types::nmt::Namespace;
use tendermint::crypto::default::ecdsa_secp256k1::SigningKey;
let signing_key = SigningKey::random(&mut rand_core::OsRng);
let public_key = *signing_key.verifying_key();
let address = AccAddress::new(public_key.into()).into();
let grpc_url = "public-celestia-mocha4-consensus.numia.xyz:9090";
let tx_client = TxClient::with_url(grpc_url, &address, public_key, signing_key)
.await
.unwrap();
let ns = Namespace::new_v0(b"abcd").unwrap();
let blob = Blob::new(ns, "some data".into(), AppVersion::V3).unwrap();
tx_client
.submit_blobs(&[blob], TxConfig::default())
.await
.unwrap();
Sourcepub fn last_seen_gas_price(&self) -> f64
pub fn last_seen_gas_price(&self) -> f64
Get most recent minimal gas price seen by the client
Sourcepub fn app_version(&self) -> AppVersion
pub fn app_version(&self) -> AppVersion
Get client’s app version
Source§impl<S> TxClient<Client, S>where
S: DocSigner,
impl<S> TxClient<Client, S>where
S: DocSigner,
Sourcepub async fn with_grpcweb_url(
url: impl Into<String>,
account_address: &Address,
account_pubkey: VerifyingKey<Secp256k1>,
signer: S,
) -> Result<TxClient<Client, S>, Error>
pub async fn with_grpcweb_url( url: impl Into<String>, account_address: &Address, account_pubkey: VerifyingKey<Secp256k1>, signer: S, ) -> Result<TxClient<Client, S>, Error>
Create a new client connected to the given url
with default
settings of tonic_web_wasm_client::Client
.
Methods from Deref<Target = GrpcClient<T>>§
Sourcepub async fn get_auth_params(&self) -> Result<Params, Error>
pub async fn get_auth_params(&self) -> Result<Params, Error>
Get auth params
Sourcepub async fn get_balance(
&self,
address: &Address,
denom: impl Into<String>,
) -> Result<Coin, Error>
pub async fn get_balance( &self, address: &Address, denom: impl Into<String>, ) -> Result<Coin, Error>
Get balance of coins with given denom
Sourcepub async fn get_all_balances(
&self,
address: &Address,
) -> Result<Vec<Coin>, Error>
pub async fn get_all_balances( &self, address: &Address, ) -> Result<Vec<Coin>, Error>
Get balance of all coins
Sourcepub async fn get_spendable_balances(
&self,
address: &Address,
) -> Result<Vec<Coin>, Error>
pub async fn get_spendable_balances( &self, address: &Address, ) -> Result<Vec<Coin>, Error>
Get balance of all spendable coins
Sourcepub async fn get_min_gas_price(&self) -> Result<f64, Error>
pub async fn get_min_gas_price(&self) -> Result<f64, Error>
Get Minimum Gas price
Sourcepub async fn get_latest_block(&self) -> Result<Block, Error>
pub async fn get_latest_block(&self) -> Result<Block, Error>
Get latest block
Sourcepub async fn get_block_by_height(&self, height: i64) -> Result<Block, Error>
pub async fn get_block_by_height(&self, height: i64) -> Result<Block, Error>
Get block by height
Sourcepub async fn broadcast_tx(
&self,
tx_bytes: Vec<u8>,
mode: BroadcastMode,
) -> Result<TxResponse, Error>
pub async fn broadcast_tx( &self, tx_bytes: Vec<u8>, mode: BroadcastMode, ) -> Result<TxResponse, Error>
Broadcast prepared and serialised transaction
Sourcepub async fn simulate(&self, tx_bytes: Vec<u8>) -> Result<GasInfo, Error>
pub async fn simulate(&self, tx_bytes: Vec<u8>) -> Result<GasInfo, Error>
Broadcast prepared and serialised transaction
Sourcepub async fn get_blob_params(&self) -> Result<BlobParams, Error>
pub async fn get_blob_params(&self) -> Result<BlobParams, Error>
Get blob params
Trait Implementations§
Auto Trait Implementations§
impl<T, S> !Freeze for TxClient<T, S>
impl<T, S> !RefUnwindSafe for TxClient<T, S>
impl<T, S> Send for TxClient<T, S>
impl<T, S> Sync for TxClient<T, S>
impl<T, S> Unpin for TxClient<T, S>
impl<T, S> UnwindSafe for TxClient<T, S>where
S: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.