Skip to content

Instantly share code, notes, and snippets.

@shrugs
Created August 29, 2018 23:27
Show Gist options
  • Save shrugs/92f1a268fe0fd0d21c39efbb09c11875 to your computer and use it in GitHub Desktop.
Save shrugs/92f1a268fe0fd0d21c39efbb09c11875 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.24;
library Flags {
function makeFlagSet(bytes8[] _flags)
internal
pure
returns (bytes8)
{
bytes8 flagSet;
for (uint8 i = 0; i < _flags.length; i++) {
flagSet = addFlag(flagSet, _flags[i]);
}
return flagSet;
}
function hasFlag(bytes8 _field, bytes8 _flag)
internal
pure
returns (bool)
{
return _flagIntersection(_field, _flag) != 0;
}
function addFlag(bytes8 _field, bytes8 _flag)
internal
pure
returns (bytes8)
{
return _field | _flag;
}
function removeFlag(bytes8 _field, bytes8 _flag)
internal
pure
returns (bytes8)
{
return _field & ~_flag;
}
function _flagIntersection(bytes8 _field, bytes8 _flags)
internal
pure
returns (bytes8)
{
return (_field & _flags);
}
}
@shrugs
Copy link
Author

shrugs commented Aug 29, 2018

  bytes8 constant public PURPOSE_MANAGEMENT = bytes8(1);  // [...] 00000000 00000000 00000000 00000001
  bytes8 constant public PURPOSE_ACTION     = bytes8(2);  // [...] 00000000 00000000 00000000 00000010
  bytes8 constant public PURPOSE_CLAIM      = bytes8(4);  // [...] 00000000 00000000 00000000 00000100
  bytes8 constant public PURPOSE_ENCRYPTION = bytes8(8);  // [...] 00000000 00000000 00000000 00001000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment