From 661eff3d0603020d3d386fa75b4c5e855f1a8a6f Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Tue, 29 Sep 2020 16:42:46 -0600 Subject: [PATCH] Reorganize proto --- storage-bigtable/build-proto/src/main.rs | 4 +- .../solana.bigtable.confirmed_block.rs} | 0 .../src/{proto => }/confirmed_block.proto | 4 +- storage-bigtable/src/lib.rs | 4 +- .../src/{proto/mod.rs => utils.rs} | 71 ++++++++++--------- 5 files changed, 44 insertions(+), 39 deletions(-) rename storage-bigtable/{src/proto/generated.rs => proto/solana.bigtable.confirmed_block.rs} (100%) rename storage-bigtable/src/{proto => }/confirmed_block.proto (97%) rename storage-bigtable/src/{proto/mod.rs => utils.rs} (76%) diff --git a/storage-bigtable/build-proto/src/main.rs b/storage-bigtable/build-proto/src/main.rs index 3cb4a42c9cf6c8..1afc36df440503 100644 --- a/storage-bigtable/build-proto/src/main.rs +++ b/storage-bigtable/build-proto/src/main.rs @@ -17,8 +17,8 @@ fn main() -> Result<(), std::io::Error> { &[googleapis], )?; - let out_dir = manifest_dir.join("../src/proto"); - let proto_files = manifest_dir.join("../src/proto"); + let out_dir = manifest_dir.join("../proto"); + let proto_files = manifest_dir.join("../src"); println!("Protobuf directory: {}", proto_files.display()); println!("output directory: {}", out_dir.display()); diff --git a/storage-bigtable/src/proto/generated.rs b/storage-bigtable/proto/solana.bigtable.confirmed_block.rs similarity index 100% rename from storage-bigtable/src/proto/generated.rs rename to storage-bigtable/proto/solana.bigtable.confirmed_block.rs diff --git a/storage-bigtable/src/proto/confirmed_block.proto b/storage-bigtable/src/confirmed_block.proto similarity index 97% rename from storage-bigtable/src/proto/confirmed_block.proto rename to storage-bigtable/src/confirmed_block.proto index e3b085627925e0..762dd1faf4b825 100644 --- a/storage-bigtable/src/proto/confirmed_block.proto +++ b/storage-bigtable/src/confirmed_block.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package Generated; +package solana.bigtable.ConfirmedBlock; message ConfirmedBlock { string previous_blockhash = 1; @@ -64,4 +64,4 @@ message Reward { message UnixTimestamp { int64 timestamp = 1; -} \ No newline at end of file +} diff --git a/storage-bigtable/src/lib.rs b/storage-bigtable/src/lib.rs index 26bef199a89ee1..a88faa8b5294e1 100644 --- a/storage-bigtable/src/lib.rs +++ b/storage-bigtable/src/lib.rs @@ -20,9 +20,9 @@ extern crate serde_derive; mod access_token; mod bigtable; mod compression; -mod proto; +mod utils; mod root_ca_certificate; -use proto::generated as prost; +use utils::prost; #[derive(Debug, Error)] pub enum Error { diff --git a/storage-bigtable/src/proto/mod.rs b/storage-bigtable/src/utils.rs similarity index 76% rename from storage-bigtable/src/proto/mod.rs rename to storage-bigtable/src/utils.rs index 2fc9b14374af6e..81f65580bdd258 100644 --- a/storage-bigtable/src/proto/mod.rs +++ b/storage-bigtable/src/utils.rs @@ -11,9 +11,14 @@ use solana_transaction_status::{ }; use std::convert::{TryFrom, TryInto}; -pub mod generated; +pub mod prost { + include!(concat!( + env!("CARGO_MANIFEST_DIR"), + concat!("/proto/solana.bigtable.confirmed_block.rs") + )); +} -impl From for generated::Reward { +impl From for prost::Reward { fn from(reward: Reward) -> Self { Self { pubkey: reward.pubkey, @@ -22,8 +27,8 @@ impl From for generated::Reward { } } -impl From for Reward { - fn from(reward: generated::Reward) -> Self { +impl From for Reward { + fn from(reward: prost::Reward) -> Self { Self { pubkey: reward.pubkey, lamports: reward.lamports, @@ -31,7 +36,7 @@ impl From for Reward { } } -impl From for generated::ConfirmedBlock { +impl From for prost::ConfirmedBlock { fn from(confirmed_block: ConfirmedBlock) -> Self { let ConfirmedBlock { previous_blockhash, @@ -48,17 +53,17 @@ impl From for generated::ConfirmedBlock { parent_slot, transactions: transactions.into_iter().map(|tx| tx.into()).collect(), rewards: rewards.into_iter().map(|r| r.into()).collect(), - block_time: block_time.map(|timestamp| generated::UnixTimestamp { timestamp }), + block_time: block_time.map(|timestamp| prost::UnixTimestamp { timestamp }), } } } -impl TryFrom for ConfirmedBlock { +impl TryFrom for ConfirmedBlock { type Error = bincode::Error; fn try_from( - confirmed_block: generated::ConfirmedBlock, + confirmed_block: prost::ConfirmedBlock, ) -> std::result::Result { - let generated::ConfirmedBlock { + let prost::ConfirmedBlock { previous_blockhash, blockhash, parent_slot, @@ -76,12 +81,12 @@ impl TryFrom for ConfirmedBlock { .map(|tx| tx.try_into()) .collect::, Self::Error>>()?, rewards: rewards.into_iter().map(|r| r.into()).collect(), - block_time: block_time.map(|generated::UnixTimestamp { timestamp }| timestamp), + block_time: block_time.map(|prost::UnixTimestamp { timestamp }| timestamp), }) } } -impl From for generated::ConfirmedTransaction { +impl From for prost::ConfirmedTransaction { fn from(value: TransactionWithStatusMeta) -> Self { let meta = if let Some(meta) = value.meta { Some(meta.into()) @@ -95,9 +100,9 @@ impl From for generated::ConfirmedTransaction { } } -impl TryFrom for TransactionWithStatusMeta { +impl TryFrom for TransactionWithStatusMeta { type Error = bincode::Error; - fn try_from(value: generated::ConfirmedTransaction) -> std::result::Result { + fn try_from(value: prost::ConfirmedTransaction) -> std::result::Result { let meta = if let Some(meta) = value.meta { Some(meta.try_into()?) } else { @@ -110,7 +115,7 @@ impl TryFrom for TransactionWithStatusMeta { } } -impl From for generated::Transaction { +impl From for prost::Transaction { fn from(value: Transaction) -> Self { Self { signatures: value @@ -123,8 +128,8 @@ impl From for generated::Transaction { } } -impl From for Transaction { - fn from(value: generated::Transaction) -> Self { +impl From for Transaction { + fn from(value: prost::Transaction) -> Self { Self { signatures: value .signatures @@ -136,7 +141,7 @@ impl From for Transaction { } } -impl From for generated::Message { +impl From for prost::Message { fn from(value: Message) -> Self { Self { header: Some(value.header.into()), @@ -151,8 +156,8 @@ impl From for generated::Message { } } -impl From for Message { - fn from(value: generated::Message) -> Self { +impl From for Message { + fn from(value: prost::Message) -> Self { Self { header: value.header.expect("header is required").into(), account_keys: value @@ -166,7 +171,7 @@ impl From for Message { } } -impl From for generated::MessageHeader { +impl From for prost::MessageHeader { fn from(value: MessageHeader) -> Self { Self { num_required_signatures: value.num_required_signatures as u32, @@ -176,8 +181,8 @@ impl From for generated::MessageHeader { } } -impl From for MessageHeader { - fn from(value: generated::MessageHeader) -> Self { +impl From for MessageHeader { + fn from(value: prost::MessageHeader) -> Self { Self { num_required_signatures: value.num_required_signatures as u8, num_readonly_signed_accounts: value.num_readonly_signed_accounts as u8, @@ -186,7 +191,7 @@ impl From for MessageHeader { } } -impl From for generated::TransactionStatusMeta { +impl From for prost::TransactionStatusMeta { fn from(value: TransactionStatusMeta) -> Self { let TransactionStatusMeta { status, @@ -197,7 +202,7 @@ impl From for generated::TransactionStatusMeta { } = value; let err = match status { Ok(()) => None, - Err(err) => Some(generated::TransactionError { + Err(err) => Some(prost::TransactionError { err: bincode::serialize(&err).expect("transaction error to serialize to bytes"), }), }; @@ -216,11 +221,11 @@ impl From for generated::TransactionStatusMeta { } } -impl TryFrom for TransactionStatusMeta { +impl TryFrom for TransactionStatusMeta { type Error = bincode::Error; - fn try_from(value: generated::TransactionStatusMeta) -> std::result::Result { - let generated::TransactionStatusMeta { + fn try_from(value: prost::TransactionStatusMeta) -> std::result::Result { + let prost::TransactionStatusMeta { err, fee, pre_balances, @@ -247,7 +252,7 @@ impl TryFrom for TransactionStatusMeta { } } -impl From for generated::InnerInstructions { +impl From for prost::InnerInstructions { fn from(value: InnerInstructions) -> Self { Self { index: value.index as u32, @@ -256,8 +261,8 @@ impl From for generated::InnerInstructions { } } -impl From for InnerInstructions { - fn from(value: generated::InnerInstructions) -> Self { +impl From for InnerInstructions { + fn from(value: prost::InnerInstructions) -> Self { Self { index: value.index as u8, instructions: value.instructions.into_iter().map(|i| i.into()).collect(), @@ -265,7 +270,7 @@ impl From for InnerInstructions { } } -impl From for generated::CompiledInstruction { +impl From for prost::CompiledInstruction { fn from(value: CompiledInstruction) -> Self { Self { program_id_index: value.program_id_index as u32, @@ -275,8 +280,8 @@ impl From for generated::CompiledInstruction { } } -impl From for CompiledInstruction { - fn from(value: generated::CompiledInstruction) -> Self { +impl From for CompiledInstruction { + fn from(value: prost::CompiledInstruction) -> Self { Self { program_id_index: value.program_id_index as u8, accounts: value.accounts,