Removing gas token from approveAndCallGasRelayed

This commit is contained in:
Richard Ramos 2018-12-03 09:24:55 -04:00
parent 8e48afde06
commit c650f52d9f
8 changed files with 170 additions and 157 deletions

View File

@ -46,7 +46,8 @@ const gasPrice = 1000000000000; // In wei equivalent to the used token
const s = new StatusGasRelayer.AvailableRelayers(Contracts.Identity, identityAddress, accountAddress)
.setRelayersSymKeyID(skid)
.setAsymmetricKeyID(kid)
.setGas(gasToken, gasPrice);
.setGasToken(gasToken)
.setGas(gasPrice);
await s.post(web3);
```
@ -75,7 +76,8 @@ try {
const s = new StatusGasRelayer.Identity(identityAddress, accountAddress)
.setContractFunction(Functions.Identity.call)
.setTransaction(to, value, data) // 'value' is in wei, and 'data' must be a hex string
.setGas(gasToken, gasPrice, gasLimit)
.setGasToken(gasToken)
.setGas(gasPrice, gasMinimal)
.setRelayer(relayer)
.setAsymmetricKeyID(kid);
@ -94,7 +96,8 @@ try {
.setContractFunction(Functions.Identity.approveAndCall)
.setTransaction(to, value, data)
.setBaseToken(baseToken)
.setGas(gasToken, gasPrice, gasLimit)
.setGas(gasPrice, gasMinimal)
.setGasToken(SNT_Address)
.setRelayer(relayer)
.setAsymmetricKeyID(kid);

View File

@ -78,7 +78,8 @@ class ApproveAndCallGasRelayed extends Component {
.setContractFunction(Functions.Identity.approveAndCall)
.setTransaction(this.state.to, this.state.value, this.state.data)
.setBaseToken(this.state.baseToken)
.setGas(this.state.gasToken, this.state.gasPrice, this.state.gasMinimal);
.setGasToken(STT.options.address)
.setGas(this.state.gasPrice, this.state.gasMinimal);
const signature = await s.sign(web3);
@ -103,7 +104,8 @@ class ApproveAndCallGasRelayed extends Component {
const s = new StatusGasRelayer.AvailableRelayers(Contracts.Identity, this.props.identityAddress, web3.eth.defaultAccount)
.setRelayersSymKeyID(skid)
.setAsymmetricKeyID(kid)
.setGas(this.state.gasToken, this.state.gasPrice);
.setGasToken(STT.options.address)
.setGas(this.state.gasPrice);
await s.post(web3);
console.log("Message sent");
@ -137,11 +139,14 @@ class ApproveAndCallGasRelayed extends Component {
try {
console.log(web3.eth.defaultAccount);
const s = new StatusGasRelayer.Identity(this.props.identityAddress, web3.eth.defaultAccount)
.setContractFunction(Functions.Identity.approveAndCall)
.setTransaction(this.state.to, this.state.value, this.state.data)
.setBaseToken(this.state.baseToken)
.setGas(this.state.gasToken, this.state.gasPrice, this.state.gasMinimal)
.setGasToken(STT.options.address)
.setGas(this.state.gasPrice, this.state.gasMinimal)
.setRelayer(relayer)
.setAsymmetricKeyID(kid);
@ -245,27 +250,7 @@ class ApproveAndCallGasRelayed extends Component {
}}
/>
</Grid>
<Grid item xs={6}>
<TextField
id="gasToken"
label="Gas Token"
value={this.state.gasToken}
onChange={this.handleChange('gasToken')}
margin="normal"
fullWidth
select
SelectProps={{
native: true
}}
>
<option key={STT.options.address} value={STT.options.address}>
{STT.options.address} (STT)
</option>
<option key="0x0000000000000000000000000000000000000000" value="0x0000000000000000000000000000000000000000">
0x0000000000000000000000000000000000000000 (ETH)
</option>
</TextField>
</Grid>
<Grid item xs={2}>
<TextField
id="gasPrice"

View File

@ -44,6 +44,9 @@ class Body extends Component {
const web3js = new Web3('ws://localhost:8546');
web3js.shh.setMinPoW(0.002).then(res => {
console.log("Min PoW set: " + res);
})
// Default for devenv
web3js.eth.net.getId().then(netId => {

View File

@ -44,6 +44,10 @@ class Body extends Component {
const web3js = new Web3('ws://localhost:8546');
web3js.shh.setMinPoW(0.002).then(res => {
console.log("Min PoW set: " + res);
})
// Default for devenv
web3js.eth.net.getId().then(netId => {

View File

@ -83,7 +83,8 @@ class CallGasRelayed extends Component {
const s = new StatusGasRelayer.Identity(this.props.identityAddress, web3.eth.defaultAccount)
.setContractFunction(Functions.Identity.call)
.setTransaction(this.state.to, this.state.value, this.state.data)
.setGas(this.state.gasToken, this.state.gasPrice, this.state.gasMinimal);
.setGasToken(this.state.gasToken)
.setGas(this.state.gasPrice, this.state.gasMinimal);
const signature = await s.sign(web3);
@ -108,7 +109,9 @@ class CallGasRelayed extends Component {
const s = new StatusGasRelayer.AvailableRelayers(Contracts.Identity, this.props.identityAddress, web3.eth.defaultAccount)
.setRelayersSymKeyID(skid)
.setAsymmetricKeyID(kid)
.setGas(this.state.gasToken, this.state.gasPrice);
.setGasToken(this.state.gasToken)
.setGas(this.state.gasPrice);
await s.post(web3);
console.log("Message sent");
@ -146,7 +149,8 @@ class CallGasRelayed extends Component {
const s = new StatusGasRelayer.Identity(this.props.identityAddress, web3.eth.defaultAccount)
.setContractFunction(Functions.Identity.call)
.setTransaction(this.state.to, this.state.value, this.state.data)
.setGas(this.state.gasToken, this.state.gasPrice, this.state.gasMinimal)
.setGasToken(this.state.gasToken)
.setGas(this.state.gasPrice, this.state.gasMinimal)
.setRelayer(relayer)
.setAsymmetricKeyID(kid);

View File

@ -111,7 +111,8 @@ class Execute extends Component {
const s = new StatusGasRelayer.AvailableRelayers(Contracts.SNT, SNTController.options.address, this.state.account)
.setRelayersSymKeyID(skid)
.setAsymmetricKeyID(kid)
.setGas(STT.options.address, this.state.gasPrice);
.setGasToken(STT.options.address)
.setGas(this.state.gasPrice);
await s.post(web3);
console.log("Message sent");

View File

@ -112,7 +112,8 @@ class TransferSNT extends Component {
const s = new StatusGasRelayer.AvailableRelayers(Contracts.SNT, SNTController.options.address, this.state.account)
.setRelayersSymKeyID(skid)
.setAsymmetricKeyID(kid)
.setGas(STT.options.address, this.state.gasPrice);
.setGasToken(STT.options.address)
.setGas(this.state.gasPrice);
await s.post(web3);
console.log("Message sent");

View File

@ -189,8 +189,12 @@ class IdentityGasRelayedAction extends Action {
return this;
}
setGas(token, price, gasMinimal){
setGasToken(token){
this.gasToken = token;
return this;
}
setGas(price, gasMinimal){
this.gasPrice = price;
this.gasMinimal = gasMinimal;
return this;
@ -243,13 +247,14 @@ class IdentityGasRelayedAction extends Action {
).call();
break;
case Functions.Identity.approveAndCall:
hashedMessage = await contract.methods.deployGasRelayHash(
hashedMessage = await contract.methods.approveAndCallGasRelayHash(
this.baseToken,
this.to,
this.value,
this.data == "0x" ? emptyBytesSha : web3.utils.soliditySha3({t: 'bytes', v: this.data}),
nonce,
this.gasPrice,
this.gasMinimal,
this.gasToken
this.gasMinimal
).call();
break;
default:
@ -295,7 +300,6 @@ class IdentityGasRelayedAction extends Action {
this.nonce,
this.gasPrice,
this.gasMinimal,
this.gasToken,
this.signature
]);
break;
@ -443,7 +447,19 @@ class AvailableRelayersAction extends Action {
return this;
}
setGasToken(token){
this.gasToken = token;
return this;
}
setGas(price, gasMinimal){
this.gasPrice = price;
this.gasMinimal = gasMinimal;
return this;
}
_getMessage = web3 => {
console.log(this);
return {
contract: this.contractAddress,
address: this.accountAddress || web3.eth.defaultAccount,
@ -620,47 +636,46 @@ const identityGasRelayABI = [
{
"constant": true,
"inputs": [
{
{
"name": "_to",
"type": "address"
},
{
},
{
"name": "_value",
"type": "uint256"
},
{
},
{
"name": "_dataHash",
"type": "bytes32"
},
{
},
{
"name": "_nonce",
"type": "uint256"
},
{
},
{
"name": "_gasPrice",
"type": "uint256"
},
{
},
{
"name": "_gasMinimal",
"type": "uint256"
},
{
},
{
"name": "_gasToken",
"type": "address"
}
}
],
"name": "callGasRelayHash",
"outputs": [
{
{
"name": "_callGasRelayHash",
"type": "bytes32"
}
}
],
"payable": false,
"stateMutability": "view",
"type": "function",
"signature": "0xe27e2e5c"
},
"type": "function"
},
{
"constant": true,
"inputs": [],
@ -677,55 +692,54 @@ const identityGasRelayABI = [
"signature": "0xaffed0e0"
},
{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
},
{
"name": "_data",
"type": "bytes"
},
{
"name": "_nonce",
"type": "uint256"
},
{
"name": "_gasPrice",
"type": "uint256"
},
{
"name": "_gasMinimal",
"type": "uint256"
},
{
"name": "_gasToken",
"type": "address"
},
{
"name": "_messageSignatures",
"type": "bytes"
}
],
"name": "callGasRelayed",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function",
"signature": "0xfd0dded5"
},
{
"constant": false,
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
},
{
"name": "_data",
"type": "bytes"
},
{
"name": "_nonce",
"type": "uint256"
},
{
"name": "_gasPrice",
"type": "uint256"
},
{
"name": "_gasMinimal",
"type": "uint256"
},
{
"name": "_gasToken",
"type": "address"
},
{
"name": "_messageSignatures",
"type": "bytes"
}
],
"name": "callGasRelayed",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_baseToken",
@ -735,50 +749,6 @@ const identityGasRelayABI = [
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
},
{
"name": "_data",
"type": "bytes"
},
{
"name": "_nonce",
"type": "uint256"
},
{
"name": "_gasPrice",
"type": "uint256"
},
{
"name": "_gasMinimal",
"type": "uint256"
},
{
"name": "_gasToken",
"type": "address"
},
{
"name": "_messageSignatures",
"type": "bytes"
}
],
"name": "approveAndCallGasRelayed",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function",
"signature": "0x59f4ac61"
},
{
"constant": true,
"inputs": [
{
"name": "_value",
"type": "uint256"
@ -798,13 +768,9 @@ const identityGasRelayABI = [
{
"name": "_gasMinimal",
"type": "uint256"
},
{
"name": "_gasToken",
"type": "address"
}
],
"name": "deployGasRelayHash",
"name": "approveAndCallGasRelayHash",
"outputs": [
{
"name": "_callGasRelayHash",
@ -813,9 +779,55 @@ const identityGasRelayABI = [
],
"payable": false,
"stateMutability": "view",
"type": "function",
"signature": "0x86962d85"
}
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_baseToken",
"type": "address"
},
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
},
{
"name": "_data",
"type": "bytes"
},
{
"name": "_nonce",
"type": "uint256"
},
{
"name": "_gasPrice",
"type": "uint256"
},
{
"name": "_gasMinimal",
"type": "uint256"
},
{
"name": "_messageSignatures",
"type": "bytes"
}
],
"name": "approveAndCallGasRelayed",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
];
export default StatusGasRelayer;