Skip to content

Commit 7e63f2b

Browse files
committed
BLOCKOTUS/blockotus-organism#16 trycatch to promise
1 parent b7d8c6f commit 7e63f2b

File tree

7 files changed

+883
-164
lines changed

7 files changed

+883
-164
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

fabric/helper/javascript/.gitignore

Lines changed: 0 additions & 77 deletions
This file was deleted.

fabric/helper/javascript/index.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*/
4+
5+
'use strict';
6+
7+
const { Gateway, Wallets } = require('fabric-network');
8+
const fs = require('fs');
9+
const path = require('path');
10+
11+
const WALLET_PATH = path.join(__dirname, '..', '..', '..', '..', '..', 'wallet');
12+
const CCP_PATH = path.resolve(__dirname, '..', '..', '..', '..', '..', 'network', 'organizations', 'peerOrganizations', 'org1.example.com', 'connection-org1.json');
13+
14+
async function getContractAndGateway({username, chaincode, contract}) {
15+
// load the network configuration
16+
const ccp = JSON.parse(fs.readFileSync(CCP_PATH, 'utf8'));
17+
18+
// Create a new file system based wallet for managing identities.
19+
const wallet = await Wallets.newFileSystemWallet(WALLET_PATH);
20+
21+
// Check to see if we've already enrolled the user.
22+
const identity = await wallet.get(username);
23+
if (!identity) throw new Error(`An identity for the user "${username}" does not exist in the wallet`);
24+
25+
// Create a new gateway for connecting to our peer node.
26+
const gateway = new Gateway();
27+
await gateway.connect(ccp, { identity, discovery: { enabled: true, asLocalhost: true } });
28+
29+
// Get the network (channel) our contract is deployed to.
30+
const network = await gateway.getNetwork('mychannel');
31+
32+
// Get the contract from the network.
33+
return {contract: network.getContract(chaincode, contract), gateway};
34+
}
35+
36+
37+
module.exports = {
38+
getContractAndGateway
39+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "javascript",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"fabric-network": "^2.2.2"
13+
}
14+
}

0 commit comments

Comments
 (0)