Added babel + linting some of the code

This commit is contained in:
Richard Ramos 2018-08-06 09:18:30 -04:00
parent cb957b57d0
commit bd93bb3062
14 changed files with 722 additions and 113 deletions

12
gas-relayer/.babelrc Normal file
View File

@ -0,0 +1,12 @@
{
"plugins": [
"transform-object-rest-spread"
],
"presets": [
"stage-2"
],
"ignore": [
"config/",
"node_modules"
]
}

288
gas-relayer/.eslintrc Normal file
View File

@ -0,0 +1,288 @@
{
"parser": "babel-eslint",
"plugins": [ ],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"env": {
"es6": true,
"browser": true,
"node": true,
"mocha": true
},
"extends": [
"eslint:recommended"
],
"rules": {
"accessor-pairs": "error",
"array-bracket-newline": "error",
"array-bracket-spacing": [
"error",
"never"
],
"array-callback-return": "off",
"array-element-newline": "off",
"arrow-body-style": "off",
"arrow-parens": "off",
"arrow-spacing": [
"error",
{
"after": true,
"before": true
}
],
"block-scoped-var": "error",
"block-spacing": "error",
"brace-style": "off",
"callback-return": "off",
"camelcase": "off",
"capitalized-comments": "off",
"class-methods-use-this": "off",
"comma-dangle": "error",
"comma-spacing": "off",
"comma-style": [
"error",
"last"
],
"complexity": "error",
"computed-property-spacing": [
"error",
"never"
],
"consistent-return": "off",
"consistent-this": "off",
"curly": "off",
"default-case": "error",
"dot-location": [
"error",
"property"
],
"dot-notation": "off",
"eol-last": "error",
"eqeqeq": "off",
"for-direction": "error",
"func-call-spacing": "error",
"func-name-matching": "error",
"func-names": "off",
"func-style": "off",
"function-paren-newline": "off",
"generator-star-spacing": "error",
"getter-return": "error",
"global-require": "off",
"guard-for-in": "off",
"handle-callback-err": "off",
"id-blacklist": "error",
"id-length": "off",
"id-match": "error",
"indent": "off",
"indent-legacy": "off",
"init-declarations": "off",
"jsx-quotes": "error",
"key-spacing": "off",
"keyword-spacing": "off",
"line-comment-position": "off",
"linebreak-style": [
"error",
"unix"
],
"lines-around-comment": "error",
"lines-around-directive": "error",
"max-depth": "error",
"max-len": "off",
"max-lines": "off",
"max-nested-callbacks": "error",
"max-params": "off",
"max-statements": "off",
"max-statements-per-line": "off",
"multiline-ternary": [
"error",
"never"
],
"new-parens": "off",
"newline-after-var": "off",
"newline-before-return": "off",
"newline-per-chained-call": "off",
"no-alert": "error",
"no-array-constructor": "error",
"no-await-in-loop": "error",
"no-bitwise": "error",
"no-buffer-constructor": "error",
"no-caller": "error",
"no-catch-shadow": "error",
"no-confusing-arrow": "error",
"no-console": "off",
"no-continue": "off",
"no-div-regex": "error",
"no-duplicate-imports": "error",
"no-else-return": "off",
"no-empty-function": "off",
"no-eq-null": "error",
"no-eval": "off",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-extra-parens": "off",
"no-floating-decimal": "error",
"no-implicit-coercion": "error",
"no-implicit-globals": "error",
"no-implied-eval": "error",
"no-inline-comments": "off",
"no-inner-declarations": [
"error",
"functions"
],
"no-invalid-this": "off",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-lonely-if": "off",
"no-loop-func": "off",
"no-magic-numbers": "off",
"no-mixed-operators": "error",
"no-mixed-requires": "error",
"no-multi-assign": "error",
"no-multi-spaces": "off",
"no-multi-str": "error",
"no-multiple-empty-lines": "error",
"no-native-reassign": "error",
"no-negated-condition": "off",
"no-negated-in-lhs": "error",
"no-nested-ternary": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-object": "error",
"no-new-require": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-param-reassign": "off",
"no-path-concat": "error",
"no-plusplus": "off",
"no-process-env": "off",
"no-process-exit": "off",
"no-proto": "error",
"no-prototype-builtins": "off",
"no-restricted-globals": "error",
"no-restricted-imports": "error",
"no-restricted-modules": "error",
"no-restricted-properties": "error",
"no-restricted-syntax": "error",
"no-return-assign": "error",
"no-return-await": "error",
"no-script-url": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-shadow": "off",
"no-shadow-restricted-names": "error",
"no-spaced-func": "error",
"no-sync": "off",
"no-tabs": "error",
"no-template-curly-in-string": "error",
"no-ternary": "off",
"no-throw-literal": "error",
"no-trailing-spaces": "off",
"no-undef-init": "error",
"no-undefined": "off",
"no-underscore-dangle": "off",
"no-unmodified-loop-condition": "error",
"no-unneeded-ternary": "error",
"no-unused-expressions": "error",
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"no-use-before-define": "off",
"no-useless-call": "off",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
"no-useless-constructor": "error",
"no-useless-escape": "off",
"no-useless-rename": "error",
"no-useless-return": "off",
"no-var": "off",
"no-void": "error",
"no-warning-comments": "off",
"no-whitespace-before-property": "error",
"no-with": "error",
"nonblock-statement-body-position": "error",
"object-curly-newline": "off",
"object-curly-spacing": [
"error",
"never"
],
"object-property-newline": "off",
"object-shorthand": "off",
"one-var": "off",
"one-var-declaration-per-line": "off",
"operator-assignment": "off",
"operator-linebreak": "error",
"padded-blocks": "off",
"padding-line-between-statements": "error",
"prefer-arrow-callback": "off",
"prefer-const": "off",
"prefer-destructuring": "off",
"prefer-numeric-literals": "error",
"prefer-promise-reject-errors": "error",
"prefer-reflect": "off",
"prefer-rest-params": "off",
"prefer-spread": "off",
"prefer-template": "off",
"quote-props": "off",
"quotes": "off",
"radix": "error",
"require-await": "error",
"require-jsdoc": "off",
"rest-spread-spacing": "error",
"semi": "error",
"semi-spacing": [
"error",
{
"after": true,
"before": false
}
],
"semi-style": [
"error",
"last"
],
"sort-imports": [2, {
"ignoreCase": false,
"ignoreMemberSort": false,
"memberSyntaxSortOrder": ["none", "all", "multiple", "single"]
}],
"sort-keys": "off",
"sort-vars": "off",
"space-before-blocks": "off",
"space-before-function-paren": "off",
"space-in-parens": [
"error",
"never"
],
"space-infix-ops": "off",
"space-unary-ops": "error",
"spaced-comment": "off",
"strict": "error",
"switch-colon-spacing": "error",
"symbol-description": "error",
"template-curly-spacing": [
"error",
"never"
],
"template-tag-spacing": "error",
"unicode-bom": [
"error",
"never"
],
"valid-jsdoc": "error",
"vars-on-top": "off",
"wrap-iife": "error",
"wrap-regex": "error",
"yield-star-spacing": "error",
"yoda": [
"error",
"never"
]
}
}

View File

@ -9,6 +9,17 @@
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-eslint": "^8.2.6",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-stage-2": "^6.24.1",
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0"
},
"dependencies": {
"daemonize2": "^0.4.2",
"ganache-cli": "^6.1.0",

View File

@ -53,7 +53,7 @@ class ContractSettings {
if(this.pendingToLoad == 0) this.events.emit("setup:complete", this);
})
.catch((err) => {
console.error("Invalid contract for " + contractName);
console.error("Invalid contract for " + topicName);
console.error(err);
process.exit();
});

View File

@ -24,7 +24,7 @@ class MessageProcessor {
async _validateInput(message){
const contract = this.settings.getContractByTopic(message.topic);
if(!/^0x[0-9a-f]{40}$/i.test(message.input.address)){
if(!(/^0x[0-9a-f]{40}$/i).test(message.input.address)){
this._reply('Invalid address', message);
return false;
}
@ -110,15 +110,15 @@ class MessageProcessor {
this.web3.eth.estimateGas(p)
.then((estimatedGas) => {
p.gas = parseInt(estimatedGas * 1.1)
p.gas = parseInt(estimatedGas * 1.1, 10);
return this.web3.eth.sendTransaction(p);
})
.then((receipt) => {
return this._reply("Transaction mined;"
+ receipt.transactionHash
+ ';'
+ JSON.stringify(receipt)
, message);
return this._reply("Transaction mined;" +
receipt.transactionHash +
';' +
JSON.stringify(receipt),
message);
}).catch((err) => {
this._reply("Couldn't mine transaction: " + err.message, message);
// TODO log this?

View File

@ -17,7 +17,7 @@ let connectionURL = `${config.node.local.protocol}://${config.node.local.host}:$
const web3 = new Web3(connectionURL);
web3.eth.net.isListening()
.then(listening => events.emit('web3:connected', connectionURL))
.then(() => events.emit('web3:connected', connectionURL))
.catch(error => {
console.error(error);
process.exit();
@ -34,13 +34,10 @@ events.on('web3:connected', connURL => {
// Setting up Whisper options
const shhOptions = {
ttl: config.node.whisper.ttl,
minPow: config.node.whisper.minPow,
minPow: config.node.whisper.minPow
};
events.on('setup:complete', (settings) => {
let kId;
let symKId;
// Listening to whisper
@ -61,11 +58,8 @@ events.on('setup:complete', (settings) => {
events.emit('server:listen', shhOptions, settings);
}
if(config.heartbeat.enabled){
let heartbeatSymKeyId;
web3.shh.addSymKey(config.heartbeat.symKey)
.then(heartbeatSymKeyId => {
@ -100,16 +94,17 @@ events.on('setup:complete', (settings) => {
events.on('server:listen', (shhOptions, settings) => {
let processor = new MessageProcessor(config, settings, web3, shhOptions.kId);
web3.shh.subscribe('messages', shhOptions, (error, message, subscription) => processor.process(error, message));
web3.shh.subscribe('messages', shhOptions, (error, message) => processor.process(error, message));
});
// Daemon helper functions
process.on("uncaughtException", function(err) {
// TODO
console.error(err);
});
process.once("SIGTERM", function() {
log("Stopping...");
console.log("Stopping...");
});

View File

@ -15,19 +15,19 @@ class IdentityStrategy {
const parameterList = this.web3.eth.abi.decodeParameters(this.contract.allowedFunctions[message.input.functionName].inputs, message.input.functionParameters);
return function(parameterName){
return parameterList[parameterName];
}
};
}
async _validateInstance(message){
const instanceCodeHash = this.web3.utils.soliditySha3(await this.web3.eth.getCode(message.input.address));
const kernelVerifSignature = this.web3.utils.soliditySha3(this.contract.kernelVerification).slice(0, 10);
if(instanceCodeHash == null) return false;
if(instanceCodeHash === null) return false;
let verificationResult = await this.web3.eth.call({
to: this.contract.factoryAddress,
data: kernelVerifSignature + instanceCodeHash.slice(2)});
return this.web3.eth.abi.decodeParameter('bool', verificationResult);;
return this.web3.eth.abi.decodeParameter('bool', verificationResult);
}
async getBalance(token, message, gasToken){
@ -67,7 +67,7 @@ class IdentityStrategy {
if(this.contract.isIdentity){
let validInstance = await this._validateInstance(message);
if(!validInstance){
return { success: false, message: "Invalid identity instance" };
return {success: false, message: "Invalid identity instance"};
}
}
@ -75,9 +75,7 @@ class IdentityStrategy {
// Verifying if token is allowed
const token = this.settings.getToken(params('_gasToken'));
if(token == undefined)
return { success: false, message: "Token not allowed" };
if(token == undefined) return {success: false, message: "Token not allowed"};
// Determine if enough balance for baseToken
const gasPrice = this.web3.utils.toBN(params('_gasPrice'));
@ -85,9 +83,9 @@ class IdentityStrategy {
if(this.contract.allowedFunctions[message.input.functionName].isToken){
const Token = new this.web3.eth.Contract(erc20ABI);
Token.options.address = params('_baseToken');
const baseToken = new this.web3.utils.BN(await Token.methods.balanceOf(message.input.address).call());
// const baseToken = new this.web3.utils.BN(await Token.methods.balanceOf(message.input.address).call());
if(balance.lt(this.web3.utils.BN(params('_value')))){
return { success: false, message: "Identity has not enough balance for specified value" };
return {success: false, message: "Identity has not enough balance for specified value"};
}
}
@ -95,7 +93,7 @@ class IdentityStrategy {
const gasToken = params('_gasToken');
const balance = await this.getBalance(token, message, gasToken);
if(balance.lt(this.web3.utils.toBN(gasPrice.mul(gasLimit)))) {
return { success: false, message: "Identity has not enough tokens for gasPrice*gasLimit"};
return {success: false, message: "Identity has not enough tokens for gasPrice*gasLimit"};
}
@ -104,11 +102,10 @@ class IdentityStrategy {
try {
estimatedGas = await this._estimateGas(message, latestBlock.gasLimit);
if(gasLimit.lt(estimatedGas)) {
return { success: false, message: "Gas limit below estimated gas" };
return {success: false, message: "Gas limit below estimated gas"};
}
} catch(exc){
if(exc.message.indexOf("revert") > -1)
return { success: false, message: "Transaction will revert" };
if(exc.message.indexOf("revert") > -1) return {success: false, message: "Transaction will revert"};
}
return {

12
test-dapp/.babelrc Normal file
View File

@ -0,0 +1,12 @@
{
"plugins": [
"transform-object-rest-spread"
],
"presets": [
"stage-2"
],
"ignore": [
"config/",
"node_modules"
]
}

291
test-dapp/.eslintrc Normal file
View File

@ -0,0 +1,291 @@
{
"parser": "babel-eslint",
"plugins": [
"react"
],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"env": {
"es6": true,
"browser": true,
"node": true,
"mocha": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"rules": {
"accessor-pairs": "error",
"array-bracket-newline": "error",
"array-bracket-spacing": [
"error",
"never"
],
"array-callback-return": "off",
"array-element-newline": "off",
"arrow-body-style": "off",
"arrow-parens": "off",
"arrow-spacing": [
"error",
{
"after": true,
"before": true
}
],
"block-scoped-var": "error",
"block-spacing": "error",
"brace-style": "off",
"callback-return": "off",
"camelcase": "off",
"capitalized-comments": "off",
"class-methods-use-this": "off",
"comma-dangle": "error",
"comma-spacing": "off",
"comma-style": [
"error",
"last"
],
"complexity": "error",
"computed-property-spacing": [
"error",
"never"
],
"consistent-return": "off",
"consistent-this": "off",
"curly": "off",
"default-case": "error",
"dot-location": [
"error",
"property"
],
"dot-notation": "off",
"eol-last": "error",
"eqeqeq": "off",
"for-direction": "error",
"func-call-spacing": "error",
"func-name-matching": "error",
"func-names": "off",
"func-style": "off",
"function-paren-newline": "off",
"generator-star-spacing": "error",
"getter-return": "error",
"global-require": "off",
"guard-for-in": "off",
"handle-callback-err": "off",
"id-blacklist": "error",
"id-length": "off",
"id-match": "error",
"indent": "off",
"indent-legacy": "off",
"init-declarations": "off",
"jsx-quotes": "error",
"key-spacing": "off",
"keyword-spacing": "off",
"line-comment-position": "off",
"linebreak-style": [
"error",
"unix"
],
"lines-around-comment": "error",
"lines-around-directive": "error",
"max-depth": "error",
"max-len": "off",
"max-lines": "off",
"max-nested-callbacks": "error",
"max-params": "off",
"max-statements": "off",
"max-statements-per-line": "off",
"multiline-ternary": [
"error",
"never"
],
"new-parens": "off",
"newline-after-var": "off",
"newline-before-return": "off",
"newline-per-chained-call": "off",
"no-alert": "error",
"no-array-constructor": "error",
"no-await-in-loop": "error",
"no-bitwise": "error",
"no-buffer-constructor": "error",
"no-caller": "error",
"no-catch-shadow": "error",
"no-confusing-arrow": "error",
"no-console": "off",
"no-continue": "off",
"no-div-regex": "error",
"no-duplicate-imports": "error",
"no-else-return": "off",
"no-empty-function": "off",
"no-eq-null": "error",
"no-eval": "off",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-extra-parens": "off",
"no-floating-decimal": "error",
"no-implicit-coercion": "error",
"no-implicit-globals": "error",
"no-implied-eval": "error",
"no-inline-comments": "off",
"no-inner-declarations": [
"error",
"functions"
],
"no-invalid-this": "off",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-lonely-if": "off",
"no-loop-func": "off",
"no-magic-numbers": "off",
"no-mixed-operators": "error",
"no-mixed-requires": "error",
"no-multi-assign": "error",
"no-multi-spaces": "off",
"no-multi-str": "error",
"no-multiple-empty-lines": "error",
"no-native-reassign": "error",
"no-negated-condition": "off",
"no-negated-in-lhs": "error",
"no-nested-ternary": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-object": "error",
"no-new-require": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-param-reassign": "off",
"no-path-concat": "error",
"no-plusplus": "off",
"no-process-env": "off",
"no-process-exit": "off",
"no-proto": "error",
"no-prototype-builtins": "off",
"no-restricted-globals": "error",
"no-restricted-imports": "error",
"no-restricted-modules": "error",
"no-restricted-properties": "error",
"no-restricted-syntax": "error",
"no-return-assign": "error",
"no-return-await": "error",
"no-script-url": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-shadow": "off",
"no-shadow-restricted-names": "error",
"no-spaced-func": "error",
"no-sync": "off",
"no-tabs": "error",
"no-template-curly-in-string": "error",
"no-ternary": "off",
"no-throw-literal": "error",
"no-trailing-spaces": "off",
"no-undef-init": "error",
"no-undefined": "off",
"no-underscore-dangle": "off",
"no-unmodified-loop-condition": "error",
"no-unneeded-ternary": "error",
"no-unused-expressions": "error",
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"no-use-before-define": "off",
"no-useless-call": "off",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
"no-useless-constructor": "error",
"no-useless-escape": "off",
"no-useless-rename": "error",
"no-useless-return": "off",
"no-var": "off",
"no-void": "error",
"no-warning-comments": "off",
"no-whitespace-before-property": "error",
"no-with": "error",
"nonblock-statement-body-position": "error",
"object-curly-newline": "off",
"object-curly-spacing": [
"error",
"never"
],
"object-property-newline": "off",
"object-shorthand": "off",
"one-var": "off",
"one-var-declaration-per-line": "off",
"operator-assignment": "off",
"operator-linebreak": "error",
"padded-blocks": "off",
"padding-line-between-statements": "error",
"prefer-arrow-callback": "off",
"prefer-const": "off",
"prefer-destructuring": "off",
"prefer-numeric-literals": "error",
"prefer-promise-reject-errors": "error",
"prefer-reflect": "off",
"prefer-rest-params": "off",
"prefer-spread": "off",
"prefer-template": "off",
"quote-props": "off",
"quotes": "off",
"radix": "error",
"require-await": "error",
"require-jsdoc": "off",
"rest-spread-spacing": "error",
"semi": "error",
"semi-spacing": [
"error",
{
"after": true,
"before": false
}
],
"semi-style": [
"error",
"last"
],
"sort-imports": [2, {
"ignoreCase": false,
"ignoreMemberSort": false,
"memberSyntaxSortOrder": ["none", "all", "multiple", "single"]
}],
"sort-keys": "off",
"sort-vars": "off",
"space-before-blocks": "off",
"space-before-function-paren": "off",
"space-in-parens": [
"error",
"never"
],
"space-infix-ops": "off",
"space-unary-ops": "error",
"spaced-comment": "off",
"strict": "error",
"switch-colon-spacing": "error",
"symbol-description": "error",
"template-curly-spacing": [
"error",
"never"
],
"template-tag-spacing": "error",
"unicode-bom": [
"error",
"never"
],
"valid-jsdoc": "error",
"vars-on-top": "off",
"wrap-iife": "error",
"wrap-regex": "error",
"yield-star-spacing": "error",
"yoda": [
"error",
"never"
]
}
}

View File

@ -1,6 +1,6 @@
import web3 from 'Embark/web3';
import EmbarkJS from 'Embark/EmbarkJS';
import React from 'react';
import web3 from 'Embark/web3';
class AccountBalance extends React.Component {
@ -15,8 +15,7 @@ class AccountBalance extends React.Component {
componentDidMount(){
EmbarkJS.onReady(err => {
if(!err)
this.updateBalances();
if(!err) this.updateBalances();
});
}
@ -25,13 +24,13 @@ class AccountBalance extends React.Component {
web3.eth.getBalance(this.props.address)
.then(eth => {
this.setState({ eth });
this.setState({eth});
});
this.props.RND.methods.balanceOf(this.props.address)
.call()
.then(rnd => {
this.setState({ rnd });
this.setState({rnd});
});
}
@ -42,7 +41,7 @@ class AccountBalance extends React.Component {
.then(() => {
this.updateBalances();
return true;
})
});
}
generateTokens(ev){
@ -71,6 +70,6 @@ class AccountBalance extends React.Component {
</div>;
}
};
}
export default AccountBalance;

View File

@ -1,9 +1,7 @@
import Web3 from 'web3';
import React from 'react';
import { Grid, Row, Form, FormGroup, FormControl, HelpBlock, Button, ControlLabel, Col, InputGroup, Alert } from 'react-bootstrap';
import {Alert, Button, Col, ControlLabel, Form, FormControl, Grid, HelpBlock, InputGroup, Row} from 'react-bootstrap';
import AccountBalance from './accountBalance';
import React from 'react';
import Web3 from 'web3';
class ApproveAndCallGasRelayed extends React.Component {
@ -42,7 +40,7 @@ class ApproveAndCallGasRelayed extends React.Component {
let accounts = await this.props.web3.eth.getAccounts();
this.setState({
account: accounts[0]
})
});
let _skid = await web3W.shh.addSymKey(this.state.symKey);
let _kid = await web3W.shh.newKeyPair();
@ -58,24 +56,25 @@ class ApproveAndCallGasRelayed extends React.Component {
"ttl": 20,
"minPow": 0.8,
"powTime": 1000
}, (error, message, subscription) => {
}, (error, message) => {
if(error) {
console.log(error);
this.setState({errorMessage: error.message})
this.setState({errorMessage: error.message});
} else {
this.state.messages.push(this.props.web3.utils.hexToAscii(message.payload));
this.setState({messages: this.state.messages})
this.setState({messages: this.state.messages});
}
});
});
}
handleChange(e, name){
this.state[name] = e.target.value;
this.setState(this.state);
const newState = {};
newState[name] = e.target.value;
this.setState(newState);
}
async sendMessage(e){
sendMessage(e){
e.preventDefault();
@ -85,8 +84,9 @@ class ApproveAndCallGasRelayed extends React.Component {
});
try {
let jsonAbi = this.props.IdentityGasRelay._jsonInterface.filter(x => x.name == "approveAndCallGasRelayed")[0]
let funCall = this.props.web3.eth.abi.encodeFunctionCall(jsonAbi, [this.state.baseToken,
let jsonAbi = this.props.IdentityGasRelay._jsonInterface.filter(x => x.name == "approveAndCallGasRelayed")[0];
let funCall = this.props.web3.eth.abi.encodeFunctionCall(jsonAbi, [
this.state.baseToken,
this.state.to,
this.state.value,
this.state.data,
@ -94,7 +94,8 @@ class ApproveAndCallGasRelayed extends React.Component {
this.state.gasPrice,
this.state.gasLimit,
this.state.gasToken,
this.state.signature]);
this.state.signature
]);
let msgObj = {
symKeyID: this.state.skid,
sig: this.state.kid,
@ -118,7 +119,7 @@ class ApproveAndCallGasRelayed extends React.Component {
});
} catch(error){
console.error(error);
this.setState({errorMessage: error.message})
this.setState({errorMessage: error.message});
}
}
@ -151,17 +152,14 @@ class ApproveAndCallGasRelayed extends React.Component {
this.setState({signature: _signature});
} catch(error){
console.error(error);
this.setState({errorMessage: error.message})
this.setState({errorMessage: error.message});
}
}
render(){
return (<Grid>
{
this.state.errorMessage != '' ?
<React.Fragment>
<Alert bsStyle="danger">{this.state.errorMessage}</Alert>
</React.Fragment> : ''
this.state.errorMessage != '' && <React.Fragment><Alert bsStyle="danger">{this.state.errorMessage}</Alert></React.Fragment>
}
<Form>
<Row>
@ -283,4 +281,4 @@ class ApproveAndCallGasRelayed extends React.Component {
}
}
export default ApproveAndCallGasRelayed;
export default ApproveAndCallGasRelayed;

View File

@ -1,8 +1,7 @@
import Web3 from 'web3';
import React from 'react';
import { Grid, Row, Form, FormGroup, FormControl, HelpBlock, Button, ControlLabel, Col, InputGroup, Alert } from 'react-bootstrap';
import {Alert, Button, Col, ControlLabel, Form, FormControl, Grid, HelpBlock, InputGroup, Row} from 'react-bootstrap';
import AccountBalance from './accountBalance';
import React from 'react';
import Web3 from 'web3';
class CallGasRelayed extends React.Component {
@ -40,7 +39,7 @@ class CallGasRelayed extends React.Component {
let accounts = await this.props.web3.eth.getAccounts();
this.setState({
account: accounts[0]
})
});
let _skid = await web3W.shh.addSymKey(this.state.symKey);
let _kid = await web3W.shh.newKeyPair();
@ -59,22 +58,22 @@ class CallGasRelayed extends React.Component {
}, (error, message, subscription) => {
if(error) {
console.log(error);
this.setState({errorMessage: error.message})
this.setState({errorMessage: error.message});
} else {
this.state.messages.push(this.props.web3.utils.hexToAscii(message.payload));
this.setState({messages: this.state.messages})
this.setState({messages: this.state.messages});
}
});
});
}
handleChange(e, name){
this.state[name] = e.target.value;
this.setState(this.state);
const newState = {};
newState[name] = e.target.value;
this.setState(newState);
}
async sendMessage(e){
sendMessage(e){
e.preventDefault();
this.setState({
@ -83,15 +82,17 @@ class CallGasRelayed extends React.Component {
});
try {
let jsonAbi = this.props.IdentityGasRelay._jsonInterface.filter(x => x.name == "callGasRelayed")[0]
let funCall = this.props.web3.eth.abi.encodeFunctionCall(jsonAbi, [this.state.to,
let jsonAbi = this.props.IdentityGasRelay._jsonInterface.filter(x => x.name == "callGasRelayed")[0];
let funCall = this.props.web3.eth.abi.encodeFunctionCall(jsonAbi, [
this.state.to,
this.state.value,
this.state.data,
this.state.nonce,
this.state.gasPrice,
this.state.gasLimit,
this.state.gasToken,
this.state.signature]);
this.state.signature
]);
let msgObj = {
symKeyID: this.state.skid,
sig: this.state.kid,
@ -115,7 +116,7 @@ class CallGasRelayed extends React.Component {
});
} catch(error){
console.error(error);
this.setState({errorMessage: error.message})
this.setState({errorMessage: error.message});
}
}
@ -147,17 +148,14 @@ class CallGasRelayed extends React.Component {
this.setState({signature: _signature});
} catch(error){
console.error(error);
this.setState({errorMessage: error.message})
this.setState({errorMessage: error.message});
}
}
render(){
return (<Grid>
{
this.state.errorMessage != '' ?
<React.Fragment>
<Alert bsStyle="danger">{this.state.errorMessage}</Alert>
</React.Fragment> : ''
this.state.errorMessage != '' && <React.Fragment><Alert bsStyle="danger">{this.state.errorMessage}</Alert></React.Fragment>
}
<Form>
<Row>
@ -268,4 +266,4 @@ class CallGasRelayed extends React.Component {
}
}
export default CallGasRelayed;
export default CallGasRelayed;

View File

@ -1,15 +1,12 @@
import './relayer-test.css';
import {Tab, Tabs} from 'react-bootstrap';
import ApproveAndCallGasRelayed from './components/approveandcallgasrelayed';
import CallGasRelayed from './components/callgasrelayed';
import IdentityGasRelay from 'Embark/contracts/IdentityGasRelay';
import RND from 'Embark/contracts/RND';
import React from 'react';
import ReactDOM from 'react-dom';
import { Tabs, Tab } from 'react-bootstrap';
import EmbarkJS from 'Embark/EmbarkJS';
import RND from 'Embark/contracts/RND';
import IdentityGasRelay from 'Embark/contracts/IdentityGasRelay';
import CallGasRelayed from './components/callgasrelayed';
import ApproveAndCallGasRelayed from './components/approveandcallgasrelayed';
import './relayer-test.css';
import web3 from 'Embark/web3';
class App extends React.Component {

View File

@ -15,7 +15,18 @@
"url": "https://github.com/status-im/contracts/issues"
},
"homepage": "https://github.com/status-im/contracts#readme",
"devDependencies": {},
"devDependencies": {
"babel-eslint": "^8.2.6",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-stage-2": "^6.24.1",
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-react": "^7.10.0",
"eslint-plugin-standard": "^3.1.0"
},
"dependencies": {
"react": "^16.3.2",
"react-bootstrap": "^0.32.1",