Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- rule NetworkAdminUser {
- description: "Grant business network administrators full access to user resources"
- participant: "org.hyperledger.composer.system.NetworkAdmin"
- operation: ALL
- resource: "**"
- action: ALLOW
- }
- rule NetworkAdminSystem {
- description: "Grant business network administrators full access to system resources"
- participant: "org.hyperledger.composer.system.NetworkAdmin"
- operation: ALL
- resource: "org.hyperledger.composer.system.**"
- action: ALLOW
- }
- rule RuleWithDataSubmission {
- description: "Allow paticipant Manufacturer to access submitCommoditydata Transaction"
- participant: "org.example.network.Manufacturer"
- operation: CREATE
- resource: "org.example.network.submitCommodityData"
- action: ALLOW
- }
- rule RuleWithCustomers {
- description: "Allow paticipant customers to read submitCommoditydata Transaction"
- participant: "org.example.network.Customer"
- operation: READ
- resource: "org.example.network.Commodity"
- action: ALLOW
- }
- ********************************************************************
- /*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- namespace org.example.network
- concept Address {
- o String city optional
- o String country
- o String region optional
- o String street optional
- o String postalCode optional
- o String postOfficeBoxNumber optional
- }
- abstract participant Trader {
- o String companyName
- o Address address
- }
- /**
- *Participants in the network
- */
- participant Manufacturer identified by tradeId extends Trader {
- o String tradeId
- }
- participant Customer identified by tradeId extends Trader {
- o String tradeId
- }
- asset Commodity identified by tradingSymbol {
- /**
- *Standard attribute
- */
- o String tradingSymbol
- o String name
- o String description
- o Double unitPrice optional
- o Double totalPrice optional
- /**
- *Submit Commodity Data
- */
- o String content optional
- o String commodityType optional
- o DateTime expirationDate optional
- o DateTime ManufactureDate optional
- }
- transaction submitCommodityData {
- o String tradingSymbol
- o String content optional
- o String commodityType optional
- o DateTime expiringDate optional
- o DateTime ManufacturingDate optional
- }
- ****************************************************************
- /**
- * New script file
- */
- /**
- * Track the trade of a commodity from one trader to another
- * @param {org.example.network.submitCommodityData} drugDetails - the trade to be processed
- * @transaction
- */
- async function submitCommodityData (drugDetails) {
- try{
- const assetRegistry = await getAssetRegistry('org.example.Network.Commodity');
- console.log(assetRegistry);
- const exists = await assetRegistry.exists(drugDetails.tradingSymbol);
- if (exists) {
- const details = await assetRegistry.get(drugDetails.tradingSymbol);
- details.tradingSymbol = drugDetails.tradingSymbol;
- details.content = drugDetails.content;
- details.commodityType = drugDetails.commodityType;
- details.expiringDate = drugDetails.expiringDate;
- details.ManufacturingDate = drugDetails.ManufacturingDate;
- // publish update
- await assetRegistry.update(details);
- } else {
- throw new Error('the batch you specified does not exist!');
- }
- }catch(error){
- console.log(error.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement