Skip to content

Commit

Permalink
feat: fiber graph channel add closed_transaction_info
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz committed Dec 3, 2024
1 parent 1c3084e commit 539fe1b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
24 changes: 19 additions & 5 deletions app/models/fiber_graph_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,30 @@ class FiberGraphChannel < ApplicationRecord

scope :open_channels, -> { where(closed_transaction_id: nil) }

def outpoint_info
open_transaction.as_json(only: %i[tx_hash block_number block_timestamp transaction_fee]).merge(
def open_transaction_info
open_transaction.as_json(only: %i[tx_hash block_number block_timestamp]).merge(
{
funding_capacity: funding_cell.capacity,
funding_udt_amount: funding_cell.udt_amount,
funding_address: funding_cell.address_hash,
capacity: funding_cell.capacity,
udt_amount: funding_cell.udt_amount,
address: funding_cell.address_hash,
},
)
end

def closed_transaction_info
return Hash.new unless closed_transaction

closed_transaction.as_json(only: %i[tx_hash block_number block_timestamp]).merge(
close_accounts: closed_transaction.outputs.map do |cell|
{
capacity: cell.capacity,
udt_amount: cell.udt_amount,
address: cell.address_hash,
}
end,
)
end

def udt_info
udt&.as_json(only: %i[full_name symbol decimal icon_file])
end
Expand Down
7 changes: 6 additions & 1 deletion app/models/suggest_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ def find_bitcoin_address
end

def find_fiber_graph_nodes
normalized_key = QueryKeyUtils.hex_string?(query_key) ? query_key.delete_prefix(Settings.default_hash_prefix) : query_key
normalized_key =
if QueryKeyUtils.start_with_default_hash_prefix?(query_key)
query_key.delete_prefix(Settings.default_hash_prefix)
else
query_key
end
fiber_graph_nodes = FiberGraphNode.where("alias = :query_key or peer_id = :query_key or node_id = :query_key", query_key: normalized_key)
FiberGraphNodeSerializer.new(fiber_graph_nodes) if fiber_graph_nodes.present?
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/api/v2/fiber/graph_channels/index.jbuilder
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
json.data do
json.fiber_graph_channels @channels do |channel|
json.(channel, :channel_outpoint, :node1, :node2, :chain_hash, :outpoint_info)
json.(channel, :channel_outpoint, :node1, :node2, :chain_hash, :open_transaction_info, :closed_transaction_info)
json.funding_tx_block_number channel.funding_tx_block_number.to_s
json.funding_tx_index channel.funding_tx_index.to_s
json.last_updated_timestamp channel.last_updated_timestamp.to_s
Expand Down
2 changes: 1 addition & 1 deletion app/views/api/v2/fiber/graph_nodes/show.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ json.data do
json.udt_cfg_infos @node.udt_cfg_infos

json.fiber_graph_channels @graph_channels do |channel|
json.(channel, :channel_outpoint, :node1, :node2, :chain_hash, :outpoint_info)
json.(channel, :channel_outpoint, :node1, :node2, :chain_hash, :open_transaction_info, :closed_transaction_info)
json.funding_tx_block_number channel.funding_tx_block_number.to_s
json.funding_tx_index channel.funding_tx_index.to_s
json.last_updated_timestamp channel.last_updated_timestamp.to_s
Expand Down

0 comments on commit 539fe1b

Please sign in to comment.