@@ -3,11 +3,14 @@ module V2
33 class CkbTransactionsController < BaseController
44 include CellDataComparator
55
6- before_action :set_ckb_transaction
76 before_action :set_pagination_params , only : %i[ display_inputs display_outputs ]
87
98 def details
109 expires_in 10 . seconds , public : true , must_revalidate : true
10+
11+ @ckb_transaction = CkbTransaction . includes ( :cell_inputs => [ :previous_cell_output ] , :cell_outputs => { } ) . find_by ( tx_hash : params [ :id ] )
12+ return head :not_found unless @ckb_transaction
13+
1114 transfers = compare_cells ( @ckb_transaction )
1215
1316 render json : { data : transfers }
@@ -16,6 +19,9 @@ def details
1619 def display_inputs
1720 expires_in 15 . seconds , public : true , must_revalidate : true
1821
22+ @ckb_transaction = CkbTransaction . includes ( :cell_inputs => [ :previous_cell_output ] ) . find_by ( tx_hash : params [ :id ] )
23+ return head :not_found unless @ckb_transaction
24+
1925 if @ckb_transaction . is_cellbase
2026 cell_inputs = @ckb_transaction . cellbase_display_inputs
2127 total_count = cell_inputs . count
@@ -35,12 +41,15 @@ def display_inputs
3541 def display_outputs
3642 expires_in 15 . seconds , public : true , must_revalidate : true
3743
44+ @ckb_transaction = CkbTransaction . includes ( :cell_outputs => { } ) . find_by ( tx_hash : params [ :id ] )
45+ return head :not_found unless @ckb_transaction
46+
3847 if @ckb_transaction . is_cellbase
3948 cell_outputs = @ckb_transaction . cellbase_display_outputs . sort_by { |output | output [ :id ] . to_i }
4049 cell_outputs = Kaminari . paginate_array ( cell_outputs ) . page ( @page ) . per ( @page_size )
4150 total_count = cell_outputs . total_count
4251 else
43- cell_outputs = @ckb_transaction . outputs . order ( id : :asc ) .
52+ cell_outputs = @ckb_transaction . cell_outputs . order ( id : :asc ) .
4453 page ( @page ) . per ( @page_size ) . fast_page
4554 total_count = cell_outputs . total_count
4655 cell_outputs = @ckb_transaction . normal_tx_display_outputs ( cell_outputs )
@@ -55,6 +64,9 @@ def display_outputs
5564 def rgb_digest
5665 expires_in 10 . seconds , public : true , must_revalidate : true
5766
67+ @ckb_transaction = CkbTransaction . includes ( :cell_inputs => [ :previous_cell_output ] , :cell_outputs => { } ) . find_by ( tx_hash : params [ :id ] )
68+ return head :not_found unless @ckb_transaction
69+
5870 transfers = [ ] . tap do |res |
5971 combine_transfers ( @ckb_transaction ) . each do |address_id , transfers |
6072 vout = BitcoinVout . includes ( :bitcoin_address ) . find_by ( address_id :)
@@ -92,11 +104,6 @@ def rgb_digest
92104
93105 private
94106
95- def set_ckb_transaction
96- @ckb_transaction = CkbTransaction . find_by ( tx_hash : params [ :id ] )
97- return head :not_found unless @ckb_transaction
98- end
99-
100107 def set_pagination_params
101108 @page = params . fetch ( :page , 1 )
102109 @page_size = params . fetch ( :page_size , CkbTransaction . default_per_page )
0 commit comments