コード例 #1
0
ファイル: esplora.py プロジェクト: AstraCore/api-server
def transaction_spent(thash):
    data = Transaction().spent(thash)
    outputs = []

    if data["error"] is None:
        result = data["result"]
        for output in result:
            item = {"spent": output["spent"]}

            if output["spent"]:
                block = Block().height(output["height"])["result"]

                item["txid"] = output["txid"]
                item["vin"] = output["vin"]
                item["status"] = {
                    "confirmed": True,
                    "block_height": block["height"],
                    "block_hash": block["hash"],
                    "block_time": block["time"]
                }

            outputs.append(item)

        return jsonify(outputs)

    else:
        return Response("Transaction not found",
                        mimetype="text/plain",
                        status=404)
コード例 #2
0
ファイル: esplora.py プロジェクト: AstraCore/api-server
def plain_block_hash(height):
    data = Block().height(height)

    if data["error"] is None:
        return Response(data["result"]["hash"], mimetype="text/plain")

    else:
        return Response("Block not found", mimetype="text/plain", status=404)
コード例 #3
0
ファイル: rest.py プロジェクト: widecoin-project/api-server
def block_by_hash(args, bhash):
    offset = args["offset"]

    data = Block().hash(bhash)
    if data["error"] is None:
        data["result"]["tx"] = data["result"]["tx"][offset:offset + 10]

    return jsonify(data)
コード例 #4
0
ファイル: rest.py プロジェクト: widecoin-project/api-server
def blocks_by_range(args, height):
    offset = args["offset"]

    if offset > 100:
        offset = 100

    result = Block().range(height, offset)
    return jsonify(utils.response(result))
コード例 #5
0
ファイル: rest.py プロジェクト: widecoin-project/api-server
def block_by_height(args, height):
    offset = args["offset"]

    data = Block().height(height)
    if data["error"] is None:
        data["result"]["tx"] = data["result"]["tx"][offset:offset + 10]

    return jsonify(data)
コード例 #6
0
def subscription_loop():
    bestblockhash = None
    mempool = []

    while True:
        data = General().info()
        if "result" in data:
            if "bestblockhash" in data["result"]:
                if data["result"]["bestblockhash"] != bestblockhash:
                    bestblockhash = data["result"]["bestblockhash"]

                    sio.emit("block.update",
                             utils.response({
                                 "height": data["result"]["blocks"],
                                 "hash": bestblockhash
                             }),
                             room="blocks")

                    updates = Block().inputs(bestblockhash)
                    for address in updates:
                        mempool = list(set(mempool) - set(updates[address]))

                        sio.emit("address.update",
                                 utils.response({
                                     "address":
                                     address,
                                     "tx":
                                     updates[address],
                                     "height":
                                     data["result"]["blocks"],
                                     "hash":
                                     bestblockhash
                                 }),
                                 room=address)

                data = General().mempool()
                temp_mempool = []

                if not data["error"]:
                    updates = Transaction.addresses(data["result"]["tx"])
                    for address in updates:
                        updates[address] = list(
                            set(updates[address]) - set(mempool))
                        temp_mempool += updates[address]

                        if len(updates[address]) > 0:
                            sio.emit("address.update",
                                     utils.response({
                                         "address": address,
                                         "tx": updates[address],
                                         "height": None,
                                         "hash": None
                                     }),
                                     room=address)

                mempool = list(set(mempool + temp_mempool))

        sio.sleep(0)
コード例 #7
0
def block_by_hash(bhash):
    offset = request.args.get("offset")
    offset = int(0 if offset is None else offset)

    data = Block().hash(bhash)
    if data["error"] is None:
        data["result"]["tx"] = data["result"]["tx"][offset:offset + 10]

    return jsonify(data)
コード例 #8
0
ファイル: esplora.py プロジェクト: AstraCore/api-server
def block_hash(bhash):
    data = Block().hash(bhash)

    if data["error"] is None:
        result = data["result"]
        return Esplora().block(result)

    else:
        return Response("Block not found", mimetype="text/plain", status=404)
コード例 #9
0
def blocks_by_range(height):
    offset = request.args.get("offset")
    offset = int(0 if offset is None else offset)

    if offset > 100:
        offset = 100

    result = Block().range(height, offset)
    return jsonify(utils.response(result))
コード例 #10
0
    def get(self, height):
        parser = reqparse.RequestParser()
        parser.add_argument('offset', type=int, default=30)
        args = parser.parse_args()

        if args['offset'] > 100:
            args['offset'] = 100

        result = Block().range(height, args['offset'])
        return utils.response(result)
コード例 #11
0
    def get(self, bhash):
        parser = reqparse.RequestParser()
        parser.add_argument('offset', type=int, default=0)
        args = parser.parse_args()

        data = Block().hash(bhash)
        if data['error'] is None:
            data['result']['tx'] = data['result']['tx'][
                args['offset']:args['offset'] + 10]

        return data
コード例 #12
0
ファイル: rest.py プロジェクト: bdcashdev/api-server
    def get(self, bhash):
        parser = reqparse.RequestParser()
        parser.add_argument("offset", type=int, default=0)
        args = parser.parse_args()

        data = Block().hash(bhash)
        if data["error"] is None:
            data["result"]["tx"] = data["result"]["tx"][
                args["offset"]:args["offset"] + 10]

        return data
コード例 #13
0
ファイル: esplora.py プロジェクト: AstraCore/api-server
def blocks_range(height):
    data = General().info()
    blocks = []

    if not height:
        height = data["result"]["blocks"]

    data = Block().range(height, config.block_page)

    for block in data:
        blocks.append(Esplora().block(block))

    return jsonify(blocks)
コード例 #14
0
ファイル: esplora.py プロジェクト: AstraCore/api-server
def block_status(bhash):
    data = Block().hash(bhash)
    next_best = None
    height = None
    best = False

    if data["error"] is None:
        result = data["result"]
        next_best = result[
            "nextblockhash"] if "nextblockhash" in result else None
        height = result["height"]
        best = True

    return {"in_best_chain": best, "height": height, "next_best": next_best}
コード例 #15
0
def init():
    bestblockhash = None

    while True:
        data = General().info()
        if data['result']['bestblockhash'] != bestblockhash:
            bestblockhash = data['result']['bestblockhash']
            sio.emit('block.update',
                     utils.response({
                         'height': data['result']['blocks'],
                         'hash': bestblockhash
                     }),
                     room='blocks')

            updates = Block().inputs(bestblockhash)
            for address in updates:
                mempool = list(set(state.mempool) - set(updates[address]))
                if address in state.rooms:
                    sio.emit('address.update',
                             utils.response({
                                 'address': address,
                                 'tx': updates[address],
                                 'height': data['result']['blocks'],
                                 'hash': bestblockhash
                             }),
                             room=address)

        data = General().mempool()
        updates = Transaction().addresses(data['result']['tx'])
        temp_mempool = []
        for address in updates:
            updates[address] = list(set(updates[address]) - set(mempool))
            temp_mempool += updates[address]
            if address in state.rooms:
                if len(updates[address]) > 0:
                    sio.emit('address.update',
                             utils.response({
                                 'address': address,
                                 'tx': updates[address],
                                 'height': None,
                                 'hash': None
                             }),
                             room=address)

        mempool = list(set(mempool + temp_mempool))
コード例 #16
0
ファイル: esplora.py プロジェクト: AstraCore/api-server
def block_transactions(bhash, start=0):
    data = Block().hash(bhash)
    transactions = []

    if start % config.tx_page != 0:
        return Response(
            f"start index must be a multipication of {config.tx_page}",
            mimetype="text/plain",
            status=400)

    if data["error"] is None:
        result = data["result"]

        for thash in result["tx"][start:start + config.tx_page]:
            transaction = Transaction().info(thash)["result"]
            transactions.append(Esplora().transaction(transaction))

        return jsonify(transactions)

    else:
        return Response("Block not found", mimetype="text/plain", status=404)
コード例 #17
0
 def get(self, height):
     return Block().get(height)
コード例 #18
0
def hash_by_height(height):
    return jsonify(Block().get(height))