Skip to content

Commit

Permalink
Merge pull request #1884 from nervosnetwork/develop
Browse files Browse the repository at this point in the history
Deploy to testnet
  • Loading branch information
rabbitz authored May 24, 2024
2 parents b8a09b4 + 97b6f5c commit 959ca91
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 11 deletions.
22 changes: 22 additions & 0 deletions app/controllers/api/v2/bitcoin_addresses_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Api
module V2
class BitcoinAddressesController < BaseController
def show
expires_in 1.minute, public: true, must_revalidate: true, stale_while_revalidate: 10.seconds

address = Addresses::Explore.run!(key: params[:id])
live_cells_count = ->(status) do
BitcoinVout.includes(:ckb_address, :cell_output).where(
ckb_address: { id: address.map(&:id) },
bitcoin_vouts: { status: },
cell_outputs: { status: "live" },
).count
end
unbound_live_cells_count = live_cells_count.call("unbound")
bound_live_cells_count = live_cells_count.call("bound")

render json: { unbound_live_cells_count:, bound_live_cells_count: }
end
end
end
end
11 changes: 10 additions & 1 deletion app/controllers/api/v2/ckb_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,25 @@ def rgb_digest
bitcoin_vouts: { ckb_transaction_id: @ckb_transaction.id },
)
op_return = @ckb_transaction.bitcoin_vouts.find_by(op_return: true)

if op_return && bitcoin_transaction
txid = bitcoin_transaction.txid
commitment = op_return.commitment
confirmations = bitcoin_transaction.confirmations
leap_direction = @ckb_transaction.leap_direction
transfer_step = @ckb_transaction.transfer_step

calculated_commitment = begin
CkbUtils.calculate_commitment(@ckb_transaction)
rescue StandardError
nil
end
commitment_verified = calculated_commitment == commitment
end

render json: {
data: { txid:, confirmations:, commitment:, leap_direction:, transfer_step:, transfers: },
data: { txid:, confirmations:, commitment:, leap_direction:,
transfer_step:, transfers:, commitment_verified: },
}
end

Expand Down
2 changes: 1 addition & 1 deletion app/jobs/csv_exportable/export_dao_depositors_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module CsvExportable
class ExportDaoDepositorsJob < BaseExporter
def perform(args)
sql = ""
sql = "".dup

if args[:start_date].present?
sql << "ckb_transactions.block_timestamp >= #{BigDecimal(args[:start_date])}"
Expand Down
4 changes: 4 additions & 0 deletions app/models/concerns/ckb_transactions/display_cells.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def cellbase_display_outputs
secondary_reward: cellbase.secondary_reward,
status: output.status,
consumed_tx_hash:,
generated_tx_hash: output.tx_hash,
cell_index: output.cell_index,
)
end
end
Expand Down Expand Up @@ -134,6 +136,8 @@ def normal_tx_display_outputs(cell_outputs_for_display)
status: output.status,
consumed_tx_hash:,
cell_type: output.cell_type,
generated_tx_hash: output.tx_hash,
cell_index: output.cell_index,
}

display_output.merge!(attributes_for_udt_cell(output)) if output.udt?
Expand Down
6 changes: 6 additions & 0 deletions app/serializers/address_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class AddressSerializer
udt_type: udt_account.udt_type,
display_name: udt_account.display_name,
uan: udt_account.uan,
udt_type_script: udt_account.udt.type_script,
}
elsif udt_account.udt_type == "xudt"
{
Expand All @@ -56,6 +57,7 @@ class AddressSerializer
amount: udt_account.amount.to_s,
type_hash: udt_account.type_hash,
udt_type: udt_account.udt_type,
udt_type_script: udt_account.udt.type_script,
}
elsif udt_account.udt_type == "omiga_inscription"
info = udt_account.udt.omiga_inscription_info
Expand All @@ -68,6 +70,7 @@ class AddressSerializer
udt_amount: udt_account.udt.total_amount.to_s,
expected_supply: info.expected_supply.to_s,
mint_status: info.mint_status,
udt_type_script: udt_account.udt.type_script,
}
elsif udt_account.udt_type == "m_nft_token"
ts = TypeScript.find_by script_hash: udt_account.type_hash
Expand All @@ -85,6 +88,7 @@ class AddressSerializer
},
udt_icon_file: udt_account.udt_icon_file,
udt_type: udt_account.udt_type,
udt_type_script: udt_account.udt.type_script,
}
elsif udt_account.udt_type == "nrc_721_token"
udt = udt_account.udt
Expand All @@ -106,6 +110,7 @@ class AddressSerializer
},
udt_icon_file: "#{udt_account.udt.nrc_factory_cell&.base_token_uri}/#{udt_account.nft_token_id}",
udt_type: udt_account.udt_type,
udt_type_script: udt.type_script,
}
elsif udt_account.udt_type == "spore_cell"
ts = TypeScript.where(script_hash: udt_account.type_hash).first
Expand All @@ -123,6 +128,7 @@ class AddressSerializer
},
udt_icon_file: data,
udt_type: udt_account.udt_type,
udt_type_script: udt_account.udt.type_script,
}
end
end
Expand Down
3 changes: 2 additions & 1 deletion app/workers/bitcoin_transaction_detect_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ def build_bitcoin_annotations!
leap_direction, transfer_step = annotation_workflow_attributes(transaction)
tags = annotation_tags(transaction)
annotations << { ckb_transaction_id: transaction.id, leap_direction:, transfer_step:, tags: }
BitcoinAnnotation.upsert_all(annotations, unique_by: [:ckb_transaction_id]) if annotations.present?
end

BitcoinAnnotation.upsert_all(annotations, unique_by: [:ckb_transaction_id]) if annotations.present?
end

def annotation_workflow_attributes(transaction)
Expand Down
1 change: 1 addition & 0 deletions config/routes/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@

resources :rgb_transactions, only: :index
resources :bitcoin_statistics, only: :index
resources :bitcoin_addresses, only: :show
end
end
4 changes: 4 additions & 0 deletions test/controllers/api/v1/addresses_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class AddressesControllerTest < ActionDispatch::IntegrationTest
"udt_type" => udt_account.udt_type,
"display_name" => nil,
"uan" => nil,
"udt_type_script" => nil,
},
], json.dig("data", 0, "attributes", "udt_accounts")
end
Expand Down Expand Up @@ -221,6 +222,7 @@ class AddressesControllerTest < ActionDispatch::IntegrationTest
"udt_icon_file" => "https://dev.nrc.com/1a2b3c",
"udt_type" => udt_account.udt_type,
"collection" => { "type_hash" => type_script.script_hash },
"udt_type_script" => nil,
},
], json.dig("data", 0, "attributes", "udt_accounts")
end
Expand All @@ -247,6 +249,7 @@ class AddressesControllerTest < ActionDispatch::IntegrationTest
"udt_icon_file" => cell_data.hex_data,
"udt_type" => udt_account.udt_type,
"collection" => { "type_hash" => cluster_type.script_hash },
"udt_type_script" => nil,
},
], json.dig("data", 0, "attributes", "udt_accounts")
end
Expand All @@ -270,6 +273,7 @@ class AddressesControllerTest < ActionDispatch::IntegrationTest
"udt_amount" => udt_account.udt.total_amount.to_s,
"expected_supply" => info.expected_supply.to_s,
"mint_status" => info.mint_status,
"udt_type_script" => udt.type_script&.transform_keys(&:to_s),
},
], json.dig("data", 0, "attributes", "udt_accounts")
end
Expand Down
28 changes: 24 additions & 4 deletions test/models/ckb_sync/node_data_processor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1489,8 +1489,21 @@ class NodeDataProcessorTest < ActiveSupport::TestCase
output = local_ckb_transactions.first.outputs.order(:id).first
cellbase = Cellbase.new(local_block)
expected_display_outputs = [
CkbUtils.hash_value_to_s(id: output.id, capacity: output.capacity, occupied_capacity: output.occupied_capacity,
address_hash: output.address_hash, target_block_number: cellbase.target_block_number, base_reward: cellbase.base_reward, commit_reward: cellbase.commit_reward, proposal_reward: cellbase.proposal_reward, secondary_reward: cellbase.secondary_reward, status: "live", consumed_tx_hash: nil),
CkbUtils.hash_value_to_s(
id: output.id,
capacity: output.capacity,
occupied_capacity: output.occupied_capacity,
address_hash: output.address_hash,
target_block_number: cellbase.target_block_number,
base_reward: cellbase.base_reward,
commit_reward: cellbase.commit_reward,
proposal_reward: cellbase.proposal_reward,
secondary_reward: cellbase.secondary_reward,
status: "live",
consumed_tx_hash: nil,
generated_tx_hash: output.tx_hash,
cell_index: output.cell_index,
),
]

assert_equal expected_display_outputs, local_block_cell_outputs
Expand Down Expand Up @@ -1533,7 +1546,10 @@ class NodeDataProcessorTest < ActiveSupport::TestCase
block.cellbase.cell_outputs.order(:id).map do |cell_output|
consumed_tx_hash = cell_output.live? ? nil : cell_output.consumed_by.tx_hash
CkbUtils.hash_value_to_s(id: cell_output.id, capacity: cell_output.capacity, occupied_capacity: cell_output.occupied_capacity,
address_hash: cell_output.address_hash, target_block_number: cellbase.target_block_number, base_reward: cellbase.base_reward, commit_reward: cellbase.commit_reward, proposal_reward: cellbase.proposal_reward, secondary_reward: cellbase.secondary_reward, status: cell_output.status, consumed_tx_hash:)
address_hash: cell_output.address_hash, target_block_number: cellbase.target_block_number,
base_reward: cellbase.base_reward, commit_reward: cellbase.commit_reward, proposal_reward: cellbase.proposal_reward,
secondary_reward: cellbase.secondary_reward, status: cell_output.status, consumed_tx_hash:, generated_tx_hash: cell_output.tx_hash,
cell_index: cell_output.cell_index)
end
assert_equal expected_cellbase_display_outputs,
block.cellbase.display_outputs
Expand Down Expand Up @@ -1577,7 +1593,11 @@ class NodeDataProcessorTest < ActiveSupport::TestCase
cell_output = block.cellbase.cell_outputs.first
expected_cellbase_display_outputs = [
CkbUtils.hash_value_to_s(id: cell_output.id,
capacity: cell_output.capacity, occupied_capacity: cell_output.occupied_capacity, address_hash: cell_output.address_hash, target_block_number: cellbase.target_block_number, base_reward: cellbase.base_reward, commit_reward: cellbase.commit_reward, proposal_reward: cellbase.proposal_reward, secondary_reward: cellbase.secondary_reward, status: "live", consumed_tx_hash: nil),
capacity: cell_output.capacity, occupied_capacity: cell_output.occupied_capacity,
address_hash: cell_output.address_hash, target_block_number: cellbase.target_block_number,
base_reward: cellbase.base_reward, commit_reward: cellbase.commit_reward, proposal_reward: cellbase.proposal_reward,
secondary_reward: cellbase.secondary_reward, status: "live", consumed_tx_hash: nil, generated_tx_hash: cell_output.tx_hash,
cell_index: cell_output.cell_index),
]

assert_equal expected_cellbase_display_outputs,
Expand Down
26 changes: 22 additions & 4 deletions test/models/ckb_transaction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class CkbTransactionTest < ActiveSupport::TestCase
:with_multiple_inputs_and_outputs)
expected_attributes = %i(
id capacity occupied_capacity address_hash status consumed_tx_hash
cell_type
cell_type generated_tx_hash cell_index
).sort

assert_equal [expected_attributes],
Expand All @@ -120,7 +120,8 @@ class CkbTransactionTest < ActiveSupport::TestCase
is_cellbase: true, block:)
expected_attributes = %i(
id capacity occupied_capacity address_hash target_block_number
base_reward commit_reward proposal_reward secondary_reward status consumed_tx_hash
base_reward commit_reward proposal_reward secondary_reward status
consumed_tx_hash generated_tx_hash cell_index
)

assert_equal [expected_attributes],
Expand Down Expand Up @@ -309,8 +310,17 @@ class CkbTransactionTest < ActiveSupport::TestCase
cell_type
).sort
consumed_tx_hash = dao_output.live? ? nil : dao_output.consumed_by.tx_hash
expected_display_output = CkbUtils.hash_value_to_s(id: dao_output.id,
capacity: dao_output.capacity, occupied_capacity: dao_output.occupied_capacity, address_hash: dao_output.address_hash, status: dao_output.status, consumed_tx_hash:, cell_type: dao_output.cell_type).sort
expected_display_output = CkbUtils.hash_value_to_s(
id: dao_output.id,
capacity: dao_output.capacity,
occupied_capacity: dao_output.occupied_capacity,
address_hash: dao_output.address_hash,
status: dao_output.status,
consumed_tx_hash:,
cell_type: dao_output.cell_type,
generated_tx_hash: dao_output.tx_hash,
cell_index: dao_output.cell_index,
).sort
display_outputs = ckb_transaction.display_outputs
assert_equal expected_attributes - display_outputs.first.keys, []
assert_equal expected_display_output, display_outputs.first.sort
Expand Down Expand Up @@ -393,6 +403,8 @@ class CkbTransactionTest < ActiveSupport::TestCase
status: udt_cell_output.status,
consumed_tx_hash: nil,
cell_type: udt_cell_output.cell_type,
generated_tx_hash: udt_cell_output.tx_hash,
cell_index: udt_cell_output.cell_index,
extra_info: udt_cell_output.udt_info,
)
o = udt_output_transaction.display_outputs.first
Expand Down Expand Up @@ -573,6 +585,8 @@ class CkbTransactionTest < ActiveSupport::TestCase
consumed_tx_hash: nil,
cell_type: m_nft_cell_output.cell_type,
extra_info: m_nft_cell_output.m_nft_info,
generated_tx_hash: m_nft_cell_output.tx_hash,
cell_index: m_nft_cell_output.cell_index,
)
o = m_nft_output_transaction.display_outputs.first
assert_equal expected_attributes - o.keys, []
Expand Down Expand Up @@ -601,6 +615,8 @@ class CkbTransactionTest < ActiveSupport::TestCase
status: m_nft_cell_output.status,
consumed_tx_hash: nil,
cell_type: m_nft_cell_output.cell_type,
generated_tx_hash: m_nft_cell_output.tx_hash,
cell_index: m_nft_cell_output.cell_index,
extra_info: m_nft_cell_output.m_nft_info,
)
o = m_nft_output_transaction.display_outputs.first
Expand Down Expand Up @@ -655,6 +671,8 @@ class CkbTransactionTest < ActiveSupport::TestCase
status: m_nft_cell_output.status,
consumed_tx_hash: nil,
cell_type: m_nft_cell_output.cell_type,
generated_tx_hash: m_nft_cell_output.tx_hash,
cell_index: m_nft_cell_output.cell_index,
extra_info: m_nft_cell_output.m_nft_info,
)
display_outputs = m_nft_output_transaction.display_outputs
Expand Down

0 comments on commit 959ca91

Please sign in to comment.