Skip to content

Commit

Permalink
Merge branch 'develop' into feat/genesis-dogfood
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMustermann2 committed Apr 10, 2024
2 parents fc3d5ef + c973d8a commit 7bf392b
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 123 deletions.
6 changes: 0 additions & 6 deletions proto/exocore/operator/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ message OperatorInfo {
ClientChainEarningAddrList client_chain_earnings_addr = 4;
// commission defines the commission parameters.
cosmos.staking.v1beta1.Commission commission = 5 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
// min_self_delegation is the validator's self declared minimum self delegation.
string min_self_delegation = 6 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

// OptedInfo is the opted information about operator
Expand Down
15 changes: 14 additions & 1 deletion x/operator/keeper/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func (k *Keeper) SetOperatorInfo(ctx sdk.Context, addr string, info *operatortyp
if err != nil {
return errorsmod.Wrap(err, "SetOperatorInfo: error occurred when parse acc address from Bech32")
}
// todo: to check the validation of input info
store := prefix.NewStore(ctx.KVStore(k.storeKey), operatortypes.KeyPrefixOperatorInfo)
// todo: think about the difference between init and update in future

Expand Down Expand Up @@ -49,6 +48,20 @@ func (k *Keeper) OperatorInfo(ctx sdk.Context, addr string) (info *operatortypes
return &ret, nil
}

// AllOperators return the address list of all operators
func (k *Keeper) AllOperators(ctx sdk.Context) []string {
store := prefix.NewStore(ctx.KVStore(k.storeKey), operatortypes.KeyPrefixOperatorInfo)
iterator := sdk.KVStorePrefixIterator(store, nil)
defer iterator.Close()

ret := make([]string, 0)
for ; iterator.Valid(); iterator.Next() {
accAddr := sdk.AccAddress(iterator.Key())
ret = append(ret, accAddr.String())
}
return ret
}

func (k *Keeper) IsOperator(ctx sdk.Context, addr sdk.AccAddress) bool {
store := prefix.NewStore(ctx.KVStore(k.storeKey), operatortypes.KeyPrefixOperatorInfo)
return store.Has(addr)
Expand Down
14 changes: 12 additions & 2 deletions x/operator/keeper/operator_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ func (suite *OperatorTestSuite) TestOperatorInfo() {
{101, "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984"},
},
},
Commission: stakingtypes.NewCommission(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec()),
MinSelfDelegation: math.NewInt(0),
Commission: stakingtypes.NewCommission(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec()),
}
err := suite.App.OperatorKeeper.SetOperatorInfo(suite.Ctx, suite.AccAddress.String(), info)
suite.NoError(err)
Expand All @@ -28,6 +27,17 @@ func (suite *OperatorTestSuite) TestOperatorInfo() {
suite.Equal(*info, *getOperatorInfo)
}

func (suite *OperatorTestSuite) TestAllOperators() {
suite.prepare()
operators := []string{suite.operatorAddr.String(), suite.AccAddress.String()}
info := &operatortype.OperatorInfo{}
err := suite.App.OperatorKeeper.SetOperatorInfo(suite.Ctx, suite.AccAddress.String(), info)
suite.NoError(err)

getOperators := suite.App.OperatorKeeper.AllOperators(suite.Ctx)
suite.Equal(operators, getOperators)
}

func (suite *OperatorTestSuite) TestHistoricalOperatorInfo() {
height := suite.Ctx.BlockHeight()
info := &operatortype.OperatorInfo{
Expand Down
6 changes: 6 additions & 0 deletions x/operator/keeper/opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package keeper
import (
"fmt"

"github.com/ethereum/go-ethereum/common"

errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"

Expand Down Expand Up @@ -87,6 +89,10 @@ func (k *Keeper) UpdateOptedInAssetsState(ctx sdk.Context, stakerID, assetID, op

// OptIn call this function to opt in AVS
func (k *Keeper) OptIn(ctx sdk.Context, operatorAddress sdk.AccAddress, avsAddr string) error {
// avsAddr should be an evm contract address
if common.IsHexAddress(avsAddr) {
return types.ErrInvalidAvsAddr
}
// check optedIn info
if k.IsOptedIn(ctx, operatorAddress.String(), avsAddr) {
return types.ErrAlreadyOptedIn
Expand Down
5 changes: 5 additions & 0 deletions x/operator/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ var (
ModuleName, 13,
"the genesis data supplied is invalid",
)

ErrInvalidAvsAddr = errorsmod.Register(
ModuleName, 14,
"avs address should be a hex evm contract address",
)
)
178 changes: 64 additions & 114 deletions x/operator/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7bf392b

Please sign in to comment.