Added token verification and base price plugin logic

This commit is contained in:
Richard Ramos 2018-04-11 11:17:08 -04:00
parent faa9dd56c0
commit b38a1794cc
3 changed files with 34 additions and 15 deletions

View File

@ -16,16 +16,16 @@
},
"tokens": {
"0x0": {
"0x0000000000000000000000000000000000000000": {
"minRelayFactor": 1,
"name": "Ethereum",
"symbol": "ETH"
},
"0x0ABEEF": {
"0x00000000000000000000000000000000000ABeEF": {
"minRelayFactor": 1000000000000,
"name": "RandomToken",
"symbol": "RDN",
"pricePlugin": "plugins/token-utils"
"pricePlugin": "../plugins/token-utils.js"
}
},

View File

@ -8,6 +8,15 @@ const erc20ABI = require('../abi/ERC20.json');
console.info("Starting...")
async function start(){
for(token in config.tokens){
if(config.tokens[token].pricePlugin !== undefined){
let PricePlugin = require(config.tokens[token].pricePlugin);
config.tokens[token].pricePlugin = new PricePlugin(config.tokens)
}
}
config.topics = [];
for(let contractName in config.contracts){
@ -25,7 +34,6 @@ for(let contractName in config.contracts){
let functionSignature = web3.utils.sha3(config.contracts[contractName].allowedFunctions[i].function).slice(0, 10);
config.contracts[contractName].allowedFunctions[functionSignature] = config.contracts[contractName].allowedFunctions[i];
delete config.contracts[contractName].allowedFunctions[i];
}
config.contracts[contractName].functionSignatures = Object.keys(config.contracts[contractName].allowedFunctions);
@ -139,25 +147,31 @@ const processMessages = async function(error, message, subscription){
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", message);
if(config.tokens[tokenAddress] == undefined){
return reply("Token not allowed", message);
}
const gasPrice = params[contract.allowedFunctions[functionName].gasPrice];
// 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();
factor = config.tokens[tokenAddress].pricePlugin.getFactor();
} else {
factor = 1;
}
console.log(factor);
// Determine if gas price offered is worth at least the minimum
/*if(_________ < config.tokens[tokenAddress].minRelayFactor){
return reply("_gasPrice less than minimum", message);
}
if(gasPrice / factor < _______ ){
return reply("_gasPrice is too low", message);
}*/
/*
// Determining balances
let balance;
@ -182,6 +196,9 @@ const processMessages = async function(error, message, subscription){
// TODO determine if balance is enough
web3.eth.sendTransaction({
from: config.blockchain.account,
to: address,

View File

@ -40,6 +40,8 @@ $(function(){
$('button').on('click', async function(e){
e.preventDefault();
$('p.result').text('');
let publicKey = add0x($("#publicKey"));
let msgTopic = add0x($('#topic'));
let msgPayload = add0x($('#payload'));