diff --git a/command/bridge/common/params.go b/command/bridge/common/params.go index 1bbb098dc7..53f4657bde 100644 --- a/command/bridge/common/params.go +++ b/command/bridge/common/params.go @@ -142,10 +142,13 @@ func (bp *ERC1155BridgeParams) Validate() error { return nil } -// ExtractExitEventID tries to extract exit event id from provided receipt -func ExtractExitEventID(receipt *ethgo.Receipt) (*big.Int, error) { - var exitEvent contractsapi.L2StateSyncedEvent +// ExtractExitEventIDs tries to extract all exit event ids from provided receipt +func ExtractExitEventIDs(receipt *ethgo.Receipt) ([]*big.Int, error) { + exitEventIDs := make([]*big.Int, 0, len(receipt.Logs)) + for _, log := range receipt.Logs { + var exitEvent contractsapi.L2StateSyncedEvent + doesMatch, err := exitEvent.ParseLog(log) if err != nil { return nil, err @@ -155,7 +158,11 @@ func ExtractExitEventID(receipt *ethgo.Receipt) (*big.Int, error) { continue } - return exitEvent.ID, nil + exitEventIDs = append(exitEventIDs, exitEvent.ID) + } + + if len(exitEventIDs) != 0 { + return exitEventIDs, nil } return nil, errors.New("failed to find exit event log") diff --git a/command/bridge/deposit/erc1155/deposit_erc1155.go b/command/bridge/deposit/erc1155/deposit_erc1155.go index dd8939f87a..c17f24a780 100644 --- a/command/bridge/deposit/erc1155/deposit_erc1155.go +++ b/command/bridge/deposit/erc1155/deposit_erc1155.go @@ -221,14 +221,14 @@ func runCommand(cmd *cobra.Command, _ []string) { } if dp.ChildChainMintable { - exitEventID, err := common.ExtractExitEventID(receipt) + exitEventIDs, err := common.ExtractExitEventIDs(receipt) if err != nil { outputter.SetError(fmt.Errorf("failed to extract exit event: %w", err)) return } - res.ExitEventIDs = []*big.Int{exitEventID} + res.ExitEventIDs = exitEventIDs } // populate child token address if a token is mapped alongside with deposit diff --git a/command/bridge/deposit/erc20/deposit_erc20.go b/command/bridge/deposit/erc20/deposit_erc20.go index 78e6916f1e..95c8258236 100644 --- a/command/bridge/deposit/erc20/deposit_erc20.go +++ b/command/bridge/deposit/erc20/deposit_erc20.go @@ -170,7 +170,7 @@ func runCommand(cmd *cobra.Command, _ []string) { } type bridgeTxData struct { - exitEventID *big.Int + exitEventIDs []*big.Int blockNumber uint64 childTokenAddr *types.Address } @@ -204,10 +204,10 @@ func runCommand(cmd *cobra.Command, _ []string) { return fmt.Errorf("receiver: %s, amount: %s", receiver, amount) } - var exitEventID *big.Int + var exitEventIDs []*big.Int if dp.ChildChainMintable { - if exitEventID, err = common.ExtractExitEventID(receipt); err != nil { + if exitEventIDs, err = common.ExtractExitEventIDs(receipt); err != nil { return fmt.Errorf("failed to extract exit event: %w", err) } } @@ -221,7 +221,7 @@ func runCommand(cmd *cobra.Command, _ []string) { // send aggregated data to channel if everything went ok bridgeTxCh <- bridgeTxData{ blockNumber: receipt.BlockNumber, - exitEventID: exitEventID, + exitEventIDs: exitEventIDs, childTokenAddr: childToken, } @@ -241,8 +241,8 @@ func runCommand(cmd *cobra.Command, _ []string) { var childToken *types.Address for x := range bridgeTxCh { - if x.exitEventID != nil { - exitEventIDs = append(exitEventIDs, x.exitEventID) + if x.exitEventIDs != nil { + exitEventIDs = append(exitEventIDs, x.exitEventIDs...) } blockNumbers = append(blockNumbers, x.blockNumber) diff --git a/command/bridge/deposit/erc721/deposit_erc721.go b/command/bridge/deposit/erc721/deposit_erc721.go index 042b5c3bc3..1ad195da83 100644 --- a/command/bridge/deposit/erc721/deposit_erc721.go +++ b/command/bridge/deposit/erc721/deposit_erc721.go @@ -195,14 +195,14 @@ func runCommand(cmd *cobra.Command, _ []string) { } if dp.ChildChainMintable { - exitEventID, err := common.ExtractExitEventID(receipt) + exitEventIDs, err := common.ExtractExitEventIDs(receipt) if err != nil { outputter.SetError(fmt.Errorf("failed to extract exit event: %w", err)) return } - res.ExitEventIDs = []*big.Int{exitEventID} + res.ExitEventIDs = exitEventIDs } // populate child token address if a token is mapped alongside with deposit diff --git a/command/bridge/withdraw/erc1155/withdraw_erc1155.go b/command/bridge/withdraw/erc1155/withdraw_erc1155.go index 8e20a73e9f..458a97d9a7 100644 --- a/command/bridge/withdraw/erc1155/withdraw_erc1155.go +++ b/command/bridge/withdraw/erc1155/withdraw_erc1155.go @@ -159,14 +159,14 @@ func runCommand(cmd *cobra.Command, _ []string) { } if !wp.ChildChainMintable { - exitEventID, err := common.ExtractExitEventID(receipt) + exitEventIDs, err := common.ExtractExitEventIDs(receipt) if err != nil { outputter.SetError(fmt.Errorf("failed to extract exit event: %w", err)) return } - res.ExitEventIDs = []*big.Int{exitEventID} + res.ExitEventIDs = exitEventIDs } outputter.SetCommandResult(res) diff --git a/command/bridge/withdraw/erc20/withdraw_erc20.go b/command/bridge/withdraw/erc20/withdraw_erc20.go index 967686647f..68d36d9d01 100644 --- a/command/bridge/withdraw/erc20/withdraw_erc20.go +++ b/command/bridge/withdraw/erc20/withdraw_erc20.go @@ -127,14 +127,14 @@ func runCommand(cmd *cobra.Command, _ []string) { } if !wp.ChildChainMintable { - exitEventID, err := common.ExtractExitEventID(receipt) + extractedExitEventIDs, err := common.ExtractExitEventIDs(receipt) if err != nil { outputter.SetError(fmt.Errorf("failed to extract exit event: %w", err)) return } - exitEventIDs = append(exitEventIDs, exitEventID) + exitEventIDs = append(exitEventIDs, extractedExitEventIDs...) } blockNumbers[i] = receipt.BlockNumber diff --git a/command/bridge/withdraw/erc721/withdraw_erc721.go b/command/bridge/withdraw/erc721/withdraw_erc721.go index b36219ae43..eae3404e3a 100644 --- a/command/bridge/withdraw/erc721/withdraw_erc721.go +++ b/command/bridge/withdraw/erc721/withdraw_erc721.go @@ -138,14 +138,14 @@ func run(cmd *cobra.Command, _ []string) { } if !wp.ChildChainMintable { - exitEventID, err := common.ExtractExitEventID(receipt) + exitEventIDs, err := common.ExtractExitEventIDs(receipt) if err != nil { outputter.SetError(fmt.Errorf("failed to extract exit event: %w", err)) return } - res.ExitEventIDs = []*big.Int{exitEventID} + res.ExitEventIDs = exitEventIDs } outputter.SetCommandResult(res) diff --git a/command/sidechain/withdraw/params.go b/command/sidechain/withdraw/params.go index 3da4cca756..2f41e1ab8b 100644 --- a/command/sidechain/withdraw/params.go +++ b/command/sidechain/withdraw/params.go @@ -20,10 +20,10 @@ func (w *withdrawParams) validateFlags() error { } type withdrawResult struct { - ValidatorAddress string `json:"validatorAddress"` - Amount *big.Int `json:"amount"` - ExitEventID *big.Int `json:"exitEventID"` - BlockNumber uint64 `json:"blockNumber"` + ValidatorAddress string `json:"validatorAddress"` + Amount *big.Int `json:"amount"` + ExitEventIDs []*big.Int `json:"exitEventIDs"` + BlockNumber uint64 `json:"blockNumber"` } func (r *withdrawResult) GetOutput() string { @@ -34,7 +34,7 @@ func (r *withdrawResult) GetOutput() string { vals := make([]string, 0, 4) vals = append(vals, fmt.Sprintf("Validator Address|%s", r.ValidatorAddress)) vals = append(vals, fmt.Sprintf("Amount Withdrawn|%d", r.Amount)) - vals = append(vals, fmt.Sprintf("Exit Event ID|%d", r.ExitEventID)) + vals = append(vals, fmt.Sprintf("Exit Event IDs|%d", r.ExitEventIDs)) vals = append(vals, fmt.Sprintf("Inclusion Block Number|%d", r.BlockNumber)) buffer.WriteString(helper.FormatKV(vals)) diff --git a/command/sidechain/withdraw/withdraw.go b/command/sidechain/withdraw/withdraw.go index ca5b33932f..d9802df551 100644 --- a/command/sidechain/withdraw/withdraw.go +++ b/command/sidechain/withdraw/withdraw.go @@ -114,7 +114,7 @@ func runCommand(cmd *cobra.Command, _ []string) error { return fmt.Errorf("could not find an appropriate log in receipt that withdraw happened on ValidatorSet") } - exitEventID, err := common.ExtractExitEventID(receipt) + exitEventIDs, err := common.ExtractExitEventIDs(receipt) if err != nil { return fmt.Errorf("withdrawal failed: %w", err) } @@ -123,7 +123,7 @@ func runCommand(cmd *cobra.Command, _ []string) error { &withdrawResult{ ValidatorAddress: validatorAccount.Ecdsa.Address().String(), Amount: withdrawalEvent.Amount, - ExitEventID: exitEventID, + ExitEventIDs: exitEventIDs, BlockNumber: receipt.BlockNumber, })