Package org.hyperledger.fabric.sdk
Class HFClient
java.lang.Object
org.hyperledger.fabric.sdk.HFClient
-
Method Summary
Modifier and TypeMethodDescriptionstatic HFClientcreateNewInstance create a new instance of the HFClientdeSerializeChannel(byte[] channelBytes) Deserialize a channel serialized byChannel.serializeChannel()deSerializeChannel(File file) Deserialize a channel serialized byChannel.serializeChannel()getChannel(String name) getChannel by namebyte[]getChannelConfigurationSignature(ChannelConfiguration channelConfiguration, User signer) Get signature for channel configurationorg.hyperledger.fabric.sdk.security.CryptoSuitebyte[]getUpdateChannelConfigurationSignature(UpdateChannelConfiguration updateChannelConfiguration, User signer) Get signature for update channel configurationloadChannelFromConfig(String channelName, NetworkConfig networkConfig) Configures a channel based on information loaded from a Network Config file.loadChannelFromConfig(String channelName, NetworkConfig networkConfig, NetworkConfig.NetworkConfigAddPeerHandler networkConfigAddPeerHandler, NetworkConfig.NetworkConfigAddOrdererHandler networkConfigAddOrdererHandler) Configures a channel based on information loaded from a Network Config file.newChannel(String name) newChannel - already configured channel.newChannel(String name, Orderer orderer, ChannelConfiguration channelConfiguration, byte[]... channelConfigurationSignatures) Create a new channelDeprecated.Deprecated.SeeLifecycleCommitChaincodeDefinitionRequestfor defining the chaincode and and thenTransactionRequest.setInit(boolean)to do the initialization if it's required by the chaincode.newLifecycleApproveChaincodeDefinitionForMyOrgRequest get new Install proposal request.newLifecycleApproveChaincodeDefinitionForMyOrgRequest get new Install proposal request.newInstallProposalRequest get new Query Install proposal request.Create a new QueryChaincodeDefinitions proposal request.Get newLifecycleQueryInstalledChaincodeRequest to find chaincodes installed.LifecycleQueryInstalledChaincodesRequest get new Query Install proposal request.Get a LifecycleSimulateCommitChaincodeDefinitionRequest to find which chaincodes are approved by which organization.newOrderer(String name, String grpcURL) Create a new urlOrderer.newOrderer(String name, String grpcURL, Properties properties) Create a new orderer.newPeer create a new peernewPeer(String name, String grpcURL, Properties properties) newPeer create a new peerget QueryLifecycleQueryChaincodeDefinitionRequest find which chaincodes are defined.newQueryProposalRequest get new query proposal request.newTransactionProposalRequest get new transaction proposal request.Deprecated.SeeLifecycleCommitChaincodeDefinitionRequestfor defining the chaincode and and thenTransactionRequest.setInit(boolean)to do the initialization if it's required by the chaincode.queryChannels(Peer peer) Query the joined channels for peersList<org.hyperledger.fabric.protos.peer.Query.ChaincodeInfo>queryInstalledChaincodes(Peer peer) Deprecated.sendInstallProposal(InstallProposalRequest installProposalRequest, Collection<Peer> peers) Deprecated.sendLifecycleInstallChaincodeRequest(LifecycleInstallChaincodeRequest lifecycleInstallChaincodeRequest, Collection<Peer> peers) Send install chaincode request proposal to peers.sendLifecycleQueryInstalledChaincode(LifecycleQueryInstalledChaincodeRequest lifecycleQueryInstalledChaincodeRequest, Collection<Peer> peers) Query installed chaincode on a peer.sendLifecycleQueryInstalledChaincodes(LifecycleQueryInstalledChaincodesRequest lifecycleQueryInstalledChaincodesRequest, Collection<Peer> peers) Query the peer for installed chaincodes informationvoidsetCryptoSuite(org.hyperledger.fabric.sdk.security.CryptoSuite cryptoSuite) voidsetExecutorService(ExecutorService executorService) Set executor service Applications need to set the executor service prior to doing any other operations on the client.setUserContext(User userContext) Set the User context for this client.
-
Method Details
-
getExecutorService
-
getUserContext
-
getCryptoSuite
public org.hyperledger.fabric.sdk.security.CryptoSuite getCryptoSuite() -
setCryptoSuite
public void setCryptoSuite(org.hyperledger.fabric.sdk.security.CryptoSuite cryptoSuite) throws CryptoException, InvalidArgumentException -
setExecutorService
Set executor service Applications need to set the executor service prior to doing any other operations on the client.- Parameters:
executorService- The executor service the application wants to use.- Throws:
InvalidArgumentException- if executor service has been set already.
-
createNewInstance
createNewInstance create a new instance of the HFClient- Returns:
- client
-
loadChannelFromConfig
public Channel loadChannelFromConfig(String channelName, NetworkConfig networkConfig, NetworkConfig.NetworkConfigAddPeerHandler networkConfigAddPeerHandler, NetworkConfig.NetworkConfigAddOrdererHandler networkConfigAddOrdererHandler) throws InvalidArgumentException, NetworkConfigurationException Configures a channel based on information loaded from a Network Config file. Note that it is up to the caller to initialize the returned channel.- Parameters:
channelName- The name of the channel to be configurednetworkConfig- The network configuration to use to configure the channelnetworkConfigAddPeerHandler- A handler that will create and add peers to the channel.networkConfigAddOrdererHandler- A handler that will create orderers and add orderers to the channel.- Returns:
- The configured channel, or null if the channel is not defined in the configuration
- Throws:
InvalidArgumentExceptionNetworkConfigurationException
-
loadChannelFromConfig
public Channel loadChannelFromConfig(String channelName, NetworkConfig networkConfig) throws InvalidArgumentException, NetworkConfigurationException Configures a channel based on information loaded from a Network Config file. Note that it is up to the caller to initialize the returned channel.- Parameters:
channelName- The name of the channel to be configurednetworkConfig- The network configuration to use to configure the channel- Returns:
- The configured channel, or null if the channel is not defined in the configuration
- Throws:
InvalidArgumentExceptionNetworkConfigurationException
-
newChannel
newChannel - already configured channel.- Parameters:
name-- Returns:
- a new channel.
- Throws:
InvalidArgumentException
-
newChannel
public Channel newChannel(String name, Orderer orderer, ChannelConfiguration channelConfiguration, byte[]... channelConfigurationSignatures) throws TransactionException, InvalidArgumentException Create a new channel- Parameters:
name- The channel's nameorderer- Orderer to create the channel with.channelConfiguration- Channel configuration data.channelConfigurationSignatures- byte arrays containing ConfigSignature's proto serialized. SeeChannel.getChannelConfigurationSignature(org.hyperledger.fabric.sdk.ChannelConfiguration, org.hyperledger.fabric.sdk.User)on how to create- Returns:
- a new channel.
- Throws:
TransactionExceptionInvalidArgumentException
-
deSerializeChannel
public Channel deSerializeChannel(File file) throws IOException, ClassNotFoundException, InvalidArgumentException Deserialize a channel serialized byChannel.serializeChannel()- Parameters:
file- a file which contains the bytes to be deserialized.- Returns:
- A Channel that has not been initialized.
- Throws:
IOExceptionClassNotFoundExceptionInvalidArgumentException
-
deSerializeChannel
public Channel deSerializeChannel(byte[] channelBytes) throws IOException, ClassNotFoundException, InvalidArgumentException Deserialize a channel serialized byChannel.serializeChannel()- Parameters:
channelBytes- bytes to be deserialized.- Returns:
- A Channel that has not been initialized.
- Throws:
IOExceptionClassNotFoundExceptionInvalidArgumentException
-
newPeer
public Peer newPeer(String name, String grpcURL, Properties properties) throws InvalidArgumentException newPeer create a new peer- Parameters:
name- name of peer.grpcURL- to the peer's locationproperties-Supported properties
- pemFile - File location for x509 pem certificate for SSL.
- pemBytes - byte array for x509 pem certificates for SSL
- trustServerCertificate - boolen(true/false) override CN to match pemFile certificate -- for development only. If the pemFile has the target server's certificate (instead of a CA Root certificate), instruct the TLS client to trust the CN value of the certificate in the pemFile, useful in development to get past default server hostname verification during TLS handshake, when the server host name does not match the certificate.
- clientKeyFile - File location for private key pem for mutual TLS
- clientCertFile - File location for x509 pem certificate for mutual TLS
- clientKeyBytes - Private key pem bytes for mutual TLS
- clientCertBytes - x509 pem certificate bytes for mutual TLS
- hostnameOverride - Specify the certificates CN -- for development only.
- sslProvider - Specify the SSL provider, openSSL or JDK.
- negotiationType - Specify the type of negotiation, TLS or plainText.
- If the pemFile does not represent the server certificate, use this property to specify the URI authority (a.k.a hostname) expected in the target server's certificate. This is required to get past default server hostname verifications during TLS handshake.
- peerEventRegistrationWaitTime - Time in milliseconds to wait for peer eventing service registration.
-
org.hyperledger.fabric.sdk.peer.organization_mspid
Peer.PEER_ORGANIZATION_MSPID_PROPERTY- Associates peer to an organization by its mspid. - grpc.NettyChannelBuilderOption.<methodName> where methodName is any method on grpc ManagedChannelBuilder. If more than one argument to the method is needed then the parameters need to be supplied in an array of Objects.
- Returns:
- Peer
- Throws:
InvalidArgumentException
-
newPeer
newPeer create a new peer- Parameters:
name-grpcURL- to the peer's location- Returns:
- Peer
- Throws:
InvalidArgumentException
-
getChannel
getChannel by name- Parameters:
name- The channel name- Returns:
- a channel (or null if the channel does not exist)
-
newInstallProposalRequest
Deprecated.newInstallProposalRequest get new Install proposal request.- Returns:
- InstallProposalRequest
-
newLifecycleInstallChaincodeRequest
newInstallProposalRequest get new Query Install proposal request. -
newLifecycleQueryInstalledChaincodeRequest
Get newLifecycleQueryInstalledChaincodeRequest to find chaincodes installed.- Returns:
LifecycleInstallChaincodeProposalResponsefinds chaincodes installed.
-
newLifecycleQueryInstalledChaincodesRequest
LifecycleQueryInstalledChaincodesRequest get new Query Install proposal request. -
newLifecycleApproveChaincodeDefinitionForMyOrgRequest
public LifecycleApproveChaincodeDefinitionForMyOrgRequest newLifecycleApproveChaincodeDefinitionForMyOrgRequest()newLifecycleApproveChaincodeDefinitionForMyOrgRequest get new Install proposal request.- Returns:
- LifecycleApproveChaincodeDefinitionForMyOrgRequest
-
newLifecycleSimulateCommitChaincodeDefinitionRequest
Get a LifecycleSimulateCommitChaincodeDefinitionRequest to find which chaincodes are approved by which organization.- Returns:
-
newLifecycleCommitChaincodeDefinitionRequest
newLifecycleApproveChaincodeDefinitionForMyOrgRequest get new Install proposal request.- Returns:
- LifecycleCommitChaincodeDefinitionRequest
-
newLifecycleQueryChaincodeDefinitionsRequest
Create a new QueryChaincodeDefinitions proposal request.- Returns:
- A proposal request.
-
newQueryLifecycleQueryChaincodeDefinitionRequest
public QueryLifecycleQueryChaincodeDefinitionRequest newQueryLifecycleQueryChaincodeDefinitionRequest()get QueryLifecycleQueryChaincodeDefinitionRequest find which chaincodes are defined.- Returns:
- QueryLifecycleQueryChaincodeDefinitionRequest
-
sendLifecycleInstallChaincodeRequest
public Collection<LifecycleInstallChaincodeProposalResponse> sendLifecycleInstallChaincodeRequest(LifecycleInstallChaincodeRequest lifecycleInstallChaincodeRequest, Collection<Peer> peers) throws ProposalException, InvalidArgumentException Send install chaincode request proposal to peers.- Parameters:
lifecycleInstallChaincodeRequest-peers- Collection of peers to install on.- Returns:
- responses from peers.
- Throws:
InvalidArgumentExceptionProposalException
-
sendLifecycleQueryInstalledChaincode
public Collection<LifecycleQueryInstalledChaincodeProposalResponse> sendLifecycleQueryInstalledChaincode(LifecycleQueryInstalledChaincodeRequest lifecycleQueryInstalledChaincodeRequest, Collection<Peer> peers) throws InvalidArgumentException, ProposalException Query installed chaincode on a peer.- Parameters:
lifecycleQueryInstalledChaincodeRequest- The requestLifecycleQueryInstalledChaincodeRequestpeers- the peer to send the request to.- Returns:
- LifecycleQueryInstalledChaincodeProposalResponse
- Throws:
InvalidArgumentExceptionProposalException
-
sendLifecycleQueryInstalledChaincodes
public Collection<LifecycleQueryInstalledChaincodesProposalResponse> sendLifecycleQueryInstalledChaincodes(LifecycleQueryInstalledChaincodesRequest lifecycleQueryInstalledChaincodesRequest, Collection<Peer> peers) throws InvalidArgumentException, ProposalException Query the peer for installed chaincodes information- Parameters:
lifecycleQueryInstalledChaincodesRequest- the requestLifecycleQueryInstalledChaincodesRequestpeers- The peer to query.- Returns:
- Collection of ChaincodeInfo on installed chaincode @see
LifecycleQueryInstalledChaincodesProposalResponse - Throws:
InvalidArgumentExceptionProposalException
-
newInstantiationProposalRequest
Deprecated.SeeLifecycleCommitChaincodeDefinitionRequestfor defining the chaincode and and thenTransactionRequest.setInit(boolean)to do the initialization if it's required by the chaincode.newInstantiationProposalRequest get new instantiation proposal request.- Returns:
- see
InstantiateProposalRequest
-
newUpgradeProposalRequest
Deprecated.SeeLifecycleCommitChaincodeDefinitionRequestfor defining the chaincode and and thenTransactionRequest.setInit(boolean)to do the initialization if it's required by the chaincode.- Returns:
UpgradeProposalRequest
-
newTransactionProposalRequest
newTransactionProposalRequest get new transaction proposal request.- Returns:
- TransactionProposalRequest
-
newQueryProposalRequest
newQueryProposalRequest get new query proposal request.- Returns:
- QueryByChaincodeRequest
-
setUserContext
Set the User context for this client.- Parameters:
userContext-- Returns:
- the old user context. Maybe null if never set!
- Throws:
IllegalStateException- if no crypto suite has been set.NullPointerException- if the user context is null.IllegalArgumentException- if the user context is not valid.
-
newOrderer
Create a new urlOrderer.- Parameters:
name- name of the orderer.grpcURL- url location of orderer grpc or grpcs protocol.- Returns:
- a new Orderer.
- Throws:
InvalidArgumentException
-
newOrderer
public Orderer newOrderer(String name, String grpcURL, Properties properties) throws InvalidArgumentException Create a new orderer.- Parameters:
name- name of Orderer.grpcURL- url location of orderer grpc or grpcs protocol.properties-Supported properties
- pemFile - File location for x509 pem certificate for SSL.
- pemBytes - byte array for x509 pem certificates for SSL
- trustServerCertificate - boolean(true/false) override CN to match pemFile certificate -- for development only. If the pemFile has the target server's certificate (instead of a CA Root certificate), instruct the TLS client to trust the CN value of the certificate in the pemFile, useful in development to get past default server hostname verification during TLS handshake, when the server host name does not match the certificate.
- clientKeyFile - File location for private key pem for mutual TLS
- clientCertFile - File location for x509 pem certificate for mutual TLS
- clientKeyBytes - Private key pem bytes for mutual TLS
- clientCertBytes - x509 pem certificate bytes for mutual TLS
- sslProvider - Specify the SSL provider, openSSL or JDK.
- negotiationType - Specify the type of negotiation, TLS or plainText.
- hostnameOverride - Specify the certificates CN -- for development only. If the pemFile does not represent the server certificate, use this property to specify the URI authority (a.k.a hostname) expected in the target server's certificate. This is required to get past default server hostname verifications during TLS handshake.
-
org.hyperledger.fabric.sdk.orderer.organization_mspid
Orderer.ORDERER_ORGANIZATION_MSPID_PROPERTY- Associates orderer to an organization by its mspid. - grpc.NettyChannelBuilderOption.<methodName> where methodName is any method on grpc ManagedChannelBuilder. If more than one argument to the method is needed then the parameters need to be supplied in an array of Objects.
- ordererWaitTimeMilliSecs Time to wait in milliseconds for the Orderer to accept requests before timing out. The default is two seconds.
- Returns:
- The orderer.
- Throws:
InvalidArgumentException
-
queryChannels
Query the joined channels for peers- Parameters:
peer- the peer to query- Returns:
- A set of strings with the names of the channels the peer has joined.
- Throws:
InvalidArgumentExceptionProposalException
-
queryInstalledChaincodes
@Deprecated public List<org.hyperledger.fabric.protos.peer.Query.ChaincodeInfo> queryInstalledChaincodes(Peer peer) throws InvalidArgumentException, ProposalException Deprecated.Query the peer for installed chaincode information- Parameters:
peer- The peer to query.- Returns:
- List of ChaincodeInfo on installed chaincode @see
Query.ChaincodeInfo - Throws:
InvalidArgumentExceptionProposalException
-
getChannelConfigurationSignature
public byte[] getChannelConfigurationSignature(ChannelConfiguration channelConfiguration, User signer) throws InvalidArgumentException Get signature for channel configuration- Parameters:
channelConfiguration-signer-- Returns:
- byte array with the signature
- Throws:
InvalidArgumentException
-
getUpdateChannelConfigurationSignature
public byte[] getUpdateChannelConfigurationSignature(UpdateChannelConfiguration updateChannelConfiguration, User signer) throws InvalidArgumentException Get signature for update channel configuration- Parameters:
updateChannelConfiguration-signer-- Returns:
- byte array with the signature
- Throws:
InvalidArgumentException
-
sendInstallProposal
@Deprecated public Collection<ProposalResponse> sendInstallProposal(InstallProposalRequest installProposalRequest, Collection<Peer> peers) throws ProposalException, InvalidArgumentException Deprecated.Send install chaincode request proposal to peers.- Parameters:
installProposalRequest-peers- Collection of peers to install on.- Returns:
- responses from peers.
- Throws:
InvalidArgumentExceptionProposalException
-
newLifecycleQueryInstalledChaincodesRequest()