@@ -8,12 +8,14 @@ import (
88 "net/http"
99
1010 "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
11- "github.com/ethereum-optimism/optimism/op-service/sources" // 新增导入
11+ "github.com/ethereum-optimism/optimism/op-service/client"
12+ "github.com/ethereum-optimism/optimism/op-service/sources"
1213 "github.com/ethereum/go-ethereum/accounts/abi/bind"
1314 "github.com/ethereum/go-ethereum/common"
14- "github.com/ethereum/go-ethereum/ethclient "
15+ gethlog "github.com/ethereum/go-ethereum/log "
1516 config "github.com/optimism-java/dispute-explorer/internal/types"
1617 "github.com/optimism-java/dispute-explorer/pkg/contract"
18+ "github.com/optimism-java/dispute-explorer/pkg/rpc"
1719
1820 "github.com/spf13/cast"
1921
@@ -24,20 +26,16 @@ import (
2426)
2527
2628type DisputeGameHandler struct {
27- Config * config.Config
28- DB * gorm.DB
29- L1RPC * ethclient.Client
30- L2RPC * ethclient.Client
31- RollupClient * sources.RollupClient // 新增字段
29+ Config * config.Config
30+ DB * gorm.DB
31+ RPCManager * rpc.Manager
3232}
3333
34- func NewDisputeGameHandler (db * gorm.DB , l1rpc * ethclient. Client , l2rpc * ethclient. Client , config * config.Config , rollupClient * sources. RollupClient ) * DisputeGameHandler {
34+ func NewDisputeGameHandler (db * gorm.DB , rpcManager * rpc. Manager , config * config.Config ) * DisputeGameHandler {
3535 return & DisputeGameHandler {
36- DB : db ,
37- L1RPC : l1rpc ,
38- L2RPC : l2rpc ,
39- Config : config ,
40- RollupClient : rollupClient , // 新增赋值
36+ DB : db ,
37+ RPCManager : rpcManager ,
38+ Config : config ,
4139 }
4240}
4341
@@ -299,7 +297,17 @@ func (h DisputeGameHandler) getClaimRoot(blockNumber int64) (string, error) {
299297 return "" , fmt .Errorf ("block number cannot be negative: %d" , blockNumber )
300298 }
301299
302- output , err := h .RollupClient .OutputAtBlock (context .Background (), uint64 (blockNumber ))
300+ // 使用RPCManager获取Node RPC URL,实现轮询
301+ nodeRPCURL := h .RPCManager .GetNodeRPCURL ()
302+
303+ // 创建RollupClient(每次使用不同的Node RPC)
304+ rpcClient , err := client .NewRPC (context .Background (), gethlog .New (), nodeRPCURL )
305+ if err != nil {
306+ return "" , fmt .Errorf ("failed to connect to node RPC %s: %w" , nodeRPCURL , err )
307+ }
308+ rollupClient := sources .NewRollupClient (rpcClient )
309+
310+ output , err := rollupClient .OutputAtBlock (context .Background (), uint64 (blockNumber ))
303311 if err != nil {
304312 return "" , fmt .Errorf ("failed to get output at block %d: %w" , blockNumber , err )
305313 }
@@ -340,7 +348,9 @@ func (h DisputeGameHandler) GetGamesClaimByPosition(c *gin.Context) {
340348}
341349
342350func (h DisputeGameHandler ) gamesClaimByPosition (req * CalculateClaim ) (string , error ) {
343- newDisputeGame , err := contract .NewDisputeGame (common .HexToAddress (req .DisputeGame ), h .L1RPC )
351+ // 获取L1客户端从RPCManager
352+ l1Client := h .RPCManager .GetRawClient (true )
353+ newDisputeGame , err := contract .NewDisputeGame (common .HexToAddress (req .DisputeGame ), l1Client )
344354 if err != nil {
345355 return "" , err
346356 }
0 commit comments