hyperledger / hyperledger/fabric-protos

Duplicate Method when trying to create proto files for rust

Open
#258 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Protocol Buffer
Stars
43
Forks
75
Avg merge
16h 55m
Merged PRs (30d)
5

Description

Hello,
I am currently implement the [Fabric Rust SDK](https://github.com/LF-Decentralized-Trust-labs/fabric-sdk-rust) and wanted to generate the proto files for rust.
I am currently using this build.rs to generate the files:
```rust
use std::path::PathBuf;
use std::path::Path;
use std::fs;

fn main() -> Result<(), Box> {
let proto_dir = PathBuf::from("fabric-protos");

if !proto_dir.exists() {
panic!("Fabric Proto directory does not exist: {:?} Did you initialize the git submodules?", proto_dir);
}

// Find all .proto files in the repository
let proto_files = find_proto_files(&proto_dir);

let mut config = tonic_build::Config::new();
config.out_dir("src/protos");

tonic_build::configure()
.build_server(true)
.build_client(true)
.compile_protos_with_config(config, &proto_files, &[proto_dir])?;
Ok(())
}
fn find_proto_files(dir: &Path) -> Vec {
let mut proto_files = Vec::new();

if let Ok(entries) = fs::read_dir(dir) {
for entry in entries.filter_map(Result::ok) {
let path = entry.path();

if path.is_dir() {
// Recursively search subdirectories
proto_files.extend(find_proto_files(&path));
} else if path.extension().map_or(false, |ext| ext == "proto") {
proto_files.push(path);
}
}
}

proto_files
}
```
One of the resulting files (called protos.rs) will have a method called "connect" which is defined two times (Line 1190 and 1264 in the resulting protos.rs file)

Method 1:
```rust
impl ChaincodeClient
where
T: tonic::client::GrpcService,
T::Error: Into,
T::ResponseBody: Body + std::marker::Send + 'static,
::Error: Into + std::marker::Send,
{
pub async fn connect(
&mut self,
request: impl tonic::IntoStreamingRequest,
) -> std::result::Result<
tonic::Response>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static("/protos.Chaincode/Connect");
let mut req = request.into_streaming_request();
req.extensions_mut().insert(GrpcMethod::new("protos.Chaincode", "Connect"));
self.inner.streaming(req, path, codec).await
}
```
Method 2:
```rust
impl ChaincodeClient {
/// Attempt to create a new client by connecting to a given endpoint.
pub async fn connect(dst: D) -> Result
where
D: TryInto,
D::Error: Into,
{
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
Ok(Self::new(conn))
}
}
```

I either need help fixing this without manually patching after every build, or maybe a rust binding will be implemented on this repo.

Thank you very much

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.