Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 68 lines (66 sloc) 3.02 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
import branches as BRANCHES
import info as INFO
import cash as CASH
import reporting as REPORTING
inset('refund.se')
# Create a new branch given a parent branch - a branch is essentially a fork of rep where new markets can be created
# period length is given in seconds
# @return branchID if success
# error messages otherwise
# -1: bad input or parent doesn't exist
# -2: no money for creation fee
# -3: branch already exists
def createSubbranch(description:str, periodLength, parent, minTradingFee, oracleOnly):
refund()
if(periodLength<=0 || !BRANCHES.getPeriodLength(parent) || description==0):
return(-1)
if(minTradingFee < 0 or minTradingFee > 2**62):
return(-1)
parentPeriod = BRANCHES.getVotePeriod(parent)
branchInfo = string(7*32+len(description))
branchInfo[0] = msg.sender
#creation fee
branchInfo[1] = 47*ONE
#length of voting cycle
branchInfo[2] = periodLength
branchInfo[3] = block.timestamp
branchInfo[4] = parent
branchInfo[5] = minTradingFee
branchInfo[6] = oracleOnly
mcopy(branchInfo + 7*32, description, chars=len(description))
# people can check that these characteristics hash to the ID if they want
# people can hand a friend their new branch hash && characteristics && say, "don't trust me? check"
branchID = sha3(branchInfo, chars=len(branchInfo))
currentVotePeriod = (block.timestamp / periodLength) - 1
if(CASH.balance(msg.sender)<47*ONE):
return(-2)
# provided event doesn't already exist, create it
if(INFO.getCreator(branchID)==0):
BRANCHES.initializeBranch(branchID, currentVotePeriod, periodLength, minTradingFee, oracleOnly, parentPeriod, parent)
else:
return(-3)
# pay creation fee, initialize branch info
if(CASH.sendFrom(parent, 47*ONE, msg.sender) && INFO.setInfo(branchID, description, tx.origin, 47*ONE) && REPORTING.setInitialReporters(parent, branchID)):
return(branchID)
else:
return(-2)