Adding factor logic to relay

This commit is contained in:
Richard Ramos 2018-04-11 09:56:25 -04:00
parent cc4dac63b8
commit e5b7b5bd3f
4 changed files with 65 additions and 9 deletions

View File

@ -15,10 +15,24 @@
"powTime": 1000 "powTime": 1000
}, },
"tokens": {
"0x0": {
"minRelayFactor": 1,
"name": "Ethereum",
"symbol": "ETH"
},
"0x0ABEEF": {
"minRelayFactor": 1000000000000,
"name": "RandomToken",
"symbol": "RDN",
"pricePlugin": "plugins/token-utils"
}
},
"contracts":{ "contracts":{
"IdentityGasRelay": { "IdentityGasRelay": {
"isIdentity": true, "isIdentity": true,
"factoryAddress": "0x24cb6a5b6c81e8ce3edb059ab97984c3d3ea2e3e", "factoryAddress": "0x96f0811c6484c59c2674da1f64e725c01d82c1b5",
"abiFile": "../abi/IdentityGasRelay.json", "abiFile": "../abi/IdentityGasRelay.json",
"allowedFunctions": [ "allowedFunctions": [
{ {
@ -26,6 +40,7 @@
"to": "_to", "to": "_to",
"value": "_value", "value": "_value",
"data": "_data", "data": "_data",
"gasPrice": "_gasPrice",
"isToken": true, "isToken": true,
"token": "_baseToken" "token": "_baseToken"
}, },
@ -34,6 +49,7 @@
"to": "_to", "to": "_to",
"value": "_value", "value": "_value",
"data": "_data", "data": "_data",
"gasPrice": "_gasPrice",
"isToken": false "isToken": false
} }
] ]

View File

@ -0,0 +1,15 @@
class TokenUtils {
constructor(tokenConfig){
this.name = tokenConfig.name || "";
this.symbol = tokenConfig.symbol || "";
this.minRelayFactor = tokenConfig.minRelayFactor || 1;
}
getFactor(){
// TODO get price from somewhere
return 100000;
}
}
module.exports = TokenUtils;

View File

@ -136,12 +136,34 @@ const processMessages = async function(error, message, subscription){
return reply('Invalid contract code', message); // TODO Log this return reply('Invalid contract code', message); // TODO Log this
} }
// Determining balances
const params = web3.eth.abi.decodeParameters(contract.allowedFunctions[functionName].inputs, functionParameters); const params = web3.eth.abi.decodeParameters(contract.allowedFunctions[functionName].inputs, functionParameters);
const tokenAddress = contract.allowedFunctions[functionName].isToken ? params[contract.allowedFunctions[functionName].token] : "0x0";
// Determine if gas price offered is worth at least the minimum
const gasPrice = params[contract.allowedFunctions[functionName].gasPrice];
if(gasPrice < config.tokens[tokenAddress].minRelayFactor){
return reply("_gasPrice less than minimum: ", config.tokens[tokenAddress.minRelayFactor]);
}
// Obtain factor
let factor;
if(contract.allowedFunctions[functionName].isToken){
const PricePlugin = require(config.tokens[tokenAddress].pricePlugin);
const pricePlg = new PricePlugin(config.tokens)
factor = pricePlg.getFactor();
} else {
factor = 1;
}
console.log(factor);
/*
// Determining balances
let balance; let balance;
if(contract.isIdentity){ if(contract.isIdentity){
if(contract.allowedFunctions[functionName].isToken){ if(contract.allowedFunctions[functionName].isToken){
const Token = new web3.eth.Contract(erc20ABI, params[contracts.allowedFunctions[functionName].token]); const Token = new web3.eth.Contract(erc20ABI, params[contract.allowedFunctions[functionName].token]);
balance = new web3.utils.BN(await Token.methods.balanceOf(address).call()); balance = new web3.utils.BN(await Token.methods.balanceOf(address).call());
} else { } else {
balance = new web3.utils.BN(await web3.eth.getBalance(address)); balance = new web3.utils.BN(await web3.eth.getBalance(address));
@ -149,14 +171,15 @@ const processMessages = async function(error, message, subscription){
} else { } else {
// TODO SNT Controller // TODO SNT Controller
} }
*/
// Estimating gas
let estimatedGas = new web3.utils.BN(await web3.eth.estimateGas({
to: address,
data: params[contracts.allowedFunctions[functionName].data]
}));
// Estimating gas
/*let estimatedGas = new web3.utils.BN(await web3.eth.estimateGas({
to: address,
data: params[contract.allowedFunctions[functionName].data]
}));*/
// TODO determine if balance is enough // TODO determine if balance is enough
web3.eth.sendTransaction({ web3.eth.sendTransaction({

View File

@ -92,6 +92,8 @@ describe('FriendsRecovery', function() {
ethUtils.ecsign(msgHash, ethUtils.toBuffer(friends[3].private, 'hex')) ethUtils.ecsign(msgHash, ethUtils.toBuffer(friends[3].private, 'hex'))
]; ];
console.log(frienSignatures[0]);
let tx2 = await recovery.methods.approvePreSigned( let tx2 = await recovery.methods.approvePreSigned(
hashedMessageToSign, hashedMessageToSign,
[ [