mirror of
https://github.com/status-im/snt-gas-relay.git
synced 2025-01-14 00:22:27 +00:00
Calculating gas limit
This commit is contained in:
parent
cae1b967ee
commit
ac70ba2b8f
@ -42,7 +42,7 @@
|
||||
"data": "_data",
|
||||
"gasPrice": "_gasPrice",
|
||||
"gasToken": "_gasToken",
|
||||
"gasMinimal": "_gasMinimal",
|
||||
"gasLimit": "_gasLimit",
|
||||
"isToken": true,
|
||||
"token": "_baseToken"
|
||||
},
|
||||
@ -53,7 +53,7 @@
|
||||
"data": "_data",
|
||||
"gasPrice": "_gasPrice",
|
||||
"gasToken": "_gasToken",
|
||||
"gasMinimal": "_gasMinimal",
|
||||
"gasLimit": "_gasLimit",
|
||||
"isToken": false
|
||||
}
|
||||
]
|
||||
|
@ -158,10 +158,9 @@ const processMessages = async function(error, message, subscription){
|
||||
}
|
||||
|
||||
const gasPrice = web3.utils.toBN(params[contract.allowedFunctions[functionName].gasPrice]);
|
||||
const gasMinimal = web3.utils.toBN(params[contract.allowedFunctions[functionName].gasMinimal]);
|
||||
const gasLimit = web3.utils.toBN(params[contract.allowedFunctions[functionName].gasLimit]);
|
||||
|
||||
|
||||
// Determining balances of gasPrice
|
||||
// Determining balances of token used
|
||||
let balance;
|
||||
if(token.symbol == "ETH")
|
||||
balance = new web3.utils.BN(await web3.eth.getBalance(address));
|
||||
@ -171,10 +170,6 @@ const processMessages = async function(error, message, subscription){
|
||||
balance = new web3.utils.BN(await Token.methods.balanceOf(address).call());
|
||||
}
|
||||
|
||||
if(balance.lt(web3.utils.toBN(gasPrice.mul(gasMinimal)))){
|
||||
return reply("Not enough balance", message);
|
||||
}
|
||||
|
||||
// Determine if enough balance for baseToken
|
||||
if(contract.allowedFunctions[functionName].isToken){
|
||||
const Token = new web3.eth.Contract(erc20ABI);
|
||||
@ -193,14 +188,18 @@ const processMessages = async function(error, message, subscription){
|
||||
factor = 1;
|
||||
}
|
||||
|
||||
// TODO Determine cost of running function in ether
|
||||
// TODO Determine if gas price offered is worth at least the minimum
|
||||
const balanceInETH = balance.div(factor);
|
||||
const gasLimitInETH = gasLimit.div(factor);
|
||||
if(balanceInETH.lt(web3.utils.toBN(gasPrice.mul(gasLimit)))){
|
||||
return reply("Not enough balance", message);
|
||||
}
|
||||
|
||||
web3.eth.sendTransaction({
|
||||
from: config.blockchain.account,
|
||||
to: address,
|
||||
value: 0,
|
||||
data: payload
|
||||
data: payload,
|
||||
gasLimit: gasLimitInETH
|
||||
})
|
||||
.then(function(receipt){
|
||||
return reply("Transaction mined;" + receipt.transactionHash, message);
|
||||
|
Loading…
x
Reference in New Issue
Block a user