Я на самом деле использую java SDK для Hyperledger Fabri c Blockchain .. Я хочу реализовать случайное одобрение однорангового узла ... Я установил одноранговый узел обнаружения и инициализировал канал, затем попытался вызвать
sendTransactionProposalToEndorsers
но я получил NullPointerException .. это - реализация, которую я сделал ... не могли бы вы помочь мне найти ошибку, которую я сделал: это метод, используемый для инициализации канала и пиров и для отправки транзакции в hyperledger :
CryptoSuite cs = CryptoSuite.Factory.getCryptoSuite();
this.client.setCryptoSuite(cs);
// Configure a user
String resolvedPeerUserPrivateKeyPath = this.properties.getPeerUserPrivateKey();
String resolvedPeerUserCertificatePath = this.properties.getPeerUserCertificate();
File peerUserPrivateKeyFile = new File(resolvedPeerUserPrivateKeyPath);
File peerUserCertificateFile = new File(resolvedPeerUserCertificatePath);
// Configure the Peer CA
String resolvedPeerCAPath = this.properties.getPeerCAPath();
File peerCaFile = new File(resolvedPeerCAPath);
// Configure the Orderer CA
String resolvedOrderedCAPath = this.properties.getOrdererCAPath();
File ordererCaFile = new File(resolvedOrderedCAPath);
// Configure the sample store file
String sampleStoreFilePath = this.properties.getSampleStoreFilePath();
File sampleStoreFile = new File(sampleStoreFilePath);
SampleStore sampleStore = new SampleStore(sampleStoreFile);
// Create the user object
// TODO : Make it configurable
this.peerUser = sampleStore.getMember(this.properties.getPeerUserName(), this.properties.getPeerUserAddress(),
this.properties.getPeerUserMspId(), peerUserPrivateKeyFile, peerUserCertificateFile);
// Use this user for authentication
this.client.setUserContext(this.peerUser);
//Create initial discovery peer.
// Channel foo = client.newChannel("foo"); //create channel that will be discovered.
// Connect to an existing channel
this.channel = this.client.newChannel(this.properties.getChannelName());
// Configure the TLS authentication properties to discuss with peers
Properties peerProperties = new Properties();
peerProperties.setProperty(this.properties.getPeerProperties0Key(), peerCaFile.getAbsolutePath());
peerProperties.setProperty(this.properties.getPeerProperties1Key(), this.properties.getPeerProperties1Value());
peerProperties.setProperty(this.properties.getPeerProperties2Key(), this.properties.getPeerProperties2Value());
// Create the peers' objects
// TODO: Loop on configured peers
Properties ordererProperties = new Properties();
Peer discoveryPeer = this.client.newPeer(this.properties.getPeer0Name(), this.properties.getPeer0Address(),peerProperties);
/* Peer peer0 = this.client.newPeer(this.properties.getPeer0Name(), this.properties.getPeer0Address(),
peerProperties); */
ordererProperties.setProperty(this.properties.getPeerProperties0Key(), ordererCaFile.getAbsolutePath());
ordererProperties.setProperty(this.properties.getPeerProperties1Key(),
this.properties.getPeerProperties1Value());
ordererProperties.setProperty(this.properties.getPeerProperties2Key(),
this.properties.getPeerProperties2Value());
// Create the orderer object
this.orderer = this.client.newOrderer(this.properties.getOrdererName(), this.properties.getOrdererAddress(),
ordererProperties);
// TODO: Loop on configured peers
this.channel.addPeer(discoveryPeer);
// TODO: Loop on configured orderers
this.channel.addOrderer(orderer);
this.channel.initialize();
this.initialized = true;
}
private Pair<Collection<ProposalResponse>, CompletableFuture<TransactionEvent>> sendTransaction(
String chainCodeName, String functionName, String[] arguments)
throws InvalidArgumentException, ProposalException, ServiceDiscoveryException {
TransactionProposalRequest tpr = this.client.newTransactionProposalRequest();
ChaincodeID cid = ChaincodeID.newBuilder().setName(chainCodeName).build();
tpr.setChaincodeID(cid);
tpr.setFcn(functionName);
tpr.setArgs(arguments);
Collection<ProposalResponse> transactionPropResp =
this.channel.sendTransactionProposalToEndorsers(tpr,
createDiscoveryOptions().setEndorsementSelector(ServiceDiscovery.EndorsementSelector.ENDORSEMENT_SELECTION_RANDOM)
.setForceDiscovery(true));
System.out.println("test test peers endorsers " + transactionPropResp);
Collection<ProposalResponse> responses;
try {
responses = this.channel.sendTransactionProposal(tpr);
} catch (Exception e1) {
log.error("Sending trx proposal failed");
throw (e1);
}
Pair<Collection<ProposalResponse>, CompletableFuture<BlockEvent.TransactionEvent>> pair = new Pair<>(responses,
this.channel.sendTransaction(responses));
return pair;
}
```