mirror of
https://github.com/status-im/snt-gas-relay.git
synced 2025-02-27 05:00:32 +00:00
Adding logic to obtain signatures
This commit is contained in:
parent
3f56fd4676
commit
69e8167499
@ -70,7 +70,7 @@ class CallGasRelayed extends Component {
|
||||
});
|
||||
};
|
||||
|
||||
sign = (event) => {
|
||||
sign = async (event) => {
|
||||
if(event) event.preventDefault();
|
||||
|
||||
this.setState({
|
||||
@ -78,25 +78,15 @@ class CallGasRelayed extends Component {
|
||||
transactionError: ''
|
||||
});
|
||||
|
||||
IdentityGasRelay.options.address = this.props.identityAddress;
|
||||
|
||||
try {
|
||||
IdentityGasRelay.methods.callGasRelayHash(
|
||||
this.state.to,
|
||||
this.state.value,
|
||||
web3.utils.soliditySha3({t: 'bytes', v: this.state.data}),
|
||||
this.props.nonce,
|
||||
this.state.gasPrice,
|
||||
this.state.gasLimit,
|
||||
this.state.gasToken
|
||||
)
|
||||
.call()
|
||||
.then(message => {
|
||||
return web3.eth.sign(message, web3.eth.defaultAccount);
|
||||
})
|
||||
.then(signature => {
|
||||
|
||||
const s = new StatusGasRelayer.Identity(this.props.identityAddress, web3.eth.defaultAccount)
|
||||
.setTransaction(this.state.to, this.state.value, this.state.data)
|
||||
.setGas(this.state.gasToken, this.state.gasPrice, this.state.gasLimit);
|
||||
|
||||
const signature = await s.sign(web3);
|
||||
|
||||
this.setState({signature});
|
||||
});
|
||||
} catch(error){
|
||||
this.setState({transactionError: error.message});
|
||||
}
|
||||
|
@ -8,12 +8,12 @@ export const Functions = {
|
||||
'call': 'callGasRelayed',
|
||||
'approveAndCall': 'approveAndCallGasRelayed'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const Actions = {
|
||||
'Availability': 'availability',
|
||||
'Transaction': 'transaction'
|
||||
}
|
||||
};
|
||||
|
||||
const relayerSymmmetricKeyID = "0xd0d905c1c62b810b787141430417caf2b3f54cffadb395b7bb39fdeb8f17266b";
|
||||
|
||||
@ -65,16 +65,23 @@ class StatusGasRelayer {
|
||||
payload: this.web3.utils.toHex(this.message)
|
||||
};
|
||||
|
||||
return await web3.shh.post(sendOptions);
|
||||
const msgId = await this.web3.shh.post(sendOptions);
|
||||
return msgId;
|
||||
}
|
||||
|
||||
validateBuild = (build) => {
|
||||
return (String(build.constructor) === String(StatusGasRelayer.AvailableRelayers));
|
||||
return (String(build.constructor) === String(StatusGasRelayer.AvailableRelayers) ||
|
||||
String(build.constructor) === String(StatusGasRelayer.Identity)
|
||||
);
|
||||
}
|
||||
|
||||
static get AvailableRelayers() {
|
||||
return AvailableRelayersAction;
|
||||
}
|
||||
|
||||
static get Identity() {
|
||||
return IdentityGasRelayedAction;
|
||||
}
|
||||
}
|
||||
|
||||
class Action {
|
||||
@ -120,14 +127,35 @@ class IdentityGasRelayedAction extends Action {
|
||||
return this;
|
||||
}
|
||||
|
||||
getNonce = async (web3) => {
|
||||
const contract = web3.eth.contract(identityGasRelayABI, this.contractAddress);
|
||||
_nonce = async(contract) => {
|
||||
const nonce = await contract.methods.nonce().call();
|
||||
return nonce;
|
||||
}
|
||||
|
||||
sign = (web3) => {
|
||||
getNonce = async (web3) => {
|
||||
const contract = new web3.eth.Contract(identityGasRelayABI, this.contractAddress);
|
||||
const nonce = await this._nonce(contract);
|
||||
return nonce;
|
||||
}
|
||||
|
||||
sign = async (web3) => {
|
||||
const contract = new web3.eth.Contract(identityGasRelayABI, this.contractAddress);
|
||||
const nonce = await this._nonce(contract);
|
||||
|
||||
// TODO: this depends of the operation to execute
|
||||
const hashedMessage = await contract.methods.callGasRelayHash(
|
||||
this.to,
|
||||
this.value,
|
||||
web3.utils.soliditySha3({t: 'bytes', v: this.data}),
|
||||
nonce,
|
||||
this.gasPrice,
|
||||
this.gasLimit,
|
||||
this.gasToken
|
||||
).call();
|
||||
|
||||
const signature = await web3.eth.sign(hashedMessage, this.accountAddress);
|
||||
|
||||
return signature;
|
||||
}
|
||||
|
||||
_getMessage = async web3 => {
|
||||
@ -166,8 +194,6 @@ class AvailableRelayersAction extends Action {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const identityGasRelayABI = [
|
||||
{
|
||||
"constant": true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user