mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-23 01:55:10 +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.
|
||||
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.
|
||||
const network = await gateway.getNetwork('mychannel');
|
||||
// Get the network (channel) our contract is deployed to.
|
||||
const network = await gateway.getNetwork('mychannel');
|
||||
|
||||
// Get the contract from the network.
|
||||
const contract = network.getContract('fabcar');
|
||||
// Get the contract from the network.
|
||||
const contract = network.getContract('fabcar');
|
||||
|
||||
// Submit the specified transaction.
|
||||
// createCar transaction - requires 5 argument, ex: ('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom')
|
||||
// changeCarOwner transaction - requires 2 args , ex: ('changeCarOwner', 'CAR12', 'Dave')
|
||||
await contract.submitTransaction('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom');
|
||||
console.log('Transaction has been submitted');
|
||||
|
||||
// Disconnect from the gateway.
|
||||
await gateway.disconnect();
|
||||
// Submit the specified transaction: The transaction function name will be evaluated on the
|
||||
// endorsing peers and then submitted to the ordering service for committing to the ledger.
|
||||
// createCar transaction - requires 5 argument, ex: ('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom')
|
||||
// changeCarOwner transaction - requires 2 args , ex: ('changeCarOwner', 'CAR12', 'Dave')
|
||||
await contract.submitTransaction('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom');
|
||||
console.log('Transaction has been submitted');
|
||||
} finally {
|
||||
// Disconnect from the gateway.
|
||||
gateway.disconnect();
|
||||
}
|
||||
|
||||
} catch (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.
|
||||
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.
|
||||
const network = await gateway.getNetwork('mychannel');
|
||||
// Get the network (channel) our contract is deployed to.
|
||||
const network = await gateway.getNetwork('mychannel');
|
||||
|
||||
// Get the contract from the network.
|
||||
const contract = network.getContract('fabcar');
|
||||
// Get the contract from the network.
|
||||
const contract = network.getContract('fabcar');
|
||||
|
||||
// Evaluate the specified transaction.
|
||||
// queryCar transaction - requires 1 argument, ex: ('queryCar', 'CAR4')
|
||||
// queryAllCars transaction - requires no arguments, ex: ('queryAllCars')
|
||||
const result = await contract.evaluateTransaction('queryAllCars');
|
||||
console.log(`Transaction has been evaluated, result is: ${result.toString()}`);
|
||||
|
||||
// Disconnect from the gateway.
|
||||
await gateway.disconnect();
|
||||
|
||||
// Evaluate the specified transaction. This is used for querying the world state.
|
||||
// The transaction function name will be evaluated on the endorsing peers but the responses
|
||||
// will not be sent to the ordering service and hence will not be committed to the ledger.
|
||||
// queryCar transaction - requires 1 argument, ex: ('queryCar', 'CAR4')
|
||||
// queryAllCars transaction - requires no arguments, ex: ('queryAllCars')
|
||||
const result = await contract.evaluateTransaction('queryAllCars');
|
||||
console.log(`Transaction has been evaluated, result is: ${result.toString()}`);
|
||||
} finally {
|
||||
// Disconnect from the gateway.
|
||||
gateway.disconnect();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Failed to evaluate transaction: ${error}`);
|
||||
process.exit(1);
|
||||
|
|
|
|||
|
|
@ -27,22 +27,24 @@ async function main() {
|
|||
|
||||
// Create a new gateway for connecting to our peer node.
|
||||
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.
|
||||
const network = await gateway.getNetwork('mychannel');
|
||||
// Get the network (channel) our contract is deployed to.
|
||||
const network = await gateway.getNetwork('mychannel');
|
||||
|
||||
// Get the contract from the network.
|
||||
const contract = network.getContract('fabcar');
|
||||
// Get the contract from the network.
|
||||
const contract = network.getContract('fabcar');
|
||||
|
||||
// Submit the specified transaction.
|
||||
// createCar transaction - requires 5 argument, ex: ('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom')
|
||||
// changeCarOwner transaction - requires 2 args , ex: ('changeCarOwner', 'CAR12', 'Dave')
|
||||
await contract.submitTransaction('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom');
|
||||
console.log(`Transaction has been submitted`);
|
||||
|
||||
// Disconnect from the gateway.
|
||||
await gateway.disconnect();
|
||||
// Submit the specified transaction.
|
||||
// createCar transaction - requires 5 argument, ex: ('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom')
|
||||
// changeCarOwner transaction - requires 2 args , ex: ('changeCarOwner', 'CAR12', 'Dave')
|
||||
await contract.submitTransaction('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom');
|
||||
console.log(`Transaction has been submitted`);
|
||||
} finally {
|
||||
// Disconnect from the gateway.
|
||||
gateway.disconnect();
|
||||
}
|
||||
|
||||
} catch (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.
|
||||
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.
|
||||
const network = await gateway.getNetwork('mychannel');
|
||||
// Get the network (channel) our contract is deployed to.
|
||||
const network = await gateway.getNetwork('mychannel');
|
||||
|
||||
// Get the contract from the network.
|
||||
const contract = network.getContract('fabcar');
|
||||
// Get the contract from the network.
|
||||
const contract = network.getContract('fabcar');
|
||||
|
||||
// Evaluate the specified transaction.
|
||||
// queryCar transaction - requires 1 argument, ex: ('queryCar', 'CAR4')
|
||||
// queryAllCars transaction - requires no arguments, ex: ('queryAllCars')
|
||||
const result = await contract.evaluateTransaction('queryAllCars');
|
||||
console.log(`Transaction has been evaluated, result is: ${result.toString()}`);
|
||||
// Evaluate the specified transaction.
|
||||
// queryCar transaction - requires 1 argument, ex: ('queryCar', 'CAR4')
|
||||
// queryAllCars transaction - requires no arguments, ex: ('queryAllCars')
|
||||
const result = await contract.evaluateTransaction('queryAllCars');
|
||||
console.log(`Transaction has been evaluated, result is: ${result.toString()}`);
|
||||
} finally {
|
||||
// Disconnect from the gateway.
|
||||
gateway.disconnect();
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error(`Failed to evaluate transaction: ${error}`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue