mirror of https://github.com/embarklabs/embark.git
chore(@embark/stack/blockchain-client): re-add missing file (#1973)
This commit is contained in:
parent
9b57a912cf
commit
cb0995f3f6
|
@ -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;
|
Loading…
Reference in New Issue