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 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 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 SVD_consensus_check(tx, txs, out, DB): if not E_check(tx, 'vote_id', [str, unicode]): return False if not E_check(tx, 'decisions', [list]): return False if not tools.reveal_time_p(DB, custom.SVD_length): out[0]+='this is not the correct time to do SVD' return False if is_number(tx['vote_id']): out[0]+='that can not be a number' return False jury=tools.db_get(tx['vote_id'], DB) if len(tx['decisions'])<5: out[0]+='need at least 5 decisions to compute SVD' return False if not E_check(jury, 'members', [list]): out[0]+='that jury has not been created yet' return False if len(jury['members'])<3: out[0]+='need at least 3 voters in order to compute SVD' return False try: matrix=txs_tools.decision_matrix(jury, tx['decisions'], DB) except: tools.log(sys.exc_info()) tools.log('matrix failure') return False w=txs_tools.weights(tx['vote_id'], DB, jury) k=txs_tools.decisions_keepers(tx['vote_id'], jury, DB) for decision in tx['decisions']: if not decision in k: out[0]+='one of the decisions has insufficient participation*certainty or has not matured yet: ' +str(decision)+' '+str(tools.db_get(decision)) return False if not txs_tools.fee_check(tx, txs, DB): out[0]+='you do not have enough money' 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 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 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 spend_verify(tx, txs, DB): if not E_check(tx, 'to', [str, unicode]): tools.log('no to') return False if not signature_check(tx): tools.log('signature check') return False if len(tx['to']) <= 30: tools.log('that address is too short') tools.log('tx: ' + str(tx)) return False return False if not E_check(tx, 'amount', int): tools.log('no amount') return False tx_copy.pop('signatures') if not txs_tools.fee_check(tx, txs, DB): tools.log('fee check error') 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 spend_verify(tx, txs, out, DB): if not E_check(tx, 'to', [str, unicode]): out[0] += 'no to' return False if not signature_check(tx): out[0] += 'signature check' return False if len(tx['to']) <= 30: out[0] += 'that address is too short' out[0] += 'tx: ' + str(tx) return False if not E_check(tx, 'amount', int): out[0] += 'no amount' return False if not txs_tools.fee_check(tx, txs, DB): out[0] += 'fee check error' return False if 'vote_id' in tx: if not tx['to'][:-29] == '11': out[0] += 'cannot hold votecoins in a multisig address' return False return True
def spend_verify(tx, txs, out, DB): if not E_check(tx, 'to', [str, unicode]): out[0]+='no to' return False if not signature_check(tx): out[0]+='signature check' return False if len(tx['to'])<=30: out[0]+='that address is too short' out[0]+='tx: ' +str(tx) return False if not E_check(tx, 'amount', int): out[0]+='no amount' return False if not txs_tools.fee_check(tx, txs, DB): out[0]+='fee check error' return False if 'vote_id' in tx: if not tx['to'][:-29]=='11': out[0]+='cannot hold votecoins in a multisig address' 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