From 5a8918cce7f4e85a65794cfb2485b13bba620f04 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 8 Jun 2022 15:24:28 +0200 Subject: [PATCH 01/15] feat: app wiring setup for tx's and ante/post handlers --- api/cosmos/tx/module/v1/module.pulsar.go | 501 +++++++++++++++++++++++ proto/cosmos/tx/module/v1/module.proto | 12 + simapp/app.go | 6 + simapp/app.yaml | 4 + types/tx/module/module.go | 73 ++++ 5 files changed, 596 insertions(+) create mode 100644 api/cosmos/tx/module/v1/module.pulsar.go create mode 100644 proto/cosmos/tx/module/v1/module.proto create mode 100644 types/tx/module/module.go diff --git a/api/cosmos/tx/module/v1/module.pulsar.go b/api/cosmos/tx/module/v1/module.pulsar.go new file mode 100644 index 000000000000..476da7b06f85 --- /dev/null +++ b/api/cosmos/tx/module/v1/module.pulsar.go @@ -0,0 +1,501 @@ +// Code generated by protoc-gen-go-pulsar. DO NOT EDIT. +package modulev1 + +import ( + _ "cosmossdk.io/api/cosmos/app/v1alpha1" + fmt "fmt" + runtime "github.com/cosmos/cosmos-proto/runtime" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoiface "google.golang.org/protobuf/runtime/protoiface" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + reflect "reflect" + sync "sync" +) + +var ( + md_Module protoreflect.MessageDescriptor +) + +func init() { + file_cosmos_tx_module_v1_module_proto_init() + md_Module = File_cosmos_tx_module_v1_module_proto.Messages().ByName("Module") +} + +var _ protoreflect.Message = (*fastReflection_Module)(nil) + +type fastReflection_Module Module + +func (x *Module) ProtoReflect() protoreflect.Message { + return (*fastReflection_Module)(x) +} + +func (x *Module) slowProtoReflect() protoreflect.Message { + mi := &file_cosmos_tx_module_v1_module_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_Module_messageType fastReflection_Module_messageType +var _ protoreflect.MessageType = fastReflection_Module_messageType{} + +type fastReflection_Module_messageType struct{} + +func (x fastReflection_Module_messageType) Zero() protoreflect.Message { + return (*fastReflection_Module)(nil) +} +func (x fastReflection_Module_messageType) New() protoreflect.Message { + return new(fastReflection_Module) +} +func (x fastReflection_Module_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_Module +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_Module) Descriptor() protoreflect.MessageDescriptor { + return md_Module +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_Module) Type() protoreflect.MessageType { + return _fastReflection_Module_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_Module) New() protoreflect.Message { + return new(fastReflection_Module) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_Module) Interface() protoreflect.ProtoMessage { + return (*Module)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_Module) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_Module) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.tx.module.v1.Module does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Module) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.tx.module.v1.Module does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_Module) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.tx.module.v1.Module does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Module) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.tx.module.v1.Module does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Module) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.tx.module.v1.Module does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_Module) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) + } + panic(fmt.Errorf("message cosmos.tx.module.v1.Module does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_Module) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in cosmos.tx.module.v1.Module", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_Module) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_Module) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_Module) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*Module) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*Module) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*Module) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, 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 protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: Module: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: Module: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.0 +// protoc (unknown) +// source: cosmos/tx/module/v1/module.proto + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// Module is the config object of the tx module. +type Module struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *Module) Reset() { + *x = Module{} + if protoimpl.UnsafeEnabled { + mi := &file_cosmos_tx_module_v1_module_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Module) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Module) ProtoMessage() {} + +// Deprecated: Use Module.ProtoReflect.Descriptor instead. +func (*Module) Descriptor() ([]byte, []int) { + return file_cosmos_tx_module_v1_module_proto_rawDescGZIP(), []int{0} +} + +var File_cosmos_tx_module_v1_module_proto protoreflect.FileDescriptor + +var file_cosmos_tx_module_v1_module_proto_rawDesc = []byte{ + 0x0a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x74, 0x78, 0x2f, 0x6d, 0x6f, 0x64, 0x75, + 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x12, 0x13, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x74, 0x78, 0x2e, 0x6d, 0x6f, + 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, + 0x61, 0x70, 0x70, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x6d, 0x6f, 0x64, + 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x37, 0x0a, 0x06, 0x4d, 0x6f, 0x64, + 0x75, 0x6c, 0x65, 0x3a, 0x2d, 0xba, 0xc0, 0x96, 0xda, 0x01, 0x27, 0x0a, 0x25, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, + 0x74, 0x78, 0x42, 0xc4, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2e, 0x74, 0x78, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0b, + 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2d, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x74, 0x78, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, + 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, + 0x54, 0x4d, 0xaa, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x54, 0x78, 0x2e, 0x4d, + 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, + 0x1f, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, + 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, + 0xea, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x54, 0x78, 0x3a, 0x3a, 0x4d, + 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, +} + +var ( + file_cosmos_tx_module_v1_module_proto_rawDescOnce sync.Once + file_cosmos_tx_module_v1_module_proto_rawDescData = file_cosmos_tx_module_v1_module_proto_rawDesc +) + +func file_cosmos_tx_module_v1_module_proto_rawDescGZIP() []byte { + file_cosmos_tx_module_v1_module_proto_rawDescOnce.Do(func() { + file_cosmos_tx_module_v1_module_proto_rawDescData = protoimpl.X.CompressGZIP(file_cosmos_tx_module_v1_module_proto_rawDescData) + }) + return file_cosmos_tx_module_v1_module_proto_rawDescData +} + +var file_cosmos_tx_module_v1_module_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_cosmos_tx_module_v1_module_proto_goTypes = []interface{}{ + (*Module)(nil), // 0: cosmos.tx.module.v1.Module +} +var file_cosmos_tx_module_v1_module_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_cosmos_tx_module_v1_module_proto_init() } +func file_cosmos_tx_module_v1_module_proto_init() { + if File_cosmos_tx_module_v1_module_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_cosmos_tx_module_v1_module_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Module); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_cosmos_tx_module_v1_module_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_cosmos_tx_module_v1_module_proto_goTypes, + DependencyIndexes: file_cosmos_tx_module_v1_module_proto_depIdxs, + MessageInfos: file_cosmos_tx_module_v1_module_proto_msgTypes, + }.Build() + File_cosmos_tx_module_v1_module_proto = out.File + file_cosmos_tx_module_v1_module_proto_rawDesc = nil + file_cosmos_tx_module_v1_module_proto_goTypes = nil + file_cosmos_tx_module_v1_module_proto_depIdxs = nil +} diff --git a/proto/cosmos/tx/module/v1/module.proto b/proto/cosmos/tx/module/v1/module.proto new file mode 100644 index 000000000000..c098ce672cbc --- /dev/null +++ b/proto/cosmos/tx/module/v1/module.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package cosmos.tx.module.v1; + +import "cosmos/app/v1alpha1/module.proto"; + +// Module is the config object of the tx module. +message Module { + option (cosmos.app.v1alpha1.module) = { + go_import: "github.com/cosmos/cosmos-sdk/types/tx" + }; +} \ No newline at end of file diff --git a/simapp/app.go b/simapp/app.go index ec072d87eca2..e97fdde1e330 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -33,6 +33,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/testdata_pulsar" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + tx "github.com/cosmos/cosmos-sdk/types/tx/module" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" @@ -214,6 +215,10 @@ func NewSimApp( var appBuilder *runtime.AppBuilder var msgServiceRouter *baseapp.MsgServiceRouter + // set custom tx config that will be injected in modules + txModuleOptions := make([]tx.TxModuleOption, 0) + txModuleOptions = append(txModuleOptions, tx.SetCustomTxConfig(encodingConfig.TxConfig)) + if err := depinject.Inject(AppConfig, &appBuilder, &app.ParamsKeeper, @@ -227,6 +232,7 @@ func NewSimApp( &app.StakingKeeper, &app.NFTKeeper, &msgServiceRouter, + &txModuleOptions, ); err != nil { panic(err) } diff --git a/simapp/app.yaml b/simapp/app.yaml index cfb38309cddd..7dca265ea60e 100644 --- a/simapp/app.yaml +++ b/simapp/app.yaml @@ -79,6 +79,10 @@ modules: config: "@type": cosmos.params.module.v1.Module + - name: tx + config: + "@type": cosmos.tx.module.v1.Module + - name: feegrant config: "@type": cosmos.feegrant.module.v1.Module diff --git a/types/tx/module/module.go b/types/tx/module/module.go new file mode 100644 index 000000000000..e44a78a8fc59 --- /dev/null +++ b/types/tx/module/module.go @@ -0,0 +1,73 @@ +package tx + +import ( + "cosmossdk.io/core/appmodule" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/depinject" + + modulev1 "cosmossdk.io/api/cosmos/tx/module/v1" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var DefaultTxModuleConfig = TxModuleConfig{ + // TODO set good defaults +} + +type TxModuleConfig struct { + TxConfig client.TxConfig + AnteHandler sdk.AnteHandler + PostHandler sdk.AnteHandler +} + +type TxModuleOption func(*TxModuleConfig) + +func SetCustomTxConfig(txConfig client.TxConfig) TxModuleOption { + return func(cfg *TxModuleConfig) { + cfg.TxConfig = txConfig + } +} + +func SetCustomAnteHandler(anteHandler sdk.AnteHandler) TxModuleOption { + return func(cfg *TxModuleConfig) { + cfg.AnteHandler = anteHandler + } +} + +func SetCustomPostHandler(PostHandler sdk.AnteHandler) TxModuleOption { + return func(cfg *TxModuleConfig) { + cfg.PostHandler = PostHandler + } +} + +// +// New App Wiring Setup +// + +func init() { + appmodule.Register(&modulev1.Module{}, + appmodule.Provide(provideModule), + ) +} + +type txInputs struct { + depinject.In + + options []TxModuleOption +} + +type txOutputs struct { + depinject.Out + + TxConfig client.TxConfig + AnteHandler sdk.AnteHandler + PostHandler sdk.AnteHandler +} + +func provideModule(in txInputs) txOutputs { + cfg := DefaultTxModuleConfig + for _, opt := range in.options { + opt(&cfg) + } + + return txOutputs{TxConfig: cfg.TxConfig, AnteHandler: cfg.AnteHandler, PostHandler: cfg.PostHandler} +} From f4d810240ac0a7aeec00cbf9fa3daf5b3d7de4b5 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 9 Jun 2022 01:38:25 +0200 Subject: [PATCH 02/15] updates --- api/cosmos/tx/module/v1/module.pulsar.go | 168 ++++++++++++++++++++--- core/appmodule/doc.go | 2 +- core/appmodule/option.go | 2 +- proto/cosmos/tx/module/v1/module.proto | 8 +- runtime/builder.go | 2 +- simapp/app.go | 61 +------- simapp/app.yaml | 2 + types/tx/module/module.go | 113 +++++++++------ 8 files changed, 235 insertions(+), 123 deletions(-) diff --git a/api/cosmos/tx/module/v1/module.pulsar.go b/api/cosmos/tx/module/v1/module.pulsar.go index 476da7b06f85..cbc8e27ce009 100644 --- a/api/cosmos/tx/module/v1/module.pulsar.go +++ b/api/cosmos/tx/module/v1/module.pulsar.go @@ -14,12 +14,16 @@ import ( ) var ( - md_Module protoreflect.MessageDescriptor + md_Module protoreflect.MessageDescriptor + fd_Module_enable_ante_handler protoreflect.FieldDescriptor + fd_Module_enable_post_handler protoreflect.FieldDescriptor ) func init() { file_cosmos_tx_module_v1_module_proto_init() md_Module = File_cosmos_tx_module_v1_module_proto.Messages().ByName("Module") + fd_Module_enable_ante_handler = md_Module.Fields().ByName("enable_ante_handler") + fd_Module_enable_post_handler = md_Module.Fields().ByName("enable_post_handler") } var _ protoreflect.Message = (*fastReflection_Module)(nil) @@ -87,6 +91,18 @@ func (x *fastReflection_Module) Interface() protoreflect.ProtoMessage { // While iterating, mutating operations may only be performed // on the current field descriptor. func (x *fastReflection_Module) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.EnableAnteHandler != false { + value := protoreflect.ValueOfBool(x.EnableAnteHandler) + if !f(fd_Module_enable_ante_handler, value) { + return + } + } + if x.EnablePostHandler != false { + value := protoreflect.ValueOfBool(x.EnablePostHandler) + if !f(fd_Module_enable_post_handler, value) { + return + } + } } // Has reports whether a field is populated. @@ -102,6 +118,10 @@ func (x *fastReflection_Module) Range(f func(protoreflect.FieldDescriptor, proto // a repeated field is populated if it is non-empty. func (x *fastReflection_Module) Has(fd protoreflect.FieldDescriptor) bool { switch fd.FullName() { + case "cosmos.tx.module.v1.Module.enable_ante_handler": + return x.EnableAnteHandler != false + case "cosmos.tx.module.v1.Module.enable_post_handler": + return x.EnablePostHandler != false default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) @@ -118,6 +138,10 @@ func (x *fastReflection_Module) Has(fd protoreflect.FieldDescriptor) bool { // Clear is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Module) Clear(fd protoreflect.FieldDescriptor) { switch fd.FullName() { + case "cosmos.tx.module.v1.Module.enable_ante_handler": + x.EnableAnteHandler = false + case "cosmos.tx.module.v1.Module.enable_post_handler": + x.EnablePostHandler = false default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) @@ -134,6 +158,12 @@ func (x *fastReflection_Module) Clear(fd protoreflect.FieldDescriptor) { // of the value; to obtain a mutable reference, use Mutable. func (x *fastReflection_Module) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { switch descriptor.FullName() { + case "cosmos.tx.module.v1.Module.enable_ante_handler": + value := x.EnableAnteHandler + return protoreflect.ValueOfBool(value) + case "cosmos.tx.module.v1.Module.enable_post_handler": + value := x.EnablePostHandler + return protoreflect.ValueOfBool(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) @@ -154,6 +184,10 @@ func (x *fastReflection_Module) Get(descriptor protoreflect.FieldDescriptor) pro // Set is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Module) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { switch fd.FullName() { + case "cosmos.tx.module.v1.Module.enable_ante_handler": + x.EnableAnteHandler = value.Bool() + case "cosmos.tx.module.v1.Module.enable_post_handler": + x.EnablePostHandler = value.Bool() default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) @@ -174,6 +208,10 @@ func (x *fastReflection_Module) Set(fd protoreflect.FieldDescriptor, value proto // Mutable is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Module) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { switch fd.FullName() { + case "cosmos.tx.module.v1.Module.enable_ante_handler": + panic(fmt.Errorf("field enable_ante_handler of message cosmos.tx.module.v1.Module is not mutable")) + case "cosmos.tx.module.v1.Module.enable_post_handler": + panic(fmt.Errorf("field enable_post_handler of message cosmos.tx.module.v1.Module is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) @@ -187,6 +225,10 @@ func (x *fastReflection_Module) Mutable(fd protoreflect.FieldDescriptor) protore // For lists, maps, and messages, this returns a new, empty, mutable value. func (x *fastReflection_Module) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { switch fd.FullName() { + case "cosmos.tx.module.v1.Module.enable_ante_handler": + return protoreflect.ValueOfBool(false) + case "cosmos.tx.module.v1.Module.enable_post_handler": + return protoreflect.ValueOfBool(false) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) @@ -256,6 +298,12 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { var n int var l int _ = l + if x.EnableAnteHandler { + n += 2 + } + if x.EnablePostHandler { + n += 2 + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -285,6 +333,26 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if x.EnablePostHandler { + i-- + if x.EnablePostHandler { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if x.EnableAnteHandler { + i-- + if x.EnableAnteHandler { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } if input.Buf != nil { input.Buf = append(input.Buf, dAtA...) } else { @@ -334,6 +402,46 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: Module: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field EnableAnteHandler", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.EnableAnteHandler = bool(v != 0) + case 2: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field EnablePostHandler", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.EnablePostHandler = bool(v != 0) default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -387,6 +495,11 @@ type Module struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + + // enable_ante_handler defines whether the ante handler are set in the app. + EnableAnteHandler bool `protobuf:"varint,1,opt,name=enable_ante_handler,json=enableAnteHandler,proto3" json:"enable_ante_handler,omitempty"` + // enable_post_handler defines whether the post handler are set in the app. + EnablePostHandler bool `protobuf:"varint,2,opt,name=enable_post_handler,json=enablePostHandler,proto3" json:"enable_post_handler,omitempty"` } func (x *Module) Reset() { @@ -409,6 +522,20 @@ func (*Module) Descriptor() ([]byte, []int) { return file_cosmos_tx_module_v1_module_proto_rawDescGZIP(), []int{0} } +func (x *Module) GetEnableAnteHandler() bool { + if x != nil { + return x.EnableAnteHandler + } + return false +} + +func (x *Module) GetEnablePostHandler() bool { + if x != nil { + return x.EnablePostHandler + } + return false +} + var File_cosmos_tx_module_v1_module_proto protoreflect.FileDescriptor var file_cosmos_tx_module_v1_module_proto_rawDesc = []byte{ @@ -417,24 +544,27 @@ var file_cosmos_tx_module_v1_module_proto_rawDesc = []byte{ 0x74, 0x6f, 0x12, 0x13, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x74, 0x78, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x6d, 0x6f, 0x64, - 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x37, 0x0a, 0x06, 0x4d, 0x6f, 0x64, - 0x75, 0x6c, 0x65, 0x3a, 0x2d, 0xba, 0xc0, 0x96, 0xda, 0x01, 0x27, 0x0a, 0x25, 0x67, 0x69, 0x74, - 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, - 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, - 0x74, 0x78, 0x42, 0xc4, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x2e, 0x74, 0x78, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0b, - 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2d, 0x63, - 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, - 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x74, 0x78, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, - 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, - 0x54, 0x4d, 0xaa, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x54, 0x78, 0x2e, 0x4d, - 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, - 0x1f, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, - 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, - 0xea, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x54, 0x78, 0x3a, 0x3a, 0x4d, - 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x68, 0x0a, 0x06, 0x4d, 0x6f, 0x64, + 0x75, 0x6c, 0x65, 0x12, 0x2e, 0x0a, 0x13, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x61, 0x6e, + 0x74, 0x65, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x11, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x41, 0x6e, 0x74, 0x65, 0x48, 0x61, 0x6e, 0x64, + 0x6c, 0x65, 0x72, 0x12, 0x2e, 0x0a, 0x13, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x70, 0x6f, + 0x73, 0x74, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x11, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x50, 0x6f, 0x73, 0x74, 0x48, 0x61, 0x6e, 0x64, + 0x6c, 0x65, 0x72, 0x42, 0xc4, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x2e, 0x74, 0x78, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x42, + 0x0b, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2d, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, + 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x74, 0x78, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, + 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, + 0x43, 0x54, 0x4d, 0xaa, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x54, 0x78, 0x2e, + 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, + 0x02, 0x1f, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, + 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, + 0x61, 0xea, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x54, 0x78, 0x3a, 0x3a, + 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( diff --git a/core/appmodule/doc.go b/core/appmodule/doc.go index fd981d484827..979f1867cd99 100644 --- a/core/appmodule/doc.go +++ b/core/appmodule/doc.go @@ -1,5 +1,5 @@ // Package appmodule defines the functionality for registering Cosmos SDK app -// modules that are assembled using the github.com/cosmos/cosmos-sdk/depinject v1.0.0-alpha.3 +// modules that are assembled using the pkg.go.dev/github.com/cosmos/cosmos-sdk/depinject // dependency injection system and the declarative app configuration format // handled by the appconfig package. package appmodule diff --git a/core/appmodule/option.go b/core/appmodule/option.go index 991415822079..cb1fc034e3a2 100644 --- a/core/appmodule/option.go +++ b/core/appmodule/option.go @@ -17,7 +17,7 @@ func (f funcOption) apply(initializer *internal.ModuleInitializer) error { } // Provide registers providers with the dependency injection system that will be -// run within the module scope. See github.com/cosmos/cosmos-sdk/depinject v1.0.0-alpha.3 for +// run within the module scope. See pkg.go.dev/github.com/cosmos/cosmos-sdk/depinject for // documentation on the dependency injection system. func Provide(providers ...interface{}) Option { return funcOption(func(initializer *internal.ModuleInitializer) error { diff --git a/proto/cosmos/tx/module/v1/module.proto b/proto/cosmos/tx/module/v1/module.proto index c098ce672cbc..2245436084ba 100644 --- a/proto/cosmos/tx/module/v1/module.proto +++ b/proto/cosmos/tx/module/v1/module.proto @@ -6,7 +6,9 @@ import "cosmos/app/v1alpha1/module.proto"; // Module is the config object of the tx module. message Module { - option (cosmos.app.v1alpha1.module) = { - go_import: "github.com/cosmos/cosmos-sdk/types/tx" - }; + // enable_ante_handler defines whether the ante handler are set in the app. + bool enable_ante_handler = 1; + + // enable_post_handler defines whether the post handler are set in the app. + bool enable_post_handler = 2; } \ No newline at end of file diff --git a/runtime/builder.go b/runtime/builder.go index 4103427e99b8..d5032a0ca4e3 100644 --- a/runtime/builder.go +++ b/runtime/builder.go @@ -35,7 +35,7 @@ func (a *AppBuilder) Build( for _, option := range a.app.baseAppOptions { baseAppOptions = append(baseAppOptions, option) } - // TODO: when the auth module is configured, fill-in txDecoder + bApp := baseapp.NewBaseApp(a.app.config.AppName, logger, db, nil, baseAppOptions...) bApp.SetMsgServiceRouter(msgServiceRouter) bApp.SetCommitMultiStoreTracer(traceStore) diff --git a/simapp/app.go b/simapp/app.go index e97fdde1e330..61546ef1a5ef 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -23,7 +23,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" - "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -33,11 +32,8 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/testdata_pulsar" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - tx "github.com/cosmos/cosmos-sdk/types/tx/module" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/auth/ante" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - "github.com/cosmos/cosmos-sdk/x/auth/posthandler" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" @@ -214,10 +210,7 @@ func NewSimApp( var appBuilder *runtime.AppBuilder var msgServiceRouter *baseapp.MsgServiceRouter - - // set custom tx config that will be injected in modules - txModuleOptions := make([]tx.TxModuleOption, 0) - txModuleOptions = append(txModuleOptions, tx.SetCustomTxConfig(encodingConfig.TxConfig)) + var txOptions func(*baseapp.BaseApp) if err := depinject.Inject(AppConfig, &appBuilder, @@ -232,12 +225,12 @@ func NewSimApp( &app.StakingKeeper, &app.NFTKeeper, &msgServiceRouter, - &txModuleOptions, + &txOptions, ); err != nil { panic(err) } - app.App = appBuilder.Build(logger, db, traceStore, msgServiceRouter, baseAppOptions...) + app.App = appBuilder.Build(logger, db, traceStore, msgServiceRouter, append(baseAppOptions, txOptions)...) app.keys = sdk.NewKVStoreKeys( minttypes.StoreKey, distrtypes.StoreKey, @@ -387,23 +380,7 @@ func NewSimApp( app.MountMemoryStores(app.memKeys) // initialize BaseApp - app.SetTxDecoder(encodingConfig.TxConfig.TxDecoder()) app.SetInitChainer(app.InitChainer) - app.setAnteHandler(encodingConfig.TxConfig, cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))) - // In v0.46, the SDK introduces _postHandlers_. PostHandlers are like - // antehandlers, but are run _after_ the `runMsgs` execution. They are also - // defined as a chain, and have the same signature as antehandlers. - // - // In baseapp, postHandlers are run in the same store branch as `runMsgs`, - // meaning that both `runMsgs` and `postHandler` state will be committed if - // both are successful, and both will be reverted if any of the two fails. - // - // The SDK exposes a default empty postHandlers chain. - // - // Please note that changing any of the anteHandler or postHandler chain is - // likely to be a state-machine breaking change, which needs a coordinated - // upgrade. - app.setPostHandler() if err := app.Load(loadLatest); err != nil { panic(err) @@ -412,38 +389,6 @@ func NewSimApp( return app } -func (app *SimApp) setAnteHandler(txConfig client.TxConfig, indexEventsStr []string) { - indexEvents := map[string]struct{}{} - for _, e := range indexEventsStr { - indexEvents[e] = struct{}{} - } - anteHandler, err := ante.NewAnteHandler( - ante.HandlerOptions{ - AccountKeeper: app.AccountKeeper, - BankKeeper: app.BankKeeper, - SignModeHandler: txConfig.SignModeHandler(), - FeegrantKeeper: app.FeeGrantKeeper, - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, - }, - ) - if err != nil { - panic(err) - } - - app.SetAnteHandler(anteHandler) -} - -func (app *SimApp) setPostHandler() { - postHandler, err := posthandler.NewPostHandler( - posthandler.HandlerOptions{}, - ) - if err != nil { - panic(err) - } - - app.SetPostHandler(postHandler) -} - // Name returns the name of the App func (app *SimApp) Name() string { return app.BaseApp.Name() } diff --git a/simapp/app.yaml b/simapp/app.yaml index 7dca265ea60e..d42624850c64 100644 --- a/simapp/app.yaml +++ b/simapp/app.yaml @@ -82,6 +82,8 @@ modules: - name: tx config: "@type": cosmos.tx.module.v1.Module + enable_ante_handler: true + enable_post_handler: true - name: feegrant config: diff --git a/types/tx/module/module.go b/types/tx/module/module.go index e44a78a8fc59..7cd24f277463 100644 --- a/types/tx/module/module.go +++ b/types/tx/module/module.go @@ -1,44 +1,21 @@ package tx import ( + "fmt" + + modulev1 "cosmossdk.io/api/cosmos/tx/module/v1" "cosmossdk.io/core/appmodule" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/depinject" - - modulev1 "cosmossdk.io/api/cosmos/tx/module/v1" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/ante" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + "github.com/cosmos/cosmos-sdk/x/auth/posthandler" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" ) -var DefaultTxModuleConfig = TxModuleConfig{ - // TODO set good defaults -} - -type TxModuleConfig struct { - TxConfig client.TxConfig - AnteHandler sdk.AnteHandler - PostHandler sdk.AnteHandler -} - -type TxModuleOption func(*TxModuleConfig) - -func SetCustomTxConfig(txConfig client.TxConfig) TxModuleOption { - return func(cfg *TxModuleConfig) { - cfg.TxConfig = txConfig - } -} - -func SetCustomAnteHandler(anteHandler sdk.AnteHandler) TxModuleOption { - return func(cfg *TxModuleConfig) { - cfg.AnteHandler = anteHandler - } -} - -func SetCustomPostHandler(PostHandler sdk.AnteHandler) TxModuleOption { - return func(cfg *TxModuleConfig) { - cfg.PostHandler = PostHandler - } -} - // // New App Wiring Setup // @@ -52,22 +29,78 @@ func init() { type txInputs struct { depinject.In - options []TxModuleOption + Config *modulev1.Module + + TxConfig client.TxConfig + + AccountKeeper authkeeper.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper"` + BankKeeper bankkeeper.Keeper `key:"cosmos.bank.v1.Keeper"` + FeeGrantKeeper feegrantkeeper.Keeper `key:"cosmos.feegrant.v1.Keeper"` } type txOutputs struct { depinject.Out - TxConfig client.TxConfig - AnteHandler sdk.AnteHandler - PostHandler sdk.AnteHandler + TxConfig client.TxConfig + BaseAppOption func(app *baseapp.BaseApp) } func provideModule(in txInputs) txOutputs { - cfg := DefaultTxModuleConfig - for _, opt := range in.options { - opt(&cfg) + baseAppOption := func(app *baseapp.BaseApp) { + + if in.Config.EnableAnteHandler { + // AnteHandlers + anteHandler, err := newAnteHandler(in) + if err != nil { + panic(err) + } + app.SetAnteHandler(anteHandler) + } + + if in.Config.EnablePostHandler { + // PostHandlers + // In v0.46, the SDK introduces _postHandlers_. PostHandlers are like + // antehandlers, but are run _after_ the `runMsgs` execution. They are also + // defined as a chain, and have the same signature as antehandlers. + // + // In baseapp, postHandlers are run in the same store branch as `runMsgs`, + // meaning that both `runMsgs` and `postHandler` state will be committed if + // both are successful, and both will be reverted if any of the two fails. + // + // The SDK exposes a default empty postHandlers chain. + // + // Please note that changing any of the anteHandler or postHandler chain is + // likely to be a state-machine breaking change, which needs a coordinated + // upgrade. + postHandler, err := posthandler.NewPostHandler( + posthandler.HandlerOptions{}, + ) + if err != nil { + panic(err) + } + app.SetPostHandler(postHandler) + } + + // TxDecoder + app.SetTxDecoder(in.TxConfig.TxDecoder()) + } + + return txOutputs{TxConfig: in.TxConfig, BaseAppOption: baseAppOption} +} + +func newAnteHandler(in txInputs) (sdk.AnteHandler, error) { + anteHandler, err := ante.NewAnteHandler( + ante.HandlerOptions{ + AccountKeeper: in.AccountKeeper, + BankKeeper: in.BankKeeper, + SignModeHandler: in.TxConfig.SignModeHandler(), + FeegrantKeeper: in.FeeGrantKeeper, + SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + }, + ) + if err != nil { + return nil, fmt.Errorf("failed to create ante handler: %w", err) } - return txOutputs{TxConfig: cfg.TxConfig, AnteHandler: cfg.AnteHandler, PostHandler: cfg.PostHandler} + return anteHandler, nil } From 7c93378190bd1eb0880e1bcf5388bc1f193c21e9 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 9 Jun 2022 01:54:24 +0200 Subject: [PATCH 03/15] updates --- api/cosmos/tx/module/v1/module.pulsar.go | 144 +++++++++++------------ proto/cosmos/tx/module/v1/module.proto | 10 +- simapp/app.yaml | 4 +- types/tx/module/module.go | 4 +- 4 files changed, 82 insertions(+), 80 deletions(-) diff --git a/api/cosmos/tx/module/v1/module.pulsar.go b/api/cosmos/tx/module/v1/module.pulsar.go index cbc8e27ce009..3b6678776b29 100644 --- a/api/cosmos/tx/module/v1/module.pulsar.go +++ b/api/cosmos/tx/module/v1/module.pulsar.go @@ -14,16 +14,16 @@ import ( ) var ( - md_Module protoreflect.MessageDescriptor - fd_Module_enable_ante_handler protoreflect.FieldDescriptor - fd_Module_enable_post_handler protoreflect.FieldDescriptor + md_Module protoreflect.MessageDescriptor + fd_Module_disable_ante_handler protoreflect.FieldDescriptor + fd_Module_disable_post_handler protoreflect.FieldDescriptor ) func init() { file_cosmos_tx_module_v1_module_proto_init() md_Module = File_cosmos_tx_module_v1_module_proto.Messages().ByName("Module") - fd_Module_enable_ante_handler = md_Module.Fields().ByName("enable_ante_handler") - fd_Module_enable_post_handler = md_Module.Fields().ByName("enable_post_handler") + fd_Module_disable_ante_handler = md_Module.Fields().ByName("disable_ante_handler") + fd_Module_disable_post_handler = md_Module.Fields().ByName("disable_post_handler") } var _ protoreflect.Message = (*fastReflection_Module)(nil) @@ -91,15 +91,15 @@ func (x *fastReflection_Module) Interface() protoreflect.ProtoMessage { // While iterating, mutating operations may only be performed // on the current field descriptor. func (x *fastReflection_Module) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { - if x.EnableAnteHandler != false { - value := protoreflect.ValueOfBool(x.EnableAnteHandler) - if !f(fd_Module_enable_ante_handler, value) { + if x.DisableAnteHandler != false { + value := protoreflect.ValueOfBool(x.DisableAnteHandler) + if !f(fd_Module_disable_ante_handler, value) { return } } - if x.EnablePostHandler != false { - value := protoreflect.ValueOfBool(x.EnablePostHandler) - if !f(fd_Module_enable_post_handler, value) { + if x.DisablePostHandler != false { + value := protoreflect.ValueOfBool(x.DisablePostHandler) + if !f(fd_Module_disable_post_handler, value) { return } } @@ -118,10 +118,10 @@ func (x *fastReflection_Module) Range(f func(protoreflect.FieldDescriptor, proto // a repeated field is populated if it is non-empty. func (x *fastReflection_Module) Has(fd protoreflect.FieldDescriptor) bool { switch fd.FullName() { - case "cosmos.tx.module.v1.Module.enable_ante_handler": - return x.EnableAnteHandler != false - case "cosmos.tx.module.v1.Module.enable_post_handler": - return x.EnablePostHandler != false + case "cosmos.tx.module.v1.Module.disable_ante_handler": + return x.DisableAnteHandler != false + case "cosmos.tx.module.v1.Module.disable_post_handler": + return x.DisablePostHandler != false default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) @@ -138,10 +138,10 @@ func (x *fastReflection_Module) Has(fd protoreflect.FieldDescriptor) bool { // Clear is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Module) Clear(fd protoreflect.FieldDescriptor) { switch fd.FullName() { - case "cosmos.tx.module.v1.Module.enable_ante_handler": - x.EnableAnteHandler = false - case "cosmos.tx.module.v1.Module.enable_post_handler": - x.EnablePostHandler = false + case "cosmos.tx.module.v1.Module.disable_ante_handler": + x.DisableAnteHandler = false + case "cosmos.tx.module.v1.Module.disable_post_handler": + x.DisablePostHandler = false default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) @@ -158,11 +158,11 @@ func (x *fastReflection_Module) Clear(fd protoreflect.FieldDescriptor) { // of the value; to obtain a mutable reference, use Mutable. func (x *fastReflection_Module) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { switch descriptor.FullName() { - case "cosmos.tx.module.v1.Module.enable_ante_handler": - value := x.EnableAnteHandler + case "cosmos.tx.module.v1.Module.disable_ante_handler": + value := x.DisableAnteHandler return protoreflect.ValueOfBool(value) - case "cosmos.tx.module.v1.Module.enable_post_handler": - value := x.EnablePostHandler + case "cosmos.tx.module.v1.Module.disable_post_handler": + value := x.DisablePostHandler return protoreflect.ValueOfBool(value) default: if descriptor.IsExtension() { @@ -184,10 +184,10 @@ func (x *fastReflection_Module) Get(descriptor protoreflect.FieldDescriptor) pro // Set is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Module) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { switch fd.FullName() { - case "cosmos.tx.module.v1.Module.enable_ante_handler": - x.EnableAnteHandler = value.Bool() - case "cosmos.tx.module.v1.Module.enable_post_handler": - x.EnablePostHandler = value.Bool() + case "cosmos.tx.module.v1.Module.disable_ante_handler": + x.DisableAnteHandler = value.Bool() + case "cosmos.tx.module.v1.Module.disable_post_handler": + x.DisablePostHandler = value.Bool() default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) @@ -208,10 +208,10 @@ func (x *fastReflection_Module) Set(fd protoreflect.FieldDescriptor, value proto // Mutable is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Module) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { switch fd.FullName() { - case "cosmos.tx.module.v1.Module.enable_ante_handler": - panic(fmt.Errorf("field enable_ante_handler of message cosmos.tx.module.v1.Module is not mutable")) - case "cosmos.tx.module.v1.Module.enable_post_handler": - panic(fmt.Errorf("field enable_post_handler of message cosmos.tx.module.v1.Module is not mutable")) + case "cosmos.tx.module.v1.Module.disable_ante_handler": + panic(fmt.Errorf("field disable_ante_handler of message cosmos.tx.module.v1.Module is not mutable")) + case "cosmos.tx.module.v1.Module.disable_post_handler": + panic(fmt.Errorf("field disable_post_handler of message cosmos.tx.module.v1.Module is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) @@ -225,9 +225,9 @@ func (x *fastReflection_Module) Mutable(fd protoreflect.FieldDescriptor) protore // For lists, maps, and messages, this returns a new, empty, mutable value. func (x *fastReflection_Module) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { switch fd.FullName() { - case "cosmos.tx.module.v1.Module.enable_ante_handler": + case "cosmos.tx.module.v1.Module.disable_ante_handler": return protoreflect.ValueOfBool(false) - case "cosmos.tx.module.v1.Module.enable_post_handler": + case "cosmos.tx.module.v1.Module.disable_post_handler": return protoreflect.ValueOfBool(false) default: if fd.IsExtension() { @@ -298,10 +298,10 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { var n int var l int _ = l - if x.EnableAnteHandler { + if x.DisableAnteHandler { n += 2 } - if x.EnablePostHandler { + if x.DisablePostHandler { n += 2 } if x.unknownFields != nil { @@ -333,9 +333,9 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } - if x.EnablePostHandler { + if x.DisablePostHandler { i-- - if x.EnablePostHandler { + if x.DisablePostHandler { dAtA[i] = 1 } else { dAtA[i] = 0 @@ -343,9 +343,9 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { i-- dAtA[i] = 0x10 } - if x.EnableAnteHandler { + if x.DisableAnteHandler { i-- - if x.EnableAnteHandler { + if x.DisableAnteHandler { dAtA[i] = 1 } else { dAtA[i] = 0 @@ -404,7 +404,7 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { switch fieldNum { case 1: if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field EnableAnteHandler", wireType) + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field DisableAnteHandler", wireType) } var v int for shift := uint(0); ; shift += 7 { @@ -421,10 +421,10 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { break } } - x.EnableAnteHandler = bool(v != 0) + x.DisableAnteHandler = bool(v != 0) case 2: if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field EnablePostHandler", wireType) + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field DisablePostHandler", wireType) } var v int for shift := uint(0); ; shift += 7 { @@ -441,7 +441,7 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { break } } - x.EnablePostHandler = bool(v != 0) + x.DisablePostHandler = bool(v != 0) default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -496,10 +496,10 @@ type Module struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // enable_ante_handler defines whether the ante handler are set in the app. - EnableAnteHandler bool `protobuf:"varint,1,opt,name=enable_ante_handler,json=enableAnteHandler,proto3" json:"enable_ante_handler,omitempty"` - // enable_post_handler defines whether the post handler are set in the app. - EnablePostHandler bool `protobuf:"varint,2,opt,name=enable_post_handler,json=enablePostHandler,proto3" json:"enable_post_handler,omitempty"` + // disable_ante_handler defines whether the ante handler are disabled in the app. + DisableAnteHandler bool `protobuf:"varint,1,opt,name=disable_ante_handler,json=disableAnteHandler,proto3" json:"disable_ante_handler,omitempty"` + // disable_post_handler defines whether the post handler are disabled in the app. + DisablePostHandler bool `protobuf:"varint,2,opt,name=disable_post_handler,json=disablePostHandler,proto3" json:"disable_post_handler,omitempty"` } func (x *Module) Reset() { @@ -522,16 +522,16 @@ func (*Module) Descriptor() ([]byte, []int) { return file_cosmos_tx_module_v1_module_proto_rawDescGZIP(), []int{0} } -func (x *Module) GetEnableAnteHandler() bool { +func (x *Module) GetDisableAnteHandler() bool { if x != nil { - return x.EnableAnteHandler + return x.DisableAnteHandler } return false } -func (x *Module) GetEnablePostHandler() bool { +func (x *Module) GetDisablePostHandler() bool { if x != nil { - return x.EnablePostHandler + return x.DisablePostHandler } return false } @@ -544,27 +544,27 @@ var file_cosmos_tx_module_v1_module_proto_rawDesc = []byte{ 0x74, 0x6f, 0x12, 0x13, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x74, 0x78, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x6d, 0x6f, 0x64, - 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x68, 0x0a, 0x06, 0x4d, 0x6f, 0x64, - 0x75, 0x6c, 0x65, 0x12, 0x2e, 0x0a, 0x13, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x61, 0x6e, - 0x74, 0x65, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x11, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x41, 0x6e, 0x74, 0x65, 0x48, 0x61, 0x6e, 0x64, - 0x6c, 0x65, 0x72, 0x12, 0x2e, 0x0a, 0x13, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x70, 0x6f, - 0x73, 0x74, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x11, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x50, 0x6f, 0x73, 0x74, 0x48, 0x61, 0x6e, 0x64, - 0x6c, 0x65, 0x72, 0x42, 0xc4, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x2e, 0x74, 0x78, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x42, - 0x0b, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2d, - 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, - 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x74, 0x78, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, - 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, - 0x43, 0x54, 0x4d, 0xaa, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x54, 0x78, 0x2e, - 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, - 0x02, 0x1f, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, - 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, - 0x61, 0xea, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x54, 0x78, 0x3a, 0x3a, - 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x74, 0x0a, 0x06, 0x4d, 0x6f, 0x64, + 0x75, 0x6c, 0x65, 0x12, 0x30, 0x0a, 0x14, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x61, + 0x6e, 0x74, 0x65, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x12, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x41, 0x6e, 0x74, 0x65, 0x48, 0x61, + 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x12, 0x30, 0x0a, 0x14, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, + 0x5f, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x12, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x50, 0x6f, 0x73, 0x74, + 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x3a, 0x06, 0xba, 0xc0, 0x96, 0xda, 0x01, 0x00, 0x42, + 0xc4, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x74, + 0x78, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x4d, 0x6f, 0x64, + 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2d, 0x63, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, + 0x6d, 0x6f, 0x73, 0x2f, 0x74, 0x78, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, + 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x54, 0x4d, 0xaa, + 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x54, 0x78, 0x2e, 0x4d, 0x6f, 0x64, 0x75, + 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, + 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1f, 0x43, 0x6f, + 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, + 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x16, + 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x54, 0x78, 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, + 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/proto/cosmos/tx/module/v1/module.proto b/proto/cosmos/tx/module/v1/module.proto index 2245436084ba..9cea23ac8e47 100644 --- a/proto/cosmos/tx/module/v1/module.proto +++ b/proto/cosmos/tx/module/v1/module.proto @@ -6,9 +6,11 @@ import "cosmos/app/v1alpha1/module.proto"; // Module is the config object of the tx module. message Module { - // enable_ante_handler defines whether the ante handler are set in the app. - bool enable_ante_handler = 1; + option (cosmos.app.v1alpha1.module) = {}; - // enable_post_handler defines whether the post handler are set in the app. - bool enable_post_handler = 2; + // disable_ante_handler defines whether the ante handler are disabled in the app. + bool disable_ante_handler = 1; + + // disable_post_handler defines whether the post handler are disabled in the app. + bool disable_post_handler = 2; } \ No newline at end of file diff --git a/simapp/app.yaml b/simapp/app.yaml index d42624850c64..2d928989e0ce 100644 --- a/simapp/app.yaml +++ b/simapp/app.yaml @@ -82,8 +82,8 @@ modules: - name: tx config: "@type": cosmos.tx.module.v1.Module - enable_ante_handler: true - enable_post_handler: true + disable_ante_handler: false + disable_post_handler: false - name: feegrant config: diff --git a/types/tx/module/module.go b/types/tx/module/module.go index 7cd24f277463..fe9eef3c4ffd 100644 --- a/types/tx/module/module.go +++ b/types/tx/module/module.go @@ -48,7 +48,7 @@ type txOutputs struct { func provideModule(in txInputs) txOutputs { baseAppOption := func(app *baseapp.BaseApp) { - if in.Config.EnableAnteHandler { + if !in.Config.DisableAnteHandler { // AnteHandlers anteHandler, err := newAnteHandler(in) if err != nil { @@ -57,7 +57,7 @@ func provideModule(in txInputs) txOutputs { app.SetAnteHandler(anteHandler) } - if in.Config.EnablePostHandler { + if !in.Config.DisableAnteHandler { // PostHandlers // In v0.46, the SDK introduces _postHandlers_. PostHandlers are like // antehandlers, but are run _after_ the `runMsgs` execution. They are also From d1c2dfabc9613bb1959a01f7a299d0c6c656f9af Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 9 Jun 2022 13:26:44 +0200 Subject: [PATCH 04/15] updates --- api/cosmos/tx/module/v1/module.pulsar.go | 45 +++++++++++++----------- proto/cosmos/tx/module/v1/module.proto | 4 ++- simapp/app.go | 3 +- types/tx/module/module.go | 9 ++--- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/api/cosmos/tx/module/v1/module.pulsar.go b/api/cosmos/tx/module/v1/module.pulsar.go index 3b6678776b29..5d584b711d5a 100644 --- a/api/cosmos/tx/module/v1/module.pulsar.go +++ b/api/cosmos/tx/module/v1/module.pulsar.go @@ -544,27 +544,30 @@ var file_cosmos_tx_module_v1_module_proto_rawDesc = []byte{ 0x74, 0x6f, 0x12, 0x13, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x74, 0x78, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x6d, 0x6f, 0x64, - 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x74, 0x0a, 0x06, 0x4d, 0x6f, 0x64, - 0x75, 0x6c, 0x65, 0x12, 0x30, 0x0a, 0x14, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x61, - 0x6e, 0x74, 0x65, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x12, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x41, 0x6e, 0x74, 0x65, 0x48, 0x61, - 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x12, 0x30, 0x0a, 0x14, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, - 0x5f, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x08, 0x52, 0x12, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x50, 0x6f, 0x73, 0x74, - 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x3a, 0x06, 0xba, 0xc0, 0x96, 0xda, 0x01, 0x00, 0x42, - 0xc4, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x74, - 0x78, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x4d, 0x6f, 0x64, - 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2d, 0x63, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, - 0x6d, 0x6f, 0x73, 0x2f, 0x74, 0x78, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, - 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x54, 0x4d, 0xaa, - 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x54, 0x78, 0x2e, 0x4d, 0x6f, 0x64, 0x75, - 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, - 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1f, 0x43, 0x6f, - 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, - 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x16, - 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x54, 0x78, 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, - 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x9b, 0x01, 0x0a, 0x06, 0x4d, 0x6f, + 0x64, 0x75, 0x6c, 0x65, 0x12, 0x30, 0x0a, 0x14, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x5f, + 0x61, 0x6e, 0x74, 0x65, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x12, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x41, 0x6e, 0x74, 0x65, 0x48, + 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x12, 0x30, 0x0a, 0x14, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, + 0x65, 0x5f, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x12, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x50, 0x6f, 0x73, + 0x74, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x3a, 0x2d, 0xba, 0xc0, 0x96, 0xda, 0x01, 0x27, + 0x0a, 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, + 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x74, + 0x79, 0x70, 0x65, 0x73, 0x2f, 0x74, 0x78, 0x42, 0xc4, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x74, 0x78, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, + 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, + 0x50, 0x01, 0x5a, 0x2d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, + 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x74, 0x78, 0x2f, 0x6d, + 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x76, + 0x31, 0xa2, 0x02, 0x03, 0x43, 0x54, 0x4d, 0xaa, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x2e, 0x54, 0x78, 0x2e, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x13, + 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, + 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1f, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, 0x78, 0x5c, + 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, + 0x54, 0x78, 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/proto/cosmos/tx/module/v1/module.proto b/proto/cosmos/tx/module/v1/module.proto index 9cea23ac8e47..1ac656a9385d 100644 --- a/proto/cosmos/tx/module/v1/module.proto +++ b/proto/cosmos/tx/module/v1/module.proto @@ -6,7 +6,9 @@ import "cosmos/app/v1alpha1/module.proto"; // Module is the config object of the tx module. message Module { - option (cosmos.app.v1alpha1.module) = {}; + option (cosmos.app.v1alpha1.module) = { + go_import: "github.com/cosmos/cosmos-sdk/types/tx" + }; // disable_ante_handler defines whether the ante handler are disabled in the app. bool disable_ante_handler = 1; diff --git a/simapp/app.go b/simapp/app.go index 61546ef1a5ef..e4e7bdeb753d 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -32,6 +32,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/testdata_pulsar" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + _ "github.com/cosmos/cosmos-sdk/types/tx/module" // import tx module for side-effects "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" @@ -355,7 +356,7 @@ func NewSimApp( // app.mm.SetOrderMigrations(custom order) app.ModuleManager.RegisterInvariants(&app.CrisisKeeper) - app.ModuleManager.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino) + app.ModuleManager.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino) // should it be app.legacyAmino here? // RegisterUpgradeHandlers is used for registering any on-chain upgrades. // Make sure it's called after `app.mm` and `app.configurator` are set. diff --git a/types/tx/module/module.go b/types/tx/module/module.go index fe9eef3c4ffd..933ff352ae60 100644 --- a/types/tx/module/module.go +++ b/types/tx/module/module.go @@ -16,10 +16,6 @@ import ( feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" ) -// -// New App Wiring Setup -// - func init() { appmodule.Register(&modulev1.Module{}, appmodule.Provide(provideModule), @@ -41,8 +37,7 @@ type txInputs struct { type txOutputs struct { depinject.Out - TxConfig client.TxConfig - BaseAppOption func(app *baseapp.BaseApp) + BaseAppOption func(*baseapp.BaseApp) } func provideModule(in txInputs) txOutputs { @@ -85,7 +80,7 @@ func provideModule(in txInputs) txOutputs { app.SetTxDecoder(in.TxConfig.TxDecoder()) } - return txOutputs{TxConfig: in.TxConfig, BaseAppOption: baseAppOption} + return txOutputs{BaseAppOption: baseAppOption} } func newAnteHandler(in txInputs) (sdk.AnteHandler, error) { From 366433d243ba614c5590136369e21b3526894ead Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 9 Jun 2022 13:40:48 +0200 Subject: [PATCH 05/15] updates --- types/tx/module/module.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/types/tx/module/module.go b/types/tx/module/module.go index 933ff352ae60..7172a2a6df1b 100644 --- a/types/tx/module/module.go +++ b/types/tx/module/module.go @@ -7,11 +7,13 @@ import ( "cosmossdk.io/core/appmodule" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/depinject" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/ante" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/auth/posthandler" + "github.com/cosmos/cosmos-sdk/x/auth/tx" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" ) @@ -25,9 +27,8 @@ func init() { type txInputs struct { depinject.In - Config *modulev1.Module - - TxConfig client.TxConfig + Config *modulev1.Module + ProtoCodecMarshaler codec.ProtoCodecMarshaler AccountKeeper authkeeper.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper"` BankKeeper bankkeeper.Keeper `key:"cosmos.bank.v1.Keeper"` @@ -37,15 +38,17 @@ type txInputs struct { type txOutputs struct { depinject.Out + TxConfig client.TxConfig BaseAppOption func(*baseapp.BaseApp) } func provideModule(in txInputs) txOutputs { + txConfig := tx.NewTxConfig(in.ProtoCodecMarshaler, tx.DefaultSignModes) baseAppOption := func(app *baseapp.BaseApp) { if !in.Config.DisableAnteHandler { // AnteHandlers - anteHandler, err := newAnteHandler(in) + anteHandler, err := newAnteHandler(txConfig, in) if err != nil { panic(err) } @@ -77,18 +80,18 @@ func provideModule(in txInputs) txOutputs { } // TxDecoder - app.SetTxDecoder(in.TxConfig.TxDecoder()) + app.SetTxDecoder(txConfig.TxDecoder()) } - return txOutputs{BaseAppOption: baseAppOption} + return txOutputs{TxConfig: txConfig, BaseAppOption: baseAppOption} } -func newAnteHandler(in txInputs) (sdk.AnteHandler, error) { +func newAnteHandler(txConfig client.TxConfig, in txInputs) (sdk.AnteHandler, error) { anteHandler, err := ante.NewAnteHandler( ante.HandlerOptions{ AccountKeeper: in.AccountKeeper, BankKeeper: in.BankKeeper, - SignModeHandler: in.TxConfig.SignModeHandler(), + SignModeHandler: txConfig.SignModeHandler(), FeegrantKeeper: in.FeeGrantKeeper, SigGasConsumer: ante.DefaultSigVerificationGasConsumer, }, From 30441c213ff1721c9687fa7c528137011474eb1c Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 9 Jun 2022 15:25:48 +0200 Subject: [PATCH 06/15] feedback --- api/cosmos/tx/module/v1/module.pulsar.go | 36 ++++++++++++------------ proto/cosmos/tx/module/v1/module.proto | 2 +- simapp/app.go | 2 +- {types => x/auth}/tx/module/module.go | 0 4 files changed, 20 insertions(+), 20 deletions(-) rename {types => x/auth}/tx/module/module.go (100%) diff --git a/api/cosmos/tx/module/v1/module.pulsar.go b/api/cosmos/tx/module/v1/module.pulsar.go index 5d584b711d5a..b94013b11ca7 100644 --- a/api/cosmos/tx/module/v1/module.pulsar.go +++ b/api/cosmos/tx/module/v1/module.pulsar.go @@ -544,30 +544,30 @@ var file_cosmos_tx_module_v1_module_proto_rawDesc = []byte{ 0x74, 0x6f, 0x12, 0x13, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x74, 0x78, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x6d, 0x6f, 0x64, - 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x9b, 0x01, 0x0a, 0x06, 0x4d, 0x6f, + 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x9c, 0x01, 0x0a, 0x06, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x12, 0x30, 0x0a, 0x14, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x61, 0x6e, 0x74, 0x65, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x12, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x41, 0x6e, 0x74, 0x65, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x12, 0x30, 0x0a, 0x14, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x12, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x50, 0x6f, 0x73, - 0x74, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x3a, 0x2d, 0xba, 0xc0, 0x96, 0xda, 0x01, 0x27, - 0x0a, 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, - 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x74, - 0x79, 0x70, 0x65, 0x73, 0x2f, 0x74, 0x78, 0x42, 0xc4, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, 0x2e, - 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x74, 0x78, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, - 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, - 0x50, 0x01, 0x5a, 0x2d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, - 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x74, 0x78, 0x2f, 0x6d, - 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x76, - 0x31, 0xa2, 0x02, 0x03, 0x43, 0x54, 0x4d, 0xaa, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x2e, 0x54, 0x78, 0x2e, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x13, - 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, - 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1f, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, 0x78, 0x5c, - 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, - 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, - 0x54, 0x78, 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x3a, 0x2e, 0xba, 0xc0, 0x96, 0xda, 0x01, 0x28, + 0x0a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, + 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x78, + 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x74, 0x78, 0x42, 0xc4, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, + 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x74, 0x78, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, + 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, + 0x6f, 0x50, 0x01, 0x5a, 0x2d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, + 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x74, 0x78, 0x2f, + 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, + 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x54, 0x4d, 0xaa, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2e, 0x54, 0x78, 0x2e, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, + 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, + 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1f, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, 0x78, + 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, + 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, + 0x3a, 0x54, 0x78, 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/proto/cosmos/tx/module/v1/module.proto b/proto/cosmos/tx/module/v1/module.proto index 1ac656a9385d..8816de36a0a4 100644 --- a/proto/cosmos/tx/module/v1/module.proto +++ b/proto/cosmos/tx/module/v1/module.proto @@ -7,7 +7,7 @@ import "cosmos/app/v1alpha1/module.proto"; // Module is the config object of the tx module. message Module { option (cosmos.app.v1alpha1.module) = { - go_import: "github.com/cosmos/cosmos-sdk/types/tx" + go_import: "github.com/cosmos/cosmos-sdk/x/auth/tx" }; // disable_ante_handler defines whether the ante handler are disabled in the app. diff --git a/simapp/app.go b/simapp/app.go index c5274e1febe2..b6c567b69424 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -32,10 +32,10 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/testdata_pulsar" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - _ "github.com/cosmos/cosmos-sdk/types/tx/module" // import tx module for side-effects "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" + _ "github.com/cosmos/cosmos-sdk/x/auth/tx" // import tx module for side-effects authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" diff --git a/types/tx/module/module.go b/x/auth/tx/module/module.go similarity index 100% rename from types/tx/module/module.go rename to x/auth/tx/module/module.go From 720ae1096567d33730dba871f76553f21661a25a Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 9 Jun 2022 15:57:58 +0200 Subject: [PATCH 07/15] typo --- simapp/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simapp/app.go b/simapp/app.go index 5c87ab7ba7a2..bb7b7f8381f4 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -35,7 +35,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" - _ "github.com/cosmos/cosmos-sdk/x/auth/tx" // import tx module for side-effects + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/module" // import tx module for side-effects authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" From 402d0768a37caf3be05420086077b45ec9680180 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 9 Jun 2022 17:19:36 +0200 Subject: [PATCH 08/15] implements feedback --- api/cosmos/tx/module/v1/module.pulsar.go | 149 +++++++++++------------ core/appmodule/doc.go | 2 +- core/appmodule/option.go | 2 +- proto/cosmos/tx/module/v1/module.proto | 8 +- simapp/app.go | 6 +- simapp/app.yaml | 4 +- x/auth/tx/module/module.go | 15 ++- 7 files changed, 93 insertions(+), 93 deletions(-) diff --git a/api/cosmos/tx/module/v1/module.pulsar.go b/api/cosmos/tx/module/v1/module.pulsar.go index b94013b11ca7..bdbf93e4a88d 100644 --- a/api/cosmos/tx/module/v1/module.pulsar.go +++ b/api/cosmos/tx/module/v1/module.pulsar.go @@ -14,16 +14,16 @@ import ( ) var ( - md_Module protoreflect.MessageDescriptor - fd_Module_disable_ante_handler protoreflect.FieldDescriptor - fd_Module_disable_post_handler protoreflect.FieldDescriptor + md_Module protoreflect.MessageDescriptor + fd_Module_skip_ante_handler protoreflect.FieldDescriptor + fd_Module_skip_post_handler protoreflect.FieldDescriptor ) func init() { file_cosmos_tx_module_v1_module_proto_init() md_Module = File_cosmos_tx_module_v1_module_proto.Messages().ByName("Module") - fd_Module_disable_ante_handler = md_Module.Fields().ByName("disable_ante_handler") - fd_Module_disable_post_handler = md_Module.Fields().ByName("disable_post_handler") + fd_Module_skip_ante_handler = md_Module.Fields().ByName("skip_ante_handler") + fd_Module_skip_post_handler = md_Module.Fields().ByName("skip_post_handler") } var _ protoreflect.Message = (*fastReflection_Module)(nil) @@ -91,15 +91,15 @@ func (x *fastReflection_Module) Interface() protoreflect.ProtoMessage { // While iterating, mutating operations may only be performed // on the current field descriptor. func (x *fastReflection_Module) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { - if x.DisableAnteHandler != false { - value := protoreflect.ValueOfBool(x.DisableAnteHandler) - if !f(fd_Module_disable_ante_handler, value) { + if x.SkipAnteHandler != false { + value := protoreflect.ValueOfBool(x.SkipAnteHandler) + if !f(fd_Module_skip_ante_handler, value) { return } } - if x.DisablePostHandler != false { - value := protoreflect.ValueOfBool(x.DisablePostHandler) - if !f(fd_Module_disable_post_handler, value) { + if x.SkipPostHandler != false { + value := protoreflect.ValueOfBool(x.SkipPostHandler) + if !f(fd_Module_skip_post_handler, value) { return } } @@ -118,10 +118,10 @@ func (x *fastReflection_Module) Range(f func(protoreflect.FieldDescriptor, proto // a repeated field is populated if it is non-empty. func (x *fastReflection_Module) Has(fd protoreflect.FieldDescriptor) bool { switch fd.FullName() { - case "cosmos.tx.module.v1.Module.disable_ante_handler": - return x.DisableAnteHandler != false - case "cosmos.tx.module.v1.Module.disable_post_handler": - return x.DisablePostHandler != false + case "cosmos.tx.module.v1.Module.skip_ante_handler": + return x.SkipAnteHandler != false + case "cosmos.tx.module.v1.Module.skip_post_handler": + return x.SkipPostHandler != false default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) @@ -138,10 +138,10 @@ func (x *fastReflection_Module) Has(fd protoreflect.FieldDescriptor) bool { // Clear is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Module) Clear(fd protoreflect.FieldDescriptor) { switch fd.FullName() { - case "cosmos.tx.module.v1.Module.disable_ante_handler": - x.DisableAnteHandler = false - case "cosmos.tx.module.v1.Module.disable_post_handler": - x.DisablePostHandler = false + case "cosmos.tx.module.v1.Module.skip_ante_handler": + x.SkipAnteHandler = false + case "cosmos.tx.module.v1.Module.skip_post_handler": + x.SkipPostHandler = false default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) @@ -158,11 +158,11 @@ func (x *fastReflection_Module) Clear(fd protoreflect.FieldDescriptor) { // of the value; to obtain a mutable reference, use Mutable. func (x *fastReflection_Module) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { switch descriptor.FullName() { - case "cosmos.tx.module.v1.Module.disable_ante_handler": - value := x.DisableAnteHandler + case "cosmos.tx.module.v1.Module.skip_ante_handler": + value := x.SkipAnteHandler return protoreflect.ValueOfBool(value) - case "cosmos.tx.module.v1.Module.disable_post_handler": - value := x.DisablePostHandler + case "cosmos.tx.module.v1.Module.skip_post_handler": + value := x.SkipPostHandler return protoreflect.ValueOfBool(value) default: if descriptor.IsExtension() { @@ -184,10 +184,10 @@ func (x *fastReflection_Module) Get(descriptor protoreflect.FieldDescriptor) pro // Set is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Module) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { switch fd.FullName() { - case "cosmos.tx.module.v1.Module.disable_ante_handler": - x.DisableAnteHandler = value.Bool() - case "cosmos.tx.module.v1.Module.disable_post_handler": - x.DisablePostHandler = value.Bool() + case "cosmos.tx.module.v1.Module.skip_ante_handler": + x.SkipAnteHandler = value.Bool() + case "cosmos.tx.module.v1.Module.skip_post_handler": + x.SkipPostHandler = value.Bool() default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) @@ -208,10 +208,10 @@ func (x *fastReflection_Module) Set(fd protoreflect.FieldDescriptor, value proto // Mutable is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Module) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { switch fd.FullName() { - case "cosmos.tx.module.v1.Module.disable_ante_handler": - panic(fmt.Errorf("field disable_ante_handler of message cosmos.tx.module.v1.Module is not mutable")) - case "cosmos.tx.module.v1.Module.disable_post_handler": - panic(fmt.Errorf("field disable_post_handler of message cosmos.tx.module.v1.Module is not mutable")) + case "cosmos.tx.module.v1.Module.skip_ante_handler": + panic(fmt.Errorf("field skip_ante_handler of message cosmos.tx.module.v1.Module is not mutable")) + case "cosmos.tx.module.v1.Module.skip_post_handler": + panic(fmt.Errorf("field skip_post_handler of message cosmos.tx.module.v1.Module is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.tx.module.v1.Module")) @@ -225,9 +225,9 @@ func (x *fastReflection_Module) Mutable(fd protoreflect.FieldDescriptor) protore // For lists, maps, and messages, this returns a new, empty, mutable value. func (x *fastReflection_Module) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { switch fd.FullName() { - case "cosmos.tx.module.v1.Module.disable_ante_handler": + case "cosmos.tx.module.v1.Module.skip_ante_handler": return protoreflect.ValueOfBool(false) - case "cosmos.tx.module.v1.Module.disable_post_handler": + case "cosmos.tx.module.v1.Module.skip_post_handler": return protoreflect.ValueOfBool(false) default: if fd.IsExtension() { @@ -298,10 +298,10 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { var n int var l int _ = l - if x.DisableAnteHandler { + if x.SkipAnteHandler { n += 2 } - if x.DisablePostHandler { + if x.SkipPostHandler { n += 2 } if x.unknownFields != nil { @@ -333,9 +333,9 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } - if x.DisablePostHandler { + if x.SkipPostHandler { i-- - if x.DisablePostHandler { + if x.SkipPostHandler { dAtA[i] = 1 } else { dAtA[i] = 0 @@ -343,9 +343,9 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { i-- dAtA[i] = 0x10 } - if x.DisableAnteHandler { + if x.SkipAnteHandler { i-- - if x.DisableAnteHandler { + if x.SkipAnteHandler { dAtA[i] = 1 } else { dAtA[i] = 0 @@ -404,7 +404,7 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { switch fieldNum { case 1: if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field DisableAnteHandler", wireType) + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SkipAnteHandler", wireType) } var v int for shift := uint(0); ; shift += 7 { @@ -421,10 +421,10 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { break } } - x.DisableAnteHandler = bool(v != 0) + x.SkipAnteHandler = bool(v != 0) case 2: if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field DisablePostHandler", wireType) + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SkipPostHandler", wireType) } var v int for shift := uint(0); ; shift += 7 { @@ -441,7 +441,7 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { break } } - x.DisablePostHandler = bool(v != 0) + x.SkipPostHandler = bool(v != 0) default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -496,10 +496,10 @@ type Module struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // disable_ante_handler defines whether the ante handler are disabled in the app. - DisableAnteHandler bool `protobuf:"varint,1,opt,name=disable_ante_handler,json=disableAnteHandler,proto3" json:"disable_ante_handler,omitempty"` - // disable_post_handler defines whether the post handler are disabled in the app. - DisablePostHandler bool `protobuf:"varint,2,opt,name=disable_post_handler,json=disablePostHandler,proto3" json:"disable_post_handler,omitempty"` + // skip_ante_handler defines whether the ante handler registration should be skipped in case an app wants to override this functionality. + SkipAnteHandler bool `protobuf:"varint,1,opt,name=skip_ante_handler,json=skipAnteHandler,proto3" json:"skip_ante_handler,omitempty"` + // skip_post_handler defines whether the post handler registration should be skipped in case an app wants to override this functionality. + SkipPostHandler bool `protobuf:"varint,2,opt,name=skip_post_handler,json=skipPostHandler,proto3" json:"skip_post_handler,omitempty"` } func (x *Module) Reset() { @@ -522,16 +522,16 @@ func (*Module) Descriptor() ([]byte, []int) { return file_cosmos_tx_module_v1_module_proto_rawDescGZIP(), []int{0} } -func (x *Module) GetDisableAnteHandler() bool { +func (x *Module) GetSkipAnteHandler() bool { if x != nil { - return x.DisableAnteHandler + return x.SkipAnteHandler } return false } -func (x *Module) GetDisablePostHandler() bool { +func (x *Module) GetSkipPostHandler() bool { if x != nil { - return x.DisablePostHandler + return x.SkipPostHandler } return false } @@ -544,30 +544,29 @@ var file_cosmos_tx_module_v1_module_proto_rawDesc = []byte{ 0x74, 0x6f, 0x12, 0x13, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x74, 0x78, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x6d, 0x6f, 0x64, - 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x9c, 0x01, 0x0a, 0x06, 0x4d, 0x6f, - 0x64, 0x75, 0x6c, 0x65, 0x12, 0x30, 0x0a, 0x14, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x5f, - 0x61, 0x6e, 0x74, 0x65, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x12, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x41, 0x6e, 0x74, 0x65, 0x48, - 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x12, 0x30, 0x0a, 0x14, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, - 0x65, 0x5f, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x12, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x50, 0x6f, 0x73, - 0x74, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x3a, 0x2e, 0xba, 0xc0, 0x96, 0xda, 0x01, 0x28, - 0x0a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, - 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x78, - 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x74, 0x78, 0x42, 0xc4, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, - 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x74, 0x78, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, - 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, - 0x6f, 0x50, 0x01, 0x5a, 0x2d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, - 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x74, 0x78, 0x2f, - 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, - 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x54, 0x4d, 0xaa, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x2e, 0x54, 0x78, 0x2e, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, 0x02, - 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, - 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1f, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, 0x78, - 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, - 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, - 0x3a, 0x54, 0x78, 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x90, 0x01, 0x0a, 0x06, 0x4d, 0x6f, + 0x64, 0x75, 0x6c, 0x65, 0x12, 0x2a, 0x0a, 0x11, 0x73, 0x6b, 0x69, 0x70, 0x5f, 0x61, 0x6e, 0x74, + 0x65, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x0f, 0x73, 0x6b, 0x69, 0x70, 0x41, 0x6e, 0x74, 0x65, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, + 0x12, 0x2a, 0x0a, 0x11, 0x73, 0x6b, 0x69, 0x70, 0x5f, 0x70, 0x6f, 0x73, 0x74, 0x5f, 0x68, 0x61, + 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0f, 0x73, 0x6b, 0x69, + 0x70, 0x50, 0x6f, 0x73, 0x74, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x3a, 0x2e, 0xba, 0xc0, + 0x96, 0xda, 0x01, 0x28, 0x0a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, + 0x64, 0x6b, 0x2f, 0x78, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x74, 0x78, 0x42, 0xc4, 0x01, 0x0a, + 0x17, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x74, 0x78, 0x2e, 0x6d, + 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, + 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, + 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x2f, 0x74, 0x78, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x6f, + 0x64, 0x75, 0x6c, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x54, 0x4d, 0xaa, 0x02, 0x13, 0x43, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x54, 0x78, 0x2e, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, + 0x56, 0x31, 0xca, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, + 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1f, 0x43, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x5c, 0x54, 0x78, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, + 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x16, 0x43, 0x6f, 0x73, + 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x54, 0x78, 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, + 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/core/appmodule/doc.go b/core/appmodule/doc.go index 979f1867cd99..bf64ed40d589 100644 --- a/core/appmodule/doc.go +++ b/core/appmodule/doc.go @@ -1,5 +1,5 @@ // Package appmodule defines the functionality for registering Cosmos SDK app -// modules that are assembled using the pkg.go.dev/github.com/cosmos/cosmos-sdk/depinject +// modules that are assembled using the cosmossdk.io/depinject // dependency injection system and the declarative app configuration format // handled by the appconfig package. package appmodule diff --git a/core/appmodule/option.go b/core/appmodule/option.go index cb1fc034e3a2..98c5518afba7 100644 --- a/core/appmodule/option.go +++ b/core/appmodule/option.go @@ -17,7 +17,7 @@ func (f funcOption) apply(initializer *internal.ModuleInitializer) error { } // Provide registers providers with the dependency injection system that will be -// run within the module scope. See pkg.go.dev/github.com/cosmos/cosmos-sdk/depinject for +// run within the module scope. See cosmossdk.io/depinject for // documentation on the dependency injection system. func Provide(providers ...interface{}) Option { return funcOption(func(initializer *internal.ModuleInitializer) error { diff --git a/proto/cosmos/tx/module/v1/module.proto b/proto/cosmos/tx/module/v1/module.proto index 8816de36a0a4..4196b1075af6 100644 --- a/proto/cosmos/tx/module/v1/module.proto +++ b/proto/cosmos/tx/module/v1/module.proto @@ -10,9 +10,9 @@ message Module { go_import: "github.com/cosmos/cosmos-sdk/x/auth/tx" }; - // disable_ante_handler defines whether the ante handler are disabled in the app. - bool disable_ante_handler = 1; + // skip_ante_handler defines whether the ante handler registration should be skipped in case an app wants to override this functionality. + bool skip_ante_handler = 1; - // disable_post_handler defines whether the post handler are disabled in the app. - bool disable_post_handler = 2; + // skip_post_handler defines whether the post handler registration should be skipped in case an app wants to override this functionality. + bool skip_post_handler = 2; } \ No newline at end of file diff --git a/simapp/app.go b/simapp/app.go index bb7b7f8381f4..e126c5382ec3 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -211,7 +211,6 @@ func NewSimApp( var appBuilder *runtime.AppBuilder var msgServiceRouter *baseapp.MsgServiceRouter - var txOptions func(*baseapp.BaseApp) if err := depinject.Inject(AppConfig, &appBuilder, @@ -228,12 +227,11 @@ func NewSimApp( &app.NFTKeeper, &app.SlashingKeeper, &msgServiceRouter, - &txOptions, ); err != nil { panic(err) } - app.App = appBuilder.Build(logger, db, traceStore, msgServiceRouter, append(baseAppOptions, txOptions)...) + app.App = appBuilder.Build(logger, db, traceStore, msgServiceRouter, baseAppOptions...) app.keys = sdk.NewKVStoreKeys( minttypes.StoreKey, distrtypes.StoreKey, @@ -352,7 +350,7 @@ func NewSimApp( // app.mm.SetOrderMigrations(custom order) app.ModuleManager.RegisterInvariants(&app.CrisisKeeper) - app.ModuleManager.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino) // should it be app.legacyAmino here? + app.ModuleManager.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino) // RegisterUpgradeHandlers is used for registering any on-chain upgrades. // Make sure it's called after `app.mm` and `app.configurator` are set. diff --git a/simapp/app.yaml b/simapp/app.yaml index e290feb88001..3d17a11d6cad 100644 --- a/simapp/app.yaml +++ b/simapp/app.yaml @@ -82,8 +82,6 @@ modules: - name: tx config: "@type": cosmos.tx.module.v1.Module - disable_ante_handler: false - disable_post_handler: false - name: feegrant config: @@ -92,7 +90,7 @@ modules: - name: bank config: "@type": cosmos.bank.module.v1.Module - + - name: authz config: "@type": cosmos.authz.module.v1.Module diff --git a/x/auth/tx/module/module.go b/x/auth/tx/module/module.go index 7172a2a6df1b..4b6db6f286cd 100644 --- a/x/auth/tx/module/module.go +++ b/x/auth/tx/module/module.go @@ -30,9 +30,9 @@ type txInputs struct { Config *modulev1.Module ProtoCodecMarshaler codec.ProtoCodecMarshaler - AccountKeeper authkeeper.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper"` - BankKeeper bankkeeper.Keeper `key:"cosmos.bank.v1.Keeper"` - FeeGrantKeeper feegrantkeeper.Keeper `key:"cosmos.feegrant.v1.Keeper"` + AccountKeeper *authkeeper.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper" optional:"true"` + BankKeeper bankkeeper.Keeper `key:"cosmos.bank.v1.Keeper" optional:"true"` + FeeGrantKeeper *feegrantkeeper.Keeper `key:"cosmos.feegrant.v1.Keeper" optional:"true"` } type txOutputs struct { @@ -44,9 +44,10 @@ type txOutputs struct { func provideModule(in txInputs) txOutputs { txConfig := tx.NewTxConfig(in.ProtoCodecMarshaler, tx.DefaultSignModes) + baseAppOption := func(app *baseapp.BaseApp) { - if !in.Config.DisableAnteHandler { + if !in.Config.SkipAnteHandler { // AnteHandlers anteHandler, err := newAnteHandler(txConfig, in) if err != nil { @@ -55,7 +56,7 @@ func provideModule(in txInputs) txOutputs { app.SetAnteHandler(anteHandler) } - if !in.Config.DisableAnteHandler { + if !in.Config.SkipPostHandler { // PostHandlers // In v0.46, the SDK introduces _postHandlers_. PostHandlers are like // antehandlers, but are run _after_ the `runMsgs` execution. They are also @@ -87,6 +88,10 @@ func provideModule(in txInputs) txOutputs { } func newAnteHandler(txConfig client.TxConfig, in txInputs) (sdk.AnteHandler, error) { + if in.AccountKeeper == nil || in.BankKeeper == nil { + return nil, fmt.Errorf("both AccountKeeper and BankKeeper are required") + } + anteHandler, err := ante.NewAnteHandler( ante.HandlerOptions{ AccountKeeper: in.AccountKeeper, From b5e9434e268b5ac6c357b7903708210f32afe2df Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 9 Jun 2022 22:50:43 +0200 Subject: [PATCH 09/15] fix test --- simapp/app.go | 12 +++++++++--- x/auth/tx/module/module.go | 31 ++++++++++++------------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index e126c5382ec3..26aec687c0d1 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -35,7 +35,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" - _ "github.com/cosmos/cosmos-sdk/x/auth/tx/module" // import tx module for side-effects + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/module" // import for side effects authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" @@ -211,8 +211,13 @@ func NewSimApp( var appBuilder *runtime.AppBuilder var msgServiceRouter *baseapp.MsgServiceRouter + var txBaseAppOption func(*baseapp.BaseApp) - if err := depinject.Inject(AppConfig, + if err := depinject.Inject( + depinject.Configs( + AppConfig, + depinject.Supply(&encodingConfig.TxConfig), + ), &appBuilder, &app.ParamsKeeper, &app.CapabilityKeeper, @@ -227,11 +232,12 @@ func NewSimApp( &app.NFTKeeper, &app.SlashingKeeper, &msgServiceRouter, + &txBaseAppOption, ); err != nil { panic(err) } - app.App = appBuilder.Build(logger, db, traceStore, msgServiceRouter, baseAppOptions...) + app.App = appBuilder.Build(logger, db, traceStore, msgServiceRouter, append(baseAppOptions, txBaseAppOption)...) app.keys = sdk.NewKVStoreKeys( minttypes.StoreKey, distrtypes.StoreKey, diff --git a/x/auth/tx/module/module.go b/x/auth/tx/module/module.go index 4b6db6f286cd..a866e0c24b8b 100644 --- a/x/auth/tx/module/module.go +++ b/x/auth/tx/module/module.go @@ -7,15 +7,11 @@ import ( "cosmossdk.io/core/appmodule" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/depinject" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/ante" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/auth/posthandler" - "github.com/cosmos/cosmos-sdk/x/auth/tx" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) func init() { @@ -27,29 +23,26 @@ func init() { type txInputs struct { depinject.In - Config *modulev1.Module - ProtoCodecMarshaler codec.ProtoCodecMarshaler + Config *modulev1.Module + TxConfig *client.TxConfig - AccountKeeper *authkeeper.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper" optional:"true"` - BankKeeper bankkeeper.Keeper `key:"cosmos.bank.v1.Keeper" optional:"true"` - FeeGrantKeeper *feegrantkeeper.Keeper `key:"cosmos.feegrant.v1.Keeper" optional:"true"` + AccountKeeper ante.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper" optional:"true"` + BankKeeper authtypes.BankKeeper `key:"cosmos.bank.v1.Keeper" optional:"true"` + FeeGrantKeeper ante.FeegrantKeeper `key:"cosmos.feegrant.v1.Keeper" optional:"true"` } type txOutputs struct { depinject.Out - TxConfig client.TxConfig BaseAppOption func(*baseapp.BaseApp) } func provideModule(in txInputs) txOutputs { - txConfig := tx.NewTxConfig(in.ProtoCodecMarshaler, tx.DefaultSignModes) - baseAppOption := func(app *baseapp.BaseApp) { if !in.Config.SkipAnteHandler { // AnteHandlers - anteHandler, err := newAnteHandler(txConfig, in) + anteHandler, err := newAnteHandler(in) if err != nil { panic(err) } @@ -81,14 +74,14 @@ func provideModule(in txInputs) txOutputs { } // TxDecoder - app.SetTxDecoder(txConfig.TxDecoder()) + app.SetTxDecoder((*in.TxConfig).TxDecoder()) } - return txOutputs{TxConfig: txConfig, BaseAppOption: baseAppOption} + return txOutputs{BaseAppOption: baseAppOption} } -func newAnteHandler(txConfig client.TxConfig, in txInputs) (sdk.AnteHandler, error) { - if in.AccountKeeper == nil || in.BankKeeper == nil { +func newAnteHandler(in txInputs) (sdk.AnteHandler, error) { + if in.BankKeeper == nil { return nil, fmt.Errorf("both AccountKeeper and BankKeeper are required") } @@ -96,7 +89,7 @@ func newAnteHandler(txConfig client.TxConfig, in txInputs) (sdk.AnteHandler, err ante.HandlerOptions{ AccountKeeper: in.AccountKeeper, BankKeeper: in.BankKeeper, - SignModeHandler: txConfig.SignModeHandler(), + SignModeHandler: (*in.TxConfig).SignModeHandler(), FeegrantKeeper: in.FeeGrantKeeper, SigGasConsumer: ante.DefaultSigVerificationGasConsumer, }, From ed52407872c9f7e823bb23d4c7643bc4a3b17016 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 9 Jun 2022 23:25:41 +0200 Subject: [PATCH 10/15] fix tests --- x/auth/tx/module/module.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/x/auth/tx/module/module.go b/x/auth/tx/module/module.go index a866e0c24b8b..47e0433c7f40 100644 --- a/x/auth/tx/module/module.go +++ b/x/auth/tx/module/module.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/auth/posthandler" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" ) func init() { @@ -26,9 +27,9 @@ type txInputs struct { Config *modulev1.Module TxConfig *client.TxConfig - AccountKeeper ante.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper" optional:"true"` - BankKeeper authtypes.BankKeeper `key:"cosmos.bank.v1.Keeper" optional:"true"` - FeeGrantKeeper ante.FeegrantKeeper `key:"cosmos.feegrant.v1.Keeper" optional:"true"` + AccountKeeper ante.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper" optional:"true"` + BankKeeper authtypes.BankKeeper `key:"cosmos.bank.v1.Keeper" optional:"true"` + FeeGrantKeeper feegrantkeeper.Keeper `key:"cosmos.feegrant.v1.Keeper" optional:"true"` } type txOutputs struct { From a2e77c8bb14378c6bdd080ea0984e0227350c565 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 9 Jun 2022 23:54:18 +0200 Subject: [PATCH 11/15] revert fix --- simapp/app.go | 11 +++-------- x/auth/tx/module/module.go | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 26aec687c0d1..5da7bbf346f1 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -35,7 +35,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" - _ "github.com/cosmos/cosmos-sdk/x/auth/tx/module" // import for side effects + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/module" // import for side-effects authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" @@ -211,13 +211,9 @@ func NewSimApp( var appBuilder *runtime.AppBuilder var msgServiceRouter *baseapp.MsgServiceRouter - var txBaseAppOption func(*baseapp.BaseApp) if err := depinject.Inject( - depinject.Configs( - AppConfig, - depinject.Supply(&encodingConfig.TxConfig), - ), + AppConfig, &appBuilder, &app.ParamsKeeper, &app.CapabilityKeeper, @@ -232,12 +228,11 @@ func NewSimApp( &app.NFTKeeper, &app.SlashingKeeper, &msgServiceRouter, - &txBaseAppOption, ); err != nil { panic(err) } - app.App = appBuilder.Build(logger, db, traceStore, msgServiceRouter, append(baseAppOptions, txBaseAppOption)...) + app.App = appBuilder.Build(logger, db, traceStore, msgServiceRouter, baseAppOptions...) app.keys = sdk.NewKVStoreKeys( minttypes.StoreKey, distrtypes.StoreKey, diff --git a/x/auth/tx/module/module.go b/x/auth/tx/module/module.go index 47e0433c7f40..c61c44369d8c 100644 --- a/x/auth/tx/module/module.go +++ b/x/auth/tx/module/module.go @@ -7,10 +7,12 @@ import ( "cosmossdk.io/core/appmodule" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/depinject" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/auth/posthandler" + "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" ) @@ -24,8 +26,8 @@ func init() { type txInputs struct { depinject.In - Config *modulev1.Module - TxConfig *client.TxConfig + Config *modulev1.Module + ProtoCodecMarshaler codec.ProtoCodecMarshaler AccountKeeper ante.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper" optional:"true"` BankKeeper authtypes.BankKeeper `key:"cosmos.bank.v1.Keeper" optional:"true"` @@ -35,15 +37,18 @@ type txInputs struct { type txOutputs struct { depinject.Out + TxConfig client.TxConfig BaseAppOption func(*baseapp.BaseApp) } func provideModule(in txInputs) txOutputs { + txConfig := tx.NewTxConfig(in.ProtoCodecMarshaler, tx.DefaultSignModes) + baseAppOption := func(app *baseapp.BaseApp) { if !in.Config.SkipAnteHandler { // AnteHandlers - anteHandler, err := newAnteHandler(in) + anteHandler, err := newAnteHandler(txConfig, in) if err != nil { panic(err) } @@ -75,13 +80,13 @@ func provideModule(in txInputs) txOutputs { } // TxDecoder - app.SetTxDecoder((*in.TxConfig).TxDecoder()) + app.SetTxDecoder(txConfig.TxDecoder()) } - return txOutputs{BaseAppOption: baseAppOption} + return txOutputs{TxConfig: txConfig, BaseAppOption: baseAppOption} } -func newAnteHandler(in txInputs) (sdk.AnteHandler, error) { +func newAnteHandler(txConfig client.TxConfig, in txInputs) (sdk.AnteHandler, error) { if in.BankKeeper == nil { return nil, fmt.Errorf("both AccountKeeper and BankKeeper are required") } @@ -90,7 +95,7 @@ func newAnteHandler(in txInputs) (sdk.AnteHandler, error) { ante.HandlerOptions{ AccountKeeper: in.AccountKeeper, BankKeeper: in.BankKeeper, - SignModeHandler: (*in.TxConfig).SignModeHandler(), + SignModeHandler: txConfig.SignModeHandler(), FeegrantKeeper: in.FeeGrantKeeper, SigGasConsumer: ante.DefaultSigVerificationGasConsumer, }, From 6e624022e4c39f77610948cbb9943e78aa05328e Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 10 Jun 2022 00:09:44 +0200 Subject: [PATCH 12/15] updates --- simapp/app.go | 4 +++- x/auth/tx/module/module.go | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 5da7bbf346f1..16c6fd21e28d 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -211,6 +211,7 @@ func NewSimApp( var appBuilder *runtime.AppBuilder var msgServiceRouter *baseapp.MsgServiceRouter + var txBaseAppOption func(*baseapp.BaseApp) if err := depinject.Inject( AppConfig, @@ -228,11 +229,12 @@ func NewSimApp( &app.NFTKeeper, &app.SlashingKeeper, &msgServiceRouter, + &txBaseAppOption, ); err != nil { panic(err) } - app.App = appBuilder.Build(logger, db, traceStore, msgServiceRouter, baseAppOptions...) + app.App = appBuilder.Build(logger, db, traceStore, msgServiceRouter, append(baseAppOptions, txBaseAppOption)...) app.keys = sdk.NewKVStoreKeys( minttypes.StoreKey, distrtypes.StoreKey, diff --git a/x/auth/tx/module/module.go b/x/auth/tx/module/module.go index c61c44369d8c..bd3f7ba1501e 100644 --- a/x/auth/tx/module/module.go +++ b/x/auth/tx/module/module.go @@ -46,8 +46,8 @@ func provideModule(in txInputs) txOutputs { baseAppOption := func(app *baseapp.BaseApp) { + // AnteHandlers if !in.Config.SkipAnteHandler { - // AnteHandlers anteHandler, err := newAnteHandler(txConfig, in) if err != nil { panic(err) @@ -55,8 +55,8 @@ func provideModule(in txInputs) txOutputs { app.SetAnteHandler(anteHandler) } + // PostHandlers if !in.Config.SkipPostHandler { - // PostHandlers // In v0.46, the SDK introduces _postHandlers_. PostHandlers are like // antehandlers, but are run _after_ the `runMsgs` execution. They are also // defined as a chain, and have the same signature as antehandlers. From ad7b8f7449e61da89fa6f74314125b92d9e5f80d Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 10 Jun 2022 00:24:38 +0200 Subject: [PATCH 13/15] fix test --- baseapp/block_gas_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 75134909061f..99bbbae22ebf 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -62,12 +62,12 @@ func TestBaseApp_BlockGas(t *testing.T) { return &sdk.Result{}, nil })) } + encCfg := simapp.MakeTestEncodingConfig() - encCfg.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil) - encCfg.InterfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), + app = simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, "", 0, encCfg, simapp.EmptyAppOptions{}, routerOpt) + app.InterfaceRegistry().RegisterImplementations((*sdk.Msg)(nil), &testdata.TestMsg{}, ) - app = simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, "", 0, encCfg, simapp.EmptyAppOptions{}, routerOpt) genState := simapp.GenesisStateWithSingleValidator(t, app) stateBytes, err := tmjson.MarshalIndent(genState, "", " ") require.NoError(t, err) From 864bafa27b677ef4fc71857f9b573678f9a66fc9 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 10 Jun 2022 00:26:17 +0200 Subject: [PATCH 14/15] updates --- simapp/app.go | 4 +--- x/auth/tx/module/module.go | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 16c6fd21e28d..5da7bbf346f1 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -211,7 +211,6 @@ func NewSimApp( var appBuilder *runtime.AppBuilder var msgServiceRouter *baseapp.MsgServiceRouter - var txBaseAppOption func(*baseapp.BaseApp) if err := depinject.Inject( AppConfig, @@ -229,12 +228,11 @@ func NewSimApp( &app.NFTKeeper, &app.SlashingKeeper, &msgServiceRouter, - &txBaseAppOption, ); err != nil { panic(err) } - app.App = appBuilder.Build(logger, db, traceStore, msgServiceRouter, append(baseAppOptions, txBaseAppOption)...) + app.App = appBuilder.Build(logger, db, traceStore, msgServiceRouter, baseAppOptions...) app.keys = sdk.NewKVStoreKeys( minttypes.StoreKey, distrtypes.StoreKey, diff --git a/x/auth/tx/module/module.go b/x/auth/tx/module/module.go index bd3f7ba1501e..5703746e3f2c 100644 --- a/x/auth/tx/module/module.go +++ b/x/auth/tx/module/module.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/depinject" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/auth/posthandler" @@ -38,7 +39,7 @@ type txOutputs struct { depinject.Out TxConfig client.TxConfig - BaseAppOption func(*baseapp.BaseApp) + BaseAppOption runtime.BaseAppOption } func provideModule(in txInputs) txOutputs { From d9efd894fc78cf5cb4868f68271ffc5644b00b3f Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 10 Jun 2022 00:28:16 +0200 Subject: [PATCH 15/15] updates --- simapp/app.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 5da7bbf346f1..91181ea53b9b 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -212,8 +212,7 @@ func NewSimApp( var appBuilder *runtime.AppBuilder var msgServiceRouter *baseapp.MsgServiceRouter - if err := depinject.Inject( - AppConfig, + if err := depinject.Inject(AppConfig, &appBuilder, &app.ParamsKeeper, &app.CapabilityKeeper,