Skip to content

Commit

Permalink
Reorganize proto
Browse files Browse the repository at this point in the history
  • Loading branch information
CriesofCarrots committed Sep 29, 2020
1 parent 403f826 commit 661eff3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 39 deletions.
4 changes: 2 additions & 2 deletions storage-bigtable/build-proto/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

package Generated;
package solana.bigtable.ConfirmedBlock;

message ConfirmedBlock {
string previous_blockhash = 1;
Expand Down Expand Up @@ -64,4 +64,4 @@ message Reward {

message UnixTimestamp {
int64 timestamp = 1;
}
}
4 changes: 2 additions & 2 deletions storage-bigtable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
71 changes: 38 additions & 33 deletions storage-bigtable/src/proto/mod.rs → storage-bigtable/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Reward> for generated::Reward {
impl From<Reward> for prost::Reward {
fn from(reward: Reward) -> Self {
Self {
pubkey: reward.pubkey,
Expand All @@ -22,16 +27,16 @@ impl From<Reward> for generated::Reward {
}
}

impl From<generated::Reward> for Reward {
fn from(reward: generated::Reward) -> Self {
impl From<prost::Reward> for Reward {
fn from(reward: prost::Reward) -> Self {
Self {
pubkey: reward.pubkey,
lamports: reward.lamports,
}
}
}

impl From<ConfirmedBlock> for generated::ConfirmedBlock {
impl From<ConfirmedBlock> for prost::ConfirmedBlock {
fn from(confirmed_block: ConfirmedBlock) -> Self {
let ConfirmedBlock {
previous_blockhash,
Expand All @@ -48,17 +53,17 @@ impl From<ConfirmedBlock> 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<generated::ConfirmedBlock> for ConfirmedBlock {
impl TryFrom<prost::ConfirmedBlock> for ConfirmedBlock {
type Error = bincode::Error;
fn try_from(
confirmed_block: generated::ConfirmedBlock,
confirmed_block: prost::ConfirmedBlock,
) -> std::result::Result<Self, Self::Error> {
let generated::ConfirmedBlock {
let prost::ConfirmedBlock {
previous_blockhash,
blockhash,
parent_slot,
Expand All @@ -76,12 +81,12 @@ impl TryFrom<generated::ConfirmedBlock> for ConfirmedBlock {
.map(|tx| tx.try_into())
.collect::<std::result::Result<Vec<TransactionWithStatusMeta>, 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<TransactionWithStatusMeta> for generated::ConfirmedTransaction {
impl From<TransactionWithStatusMeta> for prost::ConfirmedTransaction {
fn from(value: TransactionWithStatusMeta) -> Self {
let meta = if let Some(meta) = value.meta {
Some(meta.into())
Expand All @@ -95,9 +100,9 @@ impl From<TransactionWithStatusMeta> for generated::ConfirmedTransaction {
}
}

impl TryFrom<generated::ConfirmedTransaction> for TransactionWithStatusMeta {
impl TryFrom<prost::ConfirmedTransaction> for TransactionWithStatusMeta {
type Error = bincode::Error;
fn try_from(value: generated::ConfirmedTransaction) -> std::result::Result<Self, Self::Error> {
fn try_from(value: prost::ConfirmedTransaction) -> std::result::Result<Self, Self::Error> {
let meta = if let Some(meta) = value.meta {
Some(meta.try_into()?)
} else {
Expand All @@ -110,7 +115,7 @@ impl TryFrom<generated::ConfirmedTransaction> for TransactionWithStatusMeta {
}
}

impl From<Transaction> for generated::Transaction {
impl From<Transaction> for prost::Transaction {
fn from(value: Transaction) -> Self {
Self {
signatures: value
Expand All @@ -123,8 +128,8 @@ impl From<Transaction> for generated::Transaction {
}
}

impl From<generated::Transaction> for Transaction {
fn from(value: generated::Transaction) -> Self {
impl From<prost::Transaction> for Transaction {
fn from(value: prost::Transaction) -> Self {
Self {
signatures: value
.signatures
Expand All @@ -136,7 +141,7 @@ impl From<generated::Transaction> for Transaction {
}
}

impl From<Message> for generated::Message {
impl From<Message> for prost::Message {
fn from(value: Message) -> Self {
Self {
header: Some(value.header.into()),
Expand All @@ -151,8 +156,8 @@ impl From<Message> for generated::Message {
}
}

impl From<generated::Message> for Message {
fn from(value: generated::Message) -> Self {
impl From<prost::Message> for Message {
fn from(value: prost::Message) -> Self {
Self {
header: value.header.expect("header is required").into(),
account_keys: value
Expand All @@ -166,7 +171,7 @@ impl From<generated::Message> for Message {
}
}

impl From<MessageHeader> for generated::MessageHeader {
impl From<MessageHeader> for prost::MessageHeader {
fn from(value: MessageHeader) -> Self {
Self {
num_required_signatures: value.num_required_signatures as u32,
Expand All @@ -176,8 +181,8 @@ impl From<MessageHeader> for generated::MessageHeader {
}
}

impl From<generated::MessageHeader> for MessageHeader {
fn from(value: generated::MessageHeader) -> Self {
impl From<prost::MessageHeader> 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,
Expand All @@ -186,7 +191,7 @@ impl From<generated::MessageHeader> for MessageHeader {
}
}

impl From<TransactionStatusMeta> for generated::TransactionStatusMeta {
impl From<TransactionStatusMeta> for prost::TransactionStatusMeta {
fn from(value: TransactionStatusMeta) -> Self {
let TransactionStatusMeta {
status,
Expand All @@ -197,7 +202,7 @@ impl From<TransactionStatusMeta> 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"),
}),
};
Expand All @@ -216,11 +221,11 @@ impl From<TransactionStatusMeta> for generated::TransactionStatusMeta {
}
}

impl TryFrom<generated::TransactionStatusMeta> for TransactionStatusMeta {
impl TryFrom<prost::TransactionStatusMeta> for TransactionStatusMeta {
type Error = bincode::Error;

fn try_from(value: generated::TransactionStatusMeta) -> std::result::Result<Self, Self::Error> {
let generated::TransactionStatusMeta {
fn try_from(value: prost::TransactionStatusMeta) -> std::result::Result<Self, Self::Error> {
let prost::TransactionStatusMeta {
err,
fee,
pre_balances,
Expand All @@ -247,7 +252,7 @@ impl TryFrom<generated::TransactionStatusMeta> for TransactionStatusMeta {
}
}

impl From<InnerInstructions> for generated::InnerInstructions {
impl From<InnerInstructions> for prost::InnerInstructions {
fn from(value: InnerInstructions) -> Self {
Self {
index: value.index as u32,
Expand All @@ -256,16 +261,16 @@ impl From<InnerInstructions> for generated::InnerInstructions {
}
}

impl From<generated::InnerInstructions> for InnerInstructions {
fn from(value: generated::InnerInstructions) -> Self {
impl From<prost::InnerInstructions> for InnerInstructions {
fn from(value: prost::InnerInstructions) -> Self {
Self {
index: value.index as u8,
instructions: value.instructions.into_iter().map(|i| i.into()).collect(),
}
}
}

impl From<CompiledInstruction> for generated::CompiledInstruction {
impl From<CompiledInstruction> for prost::CompiledInstruction {
fn from(value: CompiledInstruction) -> Self {
Self {
program_id_index: value.program_id_index as u32,
Expand All @@ -275,8 +280,8 @@ impl From<CompiledInstruction> for generated::CompiledInstruction {
}
}

impl From<generated::CompiledInstruction> for CompiledInstruction {
fn from(value: generated::CompiledInstruction) -> Self {
impl From<prost::CompiledInstruction> for CompiledInstruction {
fn from(value: prost::CompiledInstruction) -> Self {
Self {
program_id_index: value.program_id_index as u8,
accounts: value.accounts,
Expand Down

0 comments on commit 661eff3

Please sign in to comment.