From 03cfa4bf687eeedbea917c8f766dfb67f0ac5f9d Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 16 May 2018 10:20:47 -0400 Subject: [PATCH] Simplifying message format --- app/components/approveandcallgasrelayed.js | 5 ++++- app/components/callgasrelayed.js | 5 ++++- gas-relayer/src/message-processor.js | 24 ++++++++++++++++------ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/components/approveandcallgasrelayed.js b/app/components/approveandcallgasrelayed.js index c851774..4f9040d 100644 --- a/app/components/approveandcallgasrelayed.js +++ b/app/components/approveandcallgasrelayed.js @@ -97,7 +97,10 @@ class ApproveAndCallGasRelayed extends React.Component { powTarget: 1, powTime: 20, topic: this.state.topic, - payload: this.state.address + funCall.slice(2) + payload: this.props.web3.utils.toHex({ + 'address': this.state.address, + 'encodedFunctionCall': funCall + }) }; console.log(msgObj); diff --git a/app/components/callgasrelayed.js b/app/components/callgasrelayed.js index 01ea89b..1406bef 100644 --- a/app/components/callgasrelayed.js +++ b/app/components/callgasrelayed.js @@ -97,7 +97,10 @@ class CallGasRelayed extends React.Component { powTarget: 1, powTime: 20, topic: this.state.topic, - payload: this.state.address + funCall.slice(2) + payload: this.props.web3.utils.toHex({ + 'address': this.state.address, + 'encodedFunctionCall': funCall + }) }; console.log(msgObj); diff --git a/gas-relayer/src/message-processor.js b/gas-relayer/src/message-processor.js index beb39d5..50225b9 100644 --- a/gas-relayer/src/message-processor.js +++ b/gas-relayer/src/message-processor.js @@ -69,12 +69,24 @@ class MessageProcessor { } _extractInput(message){ - return { - address: message.payload.slice(0, 42), - functionName: '0x' + message.payload.slice(42, 50), - functionParameters: '0x' + message.payload.slice(50), - payload: '0x' + message.payload.slice(42) + let obj = { + address: null, + functionName: null, + functionParameters: null, + payload: null + }; + + try { + let parsedObj = JSON.parse(this.web3.utils.toAscii(message.payload)); + obj.address = parsedObj.address; + obj.functionName = parsedObj.encodedFunctionCall.slice(0, 8); + obj.functionParameters = "0x" + parsedObj.encodedFunctionCall.slice(8); + obj.payload = parsedObj.encodedFunctionCall; + } catch(err){ + console.err("Couldn't parse " + message); } + + return obj; } _obtainParametersFunc(contract, input){ @@ -129,7 +141,7 @@ class MessageProcessor { console.error(error); } else { - let input = this._extractInput(message); + let input = JSON.parse(web3.utils.toAscii(message)); const contract = this.settings.getContractByTopic(message.topic);