Migrating from Hyperledger Composer to Convector Framework — Marbles Example

Client Access

If you want to test the above methods in Composer, this is what you usually do:

const namespace = 'org.hyperledger_composer.marbles';
const factory = businessNetworkConnection.getBusinessNetwork().getFactory();
const dan = factory.newResource(namespace, 'Player', '[email protected]');
dan.firstName = 'Dan';
dan.lastName = 'Selman';
const simon = factory.newResource(namespace, 'Player', '[email protected]');
simon.firstName = 'Simon';
simon.lastName = 'Stone';
const playerRegistry = await businessNetworkConnection.getParticipantRegistry(namespace + '.Player');
await playerRegistry.addAll([dan, simon]);
const marble = factory.newResource(namespace, 'Marble', 'MARBLE_001');
marble.size = 'SMALL';
marble.color = 'RED';
marble.owner = factory.newRelationship(namespace, 'Player', dan.$identifier);
const marbleRegistry = await businessNetworkConnection.getAssetRegistry(namespace + '.Marble');
await marbleRegistry.add(marble);
const tradeMarble = factory.newTransaction(namespace, 'TradeMarble');
tradeMarble.newOwner = factory.newRelationship(namespace, 'Player', simon.$identifier);
tradeMarble.marble = factory.newRelationship(namespace, 'Marble', marble.$identifier);
await businessNetworkConnection.submitTransaction(tradeMarble);

In Convector, we have adapters to be able to use the same controller and model in the client applications.

const adapter = new FabricControllerAdapter(configuration);
const playerCtrl = new PlayerControllerClient(adapter);
const marbleCtrl = new MarbleControllerClient(adapter);
const dan = new Player({
id: '[email protected]',
firstName: 'Dan',
lastName: 'Selman'
});
await playerCtrl.register(dan);
const simon = new Player({
id: '[email protected]',
firstName: 'Simon',
lastName: 'Stone'
});
await playerCtrl.register(simon);
const marble = new Marble({
id: '1',
size: MarbleSize.SMALL,
color: MarbleColor.RED,
owner: dan.id
});
await marbleCtrl.create(marble);
await marbleCtrl.trade(marble.id, simon.id);

Each adapter has its own internal logic, the FabricControllerAdapter for instance, handles the network profile for communication with Fabric, but Convector is not tightly coupled with Fabric, so the community can create different adapters based on their needs. This is exactly how we plan to support other blockchains in the near future, by replacing the adapter with a new implementation.
Adapters don’t have any special treatment inside convector, they just dictate the communication with the blockchain layer so that the standard adapters that we have in Convector can be replaced by a custom implementation provided by the developers or the community.

read original article here