Skip to content

Commit

Permalink
Merge pull request #2274 from rabbitz/feat/fiber
Browse files Browse the repository at this point in the history
chore: add filter to fiber graph channels
  • Loading branch information
rabbitz authored Nov 4, 2024
2 parents 227daad + 7dc7e9b commit a9fe97f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion app/controllers/api/v2/fiber/graph_channels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ class GraphChannelsController < BaseController
def index
@page = params.fetch(:page, 1)
@page_size = params.fetch(:page_size, FiberPeer.default_per_page)
@channels = FiberGraphChannel.all.page(@page).per(@page_size)
@channels = FiberGraphChannel.all
if params[:status] == "closed"
@channels = @channels.where.not(closed_transaction_id: nil)
end
@channels = @channels.page(@page).per(@page_size)
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions app/models/fiber_graph_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class FiberGraphNode < ApplicationRecord
has_many :fiber_udt_cfg_infos, dependent: :delete_all

def channel_links
FiberGraphChannel.where(node1: node_id).or(FiberGraphChannel.where(node2: node_id))
FiberGraphChannel.where(node1: node_id).or(FiberGraphChannel.where(node2: node_id)).
where(closed_transaction_id: nil)
end

def udt_cfg_infos
Expand All @@ -24,7 +25,7 @@ def connected_node_ids
end

def open_channels_count
channel_links.where(closed_transaction_id: nil).count
channel_links.count
end
end

Expand Down
1 change: 0 additions & 1 deletion app/views/api/v2/fiber/graph_nodes/index.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ json.data do
json.auto_accept_min_ckb_funding_amount node.auto_accept_min_ckb_funding_amount.to_s
json.total_capacity node.total_capacity.to_s
json.udt_cfg_infos node.udt_cfg_infos
json.channel_links_count node.channel_links.count
end
end
json.meta do
Expand Down

0 comments on commit a9fe97f

Please sign in to comment.