Skip to content

Commit

Permalink
Auto patch type that causes tendermint_proto dependency issue
Browse files Browse the repository at this point in the history
  • Loading branch information
iboss-ptk committed Sep 8, 2022
1 parent 1e849f7 commit 4121bfe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
29 changes: 5 additions & 24 deletions packages/osmosis-std/src/types/cosmos/staking/v1beta1.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
use osmosis_std_derive::CosmwasmExt;
/// HistoricalInfo contains header and validator information for a given block.
/// It is stored as part of staking module's state, which persists the `n` most
/// recent HistoricalInfo
/// (`n` is set by the staking module's `historical_entries` parameter).

// temporary remove due to tendermint proto not yet supported
// by code gen
// #[derive(
// Clone,
// PartialEq,
// ::prost::Message,
// serde::Serialize,
// serde::Deserialize,
// schemars::JsonSchema,
// CosmwasmExt,
// )]
// #[proto_message(type_url = "/cosmos.staking.v1beta1.HistoricalInfo")]
// pub struct HistoricalInfo {
// #[prost(message, optional, tag = "1")]
// pub header: ::core::option::Option<tendermint_proto::types::Header>,
// #[prost(message, repeated, tag = "2")]
// pub valset: ::prost::alloc::vec::Vec<Validator>,
// }

/// NOTE: The following type is not implemented due to current limitations of code generator
/// which currently has issue with tendermint_proto.
/// This will be fixed in the upcoming release.
#[allow(dead_code)]
struct HistoricalInfo {}
/// CommissionRates defines the initial commission rates to be used for creating
/// a validator.
#[derive(
Expand Down
29 changes: 27 additions & 2 deletions packages/proto-build/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use heck::ToUpperCamelCase;
use log::debug;
use prost_types::FileDescriptorSet;
use regex::Regex;

use syn::{File, Item, ItemMod};
use syn::__private::ToTokens;
use syn::{parse_quote, File, Item, ItemMod};
use walkdir::WalkDir;

use crate::transformers;
Expand Down Expand Up @@ -133,12 +133,37 @@ fn transform_items(
ancestors: &[String],
descriptor: &FileDescriptorSet,
) -> Vec<Item> {
// TODO: Remove this temporary hack when cosmos & tendermint code gen is supported
let remove_struct_fields_that_depends_on_tendermint_proto = |i: Item| match i.clone() {
Item::Struct(s) => {
let is_depending_on_tendermint = s.fields.iter().any(|field| {
let tt = field.ty.to_token_stream();
tt.to_string().contains("tendermint_proto")
});

if is_depending_on_tendermint {
let ident = s.ident;
Item::Struct(parse_quote! {
/// NOTE: The following type is not implemented due to current limitations of code generator
/// which currently has issue with tendermint_proto.
/// This will be fixed in the upcoming release.
#[allow(dead_code)
struct #ident {}
})
} else {
Item::Struct(s)
}
}
_ => i,
};
let items = items
.into_iter()
.map(|i| match i.clone() {
Item::Struct(s) => Item::Struct(transformers::append_attrs(src, &s, descriptor)),
_ => i,
})
// TODO: Remove this temporary hack when cosmos & tendermint code gen is supported
.map(remove_struct_fields_that_depends_on_tendermint_proto)
.map(|i: Item| transform_nested_mod(i, src, ancestors, descriptor))
.collect::<Vec<Item>>();
items
Expand Down

0 comments on commit 4121bfe

Please sign in to comment.