From 7cce03b98c636619c6a37108bc740f7facdf0e73 Mon Sep 17 00:00:00 2001 From: Rainer Koirikivi Date: Sun, 21 Apr 2024 00:14:43 +0300 Subject: [PATCH] Improve the monitor --- .../api/monitor/templates/monitor.jinja2 | 48 +++++++++++++++++-- bridge_node/bridge/api/monitor/views.py | 30 ++++++++---- bridge_node/bridge/bridges/runes/models.py | 4 +- 3 files changed, 68 insertions(+), 14 deletions(-) diff --git a/bridge_node/bridge/api/monitor/templates/monitor.jinja2 b/bridge_node/bridge/api/monitor/templates/monitor.jinja2 index f5249b8..a6bc297 100644 --- a/bridge_node/bridge/api/monitor/templates/monitor.jinja2 +++ b/bridge_node/bridge/api/monitor/templates/monitor.jinja2 @@ -7,18 +7,20 @@

Rune Deposits

+ + - {% for deposit in rune_deposits %} + + - @@ -29,23 +31,61 @@

Rune Token Deposits

runeamount tx_id:vout blockamount evm_tx_hash status created_at
{{ deposit.rune.spaced_name }}{{ deposit.transfer_amount_raw / (10**deposit.rune.divisibility) }} {{ deposit.tx_id }}:{{ deposit.vout }} {{ deposit.block_number }}{{ deposit.transfer_amount_raw / (10**deposit.rune.divisibility) }} {{ deposit.evm_tx_hash }} {{ deposit.status }} {{ deposit.created_at }}
+ + - {% for deposit in rune_token_deposits %} + + - {% endfor %}
runeamount evm_block_number evm_tx_hash receiver_btc_addresstransferred_token_amount status created_at
{{ deposit.rune.spaced_name }}{{ deposit.transferred_token_amount / (10**18) }} {{ deposit.evm_block_number }} {{ deposit.evm_tx_hash }} {{ deposit.receiver_btc_address }}{{ deposit.transferred_token_amount / (10**18) }} {{ deposit.status }} {{ deposit.created_at }}
+ +

Incoming Bitcoin Transactions

+
+ + + + + + + + + {% for tx in incoming_btc_txs %} + + + + + + + + + {% endfor %} +
tx_id:voutblockamountnum_rune_depositsstatuscreated_at
{{ tx.tx_id }}:{{ deposit.vout }}{{ tx.block_number }}{{ tx.amount_sat / (10**8) }}{{ deposit.rune_deposits|length }}{{ deposit.status }}{{ deposit.created_at }}
+ +

Incoming Bitcoin Transactions

+ + + + + + {% for rune in runes %} + + + + + {% endfor %} +
namenum_deposits
{{ rune.spaced_name }}{{ rune.deposits|length }}
diff --git a/bridge_node/bridge/api/monitor/views.py b/bridge_node/bridge/api/monitor/views.py index d969ca1..6798cad 100644 --- a/bridge_node/bridge/api/monitor/views.py +++ b/bridge_node/bridge/api/monitor/views.py @@ -12,6 +12,7 @@ from ...bridges.runes.models import ( Bridge, + Rune, RuneDeposit, RuneTokenDeposit, IncomingBtcTx, @@ -39,8 +40,8 @@ def __init__(self, request): renderer="templates/monitor.jinja2", ) def monitor(self): - incoming_btc_txs = ( - self.dbsession.query(IncomingBtcTx) + rune_deposits = ( + self.dbsession.query(RuneDeposit) .filter_by( bridge_id=self.bridge_id, ) @@ -49,23 +50,33 @@ def monitor(self): ) .limit(100) ) - rune_deposits = ( - self.dbsession.query(RuneDeposit) + rune_token_deposits = ( + self.dbsession.query(RuneTokenDeposit) .filter_by( bridge_id=self.bridge_id, ) .order_by( - RuneDeposit.created_at.desc(), + RuneTokenDeposit.created_at.desc(), ) .limit(100) ) - rune_token_deposits = ( - self.dbsession.query(RuneTokenDeposit) + incoming_btc_txs = ( + self.dbsession.query(IncomingBtcTx) .filter_by( bridge_id=self.bridge_id, ) .order_by( - RuneTokenDeposit.created_at.desc(), + IncomingBtcTx.created_at.desc(), + ) + .limit(100) + ) + runes = ( + self.dbsession.query(Rune) + .filter_by( + bridge_id=self.bridge_id, + ) + .order_by( + Rune.id.desc(), ) .limit(100) ) @@ -74,9 +85,10 @@ def monitor(self): "rune_deposits": rune_deposits, "rune_token_deposits": rune_token_deposits, "incoming_btc_txs": incoming_btc_txs, + "runes": runes, } def includeme(config: Configurator): config.add_jinja2_search_path("/srv/bridge_backend/templates") - config.add_route("monitor_deposits", "/deposits/:bridge") + config.add_route("monitor_deposits", "/:bridge/deposits") diff --git a/bridge_node/bridge/bridges/runes/models.py b/bridge_node/bridge/bridges/runes/models.py index eb6a0e1..f8e9209 100644 --- a/bridge_node/bridge/bridges/runes/models.py +++ b/bridge_node/bridge/bridges/runes/models.py @@ -168,6 +168,8 @@ class Rune(Base): divisibility = Column(Integer, nullable=False) turbo = Column(Boolean, nullable=False) + deposits = relationship("RuneDeposit", back_populates="rune") + __table_args__ = (UniqueConstraint("bridge_id", "n", name="uq_rune_n"),) def __repr__(self): @@ -190,7 +192,7 @@ class RuneDeposit(Base): rune_number = Column(Uint128, nullable=False) rune_id = Column(Integer, ForeignKey("rune.id"), nullable=False) - rune = relationship(Rune) + rune = relationship(Rune, back_populates="deposits") user_id = Column(Integer, ForeignKey("user.id"), nullable=False) user = relationship(User)