fix: calculate function signatures automatically (#599)

* fix: calculate function signatures automatically
* fix: code review
This commit is contained in:
Richard Ramos 2020-01-09 16:08:15 -04:00 committed by GitHub
parent 773b6808ad
commit a5e332ac45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 11 deletions

View File

@ -20,7 +20,7 @@ contract EscrowRelay is RelayRecipient, Ownable {
mapping(address => uint) public lastActivity;
bytes4 constant CREATE_SIGNATURE = bytes4(keccak256("createEscrow(uint256,uint256,uint256,string,string,string)"));
bytes4 constant CREATE_SIGNATURE = bytes4(keccak256("createEscrow(uint256,uint256,uint256,address,string,string,string)"));
bytes4 constant PAY_SIGNATURE = bytes4(keccak256("pay(uint256)"));
bytes4 constant CANCEL_SIGNATURE = bytes4(keccak256("cancel(uint256)"));
bytes4 constant OPEN_CASE_SIGNATURE = bytes4(keccak256("openCase(uint256,uint8)"));

View File

@ -96,6 +96,7 @@
"redux-saga": "^0.16.2",
"sass-loader": "^7.1.0",
"staking-pool": "^0.0.1",
"strip-hex-prefix": "^1.0.0",
"tabookey-gasless": "^0.4.1",
"web3": "1.2.0"
},

View File

@ -1,3 +1,4 @@
/* global web3 */
import Escrow from '../embarkArtifacts/contracts/Escrow';
import EscrowRelay from '../embarkArtifacts/contracts/EscrowRelay';
import EscrowProxy from '../embarkArtifacts/contracts/EscrowProxy';
@ -7,17 +8,20 @@ import SNT from '../embarkArtifacts/contracts/SNT';
import {checkNotEnoughETH} from './utils/transaction';
import {addressCompare, zeroAddress} from './utils/address';
import {canRelay} from './features/escrow/helpers';
import stripHexPrefix from 'strip-hex-prefix';
Escrow.options.address = EscrowProxy.options.address;
MetadataStore.options.address = MetadataStoreProxy.options.address;
const VALID_OPERATIONS = {
"cancel(uint256)": "40e58ee5",
"createEscrow(uint256,uint256,uint256,string,string,string)":"56a9480a",
"openCase(uint256,uint8)": "267b4cc3",
"pay(uint256)": "c290d691",
"rateTransaction(uint256,uint256)":"79347b06"
};
const CREATE_ESCROW = "createEscrow(uint256,uint256,uint256,address,string,string,string)";
const RATE_TRANSACTION = "rateTransaction(uint256,uint256)";
const CANCEL_ESCROW = "cancel(uint256)";
const OPEN_CASE = "openCase(uint256,uint8)";
const PAY_ESCROW = "pay(uint256)";
const VALID_OPERATIONS = [CREATE_ESCROW, CANCEL_ESCROW, OPEN_CASE, PAY_ESCROW, RATE_TRANSACTION]
.map(x => ({[x]: stripHexPrefix(web3.utils.soliditySha3(x)).substring(0,8)}))
.reduce((curr,accum) => Object.assign(curr, accum), {});
class Provider {
constructor(relayProvider) {
@ -53,9 +57,9 @@ class Provider {
const balance = await web3.eth.getBalance(web3.eth.defaultAccount);
const gasPrice = await web3.eth.getGasPrice();
if (checkNotEnoughETH(gasPrice, balance) || operation === VALID_OPERATIONS["rateTransaction(uint256,uint256)"]) {
if (checkNotEnoughETH(gasPrice, balance) || operation === VALID_OPERATIONS[RATE_TRANSACTION]) {
if(operation === VALID_OPERATIONS["createEscrow(uint256,uint256,uint256,string,string,string)"]){
if(operation === VALID_OPERATIONS[CREATE_ESCROW]){
const isEthOrSNT = await this.isEthOrSNT(web3, payload.params[0].data);
const lastActivity = await EscrowRelay.methods.lastActivity(web3.eth.defaultAccount).call();
if(!isEthOrSNT || !canRelay(parseInt(lastActivity + '000', 10))) {

View File

@ -17663,7 +17663,7 @@ strip-eof@^1.0.0:
resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf"
integrity sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=
strip-hex-prefix@1.0.0:
strip-hex-prefix@1.0.0, strip-hex-prefix@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/strip-hex-prefix/-/strip-hex-prefix-1.0.0.tgz#0c5f155fef1151373377de9dbb588da05500e36f"
integrity sha1-DF8VX+8RUTczd96du1iNoFUA428=