Skip to content

Commit

Permalink
Idempotency of MS deposits - closes #76
Browse files Browse the repository at this point in the history
  • Loading branch information
err508 committed May 22, 2018
1 parent 0f1ee40 commit 86545a2
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions raiden_contracts/contracts/MonitoringService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,27 @@ contract MonitoringService is Utils {

/// @notice Deposit tokens used to reward MSs
/// Can be called by anyone several times and on behalf of other accounts
/// @param beneficiary The account benefitting from the deposit
/// @param amount The amount of tokens to be depositted
function deposit(address beneficiary, uint amount) public {
require(amount > 0);
/// @param beneficiary The account benefiting from the deposit
/// @param total_deposit Idempotent function that sets the total_deposit of
/// tokens of the beneficiary
function deposit(address beneficiary, uint256 total_deposit) public
{
require(total_deposit != 0);

uint256 added_deposit;

// Calculate the actual amount of tokens that will be transferred
added_deposit = total_deposit - balances[beneficiary];

// This also allows for MSs to deposit and use other MSs
balances[beneficiary] += amount;
balances[beneficiary] += added_deposit;

emit NewDeposit(beneficiary, added_deposit);

// Transfer the deposit to the smart contract
require(token.transferFrom(msg.sender, address(this), amount));
require(token.transferFrom(msg.sender, address(this), added_deposit));

emit NewDeposit(beneficiary, amount);
require(balances[beneficiary] >= added_deposit);
}

/// @notice Internal function that updates the Reward struct if a newer balance proof
Expand Down Expand Up @@ -264,7 +273,7 @@ contract MonitoringService is Utils {
delete rewards[reward_identifier];
}

/// @notice Withdraw depositted tokens.
/// @notice Withdraw deposited tokens.
/// Can be called by addresses with a deposit as long as they have a positive balance
/// @param amount Amount of tokens to be withdrawn
function withdraw(uint256 amount) public {
Expand Down

0 comments on commit 86545a2

Please sign in to comment.