Package org.hyperledger.fabric.sdk
Class Channel
- java.lang.Object
-
- org.hyperledger.fabric.sdk.Channel
-
- All Implemented Interfaces:
java.io.Serializable
public class Channel extends java.lang.Object implements java.io.SerializableThe class representing a channel with which the client SDK interacts.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classChannel.AnchorPeersConfigUpdateResultstatic classChannel.DiscoveryOptionsOptions for doing service discovery.static classChannel.NOfEventsNofEvents may be used with @seeChannel.TransactionOptions.nOfEvents(NOfEvents)to control how reporting Peer service events and Eventhubs will complete the future acknowledging the transaction has been seen by those Peers.static classChannel.PeerOptionsOptions for the peer.static interfaceChannel.SDOrdererAdditionstatic interfaceChannel.SDOrdererAdditionInfostatic interfaceChannel.SDPeerAdditionstatic interfaceChannel.SDPeerAdditionInfostatic classChannel.ServiceDiscoveryChaincodeCallsAdditional metadata used by service discovery to find the endorsements needed.static classChannel.TransactionOptionsTransactionOptions class can be used to change how the SDK processes the Transaction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ChanneladdEventHub(EventHub eventHub)Add an Event Hub to this channel.ChanneladdOrderer(Orderer orderer)Add an Orderer to this channel.ChanneladdPeer(Peer peer)Add a peer to the channelChanneladdPeer(Peer peer, Channel.PeerOptions peerOptions)Add a peer to the channelprotected voidfinalize()byte[]getChannelConfigurationBytes()Channel Configuration bytes.Channel.AnchorPeersConfigUpdateResultgetConfigUpdateAnchorPeers(Peer peer, User userContext, java.util.Collection<java.lang.String> peersToAdd, java.util.Collection<java.lang.String> peersToRemove)Get a channel configuration update to add or remove peers.java.util.Collection<java.lang.String>getDiscoveredChaincodeNames()Collection of discovered chaincode names.java.util.Collection<EventHub>getEventHubs()Get all Event Hubs on this channel.java.lang.StringgetName()Get the channel namejava.util.Collection<Orderer>getOrderers()java.util.Collection<Peer>getPeers()Get the peers for this channel.java.util.Collection<Peer>getPeers(java.util.EnumSet<Peer.PeerRole> roles)Get the peers for this channel.Channel.PeerOptionsgetPeersOptions(Peer peer)java.util.PropertiesgetServiceDiscoveryProperties()byte[]getUpdateChannelConfigurationSignature(UpdateChannelConfiguration updateChannelConfiguration, User signer)Get signed byes of the update channel.Channelinitialize()Initialize the Channel.booleanisInitialized()Is channel initialized.booleanisShutdown()Is the channel shutdown.ChanneljoinPeer(Orderer orderer, Peer peer, Channel.PeerOptions peerOptions)Join peer to channelChanneljoinPeer(Peer peer)Join the peer to the channel.ChanneljoinPeer(Peer peer, Channel.PeerOptions peerOptions)protected voidloadCACertificates(boolean force)load the peer organizations CA certificates into the channel's trust store so that we can verify signatures from peer messagesprotected java.util.Map<java.lang.String,org.hyperledger.fabric.sdk.Channel.MSP>parseConfigBlock(boolean force)BlockInfoqueryBlockByHash(byte[] blockHash)query this channel for a Block by the block hash.BlockInfoqueryBlockByHash(byte[] blockHash, User userContext)query this channel for a Block by the block hash.BlockInfoqueryBlockByHash(java.util.Collection<Peer> peers, byte[] blockHash)Query a peer in this channel for a Block by the block hash.BlockInfoqueryBlockByHash(java.util.Collection<Peer> peers, byte[] blockHash, User userContext)Query a peer in this channel for a Block by the block hash.BlockInfoqueryBlockByHash(Peer peer, byte[] blockHash)Query a peer in this channel for a Block by the block hash.BlockInfoqueryBlockByNumber(long blockNumber)query this channel for a Block by the blockNumber.BlockInfoqueryBlockByNumber(long blockNumber, User userContext)query this channel for a Block by the blockNumber.BlockInfoqueryBlockByNumber(java.util.Collection<Peer> peers, long blockNumber)query a peer in this channel for a Block by the blockNumber This method may not be thread safe if client context is changed!BlockInfoqueryBlockByNumber(java.util.Collection<Peer> peers, long blockNumber, User userContext)query a peer in this channel for a Block by the blockNumberBlockInfoqueryBlockByNumber(Peer peer, long blockNumber)Query a peer in this channel for a Block by the blockNumber This method may not be thread safe if client context is changed!BlockInfoqueryBlockByNumber(Peer peer, long blockNumber, User userContext)query a peer in this channel for a Block by the blockNumberBlockInfoqueryBlockByTransactionID(java.lang.String txID)query this channel for a Block by a TransactionID contained in the block The request is tried on on each peer till successful.BlockInfoqueryBlockByTransactionID(java.lang.String txID, User userContext)query this channel for a Block by a TransactionID contained in the block The request is sent to a random peer in the channelBlockInfoqueryBlockByTransactionID(java.util.Collection<Peer> peers, java.lang.String txID)query a peer in this channel for a Block by a TransactionID contained in the block This method may not be thread safe if client context is changed!BlockInfoqueryBlockByTransactionID(java.util.Collection<Peer> peers, java.lang.String txID, User userContext)query a peer in this channel for a Block by a TransactionID contained in the blockBlockInfoqueryBlockByTransactionID(Peer peer, java.lang.String txID)query a peer in this channel for a Block by a TransactionID contained in the block This method may not be thread safe if client context is changed!BlockInfoqueryBlockByTransactionID(Peer peer, java.lang.String txID, User userContext)query a peer in this channel for a Block by a TransactionID contained in the blockBlockchainInfoqueryBlockchainInfo()query this channel for chain information.BlockchainInfoqueryBlockchainInfo(java.util.Collection<Peer> peers, User userContext)query for chain informationBlockchainInfoqueryBlockchainInfo(Peer peer)query for chain information This method may not be thread safe if client context is changed!BlockchainInfoqueryBlockchainInfo(Peer peer, User userContext)query for chain informationBlockchainInfoqueryBlockchainInfo(User userContext)query this channel for chain information.java.util.Collection<ProposalResponse>queryByChaincode(QueryByChaincodeRequest queryByChaincodeRequest)Send Query proposaljava.util.Collection<ProposalResponse>queryByChaincode(QueryByChaincodeRequest queryByChaincodeRequest, java.util.Collection<Peer> peers)Send Query proposalCollectionConfigPackagequeryCollectionsConfig(java.lang.String chaincodeName, Peer peer, User userContext)Get information on the collections used by the chaincode.java.util.List<org.hyperledger.fabric.protos.peer.Query.ChaincodeInfo>queryInstantiatedChaincodes(Peer peer)Query peer for chaincode that has been instantiated This method may not be thread safe if client context is changed!java.util.List<org.hyperledger.fabric.protos.peer.Query.ChaincodeInfo>queryInstantiatedChaincodes(Peer peer, User userContext)Query peer for chaincode that has been instantiatedTransactionInfoqueryTransactionByID(java.lang.String txID)Query this channel for a Fabric Transaction given its transactionID.TransactionInfoqueryTransactionByID(java.lang.String txID, User userContext)Query this channel for a Fabric Transaction given its transactionID.TransactionInfoqueryTransactionByID(java.util.Collection<Peer> peers, java.lang.String txID, User userContext)Query for a Fabric Transaction given its transactionIDTransactionInfoqueryTransactionByID(Peer peer, java.lang.String txID)Query for a Fabric Transaction given its transactionID This method may not be thread safe if client context is changed!TransactionInfoqueryTransactionByID(Peer peer, java.lang.String txID, User userContext)Query for a Fabric Transaction given its transactionIDjava.lang.StringregisterBlockListener(BlockListener listener)Register a block listener.java.lang.StringregisterChaincodeEventListener(java.util.regex.Pattern chaincodeId, java.util.regex.Pattern eventName, ChaincodeEventListener chaincodeEventListener)Register a chaincode event listener.voidremoveOrderer(Orderer orderer)voidremovePeer(Peer peer)Removes the peer connection from the channel.java.util.Collection<ProposalResponse>sendInstantiationProposal(InstantiateProposalRequest instantiateProposalRequest)Send instantiate request to the channel.java.util.Collection<ProposalResponse>sendInstantiationProposal(InstantiateProposalRequest instantiateProposalRequest, java.util.Collection<Peer> peers)Send instantiate request to the channel.java.util.concurrent.CompletableFuture<BlockEvent.TransactionEvent>sendTransaction(java.util.Collection<ProposalResponse> proposalResponses)Send transaction to one of the orderers on the channel using the usercontext set on the client.java.util.concurrent.CompletableFuture<BlockEvent.TransactionEvent>sendTransaction(java.util.Collection<ProposalResponse> proposalResponses, java.util.Collection<Orderer> orderers)Send transaction to one of the specified orderers using the usercontext set on the client..java.util.concurrent.CompletableFuture<BlockEvent.TransactionEvent>sendTransaction(java.util.Collection<ProposalResponse> proposalResponses, java.util.Collection<Orderer> orderers, User userContext)Send transaction to one of a specified set of orderers with the specified user context.java.util.concurrent.CompletableFuture<BlockEvent.TransactionEvent>sendTransaction(java.util.Collection<ProposalResponse> proposalResponses, Channel.TransactionOptions transactionOptions)Send transaction to one of a specified set of orderers with the specified user context.java.util.concurrent.CompletableFuture<BlockEvent.TransactionEvent>sendTransaction(java.util.Collection<ProposalResponse> proposalResponses, User userContext)Send transaction to one of the orderers on the channel using a specific user context.java.util.Collection<ProposalResponse>sendTransactionProposal(TransactionProposalRequest transactionProposalRequest)Send a transaction proposal.java.util.Collection<ProposalResponse>sendTransactionProposal(TransactionProposalRequest transactionProposalRequest, java.util.Collection<Peer> peers)Send a transaction proposal to specific peers.java.util.Collection<ProposalResponse>sendTransactionProposalToEndorsers(TransactionProposalRequest transactionProposalRequest, Channel.DiscoveryOptions discoveryOptions)Send a transaction proposal.java.util.Collection<ProposalResponse>sendUpgradeProposal(UpgradeProposalRequest upgradeProposalRequest)Send Upgrade proposal proposal to upgrade chaincode to a new version.java.util.Collection<ProposalResponse>sendUpgradeProposal(UpgradeProposalRequest upgradeProposalRequest, java.util.Collection<Peer> peers)Send Upgrade proposal proposal to upgrade chaincode to a new version.byte[]serializeChannel()Serialize channel to a byte array using Java serialization.voidserializeChannel(java.io.File file)Serialize channel to a file using Java serialization.ServiceDiscovery.EndorsementSelectorsetSDEndorserSelector(ServiceDiscovery.EndorsementSelector endorsementSelector)Channel.SDOrdererAdditionsetSDOrdererAddition(Channel.SDOrdererAddition sdOrdererAddition)Set service discovery peer addition override.Channel.SDPeerAdditionsetSDPeerAddition(Channel.SDPeerAddition sdPeerAddition)Set service discovery peer addition override.voidsetServiceDiscoveryProperties(java.util.Properties serviceDiscoveryProperties)voidshutdown(boolean force)Shutdown the channel with all resources released.java.lang.StringtoString()booleanunregisterBlockListener(java.lang.String handle)Unregister a block listener.booleanunregisterChaincodeEventListener(java.lang.String handle)Unregister an existing chaincode event listener.voidupdateChannelConfiguration(UpdateChannelConfiguration updateChannelConfiguration, byte[]... signers)Update channel with specified channel configurationvoidupdateChannelConfiguration(UpdateChannelConfiguration updateChannelConfiguration, Orderer orderer, byte[]... signers)Update channel with specified channel configuration
-
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getEventHubs
public java.util.Collection<EventHub> getEventHubs()
Get all Event Hubs on this channel.- Returns:
- Event Hubs
-
updateChannelConfiguration
public void updateChannelConfiguration(UpdateChannelConfiguration updateChannelConfiguration, byte[]... signers) throws TransactionException, InvalidArgumentException
Update channel with specified channel configuration- Parameters:
updateChannelConfiguration- Updated Channel configurationsigners- signers- Throws:
TransactionExceptionInvalidArgumentException
-
updateChannelConfiguration
public void updateChannelConfiguration(UpdateChannelConfiguration updateChannelConfiguration, Orderer orderer, byte[]... signers) throws TransactionException, InvalidArgumentException
Update channel with specified channel configuration- Parameters:
updateChannelConfiguration- Channel configurationsigners- signersorderer- The specific orderer to use.- Throws:
TransactionExceptionInvalidArgumentException
-
isInitialized
public boolean isInitialized()
Is channel initialized.- Returns:
- true if the channel has been initialized.
-
getName
public java.lang.String getName()
Get the channel name- Returns:
- The name of the channel
-
addPeer
public Channel addPeer(Peer peer) throws InvalidArgumentException
Add a peer to the channel- Parameters:
peer- The Peer to add.- Returns:
- Channel The current channel added.
- Throws:
InvalidArgumentException
-
addPeer
public Channel addPeer(Peer peer, Channel.PeerOptions peerOptions) throws InvalidArgumentException
Add a peer to the channel- Parameters:
peer- The Peer to add.peerOptions- seePeer.PeerRole- Returns:
- Channel The current channel added.
- Throws:
InvalidArgumentException
-
joinPeer
public Channel joinPeer(Peer peer) throws ProposalException
Join the peer to the channel. The peer is added with all roles seeChannel.PeerOptions- Parameters:
peer- the peer to join the channel.- Returns:
- Throws:
ProposalException
-
joinPeer
public Channel joinPeer(Peer peer, Channel.PeerOptions peerOptions) throws ProposalException
- Parameters:
peer- the peer to join the channel.peerOptions- seeChannel.PeerOptions- Returns:
- Throws:
ProposalException
-
joinPeer
public Channel joinPeer(Orderer orderer, Peer peer, Channel.PeerOptions peerOptions) throws ProposalException
Join peer to channel- Parameters:
orderer- The orderer to get the genesis block.peer- the peer to join the channel.peerOptions- seeChannel.PeerOptions- Returns:
- Throws:
ProposalException
-
removePeer
public void removePeer(Peer peer) throws InvalidArgumentException
Removes the peer connection from the channel. This does NOT unjoin the peer from from the channel. Fabric does not support that at this time -- maybe some day, but not today- Parameters:
peer-- Throws:
InvalidArgumentException
-
addOrderer
public Channel addOrderer(Orderer orderer) throws InvalidArgumentException
Add an Orderer to this channel.- Parameters:
orderer- the orderer to add.- Returns:
- this channel.
- Throws:
InvalidArgumentException
-
removeOrderer
public void removeOrderer(Orderer orderer) throws InvalidArgumentException
- Throws:
InvalidArgumentException
-
getPeersOptions
public Channel.PeerOptions getPeersOptions(Peer peer)
-
addEventHub
public Channel addEventHub(EventHub eventHub) throws InvalidArgumentException
Add an Event Hub to this channel.- Parameters:
eventHub-- Returns:
- this channel
- Throws:
InvalidArgumentException
-
getPeers
public java.util.Collection<Peer> getPeers()
Get the peers for this channel.- Returns:
- the peers.
-
getPeers
public java.util.Collection<Peer> getPeers(java.util.EnumSet<Peer.PeerRole> roles)
Get the peers for this channel.- Returns:
- the peers.
-
initialize
public Channel initialize() throws InvalidArgumentException, TransactionException
Initialize the Channel. Starts the channel. event hubs will connect.- Returns:
- this channel.
- Throws:
InvalidArgumentExceptionTransactionException
-
getServiceDiscoveryProperties
public java.util.Properties getServiceDiscoveryProperties()
-
setServiceDiscoveryProperties
public void setServiceDiscoveryProperties(java.util.Properties serviceDiscoveryProperties)
-
setSDOrdererAddition
public Channel.SDOrdererAddition setSDOrdererAddition(Channel.SDOrdererAddition sdOrdererAddition)
Set service discovery peer addition override.- Parameters:
sdOrdererAddition-- Returns:
-
setSDPeerAddition
public Channel.SDPeerAddition setSDPeerAddition(Channel.SDPeerAddition sdPeerAddition)
Set service discovery peer addition override.- Parameters:
sdPeerAddition-- Returns:
-
loadCACertificates
protected void loadCACertificates(boolean force) throws InvalidArgumentException, CryptoException, TransactionExceptionload the peer organizations CA certificates into the channel's trust store so that we can verify signatures from peer messages
-
isShutdown
public boolean isShutdown()
Is the channel shutdown.- Returns:
- return true if the channel is shutdown.
-
getUpdateChannelConfigurationSignature
public byte[] getUpdateChannelConfigurationSignature(UpdateChannelConfiguration updateChannelConfiguration, User signer) throws InvalidArgumentException
Get signed byes of the update channel.- Parameters:
updateChannelConfiguration-signer-- Returns:
- Throws:
InvalidArgumentException
-
parseConfigBlock
protected java.util.Map<java.lang.String,org.hyperledger.fabric.sdk.Channel.MSP> parseConfigBlock(boolean force) throws TransactionException- Throws:
TransactionException
-
getConfigUpdateAnchorPeers
public Channel.AnchorPeersConfigUpdateResult getConfigUpdateAnchorPeers(Peer peer, User userContext, java.util.Collection<java.lang.String> peersToAdd, java.util.Collection<java.lang.String> peersToRemove) throws java.lang.Exception
Get a channel configuration update to add or remove peers. If both peersToAdd AND peersToRemove are null then only the current anchor peers are reported with @seeChannel.AnchorPeersConfigUpdateResult.getCurrentPeers()- Parameters:
peer- peer to use to the channel configuration from.userContext- The usercontext to use.peersToAdd- Peers to add as Host:Port peer1.org2.com:7022peersToRemove- Peers to remove as Host:Port peer1.org2.com:7022- Returns:
- The AnchorPeersConfigUpdateResult @see
Channel.AnchorPeersConfigUpdateResult - Throws:
java.lang.Exception
-
getChannelConfigurationBytes
public byte[] getChannelConfigurationBytes() throws TransactionExceptionChannel Configuration bytes. Bytes that can be used with configtxlator tool to upgrade the channel. Convert to Json for editing with:<p> curl -v POST --data-binary @fooConfig http://host/protolator/decode/common.Config <p>See http://hyperledger-fabric.readthedocs.io/en/latest/configtxlator.html- Returns:
- Channel configuration bytes.
- Throws:
TransactionException
-
getOrderers
public java.util.Collection<Orderer> getOrderers()
-
sendInstantiationProposal
public java.util.Collection<ProposalResponse> sendInstantiationProposal(InstantiateProposalRequest instantiateProposalRequest) throws InvalidArgumentException, ProposalException
Send instantiate request to the channel. Chaincode is created and initialized.- Parameters:
instantiateProposalRequest- send instantiate chaincode proposal request.- Returns:
- Collections of proposal responses
- Throws:
InvalidArgumentExceptionProposalException
-
sendInstantiationProposal
public java.util.Collection<ProposalResponse> sendInstantiationProposal(InstantiateProposalRequest instantiateProposalRequest, java.util.Collection<Peer> peers) throws InvalidArgumentException, ProposalException
Send instantiate request to the channel. Chaincode is created and initialized.- Parameters:
instantiateProposalRequest-peers-- Returns:
- responses from peers.
- Throws:
InvalidArgumentExceptionProposalException
-
sendUpgradeProposal
public java.util.Collection<ProposalResponse> sendUpgradeProposal(UpgradeProposalRequest upgradeProposalRequest) throws ProposalException, InvalidArgumentException
Send Upgrade proposal proposal to upgrade chaincode to a new version.- Parameters:
upgradeProposalRequest-- Returns:
- Collection of proposal responses.
- Throws:
ProposalExceptionInvalidArgumentException
-
sendUpgradeProposal
public java.util.Collection<ProposalResponse> sendUpgradeProposal(UpgradeProposalRequest upgradeProposalRequest, java.util.Collection<Peer> peers) throws InvalidArgumentException, ProposalException
Send Upgrade proposal proposal to upgrade chaincode to a new version.- Parameters:
upgradeProposalRequest-peers- the specific peers to send to.- Returns:
- Collection of proposal responses.
- Throws:
ProposalExceptionInvalidArgumentException
-
queryBlockByHash
public BlockInfo queryBlockByHash(byte[] blockHash) throws InvalidArgumentException, ProposalException
query this channel for a Block by the block hash. The request is retried on each peer on the channel till successful. This method may not be thread safe if client context is changed!- Parameters:
blockHash- the hash of the Block in the chain- Returns:
- the
BlockInfowith the given block Hash - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockByHash
public BlockInfo queryBlockByHash(byte[] blockHash, User userContext) throws InvalidArgumentException, ProposalException
query this channel for a Block by the block hash. The request is tried on multiple peers.- Parameters:
blockHash- the hash of the Block in the chainuserContext- the user context.- Returns:
- the
BlockInfowith the given block Hash - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockByHash
public BlockInfo queryBlockByHash(Peer peer, byte[] blockHash) throws InvalidArgumentException, ProposalException
Query a peer in this channel for a Block by the block hash. This method may not be thread safe if client context is changed!- Parameters:
peer- the Peer to query.blockHash- the hash of the Block in the chain.- Returns:
- the
BlockInfowith the given block Hash - Throws:
InvalidArgumentException- if the channel is shutdown or any of the arguments are not valid.ProposalException- if an error occurred processing the query.
-
queryBlockByHash
public BlockInfo queryBlockByHash(java.util.Collection<Peer> peers, byte[] blockHash) throws InvalidArgumentException, ProposalException
Query a peer in this channel for a Block by the block hash. Each peer is tried until successful response. This method may not be thread safe if client context is changed!- Parameters:
peers- the Peers to query.blockHash- the hash of the Block in the chain.- Returns:
- the
BlockInfowith the given block Hash - Throws:
InvalidArgumentException- if the channel is shutdown or any of the arguments are not valid.ProposalException- if an error occurred processing the query.
-
queryBlockByHash
public BlockInfo queryBlockByHash(java.util.Collection<Peer> peers, byte[] blockHash, User userContext) throws InvalidArgumentException, ProposalException
Query a peer in this channel for a Block by the block hash.- Parameters:
peers- the Peers to query.blockHash- the hash of the Block in the chain.userContext- the user context- Returns:
- the
BlockInfowith the given block Hash - Throws:
InvalidArgumentException- if the channel is shutdown or any of the arguments are not valid.ProposalException- if an error occurred processing the query.
-
queryBlockByNumber
public BlockInfo queryBlockByNumber(long blockNumber) throws InvalidArgumentException, ProposalException
query this channel for a Block by the blockNumber. The request is retried on all peers till successful This method may not be thread safe if client context is changed!- Parameters:
blockNumber- index of the Block in the chain- Returns:
- the
BlockInfowith the given blockNumber - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockByNumber
public BlockInfo queryBlockByNumber(long blockNumber, User userContext) throws InvalidArgumentException, ProposalException
query this channel for a Block by the blockNumber. The request is sent to a random peer in the channel.- Parameters:
blockNumber- index of the Block in the chainuserContext- the user context to be used.- Returns:
- the
BlockInfowith the given blockNumber - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockByNumber
public BlockInfo queryBlockByNumber(Peer peer, long blockNumber) throws InvalidArgumentException, ProposalException
Query a peer in this channel for a Block by the blockNumber This method may not be thread safe if client context is changed!- Parameters:
peer- the peer to send the request toblockNumber- index of the Block in the chain- Returns:
- the
BlockInfowith the given blockNumber - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockByNumber
public BlockInfo queryBlockByNumber(Peer peer, long blockNumber, User userContext) throws InvalidArgumentException, ProposalException
query a peer in this channel for a Block by the blockNumber- Parameters:
peer- the peer to send the request toblockNumber- index of the Block in the chainuserContext- the user context.- Returns:
- the
BlockInfowith the given blockNumber - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockByNumber
public BlockInfo queryBlockByNumber(java.util.Collection<Peer> peers, long blockNumber) throws InvalidArgumentException, ProposalException
query a peer in this channel for a Block by the blockNumber This method may not be thread safe if client context is changed!- Parameters:
peers- the peers to try and send the request toblockNumber- index of the Block in the chain- Returns:
- the
BlockInfowith the given blockNumber - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockByNumber
public BlockInfo queryBlockByNumber(java.util.Collection<Peer> peers, long blockNumber, User userContext) throws InvalidArgumentException, ProposalException
query a peer in this channel for a Block by the blockNumber- Parameters:
peers- the peers to try and send the request toblockNumber- index of the Block in the chainuserContext- the user context to use.- Returns:
- the
BlockInfowith the given blockNumber - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockByTransactionID
public BlockInfo queryBlockByTransactionID(java.lang.String txID) throws InvalidArgumentException, ProposalException
query this channel for a Block by a TransactionID contained in the block The request is tried on on each peer till successful. This method may not be thread safe if client context is changed!- Parameters:
txID- the transactionID to query on- Returns:
- the
BlockInfofor the Block containing the transaction - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockByTransactionID
public BlockInfo queryBlockByTransactionID(java.lang.String txID, User userContext) throws InvalidArgumentException, ProposalException
query this channel for a Block by a TransactionID contained in the block The request is sent to a random peer in the channel- Parameters:
txID- the transactionID to query onuserContext- the user context.- Returns:
- the
BlockInfofor the Block containing the transaction - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockByTransactionID
public BlockInfo queryBlockByTransactionID(Peer peer, java.lang.String txID) throws InvalidArgumentException, ProposalException
query a peer in this channel for a Block by a TransactionID contained in the block This method may not be thread safe if client context is changed!- Parameters:
peer- the peer to send the request totxID- the transactionID to query on- Returns:
- the
BlockInfofor the Block containing the transaction - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockByTransactionID
public BlockInfo queryBlockByTransactionID(Peer peer, java.lang.String txID, User userContext) throws InvalidArgumentException, ProposalException
query a peer in this channel for a Block by a TransactionID contained in the block- Parameters:
peer- the peer to send the request totxID- the transactionID to query onuserContext- the user context.- Returns:
- the
BlockInfofor the Block containing the transaction - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockByTransactionID
public BlockInfo queryBlockByTransactionID(java.util.Collection<Peer> peers, java.lang.String txID) throws InvalidArgumentException, ProposalException
query a peer in this channel for a Block by a TransactionID contained in the block This method may not be thread safe if client context is changed!- Parameters:
peers- the peers to try to send the request to.txID- the transactionID to query on- Returns:
- the
BlockInfofor the Block containing the transaction - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockByTransactionID
public BlockInfo queryBlockByTransactionID(java.util.Collection<Peer> peers, java.lang.String txID, User userContext) throws InvalidArgumentException, ProposalException
query a peer in this channel for a Block by a TransactionID contained in the block- Parameters:
peers- the peer to try to send the request totxID- the transactionID to query onuserContext- the user context.- Returns:
- the
BlockInfofor the Block containing the transaction - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockchainInfo
public BlockchainInfo queryBlockchainInfo() throws ProposalException, InvalidArgumentException
query this channel for chain information. The request is sent to a random peer in the channel This method may not be thread safe if client context is changed!- Returns:
- a
BlockchainInfoobject containing the chain info requested - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockchainInfo
public BlockchainInfo queryBlockchainInfo(User userContext) throws ProposalException, InvalidArgumentException
query this channel for chain information. The request is sent to a random peer in the channel- Parameters:
userContext- the user context to use.- Returns:
- a
BlockchainInfoobject containing the chain info requested - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockchainInfo
public BlockchainInfo queryBlockchainInfo(Peer peer) throws ProposalException, InvalidArgumentException
query for chain information This method may not be thread safe if client context is changed!- Parameters:
peer- The peer to send the request to- Returns:
- a
BlockchainInfoobject containing the chain info requested - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockchainInfo
public BlockchainInfo queryBlockchainInfo(Peer peer, User userContext) throws ProposalException, InvalidArgumentException
query for chain information- Parameters:
peer- The peer to send the request touserContext- the user context to use.- Returns:
- a
BlockchainInfoobject containing the chain info requested - Throws:
InvalidArgumentExceptionProposalException
-
queryBlockchainInfo
public BlockchainInfo queryBlockchainInfo(java.util.Collection<Peer> peers, User userContext) throws ProposalException, InvalidArgumentException
query for chain information- Parameters:
peers- The peers to try send the request.userContext- the user context.- Returns:
- a
BlockchainInfoobject containing the chain info requested - Throws:
InvalidArgumentExceptionProposalException
-
queryTransactionByID
public TransactionInfo queryTransactionByID(java.lang.String txID) throws ProposalException, InvalidArgumentException
Query this channel for a Fabric Transaction given its transactionID. The request is sent to a random peer in the channel. This method may not be thread safe if client context is changed!- Parameters:
txID- the ID of the transaction- Returns:
- a
TransactionInfo - Throws:
ProposalExceptionInvalidArgumentException
-
queryTransactionByID
public TransactionInfo queryTransactionByID(java.lang.String txID, User userContext) throws ProposalException, InvalidArgumentException
Query this channel for a Fabric Transaction given its transactionID. The request is sent to a random peer in the channel. This method may not be thread safe if client context is changed!- Parameters:
txID- the ID of the transactionuserContext- the user context used.- Returns:
- a
TransactionInfo - Throws:
ProposalExceptionInvalidArgumentException
-
queryTransactionByID
public TransactionInfo queryTransactionByID(Peer peer, java.lang.String txID) throws ProposalException, InvalidArgumentException
Query for a Fabric Transaction given its transactionID This method may not be thread safe if client context is changed!- Parameters:
txID- the ID of the transactionpeer- the peer to send the request to- Returns:
- a
TransactionInfo - Throws:
ProposalExceptionInvalidArgumentException
-
queryTransactionByID
public TransactionInfo queryTransactionByID(Peer peer, java.lang.String txID, User userContext) throws ProposalException, InvalidArgumentException
Query for a Fabric Transaction given its transactionID- Parameters:
peer- the peer to send the request totxID- the ID of the transactionuserContext- the user context- Returns:
- a
TransactionInfo - Throws:
ProposalExceptionInvalidArgumentException
-
queryTransactionByID
public TransactionInfo queryTransactionByID(java.util.Collection<Peer> peers, java.lang.String txID, User userContext) throws ProposalException, InvalidArgumentException
Query for a Fabric Transaction given its transactionID- Parameters:
txID- the ID of the transactionpeers- the peers to try to send the request.userContext- the user context- Returns:
- a
TransactionInfo - Throws:
ProposalExceptionInvalidArgumentException
-
queryInstantiatedChaincodes
public java.util.List<org.hyperledger.fabric.protos.peer.Query.ChaincodeInfo> queryInstantiatedChaincodes(Peer peer) throws InvalidArgumentException, ProposalException
Query peer for chaincode that has been instantiated This method may not be thread safe if client context is changed!- Parameters:
peer- The peer to query.- Returns:
- A list of ChaincodeInfo @see
Query.ChaincodeInfo - Throws:
InvalidArgumentExceptionProposalException
-
queryInstantiatedChaincodes
public java.util.List<org.hyperledger.fabric.protos.peer.Query.ChaincodeInfo> queryInstantiatedChaincodes(Peer peer, User userContext) throws InvalidArgumentException, ProposalException
Query peer for chaincode that has been instantiated- Parameters:
peer- The peer to query.userContext- the user context.- Returns:
- A list of ChaincodeInfo @see
Query.ChaincodeInfo - Throws:
InvalidArgumentExceptionProposalException
-
queryCollectionsConfig
public CollectionConfigPackage queryCollectionsConfig(java.lang.String chaincodeName, Peer peer, User userContext) throws InvalidArgumentException, ProposalException
Get information on the collections used by the chaincode.- Parameters:
chaincodeName- The name of the chaincode to query.peer- Peer to query.userContext- The context of the user to sign the request.- Returns:
- CollectionConfigPackage with information on the collection used by the chaincode.
- Throws:
InvalidArgumentExceptionProposalException
-
sendTransactionProposal
public java.util.Collection<ProposalResponse> sendTransactionProposal(TransactionProposalRequest transactionProposalRequest) throws ProposalException, InvalidArgumentException
Send a transaction proposal.- Parameters:
transactionProposalRequest- The transaction proposal to be sent to all the required peers needed for endorsing.- Returns:
- responses from peers.
- Throws:
InvalidArgumentExceptionProposalException
-
sendTransactionProposalToEndorsers
public java.util.Collection<ProposalResponse> sendTransactionProposalToEndorsers(TransactionProposalRequest transactionProposalRequest, Channel.DiscoveryOptions discoveryOptions) throws ProposalException, InvalidArgumentException, ServiceDiscoveryException
Send a transaction proposal.- Parameters:
transactionProposalRequest- The transaction proposal to be sent to all the required peers needed for endorsing.discoveryOptions-- Returns:
- responses from peers.
- Throws:
InvalidArgumentExceptionProposalExceptionServiceDiscoveryException
-
getDiscoveredChaincodeNames
public java.util.Collection<java.lang.String> getDiscoveredChaincodeNames()
Collection of discovered chaincode names.- Returns:
-
sendTransactionProposal
public java.util.Collection<ProposalResponse> sendTransactionProposal(TransactionProposalRequest transactionProposalRequest, java.util.Collection<Peer> peers) throws ProposalException, InvalidArgumentException
Send a transaction proposal to specific peers.- Parameters:
transactionProposalRequest- The transaction proposal to be sent to the peers.peers-- Returns:
- responses from peers.
- Throws:
InvalidArgumentExceptionProposalException
-
queryByChaincode
public java.util.Collection<ProposalResponse> queryByChaincode(QueryByChaincodeRequest queryByChaincodeRequest) throws InvalidArgumentException, ProposalException
Send Query proposal- Parameters:
queryByChaincodeRequest-- Returns:
- Collection proposal responses.
- Throws:
InvalidArgumentExceptionProposalException
-
queryByChaincode
public java.util.Collection<ProposalResponse> queryByChaincode(QueryByChaincodeRequest queryByChaincodeRequest, java.util.Collection<Peer> peers) throws InvalidArgumentException, ProposalException
Send Query proposal- Parameters:
queryByChaincodeRequest-peers-- Returns:
- responses from peers.
- Throws:
InvalidArgumentExceptionProposalException
-
setSDEndorserSelector
public ServiceDiscovery.EndorsementSelector setSDEndorserSelector(ServiceDiscovery.EndorsementSelector endorsementSelector)
-
sendTransaction
public java.util.concurrent.CompletableFuture<BlockEvent.TransactionEvent> sendTransaction(java.util.Collection<ProposalResponse> proposalResponses, User userContext)
Send transaction to one of the orderers on the channel using a specific user context.- Parameters:
proposalResponses- The proposal responses to be sent to the orderer.userContext- The usercontext used for signing transaction.- Returns:
- a future allowing access to the result of the transaction invocation once complete.
-
sendTransaction
public java.util.concurrent.CompletableFuture<BlockEvent.TransactionEvent> sendTransaction(java.util.Collection<ProposalResponse> proposalResponses)
Send transaction to one of the orderers on the channel using the usercontext set on the client.- Parameters:
proposalResponses- .- Returns:
- a future allowing access to the result of the transaction invocation once complete.
-
sendTransaction
public java.util.concurrent.CompletableFuture<BlockEvent.TransactionEvent> sendTransaction(java.util.Collection<ProposalResponse> proposalResponses, java.util.Collection<Orderer> orderers)
Send transaction to one of the specified orderers using the usercontext set on the client..- Parameters:
proposalResponses- The proposal responses to be sent to the ordererorderers- The orderers to send the transaction to.- Returns:
- a future allowing access to the result of the transaction invocation once complete.
-
sendTransaction
public java.util.concurrent.CompletableFuture<BlockEvent.TransactionEvent> sendTransaction(java.util.Collection<ProposalResponse> proposalResponses, java.util.Collection<Orderer> orderers, User userContext)
Send transaction to one of a specified set of orderers with the specified user context. IF there are no event hubs or eventing peers this future returns immediately completed indicating that orderer has accepted the transaction only.- Parameters:
proposalResponses-orderers-- Returns:
- Future allowing access to the result of the transaction invocation.
-
sendTransaction
public java.util.concurrent.CompletableFuture<BlockEvent.TransactionEvent> sendTransaction(java.util.Collection<ProposalResponse> proposalResponses, Channel.TransactionOptions transactionOptions)
Send transaction to one of a specified set of orderers with the specified user context. IF there are no event hubs or eventing peers this future returns immediately completed indicating that orderer has accepted the transaction only.- Parameters:
proposalResponses-transactionOptions-- Returns:
- Future allowing access to the result of the transaction invocation.
-
registerBlockListener
public java.lang.String registerBlockListener(BlockListener listener) throws InvalidArgumentException
Register a block listener.- Parameters:
listener- function with single argument with typeBlockEvent- Returns:
- The handle of the registered block listener.
- Throws:
InvalidArgumentException- if the channel is shutdown.
-
unregisterBlockListener
public boolean unregisterBlockListener(java.lang.String handle) throws InvalidArgumentExceptionUnregister a block listener.- Parameters:
handle- of Block listener to remove.- Returns:
- false if not found.
- Throws:
InvalidArgumentException- if the channel is shutdown or invalid arguments.
-
registerChaincodeEventListener
public java.lang.String registerChaincodeEventListener(java.util.regex.Pattern chaincodeId, java.util.regex.Pattern eventName, ChaincodeEventListener chaincodeEventListener) throws InvalidArgumentExceptionRegister a chaincode event listener. Both chaincodeId pattern AND eventName pattern must match to invoke the chaincodeEventListener- Parameters:
chaincodeId- Java pattern for chaincode identifier also know as chaincode name. If maeventName- Java pattern to match the event name.chaincodeEventListener- The listener to be invoked if both chaincodeId and eventName pattern matches.- Returns:
- Handle to be used to unregister the event listener
unregisterChaincodeEventListener(String) - Throws:
InvalidArgumentException
-
unregisterChaincodeEventListener
public boolean unregisterChaincodeEventListener(java.lang.String handle) throws InvalidArgumentExceptionUnregister an existing chaincode event listener.- Parameters:
handle- Chaincode event listener handle to be unregistered.- Returns:
- True if the chaincode handler was found and removed.
- Throws:
InvalidArgumentException
-
shutdown
public void shutdown(boolean force)
Shutdown the channel with all resources released.- Parameters:
force- force immediate shutdown.
-
serializeChannel
public void serializeChannel(java.io.File file) throws java.io.IOException, InvalidArgumentExceptionSerialize channel to a file using Java serialization. Deserialized channel will NOT be in an initialized state.- Parameters:
file- file- Throws:
java.io.IOExceptionInvalidArgumentException
-
serializeChannel
public byte[] serializeChannel() throws java.io.IOException, InvalidArgumentExceptionSerialize channel to a byte array using Java serialization. Deserialized channel will NOT be in an initialized state.- Throws:
InvalidArgumentExceptionjava.io.IOException
-
finalize
protected void finalize() throws java.lang.Throwable- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
-