From cb0995f3f638f4b4ae41bc1b7e14313333268b81 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 16 Oct 2019 11:00:26 -0400 Subject: [PATCH] chore(@embark/stack/blockchain-client): re-add missing file (#1973) --- packages/stack/blockchain-client/src/index.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 packages/stack/blockchain-client/src/index.js diff --git a/packages/stack/blockchain-client/src/index.js b/packages/stack/blockchain-client/src/index.js new file mode 100644 index 000000000..650579db2 --- /dev/null +++ b/packages/stack/blockchain-client/src/index.js @@ -0,0 +1,41 @@ +const Web3 = require('web3'); + +class BlockchainClient { + + constructor(embark, _options) { + this.embark = embark; + this.events = embark.events; + + this.blockchainClients = {}; + this.client = null; + this.events.setCommandHandler("blockchain:client:register", (clientName, blockchainClient) => { + this.blockchainClients[clientName] = blockchainClient; + this.client = blockchainClient; + }); + + // TODO: unclear currently if this belongs here so it's a bit hardcoded for now + this.events.setCommandHandler("blockchain:client:provider", (clientName, cb) => { + this.events.request("proxy:endpoint:get", (err, endpoint) => { + if (err) { + return cb(err); + } + const web3 = new Web3(endpoint); + cb(null, web3.currentProvider); + }); + }); + + // TODO: maybe not the ideal event to listen to? + // for e.g, could wait for all stack components to be ready + // TODO: probably better to have 2 stages in engine, services start, then connections, etc.. + this.events.on("blockchain:started", (_clientName) => { + // make connections + // this.client.initAndConnect(); // and config options + // should do stuff like + // connect to endpoint given + // set default account + }); + } + +} + +module.exports = BlockchainClient;