diff --git a/app/controllers/api/v2/fiber/peers_controller.rb b/app/controllers/api/v2/fiber/peers_controller.rb index 61547b92e..1fb3b8731 100644 --- a/app/controllers/api/v2/fiber/peers_controller.rb +++ b/app/controllers/api/v2/fiber/peers_controller.rb @@ -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 diff --git a/app/models/fiber_channel.rb b/app/models/fiber_channel.rb index 5b16ea5ce..5db6d0f6e 100644 --- a/app/models/fiber_channel.rb +++ b/app/models/fiber_channel.rb @@ -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 diff --git a/app/models/fiber_peer.rb b/app/models/fiber_peer.rb index 35e040818..8843251c9 100644 --- a/app/models/fiber_peer.rb +++ b/app/models/fiber_peer.rb @@ -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 diff --git a/app/views/api/v2/fiber/peers/index.jbuilder b/app/views/api/v2/fiber/peers/index.jbuilder index 756fa5efb..c0dfce2e0 100644 --- a/app/views/api/v2/fiber/peers/index.jbuilder +++ b/app/views/api/v2/fiber/peers/index.jbuilder @@ -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 \ No newline at end of file diff --git a/app/views/api/v2/fiber/peers/show.jbuilder b/app/views/api/v2/fiber/peers/show.jbuilder index 2946b53ce..2ea20791f 100644 --- a/app/views/api/v2/fiber/peers/show.jbuilder +++ b/app/views/api/v2/fiber/peers/show.jbuilder @@ -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 diff --git a/app/workers/fiber_detect_worker.rb b/app/workers/fiber_detect_worker.rb index 9b8f4544f..ee8267748 100644 --- a/app/workers/fiber_detect_worker.rb +++ b/app/workers/fiber_detect_worker.rb @@ -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, @@ -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), diff --git a/config/routes/v2.rb b/config/routes/v2.rb index 446cf6cd6..b0cbf8fcc 100644 --- a/config/routes/v2.rb +++ b/config/routes/v2.rb @@ -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 diff --git a/db/migrate/20240920094807_add_fiber_peer_id_to_fiber_channels.rb b/db/migrate/20240920094807_add_fiber_peer_id_to_fiber_channels.rb index f80e003ad..375d2683d 100644 --- a/db/migrate/20240920094807_add_fiber_peer_id_to_fiber_channels.rb +++ b/db/migrate/20240920094807_add_fiber_peer_id_to_fiber_channels.rb @@ -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 diff --git a/db/structure.sql b/db/structure.sql index ade3e0627..c6e7b4b0d 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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,