Skip to content

Commit

Permalink
Merge pull request #38 from cita-cloud/proto_add_serde
Browse files Browse the repository at this point in the history
proto struct add serde trait
  • Loading branch information
JLerxky authored Nov 20, 2024
2 parents a5a8775 + ed4e887 commit 99e67c4
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 71 deletions.
1 change: 1 addition & 0 deletions cloud-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ http = "1.1"
futures-retry = "0.6"
backoff = "0.4"
async-trait = "0.1"
serde = { version = "1.0", default-features = false, features = ["derive"] }
tracing = "0.1"
tracing-opentelemetry = "0.27"
opentelemetry = "0.26"
Expand Down
3 changes: 3 additions & 0 deletions cloud-proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=protos");
tonic_build::configure()
.out_dir("src/proto")
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
.compile_protos(
&[
"blockchain.proto",
Expand All @@ -33,10 +34,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
)?;
tonic_build::configure()
.out_dir("src/proto")
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
.file_descriptor_set_path("src/reflect/controller.bin")
.compile_protos(&["controller.proto"], &["protos/protos"])?;
tonic_build::configure()
.out_dir("src/proto")
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
.file_descriptor_set_path("src/reflect/executor.bin")
.compile_protos(&["executor.proto", "vm/evm.proto"], &["protos/protos"])?;
}
Expand Down
24 changes: 12 additions & 12 deletions cloud-proto/src/proto/blockchain.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is @generated by prost-build.
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct BlockHeader {
/// hash of previous BlockHeader
#[prost(bytes = "vec", tag = "1")]
Expand All @@ -13,7 +13,7 @@ pub struct BlockHeader {
#[prost(bytes = "vec", tag = "5")]
pub proposer: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct Transaction {
#[prost(uint32, tag = "1")]
pub version: u32,
Expand All @@ -37,15 +37,15 @@ pub struct Transaction {
#[prost(bytes = "vec", tag = "8")]
pub chain_id: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct Witness {
#[prost(bytes = "vec", tag = "1")]
pub signature: ::prost::alloc::vec::Vec<u8>,
/// add to support multi-address, or we don't know which address algorithm to use
#[prost(bytes = "vec", tag = "2")]
pub sender: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct UnverifiedTransaction {
#[prost(message, optional, tag = "1")]
pub transaction: ::core::option::Option<Transaction>,
Expand All @@ -55,7 +55,7 @@ pub struct UnverifiedTransaction {
#[prost(message, optional, tag = "3")]
pub witness: ::core::option::Option<Witness>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct UtxoTransaction {
#[prost(uint32, tag = "1")]
pub version: u32,
Expand All @@ -66,7 +66,7 @@ pub struct UtxoTransaction {
#[prost(uint64, tag = "4")]
pub lock_id: u64,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct UnverifiedUtxoTransaction {
#[prost(message, optional, tag = "1")]
pub transaction: ::core::option::Option<UtxoTransaction>,
Expand All @@ -76,33 +76,33 @@ pub struct UnverifiedUtxoTransaction {
#[prost(message, repeated, tag = "3")]
pub witnesses: ::prost::alloc::vec::Vec<Witness>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct RawTransactions {
#[prost(message, repeated, tag = "1")]
pub body: ::prost::alloc::vec::Vec<RawTransaction>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct RawTransaction {
#[prost(oneof = "raw_transaction::Tx", tags = "1, 2")]
pub tx: ::core::option::Option<raw_transaction::Tx>,
}
/// Nested message and enum types in `RawTransaction`.
pub mod raw_transaction {
#[derive(Clone, PartialEq, ::prost::Oneof)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Oneof)]
pub enum Tx {
#[prost(message, tag = "1")]
NormalTx(super::UnverifiedTransaction),
#[prost(message, tag = "2")]
UtxoTx(super::UnverifiedUtxoTransaction),
}
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct CompactBlockBody {
/// transaction hash of UnverifiedTransaction or UnverifyedUtxoTransaction.
#[prost(bytes = "vec", repeated, tag = "1")]
pub tx_hashes: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct CompactBlock {
#[prost(uint32, tag = "1")]
pub version: u32,
Expand All @@ -111,7 +111,7 @@ pub struct CompactBlock {
#[prost(message, optional, tag = "3")]
pub body: ::core::option::Option<CompactBlockBody>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct Block {
#[prost(uint32, tag = "1")]
pub version: u32,
Expand Down
36 changes: 18 additions & 18 deletions cloud-proto/src/proto/common.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
// This file is @generated by prost-build.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, PartialEq, ::prost::Message)]
pub struct Empty {}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct Hash {
#[prost(bytes = "vec", tag = "1")]
pub hash: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct StateRoot {
#[prost(bytes = "vec", tag = "1")]
pub state_root: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct Proof {
#[prost(bytes = "vec", tag = "1")]
pub proof: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct Hashes {
#[prost(message, repeated, tag = "1")]
pub hashes: ::prost::alloc::vec::Vec<Hash>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct Address {
#[prost(bytes = "vec", tag = "1")]
pub address: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct Proposal {
#[prost(uint64, tag = "1")]
pub height: u64,
#[prost(bytes = "vec", tag = "2")]
pub data: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct ProposalInner {
#[prost(bytes = "vec", tag = "1")]
pub pre_state_root: ::prost::alloc::vec::Vec<u8>,
#[prost(message, optional, tag = "2")]
pub proposal: ::core::option::Option<super::blockchain::CompactBlock>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct ProposalWithProof {
#[prost(message, optional, tag = "1")]
pub proposal: ::core::option::Option<Proposal>,
#[prost(bytes = "vec", tag = "2")]
pub proof: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct ConsensusConfiguration {
#[prost(uint64, tag = "1")]
pub height: u64,
Expand All @@ -56,45 +56,45 @@ pub struct ConsensusConfiguration {
#[prost(bytes = "vec", repeated, tag = "3")]
pub validators: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec<u8>>,
}
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, PartialEq, ::prost::Message)]
pub struct StatusCode {
#[prost(uint32, tag = "1")]
pub code: u32,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct HashResponse {
#[prost(message, optional, tag = "1")]
pub status: ::core::option::Option<StatusCode>,
#[prost(message, optional, tag = "2")]
pub hash: ::core::option::Option<Hash>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct ProposalResponse {
#[prost(message, optional, tag = "1")]
pub status: ::core::option::Option<StatusCode>,
#[prost(message, optional, tag = "2")]
pub proposal: ::core::option::Option<Proposal>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct ConsensusConfigurationResponse {
#[prost(message, optional, tag = "1")]
pub status: ::core::option::Option<StatusCode>,
#[prost(message, optional, tag = "2")]
pub config: ::core::option::Option<ConsensusConfiguration>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct NodeNetInfo {
#[prost(string, tag = "1")]
pub multi_address: ::prost::alloc::string::String,
#[prost(uint64, tag = "2")]
pub origin: u64,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct TotalNodeNetInfo {
#[prost(message, repeated, tag = "1")]
pub nodes: ::prost::alloc::vec::Vec<NodeNetInfo>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct PeerStatus {
#[prost(uint64, tag = "1")]
pub height: u64,
Expand All @@ -103,7 +103,7 @@ pub struct PeerStatus {
#[prost(message, optional, tag = "3")]
pub node_net_info: ::core::option::Option<NodeNetInfo>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct NodeStatus {
#[prost(bool, tag = "1")]
pub is_sync: bool,
Expand Down
10 changes: 5 additions & 5 deletions cloud-proto/src/proto/controller.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// This file is @generated by prost-build.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, PartialEq, ::prost::Message)]
pub struct Flag {
#[prost(bool, tag = "1")]
pub flag: bool,
}
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, PartialEq, ::prost::Message)]
pub struct BlockNumber {
#[prost(uint64, tag = "1")]
pub block_number: u64,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct SystemConfig {
#[prost(uint32, tag = "1")]
pub version: u32,
Expand Down Expand Up @@ -44,12 +44,12 @@ pub struct SystemConfig {
#[prost(bytes = "vec", tag = "16")]
pub block_limit_pre_hash: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, PartialEq, ::prost::Message)]
pub struct TransactionIndex {
#[prost(uint64, tag = "1")]
pub tx_index: u64,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct CrossChainProof {
#[prost(uint32, tag = "1")]
pub version: u32,
Expand Down
14 changes: 7 additions & 7 deletions cloud-proto/src/proto/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is @generated by prost-build.
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct GetCryptoInfoResponse {
#[prost(message, optional, tag = "1")]
pub status: ::core::option::Option<super::common::StatusCode>,
Expand All @@ -12,38 +12,38 @@ pub struct GetCryptoInfoResponse {
#[prost(uint32, tag = "5")]
pub address_len: u32,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct HashDataRequest {
#[prost(bytes = "vec", tag = "1")]
pub data: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct VerifyDataHashRequest {
#[prost(bytes = "vec", tag = "1")]
pub data: ::prost::alloc::vec::Vec<u8>,
#[prost(bytes = "vec", tag = "2")]
pub hash: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct SignMessageRequest {
#[prost(bytes = "vec", tag = "2")]
pub msg: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct SignMessageResponse {
#[prost(message, optional, tag = "1")]
pub status: ::core::option::Option<super::common::StatusCode>,
#[prost(bytes = "vec", tag = "2")]
pub signature: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct RecoverSignatureRequest {
#[prost(bytes = "vec", tag = "1")]
pub msg: ::prost::alloc::vec::Vec<u8>,
#[prost(bytes = "vec", tag = "2")]
pub signature: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)]
pub struct RecoverSignatureResponse {
#[prost(message, optional, tag = "1")]
pub status: ::core::option::Option<super::common::StatusCode>,
Expand Down
Loading

0 comments on commit 99e67c4

Please sign in to comment.