mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-25 02:55:09 +00:00
Improved gateway.disconnect usage in js/ts app, Improved comments
Signed-off-by: Sijo Cherian <sijo@ibm.com>
This commit is contained in:
parent
2f58fb29c4
commit
d5abf2b3a0
4 changed files with 63 additions and 50 deletions
|
|
@ -31,22 +31,25 @@ async function main() {
|
||||||
|
|
||||||
// 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(ccp, { wallet, identity: 'appUser', discovery: { enabled: true, asLocalhost: true } });
|
try {
|
||||||
|
await gateway.connect(ccp, { wallet, identity: 'appUser', 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');
|
||||||
|
|
||||||
// Get the contract from the network.
|
// Get the contract from the network.
|
||||||
const contract = network.getContract('fabcar');
|
const contract = network.getContract('fabcar');
|
||||||
|
|
||||||
// Submit the specified transaction.
|
// Submit the specified transaction: The transaction function name will be evaluated on the
|
||||||
// createCar transaction - requires 5 argument, ex: ('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom')
|
// endorsing peers and then submitted to the ordering service for committing to the ledger.
|
||||||
// changeCarOwner transaction - requires 2 args , ex: ('changeCarOwner', 'CAR12', 'Dave')
|
// createCar transaction - requires 5 argument, ex: ('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom')
|
||||||
await contract.submitTransaction('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom');
|
// changeCarOwner transaction - requires 2 args , ex: ('changeCarOwner', 'CAR12', 'Dave')
|
||||||
console.log('Transaction has been submitted');
|
await contract.submitTransaction('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom');
|
||||||
|
console.log('Transaction has been submitted');
|
||||||
// Disconnect from the gateway.
|
} finally {
|
||||||
await gateway.disconnect();
|
// Disconnect from the gateway.
|
||||||
|
gateway.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Failed to submit transaction: ${error}`);
|
console.error(`Failed to submit transaction: ${error}`);
|
||||||
|
|
|
||||||
|
|
@ -32,23 +32,26 @@ async function main() {
|
||||||
|
|
||||||
// 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(ccp, { wallet, identity: 'appUser', discovery: { enabled: true, asLocalhost: true } });
|
try {
|
||||||
|
await gateway.connect(ccp, { wallet, identity: 'appUser', 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');
|
||||||
|
|
||||||
// Get the contract from the network.
|
// Get the contract from the network.
|
||||||
const contract = network.getContract('fabcar');
|
const contract = network.getContract('fabcar');
|
||||||
|
|
||||||
// Evaluate the specified transaction.
|
// Evaluate the specified transaction. This is used for querying the world state.
|
||||||
// queryCar transaction - requires 1 argument, ex: ('queryCar', 'CAR4')
|
// The transaction function name will be evaluated on the endorsing peers but the responses
|
||||||
// queryAllCars transaction - requires no arguments, ex: ('queryAllCars')
|
// will not be sent to the ordering service and hence will not be committed to the ledger.
|
||||||
const result = await contract.evaluateTransaction('queryAllCars');
|
// queryCar transaction - requires 1 argument, ex: ('queryCar', 'CAR4')
|
||||||
console.log(`Transaction has been evaluated, result is: ${result.toString()}`);
|
// queryAllCars transaction - requires no arguments, ex: ('queryAllCars')
|
||||||
|
const result = await contract.evaluateTransaction('queryAllCars');
|
||||||
// Disconnect from the gateway.
|
console.log(`Transaction has been evaluated, result is: ${result.toString()}`);
|
||||||
await gateway.disconnect();
|
} finally {
|
||||||
|
// Disconnect from the gateway.
|
||||||
|
gateway.disconnect();
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Failed to evaluate transaction: ${error}`);
|
console.error(`Failed to evaluate transaction: ${error}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|
|
||||||
|
|
@ -27,22 +27,24 @@ async function main() {
|
||||||
|
|
||||||
// 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(ccp, { wallet, identity: 'appUser', discovery: { enabled: true, asLocalhost: true } });
|
try {
|
||||||
|
await gateway.connect(ccp, { wallet, identity: 'appUser', 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');
|
||||||
|
|
||||||
// Get the contract from the network.
|
// Get the contract from the network.
|
||||||
const contract = network.getContract('fabcar');
|
const contract = network.getContract('fabcar');
|
||||||
|
|
||||||
// Submit the specified transaction.
|
// Submit the specified transaction.
|
||||||
// createCar transaction - requires 5 argument, ex: ('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom')
|
// createCar transaction - requires 5 argument, ex: ('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom')
|
||||||
// changeCarOwner transaction - requires 2 args , ex: ('changeCarOwner', 'CAR12', 'Dave')
|
// changeCarOwner transaction - requires 2 args , ex: ('changeCarOwner', 'CAR12', 'Dave')
|
||||||
await contract.submitTransaction('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom');
|
await contract.submitTransaction('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom');
|
||||||
console.log(`Transaction has been submitted`);
|
console.log(`Transaction has been submitted`);
|
||||||
|
} finally {
|
||||||
// Disconnect from the gateway.
|
// Disconnect from the gateway.
|
||||||
await gateway.disconnect();
|
gateway.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Failed to submit transaction: ${error}`);
|
console.error(`Failed to submit transaction: ${error}`);
|
||||||
|
|
|
||||||
|
|
@ -28,19 +28,24 @@ async function main() {
|
||||||
|
|
||||||
// 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(ccp, { wallet, identity: 'appUser', discovery: { enabled: true, asLocalhost: true } });
|
try {
|
||||||
|
await gateway.connect(ccp, { wallet, identity: 'appUser', 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');
|
||||||
|
|
||||||
// Get the contract from the network.
|
// Get the contract from the network.
|
||||||
const contract = network.getContract('fabcar');
|
const contract = network.getContract('fabcar');
|
||||||
|
|
||||||
// Evaluate the specified transaction.
|
// Evaluate the specified transaction.
|
||||||
// queryCar transaction - requires 1 argument, ex: ('queryCar', 'CAR4')
|
// queryCar transaction - requires 1 argument, ex: ('queryCar', 'CAR4')
|
||||||
// queryAllCars transaction - requires no arguments, ex: ('queryAllCars')
|
// queryAllCars transaction - requires no arguments, ex: ('queryAllCars')
|
||||||
const result = await contract.evaluateTransaction('queryAllCars');
|
const result = await contract.evaluateTransaction('queryAllCars');
|
||||||
console.log(`Transaction has been evaluated, result is: ${result.toString()}`);
|
console.log(`Transaction has been evaluated, result is: ${result.toString()}`);
|
||||||
|
} finally {
|
||||||
|
// Disconnect from the gateway.
|
||||||
|
gateway.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Failed to evaluate transaction: ${error}`);
|
console.error(`Failed to evaluate transaction: ${error}`);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue