From 1b3212255765682ff6dff86c5c276e28eb0ad9f8 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 17 Apr 2018 17:35:00 -0400 Subject: [PATCH] add event and API endpoint to get the contract sourcecode --- lib/pipeline/pipeline.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index d8625348..5e4b827b 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -19,6 +19,24 @@ class Pipeline { this.logger = options.logger; this.plugins = options.plugins; this.pipelinePlugins = this.plugins.getPluginsFor('pipeline'); + + const self = this; + self.events.setCommandHandler("files:contract", (filename, cb) => { + let file = self.contractsFiles.find((file) => file.filename === filename); + if (!file) { + return cb({error: filename + " not found"}); + } + file.content(cb); + }); + + let plugin = this.plugins.createPlugin('deployment', {}); + plugin.registerAPICall( + 'get', + '/embark/files/contracts/', + (req, res) => { + self.events.request('files:contract', req.query.filename, res.send.bind(res)); + } + ); } build(abi, contractsJSON, path, callback) {