1#![doc = include_str!("../README.md")]
2
3#[cfg(all(target_arch = "wasm32", test))]
4wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
5
6mod blob;
7mod blobstream;
8mod client;
9mod fraud;
10mod header;
11mod share;
12mod state;
13#[cfg(test)]
14mod test_utils;
15mod utils;
16
17pub mod api {
19 pub use crate::blob::BlobApi;
20 pub use crate::blobstream::BlobstreamApi;
21 pub use crate::fraud::FraudApi;
22 pub use crate::header::HeaderApi;
23 pub use crate::share::ShareApi;
24 pub use crate::state::StateApi;
25
26 pub mod blob {
28 #[doc(inline)]
29 pub use celestia_rpc::blob::BlobsAtHeight;
30 }
31
32 pub mod share {
34 #[doc(inline)]
35 pub use celestia_rpc::share::{
36 GetRangeResponse, GetRowResponse, RowSide, SampleCoordinates,
37 };
38 }
39
40 pub mod fraud {
42 #[doc(inline)]
43 pub use celestia_rpc::fraud::{Proof, ProofType};
44 }
45
46 pub mod state {
48 #[doc(inline)]
49 pub use crate::state::AsyncGrpcCall;
50 }
51}
52
53pub mod tx {
55 #[doc(inline)]
56 pub use celestia_grpc::grpc::{GasEstimate, TxPriority};
57 #[doc(inline)]
58 pub use celestia_grpc::{DocSigner, IntoProtobufAny, SignDoc, TxConfig, TxInfo};
59 #[doc(inline)]
60 pub use k256::ecdsa::signature::{Error as SignatureError, Keypair};
61 #[doc(inline)]
62 pub use k256::ecdsa::{Signature, SigningKey, VerifyingKey};
63}
64
65use celestia_grpc::GrpcClientBuilderError;
66
67#[doc(inline)]
71pub use celestia_proto as proto;
72
73#[doc(inline)]
77pub use celestia_types as types;
78
79pub use crate::client::{Client, ClientBuilder, Endpoint};
80
81pub type Result<T, E = Error> = std::result::Result<T, E>;
85
86#[derive(Debug, thiserror::Error)]
90pub enum Error {
91 #[error("RPC error: {0}")]
93 Rpc(#[from] celestia_rpc::Error),
94
95 #[error("gRPC error: {0}")]
97 Grpc(celestia_grpc::Error),
98
99 #[error("gRPC client builder error: {0}")]
101 GrpcBuilder(GrpcClientBuilderError),
102
103 #[error("Celestia types error: {0}")]
105 Types(#[from] celestia_types::Error),
106
107 #[error("Client is constructed for read-only mode, operation not supported")]
109 ReadOnlyMode,
110
111 #[error("Chain id of RPC endpoint missmatch with chain id of gRPC endpoint")]
113 ChainIdMissmatch,
114
115 #[error("Invalid height: {0}")]
117 InvalidHeight(u64),
118
119 #[error("Invalid private key")]
121 InvalidPrivateKey,
122
123 #[error("RPC endpoint not set")]
125 RpcEndpointNotSet,
126
127 #[error("Client has no associated account address")]
129 NoAssociatedAddress,
130
131 #[error("Signer is set but gRPC endpoint is not")]
133 GrpcEndpointNotSet,
134}
135
136impl From<jsonrpsee_core::ClientError> for Error {
137 fn from(value: jsonrpsee_core::ClientError) -> Self {
138 Error::Rpc(celestia_rpc::Error::JsonRpc(value))
139 }
140}
141
142impl From<serde_json::Error> for Error {
143 fn from(value: serde_json::Error) -> Self {
144 jsonrpsee_core::ClientError::ParseError(value).into()
145 }
146}
147
148impl From<GrpcClientBuilderError> for Error {
149 fn from(value: GrpcClientBuilderError) -> Self {
150 match value {
151 GrpcClientBuilderError::TransportNotSet => Error::GrpcEndpointNotSet,
152 GrpcClientBuilderError::InvalidPrivateKey => Error::InvalidPrivateKey,
153 e => Error::GrpcBuilder(e),
154 }
155 }
156}
157
158impl From<celestia_grpc::Error> for Error {
159 fn from(value: celestia_grpc::Error) -> Self {
160 match value {
161 celestia_grpc::Error::MissingSigner => Error::ReadOnlyMode,
162 e => Error::Grpc(e),
163 }
164 }
165}
166
167impl Error {
168 pub fn as_grpc_status(&self) -> Option<&tonic::Status> {
170 match self {
171 Error::Grpc(celestia_grpc::Error::TonicError(status)) => Some(&**status),
172 _ => None,
173 }
174 }
175
176 pub fn as_rpc_call_error(&self) -> Option<&jsonrpsee_types::error::ErrorObjectOwned> {
178 match self {
179 Error::Rpc(celestia_rpc::Error::JsonRpc(jsonrpsee_core::ClientError::Call(e))) => {
180 Some(e)
181 }
182 _ => None,
183 }
184 }
185}