Package org.hyperledger.fabric.client
Interface Gateway
- All Superinterfaces:
AutoCloseable
The Gateway provides the connection point for an application to access the Fabric network as a specific user. It is
instantiated from a Builder instance that is created using
newInstance()
, and configured using a gateway
URL and a signing identity. It can then be connected to a fabric network using the Builder's
connect()
method. Once connected, it can then access individual Network
instances
(channels) using the getNetwork()
method which in turn can access the Contract
installed on a network and submit transactions
to the ledger.
Gateway instances should be reused for multiple transaction invocations and only closed once connection to the Fabric network is no longer required.
Multiple Gateway instances may share the same underlying gRPC connection by supplying the gRPC Channel
as
an option to the Gateway connect.
Identity identity = new X509Identity("mspId", certificate);
Signer signer = Signers.newPrivateKeySigner(privateKey);
Gateway.Builder builder = Gateway.newInstance()
.identity(identity)
.signer(signer)
.connection(grpcChannel);
try (Gateway gateway = builder.connect()) {
Network network = gateway.getNetwork("channel");
// Interactions with the network
}
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
The builder is used to specify the options used when connecting a Gateway. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close the gateway connection and all associated resources, including removing listeners attached to networks and contracts created by the gateway.Returns the identity used to interact with Fabric.getNetwork
(String networkName) Returns an object representing a network.newBlockAndPrivateDataEventsRequest
(byte[] bytes) Recreate a block and private data events request from serialized data.newBlockEventsRequest
(byte[] bytes) Recreates a block events request from serialized bytes.newChaincodeEventsRequest
(byte[] bytes) Recreates a chaincode events request from serialized data.newCommit
(byte[] bytes) Recreates a commit from serialized data.newFilteredBlockEventsRequest
(byte[] bytes) Recreates a filtered block event request from serialized data.static Gateway.Builder
Creates a gateway builder which is used to configure and connect a new Gateway instance.newProposal
(byte[] proposalBytes) Recreates a proposal from serialized data.newSignedBlockAndPrivateDataEventsRequest
(byte[] bytes, byte[] signature) Create a block and private data events request with the specified digital signature, which can be used to receive block and private data events.newSignedBlockEventsRequest
(byte[] bytes, byte[] signature) Create a block events request with the specified digital signature, which can be used to receive block events.newSignedChaincodeEventsRequest
(byte[] bytes, byte[] signature) Create a chaincode events request with the specified digital signature, which can be used to obtain events emitted by transaction functions of a specific chaincode.newSignedCommit
(byte[] bytes, byte[] signature) Create a commit with the specified digital signature, which can be used to access information about a transaction that is committed to the ledger.newSignedFilteredBlockEventsRequest
(byte[] bytes, byte[] signature) Create a filtered block events request with the specified digital signature, which can be used to receive filtered block events.* Supports off-line signing flow.newSignedProposal
(byte[] proposalBytes, byte[] signature) Create a proposal with the specified digital signature.newSignedTransaction
(byte[] transactionBytes, byte[] signature) Create a transaction with the specified digital signature.newTransaction
(byte[] transactionBytes) Recreates a transaction from serialized data.
-
Method Details
-
newInstance
Creates a gateway builder which is used to configure and connect a new Gateway instance.- Returns:
- A gateway builder.
-
getIdentity
Identity getIdentity()Returns the identity used to interact with Fabric.- Returns:
- A client identity.
-
getNetwork
Returns an object representing a network.- Parameters:
networkName
- The name of the network (channel name)- Returns:
- A network.
- Throws:
NullPointerException
- if the network name is null.
-
newSignedProposal
Create a proposal with the specified digital signature. Supports off-line signing flow.- Parameters:
proposalBytes
- The proposal.signature
- A digital signature.- Returns:
- A signed proposal.
- Throws:
IllegalArgumentException
- if the supplied proposal bytes are not a valid proposal.
-
newProposal
Recreates a proposal from serialized data.- Parameters:
proposalBytes
- The proposal.- Returns:
- A proposal.
- Throws:
IllegalArgumentException
- if the supplied proposal bytes are not a valid proposal.
-
newSignedTransaction
Create a transaction with the specified digital signature. Supports off-line signing flow.- Parameters:
transactionBytes
- The transaction.signature
- A digital signature.- Returns:
- A signed transaction.
- Throws:
IllegalArgumentException
- if the supplied transaction bytes are not a valid transaction.
-
newTransaction
Recreates a transaction from serialized data.- Parameters:
transactionBytes
- The transaction.- Returns:
- A transaction.
- Throws:
IllegalArgumentException
- if the supplied transaction bytes are not a valid transaction.
-
newSignedCommit
Create a commit with the specified digital signature, which can be used to access information about a transaction that is committed to the ledger. Supports off-line signing flow.- Parameters:
bytes
- Serialized commit status request.signature
- Digital signature.- Returns:
- A signed commit status request.
- Throws:
IllegalArgumentException
- if the supplied commit bytes are not a valid commit.
-
newCommit
Recreates a commit from serialized data.- Parameters:
bytes
- Serialized commit status request.- Returns:
- A signed commit status request.
- Throws:
IllegalArgumentException
- if the supplied commit bytes are not a valid commit.
-
newSignedChaincodeEventsRequest
Create a chaincode events request with the specified digital signature, which can be used to obtain events emitted by transaction functions of a specific chaincode. Supports off-line signing flow.- Parameters:
bytes
- Serialized chaincode events request.signature
- Digital signature.- Returns:
- A signed chaincode events request.
- Throws:
IllegalArgumentException
- if the supplied chaincode events request bytes are not valid.
-
newChaincodeEventsRequest
Recreates a chaincode events request from serialized data.- Parameters:
bytes
- Serialized chaincode events request.- Returns:
- A chaincode events request.
- Throws:
IllegalArgumentException
- if the supplied chaincode events request bytes are not valid.
-
newSignedBlockEventsRequest
Create a block events request with the specified digital signature, which can be used to receive block events. Supports off-line signing flow.- Parameters:
bytes
- Serialized block events request.signature
- Digital signature.- Returns:
- A signed block events request.
- Throws:
IllegalArgumentException
- if the supplied request bytes are not valid.
-
newBlockEventsRequest
Recreates a block events request from serialized bytes.- Parameters:
bytes
- Serialized block events request.- Returns:
- A block events request.
- Throws:
IllegalArgumentException
- if the supplied request bytes are not valid.
-
newSignedFilteredBlockEventsRequest
Create a filtered block events request with the specified digital signature, which can be used to receive filtered block events.* Supports off-line signing flow.- Parameters:
bytes
- Serialized filtered block events request.signature
- Digital signature.- Returns:
- A signed filtered block events request.
- Throws:
IllegalArgumentException
- if the supplied request bytes are not valid.
-
newFilteredBlockEventsRequest
Recreates a filtered block event request from serialized data.- Parameters:
bytes
- Serialized filtered block events request.- Returns:
- A filtered block events request.
- Throws:
IllegalArgumentException
- if the supplied request bytes are not valid.
-
newSignedBlockAndPrivateDataEventsRequest
BlockAndPrivateDataEventsRequest newSignedBlockAndPrivateDataEventsRequest(byte[] bytes, byte[] signature) Create a block and private data events request with the specified digital signature, which can be used to receive block and private data events. Supports off-line signing flow.- Parameters:
bytes
- Serialized block and private data events request.signature
- Digital signature.- Returns:
- A signed block and private data events request.
- Throws:
IllegalArgumentException
- if the supplied request bytes are not valid.
-
newBlockAndPrivateDataEventsRequest
Recreate a block and private data events request from serialized data.- Parameters:
bytes
- Serialized block and private data events request.- Returns:
- A block and private data events request.
- Throws:
IllegalArgumentException
- if the supplied request bytes are not valid.
-
close
void close()Close the gateway connection and all associated resources, including removing listeners attached to networks and contracts created by the gateway.- Specified by:
close
in interfaceAutoCloseable
-