Package org.hyperledger.fabric.sdk
Class HFClient
- java.lang.Object
-
- org.hyperledger.fabric.sdk.HFClient
-
public class HFClient extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.ExecutorService
executorService
protected java.util.concurrent.ThreadFactory
threadFactory
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HFClient
createNewInstance()
createNewInstance create a new instance of the HFClientChannel
deSerializeChannel(byte[] channelBytes)
Deserialize a channel serialized byChannel.serializeChannel()
Channel
deSerializeChannel(java.io.File file)
Deserialize a channel serialized byChannel.serializeChannel()
Channel
getChannel(java.lang.String name)
getChannel by namebyte[]
getChannelConfigurationSignature(ChannelConfiguration channelConfiguration, User signer)
Get signature for channel configurationCryptoSuite
getCryptoSuite()
byte[]
getUpdateChannelConfigurationSignature(UpdateChannelConfiguration updateChannelConfiguration, User signer)
Get signature for update channel configurationUser
getUserContext()
Channel
loadChannelFromConfig(java.lang.String channelName, NetworkConfig networkConfig)
Configures a channel based on information loaded from a Network Config file.Channel
newChannel(java.lang.String name)
newChannel - already configured channel.Channel
newChannel(java.lang.String name, Orderer orderer, ChannelConfiguration channelConfiguration, byte[]... channelConfigurationSignatures)
Create a new channelEventHub
newEventHub(java.lang.String name, java.lang.String grpcURL)
Create a new event hubEventHub
newEventHub(java.lang.String name, java.lang.String grpcURL, java.util.Properties properties)
Create a new Eventhub.InstallProposalRequest
newInstallProposalRequest()
newInstallProposalRequest get new Install proposal request.InstantiateProposalRequest
newInstantiationProposalRequest()
newInstantiationProposalRequest get new instantiation proposal request.Orderer
newOrderer(java.lang.String name, java.lang.String grpcURL)
Create a new urlOrderer.Orderer
newOrderer(java.lang.String name, java.lang.String grpcURL, java.util.Properties properties)
Create a new orderer.Peer
newPeer(java.lang.String name, java.lang.String grpcURL)
newPeer create a new peerPeer
newPeer(java.lang.String name, java.lang.String grpcURL, java.util.Properties properties)
newPeer create a new peerQueryByChaincodeRequest
newQueryProposalRequest()
newQueryProposalRequest get new query proposal request.TransactionProposalRequest
newTransactionProposalRequest()
newTransactionProposalRequest get new transaction proposal request.UpgradeProposalRequest
newUpgradeProposalRequest()
java.util.Set<java.lang.String>
queryChannels(Peer peer)
Query the joined channels for peersjava.util.List<org.hyperledger.fabric.protos.peer.Query.ChaincodeInfo>
queryInstalledChaincodes(Peer peer)
Query the peer for installed chaincode informationjava.util.Collection<ProposalResponse>
sendInstallProposal(InstallProposalRequest installProposalRequest, java.util.Collection<Peer> peers)
Send install chaincode request proposal to peers.void
setCryptoSuite(CryptoSuite cryptoSuite)
User
setUserContext(User userContext)
Set the User context for this client.
-
-
-
Method Detail
-
getUserContext
public User getUserContext()
-
getCryptoSuite
public CryptoSuite getCryptoSuite()
-
setCryptoSuite
public void setCryptoSuite(CryptoSuite cryptoSuite) throws CryptoException, InvalidArgumentException
-
createNewInstance
public static HFClient createNewInstance()
createNewInstance create a new instance of the HFClient- Returns:
- client
-
loadChannelFromConfig
public Channel loadChannelFromConfig(java.lang.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:
InvalidArgumentException
NetworkConfigurationException
-
newChannel
public Channel newChannel(java.lang.String name) throws InvalidArgumentException
newChannel - already configured channel.- Parameters:
name
-- Returns:
- a new channel.
- Throws:
InvalidArgumentException
-
newChannel
public Channel newChannel(java.lang.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:
TransactionException
InvalidArgumentException
-
deSerializeChannel
public Channel deSerializeChannel(java.io.File file) throws java.io.IOException, java.lang.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:
java.io.IOException
java.lang.ClassNotFoundException
InvalidArgumentException
-
deSerializeChannel
public Channel deSerializeChannel(byte[] channelBytes) throws java.io.IOException, java.lang.ClassNotFoundException, InvalidArgumentException
Deserialize a channel serialized byChannel.serializeChannel()
- Parameters:
channelBytes
- bytes to be deserialized.- Returns:
- A Channel that has not been initialized.
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
InvalidArgumentException
-
newPeer
public Peer newPeer(java.lang.String name, java.lang.String grpcURL, java.util.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.
- 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
public Peer newPeer(java.lang.String name, java.lang.String grpcURL) throws InvalidArgumentException
newPeer create a new peer- Parameters:
name
-grpcURL
- to the peer's location- Returns:
- Peer
- Throws:
InvalidArgumentException
-
getChannel
public Channel getChannel(java.lang.String name)
getChannel by name- Parameters:
name
- The channel name- Returns:
- a channel (or null if the channel does not exist)
-
newInstallProposalRequest
public InstallProposalRequest newInstallProposalRequest()
newInstallProposalRequest get new Install proposal request.- Returns:
- InstallProposalRequest
-
newInstantiationProposalRequest
public InstantiateProposalRequest newInstantiationProposalRequest()
newInstantiationProposalRequest get new instantiation proposal request.- Returns:
- InstantiateProposalRequest
-
newUpgradeProposalRequest
public UpgradeProposalRequest newUpgradeProposalRequest()
-
newTransactionProposalRequest
public TransactionProposalRequest newTransactionProposalRequest()
newTransactionProposalRequest get new transaction proposal request.- Returns:
- TransactionProposalRequest
-
newQueryProposalRequest
public QueryByChaincodeRequest newQueryProposalRequest()
newQueryProposalRequest get new query proposal request.- Returns:
- QueryByChaincodeRequest
-
setUserContext
public User setUserContext(User userContext) throws InvalidArgumentException
Set the User context for this client.- Parameters:
userContext
-- Returns:
- the old user context. Maybe null if never set!
- Throws:
InvalidArgumentException
-
newEventHub
public EventHub newEventHub(java.lang.String name, java.lang.String grpcURL, java.util.Properties properties) throws InvalidArgumentException
Create a new Eventhub.- Parameters:
name
- name of Eventhub.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 PKCS8-encoded private key pem for mutual TLS
- clientCertFile - File location for x509 pem certificate 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.
- 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:
- The orderer.
- Throws:
InvalidArgumentException
-
newEventHub
public EventHub newEventHub(java.lang.String name, java.lang.String grpcURL) throws InvalidArgumentException
Create a new event hub- Parameters:
name
- Name of eventhup should match peer's name it's associated with.grpcURL
- The http url location of the event hub- Returns:
- event hub
- Throws:
InvalidArgumentException
-
newOrderer
public Orderer newOrderer(java.lang.String name, java.lang.String grpcURL) throws InvalidArgumentException
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(java.lang.String name, java.lang.String grpcURL, java.util.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.
- 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
public java.util.Set<java.lang.String> queryChannels(Peer peer) throws InvalidArgumentException, ProposalException
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:
InvalidArgumentException
ProposalException
-
queryInstalledChaincodes
public java.util.List<org.hyperledger.fabric.protos.peer.Query.ChaincodeInfo> queryInstalledChaincodes(Peer peer) throws InvalidArgumentException, ProposalException
Query the peer for installed chaincode information- Parameters:
peer
- The peer to query.- Returns:
- List of ChaincodeInfo on installed chaincode @see
Query.ChaincodeInfo
- Throws:
InvalidArgumentException
ProposalException
-
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
public java.util.Collection<ProposalResponse> sendInstallProposal(InstallProposalRequest installProposalRequest, java.util.Collection<Peer> peers) throws ProposalException, InvalidArgumentException
Send install chaincode request proposal to peers.- Parameters:
installProposalRequest
-peers
- Collection of peers to install on.- Returns:
- responses from peers.
- Throws:
InvalidArgumentException
ProposalException
-
-