Fixing estimation connection error

This commit is contained in:
Richard Ramos 2018-05-03 10:59:28 -04:00
parent 520859cd27
commit 8e32274461
2 changed files with 25 additions and 10 deletions

View File

@ -3,9 +3,13 @@
"protocol": "ws", "protocol": "ws",
"host": "localhost", "host": "localhost",
"port": 8546, "port": 8546,
"ganache": {
"protocol": "http",
"host": "localhost",
"port": "8545"
},
"blockchain": { "blockchain": {
"account": "0xad7ace64197d216d89a1a5c0b730d20b4aa3cbf8", "account": "0x1847ab5a71eaa95315c3fc2d3dfb53b7e6e8f313"
"gasPrice": 100000000000
}, },
"whisper": { "whisper": {
"symKey": "0xd0d905c1c62b810b787141430417caf2b3f54cffadb395b7bb39fdeb8f17266b", "symKey": "0xd0d905c1c62b810b787141430417caf2b3f54cffadb395b7bb39fdeb8f17266b",
@ -21,7 +25,7 @@
"name": "Ethereum", "name": "Ethereum",
"symbol": "ETH" "symbol": "ETH"
}, },
"0x04936bA0aFC438b653E312298D11c7750f4b74cF": { "0xf8a85AfA502a0A27aAA3528C62eB059Db97a6007": {
"minRelayFactor": 10000, "minRelayFactor": 10000,
"name": "Random Test Token", "name": "Random Test Token",
"symbol": "RDN", "symbol": "RDN",
@ -33,7 +37,7 @@
"IdentityGasRelay": { "IdentityGasRelay": {
"abiFile": "../abi/IdentityGasRelay.json", "abiFile": "../abi/IdentityGasRelay.json",
"isIdentity": true, "isIdentity": true,
"factoryAddress": "0x0e34619748Aa612A11d6c2F31783384eb2b47366", "factoryAddress": "0xdd8b8aCf484875dC6565F6B614B8Dc9C7f074C00",
"kernelVerification": "isKernel(address _addr)", "kernelVerification": "isKernel(address _addr)",
"allowedFunctions": [ "allowedFunctions": [
{ {

View File

@ -100,14 +100,20 @@ class MessageProcessor {
} }
async _estimateGas(input){ async _estimateGas(input){
const web3Sim = new Web3(ganache.provider({fork: `${this.config.node.protocol}://${this.config.node.host}:${this.config.node.port}`})); let web3Sim = new Web3(ganache.provider({
const simAccounts = await web3Sim.eth.getAccounts(); fork: `${this.config.node.ganache.protocol}://${this.config.node.ganache.host}:${this.config.node.ganache.port}`,
locked: false
}));
let simAccounts = await web3Sim.eth.getAccounts();
let simulatedReceipt = await web3Sim.eth.sendTransaction({ let simulatedReceipt = await web3Sim.eth.sendTransaction({
from: simAccounts[0], from: simAccounts[0],
to: input.address, to: input.address,
value: 0, value: 0,
data: input.payload data: input.payload
}); });
return web3Sim.utils.toBN(simulatedReceipt.gasUsed); return web3Sim.utils.toBN(simulatedReceipt.gasUsed);
} }
@ -160,10 +166,15 @@ class MessageProcessor {
const gasPriceInETH = gasPrice.div(factor); const gasPriceInETH = gasPrice.div(factor);
const gasLimitInETH = gasLimit.div(factor); const gasLimitInETH = gasLimit.div(factor);
const estimatedGas = this._estimateGas(input); try {
const estimatedGas = await this._estimateGas(input);
if(gasLimitInETH.lt(estimatedGas)) { if(gasLimitInETH.lt(estimatedGas)) {
return this._reply("Gas limit below estimated gas", message); return this._reply("Gas limit below estimated gas", message);
} }
} catch(exc){
if(exc.message.indexOf("revert") > -1)
return this._reply("Transaction will revert");
}
const estimatedGasInToken = estimatedGas.mul(factor); const estimatedGasInToken = estimatedGas.mul(factor);
if(estimatedGasInToken.mul(gasPrice) < token.minRelayFactor){ if(estimatedGasInToken.mul(gasPrice) < token.minRelayFactor){
@ -184,7 +195,7 @@ class MessageProcessor {
return this._reply("Transaction mined;" return this._reply("Transaction mined;"
+ receipt.transactionHash + receipt.transactionHash
+ ';' + ';'
+ JSON.stringify(receipt.events) + JSON.stringify(receipt)
, message); , message);
}).catch((err) => { }).catch((err) => {
this._reply("Couldn't mine transaction: " + err.message, message); this._reply("Couldn't mine transaction: " + err.message, message);