Forked from VladLupashevskyi/gist:84f18eabb1e4afadf572cf92af3e7e7f
Last active
November 23, 2020 21:02
-
-
Save kavu/5f20dca78989833a201a9a5492927f49 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
pragma solidity 0.5.5; | |
contract TxPermission { | |
/// Allowed transaction types mask | |
uint32 constant None = 0; | |
uint32 constant All = 0xffffffff; | |
uint32 constant Basic = 0x01; | |
uint32 constant Call = 0x02; | |
uint32 constant Create = 0x04; | |
uint32 constant Private = 0x08; | |
/// Contract name | |
function contractName() public pure returns (string memory) { | |
return "TX_PERMISSION_CONTRACT"; | |
} | |
/// Contract name hash | |
function contractNameHash() public pure returns (bytes32) { | |
return keccak256(abi.encodePacked(contractName())); | |
} | |
/// Contract version | |
function contractVersion() public pure returns (uint256) { | |
return 2; | |
} | |
/* | |
* Allowed transaction types | |
* | |
* Returns: | |
* - uint32 - set of allowed transactions for #'sender' depending on tx #'to' address | |
* and value in wei. | |
* - bool - if true is returned the same permissions will be applied from the same #'sender' | |
* without calling this contract again. | |
* | |
* In case of contract creation #'to' address equals to zero-address | |
* | |
* Result is represented as set of flags: | |
* - 0x01 - basic transaction (e.g. ether transferring to user wallet) | |
* - 0x02 - contract call | |
* - 0x04 - contract creation | |
* - 0x08 - private transaction | |
* | |
* @param sender Transaction sender address | |
* @param to Transaction recepient address | |
* @param value Value in wei for transaction | |
* | |
*/ | |
function allowedTxTypes(address sender, address to, uint value) public pure returns (uint32, bool) { | |
if (sender == 0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf) return (All, true); // Secret: 0x00..01 | |
if (sender == 0x2B5AD5c4795c026514f8317c7a215E218DcCD6cF) return (Basic | Call, true); // Secret: 0x00..02 | |
if (sender == 0x6813Eb9362372EEF6200f3b1dbC3f819671cBA69) return (Basic, true); // Secret: 0x00..03 | |
if ((sender == 0xe1AB8145F7E55DC933d51a18c793F901A3A0b276) && (value == 0)) return (All, false); // Secret: 0x00..05 | |
if ((sender == 0xE57bFE9F44b819898F47BF37E5AF72a0783e1141) && (to == 0xd41c057fd1c78805AAC12B0A94a405c0461A6FBb)) return (Basic, false); // Secret: 0x00..06 | |
if ((sender == 0xd41c057fd1c78805AAC12B0A94a405c0461A6FBb) && (to == 0xE57bFE9F44b819898F47BF37E5AF72a0783e1141) && (value == 0)) return (All, false); // Secret: 0x00..07 | |
return (None, true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment