Car Sales Network For Hyperledger Fabric/Composer
#1
Description: A network that allows a buyer participant to purchase a vehicle asset from a seller participant. The price of the vehicle is deducted from the buyer participant's balance and transferred to the seller's balance.

Installation:
You can either copy and paste the model file/transaction file into the Composer Playground or download the .bna file that is attached.

License: None. Do whatever you would like with the code.

Model File: (models/model.cto)
Code:
namespace org.tradesnetwork

asset Car identified by CarId {
o String CarId
o Make   make
o String model
o String VIN
}

enum Make {
o CHEVY
o FORD
o DODGE
o TOYOTA
o SUBARU
o HONDA
}

participant Buyer identified by BuyerID {
o String BuyerID
o Double balance
o String name
}

participant Seller identified by SellerID {
o String SellerID
o Double balance
o String name
}

transaction Sale {
  --> SaleContract saleContract
}

asset SaleContract identified by SaleID {
o String SaleID
o Double price
o Make make
o String model
o String VIN
--> Buyer buyer
--> Seller seller
}

Transaction File: (lib/logic.js)
Code:
/**
* Move one asset to a different participant
* @param {org.tradesnetwork.Sale} sale - the ShipmentReceived transaction
* @transaction
*/

async function sale(contract){
  const car = contract.car;
  const price = contract.saleContract.price;
  const terms = contract.saleContract.SaleID;
  const seller = contract.saleContract.seller;
  const buyer  = contract.saleContract.buyer;
  seller.balance += price;
  buyer.balance  -= price;
  
  
  // Update seller balance
  const sellerRegistry = await getParticipantRegistry('org.tradesnetwork.Seller');
  await sellerRegistry.update(seller);
  
  // Update buyer balance
  const buyerRegistry = await getParticipantRegistry('org.tradesnetwork.Buyer');
  await buyerRegistry.update(buyer);
}
Reply