mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-22 21:29:14 +00:00
remove provider-engine as it has been creating lots of issues
This commit is contained in:
parent
01900f8c6e
commit
26243e21e0
@ -34,7 +34,6 @@ EmbarkJS.Contract = function(options) {
|
|||||||
|
|
||||||
if (EmbarkJS.isNewWeb3(this.web3)) {
|
if (EmbarkJS.isNewWeb3(this.web3)) {
|
||||||
ContractClass = new this.web3.eth.Contract(this.abi, this.address);
|
ContractClass = new this.web3.eth.Contract(this.abi, this.address);
|
||||||
ContractClass.setProvider(this.web3.currentProvider);
|
|
||||||
ContractClass.options.data = this.code;
|
ContractClass.options.data = this.code;
|
||||||
ContractClass.options.from = this.from || this.web3.eth.defaultAccount;
|
ContractClass.options.from = this.from || this.web3.eth.defaultAccount;
|
||||||
ContractClass.abi = ContractClass.options.abi;
|
ContractClass.abi = ContractClass.options.abi;
|
||||||
|
@ -123,6 +123,10 @@ class Cmd {
|
|||||||
.description(__('run dapp (default: %s)', 'development'))
|
.description(__('run dapp (default: %s)', 'development'))
|
||||||
.action(function (env, options) {
|
.action(function (env, options) {
|
||||||
i18n.setOrDetectLocale(options.locale);
|
i18n.setOrDetectLocale(options.locale);
|
||||||
|
embark.initConfig(env || 'development', {
|
||||||
|
embarkConfig: 'embark.json',
|
||||||
|
interceptLogs: false
|
||||||
|
});
|
||||||
embark.run({
|
embark.run({
|
||||||
env: env || 'development',
|
env: env || 'development',
|
||||||
serverPort: options.port,
|
serverPort: options.port,
|
||||||
|
@ -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 async = require('async');
|
||||||
const AccountParser = require('./accountParser');
|
const AccountParser = require('./accountParser');
|
||||||
const fundAccount = require('./fundAccount');
|
const fundAccount = require('./fundAccount');
|
||||||
const EventEmitter = require('events');
|
|
||||||
|
|
||||||
EventEmitter.prototype._maxListeners = 300;
|
class Provider {
|
||||||
const NO_ACCOUNTS = 'noAccounts';
|
|
||||||
|
|
||||||
class Provider extends ProviderEngine {
|
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super();
|
|
||||||
this.web3 = options.web3;
|
this.web3 = options.web3;
|
||||||
this.accountsConfig = options.accountsConfig;
|
this.accountsConfig = options.accountsConfig;
|
||||||
this.blockchainConfig = options.blockchainConfig;
|
this.blockchainConfig = options.blockchainConfig;
|
||||||
@ -25,71 +11,52 @@ class Provider extends ProviderEngine {
|
|||||||
this.web3Endpoint = options.web3Endpoint;
|
this.web3Endpoint = options.web3Endpoint;
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.isDev = options.isDev;
|
this.isDev = options.isDev;
|
||||||
this.asyncMethods = {};
|
|
||||||
this.setMaxListeners(300);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
startWeb3Provider(callback) {
|
startWeb3Provider(callback) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
// cache layer
|
|
||||||
// self.addProvider(new CacheSubprovider())
|
|
||||||
|
|
||||||
// self.addProvider(new NonceSubprovider())
|
|
||||||
|
|
||||||
if (this.type === 'rpc') {
|
if (this.type === 'rpc') {
|
||||||
self.addProvider(new RpcSubprovider({
|
self.provider = new this.web3.providers.HttpProvider(self.web3Endpoint);
|
||||||
rpcUrl: self.web3Endpoint
|
|
||||||
}));
|
|
||||||
} else if (this.type === 'ws') {
|
} else if (this.type === 'ws') {
|
||||||
console.log('USing ws');
|
self.provider = new this.web3.providers.WebsocketProvider(self.web3Endpoint, {headers: {Origin: "embark"}});
|
||||||
self.addProvider(new SubscriptionSubprovider());
|
|
||||||
self.addProvider(new WsSubprovider({
|
|
||||||
rpcUrl: self.web3Endpoint,
|
|
||||||
origin: this.blockchainConfig.wsOrigins.split(',')[0]
|
|
||||||
}));
|
|
||||||
} else {
|
} else {
|
||||||
return callback(__("contracts config error: unknown deployment type %s", this.type));
|
return callback(__("contracts config error: unknown deployment type %s", this.type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.web3.setProvider(self.provider);
|
||||||
|
|
||||||
// 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.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, self.logger);
|
self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, self.logger);
|
||||||
self.addresses = [];
|
self.addresses = [];
|
||||||
async.waterfall([
|
if (!self.accounts.length) {
|
||||||
function populateWeb3Wallet(next) {
|
return callback();
|
||||||
if (!self.accounts.length) {
|
}
|
||||||
return next(NO_ACCOUNTS);
|
self.accounts.forEach(account => {
|
||||||
}
|
self.addresses.push(account.address);
|
||||||
self.accounts.forEach(account => {
|
self.web3.eth.accounts.wallet.add(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();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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) {
|
fundAccounts(callback) {
|
||||||
@ -104,24 +71,6 @@ class Provider extends ProviderEngine {
|
|||||||
fundAccount(self.web3, account.address, account.hexBalance, eachCb);
|
fundAccount(self.web3, account.address, account.hexBalance, eachCb);
|
||||||
}, callback);
|
}, 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;
|
module.exports = Provider;
|
||||||
|
@ -44,12 +44,11 @@ class Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
initWeb3Provider(callback) {
|
initWeb3Provider(callback) {
|
||||||
const self = this;
|
|
||||||
if (this.provider) {
|
if (this.provider) {
|
||||||
this.provider.stop();
|
this.provider.stop();
|
||||||
}
|
}
|
||||||
if (this.simOptions.host) {
|
if (this.simOptions.host) {
|
||||||
let {host, port, type, protocol, accounts} = this.simOptions;
|
let {host, port, type, protocol, accounts} = this.simOptions;
|
||||||
if (!protocol) {
|
if (!protocol) {
|
||||||
protocol = (this.simOptions.type === "rpc") ? 'http' : 'ws';
|
protocol = (this.simOptions.type === "rpc") ? 'http' : 'ws';
|
||||||
}
|
}
|
||||||
@ -71,21 +70,6 @@ class Test {
|
|||||||
return callback(err);
|
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 = new Provider(providerOptions);
|
||||||
this.provider.startWeb3Provider(callback);
|
this.provider.startWeb3Provider(callback);
|
||||||
});
|
});
|
||||||
@ -203,7 +187,11 @@ class Test {
|
|||||||
if (options.deployment.type !== 'rpc' && options.deployment.type !== 'ws') {
|
if (options.deployment.type !== 'rpc' && options.deployment.type !== 'ws') {
|
||||||
callback(__("contracts config error: unknown deployment type %s", options.deployment.type));
|
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;
|
resetServices = true;
|
||||||
}
|
}
|
||||||
if (!resetServices) {
|
if (!resetServices) {
|
||||||
@ -289,7 +277,9 @@ class Test {
|
|||||||
console.warn("Warning: default account has no funds");
|
console.warn("Warning: default account has no funds");
|
||||||
}
|
}
|
||||||
next(null, accounts);
|
next(null, accounts);
|
||||||
}).catch((err) => { next(err); });
|
}).catch((err) => {
|
||||||
|
next(err);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
function deploy(accounts, next) {
|
function deploy(accounts, next) {
|
||||||
self.engine.deployManager.gasLimit = 6000000;
|
self.engine.deployManager.gasLimit = 6000000;
|
||||||
@ -310,7 +300,13 @@ class Test {
|
|||||||
} else {
|
} else {
|
||||||
data = self.contracts[contractName].options.data;
|
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;
|
self.contracts[contractName].address = contract.deployedAddress;
|
||||||
if (self.contracts[contractName].options) {
|
if (self.contracts[contractName].options) {
|
||||||
@ -358,7 +354,13 @@ class Test {
|
|||||||
contract = this.engine.contractsManager.contracts[contractNames[0]];
|
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].address = contract.address;
|
||||||
this.contracts[contractName].options.data = contract.code;
|
this.contracts[contractName].options.data = contract.code;
|
||||||
this.contracts[contractName].options.gas = 6000000;
|
this.contracts[contractName].options.gas = 6000000;
|
||||||
|
958
package-lock.json
generated
958
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -38,7 +38,6 @@
|
|||||||
"css-loader": "^0.28.11",
|
"css-loader": "^0.28.11",
|
||||||
"deep-equal": "^1.0.1",
|
"deep-equal": "^1.0.1",
|
||||||
"ejs": "^2.5.8",
|
"ejs": "^2.5.8",
|
||||||
"embark-web3-provider-engine": "14.0.7",
|
|
||||||
"eth-ens-namehash": "^2.0.8",
|
"eth-ens-namehash": "^2.0.8",
|
||||||
"eth-lib": "^0.2.8",
|
"eth-lib": "^0.2.8",
|
||||||
"ethereumjs-wallet": "0.6.0",
|
"ethereumjs-wallet": "0.6.0",
|
||||||
|
@ -3,11 +3,6 @@ const SimpleStorage = require('Embark/contracts/SimpleStorage');
|
|||||||
let accounts;
|
let accounts;
|
||||||
|
|
||||||
config({
|
config({
|
||||||
deployment: {
|
|
||||||
type: 'ws',
|
|
||||||
host: 'localhost',
|
|
||||||
port: '8546'
|
|
||||||
},
|
|
||||||
contracts: {
|
contracts: {
|
||||||
"SimpleStorage": {
|
"SimpleStorage": {
|
||||||
args: [100],
|
args: [100],
|
||||||
@ -43,20 +38,14 @@ contract("SimpleStorage", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('listens to events', function (done) {
|
it('listens to events', function (done) {
|
||||||
SimpleStorage.once('EventOnSet2', function(error, _result){
|
SimpleStorage.once('EventOnSet2', async function (error, _result) {
|
||||||
console.log('error', error);
|
assert.strictEqual(error, null);
|
||||||
console.log('result', _result);
|
|
||||||
|
|
||||||
/*assert.strictEqual(error, null);
|
|
||||||
let result = await SimpleStorage.methods.get().call();
|
let result = await SimpleStorage.methods.get().call();
|
||||||
assert.strictEqual(parseInt(result, 10), 150);*/
|
assert.strictEqual(parseInt(result, 10), 150);
|
||||||
done(error);
|
done(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('TEST');
|
SimpleStorage.methods.set2(150, 100).send();
|
||||||
SimpleStorage.methods.set2(150, 100).send(() => {
|
|
||||||
console.log('Done');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user