@@ -84,10 +84,14 @@ type ConcreteInfo struct {
8484
8585 // These fields get set for all concrete types,
8686 // even those not manually registered (e.g. are never interface values).
87- IsAminoMarshaler bool // Implements MarshalAmino() (<ReprObject>, error).
88- AminoMarshalReprType reflect.Type // <ReprType>
89- IsAminoUnmarshaler bool // Implements UnmarshalAmino(<ReprObject>) (error).
90- AminoUnmarshalReprType reflect.Type // <ReprType>
87+ IsAminoMarshaler bool // Implements MarshalAmino() (<ReprObject>, error).
88+ AminoMarshalReprType reflect.Type // <ReprType>
89+ IsAminoUnmarshaler bool // Implements UnmarshalAmino(<ReprObject>) (error).
90+ AminoUnmarshalReprType reflect.Type // <ReprType>
91+ IsAminoJSONMarshaler bool // Implements MarshalAminoJSON() (<ReprObject>, error).
92+ AminoJSONMarshalReprType reflect.Type // <ReprType>
93+ IsAminoJSONUnmarshaler bool // Implements UnmarshalAminoJSON(<ReprObject>) (error).
94+ AminoJSONUnmarshalReprType reflect.Type // <ReprType>
9195}
9296
9397type StructInfo struct {
@@ -566,6 +570,14 @@ func (cdc *Codec) newTypeInfoUnregistered(rt reflect.Type) *TypeInfo {
566570 info .ConcreteInfo .IsAminoUnmarshaler = true
567571 info .ConcreteInfo .AminoUnmarshalReprType = unmarshalAminoReprType (rm )
568572 }
573+ if rm , ok := rt .MethodByName ("MarshalAminoJSON" ); ok {
574+ info .ConcreteInfo .IsAminoJSONMarshaler = true
575+ info .ConcreteInfo .AminoJSONMarshalReprType = marshalAminoJSONReprType (rm )
576+ }
577+ if rm , ok := reflect .PtrTo (rt ).MethodByName ("UnmarshalAminoJSON" ); ok {
578+ info .ConcreteInfo .IsAminoJSONUnmarshaler = true
579+ info .ConcreteInfo .AminoJSONUnmarshalReprType = unmarshalAminoJSONReprType (rm )
580+ }
569581 return info
570582}
571583
@@ -804,3 +816,42 @@ func unmarshalAminoReprType(rm reflect.Method) (rrt reflect.Type) {
804816 }
805817 return
806818}
819+
820+ func marshalAminoJSONReprType (rm reflect.Method ) (rrt reflect.Type ) {
821+ // Verify form of this method.
822+ if rm .Type .NumIn () != 1 {
823+ panic (fmt .Sprintf ("MarshalAminoJSON should have 1 input parameters (including receiver); got %v" , rm .Type ))
824+ }
825+ if rm .Type .NumOut () != 2 {
826+ panic (fmt .Sprintf ("MarshalAminoJSON should have 2 output parameters; got %v" , rm .Type ))
827+ }
828+ if out := rm .Type .Out (1 ); out != errorType {
829+ panic (fmt .Sprintf ("MarshalAminoJSON should have second output parameter of error type, got %v" , out ))
830+ }
831+ rrt = rm .Type .Out (0 )
832+ if rrt .Kind () == reflect .Ptr {
833+ panic (fmt .Sprintf ("Representative objects cannot be pointers; got %v" , rrt ))
834+ }
835+ return
836+ }
837+
838+ func unmarshalAminoJSONReprType (rm reflect.Method ) (rrt reflect.Type ) {
839+ // Verify form of this method.
840+ if rm .Type .NumIn () != 2 {
841+ panic (fmt .Sprintf ("UnmarshalAminoJSON should have 2 input parameters (including receiver); got %v" , rm .Type ))
842+ }
843+ if in1 := rm .Type .In (0 ); in1 .Kind () != reflect .Ptr {
844+ panic (fmt .Sprintf ("UnmarshalAminoJSON first input parameter should be pointer type but got %v" , in1 ))
845+ }
846+ if rm .Type .NumOut () != 1 {
847+ panic (fmt .Sprintf ("UnmarshalAminoJSON should have 1 output parameters; got %v" , rm .Type ))
848+ }
849+ if out := rm .Type .Out (0 ); out != errorType {
850+ panic (fmt .Sprintf ("UnmarshalAminoJSON should have first output parameter of error type, got %v" , out ))
851+ }
852+ rrt = rm .Type .In (1 )
853+ if rrt .Kind () == reflect .Ptr {
854+ panic (fmt .Sprintf ("Representative objects cannot be pointers; got %v" , rrt ))
855+ }
856+ return
857+ }
0 commit comments