fabric-protos icon indicating copy to clipboard operation
fabric-protos copied to clipboard

add csharp namespace option

Open Varorbc opened this issue 1 year ago • 13 comments

part of #227

Varorbc avatar Jun 04 '24 11:06 Varorbc

@jt-nti please review

Varorbc avatar Jun 04 '24 11:06 Varorbc

At first glance, "Hyperledger.Fabric" seems good to me. (I've opened hyperledger-labs/governance#67 to reserve the "Hyperledger" prefix.)

The specific namespaces I looked at mostly seemed reasonable, although I noticed you skipped "orderer". on a couple- was that intentional?

jt-nti avatar Jun 04 '24 14:06 jt-nti

My negligence, I have fixed it.

Varorbc avatar Jun 04 '24 14:06 Varorbc

The build failed. What should I do?

Varorbc avatar Jun 05 '24 15:06 Varorbc

@Varorbc you shouldn't need to do anything about the build failure- it's picking up the incompatible change to the namespace but since C# is new as far as Fabric protos go, I think that's ok. Once the namespaces have been added though, it would be good to avoid any future breaking changes so it's definitely worth getting them right first time.

I've been playing with adding C# bindings and these are the namespaces that came out using the Hyperledger.Fabric.Protos prefix you proposed, so it would be good if the manual csharp_namespace options matched:

$ ls -R
Hyperledger

./Hyperledger:
Fabric

./Hyperledger/Fabric:
Protos

./Hyperledger/Fabric/Protos:
Common          Etcdraft        Google          Kvrwset         Msp             Protos          Rwset
Discovery       Gateway         Gossip          Lifecycle       Orderer         Queryresult     Transientstore

./Hyperledger/Fabric/Protos/Common:
Collection.cs           Configtx.cs             Ledger.cs               Policies.cs
Common.cs               Configuration.cs        MspPrincipal.cs

./Hyperledger/Fabric/Protos/Discovery:
Protocol.cs     ProtocolGrpc.cs

./Hyperledger/Fabric/Protos/Etcdraft:
Configuration.cs        Metadata.cs

./Hyperledger/Fabric/Protos/Gateway:
Gateway.cs      GatewayGrpc.cs

./Hyperledger/Fabric/Protos/Google:
Rpc

./Hyperledger/Fabric/Protos/Google/Rpc:
Status.cs

./Hyperledger/Fabric/Protos/Gossip:
Message.cs      MessageGrpc.cs

./Hyperledger/Fabric/Protos/Kvrwset:
KvRwset.cs

./Hyperledger/Fabric/Protos/Lifecycle:
ChaincodeDefinition.cs  Db.cs                   Lifecycle.cs

./Hyperledger/Fabric/Protos/Msp:
Identities.cs   MspConfig.cs

./Hyperledger/Fabric/Protos/Orderer:
Ab.cs                   Blockattestation.cs     Cluster.cs              Clusterserver.cs        Configuration.cs
AbGrpc.cs               BlockattestationGrpc.cs ClusterGrpc.cs          ClusterserverGrpc.cs    Smartbft

./Hyperledger/Fabric/Protos/Orderer/Smartbft:
Configuration.cs

./Hyperledger/Fabric/Protos/Protos:
Chaincode.cs            Collection.cs           Peer.cs                 ProposalResponse.cs     Snapshot.cs
ChaincodeEvent.cs       Configuration.cs        PeerGrpc.cs             Query.cs                SnapshotGrpc.cs
ChaincodeShim.cs        Events.cs               Policy.cs               Resources.cs            Transaction.cs
ChaincodeShimGrpc.cs    EventsGrpc.cs           Proposal.cs             SignedCcDepSpec.cs

./Hyperledger/Fabric/Protos/Queryresult:
KvQueryResult.cs

./Hyperledger/Fabric/Protos/Rwset:
Rwset.cs

./Hyperledger/Fabric/Protos/Transientstore:
Transientstore.cs

jt-nti avatar Jun 06 '24 11:06 jt-nti

Do you mean that I changed the namespace of KvQueryResult to thisHyperledger.Fabric.Protos.Queryresult.KvQueryResult.cs? R in the word QueryResult is lowercase instead of uppercase?

Varorbc avatar Jun 06 '24 12:06 Varorbc

@Varorbc which do you think is more natural for a C# developer? I can add overrides if you think it would be better to adjust some of the defaults, e.g.

    - file_option: csharp_namespace
      path: ledger/queryresult/kv_query_result.proto
      value: Hyperledger.Fabric.Protos.QueryResult

jt-nti avatar Jun 06 '24 12:06 jt-nti

@jt-nti This is a naming convention, and C# developers prefer PascalCase style.

Varorbc avatar Jun 06 '24 13:06 Varorbc

@Varorbc that makes sense. There also seems to be a convention to only uppercase two letter acronyms, so I think MSP should be Msp. (And similarly SmartBFT should be SmartBft in #229)

jt-nti avatar Jun 07 '24 16:06 jt-nti

@jt-nti I think it's all right whether the abbreviation of a phrase is capitalized or capitalized, depending on which one you think is better, but there are some special cases, such as RSA, which use all capitals instead of Rsa.

Varorbc avatar Jun 08 '24 00:06 Varorbc

I see that MSPConfig is used here, not MspConfig.

I see that SmartBFT is used here, not SmartBft.

Varorbc avatar Jun 08 '24 00:06 Varorbc

@Varorbc the actual message names in the proto files don't follow the C# conventions and I don't know of any way to customise them in code generation, but I think it probably makes sense to follow the acronym conventions for the new namespaces.

https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/capitalization-conventions?redirectedfrom=MSDN

jt-nti avatar Jun 10 '24 10:06 jt-nti

Yes, it seems that there is no way to customize the message name.

Varorbc avatar Jun 10 '24 11:06 Varorbc