From 04fa3350848f817ce7fb5cd532ff3ffd17280253 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Fri, 19 Apr 2019 12:22:01 +0200 Subject: [PATCH] Add rewarding system --- contracts/NodesV2.sol | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/contracts/NodesV2.sol b/contracts/NodesV2.sol index 2d74d9f..e2ec63b 100644 --- a/contracts/NodesV2.sol +++ b/contracts/NodesV2.sol @@ -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