mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-25 19:15:10 +00:00
FAB-17456 fabric-samples - pre-read ccp
Applications must pass an 'Common Connection Profile' object to the Gateway as of v2. NodeSDK should not have access to the file system. Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
This commit is contained in:
parent
571733f7b9
commit
ee83195685
18 changed files with 41 additions and 4919 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -10,8 +10,7 @@
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fabric-network": "beta",
|
"fabric-network": "unstable",
|
||||||
"fabric-client": "beta",
|
|
||||||
"js-yaml": "^3.12.0"
|
"js-yaml": "^3.12.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -10,8 +10,7 @@
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fabric-network": "beta",
|
"fabric-network": "unstable",
|
||||||
"fabric-client": "beta",
|
|
||||||
"js-yaml": "^3.12.0"
|
"js-yaml": "^3.12.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,11 @@ async function main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
|
||||||
|
|
||||||
// Create a new gateway for connecting to our peer node.
|
// Create a new gateway for connecting to our peer node.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
await gateway.connect(connectionProfile, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the network (channel) our contract is deployed to.
|
// Get the network (channel) our contract is deployed to.
|
||||||
const network = await gateway.getNetwork('mychannel');
|
const network = await gateway.getNetwork('mychannel');
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fabric-ca-client": "beta",
|
"fabric-ca-client": "beta",
|
||||||
"fabric-network": "beta"
|
"fabric-network": "unstable"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
const { Gateway, Wallets } = require('fabric-network');
|
const { Gateway, Wallets } = require('fabric-network');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json');
|
const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json');
|
||||||
|
|
||||||
|
|
@ -25,9 +26,11 @@ async function main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
|
||||||
|
|
||||||
// Create a new gateway for connecting to our peer node.
|
// Create a new gateway for connecting to our peer node.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
await gateway.connect(connectionProfile, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the network (channel) our contract is deployed to.
|
// Get the network (channel) our contract is deployed to.
|
||||||
const network = await gateway.getNetwork('mychannel');
|
const network = await gateway.getNetwork('mychannel');
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,11 @@ async function main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
|
||||||
|
|
||||||
// Create a new gateway for connecting to our peer node.
|
// Create a new gateway for connecting to our peer node.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccpPath, { wallet, identity: 'admin', discovery: { enabled: true, asLocalhost: true } });
|
await gateway.connect(connectionProfile, { wallet, identity: 'admin', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the CA client object from the gateway for interacting with the CA.
|
// Get the CA client object from the gateway for interacting with the CA.
|
||||||
const client = gateway.getClient();
|
const client = gateway.getClient();
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fabric-ca-client": "beta",
|
"fabric-ca-client": "beta",
|
||||||
"fabric-network": "beta"
|
"fabric-network": "unstable"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chai": "^4.1.7",
|
"@types/chai": "^4.1.7",
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
import { Gateway, Wallets } from 'fabric-network';
|
import { Gateway, Wallets } from 'fabric-network';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');
|
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');
|
||||||
|
|
||||||
|
|
@ -23,9 +24,11 @@ async function main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
|
||||||
|
|
||||||
// Create a new gateway for connecting to our peer node.
|
// Create a new gateway for connecting to our peer node.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
await gateway.connect(connectionProfile, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the network (channel) our contract is deployed to.
|
// Get the network (channel) our contract is deployed to.
|
||||||
const network = await gateway.getNetwork('mychannel');
|
const network = await gateway.getNetwork('mychannel');
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
import { Gateway, Wallets } from 'fabric-network';
|
import { Gateway, Wallets } from 'fabric-network';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');
|
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');
|
||||||
|
|
||||||
|
|
@ -23,9 +24,11 @@ async function main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
|
||||||
|
|
||||||
// Create a new gateway for connecting to our peer node.
|
// Create a new gateway for connecting to our peer node.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
await gateway.connect(connectionProfile, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the network (channel) our contract is deployed to.
|
// Get the network (channel) our contract is deployed to.
|
||||||
const network = await gateway.getNetwork('mychannel');
|
const network = await gateway.getNetwork('mychannel');
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
import { Gateway, Wallets, X509Identity } from 'fabric-network';
|
import { Gateway, Wallets, X509Identity } from 'fabric-network';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');
|
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');
|
||||||
|
|
||||||
|
|
@ -30,9 +31,11 @@ async function main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
|
||||||
|
|
||||||
// Create a new gateway for connecting to our peer node.
|
// Create a new gateway for connecting to our peer node.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccpPath, { wallet, identity: 'admin', discovery: { enabled: true, asLocalhost: true } });
|
await gateway.connect(connectionProfile, { wallet, identity: 'admin', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the CA client object from the gateway for interacting with the CA.
|
// Get the CA client object from the gateway for interacting with the CA.
|
||||||
const client = gateway.getClient();
|
const client = gateway.getClient();
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ async function main() {
|
||||||
// Parse the connection profile. This would be the path to the file downloaded
|
// Parse the connection profile. This would be the path to the file downloaded
|
||||||
// from the IBM Blockchain Platform operational console.
|
// from the IBM Blockchain Platform operational console.
|
||||||
const ccpPath = path.resolve(__dirname, '..', 'first-network', 'connection-org1.json');
|
const ccpPath = path.resolve(__dirname, '..', 'first-network', 'connection-org1.json');
|
||||||
const ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
|
const connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
|
||||||
|
|
||||||
// Configure a wallet. This wallet must already be primed with an identity that
|
// Configure a wallet. This wallet must already be primed with an identity that
|
||||||
// the application can use to interact with the peer node.
|
// the application can use to interact with the peer node.
|
||||||
|
|
@ -80,7 +80,7 @@ async function main() {
|
||||||
// Create a new gateway, and connect to the gateway peer node(s). The identity
|
// Create a new gateway, and connect to the gateway peer node(s). The identity
|
||||||
// specified must already exist in the specified wallet.
|
// specified must already exist in the specified wallet.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
await gateway.connect(connectionProfile, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the network channel that the smart contract is deployed to.
|
// Get the network channel that the smart contract is deployed to.
|
||||||
const network = await gateway.getNetwork(channelid);
|
const network = await gateway.getNetwork(channelid);
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,6 @@ const couchdbutil = require('./couchdbutil.js');
|
||||||
const blockProcessing = require('./blockProcessing.js');
|
const blockProcessing = require('./blockProcessing.js');
|
||||||
|
|
||||||
const ccpPath = path.resolve(__dirname, '..', 'first-network', 'connection-org1.json');
|
const ccpPath = path.resolve(__dirname, '..', 'first-network', 'connection-org1.json');
|
||||||
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
|
|
||||||
const ccp = JSON.parse(ccpJSON);
|
|
||||||
|
|
||||||
const config = require('./config.json');
|
const config = require('./config.json');
|
||||||
const channelid = config.channelid;
|
const channelid = config.channelid;
|
||||||
|
|
@ -109,9 +107,11 @@ async function main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
|
||||||
|
|
||||||
// Create a new gateway for connecting to our peer node.
|
// Create a new gateway for connecting to our peer node.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
await gateway.connect(connectionProfile, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the network (channel) our contract is deployed to.
|
// Get the network (channel) our contract is deployed to.
|
||||||
const network = await gateway.getNetwork('mychannel');
|
const network = await gateway.getNetwork('mychannel');
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,9 @@ exports.processBlockEvent = async function (channelname, block, use_couchdb, nan
|
||||||
}
|
}
|
||||||
|
|
||||||
// tx may be rejected at commit stage by peers
|
// tx may be rejected at commit stage by peers
|
||||||
// only valid transactions (code=0) update the word state and off-chain db
|
// only valid transactions (code=0) update the world state and off-chain db
|
||||||
// filter through valid tx, refer below for list of error codes
|
// filter through valid tx, refer below for list of error codes
|
||||||
// https://github.com/hyperledger/fabric-sdk-node/blob/release-1.4/fabric-client/lib/protos/peer/transaction.proto
|
// https://github.com/hyperledger/fabric-sdk-node/blob/release-2.0/fabric-protos/protos/peer/transaction.proto
|
||||||
if (txSuccess[dataItem] !== 0) {
|
if (txSuccess[dataItem] !== 0) {
|
||||||
continue();
|
continue();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,12 @@ async function main() {
|
||||||
const walletPath = path.resolve(__dirname, 'wallet');
|
const walletPath = path.resolve(__dirname, 'wallet');
|
||||||
const wallet = new FileSystemWallet(walletPath);
|
const wallet = new FileSystemWallet(walletPath);
|
||||||
|
|
||||||
|
const connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
|
||||||
|
|
||||||
// Create a new gateway, and connect to the gateway peer node(s). The identity
|
// Create a new gateway, and connect to the gateway peer node(s). The identity
|
||||||
// specified must already exist in the specified wallet.
|
// specified must already exist in the specified wallet.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
await gateway.connect(connectionProfile, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the network channel that the smart contract is deployed to.
|
// Get the network channel that the smart contract is deployed to.
|
||||||
const network = await gateway.getNetwork(channelid);
|
const network = await gateway.getNetwork(channelid);
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fabric-ca-client": "beta",
|
"fabric-ca-client": "beta",
|
||||||
"fabric-network": "beta"
|
"fabric-network": "unstable"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ async function main() {
|
||||||
// Create a new gateway, and connect to the gateway peer node(s). The identity
|
// Create a new gateway, and connect to the gateway peer node(s). The identity
|
||||||
// specified must already exist in the specified wallet.
|
// specified must already exist in the specified wallet.
|
||||||
const gateway = new Gateway();
|
const gateway = new Gateway();
|
||||||
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
await gateway.connect(ccp, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
||||||
|
|
||||||
// Get the network channel that the smart contract is deployed to.
|
// Get the network channel that the smart contract is deployed to.
|
||||||
const network = await gateway.getNetwork(channelid);
|
const network = await gateway.getNetwork(channelid);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue