Created
July 7, 2016 20:04
-
-
Save joeykrug/2a801c7fbe1a2e2fc9f6133a4068fa29 to your computer and use it in GitHub Desktop.
Rep
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
# This software (Augur) allows buying && selling event outcomes in ethereum | |
# Copyright (C) 2015 Forecast Foundation OU | |
# This program is free software; you can redistribute it &&/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation; either version 2 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is free software: you can redistribute it &&/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# check for overflows | |
# Storage of all data associated with reporters | |
# takes reporterID as key, value is rep amount | |
data reporting[] | |
# keeps track of total rep in the system | |
data totalRep | |
# sender/owner, then spender, e.g. approvedToSpend[owner][spender] | |
# 1 if spender is approved, 0 if not | |
data approvedToSpend[][] | |
# whether the contract has been finished seeding | |
data seeded | |
event Transfer(_from:indexed, _to:indexed, _value) | |
event Approval(_owner:indexed, _spender:indexed) | |
macro ONE: | |
2**64 | |
macro refund(): | |
if(msg.value > 0): | |
send(msg.sender, msg.value) | |
def any(): | |
refund() | |
# Transfer rep | |
# @return value of reputation sent, 0 if not enough reputation | |
def transfer(receiver, value): | |
senderBalance = self.reporting[msg.sender] | |
if(senderBalance < value or value <= 0 or !self.seeded): | |
throw() | |
self.reporting[msg.sender] -= value | |
self.reporting[receiver] += value | |
log(type=Transfer, msg.sender, receiver, value) | |
return(value) | |
# TransferFrom per token api for rep | |
# fails unless from has authorized sender | |
def transferFrom(from, receiver, value): | |
senderBalance = self.reporting[from] | |
if(senderBalance < value or value <= 0 or (!self.approvedToSpend[from][msg.sender] and from!=msg.sender) or !self.seeded): | |
throw() | |
self.reporting[from] -= value | |
self.reporting[receiver] += value | |
log(type=Transfer, from, receiver, value) | |
return(value) | |
# Allows spender to withdraw from your rep account | |
def approve(spender): | |
self.approvedToSpend[msg.sender][spender] = 1 | |
log(type=Approval, msg.sender, spender) | |
return(1) | |
# Sets the initial distribution of rep | |
def setSaleDistribution(addresses: arr, balances: arr): | |
i = 0 | |
while i < len(addresses): | |
if(!self.reporting[addresses[i]] && !self.seeded): | |
self.reporting[addresses[i]] = balances[i] | |
self.totalRep += balances[i] | |
i+=1 | |
if(totalRep == 11000000*ONE): | |
self.seeded = 1 | |
return(1) | |
# Returns whether spender can withdraw from owner | |
def approved(owner, spender): | |
return(self.approvedToSpend[owner][spender]) | |
# @return reputation value | |
def balanceOf(address): | |
return(self.reporting[address]) | |
def getTotalRep(branch): | |
return(self.totalRep) | |
macro throw(): | |
i = 0 | |
while(1): | |
i +=1 |
Appears to be missing an unapprove
method.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Recommend renaming
reporting
torep
or something. The comment of what is stored in there (mapping of address to REP amount) doesn't align with an intuitive understanding of whatreporting
means.