Skip to content

Commit

Permalink
Improve the monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
koirikivi committed Apr 20, 2024
1 parent 5c64392 commit 7cce03b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 14 deletions.
48 changes: 44 additions & 4 deletions bridge_node/bridge/api/monitor/templates/monitor.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
<h2>Rune Deposits</h1>
<table>
<tr>
<th>rune</th>
<th>amount</th>
<th>tx_id:vout</th>
<th>block</th>
<th>amount</th>
<th>evm_tx_hash</th>
<th>status</th>
<th>created_at</th>
</tr>
{% for deposit in rune_deposits %}
<tr>
<th>{{ deposit.rune.spaced_name }}</th>
<td>{{ deposit.transfer_amount_raw / (10**deposit.rune.divisibility) }}</td>
<td>{{ deposit.tx_id }}:{{ deposit.vout }}</td>
<td>{{ deposit.block_number }}</td>
<td>{{ deposit.transfer_amount_raw / (10**deposit.rune.divisibility) }}</td>
<td>{{ deposit.evm_tx_hash }}</td>
<td>{{ deposit.status }}</td>
<td>{{ deposit.created_at }}</td>
Expand All @@ -29,23 +31,61 @@
<h2>Rune Token Deposits</h1>
<table>
<tr>
<th>rune</th>
<th>amount</th>
<th>evm_block_number</th>
<th>evm_tx_hash</th>
<th>receiver_btc_address</th>
<th>transferred_token_amount</th>
<th>status</th>
<th>created_at</th>
</tr>
{% for deposit in rune_token_deposits %}
<tr>
<th>{{ deposit.rune.spaced_name }}</th>
<td>{{ deposit.transferred_token_amount / (10**18) }}</td>
<td>{{ deposit.evm_block_number }}</td>
<td>{{ deposit.evm_tx_hash }}</td>
<td>{{ deposit.receiver_btc_address }}</td>
<td>{{ deposit.transferred_token_amount / (10**18) }}</td>
<td>{{ deposit.status }}</td>
<td>{{ deposit.created_at }}</td>
</tr>
{% endfor %}
<table>

<h2>Incoming Bitcoin Transactions</h1>
<table>
<tr>
<th>tx_id:vout</th>
<th>block</th>
<th>amount</th>
<th>num_rune_deposits</th>
<th>status</th>
<th>created_at</th>
</tr>
{% for tx in incoming_btc_txs %}
<tr>
<td>{{ tx.tx_id }}:{{ deposit.vout }}</td>
<td>{{ tx.block_number }}</td>
<td>{{ tx.amount_sat / (10**8) }}</td>
<td>{{ deposit.rune_deposits|length }}</td>
<td>{{ deposit.status }}</td>
<td>{{ deposit.created_at }}</td>
</tr>
{% endfor %}
</table>

<h2>Incoming Bitcoin Transactions</h1>
<table>
<tr>
<th>name</th>
<th>num_deposits</th>
</tr>
{% for rune in runes %}
<tr>
<td>{{ rune.spaced_name }}</td>
<td>{{ rune.deposits|length }}</td>
</tr>
{% endfor %}
</table>
</body>
</html>
30 changes: 21 additions & 9 deletions bridge_node/bridge/api/monitor/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from ...bridges.runes.models import (
Bridge,
Rune,
RuneDeposit,
RuneTokenDeposit,
IncomingBtcTx,
Expand Down Expand Up @@ -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,
)
Expand All @@ -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)
)
Expand All @@ -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")
4 changes: 3 additions & 1 deletion bridge_node/bridge/bridges/runes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down

0 comments on commit 7cce03b

Please sign in to comment.