Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 129 lines (115 sloc) 4.57 KB
# 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/>.
# Any questions please contact joey@augur.net
inset('refund.se')
# address -> value map of "cash [a made up subcurrency/token for testing"
data cashcoinBalances[]
# address -> address mapping of a cash address to the address that owns it
data owners[]
event sentCash(_from:indexed, _to:indexed, _value, timestamp)
event deposit(sender:indexed, value, timestamp)
event withdraw(sender:indexed, to:indexed, value, timestamp)
def init():
# test initial funds
self.cashcoinBalances[msg.sender] = 100000*ONE
# @return: cash balance of address
def balance(address):
refund()
return(self.cashcoinBalances[address])
# A random market could have a balance, and when that account was created/first used in the subcurrency, it'd have whatever contract that created it be the owner, so for example...
# needs to be called when making a market, branch, etc. or a new cash user acc.
def initiateOwner(account):
refund()
if(self.owners[account]==0 and self.cashcoinBalances[account]==0):
self.owners[account] = msg.sender
return(1)
else:
return(0)
# Send cash to a receiver from msg.sender
# should send values as fixed point in UI (1 is ONE, 4 is 4*ONE, .5 is ONEHALF, etc.)
# @return: value sent, 0 if fails
def send(recver, value):
refund()
if(self.owners[msg.sender]==0):
self.owners[msg.sender] = msg.sender
#if(self.owners[recver]==0):
# return(0)
sender = msg.sender
senderBalance = self.cashcoinBalances[sender]
if(senderBalance >= value && value > 0):
self.cashcoinBalances[sender] -= value
self.cashcoinBalances[recver] += value
log(type=sentCash, msg.sender, recver, value)
return(value)
else:
return(0)
# Sends cash from a user to a receiver
# @return value of cash sent; fail is 0
def sendFrom(recver, value, from):
refund()
# sendFrom would check if the sender had an owner, if it did, then it'd check and see if the msg.sender was the owner.
# it's not owned by a regular account nor a contract owned account (i.e. a market's hash from markets.)
if(from!=tx.origin and msg.sender!=self.owners[from] and msg.sender!=from):
return(0)
#if(self.owners[recver]==0):
# return(0)
senderBalance = self.cashcoinBalances[from]
if(senderBalance >= value && value > 0):
self.cashcoinBalances[from] -= value
self.cashcoinBalances[recver] += value
log(type=sentCash, from, recver, value, block.timestamp)
return(value)
else:
return(0)
# make sure only coming from specific contracts
def subtractCash(ID, amount):
refund()
#if(!self.whitelist.check(msg.sender)):
# return(-1)
#if(msg.sender!=self.owners[ID] && tx.origin!=self.owners[ID]):
# return(0)
self.cashcoinBalances[ID] -= amount
return(1)
def addCash(ID, amount):
refund()
#if(!self.whitelist.check(msg.sender)):
# return(-1)
self.cashcoinBalances[ID] += amount
return(1)
def setCash(address, balance):
refund()
#if !self.whitelist.check(msg.sender):
# return(-1)
self.cashcoinBalances[address] = balance
return(1)
def depositEther():
self.cashcoinBalances[msg.sender] += msg.value
log(type=deposit, msg.sender, msg.value, block.timestamp)
return msg.value
def withdrawEther(to, value):
if(value < 0):
return(-1)
if self.cashcoinBalances[msg.sender] >= value:
self.cashcoinBalances[msg.sender] -= value
send(to, value)
log(type=withdraw, msg.sender, to, value, block.timestamp)
return 1
else:
return 0