#![doc = include_str!("../README.md")]
#[cfg(all(target_arch = "wasm32", test))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
mod blob;
mod blobstream;
mod client;
mod fraud;
mod header;
mod share;
mod state;
#[cfg(test)]
mod test_utils;
mod utils;
pub mod api {
pub use crate::blob::BlobApi;
pub use crate::blobstream::BlobstreamApi;
pub use crate::fraud::FraudApi;
pub use crate::header::HeaderApi;
pub use crate::share::ShareApi;
pub use crate::state::StateApi;
pub mod blob {
#[doc(inline)]
pub use celestia_rpc::blob::BlobsAtHeight;
}
pub mod share {
#[doc(inline)]
pub use celestia_rpc::share::{
GetRangeResponse, GetRowResponse, RowSide, SampleCoordinates,
};
}
pub mod fraud {
#[doc(inline)]
pub use celestia_rpc::fraud::{Proof, ProofType};
}
}
pub mod tx {
#[doc(inline)]
pub use celestia_grpc::grpc::{GasEstimate, TxPriority};
#[doc(inline)]
pub use celestia_grpc::{DocSigner, IntoProtobufAny, SignDoc, TxConfig, TxInfo};
#[doc(inline)]
pub use k256::ecdsa::signature::{Error as SignatureError, Keypair};
#[doc(inline)]
pub use k256::ecdsa::{Signature, SigningKey, VerifyingKey};
}
#[doc(inline)]
pub use celestia_proto as proto;
#[doc(inline)]
pub use celestia_types as types;
pub use crate::client::{Client, ClientBuilder};
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("RPC error: {0}")]
Rpc(#[from] celestia_rpc::Error),
#[error("GRPC error: {0}")]
Grpc(#[from] celestia_grpc::Error),
#[error("Celestia types error: {0}")]
Types(#[from] celestia_types::Error),
#[error("Client is constructed for read-only mode, operation not supported")]
ReadOnlyMode,
#[error("Chain id of RPC endpoint missmatch with chain id of gRPC endpoint")]
ChainIdMissmatch,
#[error("RPC authentication token is not supported")]
AuthTokenNotSupported,
#[error("Invalid height: {0}")]
InvalidHeight(u64),
#[error("Invalid private key")]
InvalidPrivateKey,
#[error("RPC endpoint not set")]
RpcEndpointNotSet,
#[error("GRPC endpoint is set but singer is not")]
SignerNotSet,
#[error("Signer is set but GRPC endpoint is not")]
GrpcEndpointNotSet,
}
impl From<jsonrpsee_core::ClientError> for Error {
fn from(value: jsonrpsee_core::ClientError) -> Self {
Error::Rpc(celestia_rpc::Error::JsonRpc(value))
}
}
impl From<serde_json::Error> for Error {
fn from(value: serde_json::Error) -> Self {
jsonrpsee_core::ClientError::ParseError(value).into()
}
}
impl Error {
pub fn as_grpc_status(&self) -> Option<&tonic::Status> {
match self {
Error::Grpc(celestia_grpc::Error::TonicError(status)) => Some(&**status),
_ => None,
}
}
pub fn as_rpc_call_error(&self) -> Option<&jsonrpsee_types::error::ErrorObjectOwned> {
match self {
Error::Rpc(celestia_rpc::Error::JsonRpc(jsonrpsee_core::ClientError::Call(e))) => {
Some(e)
}
_ => None,
}
}
}