SHARE
TWEET

Untitled

a guest Apr 20th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Licensed under the Apache License, Version 2.0 (the "License");
  3.  * you may not use this file except in compliance with the License.
  4.  * You may obtain a copy of the License at
  5.  *
  6.  * http://www.apache.org/licenses/LICENSE-2.0
  7.  *
  8.  * Unless required by applicable law or agreed to in writing, software
  9.  * distributed under the License is distributed on an "AS IS" BASIS,
  10.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11.  * See the License for the specific language governing permissions and
  12.  * limitations under the License.
  13.  */
  14.  
  15. rule NetworkAdminUser {
  16.     description: "Grant business network administrators full access to user resources"
  17.     participant: "org.hyperledger.composer.system.NetworkAdmin"
  18.     operation: ALL
  19.     resource: "**"
  20.     action: ALLOW
  21. }
  22.  
  23. rule NetworkAdminSystem {
  24.     description: "Grant business network administrators full access to system resources"
  25.     participant: "org.hyperledger.composer.system.NetworkAdmin"
  26.     operation: ALL
  27.     resource: "org.hyperledger.composer.system.**"
  28.     action: ALLOW
  29. }
  30.  
  31. rule RuleWithDataSubmission {
  32.     description: "Allow paticipant Manufacturer to access submitCommoditydata Transaction"
  33.     participant: "org.example.network.Manufacturer"
  34.     operation: CREATE
  35.     resource: "org.example.network.submitCommodityData"
  36.     action: ALLOW
  37. }
  38.  
  39. rule RuleWithCustomers {
  40.     description: "Allow paticipant customers to read submitCommoditydata Transaction"
  41.     participant: "org.example.network.Customer"
  42.     operation: READ
  43.     resource: "org.example.network.Commodity"
  44.     action: ALLOW
  45. }
  46.  
  47. ********************************************************************
  48. /*
  49.  * Licensed under the Apache License, Version 2.0 (the "License");
  50.  * you may not use this file except in compliance with the License.
  51.  * You may obtain a copy of the License at
  52.  *
  53.  * http://www.apache.org/licenses/LICENSE-2.0
  54.  *
  55.  * Unless required by applicable law or agreed to in writing, software
  56.  * distributed under the License is distributed on an "AS IS" BASIS,
  57.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  58.  * See the License for the specific language governing permissions and
  59.  * limitations under the License.
  60.  */
  61.  
  62. namespace org.example.network
  63.  
  64. concept Address {
  65.     o String city optional
  66.     o String country
  67.     o String region optional
  68.     o String street optional
  69.     o String postalCode optional
  70.     o String postOfficeBoxNumber optional
  71. }
  72.  
  73. abstract participant Trader {
  74.     o String companyName
  75.     o Address address
  76. }
  77.  
  78.  
  79. /**
  80.  *Participants in the network
  81.  */
  82.  
  83. participant Manufacturer identified by tradeId extends Trader {
  84.     o String tradeId
  85. }
  86.  
  87. participant Customer identified by tradeId extends Trader {
  88.     o String tradeId
  89. }
  90.  
  91. asset Commodity identified by tradingSymbol {
  92.   /**
  93.    *Standard attribute
  94.    */
  95.  
  96.     o String tradingSymbol
  97.     o String name
  98.     o String description
  99.     o Double unitPrice optional
  100.     o Double totalPrice optional
  101.  
  102.     /**
  103.     *Submit Commodity Data
  104.     */
  105.     o String content optional
  106.     o String commodityType optional
  107.     o DateTime expirationDate optional
  108.     o DateTime ManufactureDate optional
  109. }
  110.  
  111. transaction submitCommodityData {
  112.   o String tradingSymbol
  113.   o String content optional
  114.   o String commodityType optional
  115.   o DateTime expiringDate optional
  116.   o DateTime ManufacturingDate optional
  117. }
  118.  
  119.  
  120. ****************************************************************
  121. /**
  122.  * New script file
  123.  */
  124.  
  125. /**
  126.  * Track the trade of a commodity from one trader to another
  127.  * @param {org.example.network.submitCommodityData} drugDetails - the trade to be processed
  128.  * @transaction
  129.  */
  130. async function submitCommodityData (drugDetails) {
  131.   try{
  132.     const assetRegistry = await getAssetRegistry('org.example.Network.Commodity');
  133.     console.log(assetRegistry);
  134.     const exists = await assetRegistry.exists(drugDetails.tradingSymbol);
  135.  
  136.       if (exists) {
  137.         const details = await assetRegistry.get(drugDetails.tradingSymbol);
  138.  
  139.         details.tradingSymbol = drugDetails.tradingSymbol;
  140.         details.content = drugDetails.content;
  141.         details.commodityType = drugDetails.commodityType;
  142.         details.expiringDate = drugDetails.expiringDate;
  143.         details.ManufacturingDate = drugDetails.ManufacturingDate;
  144.  
  145.         // publish update
  146.         await assetRegistry.update(details);
  147.  
  148.       } else {
  149.         throw new Error('the batch you specified does not exist!');
  150.       }
  151.   }catch(error){
  152.     console.log(error.toString());
  153.   }
  154.  
  155. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top