-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2304 from nervosnetwork/testnet
Deploy to mainnet
- Loading branch information
Showing
134 changed files
with
2,656 additions
and
2,181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Api | ||
module V2 | ||
module Fiber | ||
class ChannelsController < BaseController | ||
def show | ||
@channel = FiberChannel.find_by(channel_id: params[:channel_id]) | ||
raise Api::V2::Exceptions::FiberChannelNotFoundError unless @channel | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Api | ||
module V2 | ||
module Fiber | ||
class GraphChannelsController < BaseController | ||
def index | ||
@page = params.fetch(:page, 1) | ||
@page_size = params.fetch(:page_size, FiberPeer.default_per_page) | ||
@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 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Api | ||
module V2 | ||
module Fiber | ||
class GraphNodesController < BaseController | ||
def index | ||
@page = params.fetch(:page, 1) | ||
@page_size = params.fetch(:page_size, FiberGraphNode.default_per_page) | ||
@nodes = | ||
if params[:q].present? | ||
FiberGraphNode.where("alias = :q or peer_id = :q or node_id = :q", q: params[:q]).page(@page).per(@page_size) | ||
else | ||
FiberGraphNode.all.page(@page).per(@page_size) | ||
end | ||
end | ||
|
||
def show | ||
@node = FiberGraphNode.find_by(node_id: params[:node_id]) | ||
raise Api::V2::Exceptions::FiberGraphNodeNotFoundError unless @node | ||
|
||
@graph_channels = FiberGraphChannel.where(node1: params[:node_id]).or( | ||
FiberGraphChannel.where(node2: params[:node_id]), | ||
) | ||
|
||
if params[:status] == "closed" | ||
@graph_channels = @graph_channels.where.not(closed_transaction_id: nil) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module Api | ||
module V2 | ||
module Fiber | ||
class PeersController < BaseController | ||
before_action :test_connection, only: :create | ||
|
||
def index | ||
@page = params.fetch(:page, 1) | ||
@page_size = params.fetch(:page_size, FiberPeer.default_per_page) | ||
@peers = FiberPeer.all.page(@page).per(@page_size) | ||
end | ||
|
||
def show | ||
@peer = FiberPeer.find_by(peer_id: params[:peer_id]) | ||
raise Api::V2::Exceptions::FiberPeerNotFoundError unless @peer | ||
end | ||
|
||
def create | ||
fiber_peer = FiberPeer.find_or_initialize_by(peer_id: fiber_peer_params[:peer_id]) | ||
fiber_peer.name = fiber_peer_params[:name] | ||
new_rpc = Array(fiber_peer_params[:rpc_listening_addr]) | ||
fiber_peer.rpc_listening_addr = (fiber_peer.rpc_listening_addr + new_rpc).uniq | ||
fiber_peer.save! | ||
|
||
FiberDetectWorker.perform_async(fiber_peer.peer_id) | ||
|
||
head :no_content | ||
rescue ActiveRecord::RecordInvalid => e | ||
raise Api::V2::Exceptions::FiberPeerParamsInvalidError.new(e.message) | ||
end | ||
|
||
private | ||
|
||
def fiber_peer_params | ||
params.permit(:name, :peer_id, :rpc_listening_addr) | ||
end | ||
|
||
def test_connection | ||
FiberCoordinator.instance.list_channels(fiber_peer_params[:rpc_listening_addr], { "peer_id": nil }) | ||
rescue StandardError => e | ||
raise Api::V2::Exceptions::FiberPeerParamsInvalidError.new(e.message) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.