Skip to content

Instantly share code, notes, and snippets.

@VladLupashevskyi
Last active March 23, 2019 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save VladLupashevskyi/84f18eabb1e4afadf572cf92af3e7e7f to your computer and use it in GitHub Desktop.
Save VladLupashevskyi/84f18eabb1e4afadf572cf92af3e7e7f to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.20;
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 constant returns (string) {
return "TX_PERMISSION_CONTRACT";
}
/// Contract name hash
function contractNameHash() public constant returns (bytes32) {
return keccak256(contractName());
}
/// Contract version
function contractVersion() public constant 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 constant 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