Skip to content

Instantly share code, notes, and snippets.

@jim380
Created August 18, 2018 21:12
Show Gist options
  • Save jim380/4712a75506881ed151c206047e615d91 to your computer and use it in GitHub Desktop.
Save jim380/4712a75506881ed151c206047e615d91 to your computer and use it in GitHub Desktop.
transferProxy() snippet
function transferProxy(address _from, address _to, uint256 _value, uint256 _fee,
uint8 _v, bytes32 _r, bytes32 _s) public returns (bool){
if(balances[_from] < _fee + _value || _fee > _fee + _value) revert();
uint256 nonce = nonces[_from];
bytes32 h = keccak256(_from,_to,_value,_fee,nonce);
if(_from != ecrecover(h,_v,_r,_s)) revert();
if(balances[_to] + _value < balances[_to]
|| balances[msg.sender] + _fee < balances[msg.sender]) revert();
balances[_to] += _value;
emit Transfer(_from, _to, _value);
balances[msg.sender] += _fee;
emit Transfer(_from, msg.sender, _fee);
balances[_from] -= _value + _fee;
nonces[_from] = nonce + 1;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment