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)
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))
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)
def mempool_recent(): data = General().mempool() result = [] for txid in data["result"]["tx"]: transaction = Transaction().info(txid)["result"] item = Esplora().transaction(transaction) result.append({ "txid": item["txid"], "fee": item["fee"], "vsize": item["weight"], "value": item["value"] }) return jsonify(result)
def price(): data = General().price() return jsonify(utils.response(data["sugarchain"]))
def supply_plain(): data = int(utils.amount(General().supply()["supply"])) return Response(str(data), mimetype="text/plain")
def supply(): data = General().supply() return jsonify(utils.response(data))
def EstimateFee(): return General().fee()
def get(self): data = General().supply() return utils.response(data)
def get(self): return General().info()
def plain_tip_height(): data = General().info() return Response(str(data["result"]["blocks"]), mimetype="text/plain")
def get(self): data = General().price() return utils.response(data['beyondcoin'])
def get(self): data = General().price() return utils.response(data['mochimo'])
def getprice(): data = General().getprice() return jsonify(utils.response(data))
def get(self): parser = reqparse.RequestParser() parser.add_argument("currency", type=str, default="RPD") args = parser.parse_args() return General().price(args["currency"])
def get(self): data = General().price() return utils.response(data["sugarchain"])
def get(self): return General().mempool()
def mempool_info(): return jsonify(General().mempool())
def get(self): return General().fee()
def estimate_fee(): return jsonify(General().fee())
def get(self): data = int(utils.amount(General().supply()['supply'])) return Response(str(data), mimetype='text/plain')
def get_info(): return jsonify(General().info())
def GetInfo(): return General().info()
def GetPrice(currency="RPD"): return General().price(currency)