Skip to content

Duplicate Method when trying to create proto files for rust #258

@arne-fuchs

Description

@arne-fuchs

Hello,
I am currently implement the Fabric Rust SDK and wanted to generate the proto files for rust.
I am currently using this build.rs to generate the files:

use std::path::PathBuf;
use std::path::Path;
use std::fs;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    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<PathBuf> {
    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:

impl<T> ChaincodeClient<T>
    where
        T: tonic::client::GrpcService<tonic::body::Body>,
        T::Error: Into<StdError>,
        T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
        <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
    {
        pub async fn connect(
            &mut self,
            request: impl tonic::IntoStreamingRequest<Message = super::ChaincodeMessage>,
        ) -> std::result::Result<
            tonic::Response<tonic::codec::Streaming<super::ChaincodeMessage>>,
            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:

 impl ChaincodeClient<tonic::transport::Channel> {
        /// Attempt to create a new client by connecting to a given endpoint.
        pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
        where
            D: TryInto<tonic::transport::Endpoint>,
            D::Error: Into<StdError>,
        {
            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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions