Skip to content

Commit

Permalink
Add atomic swap contract
Browse files Browse the repository at this point in the history
  • Loading branch information
jwheur authored and RavenXce committed Jun 10, 2019
1 parent e25cf13 commit 59fed64
Show file tree
Hide file tree
Showing 30 changed files with 1,722 additions and 136 deletions.
68 changes: 68 additions & 0 deletions contracts/AirDropper.sol
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;
}
}
Loading

0 comments on commit 59fed64

Please sign in to comment.