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.Serializable
The 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 class
Channel.AnchorPeersConfigUpdateResult
static class
Channel.DiscoveryOptions
Options for doing service discovery.static class
Channel.NOfEvents
NofEvents 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 class
Channel.PeerOptions
Options for the peer.static interface
Channel.SDOrdererAddition
static interface
Channel.SDOrdererAdditionInfo
static interface
Channel.SDPeerAddition
static interface
Channel.SDPeerAdditionInfo
static class
Channel.ServiceDiscoveryChaincodeCalls
Additional metadata used by service discovery to find the endorsements needed.static class
Channel.TransactionOptions
TransactionOptions 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 Channel
addEventHub(EventHub eventHub)
Add an Event Hub to this channel.Channel
addOrderer(Orderer orderer)
Add an Orderer to this channel.Channel
addPeer(Peer peer)
Add a peer to the channelChannel
addPeer(Peer peer, Channel.PeerOptions peerOptions)
Add a peer to the channelprotected void
finalize()
byte[]
getChannelConfigurationBytes()
Channel Configuration bytes.Channel.AnchorPeersConfigUpdateResult
getConfigUpdateAnchorPeers(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.String
getName()
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.PeerOptions
getPeersOptions(Peer peer)
java.util.Properties
getServiceDiscoveryProperties()
byte[]
getUpdateChannelConfigurationSignature(UpdateChannelConfiguration updateChannelConfiguration, User signer)
Get signed byes of the update channel.Channel
initialize()
Initialize the Channel.boolean
isInitialized()
Is channel initialized.boolean
isShutdown()
Is the channel shutdown.Channel
joinPeer(Orderer orderer, Peer peer, Channel.PeerOptions peerOptions)
Join peer to channelChannel
joinPeer(Peer peer)
Join the peer to the channel.Channel
joinPeer(Peer peer, Channel.PeerOptions peerOptions)
protected void
loadCACertificates(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)
BlockInfo
queryBlockByHash(byte[] blockHash)
query this channel for a Block by the block hash.BlockInfo
queryBlockByHash(byte[] blockHash, User userContext)
query this channel for a Block by the block hash.BlockInfo
queryBlockByHash(java.util.Collection<Peer> peers, byte[] blockHash)
Query a peer in this channel for a Block by the block hash.BlockInfo
queryBlockByHash(java.util.Collection<Peer> peers, byte[] blockHash, User userContext)
Query a peer in this channel for a Block by the block hash.BlockInfo
queryBlockByHash(Peer peer, byte[] blockHash)
Query a peer in this channel for a Block by the block hash.BlockInfo
queryBlockByNumber(long blockNumber)
query this channel for a Block by the blockNumber.BlockInfo
queryBlockByNumber(long blockNumber, User userContext)
query this channel for a Block by the blockNumber.BlockInfo
queryBlockByNumber(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!BlockInfo
queryBlockByNumber(java.util.Collection<Peer> peers, long blockNumber, User userContext)
query a peer in this channel for a Block by the blockNumberBlockInfo
queryBlockByNumber(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!BlockInfo
queryBlockByNumber(Peer peer, long blockNumber, User userContext)
query a peer in this channel for a Block by the blockNumberBlockInfo
queryBlockByTransactionID(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.BlockInfo
queryBlockByTransactionID(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 channelBlockInfo
queryBlockByTransactionID(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!BlockInfo
queryBlockByTransactionID(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 blockBlockInfo
queryBlockByTransactionID(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!BlockInfo
queryBlockByTransactionID(Peer peer, java.lang.String txID, User userContext)
query a peer in this channel for a Block by a TransactionID contained in the blockBlockchainInfo
queryBlockchainInfo()
query this channel for chain information.BlockchainInfo
queryBlockchainInfo(java.util.Collection<Peer> peers, User userContext)
query for chain informationBlockchainInfo
queryBlockchainInfo(Peer peer)
query for chain information This method may not be thread safe if client context is changed!BlockchainInfo
queryBlockchainInfo(Peer peer, User userContext)
query for chain informationBlockchainInfo
queryBlockchainInfo(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 proposalCollectionConfigPackage
queryCollectionsConfig(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 instantiatedTransactionInfo
queryTransactionByID(java.lang.String txID)
Query this channel for a Fabric Transaction given its transactionID.TransactionInfo
queryTransactionByID(java.lang.String txID, User userContext)
Query this channel for a Fabric Transaction given its transactionID.TransactionInfo
queryTransactionByID(java.util.Collection<Peer> peers, java.lang.String txID, User userContext)
Query for a Fabric Transaction given its transactionIDTransactionInfo
queryTransactionByID(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!TransactionInfo
queryTransactionByID(Peer peer, java.lang.String txID, User userContext)
Query for a Fabric Transaction given its transactionIDjava.lang.String
registerBlockListener(BlockListener listener)
Register a block listener.java.lang.String
registerChaincodeEventListener(java.util.regex.Pattern chaincodeId, java.util.regex.Pattern eventName, ChaincodeEventListener chaincodeEventListener)
Register a chaincode event listener.void
removeOrderer(Orderer orderer)
void
removePeer(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.void
serializeChannel(java.io.File file)
Serialize channel to a file using Java serialization.ServiceDiscovery.EndorsementSelector
setSDEndorserSelector(ServiceDiscovery.EndorsementSelector endorsementSelector)
Channel.SDOrdererAddition
setSDOrdererAddition(Channel.SDOrdererAddition sdOrdererAddition)
Set service discovery peer addition override.Channel.SDPeerAddition
setSDPeerAddition(Channel.SDPeerAddition sdPeerAddition)
Set service discovery peer addition override.void
setServiceDiscoveryProperties(java.util.Properties serviceDiscoveryProperties)
void
shutdown(boolean force)
Shutdown the channel with all resources released.java.lang.String
toString()
boolean
unregisterBlockListener(java.lang.String handle)
Unregister a block listener.boolean
unregisterChaincodeEventListener(java.lang.String handle)
Unregister an existing chaincode event listener.void
updateChannelConfiguration(UpdateChannelConfiguration updateChannelConfiguration, byte[]... signers)
Update channel with specified channel configurationvoid
updateChannelConfiguration(UpdateChannelConfiguration updateChannelConfiguration, Orderer orderer, byte[]... signers)
Update channel with specified channel configuration
-
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toString
in 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:
TransactionException
InvalidArgumentException
-
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:
TransactionException
InvalidArgumentException
-
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:
InvalidArgumentException
TransactionException
-
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, TransactionException
load 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 TransactionException
Channel 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:
InvalidArgumentException
ProposalException
-
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:
InvalidArgumentException
ProposalException
-
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:
ProposalException
InvalidArgumentException
-
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:
ProposalException
InvalidArgumentException
-
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
BlockInfo
with the given block Hash - Throws:
InvalidArgumentException
ProposalException
-
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
BlockInfo
with the given block Hash - Throws:
InvalidArgumentException
ProposalException
-
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
BlockInfo
with 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
BlockInfo
with 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
BlockInfo
with 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
BlockInfo
with the given blockNumber - Throws:
InvalidArgumentException
ProposalException
-
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
BlockInfo
with the given blockNumber - Throws:
InvalidArgumentException
ProposalException
-
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
BlockInfo
with the given blockNumber - Throws:
InvalidArgumentException
ProposalException
-
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
BlockInfo
with the given blockNumber - Throws:
InvalidArgumentException
ProposalException
-
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
BlockInfo
with the given blockNumber - Throws:
InvalidArgumentException
ProposalException
-
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
BlockInfo
with the given blockNumber - Throws:
InvalidArgumentException
ProposalException
-
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
BlockInfo
for the Block containing the transaction - Throws:
InvalidArgumentException
ProposalException
-
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
BlockInfo
for the Block containing the transaction - Throws:
InvalidArgumentException
ProposalException
-
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
BlockInfo
for the Block containing the transaction - Throws:
InvalidArgumentException
ProposalException
-
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
BlockInfo
for the Block containing the transaction - Throws:
InvalidArgumentException
ProposalException
-
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
BlockInfo
for the Block containing the transaction - Throws:
InvalidArgumentException
ProposalException
-
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
BlockInfo
for the Block containing the transaction - Throws:
InvalidArgumentException
ProposalException
-
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
BlockchainInfo
object containing the chain info requested - Throws:
InvalidArgumentException
ProposalException
-
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
BlockchainInfo
object containing the chain info requested - Throws:
InvalidArgumentException
ProposalException
-
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
BlockchainInfo
object containing the chain info requested - Throws:
InvalidArgumentException
ProposalException
-
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
BlockchainInfo
object containing the chain info requested - Throws:
InvalidArgumentException
ProposalException
-
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
BlockchainInfo
object containing the chain info requested - Throws:
InvalidArgumentException
ProposalException
-
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:
ProposalException
InvalidArgumentException
-
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:
ProposalException
InvalidArgumentException
-
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:
ProposalException
InvalidArgumentException
-
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:
ProposalException
InvalidArgumentException
-
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:
ProposalException
InvalidArgumentException
-
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:
InvalidArgumentException
ProposalException
-
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:
InvalidArgumentException
ProposalException
-
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:
InvalidArgumentException
ProposalException
-
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:
InvalidArgumentException
ProposalException
-
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:
InvalidArgumentException
ProposalException
ServiceDiscoveryException
-
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:
InvalidArgumentException
ProposalException
-
queryByChaincode
public java.util.Collection<ProposalResponse> queryByChaincode(QueryByChaincodeRequest queryByChaincodeRequest) throws InvalidArgumentException, ProposalException
Send Query proposal- Parameters:
queryByChaincodeRequest
-- Returns:
- Collection proposal responses.
- Throws:
InvalidArgumentException
ProposalException
-
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:
InvalidArgumentException
ProposalException
-
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 InvalidArgumentException
Unregister 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 InvalidArgumentException
Register 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 InvalidArgumentException
Unregister 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, InvalidArgumentException
Serialize channel to a file using Java serialization. Deserialized channel will NOT be in an initialized state.- Parameters:
file
- file- Throws:
java.io.IOException
InvalidArgumentException
-
serializeChannel
public byte[] serializeChannel() throws java.io.IOException, InvalidArgumentException
Serialize channel to a byte array using Java serialization. Deserialized channel will NOT be in an initialized state.- Throws:
InvalidArgumentException
java.io.IOException
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
-