fabric java sdk peerorganizations文件
时间: 2023-12-03 14:45:38 浏览: 93
在使用Hyperledger Fabric Java SDK时,`peerOrganizations`文件夹是存放组织信息的地方。在这个文件夹下一般会有多个组织的文件夹,每个文件夹都包含了该组织的证书和私钥。
在Java SDK中,`peerOrganizations`文件夹的路径可以通过创建`HFClient`对象时传入的`config`参数来指定。例如:
```
HFClient client = HFClient.createNewInstance();
client.setCryptoSuite(CryptoSuite.Factory.getCryptoSuite());
client.setUserContext(userContext);
client.loadChannelFromConfig(channelName, config);
```
其中,`config`参数可以通过以下代码创建:
```
File configFile = new File("/path/to/config.yaml");
Config config = Config.fromYamlFile(configFile);
```
在这个`config.yaml`文件中,可以指定`peerOrganizations`文件夹的路径,例如:
```
network:
channels:
mychannel:
peers:
peer0.org1.example.com:
endorsingPeer: true
chaincodeQuery: true
ledgerQuery: true
eventSource: true
policies:
queryChannelConfig:
minResponses: 1
maxTargets: 1
retryOpts:
attempts: 5
initialBackoff: 500ms
maxBackoff: 5s
backoffFactor: 2.0
eventSubscription:
minResponses: 1
maxTargets: 1
retryOpts:
attempts: 3
initialBackoff: 500ms
maxBackoff: 5s
backoffFactor: 2.0
consortiums:
SampleConsortium:
organizations:
- Org1
- Org2
organizations:
Org1:
mspid: Org1MSP
peers:
- peer0.org1.example.com
- peer1.org1.example.com
certificateAuthorities:
- ca.org1.example.com
adminPrivateKey:
path: /path/to/org1/admin/private_key.pem
signedCert:
path: /path/to/org1/admin/cert.pem
Org2:
mspid: Org2MSP
peers:
- peer0.org2.example.com
- peer1.org2.example.com
certificateAuthorities:
- ca.org2.example.com
adminPrivateKey:
path: /path/to/org2/admin/private_key.pem
signedCert:
path: /path/to/org2/admin/cert.pem
orderers:
orderer.example.com:
url: grpcs://orderer.example.com:7050
grpcOptions:
ssl-target-name-override: orderer.example.com
tlsCACerts:
path: /path/to/orderer/tls/ca.crt
peerOrganizations:
org1.example.com:
mspid: Org1MSP
peers:
- peer0.org1.example.com
- peer1.org1.example.com
certificateAuthorities:
- ca.org1.example.com
adminPrivateKey:
path: /path/to/org1/admin/private_key.pem
signedCert:
path: /path/to/org1/admin/cert.pem
org2.example.com:
mspid: Org2MSP
peers:
- peer0.org2.example.com
- peer1.org2.example.com
certificateAuthorities:
- ca.org2.example.com
adminPrivateKey:
path: /path/to/org2/admin/private_key.pem
signedCert:
path: /path/to/org2/admin/cert.pem
orderer.example.com:
url: grpcs://orderer.example.com:7050
grpcOptions:
ssl-target-name-override: orderer.example.com
tlsCACerts:
path: /path/to/orderer/tls/ca.crt
```
在这个例子中,`peerOrganizations`文件夹的路径是相对于`config.yaml`文件所在的路径的。如果需要使用绝对路径,可以直接将绝对路径指定在`path`属性中。
阅读全文