Module: composer-runtime

The runtime module provides the API that is made available to transaction
processing functions.

Source:

Classes

AccessException
AssetRegistry
Factory
ParticipantRegistry

Methods


getAssetRegistry(id)

Get an existing asset registry using the unique identifier of the asset
registry. An asset registry can be used to retrieve, update, or delete
existing assets, or create new assets.

Parameters:
Name Type Description
id string

The ID of the asset registry.

Source:
Returns:

A promise. The promise is resolved with an {@link
module:composer-runtime.AssetRegistry AssetRegistry} instance
representing the asset registry if it exists. If the asset registry
does not exist, or the current user does not have access to the asset
registry, then the promise will be rejected with an error that describes
the problem.

Type
Promise
Example
// Get the vehicle asset registry.
return getAssetRegistry('org.acme.Vehicle')
  .then(function (vehicleAssetRegistry) {
    // Call methods on the vehicle asset registry.
  })
  .catch(function (error) {
    // Add optional error handling here.
  });

getCurrentParticipant()

Get the current participant. The current participant is determined by
the identity that was used to submit the current transaction.

Source:
Returns:

The current participant,
or null if the transaction was submitted using an identity that does
not map to a participant.

Type
module:composer-common.Resource
Example
// Get the current participant.
var currentParticipant = getCurrentParticipant();
// Check to see if the current participant is a driver.
if (currentParticipant.getFullyQualifiedType() !== 'org.acme.Driver') {
  // Throw an error as the current participant is not a driver.
  throw new Error('Current participant is not a driver');
}
// Check to see if the current participant is the first driver.
if (currentParticipant.getFullyQualifiedIdentifier() !== 'org.acme.Driver#DRIVER_1') {
  // Throw an error as the current participant is not a driver.
  throw new Error('Current participant is not the first driver');
}

getFactory()

Get the factory. The factory can be used to create new instances of
assets, participants, and transactions for storing in registries. The
factory can also be used for creating relationships to assets, particpants,
and transactions.

Source:
Returns:

The factory.

Type
module:composer-runtime.Factory
Example
// Get the factory.
var factory = getFactory();

getParticipantRegistry(id)

Get an existing participant registry using the unique identifier of the participant
registry. An participant registry can be used to retrieve, update, or delete
existing participants, or create new participants.

Parameters:
Name Type Description
id string

The ID of the participant registry.

Source:
Returns:

A promise. The promise is resolved with an {@link
module:composer-runtime.ParticipantRegistry ParticipantRegistry} instance
representing the participant registry if it exists. If the participant registry
does not exist, or the current user does not have access to the participant
registry, then the promise will be rejected with an error that describes
the problem.

Type
Promise
Example
// Get the driver participant registry.
return getParticipantRegistry('org.acme.Driver')
  .then(function (driverParticipantRegistry) {
    // Call methods on the driver participant registry.
  })
  .catch(function (error) {
    // Add optional error handling here.
  });