@@ -61,45 +61,48 @@ func (h Host) QueryBatchInfos() (*ophosttypes.QueryBatchInfosResponse, error) {
6161 return h .ophostQueryClient .BatchInfos (ctx , req )
6262}
6363
64- func (h Host ) QueryHeightsOfOutputTxWithL2BlockNumber (l2BlockNumber uint64 ) (uint64 , uint64 , error ) {
64+ func (h Host ) QueryHeightsOfOutputTxWithL2BlockNumber (bridgeId int64 , l2BlockNumber uint64 ) (uint64 , uint64 , uint64 , error ) {
6565 ctx , cancel := rpcclient .GetQueryContext (0 )
6666 defer cancel ()
6767
6868 query := fmt .Sprintf ("%s.%s = %d AND %s.%s <= %d" , ophosttypes .EventTypeProposeOutput ,
6969 ophosttypes .AttributeKeyBridgeId ,
70- h . bridgeId ,
70+ bridgeId ,
7171 ophosttypes .EventTypeProposeOutput ,
7272 ophosttypes .AttributeKeyL2BlockNumber ,
7373 l2BlockNumber ,
7474 )
75-
7675 perPage := 1
7776 res , err := h .node .GetRPCClient ().TxSearch (ctx , query , false , nil , & perPage , "desc" )
7877 if err != nil {
79- return 0 , 0 , err
78+ return 0 , 0 , 0 , err
8079 }
8180 if len (res .Txs ) == 0 {
8281 // no output tx found
83- return 0 , 0 , nil
82+ return 0 , 0 , 0 , nil
8483 }
8584
8685 l2StartHeight := uint64 (0 )
87- LOOP:
86+ outputIndex := uint64 ( 0 )
8887 for _ , event := range res .Txs [0 ].TxResult .Events {
8988 if event .Type == ophosttypes .EventTypeProposeOutput {
9089 for _ , attr := range event .Attributes {
9190 if attr .Key == ophosttypes .AttributeKeyL2BlockNumber {
9291 l2StartHeight , err = strconv .ParseUint (attr .Value , 10 , 64 )
9392 if err != nil {
94- return 0 , 0 , err
93+ return 0 , 0 , 0 , err
94+ }
95+ } else if attr .Key == ophosttypes .AttributeKeyOutputIndex {
96+ outputIndex , err = strconv .ParseUint (attr .Value , 10 , 64 )
97+ if err != nil {
98+ return 0 , 0 , 0 , err
9599 }
96- break LOOP
97100 }
98101 }
99102 }
100103 }
101- if l2StartHeight == 0 {
102- return 0 , 0 , fmt .Errorf ("something wrong: l2 block number not found in the output tx" )
104+ if l2StartHeight == 0 || outputIndex == 0 {
105+ return 0 , 0 , 0 , fmt .Errorf ("something wrong: l2 block number not found in the output tx" )
103106 }
104- return uint64 (res .Txs [0 ].Height ), l2StartHeight , nil
107+ return uint64 (res .Txs [0 ].Height ), l2StartHeight , outputIndex + 1 , nil
105108}
0 commit comments