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:
Bret Harrison 2020-02-04 20:12:33 -05:00
parent 571733f7b9
commit ee83195685
18 changed files with 41 additions and 4919 deletions

File diff suppressed because it is too large Load diff

View file

@ -10,8 +10,7 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"fabric-network": "beta",
"fabric-client": "beta",
"fabric-network": "unstable",
"js-yaml": "^3.12.0"
},
"devDependencies": {

File diff suppressed because it is too large Load diff

View file

@ -10,8 +10,7 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"fabric-network": "beta",
"fabric-client": "beta",
"fabric-network": "unstable",
"js-yaml": "^3.12.0"
},
"devDependencies": {

View file

@ -25,9 +25,11 @@ async function main() {
return;
}
let connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
// Create a new gateway for connecting to our peer node.
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.
const network = await gateway.getNetwork('mychannel');

View file

@ -16,7 +16,7 @@
"license": "Apache-2.0",
"dependencies": {
"fabric-ca-client": "beta",
"fabric-network": "beta"
"fabric-network": "unstable"
},
"devDependencies": {
"chai": "^4.2.0",

View file

@ -6,6 +6,7 @@
const { Gateway, Wallets } = require('fabric-network');
const path = require('path');
const fs = require('fs');
const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json');
@ -25,9 +26,11 @@ async function main() {
return;
}
let connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
// Create a new gateway for connecting to our peer node.
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.
const network = await gateway.getNetwork('mychannel');

View file

@ -32,9 +32,11 @@ async function main() {
return;
}
let connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
// Create a new gateway for connecting to our peer node.
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.
const client = gateway.getClient();

View file

@ -19,7 +19,7 @@
"license": "Apache-2.0",
"dependencies": {
"fabric-ca-client": "beta",
"fabric-network": "beta"
"fabric-network": "unstable"
},
"devDependencies": {
"@types/chai": "^4.1.7",

View file

@ -4,6 +4,7 @@
import { Gateway, Wallets } from 'fabric-network';
import * as path from 'path';
import * as fs from 'fs';
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');
@ -23,9 +24,11 @@ async function main() {
return;
}
const connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
// Create a new gateway for connecting to our peer node.
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.
const network = await gateway.getNetwork('mychannel');

View file

@ -4,6 +4,7 @@
import { Gateway, Wallets } from 'fabric-network';
import * as path from 'path';
import * as fs from 'fs';
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');
@ -23,9 +24,11 @@ async function main() {
return;
}
const connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
// Create a new gateway for connecting to our peer node.
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.
const network = await gateway.getNetwork('mychannel');

View file

@ -4,6 +4,7 @@
import { Gateway, Wallets, X509Identity } from 'fabric-network';
import * as path from 'path';
import * as fs from 'fs';
const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json');
@ -30,9 +31,11 @@ async function main() {
return;
}
const connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
// Create a new gateway for connecting to our peer node.
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.
const client = gateway.getClient();

View file

@ -70,7 +70,7 @@ async function main() {
// Parse the connection profile. This would be the path to the file downloaded
// from the IBM Blockchain Platform operational console.
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
// 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
// specified must already exist in the specified wallet.
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.
const network = await gateway.getNetwork(channelid);

View file

@ -48,8 +48,6 @@ const couchdbutil = require('./couchdbutil.js');
const blockProcessing = require('./blockProcessing.js');
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 channelid = config.channelid;
@ -109,9 +107,11 @@ async function main() {
return;
}
const connectionProfile = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
// Create a new gateway for connecting to our peer node.
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.
const network = await gateway.getNetwork('mychannel');

View file

@ -46,9 +46,9 @@ exports.processBlockEvent = async function (channelname, block, use_couchdb, nan
}
// 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
// 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) {
continue();
}

View file

@ -44,10 +44,12 @@ async function main() {
const walletPath = path.resolve(__dirname, 'wallet');
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
// specified must already exist in the specified wallet.
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.
const network = await gateway.getNetwork(channelid);

View file

@ -16,7 +16,7 @@
"license": "Apache-2.0",
"dependencies": {
"fabric-ca-client": "beta",
"fabric-network": "beta"
"fabric-network": "unstable"
},
"devDependencies": {
"chai": "^4.2.0",

View file

@ -47,7 +47,7 @@ async function main() {
// Create a new gateway, and connect to the gateway peer node(s). The identity
// specified must already exist in the specified wallet.
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.
const network = await gateway.getNetwork(channelid);