def jury_vote_check(tx, txs, out, DB): if not transactions.signature_check(tx): out[0]+='signature check' return False if not E_check(tx, 'decision_id', [str, unicode]): return False if not E_check(tx, 'vote_id', [str, unicode]): return False if is_number(tx['vote_id']) or is_number(tx['decision_id']): out[0]+='that can not be a number' return False if not E_check(tx, 'old_vote', [str, unicode]): return False if not E_check(tx, 'new_vote', [str, unicode]): return False decision=tools.db_get(tx['decision_id'], DB) if 'state' not in decision: out[0]+='that is not a decision_id' out[0]+='decision: ' +str(decision) out[0]+='tx: ' +str(tx) return False if decision['state']!='proposed': out[0]+='this decision has already been decided' return False if not tools.db_existence(tx['decision_id'], DB): out[0]+='decision error' return False if tools.reveal_time_p(DB): out[0]+='reveal time check' return False if len(tx['new_vote'])<4: out[0]+='secret too short error' return False if not txs_tools.fee_check(tx, txs, DB): return False return True
def collect_winnings_check(tx, txs, out, DB): if not transactions.signature_check(tx): out[0]+='signature check' return False if not E_check(tx, 'address', [str, unicode]): out[0]+='no address error' return False acc=tools.db_get(tx['address'], DB) if not E_check(tx, 'PM_id', [str, unicode]): out[0]+='no PM_id error' return False if tx['PM_id'] not in acc['shares']: out[0]+='you do not own any shares for this PM' return False if not tx['shares']==acc['shares'][tx['PM_id']]: out[0]+='that is not how many shares you have error' return False pm=tools.db_get(tx['PM_id'], DB) if 'decisions' not in pm: out[0]+='that is not a prediction market yet' return False for dec in pm['decisions']: decision = tools.db_get(dec, DB) if decision['state'] not in ['yes', 'no']: out[0]+='we have not yet reached consensus on the outcome of this market error' return False return True
def reveal_jury_vote_check(tx, txs, out, DB): if not transactions.signature_check(tx): out[0]+='signature check' return False address=addr(tx) acc=tools.db_get(address, DB) if not E_check(tx, 'decision_id', [str, unicode]): out[0]+='decision id error' return False if is_number(tx['decision_id']): out[0]+='that can not be a number' return False decision=tools.db_get(tx['decision_id'], DB) if decision['state']!='proposed': out[0]+='this decision has already been decided' return False if not E_check(tx, 'old_vote', [str, unicode]): return False if not E_check(tx, 'secret', [str, unicode]): return False if not E_check(tx, 'new_vote', [str, unicode]): out[0]+='new vote error' return False if tx['decision_id'] not in acc['votes']: out[0]+='decision id not in acc[votes] error' return False answer_hash=acc['votes'][tx['decision_id']] if not answer_hash==tools.det_hash([tx['new_vote'], tx['secret']]): out[0]+='hash does not match' return False if not E_check(tx, 'old_vote', [str, unicode]): out[0]+='old vote does not exist error' return False if not txs_tools.fee_check(tx, txs, DB): return False return True
def create_jury_check(tx, txs, out, DB): address=addr(tx) mine=filter(lambda t: t['type']=='create_jury', txs) mine=filter(lambda t: addr(t)==address, mine) if len(mine)>0: out[0]+='you cannot create 2 juries on the same block from the same address' return False if not transactions.signature_check(tx): out[0]+='signature check' return False if not E_check(tx, 'vote_id', [str, unicode]): out[0]+='vote id error' return False if tools.is_number(tx['vote_id']): out[0]+='vote_id can not be a number' return False if len(tx['vote_id'])>1000: return False if tools.db_existence(tx['vote_id'], DB): out[0]+='this vote_id is already being used' return False if not tools.db_existence(address, DB): out[0]+='this address is not used by anyone' return False acc=tools.db_get(address, DB) for t in txs: if t['type']=='prediction_market': if t['jury_id']==tx['jury_id']: out[0]+='this zeroth confirmation transaction already exists' return False if not txs_tools.fee_check(tx, txs, DB): return False return True
def jury_vote_check(tx, txs, out, DB): #make sure that this person is one of the 1000 richest people for this rep type. if not transactions.signature_check(tx): out[0]+='signature check' return False if not E_check(tx, 'decision_id', [str, unicode]): return False if not E_check(tx, 'vote_id', [str, unicode]): return False if is_number(tx['vote_id']) or is_number(tx['decision_id']): out[0]+='that can not be a number' return False if not E_check(tx, 'old_vote', [str, unicode]): return False if not E_check(tx, 'new_vote', [str, unicode]): return False decision=tools.db_get(tx['decision_id'], DB) if 'state' not in decision: out[0]+='that is not a decision_id' out[0]+='decision: ' +str(decision) out[0]+='tx: ' +str(tx) return False if decision['state']!='proposed': out[0]+='this decision has already been decided' return False if not tools.db_existence(tx['decision_id'], DB): out[0]+='decision error' return False if tools.reveal_time_p(DB): out[0]+='reveal time check' return False if len(tx['new_vote'])<4: out[0]+='secret too short error' return False if not txs_tools.fee_check(tx, txs, DB): return False return True
def slasher_jury_vote_check(tx, txs, out, DB): address=addr(tx) if tools.reveal_time_p(DB): out[0]+='reveal time check slasher' return False if not transactions.signature_check(tx): out[0]+='signature check' return False if not E_check(tx, 'amount', int): out[0]+='how many votecoins are we confiscating?' return False if not E_check(tx, 'reveal', dict): out[0]+='no reveal' return False if not reveal_jury_vote_check(tx['reveal'], txs, DB): out[0]+='this is an invalid reveal tx' return False victim=tools.db_get(addr(tx['reveal']), DB) decision=tx['reveal']['decision_id'] decision=tools.db_get(decision, DB) if victim['votecoin'][tx['reveal']['vote_id']]!=tx['amount']: out[0]+='that is not how many votecoins they have' return False return True
def create_jury_check(tx, txs, out, DB): address=addr(tx) mine=filter(lambda t: t['type']=='create_jury', txs) mine=filter(lambda t: addr(t)==address, mine) if len(mine)>0: out[0]+='you cannot create 2 juries on the same block from the same address' return False if not transactions.signature_check(tx): out[0]+='signature check' return False if not E_check(tx, 'vote_id', [str, unicode]): out[0]+='vote id error' return False if tools.is_number(tx['vote_id']): out[0]+='vote_id can not be a number' return False if len(tx['vote_id'])>1000: return False if tools.db_existence(tx['vote_id'], DB): out[0]+='this vote_id is already being used' return False if not tools.db_existence(address, DB): out[0]+='this address is not used by anyone' return False acc=tools.db_get(address, DB) if not txs_tools.fee_check(tx, txs, DB): return False return True
def create_jury_check(tx, txs, out, DB): address=addr(tx) if not transactions.signature_check(tx): out[0]+='signature check' return False if not E_check(tx, 'vote_id', [str, unicode]): out[0]+='vote id error' return False if tools.is_number(tx['vote_id']): out[0]+='vote_id can not be a number' return False if len(tx['vote_id'])>1000: return False if tools.db_existence(tx['vote_id'], DB): out[0]+='this vote_id is already being used' return False if not tools.db_existence(address, DB): out[0]+='this address is not used by anyone' return False acc=tools.db_get(address, DB) for t in txs: if 'jury_id' in t: if t['jury_id']==tx['jury_id']: out[0]+='this zeroth confirmation transaction already exists' return False if not txs_tools.fee_check(tx, txs, DB): return False return True
def prediction_market_check(tx, txs, out, DB): if not transactions.signature_check(tx): out[0]+='signature check' return False address=addr(tx) for l in ['states', 'states_combinatory', 'decisions']: if not E_check(tx, l, list): out[0]+=str(l)+ ' error' return False for dec in tx['decisions']: if not tools.db_existence(dec, DB): out[0]+='decision is not in the database: ' +str(dec) return False if is_number(dec): out[0]+='decision_id can not be a number' return False if is_number(tx['PM_id']): out[0]+='PM_id can not be a number' return False if len(tx['states'])>200: out[0]+='too many states' return False if not E_check(tx, 'B', int): out[0]+='B error' return False for comb in tx['states_combinatory']: if len(comb)!=len(tx['decisions']): out[0]+=str(comb)+' comb error' return False for l in [tx['states_combinatory'], tx['states'], tx['decisions']]: for comb in l: copies=len(filter(lambda comb2: comb==comb2, l)) if copies!=1: out[0]+=str(comb)+' not mutually exclusive' return False if len(tx['states'])!=len(tx['states_combinatory'])+1: out[0]+='wrong number of possible states?' return False if not E_check(tx, 'PM_id', [str, unicode]): out[0]+='PM_id error' return False if len(tx['PM_id'])>1000: out[0]+='PM_id too long' return False if tools.db_existence(tx['PM_id'], DB): #out[0]+='PM: ' +str(tools.db_get(tx['PM_id'], DB)) out[0]+='this PM_id is already being used' return False for t in txs: if 'PM_id' in t: if t['PM_id']==tx['PM_id']: out[0]+='Someone used that PM in this block already' return False acc=tools.db_get(address, DB) if not txs_tools.fee_check(tx, txs, DB): out[0]+='you do not have enough money' return False return True
def buy_shares_check(tx, txs, out, DB): #make sure that we can only buy the shares of undecided markets. if not transactions.signature_check(tx): out[0]+='signature check' return False a=copy.deepcopy(tx) a.pop('signatures') half_way=tools.make_half_way(a) if tools.det_hash(half_way)>custom.buy_shares_target: out[0]+='insufficient POW' return False if not E_check(tx, 'buy', list): out[0]+='buy error' return False if not E_check(tx, 'PM_id', [str, unicode]): out[0]+='pm id error' return False pm=tools.db_get(tx['PM_id'], DB) if 'decisions' not in pm: out[0]+='that is not a prediction market yet' return False if len(tx['buy'])!=len(pm['shares_purchased']): out[0]+='buy length error' return False stop=True for i in tx['buy']: if i!=0: stop=False if stop: out[0]+='you need to buy a non-zero amount of at least one share' return False if 'price_limit' in tx: price = txs_tools.cost_to_buy_shares(tx) if price>tx['price_limit']: out[0]+='that is outside the price limit for that tx '+str(price) + ' is bigger than ' +str(tx) return False for purchase in tx['buy']: if type(purchase)!=int: return False for i in range(len(tx['buy'])): if tx['buy'][i]+pm['shares_purchased'][i]<0: out[0]+='PM cannot have negative shares' return False if not txs_tools.fee_check(tx, txs, DB): out[0]+='fee check error' return False for dec in pm['decisions']: decision = tools.db_get(dec, DB) bad=True if decision['state'] not in ['yes', 'no']: bad=False if bad: out[0]+='this PM is already expired. you cannot buy shares.' return False return True
def propose_decision_check(tx, txs, out, DB): if 'maturation' in tx: n=tx['maturation'] if type(n)!=int or n<0: return False if not transactions.signature_check(tx): out[0]+='signature check' return False if not E_check(tx, 'vote_id', [str, unicode]): out[0]+='no vote id' return False if not E_check(tx, 'decision_id', [str, unicode]): out[0]+='no decision id' return False if is_number(tx['vote_id']) or is_number(tx['decision_id']): out[0]+='that can not be a number' return False if len(tx['decision_id'])>custom.max_key_length: out[0]+='decision id too long' return False if not tools.db_existence(tx['vote_id'], DB): out[0]+='that vote id has not been created yet' return False if tools.db_existence(tx['decision_id'], DB): out[0]+='that decision id has already been used' return False for t in txs: if 'decision_id' in t: if t['decision_id']==tx['decision_id']: out[0]+='already have a zeroth confirmation tx of this' return False if not txs_tools.fee_check(tx, txs, DB): out[0]+='you do not have enough money' return False if not E_check(tx, 'txt', [str, unicode]): out[0]+='what is the txt of this decision?' return False if len(tx['txt'])>6**5: out[0]+='the txt of this decision is too long' return False return True
def buy_shares_check(tx, txs, out, DB): #make sure that we can only buy the shares of undecided markets. if not transactions.signature_check(tx): out[0]+='signature check' return False if not E_check(tx, 'buy', list): out[0]+='buy error' return False if not E_check(tx, 'PM_id', [str, unicode]): out[0]+='pm id error' return False pm=tools.db_get(tx['PM_id'], DB) if 'decisions' not in pm: out[0]+='that is not a prediction market yet' return False if len(tx['buy'])!=len(pm['shares_purchased']): out[0]+='buy length error' return False for purchase in tx['buy']: if type(purchase)!=int: return False for i in range(len(tx['buy'])): if tx['buy'][i]+pm['shares_purchased'][i]<0: out[0]+='PM cannot have negative shares' return False if not txs_tools.fee_check(tx, txs, DB): out[0]+='fee check error' return False for dec in pm['decisions']: decision = tools.db_get(dec, DB) bad=True if decision['state'] not in ['yes', 'no']: bad=False if bad: out[0]+='this PM is already expired. you cannot buy shares.' return False return True