diff --git a/app/app.go b/app/app.go index 59536da77..81a1af753 100644 --- a/app/app.go +++ b/app/app.go @@ -4,6 +4,9 @@ import ( "context" "encoding/json" "fmt" + "github.com/ExocoreNetwork/exocore/x/avs_task" + taskKeeper "github.com/ExocoreNetwork/exocore/x/avs_task/keeper" + taskTypes "github.com/ExocoreNetwork/exocore/x/avs_task/types" "io" "net/http" "os" @@ -274,6 +277,7 @@ var ( reward.AppModuleBasic{}, exoslash.AppModuleBasic{}, avs.AppModuleBasic{}, + avs_task.AppModuleBasic{}, ) // module account permissions @@ -358,6 +362,7 @@ type ExocoreApp struct { OperatorKeeper operatorKeeper.Keeper ExoSlashKeeper slashKeeper.Keeper AVSManagerKeeper avsManagerKeeper.Keeper + TaskKeeper taskKeeper.Keeper // the module manager mm *module.Manager @@ -441,6 +446,7 @@ func NewExocoreApp( exoslashTypes.StoreKey, operatorTypes.StoreKey, avsManagerTypes.StoreKey, + taskTypes.StoreKey, ) // Add the EVM transient store key @@ -658,6 +664,7 @@ func NewExocoreApp( app.RewardKeeper = *rewardKeeper.NewKeeper(appCodec, keys[rewardTypes.StoreKey], app.AssetsKeeper) app.ExoSlashKeeper = slashKeeper.NewKeeper(appCodec, keys[exoslashTypes.StoreKey], app.AssetsKeeper) app.AVSManagerKeeper = *avsManagerKeeper.NewKeeper(appCodec, keys[avsManagerTypes.StoreKey], &app.OperatorKeeper, app.AssetsKeeper) + app.TaskKeeper = taskKeeper.NewKeeper(appCodec, keys[taskTypes.StoreKey], taskTypes.AvsKeeperMock{}) // We call this after setting the hooks to ensure that the hooks are set on the keeper evmKeeper.WithPrecompiles( evmkeeper.AvailablePrecompiles( @@ -672,6 +679,7 @@ func NewExocoreApp( app.ExoSlashKeeper, app.RewardKeeper, app.AVSManagerKeeper, + app.TaskKeeper, ), ) epochsKeeper := epochskeeper.NewKeeper(appCodec, keys[epochstypes.StoreKey]) @@ -845,6 +853,7 @@ func NewExocoreApp( reward.NewAppModule(appCodec, app.RewardKeeper), exoslash.NewAppModule(appCodec, app.ExoSlashKeeper), avs.NewAppModule(appCodec, app.AVSManagerKeeper), + avs_task.NewAppModule(appCodec, app.TaskKeeper), ) // During begin block slashing happens after reward.BeginBlocker so that @@ -889,6 +898,7 @@ func NewExocoreApp( rewardTypes.ModuleName, exoslashTypes.ModuleName, avsManagerTypes.ModuleName, + taskTypes.ModuleName, ) // NOTE: fee market module must go last in order to retrieve the block gas used. @@ -928,6 +938,7 @@ func NewExocoreApp( rewardTypes.ModuleName, exoslashTypes.ModuleName, avsManagerTypes.ModuleName, + taskTypes.ModuleName, ) // NOTE: The genutils module must occur after staking so that pools are @@ -973,6 +984,7 @@ func NewExocoreApp( crisistypes.ModuleName, consensusparamtypes.ModuleName, avsManagerTypes.ModuleName, + taskTypes.ModuleName, ) app.mm.RegisterInvariants(&app.CrisisKeeper) diff --git a/go.sum b/go.sum index 434ff8667..b3af31275 100644 --- a/go.sum +++ b/go.sum @@ -1696,8 +1696,6 @@ golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= -golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= diff --git a/precompiles/avsTask/abi.json b/precompiles/avsTask/abi.json new file mode 100644 index 000000000..977576117 --- /dev/null +++ b/precompiles/avsTask/abi.json @@ -0,0 +1,122 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "operator", + "type": "address" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "pubkeyG1", + "type": "bytes" + } + ], + "name": "NewPubkeyRegistration", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "msgHash", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "pubkey", + "type": "bytes" + } + ], + "name": "checkSignatures", + "outputs": [ + { + "internalType": "bool", + "name": "valid", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "operator", + "type": "address" + } + ], + "name": "getRegisteredPubkey", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "TaskContractAddress", + "type": "string" + }, + { + "internalType": "string", + "name": "Name", + "type": "string" + }, + { + "internalType": "string", + "name": "MetaInfo", + "type": "string" + } + ], + "name": "registerAVSTask", + "outputs": [ + { + "internalType": "bool", + "name": "success", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "operator", + "type": "string" + }, + { + "internalType": "bytes", + "name": "pubKey", + "type": "bytes" + } + ], + "name": "registerBLSPublicKey", + "outputs": [ + { + "internalType": "bool", + "name": "success", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } +] \ No newline at end of file diff --git a/precompiles/avsTask/avsTask.sol b/precompiles/avsTask/avsTask.sol new file mode 100644 index 000000000..c8de44dfc --- /dev/null +++ b/precompiles/avsTask/avsTask.sol @@ -0,0 +1,53 @@ +pragma solidity >=0.8.17 .0; + +/// @dev The AVSTask contract's address. +address constant AVSTASK_PRECOMPILE_ADDRESS = 0x0000000000000000000000000000000000000901; + +/// @dev The AVSTask contract's instance. +IAVSTask constant AVSTASK_CONTRACT = IAVSTask( + AVSTASK_PRECOMPILE_ADDRESS +); + +/// @author Exocore Team +/// @title AVSTask Precompile Contract +/// @dev The interface through which solidity contracts will interact with AVSTask +/// @custom:address 0x0000000000000000000000000000000000000901 + +interface IAVSTask { +/// TRANSACTIONS +/// @dev IAVSTask the oprator, that will change the state in AVSTask module +/// @param TaskContractAddress task Contract Address +/// @param Name task name +/// @param MetaInfo task desc + function registerAVSTask( + string memory TaskContractAddress, + string memory Name, + string memory MetaInfo + ) external returns (bool success); + + /// TRANSACTIONS +/// @dev Called by the avs manager service register an operator as the owner of a BLS public key. +/// @param operator is the operator for whom the key is being registered +/// @param pubKey the public keys of the operator + function registerBLSPublicKey( + string memory operator, + bytes calldata pubKey + ) external returns (bool success); + + /// TRANSACTIONS +/// @dev Returns the pubkey and pubkey hash of an operator,Reverts if the operator has not registered a valid pubkey +/// @param operator is the operator for whom the key is being registered + function getRegisteredPubkey(address operator) external returns (bytes32); + + /// TRANSACTIONS +/// @dev Get the count of the current task + function checkSignatures( + bytes32 msgHash, + bytes calldata signature, + bytes calldata pubkey + ) external view returns (bool valid); + + // EVENTS + /// @notice Emitted when `operator` registers with the public keys `pubkeyG1`. + event NewPubkeyRegistration(address indexed operator, bytes pubkeyG1); +} diff --git a/precompiles/avsTask/error.go b/precompiles/avsTask/error.go new file mode 100644 index 000000000..1cbd69db8 --- /dev/null +++ b/precompiles/avsTask/error.go @@ -0,0 +1,8 @@ +package task + +const ( + ErrContractInputParaOrType = "the contract input parameter type or value error,arg index:%d, type is:%s,value:%v" + ErrContractCaller = "the caller doesn't have the permission to call this function,caller:%s,need:%s" + ErrInputClientChainAddrLength = "the length of input client chain addr doesn't match,input:%d,need:%d" + ErrNotYetRegistered = "this AVS has not been registered yet,input:%d" +) diff --git a/precompiles/avsTask/events.go b/precompiles/avsTask/events.go new file mode 100644 index 000000000..df51313d8 --- /dev/null +++ b/precompiles/avsTask/events.go @@ -0,0 +1,52 @@ +package task + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/core/vm" + cmn "github.com/evmos/evmos/v14/precompiles/common" +) + +const ( + // EventTypeNewTaskCreated defines the event type for the task create transaction. + EventTypeNewPubkeyRegistration = "NewPubkeyRegistration" +) + +// EmitEventTypeNewPubkeyRegistration new bls pubkey reg +func (p Precompile) EmitEventTypeNewPubkeyRegistration( + ctx sdk.Context, + stateDB vm.StateDB, + operator string, + pubkey []byte, +) error { + event := p.ABI.Events[EventTypeNewPubkeyRegistration] + topics := make([]common.Hash, 3) + + // The first topic is always the signature of the event. + topics[0] = event.ID + + var err error + // sender and receiver are indexed + topics[1], err = cmn.MakeTopic(operator) + if err != nil { + return err + } + + // Prepare the event data: denom, amount, memo + arguments := abi.Arguments{event.Inputs[2]} + packed, err := arguments.Pack(pubkey) + if err != nil { + return err + } + + stateDB.AddLog(ðtypes.Log{ + Address: p.Address(), + Topics: topics, + Data: packed, + BlockNumber: uint64(ctx.BlockHeight()), + }) + + return nil +} diff --git a/precompiles/avsTask/methods.go b/precompiles/avsTask/methods.go new file mode 100644 index 000000000..69004149a --- /dev/null +++ b/precompiles/avsTask/methods.go @@ -0,0 +1,119 @@ +package task + +import ( + "fmt" + exocmn "github.com/ExocoreNetwork/exocore/precompiles/common" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/vm" + cmn "github.com/evmos/evmos/v14/precompiles/common" + "golang.org/x/xerrors" +) + +const ( + // MethodRegisterAVSTask defines the ABI method name for the task + // transaction. + MethodRegisterAVSTask = "registerAVSTask" + MethodRegisterBLSPublicKey = "registerBLSPublicKey" + MethodIGetRegisteredPubkey = "getRegisteredPubkey" + MethodICheckSignatures = "checkSignatures" +) + +// RegisterAVSTask Middleware uses exocore's default task template to create tasks in task module. +func (p Precompile) RegisterAVSTask( + ctx sdk.Context, + _ common.Address, + contract *vm.Contract, + method *abi.Method, + args []interface{}, +) ([]byte, error) { + // check the invalidation of caller contract + flag := p.avsKeeper.IsAVS(ctx, sdk.AccAddress(contract.CallerAddress.String())) + if !flag { + return nil, fmt.Errorf(ErrNotYetRegistered, contract.CallerAddress) + } + + params, err := p.GetTaskParamsFromInputs(ctx, args) + if err != nil { + return nil, err + } + params.FromAddress = contract.CallerAddress.String() + _, err = p.taskKeeper.RegisterAVSTask(ctx, params) + if err != nil { + return nil, err + } + return method.Outputs.Pack(true) +} + +// RegisterBLSPublicKey +func (p Precompile) RegisterBLSPublicKey( + ctx sdk.Context, + _ common.Address, + stateDB vm.StateDB, + method *abi.Method, + args []interface{}, +) ([]byte, error) { + if len(args) != 2 { + return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, 2, len(args)) + } + + addr, ok := args[0].(string) + if !ok { + return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 0, "string") + } + + pubkeyBz, ok := args[1].([]byte) + if !ok { + return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 0, "string") + } + + err := p.taskKeeper.SetOperatorPubKey(ctx, addr, pubkeyBz) + if err != nil { + return nil, err + } + if err = p.EmitEventTypeNewPubkeyRegistration( + ctx, + stateDB, + addr, + pubkeyBz, + ); err != nil { + return nil, err + } + return method.Outputs.Pack(true) +} + +func (p Precompile) CheckSignatures( + ctx sdk.Context, + contract *vm.Contract, + method *abi.Method, + args []interface{}, +) ([]byte, error) { + if len(args) != 3 { + return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, 3, len(args)) + } + return method.Outputs.Pack(true) +} + +// GetRegisteredPubkey +func (p Precompile) GetRegisteredPubkey( + ctx sdk.Context, + contract *vm.Contract, + method *abi.Method, + args []interface{}, +) ([]byte, error) { + if len(args) != 1 { + return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, 1, len(args)) + } + + addr, ok := args[0].(string) + if !ok { + return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 0, "string") + } + + pubkey, err := p.taskKeeper.GetOperatorPubKey(ctx, addr) + if err != nil { + return nil, err + } + return method.Outputs.Pack(pubkey) +} diff --git a/precompiles/avsTask/parser.go b/precompiles/avsTask/parser.go new file mode 100644 index 000000000..bacc93007 --- /dev/null +++ b/precompiles/avsTask/parser.go @@ -0,0 +1,38 @@ +package task + +import ( + "fmt" + exocmn "github.com/ExocoreNetwork/exocore/precompiles/common" + types "github.com/ExocoreNetwork/exocore/x/avs_task/types" + sdk "github.com/cosmos/cosmos-sdk/types" + cmn "github.com/evmos/evmos/v14/precompiles/common" + "golang.org/x/xerrors" +) + +func (p Precompile) GetTaskParamsFromInputs(ctx sdk.Context, args []interface{}) (*types.RegisterAVSTaskReq, error) { + if len(args) != 3 { + return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, 3, len(args)) + } + taskParams := &types.RegisterAVSTaskReq{} + taskinfo := &types.TaskContractInfo{} + + taskaddr, ok := args[0].(string) + if !ok { + return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 0, "string", taskaddr) + } + taskinfo.TaskContractAddress = taskaddr + + taskName, ok := args[1].(string) + if !ok { + return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 1, "string", taskName) + } + taskinfo.Name = taskName + + metainfo, ok := args[2].(string) + if !ok || metainfo == "" { + return nil, xerrors.Errorf(exocmn.ErrContractInputParaOrType, 2, "string", metainfo) + } + taskinfo.MetaInfo = metainfo + taskParams.Task = taskinfo + return taskParams, nil +} diff --git a/precompiles/avsTask/setup_test.go b/precompiles/avsTask/setup_test.go new file mode 100644 index 000000000..8faeb9dc6 --- /dev/null +++ b/precompiles/avsTask/setup_test.go @@ -0,0 +1,37 @@ +package task_test + +import ( + "github.com/ExocoreNetwork/exocore/testutil" + tasktype "github.com/ExocoreNetwork/exocore/x/avs_task/types" + "testing" + + "github.com/ExocoreNetwork/exocore/precompiles/avsTask" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "github.com/stretchr/testify/suite" +) + +var s *TaskPrecompileTestSuite + +type TaskPrecompileTestSuite struct { + testutil.BaseTestSuite + precompile *task.Precompile +} + +func TestPrecompileTestSuite(t *testing.T) { + s = new(TaskPrecompileTestSuite) + suite.Run(t, s) + + // Run Ginkgo integration tests + RegisterFailHandler(Fail) + RunSpecs(t, "Task Precompile Suite") +} + +func (s *TaskPrecompileTestSuite) SetupTest() { + s.DoSetupTest() + precompile, err := task.NewPrecompile(s.App.AuthzKeeper, s.App.TaskKeeper, tasktype.AvsKeeperMock{}) + s.Require().NoError(err) + s.precompile = precompile +} diff --git a/precompiles/avsTask/task.go b/precompiles/avsTask/task.go new file mode 100644 index 000000000..447f8807c --- /dev/null +++ b/precompiles/avsTask/task.go @@ -0,0 +1,132 @@ +package task + +import ( + "bytes" + "embed" + "fmt" + taskKeeper "github.com/ExocoreNetwork/exocore/x/avs_task/keeper" + tasktype "github.com/ExocoreNetwork/exocore/x/avs_task/types" + "github.com/cometbft/cometbft/libs/log" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/vm" + cmn "github.com/evmos/evmos/v14/precompiles/common" +) + +var _ vm.PrecompiledContract = &Precompile{} + +// Embed abi json file to the executable binary. Needed when importing as dependency. +// +//go:embed abi.json +var f embed.FS + +// Precompile defines the precompiled contract for task. +type Precompile struct { + cmn.Precompile + taskKeeper taskKeeper.Keeper + avsKeeper tasktype.AvsKeeperMock +} + +// NewPrecompile creates a new task Precompile instance as a +// PrecompiledContract interface. +func NewPrecompile( + authzKeeper authzkeeper.Keeper, + taskKeeper taskKeeper.Keeper, + avsKeeper tasktype.AvsKeeperMock, +) (*Precompile, error) { + abiBz, err := f.ReadFile("abi.json") + if err != nil { + return nil, fmt.Errorf("error loading the task ABI %s", err) + } + + newAbi, err := abi.JSON(bytes.NewReader(abiBz)) + if err != nil { + return nil, fmt.Errorf(cmn.ErrInvalidABI, err) + } + + return &Precompile{ + Precompile: cmn.Precompile{ + ABI: newAbi, + AuthzKeeper: authzKeeper, + KvGasConfig: storetypes.KVGasConfig(), + TransientKVGasConfig: storetypes.TransientGasConfig(), + ApprovalExpiration: cmn.DefaultExpirationDuration, // should be configurable in the future. + }, + taskKeeper: taskKeeper, + avsKeeper: avsKeeper, + }, nil +} + +// Address defines the address of the task compile contract. +// address: 0x0000000000000000000000000000000000000901 +func (p Precompile) Address() common.Address { + return common.HexToAddress("0x0000000000000000000000000000000000000901") +} + +// RequiredGas calculates the precompiled contract's base gas rate. +func (p Precompile) RequiredGas(input []byte) uint64 { + methodID := input[:4] + + method, err := p.MethodById(methodID) + if err != nil { + // This should never happen since this method is going to fail during Run + return 0 + } + + return p.Precompile.RequiredGas(input, p.IsTransaction(method.Name)) +} + +// Run executes the precompiled contract AVSInfoRegisterOrDeregister methods defined in the ABI. +func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz []byte, err error) { + ctx, stateDB, method, initialGas, args, err := p.RunSetup(evm, contract, readOnly, p.IsTransaction) + if err != nil { + return nil, err + } + + // This handles any out of gas errors that may occur during the execution of a precompile tx or query. + // It avoids panics and returns the out of gas error so the EVM can continue gracefully. + defer cmn.HandleGasError(ctx, contract, initialGas, &err)() + + switch method.Name { + case MethodRegisterAVSTask: + bz, err = p.RegisterAVSTask(ctx, evm.Origin, contract, method, args) + case MethodRegisterBLSPublicKey: + bz, err = p.RegisterBLSPublicKey(ctx, evm.Origin, stateDB, method, args) + case MethodIGetRegisteredPubkey: + bz, err = p.GetRegisteredPubkey(ctx, contract, method, args) + case MethodICheckSignatures: + bz, err = p.CheckSignatures(ctx, contract, method, args) + } + + if err != nil { + return nil, err + } + + cost := ctx.GasMeter().GasConsumed() - initialGas + + if !contract.UseGas(cost) { + return nil, vm.ErrOutOfGas + } + + return bz, nil +} + +// IsTransaction checks if the given methodID corresponds to a transaction or query. +// +// Available task transactions are: +func (Precompile) IsTransaction(methodID string) bool { + switch methodID { + case MethodRegisterAVSTask: + return true + default: + return false + } +} + +// Logger returns a precompile-specific logger. +func (p Precompile) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("ExoCore module", "task") +} diff --git a/precompiles/avsTask/task_test.go b/precompiles/avsTask/task_test.go new file mode 100644 index 000000000..393227cf8 --- /dev/null +++ b/precompiles/avsTask/task_test.go @@ -0,0 +1,145 @@ +package task_test + +import ( + "github.com/ExocoreNetwork/exocore/app" + "github.com/ExocoreNetwork/exocore/precompiles/avsTask" + "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/core/vm" + "github.com/evmos/evmos/v14/x/evm/statedb" + evmtypes "github.com/evmos/evmos/v14/x/evm/types" + "math/big" +) + +func (s *TaskPrecompileTestSuite) TestIsTransaction() { + testCases := []struct { + name string + method string + isTx bool + }{ + { + task.MethodRegisterAVSTask, + s.precompile.Methods[task.MethodRegisterAVSTask].Name, + true, + }, + { + task.MethodRegisterBLSPublicKey, + s.precompile.Methods[task.MethodRegisterBLSPublicKey].Name, + true, + }, + { + "invalid", + "invalid", + false, + }, + } + + for _, tc := range testCases { + s.Run(tc.name, func() { + s.Require().Equal(s.precompile.IsTransaction(tc.method), tc.isTx) + }) + } +} + +// TestRun tests the precompiles Run method reg task. +func (s *TaskPrecompileTestSuite) TestRunRegTaskinfo() { + commonMalleate := func() (common.Address, []byte) { + input, err := s.precompile.Pack( + task.MethodRegisterAVSTask, + "exo1j9ly7f0jynscjgvct0enevaa659te58k3xztc8", + "test-task", + "test-task-url", + ) + s.Require().NoError(err, "failed to pack input") + return s.Address, input + } + successRet, err := s.precompile.Methods[task.MethodRegisterAVSTask].Outputs.Pack(true) + s.Require().NoError(err) + testcases := []struct { + name string + malleate func() (common.Address, []byte) + readOnly bool + expPass bool + errContains string + returnBytes []byte + }{ + { + name: "pass - task via pre-compiles", + malleate: func() (common.Address, []byte) { + s.Require().NoError(err) + return commonMalleate() + }, + returnBytes: successRet, + readOnly: false, + expPass: true, + }, + } + for _, tc := range testcases { + tc := tc + s.Run(tc.name, func() { + // setup basic test suite + s.SetupTest() + + baseFee := s.App.FeeMarketKeeper.GetBaseFee(s.Ctx) + + // malleate testcase + caller, input := tc.malleate() + + contract := vm.NewPrecompile(vm.AccountRef(caller), s.precompile, big.NewInt(0), uint64(1e6)) + contract.Input = input + + contractAddr := contract.Address() + // Build and sign Ethereum transaction + txArgs := evmtypes.EvmTxArgs{ + ChainID: s.App.EvmKeeper.ChainID(), + Nonce: 0, + To: &contractAddr, + Amount: nil, + GasLimit: 100000, + GasPrice: app.MainnetMinGasPrices.BigInt(), + GasFeeCap: baseFee, + GasTipCap: big.NewInt(1), + Accesses: ðtypes.AccessList{}, + } + msgEthereumTx := evmtypes.NewTx(&txArgs) + + msgEthereumTx.From = s.Address.String() + err := msgEthereumTx.Sign(s.EthSigner, s.Signer) + s.Require().NoError(err, "failed to sign Ethereum message") + + // Instantiate config + proposerAddress := s.Ctx.BlockHeader().ProposerAddress + cfg, err := s.App.EvmKeeper.EVMConfig(s.Ctx, proposerAddress, s.App.EvmKeeper.ChainID()) + s.Require().NoError(err, "failed to instantiate EVM config") + + msg, err := msgEthereumTx.AsMessage(s.EthSigner, baseFee) + s.Require().NoError(err, "failed to instantiate Ethereum message") + + // Create StateDB + s.StateDB = statedb.New(s.Ctx, s.App.EvmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(s.Ctx.HeaderHash().Bytes()))) + // Instantiate EVM + evm := s.App.EvmKeeper.NewEVM( + s.Ctx, msg, cfg, nil, s.StateDB, + ) + params := s.App.EvmKeeper.GetParams(s.Ctx) + activePrecompiles := params.GetActivePrecompilesAddrs() + precompileMap := s.App.EvmKeeper.Precompiles(activePrecompiles...) + err = vm.ValidatePrecompiles(precompileMap, activePrecompiles) + s.Require().NoError(err, "invalid precompiles", activePrecompiles) + evm.WithPrecompiles(precompileMap, activePrecompiles) + + // Run precompiled contract + bz, err := s.precompile.Run(evm, contract, tc.readOnly) + + // Check results + if tc.expPass { + s.Require().NoError(err, "expected no error when running the precompile") + s.Require().Equal(tc.returnBytes, bz, "the return doesn't match the expected result") + } else { + s.Require().Error(err, "expected error to be returned when running the precompile") + s.Require().Nil(bz, "expected returned bytes to be nil") + s.Require().ErrorContains(err, tc.errContains) + } + }) + } +} diff --git a/proto/exocore/task/v1/query.proto b/proto/exocore/task/v1/query.proto new file mode 100644 index 000000000..17a4f5751 --- /dev/null +++ b/proto/exocore/task/v1/query.proto @@ -0,0 +1,26 @@ +syntax = "proto3"; +package exocore.task.v1; + +import "cosmos_proto/cosmos.proto"; +import "exocore/task/v1/tx.proto"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "tendermint/crypto/keys.proto"; + +option go_package = "github.com/ExocoreNetwork/exocore/x/avs_task/types"; + +// QueryAVSTaskInfoReq is the request to obtain the task information. +message GetAVSTaskInfoReq { + // task_addr is the task contract address,its type should be a sdk.AccAddress + string task_addr = 1 + [(cosmos_proto.scalar) = "cosmos.AddressString"]; +} + + +// Query defines the gRPC querier service. +service Query { + // TaskInfo queries the task information. + rpc GetAVSTaskInfo(GetAVSTaskInfoReq) returns(TaskContractInfo){ + option (google.api.http).get = "/exocore/task/v1/GetAVSTaskInfoReq"; + } +} diff --git a/proto/exocore/task/v1/tx.proto b/proto/exocore/task/v1/tx.proto new file mode 100644 index 000000000..4af07cfdd --- /dev/null +++ b/proto/exocore/task/v1/tx.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; +package exocore.task.v1; + +import "amino/amino.proto"; +import "cosmos/msg/v1/msg.proto"; +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/ExocoreNetwork/exocore/x/avs_task/types"; +// TaskContractInfo is the task info. +message TaskContractInfo { + string TaskContractAddress = 1; + string Name = 2; + string MetaInfo = 3; + string Status = 4; + string sourceCode = 5; +} + +// RegisterAVSTaskReq is the request to register a new task for avs. +message RegisterAVSTaskReq { + option (cosmos.msg.v1.signer) = "FromAddress"; + option (amino.name) = "cosmos-sdk/TaskContractInfo"; + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // from_address is the address of the avs (sdk.AccAddress). + string from_address = 1 + [(cosmos_proto.scalar) = "cosmos.AddressString"]; + // info is the task info. + TaskContractInfo task = 2; +} + + +message RegisterAVSTaskResponse {} + + +// Msg defines the Msg service. +service Msg { + option (cosmos.msg.v1.service) = true; + // RegisterAVSTask registers a new task. + rpc RegisterAVSTask(RegisterAVSTaskReq) returns (RegisterAVSTaskResponse); +} \ No newline at end of file diff --git a/x/avs_task/client/cli/query.go b/x/avs_task/client/cli/query.go new file mode 100644 index 000000000..fb24367ed --- /dev/null +++ b/x/avs_task/client/cli/query.go @@ -0,0 +1,62 @@ +package cli + +import ( + "context" + "fmt" + tasktypes "github.com/ExocoreNetwork/exocore/x/avs_task/types" + "github.com/cosmos/cosmos-sdk/client/flags" + + // "strings" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + // "github.com/cosmos/cosmos-sdk/client/flags" + // sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/ExocoreNetwork/exocore/x/avs_task/types" +) + +// GetQueryCmd returns the cli query commands for this module + +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(GetTaskInfo()) + return cmd +} + +// GetTaskInfo queries operator info +func GetTaskInfo() *cobra.Command { + cmd := &cobra.Command{ + Use: "GetTaskInfo task info", + Short: "Get task info", + Long: "Get task info", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := tasktypes.NewQueryClient(clientCtx) + req := &tasktypes.GetAVSTaskInfoReq{ + TaskAddr: args[0], + } + res, err := queryClient.GetAVSTaskInfo(context.Background(), req) + if err != nil { + return err + } + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + return cmd +} diff --git a/x/avs_task/client/cli/tx.go b/x/avs_task/client/cli/tx.go new file mode 100644 index 000000000..8905f08e1 --- /dev/null +++ b/x/avs_task/client/cli/tx.go @@ -0,0 +1,68 @@ +package cli + +import ( + "fmt" + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + + // "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/ExocoreNetwork/exocore/x/avs_task/types" + taskTypes "github.com/ExocoreNetwork/exocore/x/avs_task/types" + "github.com/cosmos/cosmos-sdk/client/tx" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + // this line is used by starport scaffolding # 1 + cmd.AddCommand( + RegisterAVSTask(), + ) + return cmd +} + +func RegisterAVSTask() *cobra.Command { + cmd := &cobra.Command{ + Use: "Registertask params to taskManager module", + Short: "Registertask params to taskManager module", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + cliCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + if err != nil { + return err + } + + if err != nil { + return err + } + sender := cliCtx.GetFromAddress().String() + + msg := &taskTypes.RegisterAVSTaskReq{ + FromAddress: sender, + Task: &taskTypes.TaskContractInfo{ + TaskContractAddress: args[0], + Name: args[1], + MetaInfo: args[2]}, + } + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + return cmd +} diff --git a/x/avs_task/keeper/keeper.go b/x/avs_task/keeper/keeper.go new file mode 100644 index 000000000..2d1580cad --- /dev/null +++ b/x/avs_task/keeper/keeper.go @@ -0,0 +1,40 @@ +package keeper + +import ( + "context" + "fmt" + "github.com/ExocoreNetwork/exocore/x/avs_task/types" + tasktype "github.com/ExocoreNetwork/exocore/x/avs_task/types" + "github.com/cometbft/cometbft/libs/log" + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type ( + Keeper struct { + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + avsKeeper tasktype.AvsKeeperMock + } +) + +func NewKeeper( + cdc codec.BinaryCodec, + storeKey storetypes.StoreKey, + avsKeeper tasktype.AvsKeeperMock, +) Keeper { + return Keeper{ + cdc: cdc, + storeKey: storeKey, + avsKeeper: avsKeeper, + } +} + +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +type TaskKeeper interface { + RegisterAVSTask(ctx context.Context, req *types.RegisterAVSTaskReq) (*types.RegisterAVSTaskResponse, error) +} diff --git a/x/avs_task/keeper/msg_server.go b/x/avs_task/keeper/msg_server.go new file mode 100644 index 000000000..20ddcfd44 --- /dev/null +++ b/x/avs_task/keeper/msg_server.go @@ -0,0 +1,25 @@ +package keeper + +import ( + "context" + errorsmod "cosmossdk.io/errors" + "fmt" + "github.com/ExocoreNetwork/exocore/x/avs_task/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ types.MsgServer = &Keeper{} + +func (k *Keeper) RegisterAVSTask(ctx context.Context, req *types.RegisterAVSTaskReq) (*types.RegisterAVSTaskResponse, error) { + c := sdk.UnwrapSDKContext(ctx) + avs := k.avsKeeper.IsAVS(c, sdk.AccAddress(req.FromAddress)) + if !avs { + return nil, errorsmod.Wrap(types.ErrNotYetRegistered, fmt.Sprintf("RegisterAVSTask: avs address is %s", req.FromAddress)) + + } + err := k.SetAvsTaskInfo(c, req) + if err != nil { + return nil, err + } + return nil, nil +} diff --git a/x/avs_task/keeper/query.go b/x/avs_task/keeper/query.go new file mode 100644 index 000000000..d4c2d6586 --- /dev/null +++ b/x/avs_task/keeper/query.go @@ -0,0 +1,14 @@ +package keeper + +import ( + "context" + tasktypes "github.com/ExocoreNetwork/exocore/x/avs_task/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ tasktypes.QueryServer = &Keeper{} + +func (k *Keeper) GetAVSTaskInfo(ctx context.Context, req *tasktypes.GetAVSTaskInfoReq) (*tasktypes.TaskContractInfo, error) { + c := sdk.UnwrapSDKContext(ctx) + return k.GetAvsTaskInfo(c, req.TaskAddr) +} diff --git a/x/avs_task/keeper/setup_test.go b/x/avs_task/keeper/setup_test.go new file mode 100644 index 000000000..efb6ca9d3 --- /dev/null +++ b/x/avs_task/keeper/setup_test.go @@ -0,0 +1,44 @@ +package keeper_test + +import ( + "testing" + + sdkmath "cosmossdk.io/math" + "github.com/ExocoreNetwork/exocore/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/stretchr/testify/suite" +) + +var s *OperatorTestSuite + +type OperatorTestSuite struct { + testutil.BaseTestSuite + + // needed by test + operatorAddr sdk.AccAddress + avsAddr string + assetID string + stakerID string + assetAddr common.Address + assetDecimal uint32 + clientChainLzID uint64 + depositAmount sdkmath.Int + delegationAmount sdkmath.Int + updatedAmountForOptIn sdkmath.Int +} + +func TestOperatorTestSuite(t *testing.T) { + s = new(OperatorTestSuite) + suite.Run(t, s) + + // Run Ginkgo integration tests + RegisterFailHandler(Fail) + RunSpecs(t, "operator module Suite") +} + +func (suite *OperatorTestSuite) SetupTest() { + suite.DoSetupTest() +} diff --git a/x/avs_task/keeper/task.go b/x/avs_task/keeper/task.go new file mode 100644 index 000000000..09f202456 --- /dev/null +++ b/x/avs_task/keeper/task.go @@ -0,0 +1,76 @@ +package keeper + +import ( + errorsmod "cosmossdk.io/errors" + "fmt" + "github.com/ExocoreNetwork/exocore/x/avs_task/types" + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (k *Keeper) SetAvsTaskInfo(ctx sdk.Context, info *types.RegisterAVSTaskReq) (err error) { + + taskAccAddr, err := sdk.AccAddressFromBech32(info.Task.TaskContractAddress) + if err != nil { + return errorsmod.Wrap(err, "SetTaskInfo: error occurred when parse acc address from Bech32") + } + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixAVSTaskInfo) + + bz := k.cdc.MustMarshal(info) + + store.Set(taskAccAddr, bz) + return nil +} + +func (k *Keeper) GetAvsTaskInfo(ctx sdk.Context, addr string) (info *types.TaskContractInfo, err error) { + taskAccAddr, err := sdk.AccAddressFromBech32(addr) + if err != nil { + return nil, errorsmod.Wrap(err, "GetTaskInfo: error occurred when parse acc address from Bech32") + } + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixAVSTaskInfo) + //key := common.HexToAddress(incentive.Contract) + isExist := store.Has(taskAccAddr) + if !isExist { + return nil, errorsmod.Wrap(types.ErrNoKeyInTheStore, fmt.Sprintf("GetOperatorInfo: key is %suite", addr)) + } + + value := store.Get(taskAccAddr) + + ret := types.RegisterAVSTaskReq{} + k.cdc.MustUnmarshal(value, &ret) + return ret.Task, nil +} + +func (k *Keeper) IsExistTask(ctx sdk.Context, addr sdk.AccAddress) bool { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixAVSTaskInfo) + return store.Has(addr) +} + +func (k *Keeper) SetOperatorPubKey(ctx sdk.Context, addr string, pub []byte) (err error) { + + opAccAddr, err := sdk.AccAddressFromBech32(addr) + if err != nil { + return errorsmod.Wrap(err, "SetTaskInfo: error occurred when parse acc address from Bech32") + } + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixOperatePub) + + store.Set(opAccAddr, pub) + return nil +} + +func (k *Keeper) GetOperatorPubKey(ctx sdk.Context, addr string) (pub []byte, err error) { + opAccAddr, err := sdk.AccAddressFromBech32(addr) + if err != nil { + return nil, errorsmod.Wrap(err, "GetTaskInfo: error occurred when parse acc address from Bech32") + } + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixOperatePub) + //key := common.HexToAddress(incentive.Contract) + isExist := store.Has(opAccAddr) + if !isExist { + return nil, errorsmod.Wrap(types.ErrNoKeyInTheStore, fmt.Sprintf("GetOperatorInfo: key is %suite", addr)) + } + + value := store.Get(opAccAddr) + + return value, nil +} diff --git a/x/avs_task/keeper/task_test.go b/x/avs_task/keeper/task_test.go new file mode 100644 index 000000000..4b62f3e2c --- /dev/null +++ b/x/avs_task/keeper/task_test.go @@ -0,0 +1,31 @@ +package keeper_test + +import tasktype "github.com/ExocoreNetwork/exocore/x/avs_task/types" + +func (suite *OperatorTestSuite) TestTaskInfo() { + info := &tasktype.RegisterAVSTaskReq{ + FromAddress: suite.AccAddress.String(), + Task: &tasktype.TaskContractInfo{ + Name: "test-task-01", + MetaInfo: "task up", + TaskContractAddress: "exo1j9ly7f0jynscjgvct0enevaa659te58k3xztc8", + Status: "active", + }, + } + err := suite.App.TaskKeeper.SetAvsTaskInfo(suite.Ctx, info) + suite.NoError(err) + + getTaskInfo, err := suite.App.TaskKeeper.GetAvsTaskInfo(suite.Ctx, "exo1j9ly7f0jynscjgvct0enevaa659te58k3xztc8") + suite.NoError(err) + suite.Equal(*info.Task, *getTaskInfo) +} + +func (suite *OperatorTestSuite) TestOperator_pubkey() { + + err := suite.App.TaskKeeper.SetOperatorPubKey(suite.Ctx, "exo1j9ly7f0jynscjgvct0enevaa659te58k3xztc8", []byte("pubkey")) + suite.NoError(err) + + pub2, err := suite.App.TaskKeeper.GetOperatorPubKey(suite.Ctx, "exo1j9ly7f0jynscjgvct0enevaa659te58k3xztc8") + suite.NoError(err) + suite.Equal([]byte("pubkey"), pub2) +} diff --git a/x/avs_task/module.go b/x/avs_task/module.go new file mode 100644 index 000000000..384f40dac --- /dev/null +++ b/x/avs_task/module.go @@ -0,0 +1,126 @@ +package avs_task + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/ExocoreNetwork/exocore/x/avs_task/client/cli" + "github.com/ExocoreNetwork/exocore/x/avs_task/keeper" + "github.com/ExocoreNetwork/exocore/x/avs_task/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + abci "github.com/cometbft/cometbft/abci/types" +) + +// type check to ensure the interface is properly implemented +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleSimulation = AppModule{} +) + +type AppModuleBasic struct{} + +func (b AppModuleBasic) Name() string { + return types.ModuleName +} + +func (b AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(amino) +} + +func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) +} + +func (b AppModuleBasic) RegisterGRPCGatewayRoutes( + c client.Context, + serveMux *runtime.ServeMux, +) { + if err := types.RegisterQueryHandlerClient( + context.Background(), serveMux, types.NewQueryClient(c), + ); err != nil { + panic(err) + } +} + +func (b AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +func (b AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +type AppModule struct { + AppModuleBasic + keeper keeper.Keeper +} + +func NewAppModule(_ codec.Codec, keeper keeper.Keeper) AppModule { + return AppModule{ + AppModuleBasic: AppModuleBasic{}, + keeper: keeper, + } +} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + +// RegisterServices registers module services. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), &am.keeper) + types.RegisterQueryServer(cfg.QueryServer(), &am.keeper) +} + +func (am AppModule) GenerateGenesisState(_ *module.SimulationState) { +} + +func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) { +} + +func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { + return []simtypes.WeightedOperation{} +} + +// EndBlock executes all ABCI EndBlock logic respective to the claim module. It +// returns no validator updates. +func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate { + //am.keeper.EndBlock(ctx, req) + return []abci.ValidatorUpdate{} +} + +// DefaultGenesis returns a default GenesisState for the module, marshaled to json.RawMessage. +// The default GenesisState need to be defined by the module developer and is primarily used for +// testing +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form +func (AppModuleBasic) ValidateGenesis( + cdc codec.JSONCodec, + _ client.TxEncodingConfig, + bz json.RawMessage, +) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf( + "failed to unmarshal %s genesis state: %w", + types.ModuleName, + err, + ) + } + return genState.Validate() +} diff --git a/x/avs_task/types/codec.go b/x/avs_task/types/codec.go new file mode 100644 index 000000000..3d8d1c99b --- /dev/null +++ b/x/avs_task/types/codec.go @@ -0,0 +1,50 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +var ( + amino = codec.NewLegacyAmino() + + // ModuleCdc references the global erc20 module codec. Note, the codec should + // ONLY be used in certain instances of tests and for JSON encoding. + // + // The actual codec used for serialization should be provided to modules/erc20 and + // defined at the application level. + ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) + + // AminoCdc is a amino codec created to support amino JSON compatible msgs. + AminoCdc = codec.NewAminoCodec(amino) +) + +const ( + // Amino names + RegisterAVSTask = "exocore/RegisterAVSTask" +) + +// NOTE: This is required for the GetSignBytes function +func init() { + RegisterLegacyAminoCodec(amino) + amino.Seal() +} + +// RegisterInterfaces register implementations +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &RegisterAVSTaskReq{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +// RegisterLegacyAminoCodec registers the necessary x/restaking_assets_manage interfaces and +// concrete types on the provided LegacyAmino codec. These types are used for +// Amino JSON serialization and EIP-712 compatibility. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&RegisterAVSTaskReq{}, RegisterAVSTask, nil) +} diff --git a/x/avs_task/types/errors.go b/x/avs_task/types/errors.go new file mode 100644 index 000000000..dfe650096 --- /dev/null +++ b/x/avs_task/types/errors.go @@ -0,0 +1,15 @@ +package types + +// DONTCOVER + +import ( + errorsmod "cosmossdk.io/errors" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +// x/avs_task module sentinel errors +var ( + ErrSample = sdkerrors.Register(ModuleName, 1100, "sample error") + ErrNoKeyInTheStore = errorsmod.Register(ModuleName, 0, "there is not the key for in the store") + ErrNotYetRegistered = errorsmod.Register(ModuleName, 1101, "this AVS has not been registered yet") +) diff --git a/x/avs_task/types/expected_keepers.go b/x/avs_task/types/expected_keepers.go new file mode 100644 index 000000000..364b1b1c6 --- /dev/null +++ b/x/avs_task/types/expected_keepers.go @@ -0,0 +1,27 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +// AccountKeeper defines the expected account keeper used for simulations (noalias) +type AccountKeeper interface { + GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI + // Methods imported from account should be defined here +} + +// BankKeeper defines the expected interface needed to retrieve account balances. +type BankKeeper interface { + SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins + // Methods imported from bank should be defined here +} +type AvsKeeperMock struct{} + +func (k AvsKeeperMock) IsAVS(sdk.Context, sdk.AccAddress) bool { + return true +} + +func (k AvsKeeperMock) getAvsAddress(sdk.Context, sdk.AccAddress) string { + return "0x00000000000000000000000000000000000009999" +} diff --git a/x/avs_task/types/genesis.go b/x/avs_task/types/genesis.go new file mode 100644 index 000000000..f2689b73b --- /dev/null +++ b/x/avs_task/types/genesis.go @@ -0,0 +1,20 @@ +package types + +// DefaultIndex is the default global index +const DefaultIndex uint64 = 1 + +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + // this line is used by starport scaffolding # genesis/types/default + Params: DefaultParams(), + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + // this line is used by starport scaffolding # genesis/types/validate + + return gs.Params.Validate() +} diff --git a/x/avs_task/types/genesis.pb.go b/x/avs_task/types/genesis.pb.go new file mode 100644 index 000000000..ef60b9489 --- /dev/null +++ b/x/avs_task/types/genesis.pb.go @@ -0,0 +1,323 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: exocore/avs_task/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the avs_task module's genesis state. +type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_e135dd7e592266ea, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "exocore.avs_task.GenesisState") +} + +func init() { + proto.RegisterFile("exocore/avs_task/genesis.proto", fileDescriptor_e135dd7e592266ea) +} + +var fileDescriptor_e135dd7e592266ea = []byte{ + // 204 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x49, 0xad, 0xc8, 0x4f, + 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x49, 0x2c, 0xce, 0xce, 0x4d, 0xcc, 0x4b, 0x4c, 0x4f, 0x2d, 0x4a, + 0x2c, 0x2b, 0xd6, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x12, 0x83, 0xaa, 0xd2, 0x43, 0x55, 0x25, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa2, + 0x0f, 0x62, 0x41, 0x54, 0x4b, 0x29, 0xe3, 0x30, 0xb3, 0x20, 0xb1, 0x28, 0x31, 0x17, 0x6a, 0xa4, + 0x92, 0x0f, 0x17, 0x8f, 0x3b, 0xc4, 0x8e, 0xe0, 0x92, 0xc4, 0x92, 0x54, 0x21, 0x1b, 0x2e, 0x36, + 0x88, 0xbc, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, 0x9c, 0x1e, 0x76, 0x3b, 0xf5, 0x02, 0xc0, + 0xaa, 0x9c, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0x82, 0xea, 0x71, 0x0a, 0x3a, 0xf1, 0x48, 0x8e, + 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, + 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x8b, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, + 0xfc, 0x5c, 0x7d, 0x57, 0x88, 0x89, 0x7e, 0xa9, 0x25, 0xe5, 0xf9, 0x45, 0xd9, 0xfa, 0x30, 0x67, + 0x56, 0xa0, 0x3b, 0xb4, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0xec, 0x50, 0x63, 0x40, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xe6, 0x36, 0x08, 0xc7, 0x23, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/avs_task/types/genesis_test.go b/x/avs_task/types/genesis_test.go new file mode 100644 index 000000000..da1ab5e57 --- /dev/null +++ b/x/avs_task/types/genesis_test.go @@ -0,0 +1,41 @@ +package types_test + +import ( + "testing" + + "github.com/ExocoreNetwork/exocore/x/avs_task/types" + "github.com/stretchr/testify/require" +) + +func TestGenesisState_Validate(t *testing.T) { + tests := []struct { + desc string + genState *types.GenesisState + valid bool + }{ + { + desc: "default is valid", + genState: types.DefaultGenesis(), + valid: true, + }, + { + desc: "valid genesis state", + genState: &types.GenesisState{ + + // this line is used by starport scaffolding # types/genesis/validField + }, + valid: true, + }, + // this line is used by starport scaffolding # types/genesis/testcase + } + for _, tc := range tests { + t.Run(tc.desc, func(t *testing.T) { + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} diff --git a/x/avs_task/types/keys.go b/x/avs_task/types/keys.go new file mode 100644 index 000000000..f2a3b93ad --- /dev/null +++ b/x/avs_task/types/keys.go @@ -0,0 +1,35 @@ +package types + +import ( + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/ethereum/go-ethereum/common" +) + +const ( + // ModuleName defines the module name + ModuleName = "task" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey defines the module's message routing key + RouterKey = ModuleName +) + +const ( + prefixAVSTaskInfo = iota + 1 + prefixOperatePub +) + +var ( + // KeyPrefixAVSTaskInfo key-value: taskAddr->AVSTaskInfo + KeyPrefixAVSTaskInfo = []byte{prefixAVSTaskInfo} + KeyPrefixOperatePub = []byte{prefixOperatePub} +) + +// ModuleAddress is the native module address for EVM +var ModuleAddress common.Address + +func init() { + ModuleAddress = common.BytesToAddress(authtypes.NewModuleAddress(ModuleName).Bytes()) +} diff --git a/x/avs_task/types/msg.go b/x/avs_task/types/msg.go new file mode 100644 index 000000000..c9203fe8b --- /dev/null +++ b/x/avs_task/types/msg.go @@ -0,0 +1,29 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var ( + _ sdk.Msg = &RegisterAVSTaskReq{} +) + +// GetSigners returns the expected signers for a MsgUpdateParams message. +func (m *RegisterAVSTaskReq) GetSigners() []sdk.AccAddress { + addr := sdk.MustAccAddressFromBech32(m.FromAddress) + return []sdk.AccAddress{addr} +} + +// ValidateBasic does a sanity check of the provided data +func (m *RegisterAVSTaskReq) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(m.FromAddress); err != nil { + return errorsmod.Wrap(err, "invalid address") + } + return nil +} + +// GetSignBytes implements the LegacyMsg interface. +func (m *RegisterAVSTaskReq) GetSignBytes() []byte { + return nil +} diff --git a/x/avs_task/types/params.go b/x/avs_task/types/params.go new file mode 100644 index 000000000..52a8a059f --- /dev/null +++ b/x/avs_task/types/params.go @@ -0,0 +1,47 @@ +package types + +import ( + + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "gopkg.in/yaml.v2" +) + +var _ paramtypes.ParamSet = (*Params)(nil) + + + +// ParamKeyTable the param key table for launch module +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// NewParams creates a new Params instance +func NewParams( +) Params { + return Params{ + } +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams( + ) +} + +// ParamSetPairs get the params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + } +} + +// Validate validates the set of params +func (p Params) Validate() error { + return nil +} + +// String implements the Stringer interface. +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} diff --git a/x/avs_task/types/params.pb.go b/x/avs_task/types/params.pb.go new file mode 100644 index 000000000..2a3c7baa9 --- /dev/null +++ b/x/avs_task/types/params.pb.go @@ -0,0 +1,267 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: exocore/avs_task/params.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Params defines the parameters for the module. +type Params struct { +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_9851cd4b575e9d94, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Params)(nil), "exocore.avs_task.Params") +} + +func init() { + proto.RegisterFile("exocore/avs_task/params.proto", fileDescriptor_9851cd4b575e9d94) +} + +var fileDescriptor_9851cd4b575e9d94 = []byte{ + // 162 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4e, 0xad, 0xc8, 0x4f, + 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x49, 0x2c, 0xce, 0xce, 0x4d, 0xcc, 0x4b, 0x4c, 0x4f, 0x2d, 0x4a, + 0x2c, 0x2b, 0xd6, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, + 0x12, 0x83, 0x2a, 0xd2, 0x43, 0x55, 0x24, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa2, 0x0f, + 0x62, 0x41, 0x54, 0x2b, 0xf1, 0x71, 0xb1, 0x05, 0x80, 0x75, 0x5b, 0xb1, 0xcc, 0x58, 0x20, 0xcf, + 0xe0, 0x14, 0x74, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, + 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x16, 0xe9, 0x99, + 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xae, 0x10, 0x2b, 0xfc, 0x52, 0x4b, 0xca, + 0xf3, 0x8b, 0xb2, 0xf5, 0x61, 0xce, 0xaa, 0x40, 0x77, 0x58, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, + 0x1b, 0xd8, 0x2a, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf6, 0xbc, 0x92, 0x25, 0xbf, 0x00, + 0x00, 0x00, +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/avs_task/types/query.pb.go b/x/avs_task/types/query.pb.go new file mode 100644 index 000000000..30af4a045 --- /dev/null +++ b/x/avs_task/types/query.pb.go @@ -0,0 +1,418 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: exocore/task/v1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cometbft/cometbft/proto/tendermint/crypto" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryAVSTaskInfoReq is the request to obtain the task information. +type GetAVSTaskInfoReq struct { + // task_addr is the task contract address,its type should be a sdk.AccAddress + TaskAddr string `protobuf:"bytes,1,opt,name=task_addr,json=taskAddr,proto3" json:"task_addr,omitempty"` +} + +func (m *GetAVSTaskInfoReq) Reset() { *m = GetAVSTaskInfoReq{} } +func (m *GetAVSTaskInfoReq) String() string { return proto.CompactTextString(m) } +func (*GetAVSTaskInfoReq) ProtoMessage() {} +func (*GetAVSTaskInfoReq) Descriptor() ([]byte, []int) { + return fileDescriptor_76ba8969919da189, []int{0} +} +func (m *GetAVSTaskInfoReq) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GetAVSTaskInfoReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GetAVSTaskInfoReq.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GetAVSTaskInfoReq) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetAVSTaskInfoReq.Merge(m, src) +} +func (m *GetAVSTaskInfoReq) XXX_Size() int { + return m.Size() +} +func (m *GetAVSTaskInfoReq) XXX_DiscardUnknown() { + xxx_messageInfo_GetAVSTaskInfoReq.DiscardUnknown(m) +} + +var xxx_messageInfo_GetAVSTaskInfoReq proto.InternalMessageInfo + +func (m *GetAVSTaskInfoReq) GetTaskAddr() string { + if m != nil { + return m.TaskAddr + } + return "" +} + +func init() { + proto.RegisterType((*GetAVSTaskInfoReq)(nil), "exocore.task.v1.GetAVSTaskInfoReq") +} + +func init() { proto.RegisterFile("exocore/task/v1/query.proto", fileDescriptor_76ba8969919da189) } + +var fileDescriptor_76ba8969919da189 = []byte{ + // 334 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x90, 0xc1, 0x4a, 0xc3, 0x30, + 0x18, 0xc7, 0x17, 0x41, 0x71, 0x3d, 0x28, 0x96, 0x1d, 0xe6, 0x1c, 0x45, 0x8b, 0x07, 0x11, 0x6c, + 0xd8, 0xc4, 0x07, 0xd8, 0x44, 0x44, 0x11, 0xc1, 0x4d, 0x3c, 0x78, 0x19, 0x59, 0x1b, 0x63, 0xa9, + 0xcb, 0xd7, 0x25, 0xdf, 0xe6, 0x7a, 0xd5, 0xb3, 0x20, 0xf8, 0x2a, 0x3e, 0x84, 0xc7, 0xa1, 0x17, + 0x8f, 0xb2, 0xf9, 0x20, 0x92, 0xb5, 0x0a, 0xae, 0xb7, 0xf6, 0xfb, 0xfd, 0xf3, 0xfb, 0x92, 0xbf, + 0xb5, 0xc1, 0x47, 0xe0, 0x83, 0xe2, 0x14, 0x99, 0x8e, 0xe8, 0xb0, 0x46, 0xfb, 0x03, 0xae, 0x12, + 0x2f, 0x56, 0x80, 0x60, 0xaf, 0x66, 0xd0, 0x33, 0xd0, 0x1b, 0xd6, 0x2a, 0xeb, 0x3e, 0xe8, 0x1e, + 0xe8, 0xce, 0x0c, 0xd3, 0xf4, 0x27, 0xcd, 0x56, 0xca, 0xf3, 0x22, 0x1c, 0x65, 0xa4, 0x24, 0x40, + 0x40, 0x7a, 0xc2, 0x7c, 0x65, 0xd3, 0xaa, 0x00, 0x10, 0x77, 0x9c, 0xb2, 0x38, 0xa4, 0x4c, 0x4a, + 0x40, 0x86, 0x21, 0xc8, 0x5f, 0x5b, 0x15, 0xb9, 0x0c, 0xb8, 0xea, 0x85, 0x12, 0xa9, 0xaf, 0x92, + 0x18, 0x81, 0x46, 0x3c, 0xc9, 0xa8, 0x7b, 0x6a, 0xad, 0x1d, 0x73, 0x6c, 0x5c, 0xb5, 0x2f, 0x99, + 0x8e, 0x4e, 0xe4, 0x0d, 0xb4, 0x78, 0xdf, 0x3e, 0xb0, 0x8a, 0x66, 0x75, 0x87, 0x05, 0x81, 0x2a, + 0x93, 0x4d, 0xb2, 0x53, 0x6c, 0x96, 0xdf, 0x5f, 0xf7, 0x4a, 0xd9, 0x2d, 0x1b, 0x41, 0xa0, 0xb8, + 0xd6, 0x6d, 0x54, 0xa1, 0x14, 0xad, 0x65, 0x13, 0x35, 0xa3, 0xfa, 0x13, 0xb1, 0x16, 0x2f, 0xcc, + 0x9b, 0xed, 0x47, 0x62, 0xad, 0xfc, 0xd7, 0xda, 0xae, 0x37, 0xd7, 0x80, 0x97, 0xdb, 0x5b, 0xd9, + 0xca, 0x65, 0x0c, 0x3d, 0x04, 0x89, 0x8a, 0xf9, 0x68, 0x52, 0xee, 0xee, 0xc3, 0xc7, 0xf7, 0xcb, + 0xc2, 0xb6, 0xed, 0xd2, 0xf9, 0x92, 0x72, 0xba, 0xe6, 0xd9, 0xdb, 0xc4, 0x21, 0xe3, 0x89, 0x43, + 0xbe, 0x26, 0x0e, 0x79, 0x9e, 0x3a, 0x85, 0xf1, 0xd4, 0x29, 0x7c, 0x4e, 0x9d, 0xc2, 0x75, 0x5d, + 0x84, 0x78, 0x3b, 0xe8, 0x7a, 0x3e, 0xf4, 0xe8, 0x51, 0xea, 0x39, 0xe7, 0x78, 0x0f, 0x2a, 0xfa, + 0xd3, 0x8e, 0x28, 0x1b, 0xea, 0xce, 0x4c, 0x8e, 0x49, 0xcc, 0x75, 0x77, 0x69, 0x56, 0xd8, 0xfe, + 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2f, 0x7d, 0x53, 0xb7, 0xe7, 0x01, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // TaskInfo queries the task information. + GetAVSTaskInfo(ctx context.Context, in *GetAVSTaskInfoReq, opts ...grpc.CallOption) (*TaskContractInfo, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) GetAVSTaskInfo(ctx context.Context, in *GetAVSTaskInfoReq, opts ...grpc.CallOption) (*TaskContractInfo, error) { + out := new(TaskContractInfo) + err := c.cc.Invoke(ctx, "/exocore.task.v1.Query/GetAVSTaskInfo", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // TaskInfo queries the task information. + GetAVSTaskInfo(context.Context, *GetAVSTaskInfoReq) (*TaskContractInfo, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) GetAVSTaskInfo(ctx context.Context, req *GetAVSTaskInfoReq) (*TaskContractInfo, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetAVSTaskInfo not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_GetAVSTaskInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetAVSTaskInfoReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GetAVSTaskInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/exocore.task.v1.Query/GetAVSTaskInfo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GetAVSTaskInfo(ctx, req.(*GetAVSTaskInfoReq)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "exocore.task.v1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetAVSTaskInfo", + Handler: _Query_GetAVSTaskInfo_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "exocore/task/v1/query.proto", +} + +func (m *GetAVSTaskInfoReq) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GetAVSTaskInfoReq) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GetAVSTaskInfoReq) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.TaskAddr) > 0 { + i -= len(m.TaskAddr) + copy(dAtA[i:], m.TaskAddr) + i = encodeVarintQuery(dAtA, i, uint64(len(m.TaskAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GetAVSTaskInfoReq) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.TaskAddr) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GetAVSTaskInfoReq) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GetAVSTaskInfoReq: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GetAVSTaskInfoReq: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TaskAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TaskAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/avs_task/types/query.pb.gw.go b/x/avs_task/types/query.pb.gw.go new file mode 100644 index 000000000..baf86d5e0 --- /dev/null +++ b/x/avs_task/types/query.pb.gw.go @@ -0,0 +1,171 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: exocore/task/v1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +var ( + filter_Query_GetAVSTaskInfo_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_GetAVSTaskInfo_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetAVSTaskInfoReq + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetAVSTaskInfo_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.GetAVSTaskInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GetAVSTaskInfo_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetAVSTaskInfoReq + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetAVSTaskInfo_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.GetAVSTaskInfo(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_GetAVSTaskInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_GetAVSTaskInfo_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetAVSTaskInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_GetAVSTaskInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_GetAVSTaskInfo_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GetAVSTaskInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_GetAVSTaskInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"exocore", "task", "v1", "GetAVSTaskInfoReq"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_GetAVSTaskInfo_0 = runtime.ForwardResponseMessage +) diff --git a/x/avs_task/types/tx.pb.go b/x/avs_task/types/tx.pb.go new file mode 100644 index 000000000..db6213f51 --- /dev/null +++ b/x/avs_task/types/tx.pb.go @@ -0,0 +1,966 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: exocore/task/v1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// TaskContractInfo is the task info. +type TaskContractInfo struct { + TaskContractAddress string `protobuf:"bytes,1,opt,name=TaskContractAddress,proto3" json:"TaskContractAddress,omitempty"` + Name string `protobuf:"bytes,2,opt,name=Name,proto3" json:"Name,omitempty"` + MetaInfo string `protobuf:"bytes,3,opt,name=MetaInfo,proto3" json:"MetaInfo,omitempty"` + Status string `protobuf:"bytes,4,opt,name=Status,proto3" json:"Status,omitempty"` + SourceCode string `protobuf:"bytes,5,opt,name=sourceCode,proto3" json:"sourceCode,omitempty"` +} + +func (m *TaskContractInfo) Reset() { *m = TaskContractInfo{} } +func (m *TaskContractInfo) String() string { return proto.CompactTextString(m) } +func (*TaskContractInfo) ProtoMessage() {} +func (*TaskContractInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_bb9b36cc7c0f3a98, []int{0} +} +func (m *TaskContractInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TaskContractInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TaskContractInfo.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *TaskContractInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_TaskContractInfo.Merge(m, src) +} +func (m *TaskContractInfo) XXX_Size() int { + return m.Size() +} +func (m *TaskContractInfo) XXX_DiscardUnknown() { + xxx_messageInfo_TaskContractInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_TaskContractInfo proto.InternalMessageInfo + +func (m *TaskContractInfo) GetTaskContractAddress() string { + if m != nil { + return m.TaskContractAddress + } + return "" +} + +func (m *TaskContractInfo) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *TaskContractInfo) GetMetaInfo() string { + if m != nil { + return m.MetaInfo + } + return "" +} + +func (m *TaskContractInfo) GetStatus() string { + if m != nil { + return m.Status + } + return "" +} + +func (m *TaskContractInfo) GetSourceCode() string { + if m != nil { + return m.SourceCode + } + return "" +} + +// RegisterAVSTaskReq is the request to register a new task for avs. +type RegisterAVSTaskReq struct { + // from_address is the address of the avs (sdk.AccAddress). + FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty"` + // info is the task info. + Task *TaskContractInfo `protobuf:"bytes,2,opt,name=task,proto3" json:"task,omitempty"` +} + +func (m *RegisterAVSTaskReq) Reset() { *m = RegisterAVSTaskReq{} } +func (m *RegisterAVSTaskReq) String() string { return proto.CompactTextString(m) } +func (*RegisterAVSTaskReq) ProtoMessage() {} +func (*RegisterAVSTaskReq) Descriptor() ([]byte, []int) { + return fileDescriptor_bb9b36cc7c0f3a98, []int{1} +} +func (m *RegisterAVSTaskReq) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RegisterAVSTaskReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RegisterAVSTaskReq.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *RegisterAVSTaskReq) XXX_Merge(src proto.Message) { + xxx_messageInfo_RegisterAVSTaskReq.Merge(m, src) +} +func (m *RegisterAVSTaskReq) XXX_Size() int { + return m.Size() +} +func (m *RegisterAVSTaskReq) XXX_DiscardUnknown() { + xxx_messageInfo_RegisterAVSTaskReq.DiscardUnknown(m) +} + +var xxx_messageInfo_RegisterAVSTaskReq proto.InternalMessageInfo + +type RegisterAVSTaskResponse struct { +} + +func (m *RegisterAVSTaskResponse) Reset() { *m = RegisterAVSTaskResponse{} } +func (m *RegisterAVSTaskResponse) String() string { return proto.CompactTextString(m) } +func (*RegisterAVSTaskResponse) ProtoMessage() {} +func (*RegisterAVSTaskResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_bb9b36cc7c0f3a98, []int{2} +} +func (m *RegisterAVSTaskResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RegisterAVSTaskResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RegisterAVSTaskResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *RegisterAVSTaskResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_RegisterAVSTaskResponse.Merge(m, src) +} +func (m *RegisterAVSTaskResponse) XXX_Size() int { + return m.Size() +} +func (m *RegisterAVSTaskResponse) XXX_DiscardUnknown() { + xxx_messageInfo_RegisterAVSTaskResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_RegisterAVSTaskResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*TaskContractInfo)(nil), "exocore.task.v1.TaskContractInfo") + proto.RegisterType((*RegisterAVSTaskReq)(nil), "exocore.task.v1.RegisterAVSTaskReq") + proto.RegisterType((*RegisterAVSTaskResponse)(nil), "exocore.task.v1.RegisterAVSTaskResponse") +} + +func init() { proto.RegisterFile("exocore/task/v1/tx.proto", fileDescriptor_bb9b36cc7c0f3a98) } + +var fileDescriptor_bb9b36cc7c0f3a98 = []byte{ + // 446 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x52, 0xcf, 0x6a, 0x13, 0x41, + 0x18, 0xdf, 0xb1, 0x69, 0xd1, 0x89, 0x50, 0x1d, 0x8b, 0xdd, 0xae, 0xb0, 0xd5, 0x78, 0x29, 0x81, + 0xee, 0xd8, 0x88, 0x20, 0x7a, 0x6a, 0x8b, 0x82, 0x60, 0x7b, 0xd8, 0x88, 0x07, 0x2f, 0x71, 0xba, + 0x99, 0x8e, 0x61, 0xd9, 0xfd, 0xe2, 0x7c, 0x93, 0x18, 0x6f, 0xe2, 0x49, 0x3c, 0xf9, 0x08, 0x7d, + 0x00, 0x0f, 0x39, 0xf8, 0x04, 0x9e, 0x3c, 0x16, 0x4f, 0x1e, 0x25, 0x39, 0xc4, 0xc7, 0x90, 0x9d, + 0xd9, 0x68, 0xd8, 0x08, 0x5e, 0x96, 0xf9, 0xfd, 0x99, 0x6f, 0x7e, 0xfb, 0xe3, 0xa3, 0xbe, 0x1c, + 0x41, 0x02, 0x5a, 0x72, 0x23, 0x30, 0xe5, 0xc3, 0x3d, 0x6e, 0x46, 0x51, 0x5f, 0x83, 0x01, 0xb6, + 0x5e, 0x2a, 0x51, 0xa1, 0x44, 0xc3, 0xbd, 0xe0, 0xaa, 0xc8, 0x7a, 0x39, 0x70, 0xfb, 0x75, 0x9e, + 0x60, 0x33, 0x01, 0xcc, 0x00, 0x79, 0x86, 0xaa, 0xb8, 0x9b, 0xa1, 0x2a, 0x85, 0x2d, 0x27, 0x74, + 0x2c, 0xe2, 0x0e, 0x94, 0xd2, 0x86, 0x02, 0x05, 0x8e, 0x2f, 0x4e, 0x8e, 0x6d, 0x7c, 0x26, 0xf4, + 0xca, 0x33, 0x81, 0xe9, 0x21, 0xe4, 0x46, 0x8b, 0xc4, 0x3c, 0xc9, 0x4f, 0x81, 0xdd, 0xa1, 0xd7, + 0x16, 0xb9, 0xfd, 0x6e, 0x57, 0x4b, 0x44, 0x9f, 0xdc, 0x24, 0x3b, 0x97, 0xe2, 0x7f, 0x49, 0x8c, + 0xd1, 0xda, 0xb1, 0xc8, 0xa4, 0x7f, 0xc1, 0x5a, 0xec, 0x99, 0x05, 0xf4, 0xe2, 0x91, 0x34, 0xa2, + 0x98, 0xe8, 0xaf, 0x58, 0xfe, 0x0f, 0x66, 0xd7, 0xe9, 0x5a, 0xdb, 0x08, 0x33, 0x40, 0xbf, 0x66, + 0x95, 0x12, 0xb1, 0x90, 0x52, 0x84, 0x81, 0x4e, 0xe4, 0x21, 0x74, 0xa5, 0xbf, 0x6a, 0xb5, 0x05, + 0xa6, 0xf1, 0x95, 0x50, 0x16, 0x4b, 0xd5, 0x43, 0x23, 0xf5, 0xfe, 0xf3, 0x76, 0x11, 0x25, 0x96, + 0xaf, 0xd9, 0x43, 0x7a, 0xf9, 0x54, 0x43, 0xd6, 0x11, 0x8b, 0x49, 0x0f, 0xfc, 0xef, 0x5f, 0x76, + 0x37, 0xca, 0x0e, 0xca, 0xa0, 0x6d, 0xa3, 0x7b, 0xb9, 0x8a, 0xeb, 0x85, 0x7b, 0x9e, 0xfd, 0x1e, + 0xad, 0x15, 0x55, 0xdb, 0xec, 0xf5, 0xd6, 0xad, 0xa8, 0xd2, 0x7f, 0x54, 0xad, 0x27, 0xb6, 0xf6, + 0x07, 0xf7, 0x3f, 0x9c, 0x6d, 0x7b, 0xbf, 0xce, 0xb6, 0xbd, 0xf7, 0xb3, 0x71, 0xb3, 0xfe, 0xf8, + 0xef, 0xc0, 0x8f, 0xb3, 0x71, 0xf3, 0x86, 0x7b, 0x76, 0x17, 0xbb, 0x29, 0xaf, 0xde, 0x6f, 0x6c, + 0xd1, 0xcd, 0xa5, 0x7f, 0xc0, 0x3e, 0xe4, 0x28, 0x5b, 0x39, 0x5d, 0x39, 0x42, 0xc5, 0x5e, 0xd2, + 0xf5, 0x8a, 0x83, 0xdd, 0x5e, 0xca, 0xb5, 0xdc, 0x43, 0xb0, 0xf3, 0x7f, 0x93, 0x7b, 0x28, 0x58, + 0x7d, 0x37, 0x1b, 0x37, 0xc9, 0xc1, 0xd3, 0x6f, 0x93, 0x90, 0x9c, 0x4f, 0x42, 0xf2, 0x73, 0x12, + 0x92, 0x4f, 0xd3, 0xd0, 0x3b, 0x9f, 0x86, 0xde, 0x8f, 0x69, 0xe8, 0xbd, 0x68, 0xa9, 0x9e, 0x79, + 0x35, 0x38, 0x89, 0x12, 0xc8, 0xf8, 0x23, 0x37, 0xf4, 0x58, 0x9a, 0x37, 0xa0, 0x53, 0x3e, 0x5f, + 0xdd, 0x11, 0x17, 0x43, 0xec, 0xd8, 0x05, 0x36, 0x6f, 0xfb, 0x12, 0x4f, 0xd6, 0xec, 0x4e, 0xdd, + 0xfd, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x81, 0x9e, 0x3a, 0xaf, 0xdd, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // RegisterAVSTask registers a new task. + RegisterAVSTask(ctx context.Context, in *RegisterAVSTaskReq, opts ...grpc.CallOption) (*RegisterAVSTaskResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) RegisterAVSTask(ctx context.Context, in *RegisterAVSTaskReq, opts ...grpc.CallOption) (*RegisterAVSTaskResponse, error) { + out := new(RegisterAVSTaskResponse) + err := c.cc.Invoke(ctx, "/exocore.task.v1.Msg/RegisterAVSTask", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // RegisterAVSTask registers a new task. + RegisterAVSTask(context.Context, *RegisterAVSTaskReq) (*RegisterAVSTaskResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) RegisterAVSTask(ctx context.Context, req *RegisterAVSTaskReq) (*RegisterAVSTaskResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RegisterAVSTask not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_RegisterAVSTask_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RegisterAVSTaskReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RegisterAVSTask(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/exocore.task.v1.Msg/RegisterAVSTask", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RegisterAVSTask(ctx, req.(*RegisterAVSTaskReq)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "exocore.task.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "RegisterAVSTask", + Handler: _Msg_RegisterAVSTask_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "exocore/task/v1/tx.proto", +} + +func (m *TaskContractInfo) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TaskContractInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TaskContractInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.SourceCode) > 0 { + i -= len(m.SourceCode) + copy(dAtA[i:], m.SourceCode) + i = encodeVarintTx(dAtA, i, uint64(len(m.SourceCode))) + i-- + dAtA[i] = 0x2a + } + if len(m.Status) > 0 { + i -= len(m.Status) + copy(dAtA[i:], m.Status) + i = encodeVarintTx(dAtA, i, uint64(len(m.Status))) + i-- + dAtA[i] = 0x22 + } + if len(m.MetaInfo) > 0 { + i -= len(m.MetaInfo) + copy(dAtA[i:], m.MetaInfo) + i = encodeVarintTx(dAtA, i, uint64(len(m.MetaInfo))) + i-- + dAtA[i] = 0x1a + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintTx(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x12 + } + if len(m.TaskContractAddress) > 0 { + i -= len(m.TaskContractAddress) + copy(dAtA[i:], m.TaskContractAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.TaskContractAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *RegisterAVSTaskReq) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *RegisterAVSTaskReq) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RegisterAVSTaskReq) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Task != nil { + { + size, err := m.Task.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.FromAddress) > 0 { + i -= len(m.FromAddress) + copy(dAtA[i:], m.FromAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.FromAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *RegisterAVSTaskResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *RegisterAVSTaskResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RegisterAVSTaskResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *TaskContractInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.TaskContractAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.MetaInfo) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Status) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.SourceCode) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *RegisterAVSTaskReq) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.FromAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Task != nil { + l = m.Task.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *RegisterAVSTaskResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *TaskContractInfo) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TaskContractInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TaskContractInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TaskContractAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TaskContractAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MetaInfo", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MetaInfo = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Status = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SourceCode", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SourceCode = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *RegisterAVSTaskReq) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: RegisterAVSTaskReq: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RegisterAVSTaskReq: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FromAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FromAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Task", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Task == nil { + m.Task = &TaskContractInfo{} + } + if err := m.Task.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *RegisterAVSTaskResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: RegisterAVSTaskResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RegisterAVSTaskResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/avs_task/types/types.go b/x/avs_task/types/types.go new file mode 100644 index 000000000..ab1254f4c --- /dev/null +++ b/x/avs_task/types/types.go @@ -0,0 +1 @@ +package types diff --git a/x/evm/keeper/precompiles.go b/x/evm/keeper/precompiles.go index da6d0caf9..cbf1c62ec 100644 --- a/x/evm/keeper/precompiles.go +++ b/x/evm/keeper/precompiles.go @@ -2,6 +2,9 @@ package keeper import ( "fmt" + taskPrecompile "github.com/ExocoreNetwork/exocore/precompiles/avsTask" + taskKeeper "github.com/ExocoreNetwork/exocore/x/avs_task/keeper" + tasktype "github.com/ExocoreNetwork/exocore/x/avs_task/types" stakingStateKeeper "github.com/ExocoreNetwork/exocore/x/assets/keeper" rewardKeeper "github.com/ExocoreNetwork/exocore/x/reward/keeper" @@ -44,6 +47,7 @@ func AvailablePrecompiles( slashKeeper exoslashKeeper.Keeper, rewardKeeper rewardKeeper.Keeper, avsManagerKeeper avsManagerKeeper.Keeper, + taskKeeper taskKeeper.Keeper, ) map[common.Address]vm.PrecompiledContract { // Clone the mapping from the latest EVM fork. precompiles := maps.Clone(vm.PrecompiledContractsBerlin) @@ -107,13 +111,17 @@ func AvailablePrecompiles( if err != nil { panic(fmt.Errorf("failed to load avsManager precompile: %w", err)) } + taskPrecompile, err := taskPrecompile.NewPrecompile(authzKeeper, taskKeeper, tasktype.AvsKeeperMock{}) + if err != nil { + panic(fmt.Errorf("failed to load reward precompile: %w", err)) + } precompiles[slashPrecompile.Address()] = slashPrecompile precompiles[rewardPrecompile.Address()] = rewardPrecompile precompiles[withdrawPrecompile.Address()] = withdrawPrecompile precompiles[depositPrecompile.Address()] = depositPrecompile precompiles[delegationPrecompile.Address()] = delegationPrecompile precompiles[avsManagerPrecompile.Address()] = avsManagerPrecompile - + precompiles[taskPrecompile.Address()] = taskPrecompile precompiles[stakingPrecompile.Address()] = stakingPrecompile precompiles[ibcTransferPrecompile.Address()] = ibcTransferPrecompile return precompiles