From 3e53ee4c0d852ebb3b8af7ab54145d5475e5c81b Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 31 May 2024 16:12:32 -0400 Subject: [PATCH 01/12] add messages --- docs/openapi/openapi.swagger.yaml | 8 + docs/spec/authority/messages.md | 21 + proto/zetachain/zetacore/authority/tx.proto | 27 + .../zetachain/zetacore/authority/tx_pb.d.ts | 115 ++- .../keeper/msg_server_add_authorization.go | 34 + .../msg_server_add_authorization_test.go | 200 ++++ .../keeper/msg_server_remove_authorization.go | 50 + .../msg_server_remove_authorization_test.go | 139 +++ x/authority/types/authorizations.go | 5 +- x/authority/types/authorizations_test.go | 51 +- x/authority/types/errors.go | 7 +- x/authority/types/tx.pb.go | 916 ++++++++++++++++-- 12 files changed, 1492 insertions(+), 81 deletions(-) create mode 100644 x/authority/keeper/msg_server_add_authorization.go create mode 100644 x/authority/keeper/msg_server_add_authorization_test.go create mode 100644 x/authority/keeper/msg_server_remove_authorization.go create mode 100644 x/authority/keeper/msg_server_remove_authorization_test.go diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index c9e758227f..470b246295 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -56730,6 +56730,14 @@ definitions: ChainInfo contains static information about the chains This structure is used to dynamically update these info on a live network before hardcoding the values in a upgrade + authorityMsgAddAuthorizationResponse: + type: object + description: MsgAddAuthorizationResponse defines the MsgAddAuthorizationResponse service. + authorityMsgRemoveAuthorizationResponse: + type: object + description: |- + MsgRemoveAuthorizationResponse defines the MsgRemoveAuthorizationResponse + service. authorityMsgUpdateChainInfoResponse: type: object description: MsgUpdateChainInfoResponse defines the MsgUpdateChainInfoResponse service. diff --git a/docs/spec/authority/messages.md b/docs/spec/authority/messages.md index 899a95b989..329cf8b5ec 100644 --- a/docs/spec/authority/messages.md +++ b/docs/spec/authority/messages.md @@ -23,3 +23,24 @@ message MsgUpdateChainInfo { } ``` +## MsgAddAuthorization + +```proto +message MsgAddAuthorization { + string creator = 1; + string msg_url = 2; + Policy policy = 3; +} +``` + +## MsgRemoveAuthorization + +RemoveAuthorization removes the authorization from the list. It does not check if the authorization exists or not. + +```proto +message MsgRemoveAuthorization { + string creator = 1; + string msg_url = 2; +} +``` + diff --git a/proto/zetachain/zetacore/authority/tx.proto b/proto/zetachain/zetacore/authority/tx.proto index 55509e3172..29b1b44362 100644 --- a/proto/zetachain/zetacore/authority/tx.proto +++ b/proto/zetachain/zetacore/authority/tx.proto @@ -12,8 +12,35 @@ option go_package = "github.com/zeta-chain/zetacore/x/authority/types"; service Msg { rpc UpdatePolicies(MsgUpdatePolicies) returns (MsgUpdatePoliciesResponse); rpc UpdateChainInfo(MsgUpdateChainInfo) returns (MsgUpdateChainInfoResponse); + rpc AddAuthorization(MsgAddAuthorization) + returns (MsgAddAuthorizationResponse); + rpc RemoveAuthorization(MsgRemoveAuthorization) + returns (MsgRemoveAuthorizationResponse); } +// MsgAddAuthorization defines the MsgAddAuthorization service. +// Adds an authorization to the chain. If the authorization already exists, it +// will be updated. +message MsgAddAuthorization { + string creator = 1; + string msg_url = 2; + PolicyType authorized_policy = 3; +} + +// MsgAddAuthorizationResponse defines the MsgAddAuthorizationResponse service. +message MsgAddAuthorizationResponse {} + +// MsgRemoveAuthorization defines the MsgRemoveAuthorization service. +// Removes an authorization from the chain. +message MsgRemoveAuthorization { + string creator = 1; + string msg_url = 2; +} + +// MsgRemoveAuthorizationResponse defines the MsgRemoveAuthorizationResponse +// service. +message MsgRemoveAuthorizationResponse {} + // MsgUpdatePolicies defines the MsgUpdatePolicies service. message MsgUpdatePolicies { string creator = 1; diff --git a/typescript/zetachain/zetacore/authority/tx_pb.d.ts b/typescript/zetachain/zetacore/authority/tx_pb.d.ts index bd531ac2e5..391d9632ab 100644 --- a/typescript/zetachain/zetacore/authority/tx_pb.d.ts +++ b/typescript/zetachain/zetacore/authority/tx_pb.d.ts @@ -5,9 +5,122 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; import { Message, proto3 } from "@bufbuild/protobuf"; -import type { Policies } from "./policies_pb.js"; +import type { Policies, Policy } from "./policies_pb.js"; import type { ChainInfo } from "./chain_info_pb.js"; +/** + * MsgAddAuthorization defines the MsgAddAuthorization service. + * Adds an authorization to the chain. If the authorization already exists, it + * will be updated. + * + * @generated from message zetachain.zetacore.authority.MsgAddAuthorization + */ +export declare class MsgAddAuthorization extends Message { + /** + * @generated from field: string creator = 1; + */ + creator: string; + + /** + * @generated from field: string msg_url = 2; + */ + msgUrl: string; + + /** + * @generated from field: zetachain.zetacore.authority.Policy policy = 3; + */ + policy?: Policy; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.MsgAddAuthorization"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgAddAuthorization; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgAddAuthorization; + + static fromJsonString(jsonString: string, options?: Partial): MsgAddAuthorization; + + static equals(a: MsgAddAuthorization | PlainMessage | undefined, b: MsgAddAuthorization | PlainMessage | undefined): boolean; +} + +/** + * MsgAddAuthorizationResponse defines the MsgAddAuthorizationResponse service. + * + * @generated from message zetachain.zetacore.authority.MsgAddAuthorizationResponse + */ +export declare class MsgAddAuthorizationResponse extends Message { + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.MsgAddAuthorizationResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgAddAuthorizationResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgAddAuthorizationResponse; + + static fromJsonString(jsonString: string, options?: Partial): MsgAddAuthorizationResponse; + + static equals(a: MsgAddAuthorizationResponse | PlainMessage | undefined, b: MsgAddAuthorizationResponse | PlainMessage | undefined): boolean; +} + +/** + * MsgRemoveAuthorization defines the MsgRemoveAuthorization service. + * Removes an authorization from the chain. + * + * @generated from message zetachain.zetacore.authority.MsgRemoveAuthorization + */ +export declare class MsgRemoveAuthorization extends Message { + /** + * @generated from field: string creator = 1; + */ + creator: string; + + /** + * @generated from field: string msg_url = 2; + */ + msgUrl: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.MsgRemoveAuthorization"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgRemoveAuthorization; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgRemoveAuthorization; + + static fromJsonString(jsonString: string, options?: Partial): MsgRemoveAuthorization; + + static equals(a: MsgRemoveAuthorization | PlainMessage | undefined, b: MsgRemoveAuthorization | PlainMessage | undefined): boolean; +} + +/** + * MsgRemoveAuthorizationResponse defines the MsgRemoveAuthorizationResponse + * service. + * + * @generated from message zetachain.zetacore.authority.MsgRemoveAuthorizationResponse + */ +export declare class MsgRemoveAuthorizationResponse extends Message { + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.MsgRemoveAuthorizationResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgRemoveAuthorizationResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgRemoveAuthorizationResponse; + + static fromJsonString(jsonString: string, options?: Partial): MsgRemoveAuthorizationResponse; + + static equals(a: MsgRemoveAuthorizationResponse | PlainMessage | undefined, b: MsgRemoveAuthorizationResponse | PlainMessage | undefined): boolean; +} + /** * MsgUpdatePolicies defines the MsgUpdatePolicies service. * diff --git a/x/authority/keeper/msg_server_add_authorization.go b/x/authority/keeper/msg_server_add_authorization.go new file mode 100644 index 0000000000..bb72c48d11 --- /dev/null +++ b/x/authority/keeper/msg_server_add_authorization.go @@ -0,0 +1,34 @@ +package keeper + +import ( + "context" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +// AddAuthorization defines a method to add an authorization.If the authorization already exists, it will be overwritten with the provided policy. +// This should be called by the admin policy account. +func (k msgServer) AddAuthorization(goCtx context.Context, msg *types.MsgAddAuthorization) (*types.MsgAddAuthorizationResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if !k.IsAuthorized(ctx, msg.Creator, types.PolicyType_groupAdmin) { + return nil, errorsmod.Wrap( + types.ErrUnauthorized, + "AddAuthorization can only be executed by the admin policy account", + ) + } + + authorizationList, _ := k.GetAuthorizationList(ctx) + authorizationList.SetAuthorization(types.Authorization{MsgUrl: msg.MsgUrl, AuthorizedPolicy: msg.AuthorizedPolicy}) + + // validate the authorization list after adding the authorization as a precautionary measure. + err := authorizationList.Validate() + if err != nil { + return nil, errorsmod.Wrap(err, "authorization list is invalid") + } + + k.SetAuthorizationList(ctx, authorizationList) + return &types.MsgAddAuthorizationResponse{}, nil +} diff --git a/x/authority/keeper/msg_server_add_authorization_test.go b/x/authority/keeper/msg_server_add_authorization_test.go new file mode 100644 index 0000000000..35115221cb --- /dev/null +++ b/x/authority/keeper/msg_server_add_authorization_test.go @@ -0,0 +1,200 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/authority/keeper" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestMsgServer_AddAuthorization(t *testing.T) { + t.Run("successfully add authorization of type admin to existing authorization list", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolices(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + msgServer := keeper.NewMsgServerImpl(*k) + url := "/zetachain.zetacore.sample.ABC" + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupAdmin, policy) + }) + + t.Run("successfully add authorization of type operational to existing authorization list", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolices(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + msgServer := keeper.NewMsgServerImpl(*k) + url := "/zetachain.zetacore.sample.ABC" + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupOperational, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupOperational, policy) + }) + + t.Run("successfully add authorization of type emergency to existing authorization list", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolices(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + msgServer := keeper.NewMsgServerImpl(*k) + url := "/zetachain.zetacore.sample.ABC" + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupEmergency, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupEmergency, policy) + }) + + t.Run("successfully add authorization to empty authorization list", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolices(ctx, k) + k.SetAuthorizationList(ctx, types.AuthorizationList{}) + msgServer := keeper.NewMsgServerImpl(*k) + url := "/zetachain.zetacore.sample.ABC" + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupAdmin, policy) + }) + + t.Run("successfully set authorization when list is not found ", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolices(ctx, k) + msgServer := keeper.NewMsgServerImpl(*k) + url := "/zetachain.zetacore.sample.ABC" + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupAdmin, policy) + }) + + t.Run("update existing authorization", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolices(ctx, k) + k.SetAuthorizationList(ctx, types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "/zetachain.zetacore.sample.ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }, + }) + msgServer := keeper.NewMsgServerImpl(*k) + url := "/zetachain.zetacore.sample.ABC" + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + policy, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err) + require.Equal(t, types.PolicyType_groupAdmin, policy) + }) + + t.Run("fail to add authorization with invalid policy as creator", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + msgServer := keeper.NewMsgServerImpl(*k) + url := "/zetachain.zetacore.sample.ABC" + + msg := &types.MsgAddAuthorization{ + Creator: sample.AccAddress(), + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrUnauthorized) + }) + + // This scenario is not possible as the authorization list is always valid.But it is good to have in case the validation logic is changed in the future + t.Run("fail to set invalid authorization list", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolices(ctx, k) + k.SetAuthorizationList(ctx, types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "/zetachain.zetacore.sample.ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + { + MsgUrl: "/zetachain.zetacore.sample.ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }}) + msgServer := keeper.NewMsgServerImpl(*k) + url := "/zetachain.zetacore.sample.ABC" + + msg := &types.MsgAddAuthorization{ + Creator: admin, + MsgUrl: url, + AuthorizedPolicy: types.PolicyType_groupAdmin, + } + + _, err := msgServer.AddAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrInvalidAuthorizationList) + }) +} diff --git a/x/authority/keeper/msg_server_remove_authorization.go b/x/authority/keeper/msg_server_remove_authorization.go new file mode 100644 index 0000000000..d51df49b23 --- /dev/null +++ b/x/authority/keeper/msg_server_remove_authorization.go @@ -0,0 +1,50 @@ +package keeper + +import ( + "context" + "fmt" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +// RemoveAuthorization defines a method to remove an authorization. +// This should be called by the admin policy account. +func (k msgServer) RemoveAuthorization(goCtx context.Context, msg *types.MsgRemoveAuthorization) (*types.MsgRemoveAuthorizationResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if !k.IsAuthorized(ctx, msg.Creator, types.PolicyType_groupAdmin) { + return nil, errorsmod.Wrap( + types.ErrUnauthorized, + "RemoveAuthorization can only be executed by the admin policy account", + ) + } + + // check if the authorization list exists, we can return early if there is no list. + authorizationList, found := k.GetAuthorizationList(ctx) + if !found { + return nil, errorsmod.Wrap( + types.ErrAuthorizationListNotFound, + "authorization list not found", + ) + } + + // check if the authorization exists, we can return early if the authorization does not exist. + _, err := authorizationList.GetAuthorizedPolicy(msg.MsgUrl) + if err != nil { + return nil, errorsmod.Wrap(err, fmt.Sprintf("msg url %s", msg.MsgUrl)) + } + + // remove the authorization + authorizationList.RemoveAuthorization(msg.MsgUrl) + + // validate the authorization list after adding the authorization as a precautionary measure. + err = authorizationList.Validate() + if err != nil { + return nil, errorsmod.Wrap(err, "authorization list is invalid") + } + k.SetAuthorizationList(ctx, authorizationList) + + return &types.MsgRemoveAuthorizationResponse{}, nil +} diff --git a/x/authority/keeper/msg_server_remove_authorization_test.go b/x/authority/keeper/msg_server_remove_authorization_test.go new file mode 100644 index 0000000000..89e0ee7702 --- /dev/null +++ b/x/authority/keeper/msg_server_remove_authorization_test.go @@ -0,0 +1,139 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/authority/keeper" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestMsgServer_RemoveAuthorization(t *testing.T) { + t.Run("successfully remove authorization", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolices(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + msgServer := keeper.NewMsgServerImpl(*k) + url := types.OperationPolicyMessages[0] + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: url, + } + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + _, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err, types.ErrAuthorizationNotFound) + + _, err = msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found = k.GetAuthorizationList(ctx) + require.True(t, found) + _, err = authorizationList.GetAuthorizedPolicy(url) + require.ErrorIs(t, err, types.ErrAuthorizationNotFound) + }) + + t.Run("unable to remove authorization if creator is not the correct policy", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + msgServer := keeper.NewMsgServerImpl(*k) + url := types.OperationPolicyMessages[0] + + msg := &types.MsgRemoveAuthorization{ + Creator: sample.AccAddress(), + MsgUrl: url, + } + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + _, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err, types.ErrAuthorizationNotFound) + + _, err = msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrUnauthorized) + + authorizationList, found = k.GetAuthorizationList(ctx) + require.True(t, found) + require.Equal(t, types.DefaultAuthorizationsList(), authorizationList) + }) + + t.Run("unable to remove authorization if authorization list does not exist", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolices(ctx, k) + msgServer := keeper.NewMsgServerImpl(*k) + url := types.OperationPolicyMessages[0] + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: url, + } + + _, err := msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrAuthorizationListNotFound) + }) + + t.Run("unable to remove authorization if authorization does not exist", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolices(ctx, k) + authorizationList := types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }} + k.SetAuthorizationList(ctx, authorizationList) + msgServer := keeper.NewMsgServerImpl(*k) + url := "invalid" + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: url, + } + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + _, err := authorizationList.GetAuthorizedPolicy(url) + require.ErrorIs(t, err, types.ErrAuthorizationNotFound) + + _, err = msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrAuthorizationNotFound) + + authorizationListNew, found := k.GetAuthorizationList(ctx) + require.True(t, found) + require.Equal(t, authorizationList, authorizationListNew) + }) + + t.Run("unable to remove authorization if authorization list is invalid", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolices(ctx, k) + authorizationList := types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }} + k.SetAuthorizationList(ctx, authorizationList) + msgServer := keeper.NewMsgServerImpl(*k) + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: "ABC", + } + + _, err := msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.ErrorIs(t, err, types.ErrInvalidAuthorizationList) + }) +} diff --git a/x/authority/types/authorizations.go b/x/authority/types/authorizations.go index 0de98a768e..a864e2abf9 100644 --- a/x/authority/types/authorizations.go +++ b/x/authority/types/authorizations.go @@ -94,10 +94,11 @@ func (a *AuthorizationList) SetAuthorization(authorization Authorization) { } // RemoveAuthorization removes the authorization from the list. It does not check if the authorization exists or not. -func (a *AuthorizationList) RemoveAuthorization(authorization Authorization) { +func (a *AuthorizationList) RemoveAuthorization(msgURL string) { for i, auth := range a.Authorizations { - if auth.MsgUrl == authorization.MsgUrl { + if auth.MsgUrl == msgURL { a.Authorizations = append(a.Authorizations[:i], a.Authorizations[i+1:]...) + return } } } diff --git a/x/authority/types/authorizations_test.go b/x/authority/types/authorizations_test.go index 8bb7ed805a..84864372a4 100644 --- a/x/authority/types/authorizations_test.go +++ b/x/authority/types/authorizations_test.go @@ -275,10 +275,10 @@ func TestAuthorizationList_Validate(t *testing.T) { func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { tt := []struct { - name string - oldList types.AuthorizationList - removeAuthorization types.Authorization - expectedList types.AuthorizationList + name string + oldList types.AuthorizationList + removeMsgUrl string + expectedList types.AuthorizationList }{ { name: "remove authorization successfully", @@ -292,9 +292,7 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { AuthorizedPolicy: types.PolicyType_groupOperational, }, }}, - removeAuthorization: types.Authorization{ - MsgUrl: "ABC", - }, + removeMsgUrl: "XYZ", expectedList: types.AuthorizationList{Authorizations: []types.Authorization{ { MsgUrl: "XYZ", @@ -318,9 +316,7 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { AuthorizedPolicy: types.PolicyType_groupOperational, }, }}, - removeAuthorization: types.Authorization{ - MsgUrl: "XYZ", - }, + removeMsgUrl: "XYZ", expectedList: types.AuthorizationList{Authorizations: []types.Authorization{ { MsgUrl: "ABC", @@ -333,11 +329,9 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { }}, }, { - name: "do not remove anything when trying to remove from an empty list", - oldList: types.AuthorizationList{Authorizations: []types.Authorization{}}, - removeAuthorization: types.Authorization{ - MsgUrl: "XYZ", - }, + name: "do not remove anything when trying to remove from an empty list", + oldList: types.AuthorizationList{Authorizations: []types.Authorization{}}, + removeMsgUrl: "XYZ", expectedList: types.AuthorizationList{Authorizations: []types.Authorization{}}, }, { @@ -348,9 +342,28 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { AuthorizedPolicy: types.PolicyType_groupOperational, }, }}, - removeAuthorization: types.Authorization{ - MsgUrl: "XYZ", - }, + removeMsgUrl: "XYZ", + expectedList: types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }}, + }, + // The list is invalid, but this test case tries to assert the expected functionality + { + name: "return after removing first occurance", + oldList: types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }}, + removeMsgUrl: "ABC", expectedList: types.AuthorizationList{Authorizations: []types.Authorization{ { MsgUrl: "ABC", @@ -361,7 +374,7 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { - tc.oldList.RemoveAuthorization(tc.removeAuthorization) + tc.oldList.RemoveAuthorization(tc.removeMsgUrl) require.Equal(t, tc.expectedList, tc.oldList) }) } diff --git a/x/authority/types/errors.go b/x/authority/types/errors.go index 88b44b9887..9d9509e9d4 100644 --- a/x/authority/types/errors.go +++ b/x/authority/types/errors.go @@ -3,7 +3,8 @@ package types import errorsmod "cosmossdk.io/errors" var ( - ErrUnauthorized = errorsmod.Register(ModuleName, 1102, "sender not authorized") - ErrInvalidAuthorizationList = errorsmod.Register(ModuleName, 1103, "invalid authorization list") - ErrAuthorizationNotFound = errorsmod.Register(ModuleName, 1104, "authorization not found") + ErrUnauthorized = errorsmod.Register(ModuleName, 1102, "sender not authorized") + ErrInvalidAuthorizationList = errorsmod.Register(ModuleName, 1103, "invalid authorization list") + ErrAuthorizationNotFound = errorsmod.Register(ModuleName, 1104, "authorization not found") + ErrAuthorizationListNotFound = errorsmod.Register(ModuleName, 1105, "authorization list not found") ) diff --git a/x/authority/types/tx.pb.go b/x/authority/types/tx.pb.go index ac5c04416b..928353417f 100644 --- a/x/authority/types/tx.pb.go +++ b/x/authority/types/tx.pb.go @@ -28,6 +28,198 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// MsgAddAuthorization defines the MsgAddAuthorization service. +// Adds an authorization to the chain. If the authorization already exists, it +// will be updated. +type MsgAddAuthorization struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + MsgUrl string `protobuf:"bytes,2,opt,name=msg_url,json=msgUrl,proto3" json:"msg_url,omitempty"` + AuthorizedPolicy PolicyType `protobuf:"varint,3,opt,name=authorized_policy,json=authorizedPolicy,proto3,enum=zetachain.zetacore.authority.PolicyType" json:"authorized_policy,omitempty"` +} + +func (m *MsgAddAuthorization) Reset() { *m = MsgAddAuthorization{} } +func (m *MsgAddAuthorization) String() string { return proto.CompactTextString(m) } +func (*MsgAddAuthorization) ProtoMessage() {} +func (*MsgAddAuthorization) Descriptor() ([]byte, []int) { + return fileDescriptor_42e081863c477116, []int{0} +} +func (m *MsgAddAuthorization) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAddAuthorization) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAddAuthorization.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 *MsgAddAuthorization) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAddAuthorization.Merge(m, src) +} +func (m *MsgAddAuthorization) XXX_Size() int { + return m.Size() +} +func (m *MsgAddAuthorization) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAddAuthorization.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAddAuthorization proto.InternalMessageInfo + +func (m *MsgAddAuthorization) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgAddAuthorization) GetMsgUrl() string { + if m != nil { + return m.MsgUrl + } + return "" +} + +func (m *MsgAddAuthorization) GetAuthorizedPolicy() PolicyType { + if m != nil { + return m.AuthorizedPolicy + } + return PolicyType_groupEmergency +} + +// MsgAddAuthorizationResponse defines the MsgAddAuthorizationResponse service. +type MsgAddAuthorizationResponse struct { +} + +func (m *MsgAddAuthorizationResponse) Reset() { *m = MsgAddAuthorizationResponse{} } +func (m *MsgAddAuthorizationResponse) String() string { return proto.CompactTextString(m) } +func (*MsgAddAuthorizationResponse) ProtoMessage() {} +func (*MsgAddAuthorizationResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_42e081863c477116, []int{1} +} +func (m *MsgAddAuthorizationResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAddAuthorizationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAddAuthorizationResponse.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 *MsgAddAuthorizationResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAddAuthorizationResponse.Merge(m, src) +} +func (m *MsgAddAuthorizationResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgAddAuthorizationResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAddAuthorizationResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAddAuthorizationResponse proto.InternalMessageInfo + +// MsgRemoveAuthorization defines the MsgRemoveAuthorization service. +// Removes an authorization from the chain. +type MsgRemoveAuthorization struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + MsgUrl string `protobuf:"bytes,2,opt,name=msg_url,json=msgUrl,proto3" json:"msg_url,omitempty"` +} + +func (m *MsgRemoveAuthorization) Reset() { *m = MsgRemoveAuthorization{} } +func (m *MsgRemoveAuthorization) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveAuthorization) ProtoMessage() {} +func (*MsgRemoveAuthorization) Descriptor() ([]byte, []int) { + return fileDescriptor_42e081863c477116, []int{2} +} +func (m *MsgRemoveAuthorization) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveAuthorization) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveAuthorization.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 *MsgRemoveAuthorization) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveAuthorization.Merge(m, src) +} +func (m *MsgRemoveAuthorization) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveAuthorization) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveAuthorization.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveAuthorization proto.InternalMessageInfo + +func (m *MsgRemoveAuthorization) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgRemoveAuthorization) GetMsgUrl() string { + if m != nil { + return m.MsgUrl + } + return "" +} + +// MsgRemoveAuthorizationResponse defines the MsgRemoveAuthorizationResponse +// service. +type MsgRemoveAuthorizationResponse struct { +} + +func (m *MsgRemoveAuthorizationResponse) Reset() { *m = MsgRemoveAuthorizationResponse{} } +func (m *MsgRemoveAuthorizationResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveAuthorizationResponse) ProtoMessage() {} +func (*MsgRemoveAuthorizationResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_42e081863c477116, []int{3} +} +func (m *MsgRemoveAuthorizationResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveAuthorizationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveAuthorizationResponse.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 *MsgRemoveAuthorizationResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveAuthorizationResponse.Merge(m, src) +} +func (m *MsgRemoveAuthorizationResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveAuthorizationResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveAuthorizationResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveAuthorizationResponse proto.InternalMessageInfo + // MsgUpdatePolicies defines the MsgUpdatePolicies service. type MsgUpdatePolicies struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` @@ -38,7 +230,7 @@ func (m *MsgUpdatePolicies) Reset() { *m = MsgUpdatePolicies{} } func (m *MsgUpdatePolicies) String() string { return proto.CompactTextString(m) } func (*MsgUpdatePolicies) ProtoMessage() {} func (*MsgUpdatePolicies) Descriptor() ([]byte, []int) { - return fileDescriptor_42e081863c477116, []int{0} + return fileDescriptor_42e081863c477116, []int{4} } func (m *MsgUpdatePolicies) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -89,7 +281,7 @@ func (m *MsgUpdatePoliciesResponse) Reset() { *m = MsgUpdatePoliciesResp func (m *MsgUpdatePoliciesResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdatePoliciesResponse) ProtoMessage() {} func (*MsgUpdatePoliciesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_42e081863c477116, []int{1} + return fileDescriptor_42e081863c477116, []int{5} } func (m *MsgUpdatePoliciesResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -128,7 +320,7 @@ func (m *MsgUpdateChainInfo) Reset() { *m = MsgUpdateChainInfo{} } func (m *MsgUpdateChainInfo) String() string { return proto.CompactTextString(m) } func (*MsgUpdateChainInfo) ProtoMessage() {} func (*MsgUpdateChainInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_42e081863c477116, []int{2} + return fileDescriptor_42e081863c477116, []int{6} } func (m *MsgUpdateChainInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -179,7 +371,7 @@ func (m *MsgUpdateChainInfoResponse) Reset() { *m = MsgUpdateChainInfoRe func (m *MsgUpdateChainInfoResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdateChainInfoResponse) ProtoMessage() {} func (*MsgUpdateChainInfoResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_42e081863c477116, []int{3} + return fileDescriptor_42e081863c477116, []int{7} } func (m *MsgUpdateChainInfoResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -209,6 +401,10 @@ func (m *MsgUpdateChainInfoResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateChainInfoResponse proto.InternalMessageInfo func init() { + proto.RegisterType((*MsgAddAuthorization)(nil), "zetachain.zetacore.authority.MsgAddAuthorization") + proto.RegisterType((*MsgAddAuthorizationResponse)(nil), "zetachain.zetacore.authority.MsgAddAuthorizationResponse") + proto.RegisterType((*MsgRemoveAuthorization)(nil), "zetachain.zetacore.authority.MsgRemoveAuthorization") + proto.RegisterType((*MsgRemoveAuthorizationResponse)(nil), "zetachain.zetacore.authority.MsgRemoveAuthorizationResponse") proto.RegisterType((*MsgUpdatePolicies)(nil), "zetachain.zetacore.authority.MsgUpdatePolicies") proto.RegisterType((*MsgUpdatePoliciesResponse)(nil), "zetachain.zetacore.authority.MsgUpdatePoliciesResponse") proto.RegisterType((*MsgUpdateChainInfo)(nil), "zetachain.zetacore.authority.MsgUpdateChainInfo") @@ -220,29 +416,38 @@ func init() { } var fileDescriptor_42e081863c477116 = []byte{ - // 350 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xad, 0x4a, 0x2d, 0x49, - 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x07, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x13, 0x4b, 0x4b, 0x32, - 0xf2, 0x8b, 0x32, 0x4b, 0x2a, 0xf5, 0x4b, 0x2a, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x64, - 0xe0, 0xca, 0xf4, 0x60, 0xca, 0xf4, 0xe0, 0xca, 0xa4, 0xb4, 0xf1, 0x1a, 0x52, 0x90, 0x9f, 0x93, - 0x99, 0x9c, 0x99, 0x5a, 0x0c, 0x31, 0x4a, 0x4a, 0x17, 0xaf, 0x62, 0xb0, 0x44, 0x7c, 0x66, 0x5e, - 0x5a, 0x3e, 0x54, 0xb9, 0x01, 0x5e, 0xe5, 0x50, 0x56, 0x55, 0x62, 0x49, 0x66, 0x7e, 0x1e, 0x54, - 0x87, 0x48, 0x7a, 0x7e, 0x7a, 0x3e, 0x98, 0xa9, 0x0f, 0x62, 0x41, 0x44, 0x95, 0xca, 0xb9, 0x04, - 0x7d, 0x8b, 0xd3, 0x43, 0x0b, 0x52, 0x12, 0x4b, 0x52, 0x03, 0xa0, 0x2e, 0x12, 0x92, 0xe0, 0x62, - 0x4f, 0x2e, 0x4a, 0x4d, 0x2c, 0xc9, 0x2f, 0x92, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x82, 0x71, - 0x85, 0x3c, 0xb8, 0x38, 0x60, 0xee, 0x96, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x36, 0x52, 0xd3, 0xc3, - 0x17, 0x06, 0x7a, 0x30, 0x33, 0x9d, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0x82, 0xeb, 0x56, 0x92, - 0xe6, 0x92, 0xc4, 0xb0, 0x38, 0x28, 0xb5, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0xa9, 0x86, 0x4b, - 0x08, 0x2e, 0xe9, 0x0c, 0x32, 0xda, 0x33, 0x2f, 0x2d, 0x1f, 0x8f, 0xb3, 0x7c, 0xb8, 0xb8, 0x10, - 0x21, 0x04, 0x75, 0x98, 0x3a, 0x7e, 0x87, 0xc1, 0x8d, 0x85, 0xba, 0x8c, 0x33, 0x19, 0x26, 0xa0, - 0x24, 0xc3, 0x25, 0x85, 0x69, 0x3b, 0xcc, 0x6d, 0x46, 0x0d, 0x4c, 0x5c, 0xcc, 0xbe, 0xc5, 0xe9, - 0x42, 0x55, 0x5c, 0x7c, 0x68, 0xc1, 0xa6, 0x8f, 0xdf, 0x46, 0x0c, 0xef, 0x4a, 0x99, 0x93, 0xa8, - 0x01, 0xe6, 0x06, 0xa1, 0x5a, 0x2e, 0x7e, 0xf4, 0xc0, 0x31, 0x20, 0xd2, 0x2c, 0xb8, 0x0e, 0x29, - 0x0b, 0x52, 0x75, 0xc0, 0xac, 0x77, 0xf2, 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, 0x83, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x70, 0xba, 0xd4, - 0x45, 0x4b, 0xa2, 0x15, 0xc8, 0xb9, 0xa8, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0x9c, 0x0e, 0x8d, - 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe8, 0xeb, 0xa6, 0x40, 0x72, 0x03, 0x00, 0x00, + // 487 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0x4f, 0x6f, 0xd3, 0x30, + 0x14, 0xaf, 0xd9, 0xb4, 0xb1, 0x87, 0x34, 0xb6, 0x0c, 0x41, 0xc9, 0x46, 0xa8, 0x22, 0x01, 0x95, + 0xd0, 0x92, 0x52, 0x90, 0x00, 0x89, 0xcb, 0xc6, 0x85, 0x7f, 0x95, 0xa6, 0x88, 0x5e, 0xb8, 0x54, + 0x59, 0xea, 0xb9, 0x96, 0xda, 0x38, 0x8a, 0x5d, 0x58, 0x2b, 0x90, 0xb8, 0x72, 0x82, 0x6f, 0xc0, + 0xd7, 0xd9, 0x71, 0x47, 0x4e, 0x08, 0xb5, 0x5f, 0x04, 0xcd, 0x8d, 0xbd, 0x29, 0x89, 0xbc, 0x16, + 0x6e, 0x2f, 0xf6, 0xef, 0x9f, 0x9f, 0xe3, 0x07, 0xf7, 0xc6, 0x58, 0x84, 0x51, 0x2f, 0xa4, 0xb1, + 0x2f, 0x2b, 0x96, 0x62, 0x3f, 0x1c, 0x8a, 0x1e, 0x4b, 0xa9, 0x18, 0xf9, 0xe2, 0xd8, 0x4b, 0x52, + 0x26, 0x98, 0xb5, 0xa3, 0x61, 0x9e, 0x82, 0x79, 0x1a, 0x66, 0x3f, 0x34, 0x8a, 0x24, 0xac, 0x4f, + 0x23, 0x8a, 0xf9, 0x4c, 0xca, 0xde, 0x35, 0x82, 0xe5, 0x46, 0x87, 0xc6, 0x47, 0x2c, 0x83, 0x37, + 0x8c, 0xf0, 0xac, 0x1a, 0x87, 0x82, 0xb2, 0x38, 0x63, 0xdc, 0x20, 0x8c, 0x30, 0x59, 0xfa, 0x67, + 0xd5, 0x6c, 0xd5, 0xfd, 0x89, 0x60, 0xab, 0xc5, 0xc9, 0x5e, 0xb7, 0xbb, 0x77, 0x91, 0x63, 0x55, + 0x61, 0x35, 0x4a, 0x71, 0x28, 0x58, 0x5a, 0x45, 0x35, 0x54, 0x5f, 0x0b, 0xd4, 0xa7, 0x75, 0x0b, + 0x56, 0x07, 0x9c, 0x74, 0x86, 0x69, 0xbf, 0x7a, 0x45, 0xee, 0xac, 0x0c, 0x38, 0x69, 0xa7, 0x7d, + 0xab, 0x0d, 0x9b, 0xca, 0x17, 0x77, 0x3b, 0xf2, 0x78, 0xa3, 0xea, 0x52, 0x0d, 0xd5, 0xd7, 0x9b, + 0x75, 0xcf, 0xd4, 0x28, 0xef, 0x40, 0x62, 0xdf, 0x8f, 0x12, 0x1c, 0x6c, 0x9c, 0x4b, 0xcc, 0x56, + 0xdd, 0x3b, 0xb0, 0x5d, 0x12, 0x30, 0xc0, 0x3c, 0x61, 0x31, 0xc7, 0xee, 0x5b, 0xb8, 0xd9, 0xe2, + 0x24, 0xc0, 0x03, 0xf6, 0x11, 0xff, 0xef, 0x11, 0xdc, 0x1a, 0x38, 0xe5, 0x62, 0xda, 0xee, 0x13, + 0x6c, 0xb6, 0x38, 0x69, 0x27, 0xdd, 0x50, 0xe0, 0x83, 0xec, 0x06, 0x0d, 0x4e, 0xaf, 0xe0, 0xaa, + 0xba, 0x67, 0x69, 0x75, 0xad, 0x79, 0x7f, 0x8e, 0x56, 0x50, 0xcc, 0xf7, 0x97, 0x4f, 0x7e, 0xdf, + 0xad, 0x04, 0x9a, 0xed, 0x6e, 0xc3, 0xed, 0x82, 0xb1, 0x4e, 0xf5, 0x19, 0x2c, 0xbd, 0xf9, 0xf2, + 0x4c, 0xfa, 0x75, 0x7c, 0xc4, 0x0c, 0xb1, 0xde, 0x01, 0x9c, 0xff, 0x51, 0x59, 0xb0, 0x07, 0xe6, + 0x60, 0x5a, 0x36, 0x4b, 0xb6, 0x16, 0xa9, 0x05, 0x77, 0x07, 0xec, 0xa2, 0xbb, 0xca, 0xd6, 0xfc, + 0xbe, 0x0c, 0x4b, 0x2d, 0x4e, 0xac, 0x31, 0xac, 0xe7, 0xda, 0xe6, 0x9b, 0x1d, 0x0b, 0xc7, 0xb5, + 0x9f, 0x2e, 0x48, 0x50, 0x19, 0xac, 0x2f, 0x70, 0x3d, 0xdf, 0x9c, 0xc6, 0x9c, 0x5a, 0x9a, 0x61, + 0x3f, 0x5b, 0x94, 0xa1, 0xed, 0xbf, 0x22, 0xd8, 0x28, 0xbc, 0xb0, 0x47, 0x97, 0xca, 0xe5, 0x29, + 0xf6, 0xf3, 0x85, 0x29, 0x3a, 0xc2, 0x37, 0x04, 0x5b, 0x65, 0x8f, 0xe4, 0xc9, 0xa5, 0x92, 0x25, + 0x2c, 0xfb, 0xc5, 0xbf, 0xb0, 0x54, 0x96, 0xfd, 0x37, 0x27, 0x13, 0x07, 0x9d, 0x4e, 0x1c, 0xf4, + 0x67, 0xe2, 0xa0, 0x1f, 0x53, 0xa7, 0x72, 0x3a, 0x75, 0x2a, 0xbf, 0xa6, 0x4e, 0xe5, 0x43, 0x83, + 0x50, 0xd1, 0x1b, 0x1e, 0x7a, 0x11, 0x1b, 0xc8, 0xb1, 0xb6, 0x9b, 0x9b, 0x70, 0xc7, 0x17, 0x87, + 0xf0, 0x28, 0xc1, 0xfc, 0x70, 0x45, 0x8e, 0xb1, 0xc7, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x33, + 0xb2, 0x7c, 0x5f, 0xb1, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -259,6 +464,8 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { UpdatePolicies(ctx context.Context, in *MsgUpdatePolicies, opts ...grpc.CallOption) (*MsgUpdatePoliciesResponse, error) UpdateChainInfo(ctx context.Context, in *MsgUpdateChainInfo, opts ...grpc.CallOption) (*MsgUpdateChainInfoResponse, error) + AddAuthorization(ctx context.Context, in *MsgAddAuthorization, opts ...grpc.CallOption) (*MsgAddAuthorizationResponse, error) + RemoveAuthorization(ctx context.Context, in *MsgRemoveAuthorization, opts ...grpc.CallOption) (*MsgRemoveAuthorizationResponse, error) } type msgClient struct { @@ -287,10 +494,30 @@ func (c *msgClient) UpdateChainInfo(ctx context.Context, in *MsgUpdateChainInfo, return out, nil } +func (c *msgClient) AddAuthorization(ctx context.Context, in *MsgAddAuthorization, opts ...grpc.CallOption) (*MsgAddAuthorizationResponse, error) { + out := new(MsgAddAuthorizationResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.authority.Msg/AddAuthorization", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) RemoveAuthorization(ctx context.Context, in *MsgRemoveAuthorization, opts ...grpc.CallOption) (*MsgRemoveAuthorizationResponse, error) { + out := new(MsgRemoveAuthorizationResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.authority.Msg/RemoveAuthorization", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { UpdatePolicies(context.Context, *MsgUpdatePolicies) (*MsgUpdatePoliciesResponse, error) UpdateChainInfo(context.Context, *MsgUpdateChainInfo) (*MsgUpdateChainInfoResponse, error) + AddAuthorization(context.Context, *MsgAddAuthorization) (*MsgAddAuthorizationResponse, error) + RemoveAuthorization(context.Context, *MsgRemoveAuthorization) (*MsgRemoveAuthorizationResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -303,6 +530,12 @@ func (*UnimplementedMsgServer) UpdatePolicies(ctx context.Context, req *MsgUpdat func (*UnimplementedMsgServer) UpdateChainInfo(ctx context.Context, req *MsgUpdateChainInfo) (*MsgUpdateChainInfoResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateChainInfo not implemented") } +func (*UnimplementedMsgServer) AddAuthorization(ctx context.Context, req *MsgAddAuthorization) (*MsgAddAuthorizationResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AddAuthorization not implemented") +} +func (*UnimplementedMsgServer) RemoveAuthorization(ctx context.Context, req *MsgRemoveAuthorization) (*MsgRemoveAuthorizationResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RemoveAuthorization not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -344,6 +577,42 @@ func _Msg_UpdateChainInfo_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } +func _Msg_AddAuthorization_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgAddAuthorization) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).AddAuthorization(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.authority.Msg/AddAuthorization", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).AddAuthorization(ctx, req.(*MsgAddAuthorization)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_RemoveAuthorization_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRemoveAuthorization) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RemoveAuthorization(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.authority.Msg/RemoveAuthorization", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RemoveAuthorization(ctx, req.(*MsgRemoveAuthorization)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "zetachain.zetacore.authority.Msg", HandlerType: (*MsgServer)(nil), @@ -356,12 +625,20 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "UpdateChainInfo", Handler: _Msg_UpdateChainInfo_Handler, }, + { + MethodName: "AddAuthorization", + Handler: _Msg_AddAuthorization_Handler, + }, + { + MethodName: "RemoveAuthorization", + Handler: _Msg_RemoveAuthorization_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "zetachain/zetacore/authority/tx.proto", } -func (m *MsgUpdatePolicies) Marshal() (dAtA []byte, err error) { +func (m *MsgAddAuthorization) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -371,26 +648,28 @@ func (m *MsgUpdatePolicies) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdatePolicies) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgAddAuthorization) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdatePolicies) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgAddAuthorization) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - { - size, err := m.Policies.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + if m.AuthorizedPolicy != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.AuthorizedPolicy)) + i-- + dAtA[i] = 0x18 + } + if len(m.MsgUrl) > 0 { + i -= len(m.MsgUrl) + copy(dAtA[i:], m.MsgUrl) + i = encodeVarintTx(dAtA, i, uint64(len(m.MsgUrl))) + i-- + dAtA[i] = 0x12 } - i-- - dAtA[i] = 0x12 if len(m.Creator) > 0 { i -= len(m.Creator) copy(dAtA[i:], m.Creator) @@ -401,7 +680,7 @@ func (m *MsgUpdatePolicies) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgUpdatePoliciesResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgAddAuthorizationResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -411,12 +690,12 @@ func (m *MsgUpdatePoliciesResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdatePoliciesResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgAddAuthorizationResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdatePoliciesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgAddAuthorizationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -424,7 +703,7 @@ func (m *MsgUpdatePoliciesResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } -func (m *MsgUpdateChainInfo) Marshal() (dAtA []byte, err error) { +func (m *MsgRemoveAuthorization) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -434,18 +713,78 @@ func (m *MsgUpdateChainInfo) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdateChainInfo) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgRemoveAuthorization) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdateChainInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgRemoveAuthorization) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.MsgUrl) > 0 { + i -= len(m.MsgUrl) + copy(dAtA[i:], m.MsgUrl) + i = encodeVarintTx(dAtA, i, uint64(len(m.MsgUrl))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRemoveAuthorizationResponse) 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 *MsgRemoveAuthorizationResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRemoveAuthorizationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgUpdatePolicies) 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 *MsgUpdatePolicies) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdatePolicies) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l { - size, err := m.ChainInfo.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Policies.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -464,7 +803,7 @@ func (m *MsgUpdateChainInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgUpdateChainInfoResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgUpdatePoliciesResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -474,12 +813,12 @@ func (m *MsgUpdateChainInfoResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgUpdateChainInfoResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgUpdatePoliciesResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgUpdateChainInfoResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgUpdatePoliciesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -487,17 +826,135 @@ func (m *MsgUpdateChainInfoResponse) MarshalToSizedBuffer(dAtA []byte) (int, err 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++ +func (m *MsgUpdateChainInfo) 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 *MsgUpdateChainInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateChainInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.ChainInfo.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateChainInfoResponse) 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 *MsgUpdateChainInfoResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateChainInfoResponse) 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 *MsgAddAuthorization) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.MsgUrl) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.AuthorizedPolicy != 0 { + n += 1 + sovTx(uint64(m.AuthorizedPolicy)) + } + return n +} + +func (m *MsgAddAuthorizationResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgRemoveAuthorization) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.MsgUrl) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRemoveAuthorizationResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func (m *MsgUpdatePolicies) Size() (n int) { if m == nil { return 0 @@ -552,6 +1009,353 @@ func sovTx(x uint64) (n int) { func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *MsgAddAuthorization) 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: MsgAddAuthorization: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAddAuthorization: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", 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.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgUrl", 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.MsgUrl = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AuthorizedPolicy", wireType) + } + m.AuthorizedPolicy = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AuthorizedPolicy |= PolicyType(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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 *MsgAddAuthorizationResponse) 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: MsgAddAuthorizationResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAddAuthorizationResponse: 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 (m *MsgRemoveAuthorization) 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: MsgRemoveAuthorization: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveAuthorization: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", 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.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgUrl", 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.MsgUrl = 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 *MsgRemoveAuthorizationResponse) 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: MsgRemoveAuthorizationResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveAuthorizationResponse: 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 (m *MsgUpdatePolicies) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 From 84e80acc8bc4fccbe6f8e296ff912a72f590be87 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 31 May 2024 22:27:12 -0400 Subject: [PATCH 02/12] add message types --- .../zetacore/authority/policies.proto | 1 + .../client/cli/tx_add_authorization.go | 40 +++++++ x/authority/types/authorizations_test.go | 4 +- .../types/message_add_authorization.go | 65 +++++++++++ .../types/message_add_authorizations_test.go | 104 ++++++++++++++++++ .../types/message_remove_authorization.go | 51 +++++++++ .../message_remove_authorizations_test.go | 96 ++++++++++++++++ x/authority/types/policies.go | 5 +- x/authority/types/policies.pb.go | 45 ++++---- x/authority/types/policytype.go | 13 +++ 10 files changed, 399 insertions(+), 25 deletions(-) create mode 100644 x/authority/client/cli/tx_add_authorization.go create mode 100644 x/authority/types/message_add_authorization.go create mode 100644 x/authority/types/message_add_authorizations_test.go create mode 100644 x/authority/types/message_remove_authorization.go create mode 100644 x/authority/types/message_remove_authorizations_test.go create mode 100644 x/authority/types/policytype.go diff --git a/proto/zetachain/zetacore/authority/policies.proto b/proto/zetachain/zetacore/authority/policies.proto index b02f448514..faefdbf2c7 100644 --- a/proto/zetachain/zetacore/authority/policies.proto +++ b/proto/zetachain/zetacore/authority/policies.proto @@ -14,6 +14,7 @@ enum PolicyType { // non-sensitive protocol parameters groupAdmin = 2; // Used for administrative tasks like changing sensitive // protocol parameters or moving funds + groupEmpty = 3; // Used for empty policy, no action is allowed } message Policy { diff --git a/x/authority/client/cli/tx_add_authorization.go b/x/authority/client/cli/tx_add_authorization.go new file mode 100644 index 0000000000..c4c31e3725 --- /dev/null +++ b/x/authority/client/cli/tx_add_authorization.go @@ -0,0 +1,40 @@ +package cli + +//func CmdAddAuthorization() *cobra.Command { +// cmd := &cobra.Command{ +// Use: "add-authorization [msg-url] [authorized-policy]", +// Short: "add a new authorization or update the policy of an existing authorization.Policy type can be 0 for groupEmergency, 1 for groupOperational, 2 for groupAdmin", +// Args: cobra.ExactArgs(2), +// RunE: func(cmd *cobra.Command, args []string) (err error) { +// clientCtx, err := client.GetClientTxContext(cmd) +// if err != nil { +// return err +// } +// authorizedPolicy, err := GetPolicyType(args[1]) +// +// +// return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) +// }, +// } +// flags.AddTxFlagsToCmd(cmd) +// return cmd +//} +// +//func GetPolicyType(policyTypeString string) (types.PolicyType, error) { +// policyType, err := strconv.ParseInt(policyTypeString, 10, 64) +// if err != nil { +// return types.PolicyType_groupEmpty, fmt.Errorf("failed to parse policy type: %w", err) +// } +// +// switch policyType { +// case 0: +// return types.PolicyType_groupEmergency, nil +// case 1: +// return types.PolicyType_groupOperational, nil +// case 2: +// return types.PolicyType_groupAdmin, nil +// default: +// return types.PolicyType_groupEmpty, fmt.Errorf("invalid policy type: %d", policyType) +// } +// +//} diff --git a/x/authority/types/authorizations_test.go b/x/authority/types/authorizations_test.go index 84864372a4..f718294b33 100644 --- a/x/authority/types/authorizations_test.go +++ b/x/authority/types/authorizations_test.go @@ -295,7 +295,7 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { removeMsgUrl: "XYZ", expectedList: types.AuthorizationList{Authorizations: []types.Authorization{ { - MsgUrl: "XYZ", + MsgUrl: "ABC", AuthorizedPolicy: types.PolicyType_groupOperational, }, }}, @@ -352,7 +352,7 @@ func TestAuthorizationList_RemoveAuthorizations(t *testing.T) { }, // The list is invalid, but this test case tries to assert the expected functionality { - name: "return after removing first occurance", + name: "return after removing first occurrence", oldList: types.AuthorizationList{Authorizations: []types.Authorization{ { MsgUrl: "ABC", diff --git a/x/authority/types/message_add_authorization.go b/x/authority/types/message_add_authorization.go new file mode 100644 index 0000000000..78661fe0e6 --- /dev/null +++ b/x/authority/types/message_add_authorization.go @@ -0,0 +1,65 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const TypeMsgAddAuthorization = "AddAuthorization" + +var _ sdk.Msg = &MsgAddAuthorization{} + +func NewMsgAddAuthorization(creator string, msgUrl string, authorizedPolicy PolicyType) *MsgAddAuthorization { + return &MsgAddAuthorization{ + Creator: creator, + MsgUrl: msgUrl, + AuthorizedPolicy: authorizedPolicy, + } +} + +func (msg *MsgAddAuthorization) Route() string { + return RouterKey +} + +func (msg *MsgAddAuthorization) Type() string { + return TypeMsgAddAuthorization +} + +func (msg *MsgAddAuthorization) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{signer} +} + +func (msg *MsgAddAuthorization) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgAddAuthorization) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + + // the authorized policy must be valid + if err := msg.AuthorizedPolicy.Validate(); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid authorized policy: %s", err.Error()) + } + + // the message URL must be valid + if err := ValidateMsgUrl(msg.MsgUrl); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid msg url: %s", err.Error()) + } + + return nil +} + +func ValidateMsgUrl(url string) error { + if len(url) == 0 { + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "message URL cannot be empty") + } + return nil +} diff --git a/x/authority/types/message_add_authorizations_test.go b/x/authority/types/message_add_authorizations_test.go new file mode 100644 index 0000000000..2fcea1d959 --- /dev/null +++ b/x/authority/types/message_add_authorizations_test.go @@ -0,0 +1,104 @@ +package types_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestMsgAddAuthorization_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg *types.MsgAddAuthorization + expectErr require.ErrorAssertionFunc + }{ + { + name: "invalid creator address", + msg: types.NewMsgAddAuthorization("invalid", "url", types.PolicyType_groupAdmin), + expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + require.Contains(t, err.Error(), "invalid creator address") + }, + }, + { + name: "invalid authorized policy", + msg: types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupEmpty), + expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.Contains(t, err.Error(), "invalid authorized policy") + }, + }, + { + name: "invalid msg url", + msg: types.NewMsgAddAuthorization(sample.AccAddress(), "", types.PolicyType_groupAdmin), + expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.Contains(t, err.Error(), "invalid msg url") + }, + }, + { + name: "valid message", + msg: types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupAdmin), + expectErr: require.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tt.expectErr(t, tt.msg.ValidateBasic()) + }) + } +} + +func TestMsgAddAuthorization_GetSigners(t *testing.T) { + signer := sample.AccAddress() + tests := []struct { + name string + msg *types.MsgAddAuthorization + panics bool + }{ + { + name: "valid signer", + msg: types.NewMsgAddAuthorization(signer, "url", types.PolicyType_groupAdmin), + panics: false, + }, + { + name: "invalid signer", + msg: types.NewMsgAddAuthorization("creator", "url", types.PolicyType_groupAdmin), + panics: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if !tt.panics { + signers := tt.msg.GetSigners() + require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(signer)}, signers) + } else { + require.Panics(t, func() { + tt.msg.GetSigners() + }) + } + }) + } +} + +func TestMsgAddAuthorization_Type(t *testing.T) { + msg := types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupAdmin) + require.Equal(t, types.TypeMsgAddAuthorization, msg.Type()) +} + +func TestMsgAddAuthorization_Route(t *testing.T) { + msg := types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupAdmin) + require.Equal(t, types.RouterKey, msg.Route()) +} + +func TestMsgAddAuthorization_GetSignBytes(t *testing.T) { + msg := types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupAdmin) + require.NotPanics(t, func() { + msg.GetSignBytes() + }) +} diff --git a/x/authority/types/message_remove_authorization.go b/x/authority/types/message_remove_authorization.go new file mode 100644 index 0000000000..54ed0b063e --- /dev/null +++ b/x/authority/types/message_remove_authorization.go @@ -0,0 +1,51 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const TypeRemoveAuthorization = "RemoveAuthorization" + +var _ sdk.Msg = &MsgRemoveAuthorization{} + +func NewMsgRemoveAuthorization(creator string, msgUrl string) *MsgRemoveAuthorization { + return &MsgRemoveAuthorization{ + Creator: creator, + MsgUrl: msgUrl, + } +} + +func (msg *MsgRemoveAuthorization) Route() string { + return RouterKey +} + +func (msg *MsgRemoveAuthorization) Type() string { + return TypeRemoveAuthorization +} + +func (msg *MsgRemoveAuthorization) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{signer} +} + +func (msg *MsgRemoveAuthorization) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgRemoveAuthorization) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + + if err := ValidateMsgUrl(msg.MsgUrl); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid msg url: %s", err.Error()) + } + + return nil +} diff --git a/x/authority/types/message_remove_authorizations_test.go b/x/authority/types/message_remove_authorizations_test.go new file mode 100644 index 0000000000..a2833bd8a1 --- /dev/null +++ b/x/authority/types/message_remove_authorizations_test.go @@ -0,0 +1,96 @@ +package types_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestMsgRemoveAuthorization_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg *types.MsgRemoveAuthorization + expectErr require.ErrorAssertionFunc + }{ + { + name: "invalid creator address", + msg: types.NewMsgRemoveAuthorization("invalid", "url"), + expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + require.Contains(t, err.Error(), "invalid creator address") + }, + }, + { + name: "invalid msg url", + msg: types.NewMsgRemoveAuthorization(sample.AccAddress(), ""), + expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.Contains(t, err.Error(), "invalid msg url") + }, + }, + { + name: "valid message", + msg: types.NewMsgRemoveAuthorization(sample.AccAddress(), "url"), + expectErr: require.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tt.expectErr(t, tt.msg.ValidateBasic()) + }) + } +} + +func TestMsgRemoveAuthorization_GetSigners(t *testing.T) { + signer := sample.AccAddress() + tests := []struct { + name string + msg *types.MsgRemoveAuthorization + panics bool + }{ + { + name: "valid signer", + msg: types.NewMsgRemoveAuthorization(signer, "url"), + panics: false, + }, + { + name: "invalid signer", + msg: types.NewMsgRemoveAuthorization("creator", "url"), + panics: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if !tt.panics { + signers := tt.msg.GetSigners() + require.Equal(t, []sdk.AccAddress{sdk.MustAccAddressFromBech32(signer)}, signers) + } else { + require.Panics(t, func() { + tt.msg.GetSigners() + }) + } + }) + } +} + +func TestMsgRemoveAuthorization_Type(t *testing.T) { + msg := types.NewMsgRemoveAuthorization(sample.AccAddress(), "url") + require.Equal(t, types.TypeRemoveAuthorization, msg.Type()) +} + +func TestMsgRemoveAuthorization_Route(t *testing.T) { + msg := types.NewMsgRemoveAuthorization(sample.AccAddress(), "url") + require.Equal(t, types.RouterKey, msg.Route()) +} + +func TestMsgRemoveAuthorization_GetSignBytes(t *testing.T) { + msg := types.NewMsgRemoveAuthorization(sample.AccAddress(), "url") + require.NotPanics(t, func() { + msg.GetSignBytes() + }) +} diff --git a/x/authority/types/policies.go b/x/authority/types/policies.go index 28a97594ce..af3642bfd7 100644 --- a/x/authority/types/policies.go +++ b/x/authority/types/policies.go @@ -42,9 +42,8 @@ func (p Policies) Validate() error { return fmt.Errorf("invalid address: %s", err) } - if policy.PolicyType != PolicyType_groupEmergency && policy.PolicyType != PolicyType_groupAdmin && - policy.PolicyType != PolicyType_groupOperational { - return fmt.Errorf("invalid policy type: %s", policy.PolicyType) + if err := policy.PolicyType.Validate(); err != nil { + return err } if policyTypeMap[policy.PolicyType] { diff --git a/x/authority/types/policies.pb.go b/x/authority/types/policies.pb.go index 3b2eda6564..c67621c996 100644 --- a/x/authority/types/policies.pb.go +++ b/x/authority/types/policies.pb.go @@ -31,18 +31,22 @@ const ( PolicyType_groupOperational PolicyType = 1 // non-sensitive protocol parameters PolicyType_groupAdmin PolicyType = 2 + // protocol parameters or moving funds + PolicyType_groupEmpty PolicyType = 3 ) var PolicyType_name = map[int32]string{ 0: "groupEmergency", 1: "groupOperational", 2: "groupAdmin", + 3: "groupEmpty", } var PolicyType_value = map[string]int32{ "groupEmergency": 0, "groupOperational": 1, "groupAdmin": 2, + "groupEmpty": 3, } func (x PolicyType) String() string { @@ -161,26 +165,27 @@ func init() { } var fileDescriptor_afa9e3e7b996ef74 = []byte{ - // 303 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0xae, 0x4a, 0x2d, 0x49, - 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x07, 0xb3, 0xf2, 0x8b, 0x52, 0xf5, 0x13, 0x4b, 0x4b, 0x32, - 0xf2, 0x8b, 0x32, 0x4b, 0x2a, 0xf5, 0x0b, 0xf2, 0x73, 0x32, 0x93, 0x33, 0x53, 0x8b, 0xf5, 0x0a, - 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x64, 0xe0, 0x8a, 0xf5, 0x60, 0x8a, 0xf5, 0xe0, 0x8a, 0xa5, 0x44, - 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x0a, 0xf5, 0x41, 0x2c, 0x88, 0x1e, 0xa5, 0x5c, 0x2e, 0xb6, 0x00, - 0x90, 0x29, 0x95, 0x42, 0x9e, 0x5c, 0xdc, 0x60, 0xf3, 0x2a, 0xe3, 0x4b, 0x2a, 0x0b, 0x52, 0x25, - 0x18, 0x15, 0x18, 0x35, 0xf8, 0x8c, 0x34, 0xf4, 0xf0, 0x99, 0xa9, 0x07, 0xd1, 0x1a, 0x52, 0x59, - 0x90, 0x1a, 0xc4, 0x55, 0x00, 0x67, 0x0b, 0x49, 0x70, 0xb1, 0x27, 0xa6, 0xa4, 0x14, 0xa5, 0x16, - 0x17, 0x4b, 0x30, 0x29, 0x30, 0x6a, 0x70, 0x06, 0xc1, 0xb8, 0x4a, 0x6e, 0x5c, 0x1c, 0x01, 0x50, - 0x47, 0x0b, 0x59, 0x71, 0xb1, 0x66, 0x96, 0xa4, 0xe6, 0x16, 0x4b, 0x30, 0x2a, 0x30, 0x6b, 0x70, - 0x1b, 0xa9, 0x10, 0x63, 0x55, 0x10, 0x44, 0x8b, 0x96, 0x0f, 0x17, 0x17, 0xc2, 0x6e, 0x21, 0x21, - 0x2e, 0xbe, 0xf4, 0xa2, 0xfc, 0xd2, 0x02, 0xd7, 0xdc, 0xd4, 0xa2, 0xf4, 0xd4, 0xbc, 0xe4, 0x4a, - 0x01, 0x06, 0x21, 0x11, 0x2e, 0x01, 0xb0, 0x98, 0x7f, 0x41, 0x6a, 0x51, 0x62, 0x49, 0x66, 0x7e, - 0x5e, 0x62, 0x8e, 0x00, 0xa3, 0x10, 0x1f, 0x17, 0x17, 0x58, 0xd4, 0x31, 0x25, 0x37, 0x33, 0x4f, - 0x80, 0x49, 0x8a, 0x65, 0xc5, 0x12, 0x39, 0x46, 0x27, 0xaf, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, - 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, - 0x3c, 0x96, 0x63, 0x88, 0x32, 0x48, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0x05, - 0x47, 0x80, 0x2e, 0x5a, 0x5c, 0x54, 0x20, 0xc5, 0x06, 0x28, 0xd8, 0x8a, 0x93, 0xd8, 0xc0, 0xe1, - 0x6a, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xe4, 0x91, 0xe5, 0xab, 0xba, 0x01, 0x00, 0x00, + // 310 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x51, 0xc1, 0x4a, 0x03, 0x31, + 0x14, 0xdc, 0xb4, 0x5a, 0xf5, 0x15, 0xca, 0x12, 0x7a, 0x58, 0x8a, 0x84, 0x52, 0x3c, 0x2c, 0x8a, + 0x59, 0xa9, 0x37, 0x6f, 0x0a, 0x15, 0xf4, 0x62, 0x29, 0x9e, 0x44, 0x90, 0x74, 0x1b, 0xb6, 0x81, + 0x66, 0x13, 0xb2, 0x29, 0x18, 0xbf, 0xc2, 0x8f, 0xf0, 0xe0, 0xa7, 0x78, 0xec, 0xd1, 0xa3, 0xb4, + 0x3f, 0x22, 0xcd, 0xda, 0x55, 0x3c, 0x88, 0xb7, 0x79, 0x8f, 0x99, 0x79, 0x8f, 0x19, 0x38, 0x7a, + 0xe2, 0x96, 0xa5, 0x53, 0x26, 0xf2, 0xc4, 0x23, 0x65, 0x78, 0xc2, 0xe6, 0x76, 0xaa, 0x8c, 0xb0, + 0x2e, 0xd1, 0x6a, 0x26, 0x52, 0xc1, 0x0b, 0xaa, 0x8d, 0xb2, 0x0a, 0xef, 0x57, 0x64, 0xba, 0x21, + 0xd3, 0x8a, 0xdc, 0x69, 0x67, 0x2a, 0x53, 0x9e, 0x98, 0xac, 0x51, 0xa9, 0xe9, 0x49, 0x68, 0x0c, + 0xd7, 0x2e, 0x0e, 0x5f, 0x41, 0xd3, 0xfb, 0xb9, 0x07, 0xeb, 0x34, 0x8f, 0x50, 0x17, 0xc5, 0xad, + 0x7e, 0x4c, 0xff, 0xf2, 0xa4, 0xa5, 0xf4, 0xd6, 0x69, 0x3e, 0x02, 0x5d, 0x61, 0x1c, 0xc1, 0x0e, + 0x9b, 0x4c, 0x0c, 0x2f, 0x8a, 0xa8, 0xd6, 0x45, 0xf1, 0xde, 0x68, 0x33, 0xf6, 0x2e, 0x61, 0x77, + 0xf8, 0xf5, 0x34, 0x3e, 0x83, 0x6d, 0x61, 0xb9, 0x2c, 0x22, 0xd4, 0xad, 0xc7, 0xcd, 0xfe, 0xc1, + 0x7f, 0x4e, 0x8d, 0x4a, 0xc9, 0xe1, 0x3d, 0xc0, 0xf7, 0x6d, 0x8c, 0xa1, 0x95, 0x19, 0x35, 0xd7, + 0x03, 0xc9, 0x4d, 0xc6, 0xf3, 0xd4, 0x85, 0x01, 0x6e, 0x43, 0xe8, 0x77, 0x37, 0x9a, 0x1b, 0x66, + 0x85, 0xca, 0xd9, 0x2c, 0x44, 0xb8, 0x05, 0xe0, 0xb7, 0xe7, 0x13, 0x29, 0xf2, 0xb0, 0x56, 0xcd, + 0x03, 0xa9, 0xad, 0x0b, 0xeb, 0x9d, 0xad, 0xd7, 0x17, 0x82, 0x2e, 0xae, 0xdf, 0x96, 0x04, 0x2d, + 0x96, 0x04, 0x7d, 0x2c, 0x09, 0x7a, 0x5e, 0x91, 0x60, 0xb1, 0x22, 0xc1, 0xfb, 0x8a, 0x04, 0x77, + 0x27, 0x99, 0xb0, 0xd3, 0xf9, 0x98, 0xa6, 0x4a, 0xfa, 0x42, 0x8e, 0x7f, 0x75, 0xf3, 0xf8, 0xa3, + 0x9d, 0x75, 0x8c, 0xc5, 0xb8, 0xe1, 0x73, 0x3e, 0xfd, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x37, 0x5d, + 0x49, 0x63, 0xca, 0x01, 0x00, 0x00, } func (m *Policy) Marshal() (dAtA []byte, err error) { diff --git a/x/authority/types/policytype.go b/x/authority/types/policytype.go new file mode 100644 index 0000000000..c3593e7fae --- /dev/null +++ b/x/authority/types/policytype.go @@ -0,0 +1,13 @@ +package types + +import "fmt" + +// Validate PolicyType validates the policy type. +// Valid policy types are groupEmergency, groupOperational, and groupAdmin. +func (p PolicyType) Validate() error { + if p != PolicyType_groupEmergency && p != PolicyType_groupAdmin && + p != PolicyType_groupOperational { + return fmt.Errorf("invalid policy type: %s", p) + } + return nil +} From 9589543936a43d41c615a35ca7a23aebb7da70df Mon Sep 17 00:00:00 2001 From: Tanmay Date: Mon, 3 Jun 2024 09:54:22 -0400 Subject: [PATCH 03/12] test for msg url --- .../types/message_add_authorizations_test.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/x/authority/types/message_add_authorizations_test.go b/x/authority/types/message_add_authorizations_test.go index 2fcea1d959..965bf5ec4d 100644 --- a/x/authority/types/message_add_authorizations_test.go +++ b/x/authority/types/message_add_authorizations_test.go @@ -102,3 +102,28 @@ func TestMsgAddAuthorization_GetSignBytes(t *testing.T) { msg.GetSignBytes() }) } + +func TestValidateMsgUrl(t *testing.T) { + tests := []struct { + name string + url string + expectErr error + }{ + { + name: "empty url", + url: "", + expectErr: sdkerrors.ErrInvalidRequest, + }, + { + name: "valid url", + url: "/zetachain.zetacore.crosschain.MsgRefundAbortedCCTX", + expectErr: nil, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := types.ValidateMsgUrl(tt.url) + require.ErrorIs(t, err, tt.expectErr) + }) + } +} From 77c9c9a3f0d20b84ec688c2edada2c821114befd Mon Sep 17 00:00:00 2001 From: Tanmay Date: Mon, 3 Jun 2024 11:24:27 -0400 Subject: [PATCH 04/12] add cli commands --- x/authority/client/cli/tx.go | 2 + .../client/cli/tx_add_authorization.go | 96 +++++++++++-------- .../client/cli/tx_add_authorizations_test.go | 59 ++++++++++++ .../client/cli/tx_remove_authorization.go | 33 +++++++ 4 files changed, 152 insertions(+), 38 deletions(-) create mode 100644 x/authority/client/cli/tx_add_authorizations_test.go create mode 100644 x/authority/client/cli/tx_remove_authorization.go diff --git a/x/authority/client/cli/tx.go b/x/authority/client/cli/tx.go index 1455773bf5..7eea187fc5 100644 --- a/x/authority/client/cli/tx.go +++ b/x/authority/client/cli/tx.go @@ -22,6 +22,8 @@ func GetTxCmd() *cobra.Command { cmd.AddCommand( CmdUpdatePolices(), CmdUpdateChainInfo(), + CmdAddAuthorization(), + CmdRemoveAuthorization(), ) return cmd diff --git a/x/authority/client/cli/tx_add_authorization.go b/x/authority/client/cli/tx_add_authorization.go index c4c31e3725..f0a8b9418b 100644 --- a/x/authority/client/cli/tx_add_authorization.go +++ b/x/authority/client/cli/tx_add_authorization.go @@ -1,40 +1,60 @@ package cli -//func CmdAddAuthorization() *cobra.Command { -// cmd := &cobra.Command{ -// Use: "add-authorization [msg-url] [authorized-policy]", -// Short: "add a new authorization or update the policy of an existing authorization.Policy type can be 0 for groupEmergency, 1 for groupOperational, 2 for groupAdmin", -// Args: cobra.ExactArgs(2), -// RunE: func(cmd *cobra.Command, args []string) (err error) { -// clientCtx, err := client.GetClientTxContext(cmd) -// if err != nil { -// return err -// } -// authorizedPolicy, err := GetPolicyType(args[1]) -// -// -// return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) -// }, -// } -// flags.AddTxFlagsToCmd(cmd) -// return cmd -//} -// -//func GetPolicyType(policyTypeString string) (types.PolicyType, error) { -// policyType, err := strconv.ParseInt(policyTypeString, 10, 64) -// if err != nil { -// return types.PolicyType_groupEmpty, fmt.Errorf("failed to parse policy type: %w", err) -// } -// -// switch policyType { -// case 0: -// return types.PolicyType_groupEmergency, nil -// case 1: -// return types.PolicyType_groupOperational, nil -// case 2: -// return types.PolicyType_groupAdmin, nil -// default: -// return types.PolicyType_groupEmpty, fmt.Errorf("invalid policy type: %d", policyType) -// } -// -//} +import ( + "fmt" + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func CmdAddAuthorization() *cobra.Command { + cmd := &cobra.Command{ + Use: "add-authorization [msg-url] [authorized-policy]", + Short: "add a new authorization or update the policy of an existing authorization.Policy type can be 0 for groupEmergency, 1 for groupOperational, 2 for groupAdmin", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + authorizedPolicy, err := GetPolicyType(args[1]) + if err != nil { + return err + } + msg := &types.MsgAddAuthorization{ + MsgUrl: args[0], + AuthorizedPolicy: authorizedPolicy, + } + err = msg.ValidateBasic() + if err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + return cmd +} + +func GetPolicyType(policyTypeString string) (types.PolicyType, error) { + policyType, err := strconv.ParseInt(policyTypeString, 10, 64) + if err != nil { + return types.PolicyType_groupEmpty, fmt.Errorf("failed to parse policy type: %w", err) + } + + switch policyType { + case 0: + return types.PolicyType_groupEmergency, nil + case 1: + return types.PolicyType_groupOperational, nil + case 2: + return types.PolicyType_groupAdmin, nil + default: + return types.PolicyType_groupEmpty, fmt.Errorf("invalid policy type value: %d", policyType) + } + +} diff --git a/x/authority/client/cli/tx_add_authorizations_test.go b/x/authority/client/cli/tx_add_authorizations_test.go new file mode 100644 index 0000000000..279fdc0420 --- /dev/null +++ b/x/authority/client/cli/tx_add_authorizations_test.go @@ -0,0 +1,59 @@ +package cli_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/x/authority/client/cli" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func Test_GetPolicyType(t *testing.T) { + tt := []struct { + name string + policyTypeString string + expecectedPolicyType types.PolicyType + expecterErrorString string + }{ + { + name: "groupEmergency", + policyTypeString: "0", + expecectedPolicyType: types.PolicyType_groupEmergency, + expecterErrorString: "", + }, + { + name: "groupOperational", + policyTypeString: "1", + expecectedPolicyType: types.PolicyType_groupOperational, + expecterErrorString: "", + }, + { + name: "groupAdmin", + policyTypeString: "2", + expecectedPolicyType: types.PolicyType_groupAdmin, + expecterErrorString: "", + }, + { + name: "groupEmpty", + policyTypeString: "3", + expecectedPolicyType: types.PolicyType_groupEmpty, + expecterErrorString: "invalid policy type value", + }, + { + name: "string literal for policy type not accepted", + policyTypeString: "groupEmergency", + expecectedPolicyType: types.PolicyType_groupEmpty, + expecterErrorString: "failed to parse policy type", + }, + } + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + policyType, err := cli.GetPolicyType(tc.policyTypeString) + require.Equal(t, tc.expecectedPolicyType, policyType) + if tc.expecectedPolicyType == types.PolicyType_groupEmpty { + require.ErrorContains(t, err, tc.expecterErrorString) + } + }) + } + +} diff --git a/x/authority/client/cli/tx_remove_authorization.go b/x/authority/client/cli/tx_remove_authorization.go new file mode 100644 index 0000000000..8e69c5aef7 --- /dev/null +++ b/x/authority/client/cli/tx_remove_authorization.go @@ -0,0 +1,33 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func CmdRemoveAuthorization() *cobra.Command { + cmd := &cobra.Command{ + Use: "remove-authorization [msg-url", + Short: "removes an existing authorization", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + msg := &types.MsgRemoveAuthorization{ + MsgUrl: args[0], + } + err = msg.ValidateBasic() + if err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + return cmd +} From dbb84f5b7990032800e7a79472ca01bbcd528d25 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Mon, 3 Jun 2024 12:05:44 -0400 Subject: [PATCH 05/12] add generate files --- docs/cli/zetacored/zetacored_tx_authority.md | 2 + ...etacored_tx_authority_add-authorization.md | 53 +++++++++++++++++++ ...cored_tx_authority_remove-authorization.md | 53 +++++++++++++++++++ docs/openapi/openapi.swagger.yaml | 4 ++ docs/spec/authority/messages.md | 5 +- .../zetacore/authority/policies_pb.d.ts | 9 ++++ .../zetachain/zetacore/authority/tx_pb.d.ts | 6 +-- .../client/cli/tx_add_authorization.go | 1 + .../client/cli/tx_add_authorizations_test.go | 1 + .../client/cli/tx_remove_authorization.go | 1 + .../keeper/msg_server_add_authorization.go | 6 ++- .../msg_server_add_authorization_test.go | 1 + .../keeper/msg_server_remove_authorization.go | 6 ++- .../msg_server_remove_authorization_test.go | 1 + .../types/message_add_authorization.go | 8 +-- .../types/message_add_authorizations_test.go | 3 +- .../types/message_remove_authorization.go | 6 +-- .../message_remove_authorizations_test.go | 1 + 18 files changed, 153 insertions(+), 14 deletions(-) create mode 100644 docs/cli/zetacored/zetacored_tx_authority_add-authorization.md create mode 100644 docs/cli/zetacored/zetacored_tx_authority_remove-authorization.md diff --git a/docs/cli/zetacored/zetacored_tx_authority.md b/docs/cli/zetacored/zetacored_tx_authority.md index 5a543e70b1..78af9f3a66 100644 --- a/docs/cli/zetacored/zetacored_tx_authority.md +++ b/docs/cli/zetacored/zetacored_tx_authority.md @@ -26,6 +26,8 @@ zetacored tx authority [flags] ### SEE ALSO * [zetacored tx](zetacored_tx.md) - Transactions subcommands +* [zetacored tx authority add-authorization](zetacored_tx_authority_add-authorization.md) - add a new authorization or update the policy of an existing authorization.Policy type can be 0 for groupEmergency, 1 for groupOperational, 2 for groupAdmin +* [zetacored tx authority remove-authorization](zetacored_tx_authority_remove-authorization.md) - removes an existing authorization * [zetacored tx authority update-chain-info](zetacored_tx_authority_update-chain-info.md) - Update the chain info * [zetacored tx authority update-policies](zetacored_tx_authority_update-policies.md) - Update the policies diff --git a/docs/cli/zetacored/zetacored_tx_authority_add-authorization.md b/docs/cli/zetacored/zetacored_tx_authority_add-authorization.md new file mode 100644 index 0000000000..b0a28c7b53 --- /dev/null +++ b/docs/cli/zetacored/zetacored_tx_authority_add-authorization.md @@ -0,0 +1,53 @@ +# tx authority add-authorization + +add a new authorization or update the policy of an existing authorization.Policy type can be 0 for groupEmergency, 1 for groupOperational, 2 for groupAdmin + +``` +zetacored tx authority add-authorization [msg-url] [authorized-policy] [flags] +``` + +### Options + +``` + -a, --account-number uint The account number of the signing account (offline mode only) + --aux Generate aux signer data instead of sending a tx + -b, --broadcast-mode string Transaction broadcasting mode (sync|async) + --chain-id string The network chain ID + --dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible) + --fee-granter string Fee granter grants fees for the transaction + --fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer + --fees string Fees to pay along with transaction; eg: 10uatom + --from string Name or address of private key with which to sign + --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000) + --gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1) + --gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom) + --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) + -h, --help help for add-authorization + --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) + --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used + --ledger Use a connected Ledger device + --node string [host]:[port] to tendermint rpc interface for this chain + --note string Note to add a description to the transaction (previously --memo) + --offline Offline mode (does not allow any online functionality) + -o, --output string Output format (text|json) + -s, --sequence uint The sequence number of the signing account (offline mode only) + --sign-mode string Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature + --timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height + --tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator + -y, --yes Skip tx broadcasting prompt confirmation +``` + +### Options inherited from parent commands + +``` + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --log_no_color Disable colored logs + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored tx authority](zetacored_tx_authority.md) - authority transactions subcommands + diff --git a/docs/cli/zetacored/zetacored_tx_authority_remove-authorization.md b/docs/cli/zetacored/zetacored_tx_authority_remove-authorization.md new file mode 100644 index 0000000000..e873383ea5 --- /dev/null +++ b/docs/cli/zetacored/zetacored_tx_authority_remove-authorization.md @@ -0,0 +1,53 @@ +# tx authority remove-authorization + +removes an existing authorization + +``` +zetacored tx authority remove-authorization [msg-url [flags] +``` + +### Options + +``` + -a, --account-number uint The account number of the signing account (offline mode only) + --aux Generate aux signer data instead of sending a tx + -b, --broadcast-mode string Transaction broadcasting mode (sync|async) + --chain-id string The network chain ID + --dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible) + --fee-granter string Fee granter grants fees for the transaction + --fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer + --fees string Fees to pay along with transaction; eg: 10uatom + --from string Name or address of private key with which to sign + --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000) + --gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1) + --gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom) + --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) + -h, --help help for remove-authorization + --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) + --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used + --ledger Use a connected Ledger device + --node string [host]:[port] to tendermint rpc interface for this chain + --note string Note to add a description to the transaction (previously --memo) + --offline Offline mode (does not allow any online functionality) + -o, --output string Output format (text|json) + -s, --sequence uint The sequence number of the signing account (offline mode only) + --sign-mode string Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature + --timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height + --tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator + -y, --yes Skip tx broadcasting prompt confirmation +``` + +### Options inherited from parent commands + +``` + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --log_no_color Disable colored logs + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored tx authority](zetacored_tx_authority.md) - authority transactions subcommands + diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index 470b246295..8bb38c8a67 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -56766,6 +56766,7 @@ definitions: - groupEmergency - groupOperational - groupAdmin + - groupEmpty default: groupEmergency description: |- - groupEmergency: Used for emergency situations that require immediate action @@ -56773,6 +56774,9 @@ definitions: - groupAdmin: non-sensitive protocol parameters Used for administrative tasks like changing sensitive + - groupEmpty: protocol parameters or moving funds + + Used for empty policy, no action is allowed title: PolicyType defines the type of policy authorityQueryGetChainInfoResponse: type: object diff --git a/docs/spec/authority/messages.md b/docs/spec/authority/messages.md index 329cf8b5ec..6723681885 100644 --- a/docs/spec/authority/messages.md +++ b/docs/spec/authority/messages.md @@ -25,11 +25,14 @@ message MsgUpdateChainInfo { ## MsgAddAuthorization +AddAuthorization defines a method to add an authorization.If the authorization already exists, it will be overwritten with the provided policy. +This should be called by the admin policy account. + ```proto message MsgAddAuthorization { string creator = 1; string msg_url = 2; - Policy policy = 3; + PolicyType authorized_policy = 3; } ``` diff --git a/typescript/zetachain/zetacore/authority/policies_pb.d.ts b/typescript/zetachain/zetacore/authority/policies_pb.d.ts index 21646f273a..8bf6b71c00 100644 --- a/typescript/zetachain/zetacore/authority/policies_pb.d.ts +++ b/typescript/zetachain/zetacore/authority/policies_pb.d.ts @@ -34,6 +34,15 @@ export declare enum PolicyType { * @generated from enum value: groupAdmin = 2; */ groupAdmin = 2, + + /** + * protocol parameters or moving funds + * + * Used for empty policy, no action is allowed + * + * @generated from enum value: groupEmpty = 3; + */ + groupEmpty = 3, } /** diff --git a/typescript/zetachain/zetacore/authority/tx_pb.d.ts b/typescript/zetachain/zetacore/authority/tx_pb.d.ts index 391d9632ab..827b942c9b 100644 --- a/typescript/zetachain/zetacore/authority/tx_pb.d.ts +++ b/typescript/zetachain/zetacore/authority/tx_pb.d.ts @@ -5,7 +5,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; import { Message, proto3 } from "@bufbuild/protobuf"; -import type { Policies, Policy } from "./policies_pb.js"; +import type { Policies, PolicyType } from "./policies_pb.js"; import type { ChainInfo } from "./chain_info_pb.js"; /** @@ -27,9 +27,9 @@ export declare class MsgAddAuthorization extends Message { msgUrl: string; /** - * @generated from field: zetachain.zetacore.authority.Policy policy = 3; + * @generated from field: zetachain.zetacore.authority.PolicyType authorized_policy = 3; */ - policy?: Policy; + authorizedPolicy: PolicyType; constructor(data?: PartialMessage); diff --git a/x/authority/client/cli/tx_add_authorization.go b/x/authority/client/cli/tx_add_authorization.go index f0a8b9418b..0fe76f82e7 100644 --- a/x/authority/client/cli/tx_add_authorization.go +++ b/x/authority/client/cli/tx_add_authorization.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/authority/types" ) diff --git a/x/authority/client/cli/tx_add_authorizations_test.go b/x/authority/client/cli/tx_add_authorizations_test.go index 279fdc0420..b6d764f070 100644 --- a/x/authority/client/cli/tx_add_authorizations_test.go +++ b/x/authority/client/cli/tx_add_authorizations_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/x/authority/client/cli" "github.com/zeta-chain/zetacore/x/authority/types" ) diff --git a/x/authority/client/cli/tx_remove_authorization.go b/x/authority/client/cli/tx_remove_authorization.go index 8e69c5aef7..cadaf786f6 100644 --- a/x/authority/client/cli/tx_remove_authorization.go +++ b/x/authority/client/cli/tx_remove_authorization.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/spf13/cobra" + "github.com/zeta-chain/zetacore/x/authority/types" ) diff --git a/x/authority/keeper/msg_server_add_authorization.go b/x/authority/keeper/msg_server_add_authorization.go index bb72c48d11..1e5a4ce171 100644 --- a/x/authority/keeper/msg_server_add_authorization.go +++ b/x/authority/keeper/msg_server_add_authorization.go @@ -5,12 +5,16 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/authority/types" ) // AddAuthorization defines a method to add an authorization.If the authorization already exists, it will be overwritten with the provided policy. // This should be called by the admin policy account. -func (k msgServer) AddAuthorization(goCtx context.Context, msg *types.MsgAddAuthorization) (*types.MsgAddAuthorizationResponse, error) { +func (k msgServer) AddAuthorization( + goCtx context.Context, + msg *types.MsgAddAuthorization, +) (*types.MsgAddAuthorizationResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) if !k.IsAuthorized(ctx, msg.Creator, types.PolicyType_groupAdmin) { diff --git a/x/authority/keeper/msg_server_add_authorization_test.go b/x/authority/keeper/msg_server_add_authorization_test.go index 35115221cb..dd830e7c0b 100644 --- a/x/authority/keeper/msg_server_add_authorization_test.go +++ b/x/authority/keeper/msg_server_add_authorization_test.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/authority/keeper" diff --git a/x/authority/keeper/msg_server_remove_authorization.go b/x/authority/keeper/msg_server_remove_authorization.go index d51df49b23..310f970b7f 100644 --- a/x/authority/keeper/msg_server_remove_authorization.go +++ b/x/authority/keeper/msg_server_remove_authorization.go @@ -6,12 +6,16 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/authority/types" ) // RemoveAuthorization defines a method to remove an authorization. // This should be called by the admin policy account. -func (k msgServer) RemoveAuthorization(goCtx context.Context, msg *types.MsgRemoveAuthorization) (*types.MsgRemoveAuthorizationResponse, error) { +func (k msgServer) RemoveAuthorization( + goCtx context.Context, + msg *types.MsgRemoveAuthorization, +) (*types.MsgRemoveAuthorizationResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) if !k.IsAuthorized(ctx, msg.Creator, types.PolicyType_groupAdmin) { diff --git a/x/authority/keeper/msg_server_remove_authorization_test.go b/x/authority/keeper/msg_server_remove_authorization_test.go index 89e0ee7702..1025e324ae 100644 --- a/x/authority/keeper/msg_server_remove_authorization_test.go +++ b/x/authority/keeper/msg_server_remove_authorization_test.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/authority/keeper" diff --git a/x/authority/types/message_add_authorization.go b/x/authority/types/message_add_authorization.go index 78661fe0e6..0de3162a78 100644 --- a/x/authority/types/message_add_authorization.go +++ b/x/authority/types/message_add_authorization.go @@ -10,10 +10,10 @@ const TypeMsgAddAuthorization = "AddAuthorization" var _ sdk.Msg = &MsgAddAuthorization{} -func NewMsgAddAuthorization(creator string, msgUrl string, authorizedPolicy PolicyType) *MsgAddAuthorization { +func NewMsgAddAuthorization(creator string, msgURL string, authorizedPolicy PolicyType) *MsgAddAuthorization { return &MsgAddAuthorization{ Creator: creator, - MsgUrl: msgUrl, + MsgUrl: msgURL, AuthorizedPolicy: authorizedPolicy, } } @@ -50,14 +50,14 @@ func (msg *MsgAddAuthorization) ValidateBasic() error { } // the message URL must be valid - if err := ValidateMsgUrl(msg.MsgUrl); err != nil { + if err := ValidateMsgURL(msg.MsgUrl); err != nil { return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid msg url: %s", err.Error()) } return nil } -func ValidateMsgUrl(url string) error { +func ValidateMsgURL(url string) error { if len(url) == 0 { return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "message URL cannot be empty") } diff --git a/x/authority/types/message_add_authorizations_test.go b/x/authority/types/message_add_authorizations_test.go index 965bf5ec4d..b6299ddffb 100644 --- a/x/authority/types/message_add_authorizations_test.go +++ b/x/authority/types/message_add_authorizations_test.go @@ -6,6 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/authority/types" ) @@ -122,7 +123,7 @@ func TestValidateMsgUrl(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - err := types.ValidateMsgUrl(tt.url) + err := types.ValidateMsgURL(tt.url) require.ErrorIs(t, err, tt.expectErr) }) } diff --git a/x/authority/types/message_remove_authorization.go b/x/authority/types/message_remove_authorization.go index 54ed0b063e..2404282088 100644 --- a/x/authority/types/message_remove_authorization.go +++ b/x/authority/types/message_remove_authorization.go @@ -10,10 +10,10 @@ const TypeRemoveAuthorization = "RemoveAuthorization" var _ sdk.Msg = &MsgRemoveAuthorization{} -func NewMsgRemoveAuthorization(creator string, msgUrl string) *MsgRemoveAuthorization { +func NewMsgRemoveAuthorization(creator string, msgURL string) *MsgRemoveAuthorization { return &MsgRemoveAuthorization{ Creator: creator, - MsgUrl: msgUrl, + MsgUrl: msgURL, } } @@ -43,7 +43,7 @@ func (msg *MsgRemoveAuthorization) ValidateBasic() error { return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } - if err := ValidateMsgUrl(msg.MsgUrl); err != nil { + if err := ValidateMsgURL(msg.MsgUrl); err != nil { return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid msg url: %s", err.Error()) } diff --git a/x/authority/types/message_remove_authorizations_test.go b/x/authority/types/message_remove_authorizations_test.go index a2833bd8a1..22c9150698 100644 --- a/x/authority/types/message_remove_authorizations_test.go +++ b/x/authority/types/message_remove_authorizations_test.go @@ -6,6 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/authority/types" ) From 9619262d0b866c8f814895233359d3a377a7b5f2 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Mon, 3 Jun 2024 12:41:13 -0400 Subject: [PATCH 06/12] add generate files 2 --- changelog.md | 1 + ...cored_tx_authority_remove-authorization.md | 2 +- docs/spec/authority/messages.md | 2 +- .../client/cli/tx_remove_authorization.go | 2 +- .../msg_server_remove_authorization_test.go | 54 ++++++++++++++++++- x/authority/types/authorizations.go | 4 +- x/authority/types/authorizations_test.go | 6 +-- .../types/message_add_authorizations_test.go | 6 +-- .../message_remove_authorizations_test.go | 4 +- x/authority/types/policytype_test.go | 52 ++++++++++++++++++ 10 files changed, 119 insertions(+), 14 deletions(-) create mode 100644 x/authority/types/policytype_test.go diff --git a/changelog.md b/changelog.md index d4595d2891..985843896c 100644 --- a/changelog.md +++ b/changelog.md @@ -21,6 +21,7 @@ * [2279](https://github.com/zeta-chain/node/pull/2279) - add a CCTXGateway field to chain static data * [2275](https://github.com/zeta-chain/node/pull/2275) - add ChainInfo singleton state variable in authority * [2289](https://github.com/zeta-chain/node/pull/2289) - add an authorization list to keep track of all authorizations on the chain +* [2305](https://github.com/zeta-chain/node/pull/2305) - add `MsgAddAuthorization` and `MsgRemoveAuthorization` whcih can be used to update the authorization list ### Refactor diff --git a/docs/cli/zetacored/zetacored_tx_authority_remove-authorization.md b/docs/cli/zetacored/zetacored_tx_authority_remove-authorization.md index e873383ea5..a29a02bb18 100644 --- a/docs/cli/zetacored/zetacored_tx_authority_remove-authorization.md +++ b/docs/cli/zetacored/zetacored_tx_authority_remove-authorization.md @@ -3,7 +3,7 @@ removes an existing authorization ``` -zetacored tx authority remove-authorization [msg-url [flags] +zetacored tx authority remove-authorization [msg-url] [flags] ``` ### Options diff --git a/docs/spec/authority/messages.md b/docs/spec/authority/messages.md index 6723681885..8ee4264bab 100644 --- a/docs/spec/authority/messages.md +++ b/docs/spec/authority/messages.md @@ -38,7 +38,7 @@ message MsgAddAuthorization { ## MsgRemoveAuthorization -RemoveAuthorization removes the authorization from the list. It does not check if the authorization exists or not. +RemoveAuthorization removes the authorization from the list. It should be called by the admin policy account. ```proto message MsgRemoveAuthorization { diff --git a/x/authority/client/cli/tx_remove_authorization.go b/x/authority/client/cli/tx_remove_authorization.go index cadaf786f6..3fee09f12f 100644 --- a/x/authority/client/cli/tx_remove_authorization.go +++ b/x/authority/client/cli/tx_remove_authorization.go @@ -11,7 +11,7 @@ import ( func CmdRemoveAuthorization() *cobra.Command { cmd := &cobra.Command{ - Use: "remove-authorization [msg-url", + Use: "remove-authorization [msg-url]", Short: "removes an existing authorization", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/x/authority/keeper/msg_server_remove_authorization_test.go b/x/authority/keeper/msg_server_remove_authorization_test.go index 1025e324ae..90529fe58a 100644 --- a/x/authority/keeper/msg_server_remove_authorization_test.go +++ b/x/authority/keeper/msg_server_remove_authorization_test.go @@ -13,7 +13,7 @@ import ( ) func TestMsgServer_RemoveAuthorization(t *testing.T) { - t.Run("successfully remove authorization", func(t *testing.T) { + t.Run("successfully remove operational policy authorization", func(t *testing.T) { k, ctx := keepertest.AuthorityKeeper(t) admin := keepertest.SetAdminPolices(ctx, k) k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) @@ -39,6 +39,58 @@ func TestMsgServer_RemoveAuthorization(t *testing.T) { require.ErrorIs(t, err, types.ErrAuthorizationNotFound) }) + t.Run("successfully remove admin policy authorization", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolices(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + msgServer := keeper.NewMsgServerImpl(*k) + url := types.AdminPolicyMessages[0] + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: url, + } + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + _, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err, types.ErrAuthorizationNotFound) + + _, err = msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found = k.GetAuthorizationList(ctx) + require.True(t, found) + _, err = authorizationList.GetAuthorizedPolicy(url) + require.ErrorIs(t, err, types.ErrAuthorizationNotFound) + }) + + t.Run("successfully remove emergency policy authorization", func(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + admin := keepertest.SetAdminPolices(ctx, k) + k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) + msgServer := keeper.NewMsgServerImpl(*k) + url := types.EmergencyPolicyMessages[0] + + msg := &types.MsgRemoveAuthorization{ + Creator: admin, + MsgUrl: url, + } + + authorizationList, found := k.GetAuthorizationList(ctx) + require.True(t, found) + _, err := authorizationList.GetAuthorizedPolicy(url) + require.NoError(t, err, types.ErrAuthorizationNotFound) + + _, err = msgServer.RemoveAuthorization(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + authorizationList, found = k.GetAuthorizationList(ctx) + require.True(t, found) + _, err = authorizationList.GetAuthorizedPolicy(url) + require.ErrorIs(t, err, types.ErrAuthorizationNotFound) + }) + t.Run("unable to remove authorization if creator is not the correct policy", func(t *testing.T) { k, ctx := keepertest.AuthorityKeeper(t) k.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) diff --git a/x/authority/types/authorizations.go b/x/authority/types/authorizations.go index a864e2abf9..003fac8124 100644 --- a/x/authority/types/authorizations.go +++ b/x/authority/types/authorizations.go @@ -93,7 +93,7 @@ func (a *AuthorizationList) SetAuthorization(authorization Authorization) { a.Authorizations = append(a.Authorizations, authorization) } -// RemoveAuthorization removes the authorization from the list. It does not check if the authorization exists or not. +// RemoveAuthorization removes the authorization from the list. It should be called by the admin policy account. func (a *AuthorizationList) RemoveAuthorization(msgURL string) { for i, auth := range a.Authorizations { if auth.MsgUrl == msgURL { @@ -112,7 +112,7 @@ func (a *AuthorizationList) GetAuthorizedPolicy(msgURL string) (PolicyType, erro } } // Returning first value of enum, can consider adding a default value of `EmptyPolicy` in the enum. - return PolicyType(0), ErrAuthorizationNotFound + return PolicyType_groupEmpty, ErrAuthorizationNotFound } // Validate checks if the authorization list is valid. It returns an error if the message url is duplicated with different policies. diff --git a/x/authority/types/authorizations_test.go b/x/authority/types/authorizations_test.go index f718294b33..31e7a8b462 100644 --- a/x/authority/types/authorizations_test.go +++ b/x/authority/types/authorizations_test.go @@ -176,21 +176,21 @@ func TestAuthorizationList_GetAuthorizations(t *testing.T) { }, }}, getPolicyMsgUrl: "XYZ", - expectedPolicy: types.PolicyType(0), + expectedPolicy: types.PolicyType_groupEmpty, error: types.ErrAuthorizationNotFound, }, { name: "get authorizations fails when msg not found in list", authorizations: types.AuthorizationList{Authorizations: []types.Authorization{}}, getPolicyMsgUrl: "ABC", - expectedPolicy: types.PolicyType(0), + expectedPolicy: types.PolicyType_groupEmpty, error: types.ErrAuthorizationNotFound, }, { name: "get authorizations fails when when queried for empty string", authorizations: types.AuthorizationList{Authorizations: []types.Authorization{}}, getPolicyMsgUrl: "", - expectedPolicy: types.PolicyType(0), + expectedPolicy: types.PolicyType_groupEmpty, error: types.ErrAuthorizationNotFound, }, } diff --git a/x/authority/types/message_add_authorizations_test.go b/x/authority/types/message_add_authorizations_test.go index b6299ddffb..dcc970adbd 100644 --- a/x/authority/types/message_add_authorizations_test.go +++ b/x/authority/types/message_add_authorizations_test.go @@ -22,7 +22,7 @@ func TestMsgAddAuthorization_ValidateBasic(t *testing.T) { msg: types.NewMsgAddAuthorization("invalid", "url", types.PolicyType_groupAdmin), expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) - require.Contains(t, err.Error(), "invalid creator address") + require.ErrorContains(t, err, "invalid creator address") }, }, { @@ -30,7 +30,7 @@ func TestMsgAddAuthorization_ValidateBasic(t *testing.T) { msg: types.NewMsgAddAuthorization(sample.AccAddress(), "url", types.PolicyType_groupEmpty), expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) - require.Contains(t, err.Error(), "invalid authorized policy") + require.ErrorContains(t, err, "invalid authorized policy") }, }, { @@ -38,7 +38,7 @@ func TestMsgAddAuthorization_ValidateBasic(t *testing.T) { msg: types.NewMsgAddAuthorization(sample.AccAddress(), "", types.PolicyType_groupAdmin), expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) - require.Contains(t, err.Error(), "invalid msg url") + require.ErrorContains(t, err, "invalid msg url") }, }, { diff --git a/x/authority/types/message_remove_authorizations_test.go b/x/authority/types/message_remove_authorizations_test.go index 22c9150698..d9e35e45e0 100644 --- a/x/authority/types/message_remove_authorizations_test.go +++ b/x/authority/types/message_remove_authorizations_test.go @@ -22,7 +22,7 @@ func TestMsgRemoveAuthorization_ValidateBasic(t *testing.T) { msg: types.NewMsgRemoveAuthorization("invalid", "url"), expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) - require.Contains(t, err.Error(), "invalid creator address") + require.ErrorContains(t, err, "invalid creator address") }, }, { @@ -30,7 +30,7 @@ func TestMsgRemoveAuthorization_ValidateBasic(t *testing.T) { msg: types.NewMsgRemoveAuthorization(sample.AccAddress(), ""), expectErr: func(t require.TestingT, err error, msgAndArgs ...interface{}) { require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) - require.Contains(t, err.Error(), "invalid msg url") + require.ErrorContains(t, err, "invalid msg url") }, }, { diff --git a/x/authority/types/policytype_test.go b/x/authority/types/policytype_test.go new file mode 100644 index 0000000000..5445e4f9e6 --- /dev/null +++ b/x/authority/types/policytype_test.go @@ -0,0 +1,52 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestPolicyType_Validate(t *testing.T) { + tests := []struct { + name string + policyType types.PolicyType + wantErr bool + }{ + { + name: "valid groupEmergency", + policyType: types.PolicyType_groupEmergency, + wantErr: false, + }, + { + name: "valid groupOperational", + policyType: types.PolicyType_groupOperational, + wantErr: false, + }, + { + name: "valid groupAdmin", + policyType: types.PolicyType_groupAdmin, + wantErr: false, + }, + { + name: "invalid policy type", + policyType: types.PolicyType(20), + wantErr: true, + }, + { + name: "empty policy type", + policyType: types.PolicyType_groupEmpty, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.policyType.Validate() + if tt.wantErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +} From 844b146c36f14aefb1303f34010a1d11f921ea3b Mon Sep 17 00:00:00 2001 From: Tanmay Date: Mon, 3 Jun 2024 12:48:48 -0400 Subject: [PATCH 07/12] add generate files 2 --- x/authority/types/policytype_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/authority/types/policytype_test.go b/x/authority/types/policytype_test.go index 5445e4f9e6..f1957a36a2 100644 --- a/x/authority/types/policytype_test.go +++ b/x/authority/types/policytype_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/x/authority/types" ) From 76cea0cddd48495ef12e0ec18c63cd4aa9cf5950 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Mon, 3 Jun 2024 13:49:06 -0400 Subject: [PATCH 08/12] add generated files --- .../zetacored/zetacored_query_authority.md | 2 + ...red_query_authority_list-authorizations.md | 34 + ...ored_query_authority_show-authorization.md | 34 + docs/openapi/openapi.swagger.yaml | 70 ++ .../zetachain/zetacore/authority/query.proto | 31 + .../zetacore/authority/query_pb.d.ts | 104 +++ x/authority/client/cli/query.go | 2 + .../client/cli/query_authorization_list.go | 62 ++ .../keeper/grpc_query_authorization_list.go | 51 ++ .../grpc_query_authothorization_list_test.go | 161 ++++ x/authority/types/query.pb.go | 799 +++++++++++++++++- x/authority/types/query.pb.gw.go | 166 ++++ 12 files changed, 1478 insertions(+), 38 deletions(-) create mode 100644 docs/cli/zetacored/zetacored_query_authority_list-authorizations.md create mode 100644 docs/cli/zetacored/zetacored_query_authority_show-authorization.md create mode 100644 x/authority/client/cli/query_authorization_list.go create mode 100644 x/authority/keeper/grpc_query_authorization_list.go create mode 100644 x/authority/keeper/grpc_query_authothorization_list_test.go diff --git a/docs/cli/zetacored/zetacored_query_authority.md b/docs/cli/zetacored/zetacored_query_authority.md index f1e6bd9b69..75265b3195 100644 --- a/docs/cli/zetacored/zetacored_query_authority.md +++ b/docs/cli/zetacored/zetacored_query_authority.md @@ -26,6 +26,8 @@ zetacored query authority [flags] ### SEE ALSO * [zetacored query](zetacored_query.md) - Querying subcommands +* [zetacored query authority list-authorizations](zetacored_query_authority_list-authorizations.md) - lists all authorizations +* [zetacored query authority show-authorization](zetacored_query_authority_show-authorization.md) - shows the authorization for a given message URL * [zetacored query authority show-chain-info](zetacored_query_authority_show-chain-info.md) - show the chain info * [zetacored query authority show-policies](zetacored_query_authority_show-policies.md) - show the policies diff --git a/docs/cli/zetacored/zetacored_query_authority_list-authorizations.md b/docs/cli/zetacored/zetacored_query_authority_list-authorizations.md new file mode 100644 index 0000000000..32443ff20c --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_authority_list-authorizations.md @@ -0,0 +1,34 @@ +# query authority list-authorizations + +lists all authorizations + +``` +zetacored query authority list-authorizations [flags] +``` + +### Options + +``` + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for list-authorizations + --node string [host]:[port] to Tendermint RPC interface for this chain + -o, --output string Output format (text|json) +``` + +### Options inherited from parent commands + +``` + --chain-id string The network chain ID + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --log_no_color Disable colored logs + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored query authority](zetacored_query_authority.md) - Querying commands for the authority module + diff --git a/docs/cli/zetacored/zetacored_query_authority_show-authorization.md b/docs/cli/zetacored/zetacored_query_authority_show-authorization.md new file mode 100644 index 0000000000..336129f1a1 --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_authority_show-authorization.md @@ -0,0 +1,34 @@ +# query authority show-authorization + +shows the authorization for a given message URL + +``` +zetacored query authority show-authorization [msg-url] [flags] +``` + +### Options + +``` + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for show-authorization + --node string [host]:[port] to Tendermint RPC interface for this chain + -o, --output string Output format (text|json) +``` + +### Options inherited from parent commands + +``` + --chain-id string The network chain ID + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --log_no_color Disable colored logs + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored query authority](zetacored_query_authority.md) - Querying commands for the authority module + diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index 8bb38c8a67..c97f692f7a 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -28254,6 +28254,39 @@ paths: type: boolean tags: - Query + /zeta-chain/authority/authorization/{msg_url}: + get: + operationId: Query_Authorization + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/authorityQueryAuthorizationResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: msg_url + in: path + required: true + type: string + tags: + - Query + /zeta-chain/authority/authorizationList: + get: + operationId: Query_AuthorizationList + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/authorityQueryAuthorizationListResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + tags: + - Query /zeta-chain/authority/chainInfo: get: summary: Queries ChainInfo @@ -56718,6 +56751,27 @@ definitions: format: int64 balance: type: string + authorityAuthorization: + type: object + properties: + msg_url: + type: string + title: The URL of the message that needs to be authorized + authorized_policy: + $ref: '#/definitions/authorityPolicyType' + title: The policy that is authorized to access the message + title: |- + Authorization defines the authorization required to access use a message + which needs special permissions + authorityAuthorizationList: + type: object + properties: + authorizations: + type: array + items: + type: object + $ref: '#/definitions/authorityAuthorization' + title: AuthorizationList holds the list of authorizations on zetachain authorityChainInfo: type: object properties: @@ -56778,6 +56832,22 @@ definitions: Used for empty policy, no action is allowed title: PolicyType defines the type of policy + authorityQueryAuthorizationListResponse: + type: object + properties: + authorization_list: + $ref: '#/definitions/authorityAuthorizationList' + title: |- + QueryAuthorizationListResponse is the response type for the + Query/AuthorizationList RPC + authorityQueryAuthorizationResponse: + type: object + properties: + authorization: + $ref: '#/definitions/authorityAuthorization' + description: |- + QueryAuthorizationResponse is the response type for the Query/Authorization + RPC method. authorityQueryGetChainInfoResponse: type: object properties: diff --git a/proto/zetachain/zetacore/authority/query.proto b/proto/zetachain/zetacore/authority/query.proto index c5cb89d47a..854b551818 100644 --- a/proto/zetachain/zetacore/authority/query.proto +++ b/proto/zetachain/zetacore/authority/query.proto @@ -3,6 +3,7 @@ package zetachain.zetacore.authority; import "zetachain/zetacore/authority/policies.proto"; import "zetachain/zetacore/authority/chain_info.proto"; +import "zetachain/zetacore/authority/authorization.proto"; import "cosmos/base/query/v1beta1/pagination.proto"; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; @@ -20,6 +21,36 @@ service Query { rpc ChainInfo(QueryGetChainInfoRequest) returns (QueryGetChainInfoResponse) { option (google.api.http).get = "/zeta-chain/authority/chainInfo"; } + + rpc AuthorizationList(QueryAuthorizationListRequest) + returns (QueryAuthorizationListResponse) { + option (google.api.http).get = "/zeta-chain/authority/authorizationList"; + } + + rpc Authorization(QueryAuthorizationRequest) + returns (QueryAuthorizationResponse) { + option (google.api.http).get = + "/zeta-chain/authority/authorization/{msg_url}"; + } +} + +// QueryAuthorizationListRequest is the request type for the +// Query/AuthorizationList RPC method. +message QueryAuthorizationListRequest {} +// QueryAuthorizationListResponse is the response type for the +// Query/AuthorizationList RPC +message QueryAuthorizationListResponse { + AuthorizationList authorization_list = 1 [ (gogoproto.nullable) = false ]; +} + +// QueryAuthorizationRequest is the request type for the Query/Authorization RPC +// method. +message QueryAuthorizationRequest { string msg_url = 1; } + +// QueryAuthorizationResponse is the response type for the Query/Authorization +// RPC method. +message QueryAuthorizationResponse { + Authorization authorization = 1 [ (gogoproto.nullable) = false ]; } // QueryGetPoliciesRequest is the request type for the Query/Policies RPC diff --git a/typescript/zetachain/zetacore/authority/query_pb.d.ts b/typescript/zetachain/zetacore/authority/query_pb.d.ts index 13192f4592..df4d0e5c9e 100644 --- a/typescript/zetachain/zetacore/authority/query_pb.d.ts +++ b/typescript/zetachain/zetacore/authority/query_pb.d.ts @@ -5,9 +5,113 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; import { Message, proto3 } from "@bufbuild/protobuf"; +import type { Authorization, AuthorizationList } from "./authorization_pb.js"; import type { Policies } from "./policies_pb.js"; import type { ChainInfo } from "./chain_info_pb.js"; +/** + * QueryAuthorizationListRequest is the request type for the + * Query/AuthorizationList RPC method. + * + * @generated from message zetachain.zetacore.authority.QueryAuthorizationListRequest + */ +export declare class QueryAuthorizationListRequest extends Message { + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.QueryAuthorizationListRequest"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryAuthorizationListRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryAuthorizationListRequest; + + static fromJsonString(jsonString: string, options?: Partial): QueryAuthorizationListRequest; + + static equals(a: QueryAuthorizationListRequest | PlainMessage | undefined, b: QueryAuthorizationListRequest | PlainMessage | undefined): boolean; +} + +/** + * QueryAuthorizationListResponse is the response type for the + * Query/AuthorizationList RPC + * + * @generated from message zetachain.zetacore.authority.QueryAuthorizationListResponse + */ +export declare class QueryAuthorizationListResponse extends Message { + /** + * @generated from field: zetachain.zetacore.authority.AuthorizationList authorization_list = 1; + */ + authorizationList?: AuthorizationList; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.QueryAuthorizationListResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryAuthorizationListResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryAuthorizationListResponse; + + static fromJsonString(jsonString: string, options?: Partial): QueryAuthorizationListResponse; + + static equals(a: QueryAuthorizationListResponse | PlainMessage | undefined, b: QueryAuthorizationListResponse | PlainMessage | undefined): boolean; +} + +/** + * QueryAuthorizationRequest is the request type for the Query/Authorization RPC + * method. + * + * @generated from message zetachain.zetacore.authority.QueryAuthorizationRequest + */ +export declare class QueryAuthorizationRequest extends Message { + /** + * @generated from field: string msg_url = 1; + */ + msgUrl: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.QueryAuthorizationRequest"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryAuthorizationRequest; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryAuthorizationRequest; + + static fromJsonString(jsonString: string, options?: Partial): QueryAuthorizationRequest; + + static equals(a: QueryAuthorizationRequest | PlainMessage | undefined, b: QueryAuthorizationRequest | PlainMessage | undefined): boolean; +} + +/** + * QueryAuthorizationResponse is the response type for the Query/Authorization + * RPC method. + * + * @generated from message zetachain.zetacore.authority.QueryAuthorizationResponse + */ +export declare class QueryAuthorizationResponse extends Message { + /** + * @generated from field: zetachain.zetacore.authority.Authorization authorization = 1; + */ + authorization?: Authorization; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.authority.QueryAuthorizationResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): QueryAuthorizationResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): QueryAuthorizationResponse; + + static fromJsonString(jsonString: string, options?: Partial): QueryAuthorizationResponse; + + static equals(a: QueryAuthorizationResponse | PlainMessage | undefined, b: QueryAuthorizationResponse | PlainMessage | undefined): boolean; +} + /** * QueryGetPoliciesRequest is the request type for the Query/Policies RPC * method. diff --git a/x/authority/client/cli/query.go b/x/authority/client/cli/query.go index ec6f965b7f..687158d917 100644 --- a/x/authority/client/cli/query.go +++ b/x/authority/client/cli/query.go @@ -23,6 +23,8 @@ func GetQueryCmd(_ string) *cobra.Command { cmd.AddCommand( CmdShowPolicies(), CmdShowChainInfo(), + CmdAuthorizationsList(), + CmdAuthorization(), ) return cmd diff --git a/x/authority/client/cli/query_authorization_list.go b/x/authority/client/cli/query_authorization_list.go new file mode 100644 index 0000000000..a822e9603b --- /dev/null +++ b/x/authority/client/cli/query_authorization_list.go @@ -0,0 +1,62 @@ +package cli + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/zeta-chain/zetacore/x/authority/types" +) + +// CmdAuthorizationsList shows the list of authorizations +func CmdAuthorizationsList() *cobra.Command { + cmd := &cobra.Command{ + Use: "list-authorizations", + Short: "lists all authorizations", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.AuthorizationList(context.Background(), &types.QueryAuthorizationListRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + return cmd +} + +// CmdAuthorization shows the authorization for a given message URL +func CmdAuthorization() *cobra.Command { + cmd := &cobra.Command{ + Use: "show-authorization [msg-url]", + Short: "shows the authorization for a given message URL", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + msgURL := args[0] + res, err := queryClient.Authorization(context.Background(), &types.QueryAuthorizationRequest{ + MsgUrl: msgURL, + }) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + return cmd +} diff --git a/x/authority/keeper/grpc_query_authorization_list.go b/x/authority/keeper/grpc_query_authorization_list.go new file mode 100644 index 0000000000..b25fc11f5b --- /dev/null +++ b/x/authority/keeper/grpc_query_authorization_list.go @@ -0,0 +1,51 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func (k Keeper) AuthorizationList(c context.Context, + req *types.QueryAuthorizationListRequest, +) (*types.QueryAuthorizationListResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + authorizationList, found := k.GetAuthorizationList(ctx) + if !found { + return nil, types.ErrAuthorizationListNotFound + } + return &types.QueryAuthorizationListResponse{AuthorizationList: authorizationList}, nil +} + +func (k Keeper) Authorization(c context.Context, + req *types.QueryAuthorizationRequest, +) (*types.QueryAuthorizationResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + err := types.ValidateMsgURL(req.MsgUrl) + if err != nil { + return nil, err + } + + ctx := sdk.UnwrapSDKContext(c) + authorizationList, found := k.GetAuthorizationList(ctx) + if !found { + return nil, types.ErrAuthorizationListNotFound + } + authorization, err := authorizationList.GetAuthorizedPolicy(req.MsgUrl) + if err != nil { + return nil, err + } + return &types.QueryAuthorizationResponse{Authorization: types.Authorization{ + MsgUrl: req.MsgUrl, + AuthorizedPolicy: authorization, + }}, nil +} diff --git a/x/authority/keeper/grpc_query_authothorization_list_test.go b/x/authority/keeper/grpc_query_authothorization_list_test.go new file mode 100644 index 0000000000..47148309c5 --- /dev/null +++ b/x/authority/keeper/grpc_query_authothorization_list_test.go @@ -0,0 +1,161 @@ +package keeper_test + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/x/authority/keeper" + "github.com/zeta-chain/zetacore/x/authority/types" +) + +func TestKeeper_Authorization(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + authorizationList := types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + { + MsgUrl: "DEF", + AuthorizedPolicy: types.PolicyType_groupAdmin, + }, + }} + + tt := []struct { + name string + setAuthorizationList bool + req *types.QueryAuthorizationRequest + expectedResponse *types.QueryAuthorizationResponse + expecterErrorString string + }{ + { + name: "successfully get authorization", + setAuthorizationList: true, + req: &types.QueryAuthorizationRequest{ + MsgUrl: "ABC", + }, + expectedResponse: &types.QueryAuthorizationResponse{ + Authorization: types.Authorization{ + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }, + expecterErrorString: "", + }, + { + name: "invalid request", + setAuthorizationList: true, + req: nil, + expectedResponse: nil, + expecterErrorString: "invalid request", + }, + { + name: "invalid msg url", + setAuthorizationList: true, + req: &types.QueryAuthorizationRequest{ + MsgUrl: "", + }, + expectedResponse: nil, + expecterErrorString: "message URL cannot be empty", + }, + { + name: "authorization not found", + setAuthorizationList: true, + req: &types.QueryAuthorizationRequest{ + MsgUrl: "GHI", + }, + expectedResponse: nil, + expecterErrorString: "authorization not found", + }, + { + name: "authorization list not found", + setAuthorizationList: false, + req: &types.QueryAuthorizationRequest{ + MsgUrl: "ABC", + }, + expectedResponse: nil, + expecterErrorString: "authorization list not found", + }, + } + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + removeAuthorizationList(ctx, *k) + if tc.setAuthorizationList { + k.SetAuthorizationList(ctx, authorizationList) + } + response, err := k.Authorization(ctx, tc.req) + require.Equal(t, tc.expectedResponse, response) + if tc.expecterErrorString != "" { + require.ErrorContains(t, err, tc.expecterErrorString) + } + }) + } +} + +func TestKeeper_AuthorizationList(t *testing.T) { + k, ctx := keepertest.AuthorityKeeper(t) + authorizationList := types.AuthorizationList{Authorizations: []types.Authorization{ + { + MsgUrl: "ABC", + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + { + MsgUrl: "DEF", + AuthorizedPolicy: types.PolicyType_groupAdmin, + }, + }} + tt := []struct { + name string + setAuthorizationList bool + req *types.QueryAuthorizationListRequest + expectedResponse *types.QueryAuthorizationListResponse + expecterErrorString string + }{ + { + name: "successfully get authorization list", + setAuthorizationList: true, + req: &types.QueryAuthorizationListRequest{}, + expectedResponse: &types.QueryAuthorizationListResponse{ + AuthorizationList: authorizationList, + }, + expecterErrorString: "", + }, + { + name: "invalid request", + setAuthorizationList: true, + req: nil, + expectedResponse: nil, + expecterErrorString: "invalid request", + }, + { + name: "authorization list not found", + setAuthorizationList: false, + req: &types.QueryAuthorizationListRequest{}, + expectedResponse: nil, + expecterErrorString: "authorization list not found", + }, + } + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + removeAuthorizationList(ctx, *k) + if tc.setAuthorizationList { + k.SetAuthorizationList(ctx, authorizationList) + } + response, err := k.AuthorizationList(ctx, tc.req) + require.Equal(t, tc.expectedResponse, response) + if tc.expecterErrorString != "" { + require.ErrorContains(t, err, tc.expecterErrorString) + } + }) + + } +} + +func removeAuthorizationList(ctx sdk.Context, k keeper.Keeper) { + store := prefix.NewStore(ctx.KVStore(k.GetStoreKey()), types.KeyPrefix(types.AuthorizationListKey)) + store.Delete([]byte{0}) +} diff --git a/x/authority/types/query.pb.go b/x/authority/types/query.pb.go index e9a4c227c3..2bf0f91471 100644 --- a/x/authority/types/query.pb.go +++ b/x/authority/types/query.pb.go @@ -30,6 +30,182 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// QueryAuthorizationListRequest is the request type for the +// Query/AuthorizationList RPC method. +type QueryAuthorizationListRequest struct { +} + +func (m *QueryAuthorizationListRequest) Reset() { *m = QueryAuthorizationListRequest{} } +func (m *QueryAuthorizationListRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAuthorizationListRequest) ProtoMessage() {} +func (*QueryAuthorizationListRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_5fe6130bc825be8d, []int{0} +} +func (m *QueryAuthorizationListRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAuthorizationListRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAuthorizationListRequest.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 *QueryAuthorizationListRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAuthorizationListRequest.Merge(m, src) +} +func (m *QueryAuthorizationListRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAuthorizationListRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAuthorizationListRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAuthorizationListRequest proto.InternalMessageInfo + +// QueryAuthorizationListResponse is the response type for the +// Query/AuthorizationList RPC +type QueryAuthorizationListResponse struct { + AuthorizationList AuthorizationList `protobuf:"bytes,1,opt,name=authorization_list,json=authorizationList,proto3" json:"authorization_list"` +} + +func (m *QueryAuthorizationListResponse) Reset() { *m = QueryAuthorizationListResponse{} } +func (m *QueryAuthorizationListResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAuthorizationListResponse) ProtoMessage() {} +func (*QueryAuthorizationListResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_5fe6130bc825be8d, []int{1} +} +func (m *QueryAuthorizationListResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAuthorizationListResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAuthorizationListResponse.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 *QueryAuthorizationListResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAuthorizationListResponse.Merge(m, src) +} +func (m *QueryAuthorizationListResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAuthorizationListResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAuthorizationListResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAuthorizationListResponse proto.InternalMessageInfo + +func (m *QueryAuthorizationListResponse) GetAuthorizationList() AuthorizationList { + if m != nil { + return m.AuthorizationList + } + return AuthorizationList{} +} + +// QueryAuthorizationRequest is the request type for the Query/Authorization RPC +// method. +type QueryAuthorizationRequest struct { + MsgUrl string `protobuf:"bytes,1,opt,name=msg_url,json=msgUrl,proto3" json:"msg_url,omitempty"` +} + +func (m *QueryAuthorizationRequest) Reset() { *m = QueryAuthorizationRequest{} } +func (m *QueryAuthorizationRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAuthorizationRequest) ProtoMessage() {} +func (*QueryAuthorizationRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_5fe6130bc825be8d, []int{2} +} +func (m *QueryAuthorizationRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAuthorizationRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAuthorizationRequest.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 *QueryAuthorizationRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAuthorizationRequest.Merge(m, src) +} +func (m *QueryAuthorizationRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAuthorizationRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAuthorizationRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAuthorizationRequest proto.InternalMessageInfo + +func (m *QueryAuthorizationRequest) GetMsgUrl() string { + if m != nil { + return m.MsgUrl + } + return "" +} + +// QueryAuthorizationResponse is the response type for the Query/Authorization +// RPC method. +type QueryAuthorizationResponse struct { + Authorization Authorization `protobuf:"bytes,1,opt,name=authorization,proto3" json:"authorization"` +} + +func (m *QueryAuthorizationResponse) Reset() { *m = QueryAuthorizationResponse{} } +func (m *QueryAuthorizationResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAuthorizationResponse) ProtoMessage() {} +func (*QueryAuthorizationResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_5fe6130bc825be8d, []int{3} +} +func (m *QueryAuthorizationResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAuthorizationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAuthorizationResponse.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 *QueryAuthorizationResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAuthorizationResponse.Merge(m, src) +} +func (m *QueryAuthorizationResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAuthorizationResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAuthorizationResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAuthorizationResponse proto.InternalMessageInfo + +func (m *QueryAuthorizationResponse) GetAuthorization() Authorization { + if m != nil { + return m.Authorization + } + return Authorization{} +} + // QueryGetPoliciesRequest is the request type for the Query/Policies RPC // method. type QueryGetPoliciesRequest struct { @@ -39,7 +215,7 @@ func (m *QueryGetPoliciesRequest) Reset() { *m = QueryGetPoliciesRequest func (m *QueryGetPoliciesRequest) String() string { return proto.CompactTextString(m) } func (*QueryGetPoliciesRequest) ProtoMessage() {} func (*QueryGetPoliciesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_5fe6130bc825be8d, []int{0} + return fileDescriptor_5fe6130bc825be8d, []int{4} } func (m *QueryGetPoliciesRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -78,7 +254,7 @@ func (m *QueryGetPoliciesResponse) Reset() { *m = QueryGetPoliciesRespon func (m *QueryGetPoliciesResponse) String() string { return proto.CompactTextString(m) } func (*QueryGetPoliciesResponse) ProtoMessage() {} func (*QueryGetPoliciesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_5fe6130bc825be8d, []int{1} + return fileDescriptor_5fe6130bc825be8d, []int{5} } func (m *QueryGetPoliciesResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -123,7 +299,7 @@ func (m *QueryGetChainInfoRequest) Reset() { *m = QueryGetChainInfoReque func (m *QueryGetChainInfoRequest) String() string { return proto.CompactTextString(m) } func (*QueryGetChainInfoRequest) ProtoMessage() {} func (*QueryGetChainInfoRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_5fe6130bc825be8d, []int{2} + return fileDescriptor_5fe6130bc825be8d, []int{6} } func (m *QueryGetChainInfoRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -162,7 +338,7 @@ func (m *QueryGetChainInfoResponse) Reset() { *m = QueryGetChainInfoResp func (m *QueryGetChainInfoResponse) String() string { return proto.CompactTextString(m) } func (*QueryGetChainInfoResponse) ProtoMessage() {} func (*QueryGetChainInfoResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_5fe6130bc825be8d, []int{3} + return fileDescriptor_5fe6130bc825be8d, []int{7} } func (m *QueryGetChainInfoResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -199,6 +375,10 @@ func (m *QueryGetChainInfoResponse) GetChainInfo() ChainInfo { } func init() { + proto.RegisterType((*QueryAuthorizationListRequest)(nil), "zetachain.zetacore.authority.QueryAuthorizationListRequest") + proto.RegisterType((*QueryAuthorizationListResponse)(nil), "zetachain.zetacore.authority.QueryAuthorizationListResponse") + proto.RegisterType((*QueryAuthorizationRequest)(nil), "zetachain.zetacore.authority.QueryAuthorizationRequest") + proto.RegisterType((*QueryAuthorizationResponse)(nil), "zetachain.zetacore.authority.QueryAuthorizationResponse") proto.RegisterType((*QueryGetPoliciesRequest)(nil), "zetachain.zetacore.authority.QueryGetPoliciesRequest") proto.RegisterType((*QueryGetPoliciesResponse)(nil), "zetachain.zetacore.authority.QueryGetPoliciesResponse") proto.RegisterType((*QueryGetChainInfoRequest)(nil), "zetachain.zetacore.authority.QueryGetChainInfoRequest") @@ -210,33 +390,43 @@ func init() { } var fileDescriptor_5fe6130bc825be8d = []byte{ - // 403 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0x4f, 0xcf, 0xd2, 0x40, - 0x10, 0xc6, 0x5b, 0xa2, 0x06, 0xd6, 0xdb, 0xc6, 0x44, 0x68, 0x48, 0xc1, 0x1e, 0x80, 0x68, 0xe8, - 0x0a, 0x46, 0xbd, 0xe3, 0xc1, 0x3f, 0xf1, 0xa0, 0x1c, 0xbd, 0x98, 0x6d, 0x5d, 0xca, 0x26, 0xb0, - 0x53, 0xba, 0x5b, 0x23, 0x1e, 0xfd, 0x04, 0x26, 0x7e, 0x02, 0x0f, 0x7e, 0x17, 0x8e, 0x24, 0x5c, - 0x3c, 0x19, 0x03, 0x7e, 0x10, 0xc3, 0x76, 0x5b, 0xc8, 0x0b, 0x6f, 0xf3, 0x72, 0x9b, 0xec, 0x3c, - 0xf3, 0xcc, 0x6f, 0x26, 0xb3, 0xa8, 0xf7, 0x95, 0x29, 0x1a, 0x4e, 0x29, 0x17, 0x44, 0x47, 0x90, - 0x30, 0x42, 0x53, 0x35, 0x85, 0x84, 0xab, 0x25, 0x59, 0xa4, 0x2c, 0x59, 0xfa, 0x71, 0x02, 0x0a, - 0x70, 0xb3, 0x50, 0xfa, 0xb9, 0xd2, 0x2f, 0x94, 0xce, 0xa3, 0x52, 0x9f, 0x18, 0x66, 0x3c, 0xe4, - 0x4c, 0x66, 0x56, 0x4e, 0xbf, 0x54, 0xac, 0x13, 0x1f, 0xb9, 0x98, 0x80, 0x91, 0x3f, 0x0c, 0x41, - 0xce, 0x41, 0x92, 0x80, 0x4a, 0x96, 0x21, 0x91, 0xcf, 0x83, 0x80, 0x29, 0x3a, 0x20, 0x31, 0x8d, - 0xb8, 0xa0, 0x8a, 0x83, 0x30, 0xda, 0x7b, 0x11, 0x44, 0xa0, 0x43, 0xb2, 0x8f, 0xcc, 0x6b, 0x33, - 0x02, 0x88, 0x66, 0x8c, 0xd0, 0x98, 0x13, 0x2a, 0x04, 0x28, 0x5d, 0x62, 0x70, 0xbc, 0x06, 0xba, - 0xff, 0x7e, 0xef, 0xfa, 0x92, 0xa9, 0x77, 0x06, 0x74, 0xcc, 0x16, 0x29, 0x93, 0xca, 0xfb, 0x84, - 0xea, 0xa7, 0x29, 0x19, 0x83, 0x90, 0x0c, 0xbf, 0x42, 0xd5, 0x7c, 0xae, 0xba, 0xdd, 0xb6, 0x7b, - 0x77, 0x87, 0x1d, 0xbf, 0x6c, 0x47, 0x7e, 0xee, 0x30, 0xba, 0xb5, 0xfa, 0xd3, 0xb2, 0xc6, 0x45, - 0xb5, 0xe7, 0x1c, 0xba, 0xbc, 0xd8, 0x17, 0xbf, 0x16, 0x13, 0xc8, 0x09, 0x38, 0x6a, 0x9c, 0xc9, - 0x19, 0x84, 0xb7, 0x08, 0x1d, 0xb6, 0x65, 0x20, 0xba, 0xe5, 0x10, 0x85, 0x89, 0xa1, 0xa8, 0x85, - 0xf9, 0xc3, 0x70, 0x53, 0x41, 0xb7, 0x75, 0x2f, 0xfc, 0xd3, 0x46, 0xd5, 0x9c, 0x16, 0x3f, 0x2d, - 0x37, 0xbc, 0x66, 0x75, 0xce, 0xb3, 0x4b, 0xcb, 0xb2, 0x99, 0xbc, 0xce, 0xb7, 0xcd, 0xbf, 0x1f, - 0x95, 0x36, 0x76, 0xf5, 0x6d, 0xf4, 0xb3, 0x33, 0x39, 0x3d, 0x25, 0xfc, 0xcb, 0x46, 0xb5, 0x62, - 0x18, 0x7c, 0xc3, 0x6e, 0x57, 0xd7, 0xeb, 0x3c, 0xbf, 0xb8, 0xce, 0x60, 0x76, 0x35, 0xe6, 0x03, - 0xdc, 0x3a, 0x8f, 0x59, 0x6c, 0x75, 0xf4, 0x66, 0xb5, 0x75, 0xed, 0xf5, 0xd6, 0xb5, 0xff, 0x6e, - 0x5d, 0xfb, 0xfb, 0xce, 0xb5, 0xd6, 0x3b, 0xd7, 0xfa, 0xbd, 0x73, 0xad, 0x0f, 0x8f, 0x23, 0xae, - 0xa6, 0x69, 0xe0, 0x87, 0x30, 0x3f, 0x36, 0x29, 0xbe, 0xc4, 0x97, 0x23, 0x3f, 0xb5, 0x8c, 0x99, - 0x0c, 0xee, 0xe8, 0x83, 0x7d, 0xf2, 0x3f, 0x00, 0x00, 0xff, 0xff, 0xc1, 0xd1, 0x6c, 0x32, 0xb6, - 0x03, 0x00, 0x00, + // 570 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x3f, 0x6f, 0x13, 0x31, + 0x18, 0xc6, 0x63, 0x44, 0x4b, 0x6b, 0xd4, 0xa1, 0x16, 0x52, 0xdb, 0x53, 0xb9, 0x94, 0x1b, 0x9a, + 0x42, 0x95, 0x73, 0x5b, 0x28, 0x45, 0x82, 0x85, 0x32, 0xf0, 0x47, 0x1d, 0x20, 0x12, 0x42, 0x62, + 0x89, 0x9c, 0xd4, 0xbd, 0x58, 0x4a, 0xce, 0xd7, 0xb3, 0x0f, 0x91, 0x22, 0x16, 0x06, 0x66, 0x24, + 0x3e, 0x01, 0x03, 0x1f, 0x82, 0x89, 0xb5, 0x63, 0x11, 0x0b, 0x13, 0x42, 0x09, 0x1f, 0x04, 0xc5, + 0x79, 0xef, 0x9a, 0xeb, 0x25, 0xa7, 0x1c, 0x9b, 0x65, 0xbf, 0xcf, 0xf3, 0xfc, 0xfc, 0xca, 0xaf, + 0xf1, 0xc6, 0x09, 0xd7, 0xac, 0xd9, 0x62, 0xc2, 0xa7, 0x66, 0x25, 0x43, 0x4e, 0x59, 0xa4, 0x5b, + 0x32, 0x14, 0xba, 0x4b, 0x8f, 0x23, 0x1e, 0x76, 0xdd, 0x20, 0x94, 0x5a, 0x92, 0xd5, 0xa4, 0xd2, + 0x8d, 0x2b, 0xdd, 0xa4, 0xd2, 0xda, 0xcc, 0xf5, 0x09, 0x64, 0x5b, 0x34, 0x05, 0x57, 0x43, 0x2b, + 0xab, 0x9a, 0x5b, 0x6c, 0x0e, 0xea, 0xc2, 0x3f, 0x92, 0x50, 0xbe, 0x95, 0x5b, 0x0e, 0xab, 0x13, + 0xa6, 0x85, 0xf4, 0x41, 0x71, 0xab, 0x29, 0x55, 0x47, 0x2a, 0xda, 0x60, 0x8a, 0x0f, 0x2f, 0x41, + 0xdf, 0x6c, 0x37, 0xb8, 0x66, 0xdb, 0x34, 0x60, 0x9e, 0xf0, 0x47, 0x6b, 0xaf, 0x79, 0xd2, 0x93, + 0x66, 0x49, 0x07, 0x2b, 0xd8, 0x5d, 0xf5, 0xa4, 0xf4, 0xda, 0x9c, 0xb2, 0x40, 0x50, 0xe6, 0xfb, + 0x52, 0x1b, 0x09, 0x5c, 0xc0, 0x29, 0xe3, 0xeb, 0x2f, 0x06, 0xae, 0x0f, 0x47, 0xb3, 0x0f, 0x84, + 0xd2, 0x35, 0x7e, 0x1c, 0x71, 0xa5, 0x9d, 0x8f, 0x08, 0xdb, 0x93, 0x2a, 0x54, 0x20, 0x7d, 0xc5, + 0xc9, 0x21, 0x26, 0x29, 0xf4, 0x7a, 0x5b, 0x28, 0xbd, 0x8c, 0xd6, 0xd0, 0xc6, 0xd5, 0x1d, 0xea, + 0xe6, 0x35, 0xdb, 0xcd, 0x98, 0xee, 0x5f, 0x3e, 0xfd, 0x5d, 0x2e, 0xd5, 0x16, 0xd9, 0xc5, 0x03, + 0xe7, 0x0e, 0x5e, 0xc9, 0x72, 0x00, 0x25, 0x59, 0xc2, 0x57, 0x3a, 0xca, 0xab, 0x47, 0x61, 0xdb, + 0xe4, 0xce, 0xd7, 0x66, 0x3b, 0xca, 0x7b, 0x19, 0xb6, 0x9d, 0x08, 0x5b, 0xe3, 0x54, 0x40, 0xfe, + 0x0a, 0x2f, 0xa4, 0x82, 0x00, 0x7a, 0xb3, 0x00, 0x34, 0x00, 0xa7, 0x7d, 0x9c, 0x15, 0xbc, 0x64, + 0x62, 0x1f, 0x73, 0xfd, 0x1c, 0x5e, 0x4c, 0xdc, 0xd0, 0x43, 0xbc, 0x9c, 0x3d, 0x02, 0x9e, 0x27, + 0x78, 0x2e, 0x7e, 0x60, 0x80, 0xb2, 0x9e, 0x8f, 0x12, 0x3b, 0x00, 0x45, 0xa2, 0x76, 0xac, 0xf3, + 0x94, 0x47, 0x03, 0xf1, 0x53, 0xff, 0x48, 0xc6, 0x04, 0x02, 0x3a, 0x99, 0x3e, 0x03, 0x84, 0x03, + 0x8c, 0xcf, 0x9f, 0x2d, 0x40, 0x54, 0xf2, 0x21, 0x12, 0x13, 0xa0, 0x98, 0x6f, 0xc6, 0x1b, 0x3b, + 0x3f, 0x66, 0xf0, 0x8c, 0xc9, 0x22, 0x5f, 0x10, 0x9e, 0x8b, 0x69, 0xc9, 0x6e, 0xbe, 0xe1, 0x84, + 0xd6, 0x59, 0x77, 0x8b, 0xca, 0x86, 0x77, 0x72, 0xd6, 0x3f, 0xfc, 0xfc, 0xfb, 0xf9, 0xd2, 0x1a, + 0xb1, 0xcd, 0xd4, 0x55, 0x87, 0x03, 0x98, 0x9d, 0x69, 0xf2, 0x15, 0xe1, 0xf9, 0xe4, 0x32, 0x64, + 0xca, 0xb4, 0x8b, 0xed, 0xb5, 0xf6, 0x0a, 0xeb, 0x00, 0xb3, 0x62, 0x30, 0x6f, 0x90, 0xf2, 0x78, + 0xcc, 0xa4, 0xab, 0xe4, 0x3b, 0xc2, 0x8b, 0x99, 0xc9, 0x21, 0xf7, 0xa7, 0xc8, 0x9d, 0x34, 0xe6, + 0xd6, 0x83, 0xff, 0x13, 0x03, 0x39, 0x35, 0xe4, 0x37, 0x49, 0x65, 0x3c, 0x79, 0x66, 0x98, 0xc9, + 0x37, 0x84, 0x17, 0x52, 0x76, 0x64, 0xaf, 0x28, 0x40, 0x4c, 0x7e, 0xaf, 0xb8, 0x10, 0xa8, 0x77, + 0x0d, 0x35, 0x25, 0xd5, 0x29, 0xa8, 0xe9, 0x3b, 0xf8, 0x5f, 0xde, 0xef, 0x3f, 0x3b, 0xed, 0xd9, + 0xe8, 0xac, 0x67, 0xa3, 0x3f, 0x3d, 0x1b, 0x7d, 0xea, 0xdb, 0xa5, 0xb3, 0xbe, 0x5d, 0xfa, 0xd5, + 0xb7, 0x4b, 0xaf, 0xb7, 0x3c, 0xa1, 0x5b, 0x51, 0xc3, 0x6d, 0xca, 0xce, 0xa8, 0x65, 0xf2, 0xd5, + 0xbf, 0x1d, 0x71, 0xd7, 0xdd, 0x80, 0xab, 0xc6, 0xac, 0xf9, 0x85, 0x6f, 0xff, 0x0b, 0x00, 0x00, + 0xff, 0xff, 0x86, 0xdf, 0x6e, 0x83, 0xbd, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -255,6 +445,8 @@ type QueryClient interface { Policies(ctx context.Context, in *QueryGetPoliciesRequest, opts ...grpc.CallOption) (*QueryGetPoliciesResponse, error) // Queries ChainInfo ChainInfo(ctx context.Context, in *QueryGetChainInfoRequest, opts ...grpc.CallOption) (*QueryGetChainInfoResponse, error) + AuthorizationList(ctx context.Context, in *QueryAuthorizationListRequest, opts ...grpc.CallOption) (*QueryAuthorizationListResponse, error) + Authorization(ctx context.Context, in *QueryAuthorizationRequest, opts ...grpc.CallOption) (*QueryAuthorizationResponse, error) } type queryClient struct { @@ -283,12 +475,32 @@ func (c *queryClient) ChainInfo(ctx context.Context, in *QueryGetChainInfoReques return out, nil } +func (c *queryClient) AuthorizationList(ctx context.Context, in *QueryAuthorizationListRequest, opts ...grpc.CallOption) (*QueryAuthorizationListResponse, error) { + out := new(QueryAuthorizationListResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.authority.Query/AuthorizationList", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Authorization(ctx context.Context, in *QueryAuthorizationRequest, opts ...grpc.CallOption) (*QueryAuthorizationResponse, error) { + out := new(QueryAuthorizationResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.authority.Query/Authorization", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // Queries Policies Policies(context.Context, *QueryGetPoliciesRequest) (*QueryGetPoliciesResponse, error) // Queries ChainInfo ChainInfo(context.Context, *QueryGetChainInfoRequest) (*QueryGetChainInfoResponse, error) + AuthorizationList(context.Context, *QueryAuthorizationListRequest) (*QueryAuthorizationListResponse, error) + Authorization(context.Context, *QueryAuthorizationRequest) (*QueryAuthorizationResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -301,6 +513,12 @@ func (*UnimplementedQueryServer) Policies(ctx context.Context, req *QueryGetPoli func (*UnimplementedQueryServer) ChainInfo(ctx context.Context, req *QueryGetChainInfoRequest) (*QueryGetChainInfoResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ChainInfo not implemented") } +func (*UnimplementedQueryServer) AuthorizationList(ctx context.Context, req *QueryAuthorizationListRequest) (*QueryAuthorizationListResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AuthorizationList not implemented") +} +func (*UnimplementedQueryServer) Authorization(ctx context.Context, req *QueryAuthorizationRequest) (*QueryAuthorizationResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Authorization not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -342,6 +560,42 @@ func _Query_ChainInfo_Handler(srv interface{}, ctx context.Context, dec func(int return interceptor(ctx, in, info, handler) } +func _Query_AuthorizationList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAuthorizationListRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AuthorizationList(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.authority.Query/AuthorizationList", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AuthorizationList(ctx, req.(*QueryAuthorizationListRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Authorization_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAuthorizationRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Authorization(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.authority.Query/Authorization", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Authorization(ctx, req.(*QueryAuthorizationRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "zetachain.zetacore.authority.Query", HandlerType: (*QueryServer)(nil), @@ -354,11 +608,138 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "ChainInfo", Handler: _Query_ChainInfo_Handler, }, + { + MethodName: "AuthorizationList", + Handler: _Query_AuthorizationList_Handler, + }, + { + MethodName: "Authorization", + Handler: _Query_Authorization_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "zetachain/zetacore/authority/query.proto", } +func (m *QueryAuthorizationListRequest) 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 *QueryAuthorizationListRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAuthorizationListRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryAuthorizationListResponse) 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 *QueryAuthorizationListResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAuthorizationListResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.AuthorizationList.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryAuthorizationRequest) 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 *QueryAuthorizationRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAuthorizationRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.MsgUrl) > 0 { + i -= len(m.MsgUrl) + copy(dAtA[i:], m.MsgUrl) + i = encodeVarintQuery(dAtA, i, uint64(len(m.MsgUrl))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAuthorizationResponse) 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 *QueryAuthorizationResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAuthorizationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Authorization.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func (m *QueryGetPoliciesRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -482,7 +863,7 @@ func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *QueryGetPoliciesRequest) Size() (n int) { +func (m *QueryAuthorizationListRequest) Size() (n int) { if m == nil { return 0 } @@ -491,43 +872,385 @@ func (m *QueryGetPoliciesRequest) Size() (n int) { return n } -func (m *QueryGetPoliciesResponse) Size() (n int) { +func (m *QueryAuthorizationListResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = m.Policies.Size() + l = m.AuthorizationList.Size() n += 1 + l + sovQuery(uint64(l)) return n } -func (m *QueryGetChainInfoRequest) Size() (n int) { +func (m *QueryAuthorizationRequest) Size() (n int) { if m == nil { return 0 } var l int _ = l + l = len(m.MsgUrl) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } return n } -func (m *QueryGetChainInfoResponse) Size() (n int) { +func (m *QueryAuthorizationResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = m.ChainInfo.Size() + l = m.Authorization.Size() n += 1 + l + sovQuery(uint64(l)) return n } -func sovQuery(x uint64) (n int) { +func (m *QueryGetPoliciesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryGetPoliciesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Policies.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryGetChainInfoRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryGetChainInfoResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.ChainInfo.Size() + 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 *QueryAuthorizationListRequest) 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: QueryAuthorizationListRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAuthorizationListRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + 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 (m *QueryAuthorizationListResponse) 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: QueryAuthorizationListResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAuthorizationListResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AuthorizationList", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.AuthorizationList.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + 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 (m *QueryAuthorizationRequest) 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: QueryAuthorizationRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAuthorizationRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgUrl", 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.MsgUrl = 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 (m *QueryAuthorizationResponse) 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: QueryAuthorizationResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAuthorizationResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authorization", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Authorization.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + 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 (m *QueryGetPoliciesRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/authority/types/query.pb.gw.go b/x/authority/types/query.pb.gw.go index f465e4750f..c726e46b2e 100644 --- a/x/authority/types/query.pb.gw.go +++ b/x/authority/types/query.pb.gw.go @@ -69,6 +69,78 @@ func local_request_Query_ChainInfo_0(ctx context.Context, marshaler runtime.Mars } +func request_Query_AuthorizationList_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAuthorizationListRequest + var metadata runtime.ServerMetadata + + msg, err := client.AuthorizationList(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_AuthorizationList_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAuthorizationListRequest + var metadata runtime.ServerMetadata + + msg, err := server.AuthorizationList(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_Authorization_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAuthorizationRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["msg_url"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "msg_url") + } + + protoReq.MsgUrl, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "msg_url", err) + } + + msg, err := client.Authorization(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Authorization_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAuthorizationRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["msg_url"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "msg_url") + } + + protoReq.MsgUrl, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "msg_url", err) + } + + msg, err := server.Authorization(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. @@ -121,6 +193,52 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_AuthorizationList_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_AuthorizationList_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_AuthorizationList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Authorization_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_Authorization_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_Authorization_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -202,6 +320,46 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_AuthorizationList_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_AuthorizationList_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_AuthorizationList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Authorization_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_Authorization_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_Authorization_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -209,10 +367,18 @@ var ( pattern_Query_Policies_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "authority", "policies"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_ChainInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "authority", "chainInfo"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_AuthorizationList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "authority", "authorizationList"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Authorization_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "authority", "authorization", "msg_url"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( forward_Query_Policies_0 = runtime.ForwardResponseMessage forward_Query_ChainInfo_0 = runtime.ForwardResponseMessage + + forward_Query_AuthorizationList_0 = runtime.ForwardResponseMessage + + forward_Query_Authorization_0 = runtime.ForwardResponseMessage ) From 8e40866a5445171b61df0c4ed0c8a6edc5323739 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Tue, 4 Jun 2024 14:13:26 -0400 Subject: [PATCH 09/12] add comments --- .../zetacored/zetacored_query_authority.md | 2 ++ ...red_query_authority_list-authorizations.md | 34 +++++++++++++++++++ ...ored_query_authority_show-authorization.md | 34 +++++++++++++++++++ .../keeper/grpc_query_authorization_list.go | 2 ++ 4 files changed, 72 insertions(+) create mode 100644 docs/cli/zetacored/zetacored_query_authority_list-authorizations.md create mode 100644 docs/cli/zetacored/zetacored_query_authority_show-authorization.md diff --git a/docs/cli/zetacored/zetacored_query_authority.md b/docs/cli/zetacored/zetacored_query_authority.md index f1e6bd9b69..75265b3195 100644 --- a/docs/cli/zetacored/zetacored_query_authority.md +++ b/docs/cli/zetacored/zetacored_query_authority.md @@ -26,6 +26,8 @@ zetacored query authority [flags] ### SEE ALSO * [zetacored query](zetacored_query.md) - Querying subcommands +* [zetacored query authority list-authorizations](zetacored_query_authority_list-authorizations.md) - lists all authorizations +* [zetacored query authority show-authorization](zetacored_query_authority_show-authorization.md) - shows the authorization for a given message URL * [zetacored query authority show-chain-info](zetacored_query_authority_show-chain-info.md) - show the chain info * [zetacored query authority show-policies](zetacored_query_authority_show-policies.md) - show the policies diff --git a/docs/cli/zetacored/zetacored_query_authority_list-authorizations.md b/docs/cli/zetacored/zetacored_query_authority_list-authorizations.md new file mode 100644 index 0000000000..32443ff20c --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_authority_list-authorizations.md @@ -0,0 +1,34 @@ +# query authority list-authorizations + +lists all authorizations + +``` +zetacored query authority list-authorizations [flags] +``` + +### Options + +``` + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for list-authorizations + --node string [host]:[port] to Tendermint RPC interface for this chain + -o, --output string Output format (text|json) +``` + +### Options inherited from parent commands + +``` + --chain-id string The network chain ID + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --log_no_color Disable colored logs + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored query authority](zetacored_query_authority.md) - Querying commands for the authority module + diff --git a/docs/cli/zetacored/zetacored_query_authority_show-authorization.md b/docs/cli/zetacored/zetacored_query_authority_show-authorization.md new file mode 100644 index 0000000000..336129f1a1 --- /dev/null +++ b/docs/cli/zetacored/zetacored_query_authority_show-authorization.md @@ -0,0 +1,34 @@ +# query authority show-authorization + +shows the authorization for a given message URL + +``` +zetacored query authority show-authorization [msg-url] [flags] +``` + +### Options + +``` + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for show-authorization + --node string [host]:[port] to Tendermint RPC interface for this chain + -o, --output string Output format (text|json) +``` + +### Options inherited from parent commands + +``` + --chain-id string The network chain ID + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --log_no_color Disable colored logs + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored query authority](zetacored_query_authority.md) - Querying commands for the authority module + diff --git a/x/authority/keeper/grpc_query_authorization_list.go b/x/authority/keeper/grpc_query_authorization_list.go index b25fc11f5b..d7ba919614 100644 --- a/x/authority/keeper/grpc_query_authorization_list.go +++ b/x/authority/keeper/grpc_query_authorization_list.go @@ -10,6 +10,7 @@ import ( "github.com/zeta-chain/zetacore/x/authority/types" ) +// AuthorizationList returns the list of authorizations func (k Keeper) AuthorizationList(c context.Context, req *types.QueryAuthorizationListRequest, ) (*types.QueryAuthorizationListResponse, error) { @@ -24,6 +25,7 @@ func (k Keeper) AuthorizationList(c context.Context, return &types.QueryAuthorizationListResponse{AuthorizationList: authorizationList}, nil } +// Authorization returns the authorization for a given message URL func (k Keeper) Authorization(c context.Context, req *types.QueryAuthorizationRequest, ) (*types.QueryAuthorizationResponse, error) { From 3b8bcf4e0e93f6b3bfe05b1b435f7573023625c2 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Tue, 4 Jun 2024 14:18:31 -0400 Subject: [PATCH 10/12] add changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index dbf40ef8e3..c6d5ad7684 100644 --- a/changelog.md +++ b/changelog.md @@ -23,6 +23,7 @@ * [2291](https://github.com/zeta-chain/node/pull/2291) - initialize cctx gateway interface * [2289](https://github.com/zeta-chain/node/pull/2289) - add an authorization list to keep track of all authorizations on the chain * [2305](https://github.com/zeta-chain/node/pull/2305) - add new messages `MsgAddAuthorization` and `MsgRemoveAuthorization` that can be used to update the authorization list +* [2312](https://github.com/zeta-chain/node/pull/2312) - add queries `ShowAuthorization` and `ListAuthorizations` ### Refactor From 29d3adaa9e09be91c26e57555728b7791703b891 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Wed, 5 Jun 2024 10:57:04 -0400 Subject: [PATCH 11/12] fix comments --- docs/openapi/openapi.swagger.yaml | 2 +- .../zetachain/zetacore/authority/query.proto | 2 +- .../keeper/grpc_query_authorization_list.go | 6 +- x/authority/types/query.pb.go | 74 +++++++++---------- x/authority/types/query.pb.gw.go | 2 +- 5 files changed, 43 insertions(+), 43 deletions(-) diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index c97f692f7a..ac40f0b45a 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -28273,7 +28273,7 @@ paths: type: string tags: - Query - /zeta-chain/authority/authorizationList: + /zeta-chain/authority/authorizations: get: operationId: Query_AuthorizationList responses: diff --git a/proto/zetachain/zetacore/authority/query.proto b/proto/zetachain/zetacore/authority/query.proto index 854b551818..33431783a0 100644 --- a/proto/zetachain/zetacore/authority/query.proto +++ b/proto/zetachain/zetacore/authority/query.proto @@ -24,7 +24,7 @@ service Query { rpc AuthorizationList(QueryAuthorizationListRequest) returns (QueryAuthorizationListResponse) { - option (google.api.http).get = "/zeta-chain/authority/authorizationList"; + option (google.api.http).get = "/zeta-chain/authority/authorizations"; } rpc Authorization(QueryAuthorizationRequest) diff --git a/x/authority/keeper/grpc_query_authorization_list.go b/x/authority/keeper/grpc_query_authorization_list.go index d7ba919614..5bd8e1acf8 100644 --- a/x/authority/keeper/grpc_query_authorization_list.go +++ b/x/authority/keeper/grpc_query_authorization_list.go @@ -20,7 +20,7 @@ func (k Keeper) AuthorizationList(c context.Context, ctx := sdk.UnwrapSDKContext(c) authorizationList, found := k.GetAuthorizationList(ctx) if !found { - return nil, types.ErrAuthorizationListNotFound + return nil, status.Error(codes.Internal, types.ErrAuthorizationListNotFound.Error()) } return &types.QueryAuthorizationListResponse{AuthorizationList: authorizationList}, nil } @@ -40,11 +40,11 @@ func (k Keeper) Authorization(c context.Context, ctx := sdk.UnwrapSDKContext(c) authorizationList, found := k.GetAuthorizationList(ctx) if !found { - return nil, types.ErrAuthorizationListNotFound + return nil, status.Error(codes.Internal, types.ErrAuthorizationListNotFound.Error()) } authorization, err := authorizationList.GetAuthorizedPolicy(req.MsgUrl) if err != nil { - return nil, err + return nil, status.Error(codes.Internal, err.Error()) } return &types.QueryAuthorizationResponse{Authorization: types.Authorization{ MsgUrl: req.MsgUrl, diff --git a/x/authority/types/query.pb.go b/x/authority/types/query.pb.go index 2bf0f91471..ca13419203 100644 --- a/x/authority/types/query.pb.go +++ b/x/authority/types/query.pb.go @@ -390,43 +390,43 @@ func init() { } var fileDescriptor_5fe6130bc825be8d = []byte{ - // 570 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x3f, 0x6f, 0x13, 0x31, - 0x18, 0xc6, 0x63, 0x44, 0x4b, 0x6b, 0xd4, 0xa1, 0x16, 0x52, 0xdb, 0x53, 0xb9, 0x94, 0x1b, 0x9a, - 0x42, 0x95, 0x73, 0x5b, 0x28, 0x45, 0x82, 0x85, 0x32, 0xf0, 0x47, 0x1d, 0x20, 0x12, 0x42, 0x62, - 0x89, 0x9c, 0xd4, 0xbd, 0x58, 0x4a, 0xce, 0xd7, 0xb3, 0x0f, 0x91, 0x22, 0x16, 0x06, 0x66, 0x24, - 0x3e, 0x01, 0x03, 0x1f, 0x82, 0x89, 0xb5, 0x63, 0x11, 0x0b, 0x13, 0x42, 0x09, 0x1f, 0x04, 0xc5, - 0x79, 0xef, 0x9a, 0xeb, 0x25, 0xa7, 0x1c, 0x9b, 0x65, 0xbf, 0xcf, 0xf3, 0xfc, 0xfc, 0xca, 0xaf, - 0xf1, 0xc6, 0x09, 0xd7, 0xac, 0xd9, 0x62, 0xc2, 0xa7, 0x66, 0x25, 0x43, 0x4e, 0x59, 0xa4, 0x5b, - 0x32, 0x14, 0xba, 0x4b, 0x8f, 0x23, 0x1e, 0x76, 0xdd, 0x20, 0x94, 0x5a, 0x92, 0xd5, 0xa4, 0xd2, - 0x8d, 0x2b, 0xdd, 0xa4, 0xd2, 0xda, 0xcc, 0xf5, 0x09, 0x64, 0x5b, 0x34, 0x05, 0x57, 0x43, 0x2b, - 0xab, 0x9a, 0x5b, 0x6c, 0x0e, 0xea, 0xc2, 0x3f, 0x92, 0x50, 0xbe, 0x95, 0x5b, 0x0e, 0xab, 0x13, - 0xa6, 0x85, 0xf4, 0x41, 0x71, 0xab, 0x29, 0x55, 0x47, 0x2a, 0xda, 0x60, 0x8a, 0x0f, 0x2f, 0x41, - 0xdf, 0x6c, 0x37, 0xb8, 0x66, 0xdb, 0x34, 0x60, 0x9e, 0xf0, 0x47, 0x6b, 0xaf, 0x79, 0xd2, 0x93, - 0x66, 0x49, 0x07, 0x2b, 0xd8, 0x5d, 0xf5, 0xa4, 0xf4, 0xda, 0x9c, 0xb2, 0x40, 0x50, 0xe6, 0xfb, - 0x52, 0x1b, 0x09, 0x5c, 0xc0, 0x29, 0xe3, 0xeb, 0x2f, 0x06, 0xae, 0x0f, 0x47, 0xb3, 0x0f, 0x84, - 0xd2, 0x35, 0x7e, 0x1c, 0x71, 0xa5, 0x9d, 0x8f, 0x08, 0xdb, 0x93, 0x2a, 0x54, 0x20, 0x7d, 0xc5, - 0xc9, 0x21, 0x26, 0x29, 0xf4, 0x7a, 0x5b, 0x28, 0xbd, 0x8c, 0xd6, 0xd0, 0xc6, 0xd5, 0x1d, 0xea, - 0xe6, 0x35, 0xdb, 0xcd, 0x98, 0xee, 0x5f, 0x3e, 0xfd, 0x5d, 0x2e, 0xd5, 0x16, 0xd9, 0xc5, 0x03, - 0xe7, 0x0e, 0x5e, 0xc9, 0x72, 0x00, 0x25, 0x59, 0xc2, 0x57, 0x3a, 0xca, 0xab, 0x47, 0x61, 0xdb, - 0xe4, 0xce, 0xd7, 0x66, 0x3b, 0xca, 0x7b, 0x19, 0xb6, 0x9d, 0x08, 0x5b, 0xe3, 0x54, 0x40, 0xfe, - 0x0a, 0x2f, 0xa4, 0x82, 0x00, 0x7a, 0xb3, 0x00, 0x34, 0x00, 0xa7, 0x7d, 0x9c, 0x15, 0xbc, 0x64, - 0x62, 0x1f, 0x73, 0xfd, 0x1c, 0x5e, 0x4c, 0xdc, 0xd0, 0x43, 0xbc, 0x9c, 0x3d, 0x02, 0x9e, 0x27, - 0x78, 0x2e, 0x7e, 0x60, 0x80, 0xb2, 0x9e, 0x8f, 0x12, 0x3b, 0x00, 0x45, 0xa2, 0x76, 0xac, 0xf3, - 0x94, 0x47, 0x03, 0xf1, 0x53, 0xff, 0x48, 0xc6, 0x04, 0x02, 0x3a, 0x99, 0x3e, 0x03, 0x84, 0x03, - 0x8c, 0xcf, 0x9f, 0x2d, 0x40, 0x54, 0xf2, 0x21, 0x12, 0x13, 0xa0, 0x98, 0x6f, 0xc6, 0x1b, 0x3b, - 0x3f, 0x66, 0xf0, 0x8c, 0xc9, 0x22, 0x5f, 0x10, 0x9e, 0x8b, 0x69, 0xc9, 0x6e, 0xbe, 0xe1, 0x84, - 0xd6, 0x59, 0x77, 0x8b, 0xca, 0x86, 0x77, 0x72, 0xd6, 0x3f, 0xfc, 0xfc, 0xfb, 0xf9, 0xd2, 0x1a, - 0xb1, 0xcd, 0xd4, 0x55, 0x87, 0x03, 0x98, 0x9d, 0x69, 0xf2, 0x15, 0xe1, 0xf9, 0xe4, 0x32, 0x64, - 0xca, 0xb4, 0x8b, 0xed, 0xb5, 0xf6, 0x0a, 0xeb, 0x00, 0xb3, 0x62, 0x30, 0x6f, 0x90, 0xf2, 0x78, - 0xcc, 0xa4, 0xab, 0xe4, 0x3b, 0xc2, 0x8b, 0x99, 0xc9, 0x21, 0xf7, 0xa7, 0xc8, 0x9d, 0x34, 0xe6, - 0xd6, 0x83, 0xff, 0x13, 0x03, 0x39, 0x35, 0xe4, 0x37, 0x49, 0x65, 0x3c, 0x79, 0x66, 0x98, 0xc9, - 0x37, 0x84, 0x17, 0x52, 0x76, 0x64, 0xaf, 0x28, 0x40, 0x4c, 0x7e, 0xaf, 0xb8, 0x10, 0xa8, 0x77, - 0x0d, 0x35, 0x25, 0xd5, 0x29, 0xa8, 0xe9, 0x3b, 0xf8, 0x5f, 0xde, 0xef, 0x3f, 0x3b, 0xed, 0xd9, - 0xe8, 0xac, 0x67, 0xa3, 0x3f, 0x3d, 0x1b, 0x7d, 0xea, 0xdb, 0xa5, 0xb3, 0xbe, 0x5d, 0xfa, 0xd5, - 0xb7, 0x4b, 0xaf, 0xb7, 0x3c, 0xa1, 0x5b, 0x51, 0xc3, 0x6d, 0xca, 0xce, 0xa8, 0x65, 0xf2, 0xd5, - 0xbf, 0x1d, 0x71, 0xd7, 0xdd, 0x80, 0xab, 0xc6, 0xac, 0xf9, 0x85, 0x6f, 0xff, 0x0b, 0x00, 0x00, - 0xff, 0xff, 0x86, 0xdf, 0x6e, 0x83, 0xbd, 0x06, 0x00, 0x00, + // 573 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x4f, 0x6b, 0x13, 0x41, + 0x18, 0xc6, 0x33, 0x62, 0x6b, 0x33, 0xd2, 0x43, 0x07, 0xa1, 0xed, 0x52, 0x37, 0x75, 0x91, 0xb4, + 0x58, 0xb3, 0xd3, 0x56, 0x6b, 0x05, 0xbd, 0x58, 0x0f, 0xfe, 0xa1, 0x07, 0x0d, 0x88, 0xe0, 0x25, + 0x4c, 0xd2, 0xe9, 0x66, 0x20, 0xd9, 0xd9, 0xee, 0xcc, 0x8a, 0xa9, 0x78, 0xf1, 0xe0, 0x59, 0xf0, + 0x13, 0x78, 0xf0, 0x43, 0x08, 0x7e, 0x80, 0x9e, 0xa4, 0xe0, 0xc5, 0x93, 0x48, 0xe2, 0x07, 0x91, + 0x4c, 0xde, 0xdd, 0x66, 0x9b, 0x64, 0xc9, 0xf6, 0x36, 0xcc, 0xbc, 0xcf, 0xf3, 0xfc, 0xe6, 0x65, + 0xde, 0xc1, 0xeb, 0xc7, 0x5c, 0xb3, 0x46, 0x93, 0x09, 0x9f, 0x9a, 0x95, 0x0c, 0x39, 0x65, 0x91, + 0x6e, 0xca, 0x50, 0xe8, 0x0e, 0x3d, 0x8a, 0x78, 0xd8, 0x71, 0x83, 0x50, 0x6a, 0x49, 0x56, 0x92, + 0x4a, 0x37, 0xae, 0x74, 0x93, 0x4a, 0x6b, 0x23, 0xd3, 0x27, 0x90, 0x2d, 0xd1, 0x10, 0x5c, 0x0d, + 0xac, 0xac, 0x4a, 0x66, 0xb1, 0x39, 0xa8, 0x09, 0xff, 0x50, 0x42, 0xf9, 0x66, 0x66, 0x39, 0xac, + 0x8e, 0x99, 0x16, 0xd2, 0x07, 0xc5, 0xad, 0x86, 0x54, 0x6d, 0xa9, 0x68, 0x9d, 0x29, 0x3e, 0xb8, + 0x04, 0x7d, 0xbb, 0x55, 0xe7, 0x9a, 0x6d, 0xd1, 0x80, 0x79, 0xc2, 0x1f, 0xae, 0xbd, 0xe6, 0x49, + 0x4f, 0x9a, 0x25, 0xed, 0xaf, 0x60, 0x77, 0xc5, 0x93, 0xd2, 0x6b, 0x71, 0xca, 0x02, 0x41, 0x99, + 0xef, 0x4b, 0x6d, 0x24, 0x70, 0x01, 0xa7, 0x84, 0xaf, 0xbf, 0xec, 0xbb, 0x3e, 0x1a, 0xce, 0xde, + 0x17, 0x4a, 0x57, 0xf9, 0x51, 0xc4, 0x95, 0x76, 0x3e, 0x21, 0x6c, 0x4f, 0xaa, 0x50, 0x81, 0xf4, + 0x15, 0x27, 0x07, 0x98, 0xa4, 0xd0, 0x6b, 0x2d, 0xa1, 0xf4, 0x12, 0x5a, 0x45, 0xeb, 0x57, 0xb7, + 0xa9, 0x9b, 0xd5, 0x6c, 0x77, 0xc4, 0x74, 0xef, 0xf2, 0xc9, 0x9f, 0x52, 0xa1, 0xba, 0xc0, 0xce, + 0x1f, 0x38, 0x77, 0xf1, 0xf2, 0x28, 0x07, 0x50, 0x92, 0x45, 0x7c, 0xa5, 0xad, 0xbc, 0x5a, 0x14, + 0xb6, 0x4c, 0x6e, 0xb1, 0x3a, 0xdb, 0x56, 0xde, 0xab, 0xb0, 0xe5, 0x44, 0xd8, 0x1a, 0xa7, 0x02, + 0xf2, 0xd7, 0x78, 0x3e, 0x15, 0x04, 0xd0, 0x1b, 0x39, 0xa0, 0x01, 0x38, 0xed, 0xe3, 0x2c, 0xe3, + 0x45, 0x13, 0xfb, 0x84, 0xeb, 0x17, 0xf0, 0x62, 0xe2, 0x86, 0x1e, 0xe0, 0xa5, 0xd1, 0x23, 0xe0, + 0x79, 0x8a, 0xe7, 0xe2, 0x07, 0x06, 0x28, 0xe5, 0x6c, 0x94, 0xd8, 0x01, 0x28, 0x12, 0xb5, 0x63, + 0x9d, 0xa5, 0x3c, 0xee, 0x8b, 0x9f, 0xf9, 0x87, 0x32, 0x26, 0x10, 0xd0, 0xc9, 0xf4, 0x19, 0x20, + 0xec, 0x63, 0x7c, 0xf6, 0x6c, 0x01, 0x62, 0x2d, 0x1b, 0x22, 0x31, 0x01, 0x8a, 0x62, 0x23, 0xde, + 0xd8, 0xfe, 0x39, 0x83, 0x67, 0x4c, 0x16, 0xf9, 0x8a, 0xf0, 0x5c, 0x4c, 0x4b, 0x76, 0xb2, 0x0d, + 0x27, 0xb4, 0xce, 0xba, 0x97, 0x57, 0x36, 0xb8, 0x93, 0x53, 0xfe, 0xf8, 0xeb, 0xdf, 0x97, 0x4b, + 0xab, 0xc4, 0x36, 0x53, 0x57, 0x19, 0x0c, 0xe0, 0xe8, 0x4c, 0x93, 0x6f, 0x08, 0x17, 0x93, 0xcb, + 0x90, 0x29, 0xd3, 0xce, 0xb7, 0xd7, 0xda, 0xcd, 0xad, 0x03, 0xcc, 0x35, 0x83, 0x79, 0x83, 0x94, + 0xc6, 0x63, 0x26, 0x5d, 0x25, 0x3f, 0x10, 0x5e, 0x18, 0x99, 0x1c, 0xf2, 0x60, 0x8a, 0xdc, 0x49, + 0x63, 0x6e, 0x3d, 0xbc, 0x98, 0x18, 0xc8, 0x6f, 0x1b, 0xf2, 0x32, 0xb9, 0x39, 0x9e, 0x3c, 0x35, + 0x1b, 0x8a, 0x7c, 0x47, 0x78, 0x3e, 0xe5, 0x45, 0x76, 0xf3, 0xa6, 0xc7, 0xd8, 0xf7, 0xf3, 0x0b, + 0x01, 0x79, 0xc7, 0x20, 0x53, 0x52, 0x99, 0x02, 0x99, 0xbe, 0x87, 0xcf, 0xe5, 0xc3, 0xde, 0xf3, + 0x93, 0xae, 0x8d, 0x4e, 0xbb, 0x36, 0xfa, 0xdb, 0xb5, 0xd1, 0xe7, 0x9e, 0x5d, 0x38, 0xed, 0xd9, + 0x85, 0xdf, 0x3d, 0xbb, 0xf0, 0x66, 0xd3, 0x13, 0xba, 0x19, 0xd5, 0xdd, 0x86, 0x6c, 0x0f, 0x5b, + 0x26, 0xff, 0xfc, 0xbb, 0x21, 0x77, 0xdd, 0x09, 0xb8, 0xaa, 0xcf, 0x9a, 0x2f, 0xf8, 0xce, 0xff, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x4f, 0xcd, 0x31, 0xbd, 0xba, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/authority/types/query.pb.gw.go b/x/authority/types/query.pb.gw.go index c726e46b2e..22988faa3b 100644 --- a/x/authority/types/query.pb.gw.go +++ b/x/authority/types/query.pb.gw.go @@ -368,7 +368,7 @@ var ( pattern_Query_ChainInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "authority", "chainInfo"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_AuthorizationList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "authority", "authorizationList"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_AuthorizationList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"zeta-chain", "authority", "authorizations"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_Authorization_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"zeta-chain", "authority", "authorization", "msg_url"}, "", runtime.AssumeColonVerbOpt(false))) ) From 2e0ac9c28f02ca7674362948c9842a1cd1d4f58c Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 6 Jun 2024 09:49:59 -0400 Subject: [PATCH 12/12] fix spacing --- x/authority/keeper/grpc_query_authorization_list.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/x/authority/keeper/grpc_query_authorization_list.go b/x/authority/keeper/grpc_query_authorization_list.go index 5bd8e1acf8..34c3f89708 100644 --- a/x/authority/keeper/grpc_query_authorization_list.go +++ b/x/authority/keeper/grpc_query_authorization_list.go @@ -18,10 +18,12 @@ func (k Keeper) AuthorizationList(c context.Context, return nil, status.Error(codes.InvalidArgument, "invalid request") } ctx := sdk.UnwrapSDKContext(c) + authorizationList, found := k.GetAuthorizationList(ctx) if !found { return nil, status.Error(codes.Internal, types.ErrAuthorizationListNotFound.Error()) } + return &types.QueryAuthorizationListResponse{AuthorizationList: authorizationList}, nil } @@ -32,20 +34,23 @@ func (k Keeper) Authorization(c context.Context, if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } + ctx := sdk.UnwrapSDKContext(c) + err := types.ValidateMsgURL(req.MsgUrl) if err != nil { return nil, err } - ctx := sdk.UnwrapSDKContext(c) authorizationList, found := k.GetAuthorizationList(ctx) if !found { return nil, status.Error(codes.Internal, types.ErrAuthorizationListNotFound.Error()) } + authorization, err := authorizationList.GetAuthorizedPolicy(req.MsgUrl) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } + return &types.QueryAuthorizationResponse{Authorization: types.Authorization{ MsgUrl: req.MsgUrl, AuthorizedPolicy: authorization,