Updating IdentityGasRelay

This commit is contained in:
Richard Ramos 2018-05-16 11:59:28 -04:00
parent b9b1197c8d
commit 8c3933e4c3
1 changed files with 13 additions and 17 deletions

View File

@ -1,6 +1,6 @@
pragma solidity ^0.4.21; pragma solidity ^0.4.21;
import "./IdentityKernel.sol"; import "./Identity.sol";
import "../common/MessageSigned.sol"; import "../common/MessageSigned.sol";
import "../token/ERC20Token.sol"; import "../token/ERC20Token.sol";
@ -9,7 +9,7 @@ import "../token/ERC20Token.sol";
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH) * @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
* @notice enables economic abstraction for Identity * @notice enables economic abstraction for Identity
*/ */
contract IdentityGasRelay is IdentityKernel, MessageSigned { contract IdentityGasRelay is Identity {
bytes4 public constant MSG_CALL_PREFIX = bytes4(keccak256("callGasRelay(address,uint256,bytes32,uint256,uint256,address)")); bytes4 public constant MSG_CALL_PREFIX = bytes4(keccak256("callGasRelay(address,uint256,bytes32,uint256,uint256,address)"));
bytes4 public constant MSG_DEPLOY_PREFIX = bytes4(keccak256("deployGasRelay(uint256,bytes32,uint256,uint256,address)")); bytes4 public constant MSG_DEPLOY_PREFIX = bytes4(keccak256("deployGasRelay(uint256,bytes32,uint256,uint256,address)"));
@ -27,7 +27,7 @@ contract IdentityGasRelay is IdentityKernel, MessageSigned {
* @param _gasToken token being used for paying `msg.sender` * @param _gasToken token being used for paying `msg.sender`
* @param _messageSignatures rsv concatenated ethereum signed message signatures required * @param _messageSignatures rsv concatenated ethereum signed message signatures required
*/ */
modifier gasRelayed ( modifier executeGasRelayed (
bytes32 _messageHash, bytes32 _messageHash,
uint256 _requiredPurpose, uint256 _requiredPurpose,
uint _nonce, uint _nonce,
@ -56,11 +56,6 @@ contract IdentityGasRelay is IdentityKernel, MessageSigned {
//executes transaction //executes transaction
_; _;
//signal execution to event listeners
emit ExecutedGasRelayed(
_messageHash
);
//refund gas used using contract held ERC20 tokens or ETH //refund gas used using contract held ERC20 tokens or ETH
if (_gasPrice > 0) { if (_gasPrice > 0) {
uint256 _amount = 21000 + (startGas - gasleft()); uint256 _amount = 21000 + (startGas - gasleft());
@ -96,7 +91,7 @@ contract IdentityGasRelay is IdentityKernel, MessageSigned {
bytes _messageSignatures bytes _messageSignatures
) )
external external
gasRelayed( executeGasRelayed(
callGasRelayHash( callGasRelayHash(
_to, _to,
_value, _value,
@ -115,7 +110,7 @@ contract IdentityGasRelay is IdentityKernel, MessageSigned {
) )
returns (bool success) returns (bool success)
{ {
success = _to.call.value(_value)(_data); success = _commitCall(_nonce, _to, _value, _data);
} }
@ -140,7 +135,7 @@ contract IdentityGasRelay is IdentityKernel, MessageSigned {
bytes _messageSignatures bytes _messageSignatures
) )
external external
gasRelayed( executeGasRelayed(
deployGasRelayHash( deployGasRelayHash(
_value, _value,
keccak256(_data), keccak256(_data),
@ -158,6 +153,7 @@ contract IdentityGasRelay is IdentityKernel, MessageSigned {
) )
returns(address deployedAddress) returns(address deployedAddress)
{ {
nonce++;
deployedAddress = doCreate(_value, _data); deployedAddress = doCreate(_value, _data);
emit ContractDeployed(deployedAddress); emit ContractDeployed(deployedAddress);
} }
@ -170,7 +166,7 @@ contract IdentityGasRelay is IdentityKernel, MessageSigned {
* fixes race condition in double transaction for ERC20. * fixes race condition in double transaction for ERC20.
* @param _baseToken token approved for `_to` * @param _baseToken token approved for `_to`
* @param _to destination of call * @param _to destination of call
* @param _value call value (ether) * @param _value call value (in `_baseToken`)
* @param _data call data * @param _data call data
* @param _nonce current identity nonce * @param _nonce current identity nonce
* @param _gasPrice price in SNT paid back to msg.sender for each gas unit used * @param _gasPrice price in SNT paid back to msg.sender for each gas unit used
@ -190,7 +186,7 @@ contract IdentityGasRelay is IdentityKernel, MessageSigned {
bytes _messageSignatures bytes _messageSignatures
) )
external external
gasRelayed( executeGasRelayed(
approveAndCallGasRelayHash( approveAndCallGasRelayHash(
_baseToken, _baseToken,
_to, _to,
@ -212,9 +208,9 @@ contract IdentityGasRelay is IdentityKernel, MessageSigned {
{ {
require(_baseToken != address(0)); //_baseToken should be something! require(_baseToken != address(0)); //_baseToken should be something!
require(_to != address(this)); //no management with approveAndCall require(_to != address(this)); //no management with approveAndCall
require(_to != address(0)); //need valid destination
ERC20Token(_baseToken).approve(_to, _value); ERC20Token(_baseToken).approve(_to, _value);
success = _to.call(_data); success = _commitCall(_nonce, _to, 0, _data);
} }
/** /**
@ -245,7 +241,7 @@ contract IdentityGasRelay is IdentityKernel, MessageSigned {
i i
); );
require(_currentKey > _lastKey); //assert keys are different require(_currentKey > _lastKey); //assert keys are different
require(isKeyPurpose(_currentKey, _requiredKey)); require(keyHasPurpose(_currentKey, _requiredKey));
_lastKey = _currentKey; _lastKey = _currentKey;
} }
return true; return true;