Add rewarding system

This commit is contained in:
Andrea Maria Piana 2019-04-19 12:22:01 +02:00
parent f06324c87e
commit 04fa335084
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
1 changed files with 14 additions and 0 deletions

View File

@ -13,7 +13,11 @@ contract NodesV2
uint16 maxNodes = 6000;
// How many blocks is a session
uint16 blockPerSession;
// How many blocks per subscription period
uint24 blockPerSubscription = 192960;
uint currentSessionStart;
// How much to send to user at each voting
uint currentReward;
uint32 public currentSession;
struct Enode {
@ -113,6 +117,8 @@ contract NodesV2
currentSession++;
// Set start
currentSessionStart = block.number;
// Set reward
currentReward = calculateReward();
}
function vote(
@ -177,6 +183,9 @@ contract NodesV2
}
}
}
msg.sender.transfer(currentReward);
}
function newSession() private view returns (bool) {
@ -219,6 +228,11 @@ contract NodesV2
return uint16(a) / 2 + 1;
}
function calculateReward() view internal returns (uint) {
return address(this).balance / (blockPerSubscription / blockPerSession) / activeNodes.length;
}
function _deleteInactiveNode(uint index) internal {
require(index < inactiveNodes.length);
// Remove from index