new BusinessNetworkConnection( [options])
Create an instance of the BusinessNetworkConnection class.
must be called to connect to a deployed BusinessNetworkDefinition.
Parameters:
Name | Type | Argument | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
an optional set of options to configure the instance. Properties
|
- Source:
- See:
-
See EventEmitter
Extends
- EventEmitter
Methods
-
addAssetRegistry(id, name)
-
Add a new asset registry.
Parameters:
Name Type Description id
string The unique identifier of the asset registry
name
string The name of the asset registry
Returns:
- A promise that will be resolved with the new asset
registry after it has been added.
- Type
- Promise
Example
// Add a new asset registry var businessNetwork = new BusinessNetworkConnection(); return businessNetwork.connect('testprofile', 'businessNetworkIdentifier', 'WebAppAdmin', 'DJY27pEnl16d') .then(function(businessNetworkDefinition){ return businessNetworkDefinition.addAssetRegistry('registryId','registryName'); });
- A promise that will be resolved with the new asset
-
addParticipantRegistry(id, name)
-
Add a new participant registry.
Parameters:
Name Type Description id
string The unique identifier of the participant registry
name
string The name of the participant registry
Returns:
- A promise that will be resolved with the new participant
registry after it has been added.
- Type
- Promise
Example
// Add a new participant registry var businessNetwork = new BusinessNetworkConnection(); return businessNetwork.connect('testprofile', 'businessNetworkIdentifier', 'WebAppAdmin', 'DJY27pEnl16d') .then(function(businessNetworkDefinition){ return businessNetworkDefinition.addParticipantRegistry('registryId','registryName'); });
- A promise that will be resolved with the new participant
-
connect(connectionProfile, businessNetwork, enrollmentID, enrollmentSecret)
-
Connects to a business network using a connection profile, and authenticates to the Hyperledger Fabric.
Parameters:
Name Type Description connectionProfile
string The name of the connection profile
businessNetwork
string The identifier of the business network
enrollmentID
string the enrollment ID of the user
enrollmentSecret
string the enrollment secret of the user
Returns:
A promise to a BusinessNetworkDefinition that indicates the connection is complete
- Type
- Promise
Example
// Connect and log in to HLF var businessNetwork = new BusinessNetworkConnection(); return businessNetwork.connect('testprofile', 'businessNetworkIdentifier', 'WebAppAdmin', 'DJY27pEnl16d') .then(function(businessNetworkDefinition){ // Connected });
-
disconnect()
-
Disconnects from the Hyperledger Fabric.
Returns:
A promise that will be resolved when the connection is
terminated.- Type
- Promise
Example
// Disconnects from HLF var businessNetwork = new BusinessNetworkConnection(); return businessNetwork.connect('testprofile', 'businessNetworkIdentifier', 'WebAppAdmin', 'DJY27pEnl16d') .then(function(businessNetworkDefinition){ return businessNetworkDefinition.disconnect(); }) .then(function(){ // Disconnected. });
-
existsAssetRegistry(id)
-
Determine whether a asset registry exists.
Parameters:
Name Type Description id
string The unique identifier of the asset registry
Returns:
- A promise that will be resolved with a boolean indicating whether the asset
registry exists.
- Type
- Promise
Example
// Determine whether an asset registry exists var businessNetwork = new BusinessNetworkConnection(); return businessNetwork.connect('testprofile', 'businessNetworkIdentifier', 'WebAppAdmin', 'DJY27pEnl16d') .then(function(businessNetworkDefinition){ return businessNetworkDefinition.existsAssetRegistry('businessNetworkIdentifier.registryId'); }) .then(function(exists){ // if (exists === true) { // logic here... //} });
- A promise that will be resolved with a boolean indicating whether the asset
-
getAllAssetRegistries(securityContext)
-
Get a list of all existing asset registries.
Parameters:
Name Type Description securityContext
SecurityContext The user's security context
Returns:
- A promise that will be resolved with a list of existing
asset registries
- Type
- Promise
Example
// Get all asset registries var businessNetwork = new BusinessNetworkConnection(); return businessNetwork.connect('testprofile', 'businessNetworkIdentifier', 'WebAppAdmin', 'DJY27pEnl16d') .then(function(businessNetworkDefinition){ return businessNetworkDefinition.getAllAssetRegistries(); }) .then(function(assetRegistries){ // Retrieved Asset Registries });
- A promise that will be resolved with a list of existing
-
getAllParticipantRegistries(securityContext)
-
Get a list of all existing participant registries.
Parameters:
Name Type Description securityContext
SecurityContext The user's security context
Returns:
- A promise that will be resolved with a list of existing
participant registries
- Type
- Promise
Example
// Get all participant registries var businessNetwork = new BusinessNetworkConnection(); return businessNetwork.connect('testprofile', 'businessNetworkIdentifier', 'WebAppAdmin', 'DJY27pEnl16d') .then(function(businessNetworkDefinition){ return businessNetworkDefinition.getAllParticipantRegistries(); }) .then(function(participantRegistries){ // Retrieved Participant Registries });
- A promise that will be resolved with a list of existing
-
getAssetRegistry(id)
-
Get an existing asset registry.
Parameters:
Name Type Description id
string The unique identifier of the asset registry
Returns:
- A promise that will be resolved with the existing asset
registry, or rejected if the asset registry does not exist.
- Type
- Promise
Example
// Get a asset registry var businessNetwork = new BusinessNetworkConnection(); return businessNetwork.connect('testprofile', 'businessNetworkIdentifier', 'WebAppAdmin', 'DJY27pEnl16d') .then(function(businessNetworkDefinition){ return businessNetworkDefinition.getAssetRegistry('businessNetworkIdentifier.registryId'); }) .then(function(assetRegistry){ // Retrieved Asset Registry });
- A promise that will be resolved with the existing asset
-
getBusinessNetwork()
-
Returns the currently connected BusinessNetworkDefinition
Returns:
the business network
- Type
- BusinessNetworkDefinition
Example
// Get the Business Network Definition var businessNetwork = new BusinessNetworkConnection(); return businessNetwork.connect('testprofile', 'businessNetworkIdentifier', 'WebAppAdmin', 'DJY27pEnl16d') .then(function(businessNetworkDefinition){ return businessNetworkDefinition.getBusinessNetwork(); }) .then(function(BusinessNetworkDefinition){ // Retrieved Business Network Definition });
-
getParticipantRegistry(id)
-
Get an existing participant registry.
Parameters:
Name Type Description id
string The unique identifier of the participant registry
Returns:
- A promise that will be resolved with the existing participant
registry, or rejected if the participant registry does not exist.
- Type
- Promise
Example
// Get a participant registry var businessNetwork = new BusinessNetworkConnection(); return businessNetwork.connect('testprofile', 'businessNetworkIdentifier', 'WebAppAdmin', 'DJY27pEnl16d') .then(function(businessNetworkDefinition){ return businessNetworkDefinition.getParticipantRegistry('businessNetworkIdentifier.registryId'); }) .then(function(participantRegistry){ // Retrieved Participant Registry });
- A promise that will be resolved with the existing participant
-
getTransactionRegistry()
-
Get the transaction registry.
Returns:
- A promise that will be resolved to the TransactionRegistry
- Type
- Promise
Example
// Get the transaction registry var businessNetwork = new BusinessNetworkConnection(); return businessNetwork.connect('testprofile', 'businessNetworkIdentifier', 'WebAppAdmin', 'DJY27pEnl16d') .then(function(businessNetworkDefinition){ return businessNetworkDefinition.getTransactionRegistry(); }) .then(function(transactionRegistry){ // Retrieved Transaction Registry });
-
issueIdentity(participant, userID [, options])
-
Issue an identity with the specified user ID and map it to the specified
participant.Parameters:
Name Type Argument Description participant
Resource | string The participant, or the fully qualified
identifier of the participant. The participant must already exist.userID
string The user ID for the identity.
options
object <optional>
Options for the new identity.
Properties
Name Type Argument Description issuer
boolean <optional>
Whether or not the new identity should have
permissions to create additional new identities. False by default.Returns:
A promise that will be fulfilled when the identity has
been added to the specified participant. The promise will be rejected if
the participant does not exist, or if the identity is already mapped to
another participant.- Type
- Promise
-
ping()
-
Test the connection to the runtime and verify that the version of the
runtime is compatible with this level of the client node.js module.Returns:
A promise that will be fufilled when the connection has
been tested. The promise will be rejected if the version is incompatible.- Type
- Promise
Example
// Test the connection to the runtime var businessNetwork = new BusinessNetworkConnection(); return businessNetwork.connect('testprofile', 'businessNetworkIdentifier', 'WebAppAdmin', 'DJY27pEnl16d') .then(function(businessNetworkDefinition){ return businessNetworkDefinition.ping(); }) .then(function(){ // Connection tested. });
-
revokeIdentity(identity)
-
Revoke the specified identity by removing any existing mapping to a participant.
Parameters:
Name Type Description identity
string The identity, for example the enrollment ID.
Returns:
A promise that will be fulfilled when the identity has
been removed from the specified participant. The promise will be rejected if
the participant does not exist, or if the identity is not mapped to the
participant.- Type
- Promise
-
submitTransaction(transaction)
-
Submit a transaction for processing by the currently connected business network.
Parameters:
Name Type Description transaction
Resource The transaction to submit. Use {@link
Factory#newTransaction newTransaction} to create this object.Returns:
A promise that will be fulfilled when the transaction has
been processed.- Type
- Promise
Example
// Submits a transaction var businessNetwork = new BusinessNetworkConnection(); return businessNetwork.connect('testprofile', 'businessNetworkIdentifier', 'WebAppAdmin', 'DJY27pEnl16d') .then(function(businessNetworkDefinition){ var factory = businessNetworkDefinition.getBusinessNetwork().getFactory(); var transaction = factory.newTransaction('network.transactions', 'TransactionType'); return businessNetworkDefinition.submitTransaction(transaction); }) .then(function(){ // Submitted a transaction. });