Skip to content

[Feature] Add multi-chain support foundation #17

@yellow-seed

Description

@yellow-seed

Transaction Debugger - マルチチェーン対応基盤

概要

複数のブロックチェーン(Polygon, BSC, Arbitrum等)に対応するための基盤を実装

実装内容

# lib/transaction_debugger/chains.rb
module TransactionDebugger
  class Chains
    SUPPORTED_CHAINS = {
      ethereum: {
        chain_id: 1,
        name: 'Ethereum Mainnet',
        rpc_urls: ['https://eth.llamarpc.com'],
        explorer: 'https://etherscan.io'
      },
      polygon: {
        chain_id: 137,
        name: 'Polygon',
        rpc_urls: ['https://polygon-rpc.com'],
        explorer: 'https://polygonscan.com'
      },
      arbitrum: {
        chain_id: 42161,
        name: 'Arbitrum One',
        rpc_urls: ['https://arb1.arbitrum.io/rpc'],
        explorer: 'https://arbiscan.io'
      },
      bsc: {
        chain_id: 56,
        name: 'BNB Smart Chain',
        rpc_urls: ['https://bsc-dataseed.binance.org'],
        explorer: 'https://bscscan.com'
      }
    }.freeze
    
    def self.get(chain_name)
      SUPPORTED_CHAINS[chain_name.to_sym] or raise Error, "Unsupported chain: #{chain_name}"
    end
    
    def self.detect_from_chain_id(chain_id)
      SUPPORTED_CHAINS.find { |_, config| config[:chain_id] == chain_id }&.first
    end
  end
end

Clientの拡張

# lib/transaction_debugger/client.rb に追加
module TransactionDebugger
  class Client
    def initialize(rpc_url = nil, chain: :ethereum)
      @chain_config = Chains.get(chain)
      @rpc_url = rpc_url || @chain_config[:rpc_urls].first
      # ... 既存のコード
    end
    
    def chain_id
      @chain_config[:chain_id]
    end
    
    def explorer_url(tx_hash)
      "#{@chain_config[:explorer]}/tx/#{tx_hash}"
    end
  end
end

CLIの拡張

# 使用例
tx-debug analyze 0xTX_HASH --chain polygon
tx-debug analyze 0xTX_HASH --chain arbitrum

完了条件

  • 主要チェーンの設定が追加されている
  • Clientが複数チェーンに対応している
  • CLIで --chain オプションが使える
  • エクスプローラーURLが正しく生成される
  • テストが全てパスする

Phase

Phase 3 - 高度な機能

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions