text: /*
  SPDX-License-Identifier: Apache-2.0
  */
  
  'use strict';
  
  // Bring key classes into scope, most importantly Fabric SDK network class
  const fs = require('fs');
  const yaml = require('js-yaml');
  const {FileSystemWallet, Gateway} = require('fabric-network');
  
  // A wallet stores a collection of identities for use
  const wallet = new FileSystemWallet('../identity/user/john/wallet');
  
  // Main program function
  async function main() {
  
      // A gateway defines the peers used to access Fabric networks
      const gateway = new Gateway();
  
      // Main try/catch block
      try {
  
          // Specify userName for network access
          const userName = 'User3@org1.example.com';
  
          // Load connection profile; will be used to locate a gateway
          let connectionProfile = yaml.safeLoad(fs.readFileSync('../gateway/networkConnection.yaml', 'utf8'));
  
          // Set connection options; identity and wallet
          let connectionOptions = {
              identity: userName,
              wallet: wallet,
              discovery: {enabled: false, asLocalhost: true}
          };
  
          // Connect to gateway using application specified parameters
          console.log('Connect to Fabric gateway.');
  
          await gateway.connect(connectionProfile, connectionOptions);
  
          // Access PaperNet network
          console.log('Use network channel: mychannel.');
  
          const network = await gateway.getNetwork('mychannel');
  
          // Get addressability to commercial paper contract
          console.log('Use org.papernet.commercialpaper smart contract.');
  
          const contract = await network.getContract('papercontract', 'org.papernet.commercialpaper');
  
          // redeem commercial paper
          console.log('Submit commercial paper redeem transaction.');
  
          const redeemResponse = await contract.submitTransaction('redeem', '00001', 'BigFund', '2020-11-30', '500');
  
          // process response
          console.log(`Process redeem transaction response: ${redeemResponse}`);
  
          let result = JSON.parse(redeemResponse);
  
          console.log(`${result.quantity} ${result.paper.issuer} commercial paper ${result.paper.paperNumber} successfully redeemed with ${result.redeemerAccount.owner}`);
          console.log('Transaction complete.');
  
      } catch (error) {
  
          console.log(`Error processing transaction. ${error}`);
          console.log(error.stack);
  
      } finally {
  
          // Disconnect from the gateway
          console.log('Disconnect from Fabric gateway.');
          gateway.disconnect();
  
      }
  }
  
  main().then(() => {
  
      console.log('Redeem program complete.');
  
  }).catch((e) => {
  
      console.log('Redeem program exception.');
      console.log(e);
      console.log(e.stack);
      process.exit(-1);
  
  });