Skip to content

Commit

Permalink
Merge pull request #204 from varasev/issue-203
Browse files Browse the repository at this point in the history
(Feature) Add fields into ValidatorMetadata for companies as validators
  • Loading branch information
varasev committed Dec 13, 2018
2 parents 31fa251 + 389debd commit b0fc878
Show file tree
Hide file tree
Showing 7 changed files with 1,998 additions and 1,828 deletions.
76 changes: 67 additions & 9 deletions contracts/ValidatorMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
bytes32 internal constant PROXY_STORAGE = keccak256("proxyStorage");

bytes32 internal constant CONFIRMATIONS = "confirmations";
bytes32 internal constant CONTACT_EMAIL = "contactEmail";
bytes32 internal constant CREATED_DATE = "createdDate";
bytes32 internal constant EXPIRATION_DATE = "expirationDate";
bytes32 internal constant FIRST_NAME = "firstName";
bytes32 internal constant FULL_ADDRESS = "fullAddress";
bytes32 internal constant IS_COMPANY = "isCompany";
bytes32 internal constant LAST_NAME = "lastName";
bytes32 internal constant LICENSE_ID = "licenseId";
bytes32 internal constant MIN_THRESHOLD = "minThreshold";
Expand Down Expand Up @@ -102,7 +104,9 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
uint256 expirationDate,
uint256 createdDate,
uint256 updatedDate,
uint256 minThreshold
uint256 minThreshold,
bytes32 contactEmail,
bool isCompany
) {
return _validators(false, _miningKey);
}
Expand All @@ -117,7 +121,9 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
uint256 expirationDate,
uint256 createdDate,
uint256 updatedDate,
uint256 minThreshold
uint256 minThreshold,
bytes32 contactEmail,
bool isCompany
) {
return _validators(true, _miningKey);
}
Expand All @@ -134,7 +140,7 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
return boolStorage[INIT_METADATA_DISABLED];
}

function initMetadata( // used for migration
function initMetadata( // used for migration from v1.0 contracts
bytes32 _firstName,
bytes32 _lastName,
bytes32 _licenseId,
Expand Down Expand Up @@ -178,7 +184,9 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
string _fullAddress,
bytes32 _state,
bytes32 _zipcode,
uint256 _expirationDate
uint256 _expirationDate,
bytes32 _contactEmail,
bool _isCompany
)
public
onlyValidVotingKey(msg.sender)
Expand All @@ -199,6 +207,8 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
0,
getMinThreshold()
);
_setContactEmail(false, miningKey, _contactEmail);
_setIsCompany(false, miningKey, _isCompany);
emit MetadataCreated(miningKey);
}

Expand All @@ -209,11 +219,12 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
string _fullAddress,
bytes32 _state,
bytes32 _zipcode,
uint256 _expirationDate
uint256 _expirationDate,
bytes32 _contactEmail,
bool _isCompany
)
public
onlyValidVotingKey(msg.sender)
returns(bool)
{
address miningKey = _getKeysManager().getMiningKeyByVoting(msg.sender);
_setMetadata(
Expand All @@ -230,8 +241,9 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
getTime(),
_getMinThreshold(false, miningKey)
);
_setContactEmail(true, miningKey, _contactEmail);
_setIsCompany(true, miningKey, _isCompany);
emit ChangeRequestInitiated(miningKey);
return true;
}

function cancelPendingChange() public onlyValidVotingKey(msg.sender) returns(bool) {
Expand Down Expand Up @@ -294,6 +306,8 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
_setCreatedDate(false, _miningKey, _getCreatedDate(true, _miningKey));
_setUpdatedDate(false, _miningKey, _getUpdatedDate(true, _miningKey));
_setMinThreshold(false, _miningKey, minThreshold);
_setContactEmail(false, _miningKey, _getContactEmail(true, _miningKey));
_setIsCompany(false, _miningKey, _getIsCompany(true, _miningKey));
_deleteMetadata(true, _miningKey);
emit FinalizedChange(_miningKey);
}
Expand All @@ -314,6 +328,16 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
return IBallotsStorage(IProxyStorage(proxyStorage()).getBallotsStorage());
}

function _getContactEmail(bool _pending, address _miningKey)
private
view
returns(bytes32)
{
return bytes32Storage[keccak256(abi.encode(
_storeName(_pending), _miningKey, CONTACT_EMAIL
))];
}

function _getFirstName(bool _pending, address _miningKey)
private
view
Expand All @@ -324,6 +348,16 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
))];
}

function _getIsCompany(bool _pending, address _miningKey)
private
view
returns(bool)
{
return boolStorage[keccak256(abi.encode(
_storeName(_pending), _miningKey, IS_COMPANY
))];
}

function _getLastName(bool _pending, address _miningKey)
private
view
Expand Down Expand Up @@ -460,6 +494,8 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
delete uintStorage[keccak256(abi.encode(_store, _miningKey, CREATED_DATE))];
delete uintStorage[keccak256(abi.encode(_store, _miningKey, UPDATED_DATE))];
delete uintStorage[keccak256(abi.encode(_store, _miningKey, MIN_THRESHOLD))];
delete bytes32Storage[keccak256(abi.encode(_store, _miningKey, CONTACT_EMAIL))];
delete boolStorage[keccak256(abi.encode(_store, _miningKey, IS_COMPANY))];
if (_pending) {
_confirmationsVotersClear(_miningKey);
}
Expand All @@ -480,14 +516,24 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
_getUpdatedDate(_pending, _oldMiningKey),
_getMinThreshold(_pending, _oldMiningKey)
);

_setContactEmail(_pending, _newMiningKey, _getContactEmail(_pending, _oldMiningKey));
_setIsCompany(_pending, _newMiningKey, _getIsCompany(_pending, _oldMiningKey));

if (_pending) {
_confirmationsVotersCopy(_oldMiningKey, _newMiningKey);
}

_deleteMetadata(_pending, _oldMiningKey);
}

function _setContactEmail(bool _pending, address _miningKey, bytes32 _contactEmail) private {
bytes32Storage[keccak256(abi.encode(
_storeName(_pending),
_miningKey,
CONTACT_EMAIL
))] = _contactEmail;
}

function _setFirstName(bool _pending, address _miningKey, bytes32 _firstName) private {
bytes32Storage[keccak256(abi.encode(
_storeName(_pending),
Expand All @@ -496,6 +542,14 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
))] = _firstName;
}

function _setIsCompany(bool _pending, address _miningKey, bool _isCompany) private {
boolStorage[keccak256(abi.encode(
_storeName(_pending),
_miningKey,
IS_COMPANY
))] = _isCompany;
}

function _setLastName(bool _pending, address _miningKey, bytes32 _lastName) private {
bytes32Storage[keccak256(abi.encode(
_storeName(_pending),
Expand Down Expand Up @@ -647,7 +701,9 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
uint256 expirationDate,
uint256 createdDate,
uint256 updatedDate,
uint256 minThreshold
uint256 minThreshold,
bytes32 contactEmail,
bool isCompany
) {
firstName = _getFirstName(_pending, _miningKey);
lastName = _getLastName(_pending, _miningKey);
Expand All @@ -659,6 +715,8 @@ contract ValidatorMetadata is EternalStorage, EnumThresholdTypes, IValidatorMeta
createdDate = _getCreatedDate(_pending, _miningKey);
updatedDate = _getUpdatedDate(_pending, _miningKey);
minThreshold = _getMinThreshold(_pending, _miningKey);
contactEmail = _getContactEmail(_pending, _miningKey);
isCompany = _getIsCompany(_pending, _miningKey);
}

}

0 comments on commit b0fc878

Please sign in to comment.