github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-supply-chain-master/server/blockchain/protos.js (about) 1 /** 2 * Copyright 2017 Intel Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * ---------------------------------------------------------------------------- 16 */ 17 'use strict' 18 19 const path = require('path') 20 const _ = require('lodash') 21 const protobuf = require('protobufjs') 22 23 const protos = {} 24 25 const loadProtos = (filename, protoNames) => { 26 const protoPath = path.resolve(__dirname, '../../protos', filename) 27 return protobuf.load(protoPath) 28 .then(root => { 29 protoNames.forEach(name => { 30 protos[name] = root.lookupType(name) 31 }) 32 }) 33 } 34 35 const compile = () => { 36 return Promise.all([ 37 loadProtos('agent.proto', [ 38 'Agent', 39 'AgentContainer' 40 ]), 41 loadProtos('property.proto', [ 42 'Property', 43 'PropertyContainer', 44 'PropertyPage', 45 'PropertyPageContainer', 46 'PropertySchema', 47 'PropertyValue', 48 'Location' 49 ]), 50 loadProtos('proposal.proto', [ 51 'Proposal', 52 'ProposalContainer' 53 ]), 54 loadProtos('record.proto', [ 55 'Record', 56 'RecordContainer', 57 'RecordType', 58 'RecordTypeContainer' 59 ]), 60 loadProtos('payload.proto', [ 61 'SCPayload', 62 'CreateAgentAction', 63 'FinalizeRecordAction', 64 'CreateRecordAction', 65 'CreateRecordTypeAction', 66 'UpdatePropertiesAction', 67 'CreateProposalAction', 68 'AnswerProposalAction', 69 'RevokeReporterAction' 70 ]) 71 ]) 72 } 73 74 module.exports = _.assign(protos, { compile })