-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,722 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
pragma solidity 0.4.25; | ||
|
||
import "openzeppelin-solidity/contracts/math/SafeMath.sol"; | ||
import "./Broker.sol"; | ||
|
||
/// @title The AirDropper contract to send ether to users | ||
/// @author Switcheo Network | ||
contract AirDropper { | ||
using SafeMath for uint256; | ||
|
||
// The Switcheo Broker contract | ||
Broker public broker; | ||
|
||
// A record of which hashes have been used before | ||
mapping(bytes32 => bool) public usedHashes; | ||
|
||
// Emitted when ether is sent | ||
event SendEther(bytes32 indexed id, address indexed receiver, uint256 amount); | ||
|
||
/// @notice Initializes the AirDropper contract | ||
/// @dev The broker is initialized to the Switcheo Broker | ||
constructor(address brokerAddress) | ||
public | ||
{ | ||
broker = Broker(brokerAddress); | ||
} | ||
|
||
modifier onlyCoordinator() { | ||
require( | ||
msg.sender == address(broker.coordinator()), | ||
"Invalid sender" | ||
); | ||
_; | ||
} | ||
|
||
/// @notice The payable method to allow this contract to receive ether | ||
function depositEther() external payable {} | ||
|
||
/// @notice Sends ether to a receiving address. | ||
/// @param _id The unique identifier to prevent double spends | ||
/// @param _receiver The address of the receiver | ||
/// @param _amount The amount of ether to send | ||
function sendEther( | ||
bytes32 _id, | ||
address _receiver, | ||
uint256 _amount | ||
) | ||
external | ||
onlyCoordinator | ||
{ | ||
_validateAndAddHash(_id); | ||
_receiver.transfer(_amount); | ||
emit SendEther(_id, _receiver, _amount); | ||
} | ||
|
||
/// @dev Ensures a hash hasn't been already used. | ||
/// This prevents replay attacks. | ||
function _validateAndAddHash(bytes32 _hash) | ||
private | ||
{ | ||
require( | ||
usedHashes[_hash] != true, | ||
"hash already used" | ||
); | ||
|
||
usedHashes[_hash] = true; | ||
} | ||
} |
Oops, something went wrong.