Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Make Node Red Nodes Use Cards (#75)
Browse files Browse the repository at this point in the history
Updated to use cards
Updated version of composer to 0.15

contributes to hyperledger/composer-tools#74

Signed-off-by: Caroline Church <[email protected]>
  • Loading branch information
cazfletch authored Nov 14, 2017
1 parent 73c4337 commit e7261dd
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 72 deletions.
8 changes: 5 additions & 3 deletions packages/node-red-contrib-composer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ In this example we will create a participant, the participant .

2. Create a `hyperledger-composer-out node`

3. Enter the `connection profile name`, `business network identifier`, `user Id`, and `user secret` on the `hyperledger-composer-out node`.
3. On `Composer Card` click the pencil top add a new config node. Specify the `card name`, or use the drop down to use one previous created.

4. Use an inject node and set it to use `JSON` and enter the following JSON

Expand All @@ -33,8 +33,8 @@ A node red mid flow node that allows you to create, retrieve, update, or delete
This example follows on from the above example. It will retrieve the participant that was created above.

1. Create a `hyperledger-composer-mid node`
2. Enter the `connection profile name`, `business network identifier`, `user Id`, and `user secret` on the `hyperledger-composer-mid node`.

2. On `Composer Card` click the pencil top add a new config node. Specify the `card name`, or use the drop down to use one previous created.

3. Use an `inject node` and set it to use JSON and enter the following JSON

Expand All @@ -46,3 +46,5 @@ This example follows on from the above example. It will retrieve the participant

##Hyperledger-Composer-In
A node red input node that subscribes to events from a blockchain

1. On `Composer Card` click the pencil top add a new config node. Specify the `card name`, or use the drop down to use one previous created.
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,18 @@
RED.nodes.registerType('hyperledger-composer-config',{
category: 'config',
defaults: {
connectionProfile: {value:"hlfv1",required:true},
businessNetworkIdentifier: {value:"",required:true},
userID: {value:"",required:true},
userSecret: {value:"",required:true},
cardName: {value:"",required:true}

},
label: function() {
return this.connectionProfile+":"+this.businessNetworkIdentifier;
return this.cardName;
}
});
</script>

<script type="text/x-red" data-template-name="hyperledger-composer-config">
<div class="form-row">
<label for="node-config-input-connectionProfile"><i class="icon-bookmark"></i>Connection Profile</label>
<input type="text" id="node-config-input-connectionProfile">
<label for="node-config-input-cardName"><i class="icon-bookmark"></i>Card Name</label>
<input type="text" id="node-config-input-cardName">
</div>
<div class="form-row">
<label for="node-config-input-businessNetworkIdentifier"><i class="icon-bookmark"></i>Business Network Identifier</label>
<input type="text" id="node-config-input-businessNetworkIdentifier" placeholder="my-network">
</div>
<div class="form-row">
<label for="node-config-input-userID"><i class="icon-bookmark"></i>User ID</label>
<input type="text" id="node-config-input-userID" placeholder="admin">
</div>
<div class="form-row">
<label for="node-config-input-userSecret"><i class="icon-bookmark"></i>User Secret</label>
<input type="password" id="node-config-input-userSecret" placeholder="adminpw">
</div>

</script>
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
module.exports = function(RED) {
function HyperledgerComposerConfigNode(n) {
RED.nodes.createNode(this,n);
this.connectionProfile = n.connectionProfile;
this.businessNetworkIdentifier = n.businessNetworkIdentifier;
this.userID = n.userID;
this.userSecret = n.userSecret;
this.cardName = n.cardName;
}
RED.nodes.registerType("hyperledger-composer-config",HyperledgerComposerConfigNode);
}
};
20 changes: 10 additions & 10 deletions packages/node-red-contrib-composer/nodes/hyperledger-composer.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
</div>

<div class="form-row">
<label for="node-input-composerProfile"><i class="fa fa-tag"></i>Composer Profile</label>
<input type="select" id="node-input-composerProfile" placeholder="Composer"/>
<label for="node-input-composerCard"><i class="fa fa-tag"></i>Composer Card</label>
<input type="select" id="node-input-composerCard" placeholder="Composer"/>

</div>
<div class="form-row">
Expand All @@ -41,11 +41,11 @@
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
</div>
<div class="form-row">
<label for="node-input-composerProfile"><i class="fa fa-tag"></i>Composer Profile</label>
<input type="select" id="node-input-composerProfile" placeholder="Composer"/>
<label for="node-input-composerCard"><i class="fa fa-tag"></i>Composer PCard</label>
<input type="select" id="node-input-composerCard" placeholder="Composer"/>
</div>
<div class="form-row">
<label for="node-input-connectionProfile"><i class="fa fa-tag"></i> Action</label>
<label for="node-input-actionType"><i class="fa fa-tag"></i> Action</label>
<select id="node-input-actionType">
<option value="create">Create</option>
<option value="retrieve">Retrieve</option>
Expand All @@ -66,8 +66,8 @@
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
</div>
<div class="form-row">
<label for="node-input-composerProfile"><i class="fa fa-tag"></i>Composer Profile</label>
<input type="select" id="node-input-composerProfile" placeholder="Composer"/>
<label for="node-input-composerCard"><i class="fa fa-tag"></i>Composer Card</label>
<input type="select" id="node-input-composerCard" placeholder="Composer"/>

</div>
</script>
Expand All @@ -85,7 +85,7 @@
paletteLabel: "Hyperledger Composer",
defaults: {
name: {value: ""},
composerProfile: {value:"", type:"hyperledger-composer-config"},
composerCard: {value:"", type:"hyperledger-composer-config"},
actionType: {value: "create"}

},
Expand All @@ -110,7 +110,7 @@
paletteLabel: "Hyperledger Composer",
defaults: {
name: {value: ""},
composerProfile: {value:"", type:"hyperledger-composer-config"},
composerCard: {value:"", type:"hyperledger-composer-config"},
actionType: {value: "create"}
},
inputs : 0,
Expand All @@ -136,7 +136,7 @@
paletteLabel: "Hyperledger Composer",
defaults: {
name: {value: ""},
composerProfile: {value:"", type:"hyperledger-composer-config"},
composerCard: {value:"", type:"hyperledger-composer-config"},
actionType : {value : "create"},
resolve: {value:false},
},
Expand Down
46 changes: 14 additions & 32 deletions packages/node-red-contrib-composer/nodes/hyperledger-composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = function (RED) {
let connectionPromise;
let businessNetworkConnection = new BusinessNetworkConnection();

let connectionProfileName, businessNetworkIdentifier, userID, userSecret;
let cardName;
let businessNetworkDefinition, serializer;

let listener;
Expand All @@ -38,15 +38,11 @@ module.exports = function (RED) {
*/
function connectInternal (node) {
node.log('connectInternal');
node.log('settings: connectionProfileName' + connectionProfileName + ' businessNetworkIdentifier ' + businessNetworkIdentifier + ' userID ' + userID + ' userSecret ' + userSecret);
node.log('settings: cardName' + cardName);
connecting = true;
connected = false;
connectionPromise = businessNetworkConnection
.connect(connectionProfileName,
businessNetworkIdentifier,
userID,
userSecret
)
.connect(cardName)
.then((result) => {
// setup some objects for this business network
businessNetworkDefinition = result;
Expand Down Expand Up @@ -203,7 +199,7 @@ module.exports = function (RED) {
})
.then((result) => {
node.log('got asset');
if(resolve) {
if (resolve) {
return result;
} else {
return serializer.toJSON(result);
Expand Down Expand Up @@ -364,14 +360,8 @@ module.exports = function (RED) {
function checkConfig (config) {
return Promise.resolve().then(() => {

if (!config.connectionProfile) {
throw new Error('connection profile must be set');
} else if (!config.businessNetworkIdentifier) {
throw new Error('business network identifier must be set');
} else if (!config.userID) {
throw new Error('user ID must be set');
} else if (!config.userSecret) {
throw new Error('user secret must be set');
if (!config.cardName) {
throw new Error('card name must be set');
}

return '';
Expand Down Expand Up @@ -408,14 +398,12 @@ module.exports = function (RED) {
RED.nodes.createNode(node, config);

node.on('input', function (msg) {
node.log('checking config');
this.composer = RED.nodes.getNode(config.composerProfile);
node.log('config ' + config.composerCard);
this.composer = RED.nodes.getNode(config.composerCard);
node.log('checking config' + this.composer);
checkConfig(this.composer)
.then(() => {
connectionProfileName = this.composer.connectionProfile;
businessNetworkIdentifier = this.composer.businessNetworkIdentifier;
userID = this.composer.userID;
userSecret = this.composer.userSecret;
cardName = this.composer.cardName;

node.log('checking payload');
return checkPayLoad(msg.payload, config.actionType);
Expand Down Expand Up @@ -455,13 +443,10 @@ module.exports = function (RED) {

node.on('input', function (msg) {
node.log('checking config');
this.composer = RED.nodes.getNode(config.composerProfile);
this.composer = RED.nodes.getNode(config.composerCard);
checkConfig(this.composer)
.then(() => {
connectionProfileName = this.composer.connectionProfile;
businessNetworkIdentifier = this.composer.businessNetworkIdentifier;
userID = this.composer.userID;
userSecret = this.composer.userSecret;
cardName = this.composer.cardName;

return checkPayLoad(msg.payload, config.actionType);

Expand Down Expand Up @@ -506,14 +491,11 @@ module.exports = function (RED) {
function HyperledgerComposerInNode (config) {
let node = this;
RED.nodes.createNode(node, config);
this.composer = RED.nodes.getNode(config.composerProfile);
this.composer = RED.nodes.getNode(config.composerCard);
node.log('checking config');
checkConfig(this.composer)
.then(() => {
connectionProfileName = this.composer.connectionProfile;
businessNetworkIdentifier = this.composer.businessNetworkIdentifier;
userID = this.composer.userID;
userSecret = this.composer.userSecret;
cardName = this.composer.cardName;

return subscribeToEvents(node);

Expand Down
4 changes: 2 additions & 2 deletions packages/node-red-contrib-composer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.0.9",
"description": "Hyperledger Composer nodes for node-red",
"dependencies": {
"composer-client": "^0.14.0-0",
"composer-common": "^0.14.0-0"
"composer-client": "^0.15.0-0",
"composer-common": "^0.15.0-0"
},
"devDependencies": {
"eslint": "^3.5.0"
Expand Down

0 comments on commit e7261dd

Please sign in to comment.