Created
October 2, 2018 16:04
-
-
Save Perseverance/b98f2c637168f2aaac259ab8b67afa4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract IdentityContract { | |
uint256 public nonce; | |
function getSigner(bytes32 raw, bytes sig) public view returns(address signer) { | |
return ECTools.prefixedRecover(raw, sig); | |
} | |
modifier onlyValidSignature(uint256 relayerReward, address target, uint256 value, bytes data, bytes dataHashSignature) { | |
bytes32 dataHash = keccak256(abi.encodePacked(data, relayerReward, value, target, nonce)); | |
address signer = getSigner(dataHash, dataHashSignature); | |
require(isSigner[signer]); | |
emit LogActionAuthorised(nonce, signer); | |
_; | |
} | |
/** | |
* @dev executes a transaction only if it is formatted and signed by the owner of this. Anyone can call execute. Nonce introduced as anti replay attack mechanism. | |
* | |
* @param relayerReward - the value to be sent back to the relayer | |
* @param target - the contract to be called | |
* @param value - the value to be sent to the target | |
* @param data - the data to be sent to be target | |
* @param dataHashSignature - signed bytes of the keccak256 of target, nonce, value and data keccak256(target, nonce, value, data) | |
*/ | |
function execute(address target, uint256 relayerReward, uint256 value, bytes data, bytes dataHashSignature) public payable onlyValidSignature(relayerReward, target, value, data, dataHashSignature) returns (bool) { | |
// solium-disable-next-line security/no-call-value | |
nonce++; | |
require(target.call.value(value)(data)); | |
emit LogActionExecuted(nonce-1, target, relayerReward, value, data, dataHashSignature); | |
require(rewardMsgSender(relayerReward)); | |
return true; | |
} | |
function rewardMsgSender(uint256 reward) internal returns(bool) { | |
// Override this to make your reward logic work | |
msg.sender.transfer(reward); | |
emit LogRewardsPaid(nonce-1, msg.sender, reward, deployer, 0x0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment