Skip to content

Commit

Permalink
Merge pull request #291 from bandprotocol/extra-rest-24-channels
Browse files Browse the repository at this point in the history
[Extra/rest 2.4] Add last_update column for channels
  • Loading branch information
taobun authored Apr 12, 2023
2 parents daab182 + a8d9362 commit 1e86bf7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions flusher/flusher/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,5 @@ def Column(*args, **kwargs):
Column("counterparty_channel", sa.String),
Column("state", sa.Integer),
Column("order", sa.String),
Column("last_update", CustomDateTime, index=True),
)
17 changes: 17 additions & 0 deletions flusher/flusher/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,20 +392,30 @@ def handle_set_request_count_per_day(self, msg):
)

def handle_new_incoming_packet(self, msg):
self.update_last_update_channel(msg['dst_port'], msg['dst_channel'], msg['block_time'])
del msg["block_time"]

msg["tx_id"] = self.get_transaction_id(msg["hash"])
del msg["hash"]
self.conn.execute(
insert(incoming_packets).values(**msg).on_conflict_do_nothing(constraint="incoming_packets_pkey")
)

def handle_new_outgoing_packet(self, msg):
self.update_last_update_channel(msg['src_port'], msg['src_channel'], msg['block_time'])
del msg["block_time"]

msg["tx_id"] = self.get_transaction_id(msg["hash"])
del msg["hash"]

self.conn.execute(
insert(outgoing_packets).values(**msg).on_conflict_do_nothing(constraint="outgoing_packets_pkey")
)

def handle_update_outgoing_packet(self, msg):
self.update_last_update_channel(msg['src_port'], msg['src_channel'], msg['block_time'])
del msg["block_time"]

condition = True
for col in outgoing_packets.primary_key.columns.values():
condition = (col == msg[col.name]) & condition
Expand Down Expand Up @@ -439,3 +449,10 @@ def handle_set_connection(self, msg):

def handle_set_channel(self, msg):
self.conn.execute(insert(channels).values(**msg).on_conflict_do_update(constraint="channels_pkey", set_=msg))

def update_last_update_channel(self, port, channel, timestamp):
self.conn.execute(
channels.update().where((channels.c.port == port) & (channels.c.channel == channel)).values(
last_update=timestamp
)
)
2 changes: 2 additions & 0 deletions hooks/emitter/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (h *Hook) emitSetChannel(ctx sdk.Context, portId string, channelId string)
"counterparty_channel": channel.Counterparty.ChannelId,
"state": channel.State,
"order": channel.Ordering,
"last_update": ctx.BlockTime().UnixNano(),
})
}

Expand Down Expand Up @@ -109,6 +110,7 @@ func newPacket(
) common.JsDict {
return common.JsDict{
"block_height": ctx.BlockHeight(),
"block_time": ctx.BlockTime().UnixNano(),
"src_channel": srcChannel,
"src_port": srcPort,
"sequence": sequence,
Expand Down

0 comments on commit 1e86bf7

Please sign in to comment.