示例#1
0
def latest_tx():
    json_transaction = list()
    for tx in db.get_all_unconfirmed_tx(blockchain.wallet.address):
        txins = tx.txins
        txouts = tx.txouts

        from_addr = list()
        to_addr = list()
        amount = 0
        for txin in txins:
            if txin.prev_tx_out_idx != -1:
                pubkey_hash = Wallet.get_address(txin.pubkey)
                if pubkey_hash not in from_addr:
                    from_addr.append(pubkey_hash)

        for txout in txouts:
            value = txout.value
            script_pub_key = txout.scriptPubKey
            if len(script_pub_key) == 5:
                recv_addr = get_address_from_ripemd160(script_pub_key[2])
                to_addr.append({'receiver': recv_addr, 'value': value})

        new_tx = {
            'txid': tx.txid,
            'senders': from_addr,
            'receivers': to_addr,
            'amount': amount,
            'timestamp': tx.timestamp
        }

        json_transaction.append(new_tx)

    response = {'latest_tx': json_transaction}
    return json.dumps(response), 200
示例#2
0
def block_info():
    height = request.args.get('height')
    block_index = int(height) - 1

    block = db.get_block_data_by_index(blockchain.wallet.address, block_index)

    json_transaction = list()
    for tx in block.transactions:
        txins = tx.txins
        txouts = tx.txouts

        from_addr = list()
        to_addr = list()
        amount = 0
        for txin in txins:
            if txin.prev_tx_out_idx != -1:
                address = Wallet.get_address(txin.pubkey)
                if address not in from_addr:
                    from_addr.append(address)

        for txout in txouts:
            value = txout.value
            script_pub_key = txout.scriptPubKey
            if len(script_pub_key) == 5:
                recv_addr = get_address_from_ripemd160(script_pub_key[2])
                to_addr.append({'receiver': recv_addr, 'value': value})

        new_tx = {
            'txid': tx.txid,
            'senders': from_addr,
            'receivers': to_addr,
            'amount': amount,
            'timestamp': tx.timestamp
        }

        json_transaction.append(new_tx)

    response = {
        'index': block.index,
        'current_hash': block.current_hash,
        'previous_hash': block.previous_hash,
        'timestamp': block.timestamp,
        'merkleroot': block.merkleroot,
        'difficulty': block.difficulty,
        'nonce': block.nonce,
        'transactions': json_transaction
    }

    return jsonify(response), 200
示例#3
0
def block_info():
    block_index = request.args.get('block_index')

    block = db.get_block_data_by_index(blockchain.wallet.address, block_index)

    json_transaction = list()
    for tx in block.transactions:
        if isinstance(tx, Tx_vid):
            new_tx = {
                'txid': tx.txid,
                'timestamp': tx.timestamp,
                'type': 'vid',
                'vid': tx.vid
            }
        elif isinstance(tx, Tx_report):
            new_tx = {
                'txid': tx.txid,
                'timestamp': tx.timestamp,
                'type': 'report',
                'edgeId': tx.edgeId,
                'meanSpeed': tx.meanSpeed,
                'vehicleNum': tx.vehicleNum
            }
        elif isinstance(tx, Tx_easy):
            new_tx = {
                'txid': tx.txid,
                'sender': tx.sender,
                'receiver': tx.receiver,
                'amount': tx.amount,
                'timestamp': tx.timestamp
            }
        elif isinstance(tx, Transaction):
            txins = tx.txins
            txouts = tx.txouts

            from_addr = list()
            to_addr = list()
            amount = 0

            for txin in txins:
                if txin.prev_tx_out_idx != -1:
                    address = Wallet.get_address(txin.pubkey)
                    if address not in from_addr:
                        from_addr.append(address)

            for txout in txouts:
                value = txout.value
                script_pub_key = txout.scriptPubKey
                if len(script_pub_key) == 5:
                    recv_addr = get_address_from_ripemd160(script_pub_key[2])
                    to_addr.append({'receiver': recv_addr, 'value': value})

            new_tx = {
                'txid': tx.txid,
                'senders': from_addr,
                'receivers': to_addr,
                'amount': amount,
                'timestamp': tx.timestamp
            }

        json_transaction.append(new_tx)

    response = {
        'index': block.index,
        'timestamp': block.timestamp,
        'current_hash': block.current_hash,
        'previous_hash': block.previous_hash,
        'merkleroot': block.merkleroot,
        'transactions': json_transaction
    }

    return jsonify(response), 200
示例#4
0
def tx_in_block():
    values = request.get_json()

    block_index = int(request.args.get('block_index'))

    block = db.get_block_data_by_index(blockchain.wallet.address, block_index)
    tmp = dict()
    cnt = 0
    for tx in block.transactions:
        if isinstance(tx, Tx_vid):
            tmp[str(cnt)] = {
                'txid':
                tx.txid,
                'timestamp':
                time.strftime("%Y-%m-%d %H:%M:%S",
                              time.localtime(tx.timestamp)),
                'type':
                'vid',
                'vid':
                tx.vid
            }
            cnt += 1

        elif isinstance(tx, Tx_report):
            tmp[str(cnt)] = {
                'txid':
                tx.txid,
                'timestamp':
                time.strftime("%Y-%m-%d %H:%M:%S",
                              time.localtime(tx.timestamp)),
                'type':
                'report',
                'edgeId':
                tx.edgeId,
                'meanSpeed':
                tx.meanSpeed,
                'vehicleNum':
                tx.vehicleNum
            }
            cnt += 1

        elif isinstance(tx, Tx_easy):
            tmp[str(cnt)] = {
                'txid': tx.txid,
                'sender': tx.sender,
                'receiver': tx.receiver,
                'amount': tx.amount,
                'timestamp': tx.timestamp
            }
            cnt += 1

        elif isinstance(tx, Transaction):
            txins = tx.txins
            txouts = tx.txouts

            from_addr = list()
            to_addr = list()
            amount = 0

            for txin in txins:
                if txin.prev_tx_out_idx != -1:
                    address = Wallet.get_address(txin.pubkey)
                    if address not in from_addr:
                        from_addr.append(address)

            for txout in txouts:
                value = txout.value
                script_pub_key = txout.scriptPubKey
                if len(script_pub_key) == 5:
                    recv_addr = get_address_from_ripemd160(script_pub_key[2])
                    to_addr.append({'receiver': recv_addr, 'value': value})

            tmp[str(cnt)] = {
                'txid': tx.txid,
                'senders': from_addr,
                'receivers': to_addr,
                'amount': amount,
                'timestamp': tx.timestamp
            }

            cnt += 1

    return json.dumps(tmp), 200