|
|
|
@ -7,6 +7,7 @@ contract StakeLockContract { |
|
|
|
|
string internal constant ALREADY_LOCKED = 'Tokens already locked'; |
|
|
|
|
string internal constant NO_TOKEN_UNLOCKABLE = 'No tokens unlockable'; |
|
|
|
|
string internal constant AMOUNT_ZERO = 'Amount can not be 0'; |
|
|
|
|
string internal constant EMPTY_BLS_ADDRESS = 'BLS address should not be empty'; |
|
|
|
|
|
|
|
|
|
uint256 internal constant LOCK_PERIOD_IN_EPOCHS = 3; // Final locking period TBD. |
|
|
|
|
|
|
|
|
@ -21,6 +22,8 @@ contract StakeLockContract { |
|
|
|
|
uint256 _epochNum; // The epoch when the token was locked |
|
|
|
|
uint256 _lockPeriodCount; // The number of locking period the token will be locked. |
|
|
|
|
uint256 _index; // The index in the addressList |
|
|
|
|
bytes20 _blsAddress; // The address of BLS account used for consensus message signing. |
|
|
|
|
// TODO: the bls address should be signed by the bls key to prove the ownership. |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -37,19 +40,21 @@ contract StakeLockContract { |
|
|
|
|
/** |
|
|
|
|
* @dev Locks a specified amount of tokens against an address |
|
|
|
|
* starting at the specific epoch |
|
|
|
|
* @param _blsAddress The address of BLS key for consensus message signing |
|
|
|
|
*/ |
|
|
|
|
function lock() |
|
|
|
|
function lock(bytes20 _blsAddress) |
|
|
|
|
public |
|
|
|
|
payable |
|
|
|
|
returns (bool) |
|
|
|
|
{ |
|
|
|
|
// If tokens are already locked, then functions extendLock or |
|
|
|
|
// increaseLockAmount should be used to make any changes |
|
|
|
|
require(_blsAddress != 0, EMPTY_BLS_ADDRESS); |
|
|
|
|
require(balanceOf(msg.sender) == 0, ALREADY_LOCKED); |
|
|
|
|
require(msg.value != 0, AMOUNT_ZERO); |
|
|
|
|
|
|
|
|
|
// By default, the tokens can only be locked for one locking period. |
|
|
|
|
locked[msg.sender] = lockedToken(msg.value, block.number, currentEpoch(), 1, addressList.push(msg.sender) - 1); |
|
|
|
|
locked[msg.sender] = lockedToken(msg.value, block.number, currentEpoch(), 1, addressList.push(msg.sender) - 1, _blsAddress); |
|
|
|
|
|
|
|
|
|
emit Locked(msg.sender, msg.value, currentEpoch()); |
|
|
|
|
return true; |
|
|
|
@ -118,14 +123,16 @@ contract StakeLockContract { |
|
|
|
|
function listLockedAddresses() |
|
|
|
|
public |
|
|
|
|
view |
|
|
|
|
returns (address[] memory lockedAddresses, uint256[] memory blockNums, uint256[] memory lockPeriodCounts, uint256[] memory amounts) |
|
|
|
|
returns (address[] memory lockedAddresses, bytes20[] memory blsAddresses, uint256[] memory blockNums, uint256[] memory lockPeriodCounts, uint256[] memory amounts) |
|
|
|
|
{ |
|
|
|
|
lockedAddresses = addressList; |
|
|
|
|
blsAddresses = new bytes20[](addressList.length); |
|
|
|
|
blockNums = new uint256[](addressList.length); |
|
|
|
|
lockPeriodCounts = new uint256[](addressList.length); |
|
|
|
|
amounts = new uint256[](addressList.length); |
|
|
|
|
for (uint i = 0; i < lockedAddresses.length; i++) { |
|
|
|
|
blockNums[i] = locked[lockedAddresses[i]]._blockNum; |
|
|
|
|
blsAddresses[i] = locked[lockedAddresses[i]]._blsAddress; |
|
|
|
|
lockPeriodCounts[i] = locked[lockedAddresses[i]]._lockPeriodCount; |
|
|
|
|
amounts[i] = locked[lockedAddresses[i]]._amount; |
|
|
|
|
} |
|
|
|
|