@@ -83,7 +83,11 @@ def self.get_epoch_info(epoch)
8383 end
8484
8585 def self . ckb_transaction_fee ( ckb_transaction )
86- ckb_transaction . inputs . sum ( :capacity ) - ckb_transaction . outputs . sum ( :capacity )
86+ if ckb_transaction . inputs . dao . present?
87+ dao_withdraw_tx_fee ( ckb_transaction )
88+ else
89+ normal_tx_fee ( ckb_transaction )
90+ end
8791 end
8892
8993 def self . get_unspent_cells ( address_hash )
@@ -143,4 +147,25 @@ def self.update_target_block_miner_address_pending_rewards(current_block)
143147 miner_address = target_block . miner_address
144148 Address . decrement_counter ( :pending_reward_blocks_count , miner_address . id , touch : true ) if miner_address . present?
145149 end
150+
151+ def self . normal_tx_fee ( ckb_transaction )
152+ ckb_transaction . inputs . sum ( :capacity ) - ckb_transaction . outputs . sum ( :capacity )
153+ end
154+
155+ def self . dao_withdraw_tx_fee ( ckb_transaction )
156+ dao_cells = ckb_transaction . inputs . dao
157+ witnesses = ckb_transaction . witnesses
158+ deps = ckb_transaction . deps
159+ interests =
160+ dao_cells . reduce ( 0 ) do |memo , dao_cell |
161+ witness = witnesses [ dao_cell . cell_index ]
162+ dep = deps [ witness [ "data" ] . last . hex ]
163+ out_point = CKB ::Types ::OutPoint . new ( cell : CKB ::Types ::CellOutPoint . new ( tx_hash : dao_cell . tx_hash , index : dao_cell . cell_index ) )
164+ memo + CkbSync ::Api . instance . calculate_dao_maximum_withdraw ( out_point , dep [ "block_hash" ] ) . to_i - dao_cell . capacity . to_i
165+ end
166+
167+ ckb_transaction . inputs . sum ( :capacity ) + interests - ckb_transaction . outputs . sum ( :capacity )
168+ rescue CKB ::RPCError
169+ 0
170+ end
146171end
0 commit comments