mirror of
https://github.com/status-im/snt-gas-relay.git
synced 2025-02-17 08:26:46 +00:00
Extracted gas estimate to individual function
This commit is contained in:
parent
56879acc00
commit
67e1c4939b
@ -94,6 +94,19 @@ class MessageProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_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 simulatedReceipt = await web3Sim.eth.sendTransaction({
|
||||||
|
from: simAccounts[0],
|
||||||
|
to: input.address,
|
||||||
|
value: 0,
|
||||||
|
data: input.payload
|
||||||
|
});
|
||||||
|
return web3Sim.utils.toBN(simulatedReceipt.gasUsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async process(error, message){
|
async process(error, message){
|
||||||
|
|
||||||
if(error){
|
if(error){
|
||||||
@ -142,25 +155,14 @@ class MessageProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const estimatedGas = this._estimateGas(input);
|
||||||
// Estimate costs
|
|
||||||
const web3Sim = new Web3(ganache.provider({fork: `${config.node.protocol}://${config.node.host}:${config.node.port}`}));
|
|
||||||
const simAccounts = await web3Sim.eth.getAccounts();
|
|
||||||
let simulatedReceipt = await web3Sim.eth.sendTransaction({
|
|
||||||
from: simAccounts[0],
|
|
||||||
to: input.address,
|
|
||||||
value: 0,
|
|
||||||
data: input.payload
|
|
||||||
});
|
|
||||||
|
|
||||||
const estimatedGas = web3.utils.toBN(simulatedReceipt.gasUsed);
|
|
||||||
if(gasLimit.lt(estimatedGas)) {
|
if(gasLimit.lt(estimatedGas)) {
|
||||||
return this._reply("Gas limit below estimated gas", message);
|
return this._reply("Gas limit below estimated gas", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.web3.eth.sendTransaction({
|
this.web3.eth.sendTransaction({
|
||||||
from: config.node.blockchain.account,
|
from: this.config.node.blockchain.account,
|
||||||
to: address,
|
to: address,
|
||||||
value: 0,
|
value: 0,
|
||||||
data: input.payload,
|
data: input.payload,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user