From 5260c300befe4ea8ad3eefc6a72b7bcea7a10989 Mon Sep 17 00:00:00 2001 From: Giancarlos Salas Date: Sun, 5 Mar 2023 21:45:56 -0600 Subject: [PATCH 1/3] Disable timeout-height by default (CLI) --- types/packet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/packet.go b/types/packet.go index 27370aa..f3cf866 100644 --- a/types/packet.go +++ b/types/packet.go @@ -12,7 +12,7 @@ var ( // DefaultRelativePacketTimeoutHeight is the default packet timeout height (in blocks) relative // to the current block height of the counterparty chain provided by the client state. The // timeout is disabled when set to 0. - DefaultRelativePacketTimeoutHeight = "0-1000" + DefaultRelativePacketTimeoutHeight = "0-0" // DefaultRelativePacketTimeoutTimestamp is the default packet timeout timestamp (in nanoseconds) // relative to the current block timestamp of the counterparty chain provided by the client From 6c89ce023228523965f12ec6c4bcfe5e0946a858 Mon Sep 17 00:00:00 2001 From: Dreamer <745124335@qq.com> Date: Tue, 4 Apr 2023 17:05:30 +0800 Subject: [PATCH 2/3] added params function to control whether the module is enabled --- keeper/genesis.go | 2 + keeper/keeper.go | 27 +- keeper/params.go | 31 +++ keeper/relay.go | 6 + .../nft_transfer/v1/genesis.proto | 1 + .../nft_transfer/v1/transfer.proto | 12 + testing/simapp/app.go | 3 +- types/errors.go | 2 + types/genesis.go | 9 +- types/genesis.pb.go | 79 +++++- types/params.go | 65 +++++ types/params_test.go | 12 + types/transfer.pb.go | 239 +++++++++++++++++- 13 files changed, 452 insertions(+), 36 deletions(-) create mode 100644 keeper/params.go create mode 100644 types/params.go create mode 100644 types/params_test.go diff --git a/keeper/genesis.go b/keeper/genesis.go index 3f7198a..4ca9e4f 100644 --- a/keeper/genesis.go +++ b/keeper/genesis.go @@ -26,6 +26,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { panic(fmt.Sprintf("could not claim port capability: %v", err)) } } + k.SetParams(ctx, state.Params) } // ExportGenesis exports ibc nft-transfer module's portID and class trace info into its genesis state. @@ -33,5 +34,6 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { return &types.GenesisState{ PortId: k.GetPort(ctx), Traces: k.GetAllClassTraces(ctx), + Params: k.GetParams(ctx), } } diff --git a/keeper/keeper.go b/keeper/keeper.go index b8802f5..5c8a0ef 100644 --- a/keeper/keeper.go +++ b/keeper/keeper.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" host "github.com/cosmos/ibc-go/v5/modules/core/24-host" @@ -16,8 +17,9 @@ import ( // Keeper defines the IBC non fungible transfer keeper type Keeper struct { - storeKey storetypes.StoreKey - cdc codec.Codec + storeKey storetypes.StoreKey + cdc codec.Codec + paramSpace paramtypes.Subspace ics4Wrapper types.ICS4Wrapper channelKeeper types.ChannelKeeper @@ -29,18 +31,29 @@ type Keeper struct { // NewKeeper creates a new IBC nft-transfer Keeper instance func NewKeeper( - cdc codec.Codec, key storetypes.StoreKey, - ics4Wrapper types.ICS4Wrapper, channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, - authKeeper types.AccountKeeper, nftKeeper types.NFTKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, + cdc codec.Codec, + key storetypes.StoreKey, + paramSpace paramtypes.Subspace, + ics4Wrapper types.ICS4Wrapper, + channelKeeper types.ChannelKeeper, + portKeeper types.PortKeeper, + authKeeper types.AccountKeeper, + nftKeeper types.NFTKeeper, + scopedKeeper capabilitykeeper.ScopedKeeper, ) Keeper { + // set KeyTable if it has not already been set + if !paramSpace.HasKeyTable() { + paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) + } return Keeper{ - cdc: cdc, storeKey: key, + cdc: cdc, + paramSpace: paramSpace, ics4Wrapper: ics4Wrapper, channelKeeper: channelKeeper, portKeeper: portKeeper, - authKeeper: authKeeper, nftKeeper: nftKeeper, + authKeeper: authKeeper, scopedKeeper: scopedKeeper, } } diff --git a/keeper/params.go b/keeper/params.go new file mode 100644 index 0000000..deeec9a --- /dev/null +++ b/keeper/params.go @@ -0,0 +1,31 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/bianjieai/nft-transfer/types" +) + +// GetSendEnabled retrieves the send enabled boolean from the paramstore +func (k Keeper) GetSendEnabled(ctx sdk.Context) bool { + var res bool + k.paramSpace.Get(ctx, types.KeySendEnabled, &res) + return res +} + +// GetReceiveEnabled retrieves the receive enabled boolean from the paramstore +func (k Keeper) GetReceiveEnabled(ctx sdk.Context) bool { + var res bool + k.paramSpace.Get(ctx, types.KeyReceiveEnabled, &res) + return res +} + +// GetParams returns the total set of ibc-transfer parameters. +func (k Keeper) GetParams(ctx sdk.Context) types.Params { + return types.NewParams(k.GetSendEnabled(ctx), k.GetReceiveEnabled(ctx)) +} + +// SetParams sets the total set of ibc-transfer parameters. +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + k.paramSpace.SetParamSet(ctx, ¶ms) +} diff --git a/keeper/relay.go b/keeper/relay.go index c467a19..c9aa8b5 100644 --- a/keeper/relay.go +++ b/keeper/relay.go @@ -54,6 +54,9 @@ func (k Keeper) SendTransfer( timeoutTimestamp uint64, memo string, ) error { + if !k.GetSendEnabled(ctx) { + return types.ErrSendDisabled + } sourceChannelEnd, found := k.channelKeeper.GetChannel(ctx, sourcePort, sourceChannel) if !found { return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", sourcePort, sourceChannel) @@ -127,6 +130,9 @@ func (k Keeper) SendTransfer( // unescrowed and sent to the receiving address. func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data types.NonFungibleTokenPacketData) error { + if !k.GetReceiveEnabled(ctx) { + return types.ErrReceiveDisabled + } // validate packet data upon receiving if err := data.ValidateBasic(); err != nil { diff --git a/proto/ibc/applications/nft_transfer/v1/genesis.proto b/proto/ibc/applications/nft_transfer/v1/genesis.proto index 72ee3bb..9c5d762 100644 --- a/proto/ibc/applications/nft_transfer/v1/genesis.proto +++ b/proto/ibc/applications/nft_transfer/v1/genesis.proto @@ -12,4 +12,5 @@ message GenesisState { string port_id = 1; repeated ClassTrace traces = 2 [ (gogoproto.castrepeated) = "Traces", (gogoproto.nullable) = false ]; + Params params = 3 [(gogoproto.nullable) = false]; } \ No newline at end of file diff --git a/proto/ibc/applications/nft_transfer/v1/transfer.proto b/proto/ibc/applications/nft_transfer/v1/transfer.proto index c678528..68985f8 100644 --- a/proto/ibc/applications/nft_transfer/v1/transfer.proto +++ b/proto/ibc/applications/nft_transfer/v1/transfer.proto @@ -13,3 +13,15 @@ message ClassTrace { // base classID of the relayed non-fungible token. string base_class_id = 2; } + +// Params defines the set of IBC nft-transfer parameters. +// NOTE: To prevent a nft from being transferred, set the +// TransfersEnabled parameter to true. +message Params { + // send_enabled enables or disables all cross-chain nft transfers from this + // chain. + bool send_enabled = 1; + // receive_enabled enables or disables all cross-chain nft transfers to this + // chain. + bool receive_enabled = 2; +} diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 21ed977..0c221f8 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -430,7 +430,7 @@ func NewSimApp( ) app.NFTTransferKeeper = ibcnfttransferkeeper.NewKeeper( - appCodec, keys[ibcnfttransfertypes.StoreKey], + appCodec, keys[ibcnfttransfertypes.StoreKey], app.GetSubspace(ibcnfttransfertypes.ModuleName), app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, mock.Wrap(appCodec, app.NFTKeeper), scopedNFTTransferKeeper, ) @@ -876,6 +876,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(ibchost.ModuleName) paramsKeeper.Subspace(icacontrollertypes.SubModuleName) paramsKeeper.Subspace(icahosttypes.SubModuleName) + paramsKeeper.Subspace(ibcnfttransfertypes.ModuleName) return paramsKeeper } diff --git a/types/errors.go b/types/errors.go index 33cf7cb..029c04c 100644 --- a/types/errors.go +++ b/types/errors.go @@ -14,4 +14,6 @@ var ( ErrInvalidPacket = sdkerrors.Register(ModuleName, 7, "invalid non-fungible token packet") ErrTraceNotFound = sdkerrors.Register(ModuleName, 8, "classTrace trace not found") ErrMarshal = sdkerrors.Register(ModuleName, 9, "failed to marshal token data") + ErrSendDisabled = sdkerrors.Register(ModuleName, 10, "non-fungible token transfers from this chain are disabled") + ErrReceiveDisabled = sdkerrors.Register(ModuleName, 11, "non-fungible token transfers to this chain are disabled") ) diff --git a/types/genesis.go b/types/genesis.go index 399852c..b720541 100644 --- a/types/genesis.go +++ b/types/genesis.go @@ -5,10 +5,11 @@ import ( ) // NewGenesisState creates a new ibc nft-transfer GenesisState instance. -func NewGenesisState(portID string, traces Traces) *GenesisState { +func NewGenesisState(portID string, traces Traces, params Params) *GenesisState { return &GenesisState{ PortId: portID, Traces: traces, + Params: params, } } @@ -17,6 +18,7 @@ func DefaultGenesisState() *GenesisState { return &GenesisState{ PortId: PortID, Traces: Traces{}, + Params: DefaultParams(), } } @@ -26,5 +28,8 @@ func (gs GenesisState) Validate() error { if err := host.PortIdentifierValidator(gs.PortId); err != nil { return err } - return gs.Traces.Validate() + if err := gs.Traces.Validate(); err != nil { + return err + } + return gs.Params.Validate() } diff --git a/types/genesis.pb.go b/types/genesis.pb.go index f76748c..3d08d5c 100644 --- a/types/genesis.pb.go +++ b/types/genesis.pb.go @@ -27,6 +27,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type GenesisState struct { PortId string `protobuf:"bytes,1,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` Traces Traces `protobuf:"bytes,2,rep,name=traces,proto3,castrepeated=Traces" json:"traces"` + Params Params `protobuf:"bytes,3,opt,name=params,proto3" json:"params"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -76,6 +77,13 @@ func (m *GenesisState) GetTraces() Traces { return nil } +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + func init() { proto.RegisterType((*GenesisState)(nil), "ibc.applications.nft_transfer.v1.GenesisState") } @@ -85,23 +93,25 @@ func init() { } var fileDescriptor_1971f5a454018ffc = []byte{ - // 254 bytes of a gzipped FileDescriptorProto + // 286 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0xcb, 0x4c, 0x4a, 0xd6, 0x4f, 0x2c, 0x28, 0xc8, 0xc9, 0x4c, 0x4e, 0x2c, 0xc9, 0xcc, 0xcf, 0x2b, 0xd6, 0xcf, 0x4b, 0x2b, 0x89, 0x2f, 0x29, 0x4a, 0xcc, 0x2b, 0x4e, 0x4b, 0x2d, 0xd2, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0xc8, 0x4c, 0x4a, 0xd6, 0x43, 0x56, 0xaf, 0x87, 0xac, 0x5e, 0xaf, 0xcc, 0x50, 0x4a, 0x9f, 0xa0, 0x89, 0x70, 0xd5, 0x60, - 0x23, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x4c, 0x7d, 0x10, 0x0b, 0x22, 0xaa, 0x54, 0xcb, - 0xc5, 0xe3, 0x0e, 0xb1, 0x39, 0xb8, 0x24, 0xb1, 0x24, 0x55, 0x48, 0x9c, 0x8b, 0xbd, 0x20, 0xbf, - 0xa8, 0x24, 0x3e, 0x33, 0x45, 0x82, 0x51, 0x81, 0x51, 0x83, 0x33, 0x88, 0x0d, 0xc4, 0xf5, 0x4c, - 0x11, 0x0a, 0xe1, 0x62, 0x2b, 0x29, 0x4a, 0x4c, 0x4e, 0x2d, 0x96, 0x60, 0x52, 0x60, 0xd6, 0xe0, - 0x36, 0xd2, 0xd1, 0x23, 0xe4, 0x44, 0x3d, 0xe7, 0x9c, 0xc4, 0xe2, 0xe2, 0x10, 0x90, 0x26, 0x27, - 0xbe, 0x13, 0xf7, 0xe4, 0x19, 0x56, 0xdd, 0x97, 0x67, 0x03, 0x73, 0x8b, 0x83, 0xa0, 0x66, 0x39, - 0x39, 0x9e, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, - 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x7a, 0x7a, 0x66, 0x49, - 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x52, 0x66, 0x62, 0x5e, 0x56, 0x66, 0x6a, 0x62, - 0x26, 0xc8, 0x8f, 0xba, 0x70, 0x3f, 0x96, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x3d, 0x62, - 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x96, 0x8f, 0x9f, 0x52, 0x63, 0x01, 0x00, 0x00, + 0x23, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x4c, 0x7d, 0x10, 0x0b, 0x22, 0xaa, 0x74, 0x94, + 0x91, 0x8b, 0xc7, 0x1d, 0x62, 0x75, 0x70, 0x49, 0x62, 0x49, 0xaa, 0x90, 0x38, 0x17, 0x7b, 0x41, + 0x7e, 0x51, 0x49, 0x7c, 0x66, 0x8a, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x1b, 0x88, 0xeb, + 0x99, 0x22, 0x14, 0xc2, 0xc5, 0x56, 0x52, 0x94, 0x98, 0x9c, 0x5a, 0x2c, 0xc1, 0xa4, 0xc0, 0xac, + 0xc1, 0x6d, 0xa4, 0xa3, 0x47, 0xc8, 0x8d, 0x7a, 0xce, 0x39, 0x89, 0xc5, 0xc5, 0x21, 0x20, 0x4d, + 0x4e, 0x7c, 0x27, 0xee, 0xc9, 0x33, 0xac, 0xba, 0x2f, 0xcf, 0x06, 0xe6, 0x16, 0x07, 0x41, 0xcd, + 0x12, 0x72, 0xe3, 0x62, 0x2b, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0x96, 0x60, 0x56, 0x60, 0xd4, 0xe0, + 0x36, 0xd2, 0x20, 0x6c, 0x6a, 0x00, 0x58, 0xbd, 0x13, 0x0b, 0xc8, 0xc4, 0x20, 0xa8, 0x6e, 0x27, + 0xc7, 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, 0x52, 0x4f, 0xcf, 0x2c, 0xc9, + 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xca, 0x4c, 0xcc, 0xcb, 0xca, 0x4c, 0x4d, 0xcc, + 0x04, 0x05, 0x96, 0x2e, 0x3c, 0xb0, 0x4a, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0x21, 0x62, + 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xe0, 0xd8, 0xff, 0xd7, 0xac, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -124,6 +134,16 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a if len(m.Traces) > 0 { for iNdEx := len(m.Traces) - 1; iNdEx >= 0; iNdEx-- { { @@ -175,6 +195,8 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) return n } @@ -279,6 +301,39 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/types/params.go b/types/params.go new file mode 100644 index 0000000..4ecdfab --- /dev/null +++ b/types/params.go @@ -0,0 +1,65 @@ +package types + +import ( + "fmt" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +const ( + // DefaultSendEnabled enabled + DefaultSendEnabled = true + // DefaultReceiveEnabled enabled + DefaultReceiveEnabled = true +) + +var ( + // KeySendEnabled is store's key for SendEnabled Params + KeySendEnabled = []byte("SendEnabled") + // KeyReceiveEnabled is store's key for ReceiveEnabled Params + KeyReceiveEnabled = []byte("ReceiveEnabled") +) + +// ParamKeyTable type declaration for parameters +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// NewParams creates a new parameter configuration for the ibc transfer module +func NewParams(enableSend, enableReceive bool) Params { + return Params{ + SendEnabled: enableSend, + ReceiveEnabled: enableReceive, + } +} + +// DefaultParams is the default parameter configuration for the ibc-transfer module +func DefaultParams() Params { + return NewParams(DefaultSendEnabled, DefaultReceiveEnabled) +} + +// Validate all ibc-transfer module parameters +func (p Params) Validate() error { + if err := validateEnabled(p.SendEnabled); err != nil { + return err + } + + return validateEnabled(p.ReceiveEnabled) +} + +// ParamSetPairs implements params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeySendEnabled, p.SendEnabled, validateEnabled), + paramtypes.NewParamSetPair(KeyReceiveEnabled, p.ReceiveEnabled, validateEnabled), + } +} + +func validateEnabled(i interface{}) error { + _, ok := i.(bool) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + return nil +} diff --git a/types/params_test.go b/types/params_test.go new file mode 100644 index 0000000..825efb8 --- /dev/null +++ b/types/params_test.go @@ -0,0 +1,12 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestValidateParams(t *testing.T) { + require.NoError(t, DefaultParams().Validate()) + require.NoError(t, NewParams(true, false).Validate()) +} diff --git a/types/transfer.pb.go b/types/transfer.pb.go index f894f7b..5cf70a8 100644 --- a/types/transfer.pb.go +++ b/types/transfer.pb.go @@ -79,8 +79,68 @@ func (m *ClassTrace) GetBaseClassId() string { return "" } +// Params defines the set of IBC nft-transfer parameters. +// NOTE: To prevent a nft from being transferred, set the +// TransfersEnabled parameter to true. +type Params struct { + // send_enabled enables or disables all cross-chain nft transfers from this + // chain. + SendEnabled bool `protobuf:"varint,1,opt,name=send_enabled,json=sendEnabled,proto3" json:"send_enabled,omitempty"` + // receive_enabled enables or disables all cross-chain nft transfers to this + // chain. + ReceiveEnabled bool `protobuf:"varint,2,opt,name=receive_enabled,json=receiveEnabled,proto3" json:"receive_enabled,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_fbbec0a5a50746a6, []int{1} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetSendEnabled() bool { + if m != nil { + return m.SendEnabled + } + return false +} + +func (m *Params) GetReceiveEnabled() bool { + if m != nil { + return m.ReceiveEnabled + } + return false +} + func init() { proto.RegisterType((*ClassTrace)(nil), "ibc.applications.nft_transfer.v1.ClassTrace") + proto.RegisterType((*Params)(nil), "ibc.applications.nft_transfer.v1.Params") } func init() { @@ -88,20 +148,23 @@ func init() { } var fileDescriptor_fbbec0a5a50746a6 = []byte{ - // 203 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0xcf, 0x4c, 0x4a, 0xd6, - 0x4f, 0x2c, 0x28, 0xc8, 0xc9, 0x4c, 0x4e, 0x2c, 0xc9, 0xcc, 0xcf, 0x2b, 0xd6, 0xcf, 0x4b, 0x2b, - 0x89, 0x2f, 0x29, 0x4a, 0xcc, 0x2b, 0x4e, 0x4b, 0x2d, 0xd2, 0x2f, 0x33, 0xd4, 0x87, 0xb1, 0xf5, - 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x14, 0x32, 0x93, 0x92, 0xf5, 0x90, 0x35, 0xe8, 0x21, 0x6b, - 0xd0, 0x2b, 0x33, 0x54, 0x72, 0xe1, 0xe2, 0x72, 0xce, 0x49, 0x2c, 0x2e, 0x0e, 0x29, 0x4a, 0x4c, - 0x4e, 0x15, 0x12, 0xe2, 0x62, 0x29, 0x48, 0x2c, 0xc9, 0x90, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, - 0x02, 0xb3, 0x85, 0x94, 0xb8, 0x78, 0x93, 0x12, 0x8b, 0x53, 0xe3, 0x93, 0x41, 0xca, 0xe2, 0x33, - 0x53, 0x24, 0x98, 0xc0, 0x92, 0xdc, 0x20, 0x41, 0xb0, 0x56, 0xcf, 0x14, 0x27, 0xc7, 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, 0x52, 0x4f, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, - 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xca, 0x4c, 0xcc, 0xcb, 0xca, 0x4c, 0x4d, 0xcc, 0x04, 0x39, 0x5b, - 0x17, 0xee, 0xec, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0x8b, 0x8d, 0x01, 0x01, 0x00, - 0x00, 0xff, 0xff, 0xcb, 0xe3, 0xc1, 0x45, 0xe4, 0x00, 0x00, 0x00, + // 254 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xbd, 0x4e, 0xc3, 0x30, + 0x14, 0x85, 0x9b, 0x0a, 0x55, 0xe0, 0xf2, 0x23, 0x79, 0xea, 0x64, 0x95, 0x2c, 0x65, 0xc1, 0x56, + 0xc5, 0x13, 0xf0, 0x37, 0xb0, 0xa1, 0xaa, 0x13, 0x4b, 0x74, 0xed, 0xdc, 0xd2, 0x8b, 0x52, 0xc7, + 0xb2, 0x4d, 0x24, 0xde, 0x82, 0xc7, 0x62, 0xec, 0xc8, 0x88, 0x92, 0x17, 0x41, 0x31, 0xa5, 0xea, + 0x76, 0xf4, 0xdd, 0xef, 0xdc, 0xe1, 0x30, 0x45, 0xda, 0x28, 0x70, 0xae, 0x22, 0x03, 0x91, 0x6a, + 0x1b, 0x94, 0x5d, 0xc5, 0x22, 0x7a, 0xb0, 0x61, 0x85, 0x5e, 0x35, 0x73, 0xf5, 0x9f, 0xa5, 0xf3, + 0x75, 0xac, 0xf9, 0x94, 0xb4, 0x91, 0x87, 0x05, 0x79, 0x58, 0x90, 0xcd, 0x3c, 0x7f, 0x60, 0xec, + 0xbe, 0x82, 0x10, 0x96, 0x1e, 0x0c, 0x72, 0xce, 0x8e, 0x1c, 0xc4, 0xf5, 0x24, 0x9b, 0x66, 0x57, + 0x27, 0x8b, 0x94, 0x79, 0xce, 0xce, 0x34, 0x04, 0x2c, 0x4c, 0xaf, 0x15, 0x54, 0x4e, 0x86, 0xe9, + 0x38, 0xee, 0x61, 0xaa, 0x3e, 0x95, 0xf9, 0x92, 0x8d, 0x9e, 0xc1, 0xc3, 0x26, 0xf0, 0x4b, 0x76, + 0x1a, 0xd0, 0x96, 0x05, 0x5a, 0xd0, 0x15, 0x96, 0xe9, 0xd3, 0xf1, 0x62, 0xdc, 0xb3, 0xc7, 0x3f, + 0xc4, 0x67, 0xec, 0xc2, 0xa3, 0x41, 0x6a, 0x70, 0x6f, 0x0d, 0x93, 0x75, 0xbe, 0xc3, 0x3b, 0xf1, + 0xee, 0xf6, 0xab, 0x15, 0xd9, 0xb6, 0x15, 0xd9, 0x4f, 0x2b, 0xb2, 0xcf, 0x4e, 0x0c, 0xb6, 0x9d, + 0x18, 0x7c, 0x77, 0x62, 0xf0, 0x32, 0x7b, 0xa5, 0xb8, 0x7e, 0xd7, 0xd2, 0xd4, 0x1b, 0xa5, 0x09, + 0xec, 0x1b, 0x21, 0x50, 0x3f, 0xc6, 0xf5, 0x7e, 0x8c, 0xf8, 0xe1, 0x30, 0xe8, 0x51, 0xda, 0xe1, + 0xe6, 0x37, 0x00, 0x00, 0xff, 0xff, 0xaa, 0xc1, 0x44, 0x01, 0x3a, 0x01, 0x00, 0x00, } func (m *ClassTrace) Marshal() (dAtA []byte, err error) { @@ -141,6 +204,49 @@ func (m *ClassTrace) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ReceiveEnabled { + i-- + if m.ReceiveEnabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if m.SendEnabled { + i-- + if m.SendEnabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func encodeVarintTransfer(dAtA []byte, offset int, v uint64) int { offset -= sovTransfer(v) base := offset @@ -169,6 +275,21 @@ func (m *ClassTrace) Size() (n int) { return n } +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SendEnabled { + n += 2 + } + if m.ReceiveEnabled { + n += 2 + } + return n +} + func sovTransfer(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -289,6 +410,96 @@ func (m *ClassTrace) Unmarshal(dAtA []byte) error { } return nil } +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTransfer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SendEnabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTransfer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.SendEnabled = bool(v != 0) + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ReceiveEnabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTransfer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ReceiveEnabled = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipTransfer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTransfer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTransfer(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From ae5ffed3778b09cb5c74f30bb68eb2b0f07122c9 Mon Sep 17 00:00:00 2001 From: Dreamer <745124335@qq.com> Date: Thu, 6 Apr 2023 11:37:20 +0800 Subject: [PATCH 3/3] update comment --- proto/ibc/applications/nft_transfer/v1/transfer.proto | 2 +- types/transfer.pb.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/proto/ibc/applications/nft_transfer/v1/transfer.proto b/proto/ibc/applications/nft_transfer/v1/transfer.proto index 68985f8..e89c45c 100644 --- a/proto/ibc/applications/nft_transfer/v1/transfer.proto +++ b/proto/ibc/applications/nft_transfer/v1/transfer.proto @@ -16,7 +16,7 @@ message ClassTrace { // Params defines the set of IBC nft-transfer parameters. // NOTE: To prevent a nft from being transferred, set the -// TransfersEnabled parameter to true. +// TransfersEnabled parameter to false. message Params { // send_enabled enables or disables all cross-chain nft transfers from this // chain. diff --git a/types/transfer.pb.go b/types/transfer.pb.go index 5cf70a8..b4db57d 100644 --- a/types/transfer.pb.go +++ b/types/transfer.pb.go @@ -81,7 +81,7 @@ func (m *ClassTrace) GetBaseClassId() string { // Params defines the set of IBC nft-transfer parameters. // NOTE: To prevent a nft from being transferred, set the -// TransfersEnabled parameter to true. +// TransfersEnabled parameter to false. type Params struct { // send_enabled enables or disables all cross-chain nft transfers from this // chain.