lib/my-contract.js
/**
   * 
   * submitPackingList
   * 
   * A transaction which adds shipping details from the packing list to the blockchain.
   * @param batchId - the batch we are shipping
   * @param growerId - Id of the grower which handed over beans to trader
   * @param shipperId - Id of the shipper which handed over beans to trader
   * @param issueDate - the date the package was shipped 
   * @param ICO_Num - ICO_number from the packing list
   * @param ICO_Lot - Lot where the shipment will start the journey from
   * @param FDA_Num - FDA number associated with this batch of beans 
   * @param invoiceNum - packing list invoice number
   * @param billofLadingNum - receipt of freight services
   * @param vesselName - name of the vessel
   * @param vesselVoyageNum number associated with vessel
   * @param containerNum - container which holds our shipment
   * @param sealNum - seal associated with our packing list
   * @param timestamp - when the transaction was submitted to the blockchain
   */


A transaction which adds shipping details from the packing list to the blockchain.
A transaction which adds shipping details from the packing list to the blockchain .
async submitPackingList(ctx, grower, trader, PL_Invoice_no, PL_IssueDate, PL_ICO_no,
    PL_ICO_Lot, PL_FDA_NO, PL_Bill_of_Lading_No, PL_LoadedVessel, PL_VesselVoyage_No, PL_Container_No,
    PL_Seal_no, PL_timestamp, batchId, transactionId, timestamp) {
    console.info('submit packing list invoked');
    let coffeeAsBytes = await ctx.stub.getState(batchId);
    if (!coffeeAsBytes || coffeeAsBytes.length === 0) {
      return new Error(`${batchId} batch does not exist`);
    }
    let batchCoffee = JSON.parse(coffeeAsBytes);
    batchCoffee.grower = grower;
    batchCoffee.trader = trader;
    batchCoffee.PL_Invoice_no = PL_Invoice_no;
    batchCoffee.PL_IssueDate = PL_IssueDate;
    batchCoffee.PL_ICO_no = PL_ICO_no;
    batchCoffee.PL_ICO_Lot = PL_ICO_Lot;
    batchCoffee.PL_FDA_NO = PL_FDA_NO;
    batchCoffee.PL_Bill_of_Lading_No = PL_Bill_of_Lading_No;
    batchCoffee.PL_LoadedVessel = PL_LoadedVessel;
    batchCoffee.PL_VesselVoyage_No = PL_VesselVoyage_No;
    batchCoffee.PL_Container_No = PL_Container_No;
    batchCoffee.PL_Seal_no = PL_Seal_no;
    batchCoffee.PL_timestamp = PL_timestamp;
    batchCoffee.batchId = batchId;
    batchCoffee.transactionId = transactionId;
    batchCoffee.timestamp = timestamp;
    await ctx.stub.putState(batchId, Buffer.from(JSON.stringify(batchCoffee)));
    console.info('updated ledger with key: ' + batchId + 'and value: ');
    console.info(JSON.stringify(batchCoffee));
    return batchCoffee;
  }
async submitPackingList ( ctx , grower , trader , PL_Invoice_no , PL_IssueDate , PL_ICO_no , PL_ICO_Lot , PL_FDA_NO , PL_Bill_of_Lading_No , PL_LoadedVessel , PL_VesselVoyage_No , PL_Container_No , PL_Seal_no , PL_timestamp , batchId , transactionId , timestamp ) { console . info ( 'submit packing list invoked' ) ; let coffeeAsBytes = await ctx . stub . getState ( batchId ) ; if ( ! coffeeAsBytes || coffeeAsBytes . length === 0 ) { return new Error ( ` ${ batchId } ` ) ; } let batchCoffee = JSON . parse ( coffeeAsBytes ) ; batchCoffee . grower = grower ; batchCoffee . trader = trader ; batchCoffee . PL_Invoice_no = PL_Invoice_no ; batchCoffee . PL_IssueDate = PL_IssueDate ; batchCoffee . PL_ICO_no = PL_ICO_no ; batchCoffee . PL_ICO_Lot = PL_ICO_Lot ; batchCoffee . PL_FDA_NO = PL_FDA_NO ; batchCoffee . PL_Bill_of_Lading_No = PL_Bill_of_Lading_No ; batchCoffee . PL_LoadedVessel = PL_LoadedVessel ; batchCoffee . PL_VesselVoyage_No = PL_VesselVoyage_No ; batchCoffee . PL_Container_No = PL_Container_No ; batchCoffee . PL_Seal_no = PL_Seal_no ; batchCoffee . PL_timestamp = PL_timestamp ; batchCoffee . batchId = batchId ; batchCoffee . transactionId = transactionId ; batchCoffee . timestamp = timestamp ; await ctx . stub . putState ( batchId , Buffer . from ( JSON . stringify ( batchCoffee ) ) ) ; console . info ( 'updated ledger with key: ' + batchId + 'and value: ' ) ; console . info ( JSON . stringify ( batchCoffee ) ) ; return batchCoffee ; }
submitPackingList
submitPackingList
//TODO: do if (batch exists) check //get batch identified bby batchId from the ledger // let coffeeAsBytes = await ctx.stub.getState(batchId); // let batchCoffee = JSON.parse(coffeeAsBytes); //update our batch of coffee with the shipping details //update the ledger with the new shipping + owner details