fix convention

This commit is contained in:
Ricardo Guilherme Schmidt 2018-11-16 02:54:21 -02:00
parent 6378e81a00
commit cb79d4f3e6
No known key found for this signature in database
GPG Key ID: 3F95A3AD0B607030
1 changed files with 36 additions and 21 deletions

View File

@ -14,8 +14,12 @@ import "../token/MiniMeToken.sol";
contract SNTController is TokenController, Owned, MessageSigned { contract SNTController is TokenController, Owned, MessageSigned {
bytes4 public constant TRANSFER_PREFIX = bytes4(keccak256("transferSNT(address,uint256,uint256,uint256)")); bytes4 public constant TRANSFER_PREFIX = bytes4(
bytes4 public constant EXECUTE_PREFIX = bytes4(keccak256("executeGasRelayed(address,bytes,uint256,uint256,uint256)")); keccak256("transferSNT(address,uint256,uint256,uint256)")
);
bytes4 public constant EXECUTE_PREFIX = bytes4(
keccak256("executeGasRelayed(address,bytes,uint256,uint256,uint256)")
);
MiniMeToken public snt; MiniMeToken public snt;
mapping (address => uint256) public signNonce; mapping (address => uint256) public signNonce;
@ -31,7 +35,7 @@ contract SNTController is TokenController, Owned, MessageSigned {
* @param _owner Authority address * @param _owner Authority address
* @param _snt SNT token * @param _snt SNT token
*/ */
function SNTController(address _owner, address _snt) public { constructor(address _owner, address _snt) public {
owner = _owner; owner = _owner;
snt = MiniMeToken(_snt); snt = MiniMeToken(_snt);
} }
@ -64,10 +68,17 @@ contract SNTController is TokenController, Owned, MessageSigned {
); );
address msgSigner = recoverAddress(msgSigned, _signature); address msgSigner = recoverAddress(msgSigned, _signature);
require(signNonce[msgSigner] == _nonce); require(signNonce[msgSigner] == _nonce, "Bad nonce");
signNonce[msgSigner]++; signNonce[msgSigner]++;
if (snt.transferFrom(msgSigner, _to, _amount)) { if (snt.transferFrom(msgSigner, _to, _amount)) {
require(snt.transferFrom(msgSigner, msg.sender, (21000 + startGas-gasleft()) * _gasPrice)); require(
snt.transferFrom(
msgSigner,
msg.sender,
(21000 + startGas - gasleft()) * _gasPrice
),
"Gas transfer fail"
);
} }
} }
@ -91,7 +102,7 @@ contract SNTController is TokenController, Owned, MessageSigned {
external external
{ {
uint256 startGas = gasleft(); uint256 startGas = gasleft();
require(startGas >= _gasMinimal); require(startGas >= _gasMinimal, "Bad gas left");
bytes32 msgSigned = getSignHash( bytes32 msgSigned = getSignHash(
getExecuteGasRelayedHash( getExecuteGasRelayedHash(
_allowedContract, _allowedContract,
@ -103,7 +114,7 @@ contract SNTController is TokenController, Owned, MessageSigned {
); );
address msgSigner = recoverAddress(msgSigned, _signature); address msgSigner = recoverAddress(msgSigned, _signature);
require(signNonce[msgSigner] == _nonce); require(signNonce[msgSigner] == _nonce, "Bad nonce");
signNonce[msgSigner]++; signNonce[msgSigner]++;
bool success = _allowedContract.call(_data); bool success = _allowedContract.call(_data);
emit GasRelayedExecution(msgSigner, msgSigned, success); emit GasRelayedExecution(msgSigner, msgSigned, success);
@ -146,7 +157,7 @@ contract SNTController is TokenController, Owned, MessageSigned {
snt.claimTokens(_token); snt.claimTokens(_token);
} }
if (_token == 0x0) { if (_token == 0x0) {
address(owner).transfer(this.balance); address(owner).transfer(address(this).balance);
return; return;
} }
@ -194,13 +205,15 @@ contract SNTController is TokenController, Owned, MessageSigned {
returns (bytes32 execHash) returns (bytes32 execHash)
{ {
execHash = keccak256( execHash = keccak256(
address(this), abi.encodePacked(
EXECUTE_PREFIX, address(this),
_allowedContract, EXECUTE_PREFIX,
keccak256(_data), _allowedContract,
_nonce, keccak256(_data),
_gasPrice, _nonce,
_gasMinimal _gasPrice,
_gasMinimal
)
); );
} }
@ -222,12 +235,14 @@ contract SNTController is TokenController, Owned, MessageSigned {
returns (bytes32 txHash) returns (bytes32 txHash)
{ {
txHash = keccak256( txHash = keccak256(
address(this), abi.encodePacked(
TRANSFER_PREFIX, address(this),
_to, TRANSFER_PREFIX,
_amount, _to,
_nonce, _amount,
_gasPrice _nonce,
_gasPrice
)
); );
} }