Fixing estimation connection error
This commit is contained in:
parent
520859cd27
commit
8e32274461
|
@ -3,9 +3,13 @@
|
|||
"protocol": "ws",
|
||||
"host": "localhost",
|
||||
"port": 8546,
|
||||
"ganache": {
|
||||
"protocol": "http",
|
||||
"host": "localhost",
|
||||
"port": "8545"
|
||||
},
|
||||
"blockchain": {
|
||||
"account": "0xad7ace64197d216d89a1a5c0b730d20b4aa3cbf8",
|
||||
"gasPrice": 100000000000
|
||||
"account": "0x1847ab5a71eaa95315c3fc2d3dfb53b7e6e8f313"
|
||||
},
|
||||
"whisper": {
|
||||
"symKey": "0xd0d905c1c62b810b787141430417caf2b3f54cffadb395b7bb39fdeb8f17266b",
|
||||
|
@ -21,7 +25,7 @@
|
|||
"name": "Ethereum",
|
||||
"symbol": "ETH"
|
||||
},
|
||||
"0x04936bA0aFC438b653E312298D11c7750f4b74cF": {
|
||||
"0xf8a85AfA502a0A27aAA3528C62eB059Db97a6007": {
|
||||
"minRelayFactor": 10000,
|
||||
"name": "Random Test Token",
|
||||
"symbol": "RDN",
|
||||
|
@ -33,7 +37,7 @@
|
|||
"IdentityGasRelay": {
|
||||
"abiFile": "../abi/IdentityGasRelay.json",
|
||||
"isIdentity": true,
|
||||
"factoryAddress": "0x0e34619748Aa612A11d6c2F31783384eb2b47366",
|
||||
"factoryAddress": "0xdd8b8aCf484875dC6565F6B614B8Dc9C7f074C00",
|
||||
"kernelVerification": "isKernel(address _addr)",
|
||||
"allowedFunctions": [
|
||||
{
|
||||
|
|
|
@ -100,14 +100,20 @@ class MessageProcessor {
|
|||
}
|
||||
|
||||
async _estimateGas(input){
|
||||
const web3Sim = new Web3(ganache.provider({fork: `${this.config.node.protocol}://${this.config.node.host}:${this.config.node.port}`}));
|
||||
const simAccounts = await web3Sim.eth.getAccounts();
|
||||
let web3Sim = new Web3(ganache.provider({
|
||||
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({
|
||||
from: simAccounts[0],
|
||||
to: input.address,
|
||||
value: 0,
|
||||
data: input.payload
|
||||
});
|
||||
|
||||
return web3Sim.utils.toBN(simulatedReceipt.gasUsed);
|
||||
}
|
||||
|
||||
|
@ -160,9 +166,14 @@ class MessageProcessor {
|
|||
const gasPriceInETH = gasPrice.div(factor);
|
||||
const gasLimitInETH = gasLimit.div(factor);
|
||||
|
||||
const estimatedGas = this._estimateGas(input);
|
||||
if(gasLimitInETH.lt(estimatedGas)) {
|
||||
return this._reply("Gas limit below estimated gas", message);
|
||||
try {
|
||||
const estimatedGas = await this._estimateGas(input);
|
||||
if(gasLimitInETH.lt(estimatedGas)) {
|
||||
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);
|
||||
|
@ -184,7 +195,7 @@ class MessageProcessor {
|
|||
return this._reply("Transaction mined;"
|
||||
+ receipt.transactionHash
|
||||
+ ';'
|
||||
+ JSON.stringify(receipt.events)
|
||||
+ JSON.stringify(receipt)
|
||||
, message);
|
||||
}).catch((err) => {
|
||||
this._reply("Couldn't mine transaction: " + err.message, message);
|
||||
|
|
Loading…
Reference in New Issue