blob: be2c81a70f6b0187655f912d505162bba5a5fa70 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
pragma solidity ^0.4.11;
import "../Events/Event.sol";
/// @title Categorical event contract - Categorical events resolve to an outcome from a set of outcomes
/// @author Stefan George - <stefan@gnosis.pm>
contract CategoricalEvent is Event {
/*
* Public functions
*/
/// @dev Contract constructor validates and sets basic event properties
/// @param _collateralToken Tokens used as collateral in exchange for outcome tokens
/// @param _oracle Oracle contract used to resolve the event
/// @param outcomeCount Number of event outcomes
function CategoricalEvent(
Token _collateralToken,
Oracle _oracle,
uint8 outcomeCount
)
public
Event(_collateralToken, _oracle, outcomeCount)
{
}
/// @dev Exchanges sender's winning outcome tokens for collateral tokens
/// @return Sender's winnings
function redeemWinnings()
public
returns (uint winnings)
{
// Winning outcome has to be set
require(isOutcomeSet);
// Calculate winnings
winnings = outcomeTokens[uint(outcome)].balanceOf(msg.sender);
// Revoke tokens from winning outcome
outcomeTokens[uint(outcome)].revoke(msg.sender, winnings);
// Payout winnings
require(collateralToken.transfer(msg.sender, winnings));
WinningsRedemption(msg.sender, winnings);
}
/// @dev Calculates and returns event hash
/// @return Event hash
function getEventHash()
public
constant
returns (bytes32)
{
return keccak256(abi.encodePacked(collateralToken, oracle, outcomeTokens.length));
}
}
|