def rebuild_db(): db.drop_all() db.create_all() db.session.add( Court(id=0, name="General Court", address="0x0d67440946949fe293b45c52efd8a9b3d51e2522")) db.session.add(Court(id=1, name="Court 1", parent=0, address="")) db.session.add( Court(id=2, parent=0, name="TCR Court", address="0xebcf3bca271b26ae4b162ba560e243055af0e679")) db.session.add( Court(id=3, parent=2, name="Ethfinex Court", address="0x916deab80dfbc7030277047cd18b233b3ce5b4ab")) db.session.add( Court(id=4, parent=2, name="ERC20 Court", address="0xcb4aae35333193232421e86cd2e9b6c91f3b125f")) db.session.add(Court(id=5, parent=1, name="", address="")) db.session.add(Court(id=6, parent=1, name="", address="")) db.session.add(Court(id=7, parent=1, name="", address="")) Config.set('dispute_search_block', KlerosEth.initial_block) Config.set('staking_search_block', KlerosEth.initial_block) db.session.commit()
def disputes(): disputes = Dispute.query.order_by(Dispute.id.desc()).all() total_ETH = Deposit.total() round_eth = round(total_ETH, 2) eth_price = float(Config.get('eth_price')) round_price = round(eth_price, 2) total_in_USD = round(round_eth * round_price, 2) unique_voting_jurors = Juror.list() return render_template('monitor/disputes.html', disputes=disputes, last_updated=Config.get('updated'), round_eth=round_eth, round_price=round_price, total_in_USD=total_in_USD, voting_jurors=len(unique_voting_jurors))
def court(id): court = Court.query.get(id) court.disputes = court.disputes() staking_data = [] for juror in court.jurors: juror_data = juror.current_amount_in_court(court.id) votes_in_court = juror.votes_in_court(court.id) if juror_data['court_and_children'] == 0 and votes_in_court == 0: continue staking_data.append({ 'address': juror.address, 'votes_in_court': votes_in_court, 'court_only': juror_data['court_only'], 'court_and_children': juror_data['court_and_children'] }) court.staking_data = sorted(staking_data, key=lambda x: (x['court_and_children'], x['votes_in_court']), reverse=True) num_Jurors = len(court.jurors) - 1 return render_template('monitor/court.html', court=court, last_updated=Config.get('updated'), num_Jurors=num_Jurors, jurors_stats=[], full_jurors=[], full_jurors_stats=[], voting_jurors_num=[])
def juror(address): votes = (db.session.query( Vote, Round).filter(func.lower(Vote.account) == address.lower()).filter( Vote.round_id == Round.id).order_by(Vote.round_id.desc()).all()) for v in votes: if v[0].vote == 0: v[0].color = '#F7DC6F' else: if v[0].is_winner: v[0].color = '#27AE60' else: v[0].color = '#F5B7B1' stakes = (db.session.query(JurorStake, Court).filter( func.lower(JurorStake.address) == address.lower()).filter( Court.id == JurorStake.court_id).order_by( JurorStake.staking_date.desc()).all()) disputes = Dispute.query.filter( func.lower(Dispute.created_by) == address.lower()).order_by( Dispute.created_date.desc()) return render_template('monitor/juror.html', address=address, votes=votes, stakes=stakes, disputes=disputes, last_updated=Config.get('updated'))
def dispute(id): dispute = Dispute.query.get(id) dispute.rounds = dispute.rounds() for r in dispute.rounds: r.votes = r.votes() for v in r.votes: if v.choice == 1: v.vote_str = 'Yes' elif v.choice == 2: v.vote_str = 'No' else: v.vote_str = 'Pending' if r.majority_reached: if v.choice == 0: v.color = '#F7DC6F' elif v.choice == r.winning_choice: v.color = '#27AE60' else: v.color = '#E74C3C' else: if v.choice == 0: v.color = '#FCF3CF' elif v.choice == r.winning_choice: v.color = '#D1F2EB' else: v.color = '#F5B7B1' return render_template('monitor/dispute.html', dispute=dispute, last_updated=Config.get('updated'))
account = vote_eth['address'], commit = vote_eth['commit'], choice = vote_eth['choice'], vote = vote_eth['vote'] ) db.session.add(vote) db.session.commit() for opt, arg in opts: if opt in ('-r', '--rebuild'): rebuild_db() eth_price = makerdao_medianizer.eth_price() Config.set('eth_price', eth_price) print("ETH price is : %s USD" % eth_price) print("Fetching disputes from block %s" % Config.get('dispute_search_block')) current_block = Config.get('dispute_search_block') if (current_block) == None: current_block = 0 current_block = int(current_block) end_block = int(kleros_eth.w3.eth.blockNumber) found_open_dispute = False while current_block < end_block: for dispute_eth in kleros_eth.dispute_events(current_block): dispute = Dispute.query.get(dispute_eth['dispute_id'])
#!/usr/bin/python3 import sys sys.path.extend(('lib', 'db')) from kleros import db, Dispute, Round, Vote, Config, Court, JurorStake, Deposit, Juror eth_price = float(Config.get('eth_price')) round_price = round(eth_price, 2) total_ETH = Deposit.total() round_eth = round(total_ETH, 2) total_USD = total_ETH * eth_price round_total = round(total_USD, 2) #print(j) #print(len(j)) total_jurors = 0 total_votes = 0 for court in range(5): c = Court.query.get(court) j = c.jurors total_jurors += len(j) for vote in range(len(j)): votes = j[vote]['votes'] total_votes += votes #print(len(j)) #print(total_jurors) #print("total_ETH deposited : %.2f ETH" % round_eth) #print("eth_price is %.2f USD" % round_price) #print("total_USD deposited %.5f USD" % round_total)