diff --git a/grpc/src/client.rs b/grpc/src/client.rs index c9d68ff78..53c23ba3a 100644 --- a/grpc/src/client.rs +++ b/grpc/src/client.rs @@ -1,3 +1,4 @@ +use prost::Message; use tonic::service::Interceptor; use tonic::transport::Channel; @@ -7,8 +8,8 @@ use celestia_proto::cosmos::base::node::v1beta1::service_client::ServiceClient a use celestia_proto::cosmos::base::tendermint::v1beta1::service_client::ServiceClient as TendermintServiceClient; use celestia_proto::cosmos::tx::v1beta1::service_client::ServiceClient as TxServiceClient; use celestia_tendermint::block::Block; -use celestia_types::auth::AuthParams; -use celestia_types::blob::{Blob, BlobParams}; +use celestia_types::blob::{Blob, BlobParams, RawBlobTx}; +use celestia_types::state::auth::AuthParams; use celestia_types::state::Address; use celestia_types::state::{RawTx, TxResponse}; @@ -74,11 +75,33 @@ where /// Broadcast Tx #[grpc_method(TxServiceClient::broadcast_tx)] async fn broadcast_tx( + &mut self, + tx_bytes: Vec, + mode: BroadcastMode, + ) -> Result; + + pub async fn broadcast_blob_tx( &mut self, tx: RawTx, blobs: Vec, mode: BroadcastMode, - ) -> Result; + ) -> Result { + // From https://github.com/celestiaorg/celestia-core/blob/v1.43.0-tm-v0.34.35/pkg/consts/consts.go#L19 + const BLOB_TX_TYPE_ID: &str = "BLOB"; + + if blobs.is_empty() { + return Err(Error::TxEmptyBlobList); + } + + let blobs = blobs.into_iter().map(Into::into).collect(); + let blob_tx = RawBlobTx { + tx: tx.encode_to_vec(), + blobs, + type_id: BLOB_TX_TYPE_ID.to_string(), + }; + + self.broadcast_tx(blob_tx.encode_to_vec(), mode).await + } /// Get Tx #[grpc_method(TxServiceClient::get_tx)] diff --git a/grpc/src/error.rs b/grpc/src/error.rs index d7fe08c85..9cdb2c7c6 100644 --- a/grpc/src/error.rs +++ b/grpc/src/error.rs @@ -33,4 +33,8 @@ pub enum Error { /// Unexpected reponse type #[error("Unexpected response type")] UnexpectedResponseType(String), + + /// Empty blob submission list + #[error("Attempted to submit blob transaction with empty blob list")] + TxEmptyBlobList, } diff --git a/grpc/src/types/auth.rs b/grpc/src/types/auth.rs index 8d543088d..330f13ca5 100644 --- a/grpc/src/types/auth.rs +++ b/grpc/src/types/auth.rs @@ -5,7 +5,7 @@ use celestia_proto::cosmos::auth::v1beta1::{ QueryAccountRequest, QueryAccountResponse, QueryAccountsRequest, QueryAccountsResponse, QueryParamsRequest as QueryAuthParamsRequest, QueryParamsResponse as QueryAuthParamsResponse, }; -use celestia_types::auth::{ +use celestia_types::state::auth::{ AuthParams, BaseAccount, ModuleAccount, RawBaseAccount, RawModuleAccount, }; use celestia_types::state::Address; diff --git a/grpc/src/types/tx.rs b/grpc/src/types/tx.rs index 68055baf3..9297f75d5 100644 --- a/grpc/src/types/tx.rs +++ b/grpc/src/types/tx.rs @@ -11,8 +11,7 @@ use celestia_proto::cosmos::tx::v1beta1::{ }; use celestia_tendermint::public_key::Secp256k1 as VerifyingKey; use celestia_tendermint_proto::Protobuf; -use celestia_types::auth::BaseAccount; -use celestia_types::blob::{Blob, RawBlob, RawBlobTx}; +use celestia_types::state::auth::BaseAccount; use celestia_types::state::{ AuthInfo, Fee, ModeInfo, RawTx, RawTxBody, SignerInfo, Sum, Tx, TxResponse, }; @@ -66,24 +65,12 @@ impl FromGrpcResponse for RawGetTxResponse { } } -impl IntoGrpcParam for (RawTx, Vec, BroadcastMode) { +impl IntoGrpcParam for (Vec, BroadcastMode) { fn into_parameter(self) -> BroadcastTxRequest { - let (tx, blobs, mode) = self; + let (tx_bytes, mode) = self; - // From https://github.com/celestiaorg/celestia-core/blob/v1.43.0-tm-v0.34.35/pkg/consts/consts.go#L19 - const BLOB_TX_TYPE_ID: &str = "BLOB"; - - // empty blob list causes error response, but this is already checked when creating MsgPayForBlobs - debug_assert!(!blobs.is_empty()); - - let blobs = blobs.into_iter().map(RawBlob::from).collect(); - let blob_tx = RawBlobTx { - tx: tx.encode_to_vec(), - blobs, - type_id: BLOB_TX_TYPE_ID.to_string(), - }; BroadcastTxRequest { - tx_bytes: blob_tx.encode_to_vec(), + tx_bytes, mode: mode.into(), } } diff --git a/grpc/tests/tonic.rs b/grpc/tests/tonic.rs index 2013934ff..07d1387af 100644 --- a/grpc/tests/tonic.rs +++ b/grpc/tests/tonic.rs @@ -97,7 +97,7 @@ async fn submit_blob() { ); let response = client - .broadcast_tx(tx, blobs, BroadcastMode::Sync) + .broadcast_blob_tx(tx, blobs, BroadcastMode::Sync) .await .unwrap(); diff --git a/proto/build.rs b/proto/build.rs index c07f7a8ae..d8fa46173 100644 --- a/proto/build.rs +++ b/proto/build.rs @@ -11,7 +11,6 @@ const BASE64STRING: &str = const QUOTED: &str = r#"#[serde(with = "celestia_tendermint_proto::serializers::from_str")]"#; const VEC_BASE64STRING: &str = r#"#[serde(with = "celestia_tendermint_proto::serializers::bytes::vec_base64string")]"#; -#[cfg(not(feature = "tonic"))] const OPTION_ANY: &str = r#"#[serde(with = "crate::serializers::option_any")]"#; const OPTION_TIMESTAMP: &str = r#"#[serde(with = "crate::serializers::option_timestamp")]"#; const NULL_DEFAULT: &str = r#"#[serde(with = "crate::serializers::null_default")]"#; @@ -53,7 +52,6 @@ static CUSTOM_TYPE_ATTRIBUTES: &[(&str, &str)] = &[ static CUSTOM_FIELD_ATTRIBUTES: &[(&str, &str)] = &[ (".celestia.core.v1.da.DataAvailabilityHeader.row_roots", VEC_BASE64STRING), (".celestia.core.v1.da.DataAvailabilityHeader.column_roots", VEC_BASE64STRING), - #[cfg(not(feature = "tonic"))] (".cosmos.base.abci.v1beta1.TxResponse.tx", OPTION_ANY), (".cosmos.base.abci.v1beta1.TxResponse.logs", NULL_DEFAULT), (".cosmos.base.abci.v1beta1.TxResponse.events", NULL_DEFAULT), diff --git a/proto/src/serializers.rs b/proto/src/serializers.rs index 3c436ffde..d8119ab13 100644 --- a/proto/src/serializers.rs +++ b/proto/src/serializers.rs @@ -1,6 +1,5 @@ //! Custom serializers to be used with [`serde`]. pub mod null_default; -#[cfg(not(feature = "tonic"))] pub mod option_any; pub mod option_timestamp; diff --git a/types/src/lib.rs b/types/src/lib.rs index cffa0c429..d20541d19 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -1,7 +1,6 @@ #![cfg_attr(docsrs, feature(doc_cfg))] #![doc = include_str!("../README.md")] -pub mod auth; mod bit_array; pub mod blob; mod block; diff --git a/types/src/state.rs b/types/src/state.rs index cca599845..e584d1f5a 100644 --- a/types/src/state.rs +++ b/types/src/state.rs @@ -1,6 +1,7 @@ //! Types and interfaces for accessing Celestia's state-relevant information. mod address; +pub mod auth; mod balance; mod query_delegation; mod tx; diff --git a/types/src/auth.rs b/types/src/state/auth.rs similarity index 90% rename from types/src/auth.rs rename to types/src/state/auth.rs index 23b68ac63..18b9ec6b4 100644 --- a/types/src/auth.rs +++ b/types/src/state/auth.rs @@ -16,25 +16,11 @@ use crate::Error; pub use celestia_proto::cosmos::auth::v1beta1::BaseAccount as RawBaseAccount; pub use celestia_proto::cosmos::auth::v1beta1::ModuleAccount as RawModuleAccount; +pub use celestia_proto::cosmos::auth::v1beta1::Params as AuthParams; const COSMOS_ED25519_PUBKEY: &str = "/cosmos.crypto.ed25519.PubKey"; const COSMOS_SECP256K1_PUBKEY: &str = "/cosmos.crypto.secp256k1.PubKey"; -/// Params defines the parameters for the auth module. -#[derive(Debug)] -pub struct AuthParams { - /// Maximum number of memo characters - pub max_memo_characters: u64, - /// Maximum nubmer of signatures - pub tx_sig_limit: u64, - /// Cost per transaction byte - pub tx_size_cost_per_byte: u64, - /// Cost to verify ed25519 signature - pub sig_verify_cost_ed25519: u64, - /// Cost to verify secp255k1 signature - pub sig_verify_cost_secp256k1: u64, -} - /// [`BaseAccount`] defines a base account type. /// /// It contains all the necessary fields for basic account functionality.