Пример #1
0
def witnesses(ctx):
    """ List witnesses and relevant information
    """
    t = [[
        "weight",
        "account",
        "signing_key",
        "vote_id",
        "url",
        "total_missed",
        "last_confirmed_block_num"
    ]]
    for witness in sorted(
        Witnesses(),
        key=lambda x: x.weight,
        reverse=True
    ):
        witness.refresh()
        t.append([
            "{:.2f}%".format(witness.weight * 100),
            witness.account["name"],
            witness["signing_key"],
            witness["vote_id"],
            witness["url"],
            witness["total_missed"],
            witness["last_confirmed_block_num"]
        ])
    print_table(t)
Пример #2
0
def list_of_witnesses(api_key: hug.types.text, request, hug_timer=5):
	"""Output the list of active witnesses in JSON."""
	if (check_api_token(api_key) == True): # Check the api key
		# API KEY VALID
		google_analytics(request, 'list_of_witnesses')

		list_of_witnesses = Witnesses()

		witness_data = []
		for witness in list_of_witnesses:
			target_account = Account(witness['witness_account'])
			witness_account_data = extract_object(target_account)
			witness_role_data = extract_object(witness)

			active_witnesses = Blockchain().config()['active_witnesses']

			if witness_role_data['id'] in active_witnesses:
				witness_status = True
			else:
				witness_status = False

			witness_data.append({'witness_role_data': witness_role_data,
								 'witness_account_data': witness_account_data,
								 'witness_status': witness_status})

		return {'witnesses': witness_data,
				'witness_count': len(list_of_witnesses),
				'valid_key': True,
				'took': float(hug_timer)}
	else:
	# API KEY INVALID!
		return {'valid_key': False,
				'took': float(hug_timer)}
Пример #3
0
def feeds(ctx, assets, pricethreshold, maxage):
    """ Price Feed Overview
    """
    import builtins
    witnesses = Witnesses(bitshares_instance=ctx.bitshares)

    def test_price(p, ref):
        if (math.fabs(float(p / ref) - 1.0) > pricethreshold / 100.0):
            return click.style(str(p), fg="red")
        elif (math.fabs(float(p / ref) - 1.0) > pricethreshold / 2.0 / 100.0):
            return click.style(str(p), fg="yellow")
        else:
            return click.style(str(p), fg="green")

    def test_date(d):
        now = datetime.utcnow()
        if now < d + timedelta(minutes=maxage):
            return click.style(str(d), fg="green")
        if now < d + timedelta(minutes=maxage / 2.0):
            return click.style(str(d), fg="yellow")
        else:
            return click.style(str(d), fg="red")

    output = ""
    for asset in tqdm(assets):
        t = PrettyTable([
            "Asset",
            "Producer",
            "Active Witness",
            "Date",
            "Settlement Price",
            "Core Exchange Price",
            "MCR",
            "SSPR"
        ])
        t.align = 'c'
        t.align["Producer"] = 'l'
        asset = Asset(asset, full=True, bitshares_instance=ctx.bitshares)
        current_feed = asset.feed
        feeds = asset.feeds
        producingwitnesses = builtins.set()
        witness_accounts = [
            x["witness_account"] for x in witnesses
        ]
        for feed in tqdm(feeds):
            producingwitnesses.add(feed["producer"]["id"])
            t.add_row([
                asset["symbol"],
                feed["producer"]["name"],
                click.style(
                    "X" if feed["producer"]["id"] in witness_accounts else "",
                    bold=True),
                test_date(feed["date"]),
                test_price(feed["settlement_price"], current_feed["settlement_price"]),
                test_price(feed["core_exchange_rate"], current_feed["core_exchange_rate"]),
                feed["maintenance_collateral_ratio"] / 10,
                feed["maximum_short_squeeze_ratio"] / 10,
            ])
        for missing in (builtins.set(witness_accounts).difference(producingwitnesses)):
            witness = Witness(missing)
            t.add_row([
                click.style(asset["symbol"], bg="red"),
                click.style(witness.account["name"], bg="red"),
                click.style(
                    "X" if feed["producer"]["id"] in witness_accounts else "",
                    bold=True),
                click.style(str(datetime(1970, 1, 1))),
                click.style("missing", bg="red"),
                click.style("missing", bg="red"),
                click.style("missing", bg="red"),
                click.style("missing", bg="red"),
            ])
        output += t.get_string(sortby="Date", reversesort=True)
        output += "\n"
    click.echo(output)
Пример #4
0
 def getWitnesses(self, only_active=False, lazy=False):
     from bitshares.witness import Witnesses
     return Witnesses(blockchain_instance=self.bts, lazy=lazy)
Пример #5
0
 def get_shuffle_round_time(self):
     """ returns time in seconds of one round of block creation of every active witness """
     btschain = Blockchain()
     wits = len(Witnesses(bitshares_instance=self.bts))
     intv = btschain.chainParameters().get("block_interval")
     return wits * intv