Skip to content

Commit

Permalink
Merge pull request #2199 from rabbitz/feat/fiber
Browse files Browse the repository at this point in the history
chore: rename sent_tlc_balance column
  • Loading branch information
rabbitz committed Sep 20, 2024
2 parents 48be771 + ec741f0 commit 679d473
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v2/fiber/peers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def index
end

def show
@peer = FiberPeer.find_by(id: params[:id])
@peer = FiberPeer.find_by(peer_id: params[:peer_id])
raise Api::V2::Exceptions::FiberPeerNotFoundError unless @peer
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/fiber_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FiberChannel < ApplicationRecord
# state_name :string
# state_flags :string default([]), is an Array
# local_balance :decimal(64, 2) default(0.0)
# sent_tlc_balance :decimal(64, 2) default(0.0)
# offered_tlc_balance :decimal(64, 2) default(0.0)
# remote_balance :decimal(64, 2) default(0.0)
# received_tlc_balance :decimal(64, 2) default(0.0)
# shutdown_at :datetime
Expand Down
2 changes: 2 additions & 0 deletions app/models/fiber_peer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class FiberPeer < ApplicationRecord
has_many :fiber_channels, dependent: :destroy
# has_many :fiber_transactions

validates :peer_id, presence: true, uniqueness: true

def total_local_balance
fiber_channels.where(state_name: "CHANNEL_READY").sum(:local_balance)
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/api/v2/fiber/peers/index.jbuilder
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
json.data do
json.fiber_peers @peers do |peer|
json.(peer, :id, :name, :peer_id, :rpc_listening_addr, :first_channel_opened_at,:last_channel_updated_at, :channels_count)
json.(peer, :name, :peer_id, :rpc_listening_addr, :first_channel_opened_at,:last_channel_updated_at, :channels_count)
json.total_local_balance peer.total_local_balance.to_s
end
end
1 change: 1 addition & 0 deletions app/views/api/v2/fiber/peers/show.jbuilder
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
json.data do
json.(@peer, :peer_id, :rpc_listening_addr, :first_channel_opened_at, :last_channel_updated_at)
json.fiber_channels @peer.fiber_channels do |peer_channel|
json.peer_id peer_channel.peer_id
json.channel_id peer_channel.channel_id
json.state_name peer_channel.state_name
json.state_flags peer_channel.state_flags
Expand Down
4 changes: 2 additions & 2 deletions app/workers/fiber_detect_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def sync_with_fiber_channels(fiber_peer)
end

def build_channels_attributes(fiber_peer)
data = rpc.list_channels(fiber_peer.rpc_listening_addr, { peer_id: fiber_peer.peer_id })
data = rpc.list_channels(fiber_peer.rpc_listening_addr, { peer_id: nil })
data["result"]["channels"].map do |channel|
{
fiber_peer_id: fiber_peer.id,
Expand All @@ -24,7 +24,7 @@ def build_channels_attributes(fiber_peer)
state_name: channel["state"]["state_name"],
state_flags: parse_state_flags(channel["state"]["state_flags"]),
local_balance: channel["local_balance"].to_i(16),
sent_tlc_balance: channel["sent_tlc_balance"].to_i(16),
offered_tlc_balance: channel["offered_tlc_balance"].to_i(16),
remote_balance: channel["remote_balance"].to_i(16),
received_tlc_balance: channel["received_tlc_balance"].to_i(16),
created_at: Time.at(channel["created_at"].to_i(16) / 10**6),
Expand Down
2 changes: 1 addition & 1 deletion config/routes/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
end
resources :rgb_live_cells, only: :index
namespace :fiber do
resources :peers, only: %i[index show create]
resources :peers, param: :peer_id, only: %i[index show create]
resources :channels, param: :channel_id, only: :show
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class AddFiberPeerIdToFiberChannels < ActiveRecord::Migration[7.0]
def change
rename_column :fiber_channels, :sent_tlc_balance, :offered_tlc_balance
add_column :fiber_channels, :fiber_peer_id, :integer
add_index :fiber_channels, :fiber_peer_id
end
Expand Down
2 changes: 1 addition & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ CREATE TABLE public.fiber_channels (
state_name character varying,
state_flags character varying[] DEFAULT '{}'::character varying[],
local_balance numeric(64,2) DEFAULT 0.0,
sent_tlc_balance numeric(64,2) DEFAULT 0.0,
offered_tlc_balance numeric(64,2) DEFAULT 0.0,
remote_balance numeric(64,2) DEFAULT 0.0,
received_tlc_balance numeric(64,2) DEFAULT 0.0,
shutdown_at timestamp(6) without time zone,
Expand Down

0 comments on commit 679d473

Please sign in to comment.