示例#1
0
def get_latest_block(api_key: hug.types.text, request, hug_timer=5):
	"""Retrieve the latest block's details (date & time) & output in JSON!"""
	if (check_api_token(api_key) == True): # Check the api key
		# API KEY VALID
		google_analytics(request, 'get_latest_block')

		chain = Blockchain()
		current_block_number = chain.get_current_block_num()
		block_date = chain.block_time(current_block_number)

		target_block = Block(current_block_number)

		return {'previous': target_block['previous'],
				'timestamp': target_block['timestamp'],
				'witness': target_block['witness'],
				'transaction_merkle_root': target_block['transaction_merkle_root'],
				'extensions': target_block['extensions'],
				'witness_signature': target_block['witness_signature'],
				'transactions': target_block['transactions'],
				'id': target_block['id'],
				'block_date': block_date,
				'block_number': current_block_number,
				'valid_block_number': True,
				'valid_key': True,
				'took': float(hug_timer)}
	else:
	# API KEY INVALID!
		return {'valid_key': False,
				'took': float(hug_timer)}
示例#2
0
 def __init__(self, tx):
     self.timestamp = Block(tx['block_num'])['timestamp']
     self.id_ = tx['id']
     op = tx['op'][1]
     self.from_ = op['from']
     self.amount = Decimal(op['amount']['amount']) / Decimal("10000")
     self.memo = op.get('memo')
     self.asset_id = op['amount']['asset_id']
示例#3
0
文件: info.py 项目: kjmeta1/uptick
def block(ctx, obj):
    block = Block(obj, lazy=False, bitshares_instance=ctx.bitshares)
    t = [["Key", "Value"]]
    for key in sorted(block):
        value = block[key]
        if key == "transactions":
            value = format_tx(value)
        t.append([key, value])
    print_table(t)
示例#4
0
def get_block_details(block_number: hug.types.number,
                      api_key: hug.types.text,
                      hug_timer=5):
    """Retrieve a specific block's details (date & time) & output in JSON!"""
    if (check_api_token(api_key) == True):  # Check the api key
        # API KEY VALID
        try:
            target_block = Block(block_number)
        except:
            return {
                'valid_block_number': False,
                'valid_key': True,
                'took': float(hug_timer)
            }

        chain = Blockchain()
        block_date = chain.block_time(block_number)

        return {
            'previous': target_block['previous'],
            'timestamp': target_block['timestamp'],
            'witness': target_block['witness'],
            'transaction_merkle_root': target_block['transaction_merkle_root'],
            'extensions': target_block['extensions'],
            'witness_signature': target_block['witness_signature'],
            'transactions': target_block['transactions'],
            'id': target_block['id'],
            'date': block_date,
            'block_number': block_number,
            'valid_block_number': True,
            'valid_key': True,
            'took': float(hug_timer)
        }

    else:
        # API KEY INVALID!
        return {'valid_key': False, 'took': float(hug_timer)}
示例#5
0
def info(ctx, objects):
    """ Obtain all kinds of information
    """
    if not objects:
        t = [["Key", "Value"]]
        info = ctx.bitshares.rpc.get_dynamic_global_properties()
        for key in info:
            t.append([key, info[key]])
        print_table(t)

    for obj in objects:
        # Block
        if re.match("^[0-9]*$", obj):
            block = Block(obj, lazy=False, bitshares_instance=ctx.bitshares)
            t = [["Key", "Value"]]
            for key in sorted(block):
                value = block[key]
                if key == "transactions":
                    value = format_tx(value)
                t.append([key, value])
            print_table(t)
        # Object Id
        elif re.match("^\d*\.\d*\.\d*$", obj):
            data = ctx.bitshares.rpc.get_object(obj)
            if data:
                t = [["Key", "Value"]]
                for key in sorted(data):
                    value = data[key]
                    if isinstance(value, dict) or isinstance(value, list):
                        value = format_tx(value)
                    t.append([key, value])
                print_table(t)
            else:
                print_message("Object %s unknown" % obj, "warning")

        # Asset
        elif obj.upper() == obj and re.match("^[A-Z\.]*$", obj):
            data = Asset(obj)
            t = [["Key", "Value"]]
            for key in sorted(data):
                value = data[key]
                if isinstance(value, dict):
                    value = format_tx(value)
                t.append([key, value])
            print_table(t)

        # Public Key
        elif re.match("^BTS.{48,55}$", obj):
            account = ctx.bitshares.wallet.getAccountFromPublicKey(obj)
            if account:
                t = [["Account"]]
                t.append([account])
                print_table(t)
            else:
                print_message("Public Key not known: %s" % obj, "warning")

        # Account name
        elif re.match("^[a-zA-Z0-9\-\._]{2,64}$", obj):
            account = Account(obj, full=True)
            if account:
                t = [["Key", "Value"]]
                for key in sorted(account):
                    value = account[key]
                    if isinstance(value, dict) or isinstance(value, list):
                        value = format_tx(value)
                    t.append([key, value])
                print_table(t)
            else:
                print_message("Account %s unknown" % obj, "warning")

        elif ":" in obj:
            vote = ctx.bitshares.rpc.lookup_vote_ids([obj])[0]
            if vote:
                t = [["Key", "Value"]]
                for key in sorted(vote):
                    value = vote[key]
                    if isinstance(value, dict) or isinstance(value, list):
                        value = format_tx(value)
                    t.append([key, value])
                print_table(t)
            else:
                print_message("voteid %s unknown" % obj, "warning")

        else:
            print_message("Couldn't identify object to read", "warning")
示例#6
0
def info(ctx, objects):
    if not objects:
        t = PrettyTable(["Key", "Value"])
        t.align = "l"
        info = ctx.bitshares.rpc.get_dynamic_global_properties()
        for key in info:
            t.add_row([key, info[key]])
        click.echo(t.get_string(sortby="Key"))

    for obj in objects:
        # Block
        if re.match("^[0-9]*$", obj):
            block = Block(obj, bitshares_instance=ctx.bitshares)
            if block:
                t = PrettyTable(["Key", "Value"])
                t.align = "l"
                for key in sorted(block):
                    value = block[key]
                    if key == "transactions":
                        value = json.dumps(value, indent=4)
                    t.add_row([key, value])
                click.echo(t)
            else:
                click.echo("Block number %s unknown" % obj)
        # Object Id
        elif len(obj.split(".")) == 3:
            data = ctx.bitshares.rpc.get_object(obj)
            if data:
                t = PrettyTable(["Key", "Value"])
                t.align = "l"
                for key in sorted(data):
                    value = data[key]
                    if isinstance(value, dict):
                        value = json.dumps(value, indent=4)
                    t.add_row([key, value])
                click.echo(t)
            else:
                click.echo("Object %s unknown" % obj)

        # Asset
        elif obj.upper() == obj:
            data = Asset(obj)
            t = PrettyTable(["Key", "Value"])
            t.align = "l"
            for key in sorted(data):
                value = data[key]
                if isinstance(value, dict):
                    value = json.dumps(value, indent=4)
                t.add_row([key, value])
            click.echo(t)

        # Public Key
        elif re.match("^BTS.{48,55}$", obj):
            account = ctx.bitshares.wallet.getAccountFromPublicKey(obj)
            if account:
                t = PrettyTable(["Account"])
                t.align = "l"
                t.add_row([account])
                click.echo(t)
            else:
                click.echo("Public Key not known" % obj)

        # Account name
        elif re.match("^[a-zA-Z0-9\._]{2,64}$", obj):
            account = Account(obj, full=True)
            if account:
                t = PrettyTable(["Key", "Value"])
                t.align = "l"
                for key in sorted(account):
                    value = account[key]
                    if isinstance(value, dict) or isinstance(value, list):
                        value = json.dumps(value, indent=4)
                    t.add_row([key, value])
                click.echo(t)
            else:
                click.echo("Account %s unknown" % obj)
        else:
            click.echo("Couldn't identify object to read")
示例#7
0
 def test_block(self):
     block = Block(1, use_cache=True)
     self.assertEqual(block["previous"],
                      "0000000000000000000000000000000000000000")
     self.assertEqual(block.time(), parse_time("2015-10-13T14:12:24"))
 def get_block(self, block_num: int):
     """ Retrieve a full, signed block."""
     result = Block(block_num, blockchain_instance=self.bts)
     return dict(result)
示例#9
0
 def test_block(self):
     block = Block(1)
     self.assertEqual(block["previous"], "0000000000000000000000000000000000000000")
     self.assertEqual(block.time(), parse_time('2015-10-13T14:12:24'))
def getTransactionFromHistoryItem(hist_item):
    block = Block(hist_item["block_num"], blockchain_instance=blockchain)
    trx = block.get("transactions")[hist_item["trx_in_block"]]
    return trx
示例#11
0
 def get_block(self, block_num: int):
     """ Retrieve a full, signed block."""
     return Block(block_num, blockchain_instance=self.bts, lazy=False)
示例#12
0
 def test_block(self):
     block = Block(1)
     self.assertEqual(block["previous"], "0000000000000000000000000000000000000000")
     self.assertEqual(block.time(), parse_time('2016-01-18T10:59:20'))