remove provider-engine as it has been creating lots of issues

This commit is contained in:
Jonathan Rainville 2018-07-03 16:39:17 -04:00 committed by Iuri Matias
parent 01900f8c6e
commit 26243e21e0
7 changed files with 65 additions and 1077 deletions

View File

@ -34,7 +34,6 @@ EmbarkJS.Contract = function(options) {
if (EmbarkJS.isNewWeb3(this.web3)) {
ContractClass = new this.web3.eth.Contract(this.abi, this.address);
ContractClass.setProvider(this.web3.currentProvider);
ContractClass.options.data = this.code;
ContractClass.options.from = this.from || this.web3.eth.defaultAccount;
ContractClass.abi = ContractClass.options.abi;

View File

@ -123,6 +123,10 @@ class Cmd {
.description(__('run dapp (default: %s)', 'development'))
.action(function (env, options) {
i18n.setOrDetectLocale(options.locale);
embark.initConfig(env || 'development', {
embarkConfig: 'embark.json',
interceptLogs: false
});
embark.run({
env: env || 'development',
serverPort: options.port,

View File

@ -1,23 +1,9 @@
const ProviderEngine = require('embark-web3-provider-engine');
const RpcSubprovider = require('embark-web3-provider-engine/subproviders/rpc');
const WsSubprovider = require('embark-web3-provider-engine/subproviders/websocket');
const CacheSubprovider = require('embark-web3-provider-engine/subproviders/cache.js');
const FixtureSubprovider = require('embark-web3-provider-engine/subproviders/fixture.js');
const FilterSubprovider = require('embark-web3-provider-engine/subproviders/filters.js');
const VmSubprovider = require('embark-web3-provider-engine/subproviders/vm.js');
const NonceSubprovider = require('embark-web3-provider-engine/subproviders/nonce-tracker.js');
const SubscriptionSubprovider = require('embark-web3-provider-engine/subproviders/subscriptions');
const async = require('async');
const AccountParser = require('./accountParser');
const fundAccount = require('./fundAccount');
const EventEmitter = require('events');
EventEmitter.prototype._maxListeners = 300;
const NO_ACCOUNTS = 'noAccounts';
class Provider extends ProviderEngine {
class Provider {
constructor(options) {
super();
this.web3 = options.web3;
this.accountsConfig = options.accountsConfig;
this.blockchainConfig = options.blockchainConfig;
@ -25,71 +11,52 @@ class Provider extends ProviderEngine {
this.web3Endpoint = options.web3Endpoint;
this.logger = options.logger;
this.isDev = options.isDev;
this.asyncMethods = {};
this.setMaxListeners(300);
}
startWeb3Provider(callback) {
const self = this;
// cache layer
// self.addProvider(new CacheSubprovider())
// self.addProvider(new NonceSubprovider())
if (this.type === 'rpc') {
self.addProvider(new RpcSubprovider({
rpcUrl: self.web3Endpoint
}));
self.provider = new this.web3.providers.HttpProvider(self.web3Endpoint);
} else if (this.type === 'ws') {
console.log('USing ws');
self.addProvider(new SubscriptionSubprovider());
self.addProvider(new WsSubprovider({
rpcUrl: self.web3Endpoint,
origin: this.blockchainConfig.wsOrigins.split(',')[0]
}));
self.provider = new this.web3.providers.WebsocketProvider(self.web3Endpoint, {headers: {Origin: "embark"}});
} else {
return callback(__("contracts config error: unknown deployment type %s", this.type));
}
// network connectivity error
self.on('error', (err) => {
console.log('ERR', JSON.stringify(err));
// report connectivity errors as trace due to polling
self.logger.trace('web3 provider error: ', err);
self.logger.trace('stopping web3 provider due to error');
// prevent continuous polling errors
self.stop();
});
self.web3.setProvider(self);
self.start();
self.web3.setProvider(self.provider);
self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, self.logger);
self.addresses = [];
async.waterfall([
function populateWeb3Wallet(next) {
if (!self.accounts.length) {
return next(NO_ACCOUNTS);
}
self.accounts.forEach(account => {
self.addresses.push(account.address);
self.web3.eth.accounts.wallet.add(account);
});
self.asyncMethods = {
eth_accounts: self.eth_accounts.bind(self)
};
next();
}
], function (err) {
if (err && err !== NO_ACCOUNTS) {
self.logger.error((err));
}
callback();
if (!self.accounts.length) {
return callback();
}
self.accounts.forEach(account => {
self.addresses.push(account.address);
self.web3.eth.accounts.wallet.add(account);
});
self.realAccountFunction = self.web3.eth.getAccounts;
self.web3.eth.getAccounts = function (cb) {
if (!cb) {
cb = function () {
};
}
return new Promise((resolve, reject) => {
self.realAccountFunction((err, accounts) => {
if (err) {
cb(err);
return reject(err);
}
accounts = accounts.concat(self.addresses);
// accounts = self.addresses.concat(accounts);
cb(null, accounts);
resolve(accounts);
});
});
};
callback();
}
fundAccounts(callback) {
@ -104,24 +71,6 @@ class Provider extends ProviderEngine {
fundAccount(self.web3, account.address, account.hexBalance, eachCb);
}, callback);
}
eth_accounts(payload, cb) {
return cb(null, this.addresses);
}
sendAsync(payload, callback) {
let method = this.asyncMethods[payload.method];
if (method) {
return method.call(method, payload, (err, result) => {
if (err) {
return callback(err);
}
let response = {'id': payload.id, 'jsonrpc': '2.0', 'result': result};
callback(null, response);
});
}
super.sendAsync(payload, callback);
}
}
module.exports = Provider;

View File

@ -44,12 +44,11 @@ class Test {
}
initWeb3Provider(callback) {
const self = this;
if (this.provider) {
this.provider.stop();
}
if (this.simOptions.host) {
let {host, port, type, protocol, accounts} = this.simOptions;
let {host, port, type, protocol, accounts} = this.simOptions;
if (!protocol) {
protocol = (this.simOptions.type === "rpc") ? 'http' : 'ws';
}
@ -71,21 +70,6 @@ class Test {
return callback(err);
}
/*const ProviderEngine = require('embark-web3-provider-engine');
const WsSubprovider = require('embark-web3-provider-engine/subproviders/websocket');
const SubscriptionSubprovider = require('embark-web3-provider-engine/subproviders/subscriptions');
const engine = new ProviderEngine();
self.web3 = new Web3(engine);
engine.addProvider(new SubscriptionSubprovider());
engine.addProvider(new WsSubprovider({
rpcUrl: endpoint,
origin: self.engine.config.blockchainConfig.wsOrigins.split(',')[0]
}));
engine.start();
return callback();*/
this.provider = new Provider(providerOptions);
this.provider.startWeb3Provider(callback);
});
@ -203,7 +187,11 @@ class Test {
if (options.deployment.type !== 'rpc' && options.deployment.type !== 'ws') {
callback(__("contracts config error: unknown deployment type %s", options.deployment.type));
}
Object.assign(self.simOptions, {host: options.deployment.host, port: options.deployment.port, type: options.deployment.type});
Object.assign(self.simOptions, {
host: options.deployment.host,
port: options.deployment.port,
type: options.deployment.type
});
resetServices = true;
}
if (!resetServices) {
@ -289,7 +277,9 @@ class Test {
console.warn("Warning: default account has no funds");
}
next(null, accounts);
}).catch((err) => { next(err); });
}).catch((err) => {
next(err);
});
},
function deploy(accounts, next) {
self.engine.deployManager.gasLimit = 6000000;
@ -310,7 +300,13 @@ class Test {
} else {
data = self.contracts[contractName].options.data;
}
Object.assign(self.contracts[contractName], new EmbarkJS.Contract({abi: contract.abiDefinition, address: contract.deployedAddress, from: self.web3.eth.defaultAccount, gas: 6000000, web3: self.web3}));
Object.assign(self.contracts[contractName], new EmbarkJS.Contract({
abi: contract.abiDefinition,
address: contract.deployedAddress,
from: self.web3.eth.defaultAccount,
gas: 6000000,
web3: self.web3
}));
self.contracts[contractName].address = contract.deployedAddress;
if (self.contracts[contractName].options) {
@ -358,7 +354,13 @@ class Test {
contract = this.engine.contractsManager.contracts[contractNames[0]];
}
}
this.contracts[contractName] = new EmbarkJS.Contract({abi: contract.abiDefinition, address: contract.address, from: this.web3.eth.defaultAccount, gas: 6000000, web3: this.web3});
this.contracts[contractName] = new EmbarkJS.Contract({
abi: contract.abiDefinition,
address: contract.address,
from: this.web3.eth.defaultAccount,
gas: 6000000,
web3: this.web3
});
this.contracts[contractName].address = contract.address;
this.contracts[contractName].options.data = contract.code;
this.contracts[contractName].options.gas = 6000000;

958
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -38,7 +38,6 @@
"css-loader": "^0.28.11",
"deep-equal": "^1.0.1",
"ejs": "^2.5.8",
"embark-web3-provider-engine": "14.0.7",
"eth-ens-namehash": "^2.0.8",
"eth-lib": "^0.2.8",
"ethereumjs-wallet": "0.6.0",

View File

@ -3,11 +3,6 @@ const SimpleStorage = require('Embark/contracts/SimpleStorage');
let accounts;
config({
deployment: {
type: 'ws',
host: 'localhost',
port: '8546'
},
contracts: {
"SimpleStorage": {
args: [100],
@ -43,20 +38,14 @@ contract("SimpleStorage", function () {
});
it('listens to events', function (done) {
SimpleStorage.once('EventOnSet2', function(error, _result){
console.log('error', error);
console.log('result', _result);
/*assert.strictEqual(error, null);
SimpleStorage.once('EventOnSet2', async function (error, _result) {
assert.strictEqual(error, null);
let result = await SimpleStorage.methods.get().call();
assert.strictEqual(parseInt(result, 10), 150);*/
assert.strictEqual(parseInt(result, 10), 150);
done(error);
});
console.log('TEST');
SimpleStorage.methods.set2(150, 100).send(() => {
console.log('Done');
});
SimpleStorage.methods.set2(150, 100).send();
});
});