Skip to content

Commit

Permalink
Add support for batch operator addresses to IDs translation (Layr-Lab…
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix authored Jan 25, 2025
1 parent 99de530 commit 77d4442
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ type Reader interface {
// BatchOperatorIDToAddress returns the addresses of the operators from the operator id.
BatchOperatorIDToAddress(ctx context.Context, operatorIds []OperatorID) ([]gethcommon.Address, error)

// BatchOperatorAddressToID returns the operator IDs for the given operator addresses.
BatchOperatorAddressToID(ctx context.Context, addresses []gethcommon.Address) ([]OperatorID, error)

// GetCurrentQuorumBitmapByOperatorId returns the current quorum bitmap for the operator.
GetCurrentQuorumBitmapByOperatorId(ctx context.Context, operatorId OperatorID) (*big.Int, error)

Expand Down
15 changes: 15 additions & 0 deletions core/eth/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,21 @@ func (t *Reader) BatchOperatorIDToAddress(ctx context.Context, operatorIds []cor
return addresses, nil
}

func (t *Reader) BatchOperatorAddressToID(ctx context.Context, addresses []gethcommon.Address) ([]core.OperatorID, error) {
ids, err := t.bindings.OpStateRetriever.GetBatchOperatorId(&bind.CallOpts{
Context: ctx,
}, t.bindings.RegCoordinatorAddr, addresses)
if err != nil {
t.logger.Error("Failed to get operator IDs in batch", "err", err)
return nil, err
}
operatorIds := make([]core.OperatorID, len(ids))
for i, id := range ids {
operatorIds[i] = core.OperatorID(id)
}
return operatorIds, nil
}

func (t *Reader) GetCurrentQuorumBitmapByOperatorId(ctx context.Context, operatorId core.OperatorID) (*big.Int, error) {
return t.bindings.RegistryCoordinator.GetCurrentQuorumBitmap(&bind.CallOpts{
Context: ctx,
Expand Down
6 changes: 6 additions & 0 deletions core/mock/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ func (t *MockWriter) BatchOperatorIDToAddress(ctx context.Context, operatorIds [
return result.([]gethcommon.Address), args.Error(1)
}

func (t *MockWriter) BatchOperatorAddressToID(ctx context.Context, addresses []gethcommon.Address) ([]core.OperatorID, error) {
args := t.Called()
result := args.Get(0)
return result.([]core.OperatorID), args.Error(1)
}

func (t *MockWriter) GetQuorumBitmapForOperatorsAtBlockNumber(ctx context.Context, operatorIds []core.OperatorID, blockNumber uint32) ([]*big.Int, error) {
args := t.Called()
result := args.Get(0)
Expand Down

0 comments on commit 77d4442

Please sign in to comment.